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

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: Added tests Created 7 years, 4 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 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "core/page/Chrome.h" 48 #include "core/page/Chrome.h"
49 #include "core/page/EditorClient.h" 49 #include "core/page/EditorClient.h"
50 #include "core/page/EventHandler.h" 50 #include "core/page/EventHandler.h"
51 #include "core/page/Frame.h" 51 #include "core/page/Frame.h"
52 #include "core/page/FrameTree.h" 52 #include "core/page/FrameTree.h"
53 #include "core/page/FrameView.h" 53 #include "core/page/FrameView.h"
54 #include "core/page/Page.h" 54 #include "core/page/Page.h"
55 #include "core/page/Settings.h" 55 #include "core/page/Settings.h"
56 #include "core/page/SpatialNavigation.h" 56 #include "core/page/SpatialNavigation.h"
57 #include "core/rendering/HitTestResult.h" 57 #include "core/rendering/HitTestResult.h"
58 #include "core/rendering/RenderObject.h"
59 #include "core/rendering/style/StyleNavigationValue.h"
58 60
59 namespace WebCore { 61 namespace WebCore {
60 62
61 using namespace HTMLNames; 63 using namespace HTMLNames;
62 using namespace std; 64 using namespace std;
63 65
64 FocusNavigationScope::FocusNavigationScope(TreeScope* treeScope) 66 FocusNavigationScope::FocusNavigationScope(TreeScope* treeScope)
65 : m_rootTreeScope(treeScope) 67 : m_rootTreeScope(treeScope)
66 { 68 {
67 ASSERT(treeScope); 69 ASSERT(treeScope);
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 consumed = advanceFocusDirectionallyInContainer(container, startingRect, direction); 866 consumed = advanceFocusDirectionallyInContainer(container, startingRect, direction);
865 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */); 867 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */);
866 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct ion, container); 868 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct ion, container);
867 if (container && container->isDocumentNode()) 869 if (container && container->isDocumentNode())
868 toDocument(container)->updateLayoutIgnorePendingStylesheets(); 870 toDocument(container)->updateLayoutIgnorePendingStylesheets();
869 } while (!consumed && container); 871 } while (!consumed && container);
870 872
871 return consumed; 873 return consumed;
872 } 874 }
873 875
876 bool FocusController::handleCSSFocusNavigation(FocusDirection direction)
877 {
878 DEFINE_STATIC_LOCAL(AtomicString, Current, ("current"));
879 DEFINE_STATIC_LOCAL(AtomicString, Root, ("root"));
880
881 Frame* currentFrame = focusedOrMainFrame();
882 ASSERT(currentFrame);
883
884 Document* focusedDocument = currentFrame->document();
885 if (!focusedDocument)
886 return false;
887
888 Element* focused = focusedDocument->focusedElement();
889 RenderObject* renderer = focused ? focused->renderer() : 0;
890 if (!renderer)
891 return false;
892
893 StyleNavigationValue value;
894 switch (direction) {
895 case FocusDirectionForward:
896 case FocusDirectionBackward:
897 return false;
898 case FocusDirectionUp:
899 value = renderer->style()->navUp();
900 break;
901 case FocusDirectionDown:
902 value = renderer->style()->navDown();
903 break;
904 case FocusDirectionLeft:
905 value = renderer->style()->navLeft();
906 break;
907 case FocusDirectionRight:
908 value = renderer->style()->navRight();
909 break;
910 case FocusDirectionNone:
911 default:
912 ASSERT_NOT_REACHED();
913 break;
914 }
915
916 if (value.id().isNull() || value.isAuto())
917 return false;
918
919 const AtomicString& target = value.target();
920 Frame* targetFrame = 0;
921
922 // If we were in the autoscroll/panScroll mode we want to stop it.
923 currentFrame->eventHandler()->stopAutoscrollTimer();
924
925 if (target == Current)
926 targetFrame = currentFrame;
927 else if (target == Root)
928 targetFrame = currentFrame->tree()->top();
929 else
930 targetFrame = currentFrame->tree()->find(target);
931
932 if (!targetFrame)
933 return false;
934
935 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.
936 if (!anchor)
937 return false;
938 // If it's same with the current focused, it should be consumed.
939 if (focused == anchor)
940 return true;
941
942 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.
943
944 bool successfullyFocused = setFocusedElement(anchor, targetFrame);
945 if (successfullyFocused)
946 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.
947
948 return true;
949 }
950
874 } // namespace WebCore 951 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698