webengine/osswebengine/WebKit/s60/misc/WebTabbedNavigation.cpp
changeset 15 60c5402cb945
parent 10 a359256acfc6
child 25 0ed94ceaa377
equal deleted inserted replaced
11:c8a366e56285 15:60c5402cb945
    79 }
    79 }
    80 
    80 
    81 void WebTabbedNavigation::updateCursorPosition(const TPoint& pos)
    81 void WebTabbedNavigation::updateCursorPosition(const TPoint& pos)
    82 {
    82 {
    83     m_focusPosition = pos;
    83     m_focusPosition = pos;
    84     WebFrame* frame = StaticObjectsContainer::instance()->webCursor()->getFrameAtPoint(pos);
       
    85     TPoint point(frame->frameView()->viewCoordsInFrameCoords(pos));
       
    86 
       
    87     Element* node = core(frame)->document()->elementFromPoint(point.iX, point.iY);
       
    88     if (node->isFocusable() && !node->hasTagName(iframeTag) && !node->hasTagName(frameTag))
       
    89         m_webView->page()->focusController()->setFocusedNode(node, core(frame));
       
    90     else
       
    91         m_webView->page()->focusController()->setFocusedNode(NULL, core(frame));
       
    92     m_selectedElementRect.SetRect(pos.iX, pos.iY, pos.iX + 1, pos.iY + 1);
    84     m_selectedElementRect.SetRect(pos.iX, pos.iY, pos.iX + 1, pos.iY + 1);
    93 }
    85 }
    94 
    86 
    95 void WebTabbedNavigation::focusedElementChanged(Element* element)
    87 void WebTabbedNavigation::focusedElementChanged(Element* element)
    96 {
    88 {
    99     m_node = element;
    91     m_node = element;
   100     m_selectedElementRect = element->getRect().Rect();
    92     m_selectedElementRect = element->getRect().Rect();
   101     m_focusPosition = StaticObjectsContainer::instance()->webCursor()->position();
    93     m_focusPosition = StaticObjectsContainer::instance()->webCursor()->position();
   102 }
    94 }
   103 
    95 
   104 bool WebTabbedNavigation::navigate(int horizontalDir, int verticalDir)
    96 
   105 {
    97 void WebTabbedNavigation::resetNavigationIfNeeded(TPoint& contentPos, TSize& contentSize, 
   106     if (handleSelectElementScrolling(m_webView, verticalDir)) {
    98                                                   Frame* focusedFrame, int horizontalDir, int verticalDir)
   107         StaticObjectsContainer::instance()->webCursor()->cursorUpdate(true);
    99 {
   108         return true;
   100     TPoint docBrViewCoord = kit(focusedFrame)->frameView()->frameCoordsInViewCoords(
   109     }
   101                                            TPoint(contentSize.iWidth, contentSize.iHeight));
   110     // DOM can be changed so check if we are still inside the document
   102     TRect docRect = TRect(TPoint(0,0), docBrViewCoord);
   111     // If not reset tabbed navigation parameters to the closest point in document.
       
   112     TSize contentSize = m_webView->mainFrame()->frameView()->contentSize();
       
   113     TPoint contentPos = m_webView->mainFrame()->frameView()->contentPos();
       
   114     TRect docRect = TRect(contentPos, contentSize - contentPos);
       
   115     if (!docRect.Contains(m_focusPosition)) {
   103     if (!docRect.Contains(m_focusPosition)) {
   116         TInt viewW = m_webView->Rect().Width();
   104         TInt viewW = m_webView->Rect().Width();
   117         TInt viewH = m_webView->Rect().Height();
   105         TInt viewH = m_webView->Rect().Height();
   118         if (m_focusPosition.iX > contentSize.iWidth || 
   106         if (m_focusPosition.iX > contentSize.iWidth) {
   119             m_focusPosition.iX < contentPos.iX) {
       
   120             m_focusPosition.iX = (horizontalDir == -1) ? contentPos.iX + viewW : contentPos.iX;
   107             m_focusPosition.iX = (horizontalDir == -1) ? contentPos.iX + viewW : contentPos.iX;
   121         }
   108         }
   122         
   109         
   123         if (m_focusPosition.iY > contentSize.iHeight || 
   110         if (m_focusPosition.iY > contentSize.iHeight) {
   124             m_focusPosition.iY < contentPos.iY) {
       
   125             m_focusPosition.iY = (verticalDir == -1) ? contentPos.iY + viewH : contentPos.iY;
   111             m_focusPosition.iY = (verticalDir == -1) ? contentPos.iY + viewH : contentPos.iY;
   126         }
   112         }
   127 
   113     
   128         m_selectedElementRect.SetRect(m_focusPosition.iX, m_focusPosition.iY, m_focusPosition.iX, m_focusPosition.iY);
   114         m_selectedElementRect.SetRect(m_focusPosition.iX, m_focusPosition.iY, 
       
   115                                       m_focusPosition.iX, m_focusPosition.iY);
   129         m_node = NULL;    
   116         m_node = NULL;    
   130     }
   117     }
       
   118 }
       
   119 
       
   120 
       
   121 TPoint WebTabbedNavigation::focusPointFromFocusedNode(Frame* frame, int horizontalDir, int verticalDir)
       
   122 {
       
   123     TPoint oldFocusPoint(m_focusPosition);
       
   124     TPoint focusPosition(m_focusPosition);
       
   125     TRect  selectedElementRect(m_selectedElementRect);
       
   126     
       
   127     if (frame->document()) {
       
   128         Node* focusedNode = frame->document()->focusedNode();
       
   129         if (focusedNode) {
       
   130             m_node = focusedNode;
       
   131             selectedElementRect = focusedNode->getRect().Rect();
       
   132             Frame* frame = focusedNode->document()->frame();
       
   133             selectedElementRect = kit(frame)->frameView()->frameCoordsInViewCoords(selectedElementRect);
       
   134 
       
   135             // Move the focus to the visible edge of the current object
       
   136             TRect elemVisibleRect = selectedElementRect;
       
   137             if (elemVisibleRect.Intersects(m_webView->Rect())) {
       
   138                  
       
   139                 elemVisibleRect.Intersection(m_webView->Rect());
       
   140                 if (horizontalDir == -1) {
       
   141                     focusPosition.iX = elemVisibleRect.iTl.iX;
       
   142                 }
       
   143                 else if (horizontalDir == 1) {
       
   144                     focusPosition.iX = elemVisibleRect.iBr.iX;
       
   145                 }
       
   146                 
       
   147                 if (verticalDir == -1) {
       
   148                     focusPosition.iY = elemVisibleRect.iTl.iY;
       
   149                 }
       
   150                 else if (verticalDir == 1) {
       
   151                     focusPosition.iY = elemVisibleRect.iBr.iY;
       
   152                 }
       
   153                 
       
   154                 if ((verticalDir == 0) && (horizontalDir == 0)) {
       
   155                     focusPosition = elemVisibleRect.Center();
       
   156                 }
       
   157                 m_focusPosition = focusPosition;
       
   158             }
       
   159             m_selectedElementRect = selectedElementRect;
       
   160         }
       
   161     }
       
   162     return oldFocusPoint;
       
   163 }
       
   164 
       
   165 
       
   166 void WebTabbedNavigation::calcSearchViewRect(int horizontalDir, int verticalDir, TRect& view)
       
   167 {
       
   168     
       
   169     TPoint br;
       
   170     TPoint viewBr = m_webView->Rect().iBr;
       
   171     br.iX = viewBr.iX * KMaxJumpPercent / m_webView->scalingFactor();
       
   172     br.iY = viewBr.iY * KMaxJumpPercent / m_webView->scalingFactor();
       
   173     // define the view rect where we are looking for a match
       
   174     int x, y;
       
   175     if (horizontalDir == -1) {
       
   176         view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY - br.iY, 
       
   177                 m_focusPosition.iX , m_focusPosition.iY + br.iY);
       
   178     }
       
   179     else if (horizontalDir == 1) {
       
   180         view.SetRect(m_focusPosition.iX, m_focusPosition.iY - br.iY, 
       
   181                 m_focusPosition.iX + br.iX, m_focusPosition.iY + br.iY);
       
   182     }
       
   183     else if (verticalDir == -1) {
       
   184         view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY - br.iY, 
       
   185                      m_focusPosition.iX + br.iX, m_focusPosition.iY);
       
   186     }
       
   187     else if (verticalDir == 1) {
       
   188         view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY, 
       
   189                      m_focusPosition.iX + br.iX, m_focusPosition.iY + br.iY);
       
   190     }
       
   191 }
       
   192 
       
   193 TPoint WebTabbedNavigation::updateCursorPosAfterScroll(Frame* frame, int horizontalDir, int verticalDir)
       
   194 {
       
   195     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
   196     TPoint oldPos = cursor->position();
       
   197     
       
   198     focusPointFromFocusedNode(frame, horizontalDir, verticalDir);
       
   199     if (m_node && !m_selectedElementRect.Intersects(m_webView->Rect())) {
       
   200         static_cast<Node*>(m_node)->document()->setFocusedNode(NULL);
       
   201         m_node = NULL;
       
   202     }
       
   203     
       
   204     cursor->setPosition(m_focusPosition - TPoint(horizontalDir, verticalDir));
       
   205     return oldPos;
       
   206 }
       
   207 
       
   208 bool WebTabbedNavigation::navigate(int horizontalDir, int verticalDir)
       
   209 {
       
   210     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
   211     if (handleSelectElementScrolling(m_webView, verticalDir)) {
       
   212         cursor->cursorUpdate(true);
       
   213         return true;
       
   214     }
       
   215     Frame* mainFrame = core(m_webView->mainFrame());
       
   216     FocusController* focusController = m_webView->page()->focusController();
       
   217     Frame* focusedFrame = focusController->focusedOrMainFrame();        
       
   218     TSize contentSize = kit(focusedFrame)->frameView()->contentSize();
       
   219     TPoint contentPos = kit(focusedFrame)->frameView()->contentPos();
       
   220     
       
   221     // DOM can be changed so check if we are still inside the document
       
   222     // If not reset tabbed navigation parameters to the closest point in document.
       
   223     resetNavigationIfNeeded(contentPos, contentSize, focusedFrame, horizontalDir, verticalDir);
       
   224     
   131     
   225     
   132     bool ret = m_firstNavigationOnPage;
   226     bool ret = m_firstNavigationOnPage;
   133     Frame* focusedFrame = m_webView->page()->focusController()->focusedFrame();
   227     
   134     if (focusedFrame == NULL) focusedFrame = m_webView->page()->mainFrame();
   228     if (focusedFrame == NULL) focusedFrame = mainFrame;
   135     if (focusedFrame->document()) {
   229     TPoint oldFocusPoint =  focusPointFromFocusedNode(focusedFrame, horizontalDir, verticalDir);
   136         Node* focusNode = focusedFrame->document()->focusedNode();
       
   137         if (focusNode) {
       
   138             m_node = focusNode;
       
   139             m_selectedElementRect = focusNode->getRect().Rect();
       
   140             Frame* frame = focusNode->document()->frame();
       
   141             m_selectedElementRect = TRect(kit(frame)->frameView()->frameCoordsInViewCoords(m_selectedElementRect.iTl), 
       
   142                 kit(frame)->frameView()->frameCoordsInViewCoords(m_selectedElementRect.iBr));
       
   143         }
       
   144     }
       
   145     TPoint oldFocusPoint(m_focusPosition);
       
   146     // Move the focus to the edge of the current object
       
   147     if (horizontalDir == -1) {
       
   148         m_focusPosition.iX = m_selectedElementRect.iTl.iX;
       
   149     }
       
   150     else if (horizontalDir == 1) {
       
   151         m_focusPosition.iX = m_selectedElementRect.iBr.iX;
       
   152     }
       
   153     if (verticalDir == -1) {
       
   154         m_focusPosition.iY = m_selectedElementRect.iTl.iY;
       
   155     }
       
   156     else if (verticalDir == 1) {
       
   157         m_focusPosition.iY = m_selectedElementRect.iBr.iY;
       
   158     }
       
   159     wkDebug()<<"WebTabbedNavigation::navigate. x = "<<m_focusPosition.iX<<" y = "<<m_focusPosition.iY<<flush;
       
   160     wkDebug()<<"x1 = "<<m_selectedElementRect.iTl.iX<<" y1 = "<<m_selectedElementRect.iTl.iY<<" x2 = "<<m_selectedElementRect.iBr.iX<<" y2 = "<<m_selectedElementRect.iBr.iY<<flush;
       
   161     
       
   162     // Adjust the move
       
   163     TPoint br;
       
   164     br.iX = m_webView->Rect().iBr.iX * KMaxJumpPercent / m_webView->scalingFactor();
       
   165     br.iY = m_webView->Rect().iBr.iY * KMaxJumpPercent / m_webView->scalingFactor();
       
   166     TRect view;
   230     TRect view;
   167     // define the view rect where we are looking for a match
   231     calcSearchViewRect(horizontalDir, verticalDir, view);
   168     if (horizontalDir == -1) {
   232 
   169         view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY - br.iY, m_focusPosition.iX, m_focusPosition.iY + br.iY);
   233     // walk all focusable nodes    
   170     }
       
   171     else if (horizontalDir == 1) {
       
   172         view.SetRect(m_focusPosition.iX, m_focusPosition.iY - br.iY, m_focusPosition.iX + br.iX, m_focusPosition.iY + br.iY);
       
   173     }
       
   174     else if (verticalDir == -1) {
       
   175         view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY - br.iY, m_focusPosition.iX + br.iX, m_focusPosition.iY);
       
   176     }
       
   177     else if (verticalDir == 1) {
       
   178         view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY, m_focusPosition.iX + br.iX, m_focusPosition.iY + br.iY);
       
   179     }
       
   180     //wkDebug()<<"view x1 = "<<view.iTl.iX<<" y1 = "<<view.iTl.iY<<" x2 = "<<view.iBr.iX<<" y2 = "<<view.iBr.iY<<flush;
       
   181     // walk all focusable nodes
       
   182     Frame* f = m_webView->page()->mainFrame();
       
   183     TPoint selectedPoint(0, 0);
   234     TPoint selectedPoint(0, 0);
   184     TRect selectedRect(0, 0, 0, 0);
   235     TRect selectedRect(0, 0, 0, 0);
   185     Node* selectedNode = NULL;
   236     Node* selectedNode = bestFitFocusableNode(mainFrame, view, horizontalDir, verticalDir, 
       
   237                                               selectedPoint, selectedRect);
       
   238     
       
   239     // Remember new selection
       
   240     contentPos = kit(mainFrame)->frameView()->contentPos();
       
   241     if (selectedNode) {
       
   242         // Found an element to jump to
       
   243         m_selectedElementRect = selectedRect;
       
   244         m_focusPosition = selectedPoint;
       
   245         m_node = selectedNode;
       
   246         selectedNode->document()->setFocusedNode(selectedNode);
       
   247         m_webView->page()->focusController()->setFocusedFrame(selectedNode->document()->frame());
       
   248         
       
   249         // And scroll to the selected element
       
   250         RenderLayer *layer = selectedNode->renderer()->enclosingLayer();
       
   251         if (layer) {
       
   252             layer->scrollRectToVisible(selectedNode->getRect(), RenderLayer::gAlignCenterIfNeeded, RenderLayer::gAlignCenterIfNeeded);
       
   253             WebFrameView* fv = kit(selectedNode->document()->frame())->frameView();
       
   254             TRect newRect = fv->frameCoordsInViewCoords(selectedNode->getRect().Rect());
       
   255             selectedRect = newRect;
       
   256             selectedPoint = potentialFocusPoint(horizontalDir, verticalDir, newRect);
       
   257             m_selectedElementRect = selectedRect;
       
   258             m_focusPosition = selectedPoint;
       
   259                         
       
   260             cursor->updatePositionAndElemType(m_focusPosition);
       
   261             // special handling for Select-Multi
       
   262             if (m_webView->focusedElementType() == TBrCtlDefs::EElementSelectMultiBox) {
       
   263                 handleMultiSelect(horizontalDir, verticalDir);
       
   264             }
       
   265             
       
   266             m_webView->sendMouseEventToEngine(TPointerEvent::EMove, cursor->position(), mainFrame);
       
   267             ret = true;
       
   268         }
       
   269     }
       
   270     else {
       
   271         if (!m_firstNavigationOnPage) {
       
   272             TInt vWidth = m_webView->Rect().Width();
       
   273             TInt vHeight = m_webView->Rect().Height();
       
   274             kit(mainFrame)->frameView()->scrollTo(contentPos + 
       
   275                                                   TPoint(horizontalDir * vWidth / KScrollWhenNotFound, 
       
   276                                                          verticalDir * vHeight / KScrollWhenNotFound));
       
   277           
       
   278             cursor->updatePositionAndElemType(m_focusPosition - TPoint(horizontalDir, verticalDir));
       
   279         }
       
   280     }
       
   281     cursor->cursorUpdate(true);
       
   282     return ret;
       
   283 }
       
   284 
       
   285 
       
   286 
       
   287 Node* WebTabbedNavigation::bestFitFocusableNode(Frame* topFrame, TRect& viewRect, int horizontalDir, int verticalDir, //input
       
   288                                                 TPoint& selectedPoint, TRect& selectedRect ) //output
       
   289 {
       
   290    Node* selectedNode = NULL;
       
   291    Frame* f = topFrame;
   186     while ( f ) {
   292     while ( f ) {
   187         PassRefPtr<HTMLCollection> elements = f->document()->all();   
   293         PassRefPtr<HTMLCollection> elements = f->document()->all();   
   188         TRect frameRect = kit(f)->frameView()->rectInGlobalCoords();
   294         TRect frameRect = kit(f)->frameView()->rectInGlobalCoords();
   189         for (Node* n = elements->firstItem(); n; n = elements->nextItem()) {
   295         for (Node* n = elements->firstItem(); n; n = elements->nextItem()) {
   190             if (n == m_node) continue;
   296             if (n == m_node) continue;
   191             if (n->isFocusable() && n->isElementNode() && !n->hasTagName(iframeTag) && !n->hasTagName(frameTag)) {
   297             if (n->isFocusable() && n->isElementNode() && !n->hasTagName(iframeTag) && !n->hasTagName(frameTag)) {
   192                 // Does the node intersect with the view rect?
   298                 // Does the node intersect with the view rect?
   193                 TRect nodeRect = n->getRect().Rect();
   299                 TRect nodeRect = n->getRect().Rect();
   194                 //wkDebug()<<"Each node rect x1 = "<<nodeRect.iTl.iX<<" y1 = "<<nodeRect.iTl.iY<<" x2 = "<<nodeRect.iBr.iX<<" y2 = "<<nodeRect.iBr.iY<<flush;
   300                 nodeRect = kit(f)->frameView()->frameCoordsInViewCoords(nodeRect);
   195                 nodeRect = TRect(kit(f)->frameView()->frameCoordsInViewCoords(nodeRect.iTl), 
   301                 if (nodeRect.Intersects(viewRect) && 
   196                     kit(f)->frameView()->frameCoordsInViewCoords(nodeRect.iBr));
   302                     shouldConsiderRect(nodeRect, viewRect, horizontalDir, verticalDir)) {
   197                 if (nodeRect.Intersects(view)) {
       
   198                     // Compare nodes and select the best fit
   303                     // Compare nodes and select the best fit
   199                     TPoint newFocusPoint = potentialFocusPoint(horizontalDir, verticalDir, nodeRect);
   304                     TPoint newFocusPoint = potentialFocusPoint(horizontalDir, verticalDir, nodeRect);
   200                     wkDebug()<<"Matching node rect x1 = "<<nodeRect.iTl.iX<<" y1 = "<<nodeRect.iTl.iY<<" x2 = "<<nodeRect.iBr.iX<<" y2 = "<<nodeRect.iBr.iY<<flush;
       
   201                     if (selectNode(horizontalDir, verticalDir, selectedRect, nodeRect, selectedPoint, newFocusPoint)) {
   305                     if (selectNode(horizontalDir, verticalDir, selectedRect, nodeRect, selectedPoint, newFocusPoint)) {
   202                         // found a better fit
   306                         // found a better fit
   203                         selectedNode = n;
   307                         selectedNode = n;
   204                         selectedRect.SetRect(nodeRect.iTl, nodeRect.iBr);
   308                         selectedRect.SetRect(nodeRect.iTl, nodeRect.iBr);
   205                         selectedPoint = newFocusPoint;
   309                         selectedPoint = newFocusPoint;
   207                 } // if (nodeRect.Intersects(rect[i])
   311                 } // if (nodeRect.Intersects(rect[i])
   208             } // if (n->isFocusable() && n->isElementNode())
   312             } // if (n->isFocusable() && n->isElementNode())
   209         } // for (Node* n = elements->firstItem(); n; n = elements->nextItem())
   313         } // for (Node* n = elements->firstItem(); n; n = elements->nextItem())
   210         f = f->tree()->traverseNext();
   314         f = f->tree()->traverseNext();
   211     } // while ( f )
   315     } // while ( f )
   212     // Remember new selection
   316     return selectedNode;
   213     contentPos = m_webView->mainFrame()->frameView()->contentPos();
   317 }
   214     if (selectedNode) {
   318 
   215         // Found an element to jump to
   319 
   216         m_selectedElementRect = selectedRect;
   320 bool WebTabbedNavigation::shouldConsiderRect(TRect& rect, TRect& searchRect, int horizontalDir, int verticalDir)
   217         m_focusPosition = selectedPoint;
   321 {
   218         m_node = selectedNode;
   322     bool considerX = false;
   219         selectedNode->document()->setFocusedNode(selectedNode);
   323     bool considerY = false;
   220          m_webView->page()->focusController()->setFocusedFrame(selectedNode->document()->frame());
   324     
   221         // And scroll to the selected element
   325     if (horizontalDir == 1) {
   222         RenderLayer *layer = selectedNode->renderer()->enclosingLayer();
   326         considerX = (rect.iTl.iX >= searchRect.iTl.iX);
   223         if (layer) {
   327     }
   224             layer->scrollRectToVisible(selectedNode->getRect(), RenderLayer::gAlignCenterIfNeeded, RenderLayer::gAlignCenterIfNeeded);
   328     else if (horizontalDir == -1) {
   225             TRect newRect = TRect(kit(selectedNode->document()->frame())->frameView()->frameCoordsInViewCoords(selectedNode->getRect().Rect().iTl), 
   329         considerX = (rect.iBr.iX <= searchRect.iBr.iX);
   226                 kit(selectedNode->document()->frame())->frameView()->frameCoordsInViewCoords(selectedNode->getRect().Rect().iBr));
   330     }
   227             selectedPoint += (newRect.iTl - selectedRect.iTl);
   331     
   228             m_focusPosition = selectedPoint;
   332     if (verticalDir == 1) {
   229             selectedRect = newRect;
   333         considerY = (rect.iTl.iY >= searchRect.iTl.iY);
   230             m_selectedElementRect = selectedRect;
   334     }
   231 
   335     else if (verticalDir == -1) {
   232             int x, y;
   336         considerY = (rect.iBr.iY <= searchRect.iBr.iY);
   233             selectedNode->renderer()->absolutePosition(x, y);
   337     }
   234             Vector<IntRect> rects;
   338     
   235             selectedNode->renderer()->absoluteRects(rects, x, y);
   339     return considerX || considerY;
   236             WebFrameView* fv = kit(selectedNode->document()->frame())->frameView();
   340     
   237             if (rects.size() > 0) {
   341 }
   238                  selectedPoint = TPoint(rects[0].x(), rects[0].y());
   342 
   239                 selectedPoint = fv->frameCoordsInViewCoords(selectedPoint);
   343 void WebTabbedNavigation::handleMultiSelect(int horizontalDir, int verticalDir)
       
   344 {
       
   345     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
   346     Node* n = static_cast<Node*>(m_node);
       
   347     WebFrameView* fv = kit(n->document()->frame())->frameView();
       
   348     Element* e = static_cast<Element*>(m_node);
       
   349     if (e->isControl()) {
       
   350         HTMLGenericFormElement* ie = static_cast<HTMLGenericFormElement*>( e );
       
   351         if (ie->type() == "select-multiple") {
       
   352             RenderListBox* render = static_cast<RenderListBox*>(e->renderer());
       
   353             HTMLSelectElement* selectElement = static_cast<HTMLSelectElement*>( e );
       
   354             TRect itemRect = render->itemRect(0, 0, render->indexOffset()).Rect();
       
   355             TRect itemRectViewCoord = fv->frameCoordsInViewCoords(itemRect);
       
   356             itemRectViewCoord.Move(m_selectedElementRect.iTl);
       
   357             itemRectViewCoord.Intersection(fv->topView()->Rect());           
       
   358             
       
   359             TPoint cursorPoint = itemRect.Center() + m_selectedElementRect.iTl;
       
   360             if (cursorPoint != cursor->position()) {
       
   361                 cursor->setPosition(cursorPoint);
   240             }
   362             }
   241             StaticObjectsContainer::instance()->webCursor()->updatePositionAndElemType(selectedPoint);
   363         }
   242             // special handling for Select-Multi
   364     }
   243             if (m_webView->focusedElementType() == TBrCtlDefs::EElementSelectMultiBox) {
       
   244                 Element* e = static_cast<Element*>(m_node);
       
   245                 if (e->isControl()) {
       
   246                     HTMLGenericFormElement* ie = static_cast<HTMLGenericFormElement*>( e );
       
   247                     if (ie->type() == "select-multiple") {
       
   248                         RenderListBox* render = static_cast<RenderListBox*>(e->renderer());
       
   249                         HTMLSelectElement* selectElement = static_cast<HTMLSelectElement*>( e );
       
   250                         IntRect itemRect = render->itemRect(0, 0, 0);
       
   251                         TPoint cursorPoint(StaticObjectsContainer::instance()->webCursor()->position());
       
   252                         int gap = (20 * m_webView->scalingFactor()) / 100;
       
   253                         cursorPoint.iX = max(m_focusPosition.iX,  m_selectedElementRect.iTl.iX + gap);
       
   254                         cursorPoint.iX = std::min(cursorPoint.iX,  m_selectedElementRect.iBr.iX - gap);
       
   255                         if (verticalDir == -1) {
       
   256                             cursorPoint.iY -= (itemRect.height() * m_webView->scalingFactor()) / 125;
       
   257                         }
       
   258                         if (cursorPoint != StaticObjectsContainer::instance()->webCursor()->position()) {
       
   259                             StaticObjectsContainer::instance()->webCursor()->setPosition(cursorPoint);
       
   260                         }
       
   261                     }
       
   262                 }
       
   263             }
       
   264             TPointerEvent event;
       
   265             event.iPosition = StaticObjectsContainer::instance()->webCursor()->position();
       
   266             event.iModifiers = 0;
       
   267             event.iType = TPointerEvent::EMove;
       
   268             core(m_webView->mainFrame())->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event));            
       
   269             wkDebug()<<"Focus position x = "<<selectedPoint.iX<<" y = "<<selectedPoint.iY<<flush;
       
   270             ret = true;
       
   271         }
       
   272     }
       
   273     else {
       
   274         if (!m_firstNavigationOnPage) {
       
   275             m_webView->mainFrame()->frameView()->scrollTo(contentPos + TPoint(horizontalDir * m_webView->Rect().Width() / KScrollWhenNotFound, verticalDir * m_webView->Rect().Height() / KScrollWhenNotFound));
       
   276             TPoint diff(m_webView->mainFrame()->frameView()->contentPos() - contentPos);
       
   277             if (diff.iX || diff.iY) {
       
   278                 Frame* focusedFrame = m_webView->page()->focusController()->focusedFrame();
       
   279                 if (focusedFrame == NULL) focusedFrame = m_webView->page()->mainFrame();
       
   280                 Node* focusNode = focusedFrame->document()->focusedNode();
       
   281                 if (focusNode) {
       
   282                     TRect selectedRect = focusNode->getRect().Rect();
       
   283                     selectedRect = TRect(kit(focusedFrame)->frameView()->frameCoordsInViewCoords(selectedRect.iTl), 
       
   284                         kit(focusedFrame)->frameView()->frameCoordsInViewCoords(selectedRect.iBr));
       
   285                     if (!selectedRect.Intersects(kit(focusedFrame)->frameView()->visibleRect()))
       
   286                         m_webView->page()->focusController()->setFocusedNode(NULL,0);
       
   287                 }
       
   288                 m_selectedElementRect.Move(diff);
       
   289                 m_focusPosition = oldFocusPoint + diff;
       
   290                 m_node = NULL;
       
   291                 StaticObjectsContainer::instance()->webCursor()->updatePositionAndElemType(m_focusPosition - m_webView->mainFrame()->frameView()->contentPos());
       
   292                 ret = true;
       
   293             }
       
   294             else
       
   295             {
       
   296                 m_focusPosition = oldFocusPoint;
       
   297             }
       
   298         }
       
   299     }
       
   300     StaticObjectsContainer::instance()->webCursor()->cursorUpdate(true);
       
   301     return ret;
       
   302 }
   365 }
   303 
   366 
   304 bool WebTabbedNavigation::selectNode(int horizontalDir, int verticalDir, TRect& selectedRect, TRect& newNodeRect, TPoint& selectedPoint, TPoint& newFocusPoint)
   367 bool WebTabbedNavigation::selectNode(int horizontalDir, int verticalDir, TRect& selectedRect, TRect& newNodeRect, TPoint& selectedPoint, TPoint& newFocusPoint)
   305 {
   368 {
   306     if (selectedPoint == TPoint(0, 0)) { // first selected node fixme: ensure not to divert direction too much
   369     if (selectedPoint == TPoint(0, 0)) { // first selected node fixme: ensure not to divert direction too much
   307         return true;
   370         return true;
   308     }
   371     }
   309     int selectedDist = distanceFunction(horizontalDir, verticalDir, selectedRect, selectedPoint);
   372     int selectedDist = distanceFunction(horizontalDir, verticalDir, selectedRect, selectedPoint);
   310     int newDist = distanceFunction(horizontalDir, verticalDir, newNodeRect, newFocusPoint);
   373     int newDist = distanceFunction(horizontalDir, verticalDir, newNodeRect, newFocusPoint);
   311     wkDebug()<<"WebTabbedNavigation::selectNode. selected x = "<<selectedPoint.iX<<" y = "<<selectedPoint.iY<<" new x = "<<newFocusPoint.iX<<" y = "<<newFocusPoint.iY<<"old distance = "<<selectedDist<<" new distance = "<<newDist<<flush;
   374 
   312     return newDist < selectedDist;
   375     return newDist < selectedDist;
   313 }
   376 }
   314 
   377 
   315 TPoint WebTabbedNavigation::potentialFocusPoint(int horizontalDir, int verticalDir, TRect& newNodeRect)
   378 TPoint WebTabbedNavigation::potentialFocusPoint(int horizontalDir, int verticalDir, TRect& newNodeRect)
   316 {
   379 {
   397     long ed, o;
   460     long ed, o;
   398     Math::Int(ed, euclidianDistance);
   461     Math::Int(ed, euclidianDistance);
   399     Math::Int(o, sqrt(overlap));
   462     Math::Int(o, sqrt(overlap));
   400     return ed + sameAxisDist + 2 * otherAxisDist - o;
   463     return ed + sameAxisDist + 2 * otherAxisDist - o;
   401 }
   464 }
       
   465