Chromium Code Reviews| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 inline bool isShadowInsertionPointFocusScopeOwner(Element& element) | 67 inline bool isShadowInsertionPointFocusScopeOwner(Element& element) |
| 68 { | 68 { |
| 69 return isActiveShadowInsertionPoint(element) && toHTMLShadowElement(element) .olderShadowRoot(); | 69 return isActiveShadowInsertionPoint(element) && toHTMLShadowElement(element) .olderShadowRoot(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 class FocusNavigationScope { | 72 class FocusNavigationScope { |
| 73 STACK_ALLOCATED(); | 73 STACK_ALLOCATED(); |
| 74 public: | 74 public: |
| 75 Node* rootNode() const; | 75 Node* rootNode() const; |
| 76 Element* owner() const; | 76 Element* owner() const; |
| 77 static FocusNavigationScope focusNavigationScopeOf(const Node&); | 77 static FocusNavigationScope focusNavigationScopeOf(const Element&); |
| 78 static FocusNavigationScope ownedByNonFocusableFocusScopeOwner(Element&); | 78 static FocusNavigationScope ownedByNonFocusableFocusScopeOwner(Element&); |
| 79 static FocusNavigationScope ownedByShadowHost(const Element&); | 79 static FocusNavigationScope ownedByShadowHost(const Element&); |
| 80 static FocusNavigationScope ownedByShadowInsertionPoint(HTMLShadowElement&); | 80 static FocusNavigationScope ownedByShadowInsertionPoint(HTMLShadowElement&); |
| 81 static FocusNavigationScope ownedByIFrame(const HTMLFrameOwnerElement&); | 81 static FocusNavigationScope ownedByIFrame(const HTMLFrameOwnerElement&); |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 explicit FocusNavigationScope(TreeScope*); | 84 explicit FocusNavigationScope(TreeScope*); |
| 85 RawPtrWillBeMember<TreeScope> m_rootTreeScope; | 85 RawPtrWillBeMember<TreeScope> m_rootTreeScope; |
| 86 }; | 86 }; |
| 87 | 87 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 102 if (root->isShadowRoot()) { | 102 if (root->isShadowRoot()) { |
| 103 ShadowRoot* shadowRoot = toShadowRoot(root); | 103 ShadowRoot* shadowRoot = toShadowRoot(root); |
| 104 return shadowRoot->isYoungest() ? shadowRoot->host() : shadowRoot->shado wInsertionPointOfYoungerShadowRoot(); | 104 return shadowRoot->isYoungest() ? shadowRoot->host() : shadowRoot->shado wInsertionPointOfYoungerShadowRoot(); |
| 105 } | 105 } |
| 106 // FIXME: Figure out the right thing for OOPI here. | 106 // FIXME: Figure out the right thing for OOPI here. |
| 107 if (Frame* frame = root->document().frame()) | 107 if (Frame* frame = root->document().frame()) |
| 108 return frame->deprecatedLocalOwner(); | 108 return frame->deprecatedLocalOwner(); |
| 109 return nullptr; | 109 return nullptr; |
| 110 } | 110 } |
| 111 | 111 |
| 112 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(const Node& no de) | 112 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(const Element& element) |
| 113 { | 113 { |
| 114 return FocusNavigationScope(&node.treeScope()); | 114 return FocusNavigationScope(&element.treeScope()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(El ement& element) | 117 FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(El ement& element) |
| 118 { | 118 { |
| 119 if (isShadowHost(element)) | 119 if (isShadowHost(element)) |
| 120 return FocusNavigationScope::ownedByShadowHost(element); | 120 return FocusNavigationScope::ownedByShadowHost(element); |
| 121 ASSERT(isShadowInsertionPointFocusScopeOwner(element)); | 121 ASSERT(isShadowInsertionPointFocusScopeOwner(element)); |
| 122 return FocusNavigationScope::ownedByShadowInsertionPoint(toHTMLShadowElement (element)); | 122 return FocusNavigationScope::ownedByShadowInsertionPoint(toHTMLShadowElement (element)); |
| 123 } | 123 } |
| 124 | 124 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 return findFocusableElementDescendingDownIntoFrameDocument(WebFocusTypeBackw ard, found); | 522 return findFocusableElementDescendingDownIntoFrameDocument(WebFocusTypeBackw ard, found); |
| 523 } | 523 } |
| 524 | 524 |
| 525 Element* findFocusableElementAcrossFocusScopes(WebFocusType type, const FocusNav igationScope& scope, Node* currentNode) | 525 Element* findFocusableElementAcrossFocusScopes(WebFocusType type, const FocusNav igationScope& scope, Node* currentNode) |
| 526 { | 526 { |
| 527 return (type == WebFocusTypeForward) ? | 527 return (type == WebFocusTypeForward) ? |
| 528 findFocusableElementAcrossFocusScopesForward(scope, currentNode) : | 528 findFocusableElementAcrossFocusScopesForward(scope, currentNode) : |
| 529 findFocusableElementAcrossFocusScopesBackward(scope, currentNode); | 529 findFocusableElementAcrossFocusScopesBackward(scope, currentNode); |
| 530 } | 530 } |
| 531 | 531 |
| 532 inline Element* adjustToElement(Node* node, WebFocusType type) | |
| 533 { | |
| 534 ASSERT(type == WebFocusTypeForward || type == WebFocusTypeBackward); | |
| 535 if (!node) | |
| 536 return nullptr; | |
| 537 return (type == WebFocusTypeForward) ? ElementTraversal::next(*node) : Eleme ntTraversal::previous(*node); | |
|
kochi
2016/02/19 06:11:33
I think if the |node| is an Element, you should re
hayato
2016/02/19 06:22:54
Done.
| |
| 538 } | |
| 539 | |
| 532 } // anonymous namespace | 540 } // anonymous namespace |
| 533 | 541 |
| 534 FocusController::FocusController(Page* page) | 542 FocusController::FocusController(Page* page) |
| 535 : m_page(page) | 543 : m_page(page) |
| 536 , m_isActive(false) | 544 , m_isActive(false) |
| 537 , m_isFocused(false) | 545 , m_isFocused(false) |
| 538 , m_isChangingFocusedFrame(false) | 546 , m_isChangingFocusedFrame(false) |
| 539 { | 547 { |
| 540 } | 548 } |
| 541 | 549 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 | 715 |
| 708 return false; | 716 return false; |
| 709 } | 717 } |
| 710 | 718 |
| 711 bool FocusController::advanceFocusAcrossFrames(WebFocusType type, RemoteFrame* f rom, LocalFrame* to, InputDeviceCapabilities* sourceCapabilities) | 719 bool FocusController::advanceFocusAcrossFrames(WebFocusType type, RemoteFrame* f rom, LocalFrame* to, InputDeviceCapabilities* sourceCapabilities) |
| 712 { | 720 { |
| 713 // If we are shifting focus from a child frame to its parent, the | 721 // If we are shifting focus from a child frame to its parent, the |
| 714 // child frame has no more focusable elements, and we should continue | 722 // child frame has no more focusable elements, and we should continue |
| 715 // looking for focusable elements in the parent, starting from the <iframe> | 723 // looking for focusable elements in the parent, starting from the <iframe> |
| 716 // element of the child frame. | 724 // element of the child frame. |
| 717 Node* startingNode = nullptr; | 725 Element* start = nullptr; |
| 718 if (from->tree().parent() == to) { | 726 if (from->tree().parent() == to) { |
| 719 ASSERT(from->owner()->isLocal()); | 727 ASSERT(from->owner()->isLocal()); |
| 720 startingNode = toHTMLFrameOwnerElement(from->owner()); | 728 start = toHTMLFrameOwnerElement(from->owner()); |
| 721 } | 729 } |
| 722 | 730 |
| 723 return advanceFocusInDocumentOrder(to, startingNode, type, false, sourceCapa bilities); | 731 return advanceFocusInDocumentOrder(to, start, type, false, sourceCapabilitie s); |
| 724 } | 732 } |
| 725 | 733 |
| 726 bool FocusController::advanceFocusInDocumentOrder(LocalFrame* frame, Node* start ingNode, WebFocusType type, bool initialFocus, InputDeviceCapabilities* sourceCa pabilities) | 734 bool FocusController::advanceFocusInDocumentOrder(LocalFrame* frame, Element* st art, WebFocusType type, bool initialFocus, InputDeviceCapabilities* sourceCapabi lities) |
| 727 { | 735 { |
| 728 ASSERT(frame); | 736 ASSERT(frame); |
| 729 Document* document = frame->document(); | 737 Document* document = frame->document(); |
| 738 ASSERT(document->documentElement()); | |
| 730 | 739 |
| 731 Node* currentNode = startingNode; | 740 Element* current = start; |
| 732 if (!currentNode) | 741 if (!current) |
| 733 currentNode = document->focusedElement(); | 742 current = document->focusedElement(); |
| 734 | 743 |
| 735 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself | 744 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself |
| 736 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled(); | 745 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled(); |
| 737 | 746 |
| 738 if (caretBrowsing && !currentNode) | 747 if (caretBrowsing && !current) |
| 739 currentNode = frame->selection().start().anchorNode(); | 748 current = adjustToElement(frame->selection().start().anchorNode(), type) ; |
| 740 | 749 |
| 741 document->updateLayoutIgnorePendingStylesheets(); | 750 document->updateLayoutIgnorePendingStylesheets(); |
| 742 | 751 |
| 743 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes( type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? *currentNode : *document), currentNode); | 752 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes( type, FocusNavigationScope::focusNavigationScopeOf(current ? *current : *documen t->documentElement()), current); |
| 744 | 753 |
| 745 if (!element) { | 754 if (!element) { |
| 746 // If there's a RemoteFrame on the ancestor chain, we need to continue | 755 // If there's a RemoteFrame on the ancestor chain, we need to continue |
| 747 // searching for focusable elements there. | 756 // searching for focusable elements there. |
| 748 if (frame->localFrameRoot() != frame->tree().top()) { | 757 if (frame->localFrameRoot() != frame->tree().top()) { |
| 749 document->clearFocusedElement(); | 758 document->clearFocusedElement(); |
| 750 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu s(type, frame->localFrameRoot()); | 759 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu s(type, frame->localFrameRoot()); |
| 751 return true; | 760 return true; |
| 752 } | 761 } |
| 753 | 762 |
| 754 // We didn't find an element to focus, so we should try to pass focus to Chrome. | 763 // We didn't find an element to focus, so we should try to pass focus to Chrome. |
| 755 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) { | 764 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) { |
| 756 document->clearFocusedElement(); | 765 document->clearFocusedElement(); |
| 757 setFocusedFrame(nullptr); | 766 setFocusedFrame(nullptr); |
| 758 m_page->chromeClient().takeFocus(type); | 767 m_page->chromeClient().takeFocus(type); |
| 759 return true; | 768 return true; |
| 760 } | 769 } |
| 761 | 770 |
| 762 // Chrome doesn't want focus, so we should wrap focus. | 771 // Chrome doesn't want focus, so we should wrap focus. |
| 763 element = findFocusableElementRecursively(type, FocusNavigationScope::fo cusNavigationScopeOf(*toLocalFrame(m_page->mainFrame())->document()), nullptr); | 772 element = findFocusableElementRecursively(type, FocusNavigationScope::fo cusNavigationScopeOf(*toLocalFrame(m_page->mainFrame())->document()->documentEle ment()), nullptr); |
| 764 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem ent.get()); | 773 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem ent.get()); |
| 765 | 774 |
| 766 if (!element) | 775 if (!element) |
| 767 return false; | 776 return false; |
| 768 } | 777 } |
| 769 | 778 |
| 770 ASSERT(element); | 779 ASSERT(element); |
| 771 | 780 |
| 772 if (element == document->focusedElement()) { | 781 if (element == document->focusedElement()) { |
| 773 // Focus wrapped around to the same node. | 782 // Focus wrapped around to the same node. |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1122 return consumed; | 1131 return consumed; |
| 1123 } | 1132 } |
| 1124 | 1133 |
| 1125 DEFINE_TRACE(FocusController) | 1134 DEFINE_TRACE(FocusController) |
| 1126 { | 1135 { |
| 1127 visitor->trace(m_page); | 1136 visitor->trace(m_page); |
| 1128 visitor->trace(m_focusedFrame); | 1137 visitor->trace(m_focusedFrame); |
| 1129 } | 1138 } |
| 1130 | 1139 |
| 1131 } // namespace blink | 1140 } // namespace blink |
| OLD | NEW |