Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Unified Diff: Source/core/page/FocusController.cpp

Issue 17450016: Implementation of CSS3 nav-up/down/left/right properties from CSS3 UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added tests Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/page/FocusController.cpp
diff --git a/Source/core/page/FocusController.cpp b/Source/core/page/FocusController.cpp
index 2d7fb6afddee2bff35ba272707c4c6396a97cb7d..ded762d21961cdc8b886dc6d5a8de8fcfd7b3c90 100644
--- a/Source/core/page/FocusController.cpp
+++ b/Source/core/page/FocusController.cpp
@@ -55,6 +55,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 {
@@ -871,4 +873,79 @@ bool FocusController::advanceFocusDirectionally(FocusDirection direction)
return consumed;
}
+bool FocusController::handleCSSFocusNavigation(FocusDirection direction)
+{
+ DEFINE_STATIC_LOCAL(AtomicString, Current, ("current"));
+ DEFINE_STATIC_LOCAL(AtomicString, Root, ("root"));
+
+ Frame* currentFrame = focusedOrMainFrame();
+ ASSERT(currentFrame);
+
+ Document* focusedDocument = currentFrame->document();
+ if (!focusedDocument)
+ return false;
+
+ Element* focused = focusedDocument->focusedElement();
+ RenderObject* renderer = focused ? focused->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.
+ currentFrame->eventHandler()->stopAutoscrollTimer();
+
+ if (target == Current)
+ targetFrame = currentFrame;
+ else if (target == Root)
+ targetFrame = currentFrame->tree()->top();
+ else
+ targetFrame = currentFrame->tree()->find(target);
+
+ if (!targetFrame)
+ return false;
+
+ Element* anchor = targetFrame->document()->findAnchor(value.id().string());
esprehn 2013/08/08 03:39:40 The spec doesn't seem to say we should find elemen
Krzysztof Olczyk 2013/12/04 13:56:50 Done.
+ if (!anchor)
+ return false;
+ // If it's same with the current focused, it should be consumed.
+ if (focused == anchor)
+ return true;
+
+ anchor->scrollIntoViewIfNeeded(false);
esprehn 2013/08/08 03:39:40 you shouldn't have to do this manually, doesn't th
Krzysztof Olczyk 2013/12/04 13:56:50 Done.
+
+ bool successfullyFocused = setFocusedElement(anchor, targetFrame);
+ if (successfullyFocused)
+ m_page->chrome().focusedNodeChanged(anchor);
esprehn 2013/08/08 03:39:40 This is done inside Document::setFocusedElement, I
Krzysztof Olczyk 2013/12/04 13:56:50 Done.
+
+ return true;
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698