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

Side by Side 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: Fixed compilation error in mac and crash in linux/window that were reported by trybots. Created 6 years, 2 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nuanti Ltd. 3 * Copyright (C) 2008 Nuanti Ltd.
4 * Copyright (C) 2013, 2014 Opera Software ASA. All rights reserved.
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
7 * are met: 8 * are met:
8 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
13 * 14 *
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "core/html/HTMLTextFormControlElement.h" 51 #include "core/html/HTMLTextFormControlElement.h"
51 #include "core/page/Chrome.h" 52 #include "core/page/Chrome.h"
52 #include "core/page/ChromeClient.h" 53 #include "core/page/ChromeClient.h"
53 #include "core/page/EventHandler.h" 54 #include "core/page/EventHandler.h"
54 #include "core/page/FrameTree.h" 55 #include "core/page/FrameTree.h"
55 #include "core/page/Page.h" 56 #include "core/page/Page.h"
56 #include "core/frame/Settings.h" 57 #include "core/frame/Settings.h"
57 #include "core/page/SpatialNavigation.h" 58 #include "core/page/SpatialNavigation.h"
58 #include "core/rendering/HitTestResult.h" 59 #include "core/rendering/HitTestResult.h"
59 #include "core/rendering/RenderLayer.h" 60 #include "core/rendering/RenderLayer.h"
61 #include "core/rendering/RenderObject.h"
62 #include "core/rendering/style/StyleNavigationValue.h"
60 #include <limits> 63 #include <limits>
61 64
62 namespace blink { 65 namespace blink {
63 66
64 using namespace HTMLNames; 67 using namespace HTMLNames;
65 68
66 static inline bool isShadowInsertionPointFocusScopeOwner(Node& node) 69 static inline bool isShadowInsertionPointFocusScopeOwner(Node& node)
67 { 70 {
68 return isActiveShadowInsertionPoint(node) && toHTMLShadowElement(node).older ShadowRoot(); 71 return isActiveShadowInsertionPoint(node) && toHTMLShadowElement(node).older ShadowRoot();
69 } 72 }
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 927
925 return consumed; 928 return consumed;
926 } 929 }
927 930
928 void FocusController::trace(Visitor* visitor) 931 void FocusController::trace(Visitor* visitor)
929 { 932 {
930 visitor->trace(m_page); 933 visitor->trace(m_page);
931 visitor->trace(m_focusedFrame); 934 visitor->trace(m_focusedFrame);
932 } 935 }
933 936
937 bool FocusController::handleCSSFocusNavigation(FocusType type)
938 {
939 ASSERT(focusedOrMainFrame());
940 if (!focusedOrMainFrame()->isLocalFrame())
941 return false;
942
943 LocalFrame* currentFrame = toLocalFrame(focusedOrMainFrame());
944 Document* focusedDocument = currentFrame->document();
945 if (!focusedDocument)
946 return false;
947
948 Element* focused = focusedDocument->focusedElement();
949 RenderObject* renderer = focused ? focused->renderer() : 0;
950 if (!renderer)
951 return false;
952
953 StyleNavigationValue value;
954
955 switch (type) {
956 case FocusTypeForward:
957 case FocusTypeBackward:
958 return false;
959 case FocusTypeUp:
960 value = renderer->style()->navUp();
961 break;
962 case FocusTypeDown:
963 value = renderer->style()->navDown();
964 break;
965 case FocusTypeLeft:
966 value = renderer->style()->navLeft();
967 break;
968 case FocusTypeRight:
969 value = renderer->style()->navRight();
970 break;
971 case FocusTypeNone:
972 default:
973 ASSERT_NOT_REACHED();
974 break;
975 }
976
977 if (value.isAuto())
978 return false;
979
980 // If we were in the autoscroll/panScroll mode we want to stop it.
981 currentFrame->eventHandler().stopAutoscroll();
982
983 ENavigationTarget navigationTarget = value.navigationTarget();
984 Frame* targetFrame = 0;
985 if (navigationTarget == Current)
986 targetFrame = currentFrame;
987 else if (navigationTarget == Root)
988 targetFrame = currentFrame->tree().top();
989 else
990 targetFrame = currentFrame->tree().find(value.targetName());
991
992 if (!targetFrame || !targetFrame->isLocalFrame())
993 return false;
994
995 Element* targetElement = toLocalFrame(targetFrame)->document()->getElementBy Id(value.id());
996
997 if (!targetElement)
998 return false;
999
1000 // If it's the same as the current focused, it should be considered a valid navigation,
1001 // but there is no need to change focus.
1002 if (focused == targetElement)
1003 return true;
1004
1005 return setFocusedElement(targetElement, targetFrame);
1006 }
1007
934 } // namespace blink 1008 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698