[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

yael.aharon at nokia.com yael.aharon at nokia.com
Wed Dec 22 16:25:12 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit a886edfb11d17a7d58cce2788d73c47fff336fab
Author: yael.aharon at nokia.com <yael.aharon at nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Nov 23 12:57:17 2010 +0000

    2010-11-23  Yael Aharon  <yael.aharon at nokia.com>
    
            Reviewed by Antonio Gomes.
    
            Spatial Navigation: Code cleanup
            https://bugs.webkit.org/show_bug.cgi?id=49442
    
            Remove code that is not used anymore after http://trac.webkit.org/changeset/72522.
            Added const to canBeScrolledIntoView.
            No new tests because this is only code cleanup.
    
            * page/FocusController.cpp:
            * page/FocusController.h:
            * page/SpatialNavigation.cpp:
            (WebCore::canBeScrolledIntoView):
            * page/SpatialNavigation.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72596 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index a1f72a8..ccc9bc5 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,20 @@
+2010-11-23  Yael Aharon  <yael.aharon at nokia.com>
+
+        Reviewed by Antonio Gomes.
+
+        Spatial Navigation: Code cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=49442
+
+        Remove code that is not used anymore after http://trac.webkit.org/changeset/72522.
+        Added const to canBeScrolledIntoView.
+        No new tests because this is only code cleanup.
+
+        * page/FocusController.cpp:
+        * page/FocusController.h:
+        * page/SpatialNavigation.cpp:
+        (WebCore::canBeScrolledIntoView):
+        * page/SpatialNavigation.h:
+
 2010-11-23  Jeremy Orlow  <jorlow at chromium.org>
 
         Reviewed by Steve Block.
diff --git a/WebCore/page/FocusController.cpp b/WebCore/page/FocusController.cpp
index dd999c6..d112f9a 100644
--- a/WebCore/page/FocusController.cpp
+++ b/WebCore/page/FocusController.cpp
@@ -292,197 +292,6 @@ bool FocusController::advanceFocusInDocumentOrder(FocusDirection direction, Keyb
     return true;
 }
 
-static void updateFocusCandidateInSameContainer(const FocusCandidate& candidate, FocusCandidate& closest)
-{
-    if (closest.isNull()) {
-        closest = candidate;
-        return;
-    }
-
-    if (candidate.alignment == closest.alignment) {
-        if (candidate.distance < closest.distance)
-            closest = candidate;
-        return;
-    }
-
-    if (candidate.alignment > closest.alignment)
-        closest = candidate;
-}
-
-static void updateFocusCandidateIfCloser(Node* focusedNode, const FocusCandidate& candidate, FocusCandidate& closest)
-{
-    // First, check the common case: neither candidate nor closest are
-    // inside scrollable content, then no need to care about enclosingScrollableBox
-    // heuristics or parent{Distance,Alignment}, but only distance and alignment.
-    if (!candidate.inScrollableContainer() && !closest.inScrollableContainer()) {
-        updateFocusCandidateInSameContainer(candidate, closest);
-        return;
-    }
-
-    bool sameContainer = candidate.document() == closest.document() && candidate.enclosingScrollableBox == closest.enclosingScrollableBox;
-
-    // Second, if candidate and closest are in the same "container" (i.e. {i}frame or any
-    // scrollable block element), we can handle them as common case.
-    if (sameContainer) {
-        updateFocusCandidateInSameContainer(candidate, closest);
-        return;
-    }
-
-    // Last, we are considering moving to a candidate located in a different enclosing
-    // scrollable box than closest.
-    bool isInInnerDocument = !isInRootDocument(focusedNode);
-
-    bool sameContainerAsCandidate = isInInnerDocument ? focusedNode->document() == candidate.document() :
-        focusedNode->isDescendantOf(candidate.enclosingScrollableBox);
-
-    bool sameContainerAsClosest = isInInnerDocument ? focusedNode->document() == closest.document() :
-        focusedNode->isDescendantOf(closest.enclosingScrollableBox);
-
-    // sameContainerAsCandidate and sameContainerAsClosest are mutually exclusive.
-    ASSERT(!(sameContainerAsCandidate && sameContainerAsClosest));
-
-    if (sameContainerAsCandidate) {
-        closest = candidate;
-        return;
-    }
-
-    if (sameContainerAsClosest) {
-        // Nothing to be done.
-        return;
-    }
-
-    // NOTE: !sameContainerAsCandidate && !sameContainerAsClosest
-    // If distance is shorter, and we are talking about scrollable container,
-    // lets compare parent distance and alignment before anything.
-    if (candidate.distance < closest.distance) {
-        if (candidate.alignment >= closest.parentAlignment
-         || candidate.parentAlignment == closest.parentAlignment) {
-            closest = candidate;
-            return;
-        }
-
-    } else if (candidate.parentDistance < closest.distance) {
-        if (candidate.parentAlignment >= closest.alignment) {
-            closest = candidate;
-            return;
-        }
-    }
-}
-
-void FocusController::findFocusableNodeInDirection(Node* outer, Node* focusedNode,
-                                                   FocusDirection direction, KeyboardEvent* event,
-                                                   FocusCandidate& closest, const FocusCandidate& candidateParent)
-{
-    ASSERT(outer);
-    ASSERT(candidateParent.isNull()
-        || candidateParent.node->hasTagName(frameTag)
-        || candidateParent.node->hasTagName(iframeTag)
-        || isScrollableContainerNode(candidateParent.node));
-
-    // Walk all the child nodes and update closest if we find a nearer node.
-    Node* node = outer;
-    while (node) {
-
-        // Inner documents case.
-        if (node->isFrameOwnerElement()) {
-            deepFindFocusableNodeInDirection(node, focusedNode, direction, event, closest);
-
-        // Scrollable block elements (e.g. <div>, etc) case.
-        } else if (isScrollableContainerNode(node)) {
-            deepFindFocusableNodeInDirection(node, focusedNode, direction, event, closest);
-            node = node->traverseNextSibling();
-            continue;
-
-        } else if (node != focusedNode && node->isKeyboardFocusable(event)) {
-            FocusCandidate candidate(node);
-
-            // There are two ways to identify we are in a recursive call from deepFindFocusableNodeInDirection
-            // (i.e. processing an element in an iframe, frame or a scrollable block element):
-
-            // 1) If candidateParent is not null, and it holds the distance and alignment data of the
-            // parent container element itself;
-            // 2) Parent of outer is <frame> or <iframe>;
-            // 3) Parent is any other scrollable block element.
-            if (!candidateParent.isNull()) {
-                candidate.parentAlignment = candidateParent.alignment;
-                candidate.parentDistance = candidateParent.distance;
-                candidate.enclosingScrollableBox = candidateParent.node;
-
-            } else if (!isInRootDocument(outer)) {
-                if (Document* document = static_cast<Document*>(outer->parentNode()))
-                    candidate.enclosingScrollableBox = static_cast<Node*>(document->ownerElement());
-
-            } else if (isScrollableContainerNode(outer->parentNode()))
-                candidate.enclosingScrollableBox = outer->parentNode();
-
-            // Get distance and alignment from current candidate.
-            distanceDataForNode(direction, focusedNode, candidate);
-
-            // Bail out if distance is maximum.
-            if (candidate.distance == maxDistance()) {
-                node = node->traverseNextNode(outer->parentNode());
-                continue;
-            }
-
-            updateFocusCandidateIfCloser(focusedNode, candidate, closest);
-        }
-
-        node = node->traverseNextNode(outer->parentNode());
-    }
-}
-
-void FocusController::deepFindFocusableNodeInDirection(Node* container, Node* focusedNode,
-                                                       FocusDirection direction, KeyboardEvent* event,
-                                                       FocusCandidate& closest)
-{
-    ASSERT(container->hasTagName(frameTag)
-        || container->hasTagName(iframeTag)
-        || isScrollableContainerNode(container));
-
-    // Track if focusedNode is a descendant of the current container node being processed.
-    bool descendantOfContainer = false;
-    Node* firstChild = 0;
-
-    // Iframe or Frame.
-    if (container->hasTagName(frameTag) || container->hasTagName(iframeTag)) {
-
-        HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(container);
-        if (!owner->contentFrame())
-            return;
-
-        Document* innerDocument = owner->contentFrame()->document();
-        if (!innerDocument)
-            return;
-
-        descendantOfContainer = isNodeDeepDescendantOfDocument(focusedNode, innerDocument);
-        firstChild = innerDocument->firstChild();
-
-    // Scrollable block elements (e.g. <div>, etc)
-    } else if (isScrollableContainerNode(container)) {
-
-        firstChild = container->firstChild();
-        descendantOfContainer = focusedNode->isDescendantOf(container);
-    }
-
-    if (descendantOfContainer) {
-        findFocusableNodeInDirection(firstChild, focusedNode, direction, event, closest);
-        return;
-    }
-
-    // Check if the current container element itself is a good candidate
-    // to move focus to. If it is, then we traverse its inner nodes.
-    FocusCandidate candidateParent = FocusCandidate(container);
-    distanceDataForNode(direction, focusedNode, candidateParent);
-
-    // Bail out if distance is maximum.
-    if (candidateParent.distance == maxDistance())
-        return;
-
-    // FIXME: Consider alignment?
-    if (candidateParent.distance < closest.distance)
-        findFocusableNodeInDirection(firstChild, focusedNode, direction, event, closest, candidateParent);
-}
-
 static bool relinquishesEditingFocus(Node *node)
 {
     ASSERT(node);
diff --git a/WebCore/page/FocusController.h b/WebCore/page/FocusController.h
index 883c993..be51c77 100644
--- a/WebCore/page/FocusController.h
+++ b/WebCore/page/FocusController.h
@@ -63,11 +63,6 @@ private:
     bool advanceFocusDirectionally(FocusDirection, KeyboardEvent*);
     bool advanceFocusInDocumentOrder(FocusDirection, KeyboardEvent*, bool initialFocus);
 
-    void findFocusableNodeInDirection(Node* outter, Node*, FocusDirection, KeyboardEvent*,
-                                      FocusCandidate& closestFocusCandidate,
-                                      const FocusCandidate& parentCandidate = FocusCandidate());
-    void deepFindFocusableNodeInDirection(Node* container, Node* focused, FocusDirection, KeyboardEvent*, FocusCandidate&);
-
     bool advanceFocusDirectionallyInContainer(Node* container, const IntRect& startingRect, FocusDirection, KeyboardEvent*);
     void findFocusCandidateInContainer(Node* container, const IntRect& startingRect, FocusDirection, KeyboardEvent*, FocusCandidate& closest);
 
diff --git a/WebCore/page/SpatialNavigation.cpp b/WebCore/page/SpatialNavigation.cpp
index 218fca3..1a7a407 100644
--- a/WebCore/page/SpatialNavigation.cpp
+++ b/WebCore/page/SpatialNavigation.cpp
@@ -41,15 +41,12 @@
 
 namespace WebCore {
 
-static long long spatialDistance(FocusDirection, const IntRect&, const IntRect&);
-static IntRect renderRectRelativeToRootDocument(RenderObject*);
 static RectsAlignment alignmentForRects(FocusDirection, const IntRect&, const IntRect&, const IntSize& viewSize);
 static bool areRectsFullyAligned(FocusDirection, const IntRect&, const IntRect&);
 static bool areRectsPartiallyAligned(FocusDirection, const IntRect&, const IntRect&);
 static bool areRectsMoreThanFullScreenApart(FocusDirection direction, const IntRect& curRect, const IntRect& targetRect, const IntSize& viewSize);
 static bool isRectInDirection(FocusDirection, const IntRect&, const IntRect&);
 static void deflateIfOverlapped(IntRect&, IntRect&);
-static bool checkNegativeCoordsForNode(Node*, const IntRect&);
 static IntRect rectToAbsoluteCoordinates(Frame* initialFrame, const IntRect& rect);
 static void entryAndExitPointsForDirection(FocusDirection direction, const IntRect& startingRect, const IntRect& potentialRect, IntPoint& exitPoint, IntPoint& entryPoint);
 
@@ -70,88 +67,6 @@ bool isSpatialNavigationEnabled(const Frame* frame)
     return (frame && frame->settings() && frame->settings()->isSpatialNavigationEnabled());
 }
 
-void distanceDataForNode(FocusDirection direction, Node* start, FocusCandidate& candidate)
-{
-    RenderObject* startRender = start->renderer();
-    if (!startRender) {
-        candidate.distance = maxDistance();
-        return;
-    }
-
-    RenderObject* destRender = candidate.node->renderer();
-    if (!destRender) {
-        candidate.distance = maxDistance();
-        return;
-    }
-
-    IntRect curRect = renderRectRelativeToRootDocument(startRender);
-    IntRect targetRect  = renderRectRelativeToRootDocument(destRender);
-
-    // The bounding rectangle of two consecutive nodes can overlap. In such cases,
-    // deflate both.
-    deflateIfOverlapped(curRect, targetRect);
-
-    // If empty rects or negative width or height, bail out.
-    if (curRect.isEmpty() || targetRect.isEmpty()
-     || targetRect.width() <= 0 || targetRect.height() <= 0) {
-        candidate.distance = maxDistance();
-        return;
-    }
-
-    // Negative coordinates can be used if node is scrolled up offscreen.
-    if (!checkNegativeCoordsForNode(start, curRect)) {
-        candidate.distance = maxDistance();
-        return;
-    }
-
-    if (!checkNegativeCoordsForNode(candidate.node, targetRect)) {
-        candidate.distance = maxDistance();
-        return;
-    }
-
-    if (!isRectInDirection(direction, curRect, targetRect)) {
-        candidate.distance = maxDistance();
-        return;
-    }
-
-    // The distance between two nodes is not to be considered alone when evaluating/looking
-    // for the best focus candidate node. Alignment of rects can be also a good point to be
-    // considered in order to make the algorithm to behavior in a more intuitive way.
-    IntSize viewSize = candidate.node->document()->page()->mainFrame()->view()->visibleContentRect().size();
-    candidate.alignment = alignmentForRects(direction, curRect, targetRect, viewSize);
-    candidate.distance = spatialDistance(direction, curRect, targetRect);
-}
-
-// FIXME: This function does not behave correctly with transformed frames.
-static IntRect renderRectRelativeToRootDocument(RenderObject* render)
-{
-    ASSERT(render && render->node());
-
-    IntRect rect = render->node()->getRect();
-
-    // In cases when the |render|'s associated node is in a scrollable inner
-    // document, we only consider its scrollOffset if it is not offscreen.
-    Node* node = render->node();
-    Document* mainDocument = node->document()->page()->mainFrame()->document();
-    bool considerScrollOffset = !(hasOffscreenRect(node) && node->document() != mainDocument);
-
-    if (considerScrollOffset) {
-        if (FrameView* frameView = render->node()->document()->view())
-            rect.move(-frameView->scrollOffset());
-    }
-
-    // Handle nested frames.
-    for (Frame* frame = render->document()->frame(); frame; frame = frame->tree()->parent()) {
-        if (Element* element = static_cast<Element*>(frame->ownerElement())) {
-            do {
-                rect.move(element->offsetLeft(), element->offsetTop());
-            } while ((element = element->offsetParent()));
-        }
-    }
-
-    return rect;
-}
-
 static RectsAlignment alignmentForRects(FocusDirection direction, const IntRect& curRect, const IntRect& targetRect, const IntSize& viewSize)
 {
     // If we found a node in full alignment, but it is too far away, ignore it.
@@ -328,118 +243,6 @@ static inline bool rightOf(const IntRect& a, const IntRect& b)
     return a.x() > b.right();
 }
 
-// * a = Current focused node's rect.
-// * b = Focus candidate node's rect.
-static long long spatialDistance(FocusDirection direction, const IntRect& a, const IntRect& b)
-{
-    int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
-
-    if (direction == FocusDirectionLeft) {
-        // #1  |--|
-        //
-        // #2  |--|  |--|
-        //
-        // #3  |--|
-
-        x1 = a.x();
-        x2 = b.right();
-
-        if (below(a, b)) {
-            // #1 The a rect is below b.
-            y1 = a.y();
-            y2 = b.bottom();
-        } else if (below(b, a)) {
-            // #3 The b rect is below a.
-            y1 = a.bottom();
-            y2 = b.y();
-        } else {
-            // #2 Both b and a share some common y's.
-            y1 = 0;
-            y2 = 0;
-        }
-    } else if (direction == FocusDirectionRight) {
-        //        |--|  #1
-        //
-        //  |--|  |--|  #2
-        //
-        //        |--|  #3
-
-        x1 = a.right();
-        x2 = b.x();
-
-        if (below(a, b)) {
-            // #1 The b rect is above a.
-            y1 = a.y();
-            y2 = b.bottom();
-        } else if (below(b, a)) {
-            // #3 The b rect is below a.
-            y1 = a.bottom();
-            y2 = b.y();
-        } else {
-            // #2 Both b and a share some common y's.
-            y1 = 0;
-            y2 = 0;
-        }
-    } else if (direction == FocusDirectionUp) {
-        //
-        //   #1    #2    #3
-        //
-        //  |--|  |--|  |--|
-        //
-        //        |--|
-
-        y1 = a.y();
-        y2 = b.bottom();
-
-        if (rightOf(a, b)) {
-            // #1 The b rect is to the left of a.
-            x1 = a.x();
-            x2 = b.right();
-        } else if (rightOf(b, a)) {
-            // #3 The b rect is to the right of a.
-            x1 = a.right();
-            x2 = b.x();
-        } else {
-            // #2 Both b and a share some common x's.
-            x1 = 0;
-            x2 = 0;
-        }
-    } else if (direction == FocusDirectionDown) {
-        //        |--|
-        //
-        //  |--|  |--|  |--|
-        //
-        //   #1    #2    #3
-
-        y1 = a.bottom();
-        y2 = b.y();
-
-        if (rightOf(a, b)) {
-            // #1 The b rect is to the left of a.
-            x1 = a.x();
-            x2 = b.right();
-        } else if (rightOf(b, a)) {
-            // #3 The b rect is to the right of a
-            x1 = a.right();
-            x2 = b.x();
-        } else {
-            // #2 Both b and a share some common x's.
-            x1 = 0;
-            x2 = 0;
-        }
-    }
-
-    long long dx = x1 - x2;
-    long long dy = y1 - y2;
-
-    long long distance = (dx * dx) + (dy * dy);
-
-    if (distance < 0)
-        distance *= -1;
-
-    return distance;
-}
-
 static bool isRectInDirection(FocusDirection direction, const IntRect& curRect, const IntRect& targetRect)
 {
     switch (direction) {
@@ -572,26 +375,6 @@ bool scrollInDirection(Node* container, FocusDirection direction)
     return false;
 }
 
-void scrollIntoView(Element* element)
-{
-    // NOTE: Element's scrollIntoView method could had been used here, but
-    // it is preferable to inflate |element|'s bounding rect a bit before
-    // scrolling it for accurate reason.
-    // Element's scrollIntoView method does not provide this flexibility.
-    IntRect bounds = element->getRect();
-    bounds.inflate(fudgeFactor());
-    element->renderer()->enclosingLayer()->scrollRectToVisible(bounds);
-}
-
-bool isInRootDocument(Node* node)
-{
-    if (!node)
-        return false;
-
-    Document* rootDocument = node->document()->page()->mainFrame()->document();
-    return node->document() == rootDocument;
-}
-
 static void deflateIfOverlapped(IntRect& a, IntRect& b)
 {
     if (!a.intersects(b) || a.contains(b) || b.contains(a))
@@ -607,26 +390,6 @@ static void deflateIfOverlapped(IntRect& a, IntRect& b)
         b.inflate(deflateFactor);
 }
 
-static bool checkNegativeCoordsForNode(Node* node, const IntRect& curRect)
-{
-    ASSERT(node || node->renderer());
-
-    if (curRect.x() >= 0 && curRect.y() >= 0)
-        return true;
-
-    bool canBeScrolled = false;
-
-    RenderObject* renderer = node->renderer();
-    for (; renderer; renderer = renderer->parent()) {
-        if (renderer->isBox() && toRenderBox(renderer)->canBeScrolledAndHasScrollableArea()) {
-            canBeScrolled = true;
-            break;
-        }
-    }
-
-    return canBeScrolled;
-}
-
 bool isScrollableContainerNode(const Node* node)
 {
     if (!node)
@@ -640,26 +403,6 @@ bool isScrollableContainerNode(const Node* node)
     return false;
 }
 
-bool isNodeDeepDescendantOfDocument(Node* node, Document* baseDocument)
-{
-    if (!node || !baseDocument)
-        return false;
-
-    bool descendant = baseDocument == node->document();
-
-    Element* currentElement = static_cast<Element*>(node);
-    while (!descendant) {
-        Element* documentOwner = currentElement->document()->ownerElement();
-        if (!documentOwner)
-            break;
-
-        descendant = documentOwner->document() == baseDocument;
-        currentElement = documentOwner;
-    }
-
-    return descendant;
-}
-
 Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection direction, Node* node)
 {
     ASSERT(node);
@@ -877,7 +620,7 @@ void distanceDataForNode(FocusDirection direction, FocusCandidate& current, Focu
     candidate.alignment = alignmentForRects(direction, currentRect, nodeRect, viewSize);
 }
 
-bool canBeScrolledIntoView(FocusDirection direction, FocusCandidate& candidate)
+bool canBeScrolledIntoView(FocusDirection direction, const FocusCandidate& candidate)
 {
     ASSERT(candidate.node && hasOffscreenRect(candidate.node));
     IntRect candidateRect = candidate.rect;
diff --git a/WebCore/page/SpatialNavigation.h b/WebCore/page/SpatialNavigation.h
index 2aa03b6..2700a9c 100644
--- a/WebCore/page/SpatialNavigation.h
+++ b/WebCore/page/SpatialNavigation.h
@@ -122,12 +122,9 @@ struct FocusCandidate {
     IntRect rect;
 };
 
-void distanceDataForNode(FocusDirection direction, Node* start, FocusCandidate& candidate);
 bool scrollInDirection(Frame*, FocusDirection);
 bool scrollInDirection(Node* container, FocusDirection);
-void scrollIntoView(Element*);
 bool hasOffscreenRect(Node*, FocusDirection direction = FocusDirectionNone);
-bool isInRootDocument(Node*);
 bool isScrollableContainerNode(const Node*);
 bool isNodeDeepDescendantOfDocument(Node*, Document*);
 Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection, Node* node);
@@ -136,7 +133,7 @@ bool canScrollInDirection(FocusDirection, const Frame*);
 IntRect nodeRectInAbsoluteCoordinates(Node*, bool ignoreBorder = false);
 IntRect frameRectInAbsoluteCoordinates(Frame*);
 void distanceDataForNode(FocusDirection, FocusCandidate& current, FocusCandidate& candidate);
-bool canBeScrolledIntoView(FocusDirection, FocusCandidate&);
+bool canBeScrolledIntoView(FocusDirection, const FocusCandidate&);
 IntRect virtualRectForDirection(FocusDirection, const IntRect& startingRect);
 } // namspace WebCore
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list