OLD | NEW |
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 class ScopedFocusNavigation { | 74 class ScopedFocusNavigation { |
75 STACK_ALLOCATED(); | 75 STACK_ALLOCATED(); |
76 public: | 76 public: |
77 Element* currentElement() const; | 77 Element* currentElement() const; |
78 void setCurrentElement(Element*); | 78 void setCurrentElement(Element*); |
79 void moveToNext(); | 79 void moveToNext(); |
80 void moveToPrevious(); | 80 void moveToPrevious(); |
81 void moveToFirst(); | 81 void moveToFirst(); |
82 void moveToLast(); | 82 void moveToLast(); |
83 Element* owner() const; | 83 Element* owner() const; |
84 static ScopedFocusNavigation createScopedFocusNavigation(const Element& root
, const Element* current); | 84 static ScopedFocusNavigation createFor(const Element&); |
85 static ScopedFocusNavigation createScopedFocusNavigationForDocument(Document
&); | 85 static ScopedFocusNavigation createForDocument(Document&); |
86 static ScopedFocusNavigation ownedByNonFocusableFocusScopeOwner(Element&); | 86 static ScopedFocusNavigation ownedByNonFocusableFocusScopeOwner(Element&); |
87 static ScopedFocusNavigation ownedByShadowHost(const Element&); | 87 static ScopedFocusNavigation ownedByShadowHost(const Element&); |
88 static ScopedFocusNavigation ownedByShadowInsertionPoint(HTMLShadowElement&)
; | 88 static ScopedFocusNavigation ownedByShadowInsertionPoint(HTMLShadowElement&)
; |
89 static ScopedFocusNavigation ownedByHTMLSlotElement(const HTMLSlotElement&); | 89 static ScopedFocusNavigation ownedByHTMLSlotElement(const HTMLSlotElement&); |
90 static ScopedFocusNavigation ownedByIFrame(const HTMLFrameOwnerElement&); | 90 static ScopedFocusNavigation ownedByIFrame(const HTMLFrameOwnerElement&); |
91 | 91 |
92 private: | 92 private: |
93 ScopedFocusNavigation(TreeScope&, const Element*); | 93 ScopedFocusNavigation(TreeScope&, const Element*); |
94 ScopedFocusNavigation(HTMLSlotElement&, const Element*); | 94 ScopedFocusNavigation(HTMLSlotElement&, const Element*); |
95 RawPtrWillBeMember<ContainerNode> m_rootNode; | 95 RawPtrWillBeMember<ContainerNode> m_rootNode; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (m_rootNode->isShadowRoot()) { | 196 if (m_rootNode->isShadowRoot()) { |
197 ShadowRoot& shadowRoot = toShadowRoot(*m_rootNode); | 197 ShadowRoot& shadowRoot = toShadowRoot(*m_rootNode); |
198 return shadowRoot.isYoungest() ? shadowRoot.host() : shadowRoot.shadowIn
sertionPointOfYoungerShadowRoot(); | 198 return shadowRoot.isYoungest() ? shadowRoot.host() : shadowRoot.shadowIn
sertionPointOfYoungerShadowRoot(); |
199 } | 199 } |
200 // FIXME: Figure out the right thing for OOPI here. | 200 // FIXME: Figure out the right thing for OOPI here. |
201 if (Frame* frame = m_rootNode->document().frame()) | 201 if (Frame* frame = m_rootNode->document().frame()) |
202 return frame->deprecatedLocalOwner(); | 202 return frame->deprecatedLocalOwner(); |
203 return nullptr; | 203 return nullptr; |
204 } | 204 } |
205 | 205 |
206 ScopedFocusNavigation ScopedFocusNavigation::createScopedFocusNavigation(const E
lement& root, const Element* current) | 206 ScopedFocusNavigation ScopedFocusNavigation::createFor(const Element& current) |
207 { | 207 { |
208 if (SlotScopedTraversal::isSlotScoped(root)) | 208 if (SlotScopedTraversal::isSlotScoped(current)) |
209 return ScopedFocusNavigation(*SlotScopedTraversal::findScopeOwnerSlot(ro
ot), current); | 209 return ScopedFocusNavigation(*SlotScopedTraversal::findScopeOwnerSlot(cu
rrent), ¤t); |
210 return ScopedFocusNavigation(root.treeScope(), current); | 210 return ScopedFocusNavigation(current.treeScope(), ¤t); |
211 } | 211 } |
212 | 212 |
213 ScopedFocusNavigation ScopedFocusNavigation::createScopedFocusNavigationForDocum
ent(Document& document) | 213 ScopedFocusNavigation ScopedFocusNavigation::createForDocument(Document& documen
t) |
214 { | 214 { |
215 return ScopedFocusNavigation(document, nullptr); | 215 return ScopedFocusNavigation(document, nullptr); |
216 } | 216 } |
217 | 217 |
218 ScopedFocusNavigation ScopedFocusNavigation::ownedByNonFocusableFocusScopeOwner(
Element& element) | 218 ScopedFocusNavigation ScopedFocusNavigation::ownedByNonFocusableFocusScopeOwner(
Element& element) |
219 { | 219 { |
220 if (isShadowHost(element)) | 220 if (isShadowHost(element)) |
221 return ScopedFocusNavigation::ownedByShadowHost(element); | 221 return ScopedFocusNavigation::ownedByShadowHost(element); |
222 if (isShadowInsertionPointFocusScopeOwner(element)) | 222 if (isShadowInsertionPointFocusScopeOwner(element)) |
223 return ScopedFocusNavigation::ownedByShadowInsertionPoint(toHTMLShadowEl
ement(element)); | 223 return ScopedFocusNavigation::ownedByShadowInsertionPoint(toHTMLShadowEl
ement(element)); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 } else { | 602 } else { |
603 found = findFocusableElementRecursivelyForward(scope); | 603 found = findFocusableElementRecursivelyForward(scope); |
604 } | 604 } |
605 | 605 |
606 // If there's no focusable element to advance to, move up the focus scopes u
ntil we find one. | 606 // If there's no focusable element to advance to, move up the focus scopes u
ntil we find one. |
607 ScopedFocusNavigation currentScope = scope; | 607 ScopedFocusNavigation currentScope = scope; |
608 while (!found) { | 608 while (!found) { |
609 Element* owner = currentScope.owner(); | 609 Element* owner = currentScope.owner(); |
610 if (!owner) | 610 if (!owner) |
611 break; | 611 break; |
612 currentScope = ScopedFocusNavigation::createScopedFocusNavigation(*owner
, owner); | 612 currentScope = ScopedFocusNavigation::createFor(*owner); |
613 found = findFocusableElementRecursivelyForward(currentScope); | 613 found = findFocusableElementRecursivelyForward(currentScope); |
614 } | 614 } |
615 return findFocusableElementDescendingDownIntoFrameDocument(WebFocusTypeForwa
rd, found); | 615 return findFocusableElementDescendingDownIntoFrameDocument(WebFocusTypeForwa
rd, found); |
616 } | 616 } |
617 | 617 |
618 Element* findFocusableElementAcrossFocusScopesBackward(ScopedFocusNavigation& sc
ope) | 618 Element* findFocusableElementAcrossFocusScopesBackward(ScopedFocusNavigation& sc
ope) |
619 { | 619 { |
620 ASSERT(!scope.currentElement() || !isNonFocusableShadowHost(*scope.currentEl
ement())); | 620 ASSERT(!scope.currentElement() || !isNonFocusableShadowHost(*scope.currentEl
ement())); |
621 Element* found = findFocusableElementRecursivelyBackward(scope); | 621 Element* found = findFocusableElementRecursivelyBackward(scope); |
622 | 622 |
623 // If there's no focusable element to advance to, move up the focus scopes u
ntil we find one. | 623 // If there's no focusable element to advance to, move up the focus scopes u
ntil we find one. |
624 ScopedFocusNavigation currentScope = scope; | 624 ScopedFocusNavigation currentScope = scope; |
625 while (!found) { | 625 while (!found) { |
626 Element* owner = currentScope.owner(); | 626 Element* owner = currentScope.owner(); |
627 if (!owner) | 627 if (!owner) |
628 break; | 628 break; |
629 currentScope = ScopedFocusNavigation::createScopedFocusNavigation(*owner
, owner); | 629 currentScope = ScopedFocusNavigation::createFor(*owner); |
630 if (isKeyboardFocusableShadowHost(*owner) && !isShadowHostDelegatesFocus
(*owner)) { | 630 if (isKeyboardFocusableShadowHost(*owner) && !isShadowHostDelegatesFocus
(*owner)) { |
631 found = owner; | 631 found = owner; |
632 break; | 632 break; |
633 } | 633 } |
634 found = findFocusableElementRecursivelyBackward(currentScope); | 634 found = findFocusableElementRecursivelyBackward(currentScope); |
635 } | 635 } |
636 return findFocusableElementDescendingDownIntoFrameDocument(WebFocusTypeBackw
ard, found); | 636 return findFocusableElementDescendingDownIntoFrameDocument(WebFocusTypeBackw
ard, found); |
637 } | 637 } |
638 | 638 |
639 Element* findFocusableElementAcrossFocusScopes(WebFocusType type, ScopedFocusNav
igation& scope) | 639 Element* findFocusableElementAcrossFocusScopes(WebFocusType type, ScopedFocusNav
igation& scope) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 if (!current && !initialFocus) | 862 if (!current && !initialFocus) |
863 current = document->sequentialFocusNavigationStartingPoint(type); | 863 current = document->sequentialFocusNavigationStartingPoint(type); |
864 | 864 |
865 // FIXME: Not quite correct when it comes to focus transitions leaving/enter
ing the WebView itself | 865 // FIXME: Not quite correct when it comes to focus transitions leaving/enter
ing the WebView itself |
866 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn
abled(); | 866 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn
abled(); |
867 | 867 |
868 if (caretBrowsing && !current) | 868 if (caretBrowsing && !current) |
869 current = adjustToElement(frame->selection().start().anchorNode(), type)
; | 869 current = adjustToElement(frame->selection().start().anchorNode(), type)
; |
870 | 870 |
871 document->updateLayoutIgnorePendingStylesheets(); | 871 document->updateLayoutIgnorePendingStylesheets(); |
872 ScopedFocusNavigation scope = current ? ScopedFocusNavigation::createScopedF
ocusNavigation(*current, current) : ScopedFocusNavigation::createScopedFocusNavi
gationForDocument(*document); | 872 ScopedFocusNavigation scope = current ? ScopedFocusNavigation::createFor(*cu
rrent) : ScopedFocusNavigation::createForDocument(*document); |
873 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes(
type, scope); | 873 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes(
type, scope); |
874 | 874 |
875 if (!element) { | 875 if (!element) { |
876 // If there's a RemoteFrame on the ancestor chain, we need to continue | 876 // If there's a RemoteFrame on the ancestor chain, we need to continue |
877 // searching for focusable elements there. | 877 // searching for focusable elements there. |
878 if (frame->localFrameRoot() != frame->tree().top()) { | 878 if (frame->localFrameRoot() != frame->tree().top()) { |
879 document->clearFocusedElement(); | 879 document->clearFocusedElement(); |
880 document->setSequentialFocusNavigationStartingPoint(nullptr); | 880 document->setSequentialFocusNavigationStartingPoint(nullptr); |
881 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu
s(type, frame->localFrameRoot()); | 881 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu
s(type, frame->localFrameRoot()); |
882 return true; | 882 return true; |
883 } | 883 } |
884 | 884 |
885 // We didn't find an element to focus, so we should try to pass focus to
Chrome. | 885 // We didn't find an element to focus, so we should try to pass focus to
Chrome. |
886 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) { | 886 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) { |
887 document->clearFocusedElement(); | 887 document->clearFocusedElement(); |
888 document->setSequentialFocusNavigationStartingPoint(nullptr); | 888 document->setSequentialFocusNavigationStartingPoint(nullptr); |
889 setFocusedFrame(nullptr); | 889 setFocusedFrame(nullptr); |
890 m_page->chromeClient().takeFocus(type); | 890 m_page->chromeClient().takeFocus(type); |
891 return true; | 891 return true; |
892 } | 892 } |
893 | 893 |
894 // Chrome doesn't want focus, so we should wrap focus. | 894 // Chrome doesn't want focus, so we should wrap focus. |
895 ScopedFocusNavigation scope = ScopedFocusNavigation::createScopedFocusNa
vigationForDocument(*toLocalFrame(m_page->mainFrame())->document()); | 895 ScopedFocusNavigation scope = ScopedFocusNavigation::createForDocument(*
toLocalFrame(m_page->mainFrame())->document()); |
896 element = findFocusableElementRecursively(type, scope); | 896 element = findFocusableElementRecursively(type, scope); |
897 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem
ent.get()); | 897 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem
ent.get()); |
898 | 898 |
899 if (!element) | 899 if (!element) |
900 return false; | 900 return false; |
901 } | 901 } |
902 | 902 |
903 ASSERT(element); | 903 ASSERT(element); |
904 | 904 |
905 if (element == document->focusedElement()) { | 905 if (element == document->focusedElement()) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 } | 946 } |
947 | 947 |
948 element->focus(FocusParams(SelectionBehaviorOnFocus::Reset, type, sourceCapa
bilities)); | 948 element->focus(FocusParams(SelectionBehaviorOnFocus::Reset, type, sourceCapa
bilities)); |
949 return true; | 949 return true; |
950 } | 950 } |
951 | 951 |
952 Element* FocusController::findFocusableElement(WebFocusType type, Element& eleme
nt) | 952 Element* FocusController::findFocusableElement(WebFocusType type, Element& eleme
nt) |
953 { | 953 { |
954 // FIXME: No spacial navigation code yet. | 954 // FIXME: No spacial navigation code yet. |
955 ASSERT(type == WebFocusTypeForward || type == WebFocusTypeBackward); | 955 ASSERT(type == WebFocusTypeForward || type == WebFocusTypeBackward); |
956 ScopedFocusNavigation scope = ScopedFocusNavigation::createScopedFocusNaviga
tion(element, &element); | 956 ScopedFocusNavigation scope = ScopedFocusNavigation::createFor(element); |
957 return findFocusableElementAcrossFocusScopes(type, scope); | 957 return findFocusableElementAcrossFocusScopes(type, scope); |
958 } | 958 } |
959 | 959 |
960 Element* FocusController::findFocusableElementInShadowHost(const Element& shadow
Host) | 960 Element* FocusController::findFocusableElementInShadowHost(const Element& shadow
Host) |
961 { | 961 { |
962 ASSERT(shadowHost.authorShadowRoot()); | 962 ASSERT(shadowHost.authorShadowRoot()); |
963 ScopedFocusNavigation scope = ScopedFocusNavigation::ownedByShadowHost(shado
wHost); | 963 ScopedFocusNavigation scope = ScopedFocusNavigation::ownedByShadowHost(shado
wHost); |
964 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope); | 964 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope); |
965 } | 965 } |
966 | 966 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 return consumed; | 1257 return consumed; |
1258 } | 1258 } |
1259 | 1259 |
1260 DEFINE_TRACE(FocusController) | 1260 DEFINE_TRACE(FocusController) |
1261 { | 1261 { |
1262 visitor->trace(m_page); | 1262 visitor->trace(m_page); |
1263 visitor->trace(m_focusedFrame); | 1263 visitor->trace(m_focusedFrame); |
1264 } | 1264 } |
1265 | 1265 |
1266 } // namespace blink | 1266 } // namespace blink |
OLD | NEW |