Spatial Navigation: make it work with focusable elements in overflow content
https://bugs.webkit.org/show_bug.cgi?id=36463

Reviewed by Simon Fraser and Kenneth Christiansen.
Patch by Antonio Gomes <tonikitoo@webkit.org>

WebCore:

This patch addresses the problem with Spatial Navigation. It currently does not
properly traverse scrollable contents, including scrollable div's. For this to work,
a new class member called scrollableEnclosingBox was introduced to FocusCandidate class which
keeps track of the current scrollable box Node wrapping a FocusCandidate.

To make use of enclosingScrollableBox of FocusCandidate, the DOM traversal routine
(FocusController::findNextFocusableInDirection) was changed as follows: when it
encounters a scrollable Node, each focusable node which is 'inner' keeps track of
the container reference. By the time a sibling of the scrollable Node is encountered,
there is no need to track this reference any more and the traversal algorithm continues
normally.

The common case is obviously that there is no scrollable container wrapping it.

updateFocusCandiditeIfCloser logic was also adapted to fit the need of the
newly introduced enclosingScrollableBox class member, getting simpler and more
easily maintainable.

Tests: fast/events/spatial-navigation/snav-div-scrollable-but-without-focusable-content.html
       fast/events/spatial-navigation/snav-clipped-overflow-content.html

* page/FocusController.cpp:
(WebCore::updateFocusCandidateInSameContainer):
(WebCore::updateFocusCandidateIfCloser):
(WebCore::FocusController::findFocusableNodeInDirection):
(WebCore::FocusController::deepFindFocusableNodeInDirection):
* page/SpatialNavigation.cpp:
(WebCore::isScrollableContainerNode):
* page/SpatialNavigation.h:
(WebCore::FocusCandidate::FocusCandidate):
(WebCore::FocusCandidate::inScrollableContainer):

LayoutTests:

* fast/events/spatial-navigation/snav-div-scrollable-but-without-focusable-content-expected.txt: Added.
* fast/events/spatial-navigation/snav-div-scrollable-but-without-focusable-content.html: Added.
* fast/events/spatial-navigation/snav-clipped-overflow-content-expected.txt: Added.
* fast/events/spatial-navigation/snav-clipped-overflow-content.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@61134 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/page/SpatialNavigation.cpp b/WebCore/page/SpatialNavigation.cpp
index 0239c39..9284e17 100644
--- a/WebCore/page/SpatialNavigation.cpp
+++ b/WebCore/page/SpatialNavigation.cpp
@@ -527,4 +527,17 @@
     return canBeScrolled;
 }
 
+bool isScrollableContainerNode(Node* node)
+{
+    if (!node)
+        return false;
+
+    if (RenderObject* renderer = node->renderer()) {
+        return (renderer->isBox() && toRenderBox(renderer)->canBeScrolledAndHasScrollableArea()
+             && node->hasChildNodes() && !node->isDocumentNode());
+    }
+
+    return false;
+}
+
 } // namespace WebCore