diff -r c8a366e56285 -r 60c5402cb945 webengine/osswebengine/WebKit/s60/misc/WebTabbedNavigation.cpp --- a/webengine/osswebengine/WebKit/s60/misc/WebTabbedNavigation.cpp Thu Sep 24 12:53:48 2009 +0300 +++ b/webengine/osswebengine/WebKit/s60/misc/WebTabbedNavigation.cpp Mon Oct 26 08:28:45 2009 +0200 @@ -81,14 +81,6 @@ void WebTabbedNavigation::updateCursorPosition(const TPoint& pos) { m_focusPosition = pos; - WebFrame* frame = StaticObjectsContainer::instance()->webCursor()->getFrameAtPoint(pos); - TPoint point(frame->frameView()->viewCoordsInFrameCoords(pos)); - - Element* node = core(frame)->document()->elementFromPoint(point.iX, point.iY); - if (node->isFocusable() && !node->hasTagName(iframeTag) && !node->hasTagName(frameTag)) - m_webView->page()->focusController()->setFocusedNode(node, core(frame)); - else - m_webView->page()->focusController()->setFocusedNode(NULL, core(frame)); m_selectedElementRect.SetRect(pos.iX, pos.iY, pos.iX + 1, pos.iY + 1); } @@ -101,88 +93,202 @@ m_focusPosition = StaticObjectsContainer::instance()->webCursor()->position(); } -bool WebTabbedNavigation::navigate(int horizontalDir, int verticalDir) + +void WebTabbedNavigation::resetNavigationIfNeeded(TPoint& contentPos, TSize& contentSize, + Frame* focusedFrame, int horizontalDir, int verticalDir) { - if (handleSelectElementScrolling(m_webView, verticalDir)) { - StaticObjectsContainer::instance()->webCursor()->cursorUpdate(true); - return true; - } - // DOM can be changed so check if we are still inside the document - // If not reset tabbed navigation parameters to the closest point in document. - TSize contentSize = m_webView->mainFrame()->frameView()->contentSize(); - TPoint contentPos = m_webView->mainFrame()->frameView()->contentPos(); - TRect docRect = TRect(contentPos, contentSize - contentPos); + TPoint docBrViewCoord = kit(focusedFrame)->frameView()->frameCoordsInViewCoords( + TPoint(contentSize.iWidth, contentSize.iHeight)); + TRect docRect = TRect(TPoint(0,0), docBrViewCoord); if (!docRect.Contains(m_focusPosition)) { TInt viewW = m_webView->Rect().Width(); TInt viewH = m_webView->Rect().Height(); - if (m_focusPosition.iX > contentSize.iWidth || - m_focusPosition.iX < contentPos.iX) { + if (m_focusPosition.iX > contentSize.iWidth) { m_focusPosition.iX = (horizontalDir == -1) ? contentPos.iX + viewW : contentPos.iX; } - if (m_focusPosition.iY > contentSize.iHeight || - m_focusPosition.iY < contentPos.iY) { + if (m_focusPosition.iY > contentSize.iHeight) { m_focusPosition.iY = (verticalDir == -1) ? contentPos.iY + viewH : contentPos.iY; } - - m_selectedElementRect.SetRect(m_focusPosition.iX, m_focusPosition.iY, m_focusPosition.iX, m_focusPosition.iY); + + m_selectedElementRect.SetRect(m_focusPosition.iX, m_focusPosition.iY, + m_focusPosition.iX, m_focusPosition.iY); m_node = NULL; } +} + + +TPoint WebTabbedNavigation::focusPointFromFocusedNode(Frame* frame, int horizontalDir, int verticalDir) +{ + TPoint oldFocusPoint(m_focusPosition); + TPoint focusPosition(m_focusPosition); + TRect selectedElementRect(m_selectedElementRect); - bool ret = m_firstNavigationOnPage; - Frame* focusedFrame = m_webView->page()->focusController()->focusedFrame(); - if (focusedFrame == NULL) focusedFrame = m_webView->page()->mainFrame(); - if (focusedFrame->document()) { - Node* focusNode = focusedFrame->document()->focusedNode(); - if (focusNode) { - m_node = focusNode; - m_selectedElementRect = focusNode->getRect().Rect(); - Frame* frame = focusNode->document()->frame(); - m_selectedElementRect = TRect(kit(frame)->frameView()->frameCoordsInViewCoords(m_selectedElementRect.iTl), - kit(frame)->frameView()->frameCoordsInViewCoords(m_selectedElementRect.iBr)); + if (frame->document()) { + Node* focusedNode = frame->document()->focusedNode(); + if (focusedNode) { + m_node = focusedNode; + selectedElementRect = focusedNode->getRect().Rect(); + Frame* frame = focusedNode->document()->frame(); + selectedElementRect = kit(frame)->frameView()->frameCoordsInViewCoords(selectedElementRect); + + // Move the focus to the visible edge of the current object + TRect elemVisibleRect = selectedElementRect; + if (elemVisibleRect.Intersects(m_webView->Rect())) { + + elemVisibleRect.Intersection(m_webView->Rect()); + if (horizontalDir == -1) { + focusPosition.iX = elemVisibleRect.iTl.iX; + } + else if (horizontalDir == 1) { + focusPosition.iX = elemVisibleRect.iBr.iX; + } + + if (verticalDir == -1) { + focusPosition.iY = elemVisibleRect.iTl.iY; + } + else if (verticalDir == 1) { + focusPosition.iY = elemVisibleRect.iBr.iY; + } + + if ((verticalDir == 0) && (horizontalDir == 0)) { + focusPosition = elemVisibleRect.Center(); + } + m_focusPosition = focusPosition; + } + m_selectedElementRect = selectedElementRect; } } - TPoint oldFocusPoint(m_focusPosition); - // Move the focus to the edge of the current object + return oldFocusPoint; +} + + +void WebTabbedNavigation::calcSearchViewRect(int horizontalDir, int verticalDir, TRect& view) +{ + + TPoint br; + TPoint viewBr = m_webView->Rect().iBr; + br.iX = viewBr.iX * KMaxJumpPercent / m_webView->scalingFactor(); + br.iY = viewBr.iY * KMaxJumpPercent / m_webView->scalingFactor(); + // define the view rect where we are looking for a match + int x, y; if (horizontalDir == -1) { - m_focusPosition.iX = m_selectedElementRect.iTl.iX; + view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY - br.iY, + m_focusPosition.iX , m_focusPosition.iY + br.iY); } else if (horizontalDir == 1) { - m_focusPosition.iX = m_selectedElementRect.iBr.iX; + view.SetRect(m_focusPosition.iX, m_focusPosition.iY - br.iY, + m_focusPosition.iX + br.iX, m_focusPosition.iY + br.iY); } - if (verticalDir == -1) { - m_focusPosition.iY = m_selectedElementRect.iTl.iY; + else if (verticalDir == -1) { + view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY - br.iY, + m_focusPosition.iX + br.iX, m_focusPosition.iY); } else if (verticalDir == 1) { - m_focusPosition.iY = m_selectedElementRect.iBr.iY; + view.SetRect(m_focusPosition.iX - br.iX, m_focusPosition.iY, + m_focusPosition.iX + br.iX, m_focusPosition.iY + br.iY); } - wkDebug()<<"WebTabbedNavigation::navigate. x = "<(e->renderer()); - HTMLSelectElement* selectElement = static_cast( e ); - IntRect itemRect = render->itemRect(0, 0, 0); - TPoint cursorPoint(StaticObjectsContainer::instance()->webCursor()->position()); - int gap = (20 * m_webView->scalingFactor()) / 100; - cursorPoint.iX = max(m_focusPosition.iX, m_selectedElementRect.iTl.iX + gap); - cursorPoint.iX = std::min(cursorPoint.iX, m_selectedElementRect.iBr.iX - gap); - if (verticalDir == -1) { - cursorPoint.iY -= (itemRect.height() * m_webView->scalingFactor()) / 125; - } - if (cursorPoint != StaticObjectsContainer::instance()->webCursor()->position()) { - StaticObjectsContainer::instance()->webCursor()->setPosition(cursorPoint); - } - } - } - } - TPointerEvent event; - event.iPosition = StaticObjectsContainer::instance()->webCursor()->position(); - event.iModifiers = 0; - event.iType = TPointerEvent::EMove; - core(m_webView->mainFrame())->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event)); - wkDebug()<<"Focus position x = "<(e->renderer()); + HTMLSelectElement* selectElement = static_cast( e ); + TRect itemRect = render->itemRect(0, 0, render->indexOffset()).Rect(); + TRect itemRectViewCoord = fv->frameCoordsInViewCoords(itemRect); + itemRectViewCoord.Move(m_selectedElementRect.iTl); + itemRectViewCoord.Intersection(fv->topView()->Rect()); + + TPoint cursorPoint = itemRect.Center() + m_selectedElementRect.iTl; + if (cursorPoint != cursor->position()) { + cursor->setPosition(cursorPoint); } } } - StaticObjectsContainer::instance()->webCursor()->cursorUpdate(true); - return ret; } bool WebTabbedNavigation::selectNode(int horizontalDir, int verticalDir, TRect& selectedRect, TRect& newNodeRect, TPoint& selectedPoint, TPoint& newFocusPoint) @@ -308,7 +371,7 @@ } int selectedDist = distanceFunction(horizontalDir, verticalDir, selectedRect, selectedPoint); int newDist = distanceFunction(horizontalDir, verticalDir, newNodeRect, newFocusPoint); - wkDebug()<<"WebTabbedNavigation::selectNode. selected x = "<