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

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: Rebased once again to master, fixed layout test. Created 6 years, 8 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 c8f4a75056a9cf6df2eb42042e18e2a32750d25b..acbce0fa8be01fe5a9221b8e5f7db4a5261ce1a1 100644
--- a/Source/core/page/FocusController.cpp
+++ b/Source/core/page/FocusController.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2013 Opera Software ASA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -57,6 +58,8 @@
#include "core/page/SpatialNavigation.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/RenderLayer.h"
+#include "core/rendering/RenderObject.h"
+#include "core/rendering/style/StyleNavigationValue.h"
namespace WebCore {
@@ -919,4 +922,80 @@ bool FocusController::advanceFocusDirectionally(FocusType type)
return consumed;
}
+bool FocusController::handleCSSFocusNavigation(FocusType type)
+{
+ DEFINE_STATIC_LOCAL(AtomicString, Current, ("current"));
fs 2014/04/14 12:32:01 Maybe make this 'targetCurrent' or 'frameTargetCur
Krzysztof Olczyk 2014/04/17 13:48:40 Done.
+ DEFINE_STATIC_LOCAL(AtomicString, Root, ("root"));
+
+ if (!focusedOrMainFrame()->isLocalFrame())
+ return false;
+
+ LocalFrame* currentFrame = toLocalFrame(focusedOrMainFrame());
+ ASSERT(currentFrame);
fs 2014/04/14 12:32:01 Already dereference focusedOrMainFrame() above.
Krzysztof Olczyk 2014/04/17 13:48:40 Done.
+
+ Document* focusedDocument = currentFrame->document();
+ if (!focusedDocument)
+ return false;
+
+ Element* focused = focusedDocument->focusedElement();
+ RenderObject* renderer = focused ? focused->renderer() : 0;
+ if (!renderer)
+ return false;
+
+ StyleNavigationValue value;
+
+ if (StyleNavigationData* navigationData = renderer->style()->navigation()) {
+ switch (type) {
+ case FocusTypeForward:
+ case FocusTypeBackward:
+ return false;
+ case FocusTypeUp:
+ value = navigationData->up();
+ break;
+ case FocusTypeDown:
+ value = navigationData->down();
+ break;
+ case FocusTypeLeft:
+ value = navigationData->left();
+ break;
+ case FocusTypeRight:
+ value = navigationData->right();
+ break;
+ case FocusTypeNone:
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ }
+
+ if (value.id().isNull() || value.isAuto())
fs 2014/04/14 12:32:01 When will id() be the nullAtom?
Krzysztof Olczyk 2014/04/17 13:48:40 Done.
+ 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().stopAutoscroll();
+
+ if (target == Current)
+ targetFrame = currentFrame;
+ else if (target == Root)
+ targetFrame = currentFrame->tree().top();
+ else
+ targetFrame = currentFrame->tree().find(target);
+
+ if (!targetFrame)
+ return false;
+
+ Element* targetElement = targetFrame->document()->getElementById(value.id());
+
+ if (!targetElement)
+ return false;
+ // If it's same with the current focused, it should be consumed.
fs 2014/04/14 12:32:01 s/same with the current/the same as the currently/
Krzysztof Olczyk 2014/04/17 13:48:40 Done.
+ if (focused == targetElement)
+ return true;
+
+ return setFocusedElement(targetElement, targetFrame);
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698