Index: Source/core/page/FocusController.cpp |
diff --git a/Source/core/page/FocusController.cpp b/Source/core/page/FocusController.cpp |
index acafdb1464b72aaf6840b6868de8dab332a6b34f..5e8c471dee5cfcfc90b1f4afeebf93f451dd032e 100644 |
--- a/Source/core/page/FocusController.cpp |
+++ b/Source/core/page/FocusController.cpp |
@@ -54,6 +54,8 @@ |
#include "core/page/Settings.h" |
#include "core/page/SpatialNavigation.h" |
#include "core/rendering/HitTestResult.h" |
+#include "core/rendering/RenderObject.h" |
+#include "core/rendering/style/StyleNavigationValue.h" |
namespace WebCore { |
@@ -869,4 +871,80 @@ bool FocusController::advanceFocusDirectionally(FocusDirection direction, Keyboa |
return consumed; |
} |
+bool FocusController::handleCSSFocusNavigation(FocusDirection direction) |
+{ |
+ DEFINE_STATIC_LOCAL(AtomicString, Current, ("current")); |
+ DEFINE_STATIC_LOCAL(AtomicString, Root, ("root")); |
+ |
+ Frame* curFrame = focusedOrMainFrame(); |
esprehn
2013/06/20 19:45:10
frame, or currentFrame. No abbreviations.
Krzysztof Olczyk
2013/07/22 14:14:16
Done.
|
+ ASSERT(curFrame); |
+ |
+ Document* focusedDocument = curFrame->document(); |
+ if (!focusedDocument) |
+ return false; |
+ |
+ Node* focusedNode = focusedDocument->focusedNode(); |
+ RenderObject* renderer = focusedNode ? focusedNode->renderer() : 0; |
+ if (!renderer) |
+ return false; |
+ |
+ StyleNavigationValue value; |
+ switch (direction) { |
+ case FocusDirectionForward: |
+ case FocusDirectionBackward: |
+ return false; |
+ case FocusDirectionUp: |
+ value = renderer->style()->navUp(); |
+ break; |
+ case FocusDirectionDown: |
+ value = renderer->style()->navDown(); |
+ break; |
+ case FocusDirectionLeft: |
+ value = renderer->style()->navLeft(); |
+ break; |
+ case FocusDirectionRight: |
+ value = renderer->style()->navRight(); |
+ break; |
+ case FocusDirectionNone: |
+ default: |
+ ASSERT_NOT_REACHED(); |
+ break; |
+ } |
+ |
+ if (value.id().isNull() || value.isAuto()) |
+ return false; |
+ |
+ const AtomicString& target = value.target(); |
+ Frame* targetFrame = 0; |
+ |
+ // If we were in the autoscroll/panScroll mode we want to stop it. |
+ curFrame->eventHandler()->stopAutoscrollTimer(); |
+ |
+ if (target == Current) |
+ targetFrame = curFrame; |
+ else if (target == Root) |
+ targetFrame = curFrame->tree()->top(); |
+ else |
+ targetFrame = curFrame->tree()->find(target); |
+ |
+ // TODO:// which one is right? |
esprehn
2013/06/20 19:45:10
FIXME:, also you have extra //
Krzysztof Olczyk
2013/07/22 14:14:16
Done.
|
+ if (!targetFrame) |
+ return false; // targetFrame = curFrame; |
+ |
+ Element* anchorNode = targetFrame->document()->findAnchor(value.id().string()); |
+ if (!anchorNode) |
+ return false; |
+ // If it's same with the current focused, it should be consumed. |
+ if (focusedNode == anchorNode) |
+ return true; |
+ |
+ anchorNode->scrollIntoViewIfNeeded(false); |
+ |
+ bool successfullyFocused = setFocusedNode(anchorNode, targetFrame); |
+ if (successfullyFocused) |
+ m_page->chrome().focusedNodeChanged(anchorNode); |
+ |
+ return true; |
+} |
+ |
} // namespace WebCore |