| 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 24 matching lines...) Expand all Loading... |
| 35 #include "core/dom/shadow/ElementShadow.h" | 35 #include "core/dom/shadow/ElementShadow.h" |
| 36 #include "core/dom/shadow/ShadowRoot.h" | 36 #include "core/dom/shadow/ShadowRoot.h" |
| 37 #include "core/editing/Editor.h" | 37 #include "core/editing/Editor.h" |
| 38 #include "core/editing/FrameSelection.h" | 38 #include "core/editing/FrameSelection.h" |
| 39 #include "core/editing/htmlediting.h" // For firstPositionInOrBeforeNode | 39 #include "core/editing/htmlediting.h" // For firstPositionInOrBeforeNode |
| 40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
| 41 #include "core/frame/LocalDOMWindow.h" | 41 #include "core/frame/LocalDOMWindow.h" |
| 42 #include "core/frame/FrameView.h" | 42 #include "core/frame/FrameView.h" |
| 43 #include "core/frame/LocalFrame.h" | 43 #include "core/frame/LocalFrame.h" |
| 44 #include "core/html/HTMLImageElement.h" | 44 #include "core/html/HTMLImageElement.h" |
| 45 #include "core/html/HTMLShadowElement.h" | |
| 46 #include "core/page/Chrome.h" | 45 #include "core/page/Chrome.h" |
| 47 #include "core/page/ChromeClient.h" | 46 #include "core/page/ChromeClient.h" |
| 48 #include "core/page/EventHandler.h" | 47 #include "core/page/EventHandler.h" |
| 49 #include "core/page/Page.h" | 48 #include "core/page/Page.h" |
| 50 #include "core/frame/Settings.h" | 49 #include "core/frame/Settings.h" |
| 51 #include "core/rendering/HitTestResult.h" | 50 #include "core/rendering/HitTestResult.h" |
| 52 #include "core/rendering/RenderLayer.h" | 51 #include "core/rendering/RenderLayer.h" |
| 53 #include <limits> | 52 #include <limits> |
| 54 | 53 |
| 55 namespace blink { | 54 namespace blink { |
| 56 | 55 |
| 57 static inline bool isShadowInsertionPointFocusScopeOwner(Node& node) | |
| 58 { | |
| 59 return isActiveShadowInsertionPoint(node) && toHTMLShadowElement(node).older
ShadowRoot(); | |
| 60 } | |
| 61 | |
| 62 // FIXME: Some of Node* return values and Node* arguments should be Element*. | 56 // FIXME: Some of Node* return values and Node* arguments should be Element*. |
| 63 | 57 |
| 64 FocusNavigationScope::FocusNavigationScope(TreeScope* treeScope) | 58 FocusNavigationScope::FocusNavigationScope(TreeScope* treeScope) |
| 65 : m_rootTreeScope(treeScope) | 59 : m_rootTreeScope(treeScope) |
| 66 { | 60 { |
| 67 ASSERT(treeScope); | 61 ASSERT(treeScope); |
| 68 } | 62 } |
| 69 | 63 |
| 70 Node* FocusNavigationScope::rootNode() const | 64 Node* FocusNavigationScope::rootNode() const |
| 71 { | 65 { |
| 72 return &m_rootTreeScope->rootNode(); | 66 return &m_rootTreeScope->rootNode(); |
| 73 } | 67 } |
| 74 | 68 |
| 75 Element* FocusNavigationScope::owner() const | 69 Element* FocusNavigationScope::owner() const |
| 76 { | 70 { |
| 77 Node* root = rootNode(); | 71 Node* root = rootNode(); |
| 78 if (root->isShadowRoot()) { | 72 if (root->isShadowRoot()) { |
| 79 ShadowRoot* shadowRoot = toShadowRoot(root); | 73 ShadowRoot* shadowRoot = toShadowRoot(root); |
| 80 return shadowRoot->isYoungest() ? shadowRoot->host() : shadowRoot->shado
wInsertionPointOfYoungerShadowRoot(); | 74 return shadowRoot->host(); |
| 81 } | 75 } |
| 82 return 0; | 76 return 0; |
| 83 } | 77 } |
| 84 | 78 |
| 85 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node) | 79 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node) |
| 86 { | 80 { |
| 87 ASSERT(node); | 81 ASSERT(node); |
| 88 Node* root = node; | 82 Node* root = node; |
| 89 for (Node* n = node; n; n = n->parentNode()) | 83 for (Node* n = node; n; n = n->parentNode()) |
| 90 root = n; | 84 root = n; |
| 91 // The result is not always a ShadowRoot nor a DocumentNode since | 85 // The result is not always a ShadowRoot nor a DocumentNode since |
| 92 // a starting node is in an orphaned tree in composed shadow tree. | 86 // a starting node is in an orphaned tree in composed shadow tree. |
| 93 return FocusNavigationScope(&root->treeScope()); | 87 return FocusNavigationScope(&root->treeScope()); |
| 94 } | 88 } |
| 95 | 89 |
| 96 FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(No
de* node) | 90 FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(No
de* node) |
| 97 { | 91 { |
| 98 ASSERT(node); | 92 ASSERT(node); |
| 99 if (isShadowHost(node)) | 93 return FocusNavigationScope::ownedByShadowHost(node); |
| 100 return FocusNavigationScope::ownedByShadowHost(node); | |
| 101 ASSERT(isShadowInsertionPointFocusScopeOwner(*node)); | |
| 102 return FocusNavigationScope::ownedByShadowInsertionPoint(toHTMLShadowElement
(node)); | |
| 103 } | 94 } |
| 104 | 95 |
| 105 FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node* node) | 96 FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node* node) |
| 106 { | 97 { |
| 107 ASSERT(isShadowHost(node)); | 98 ASSERT(isShadowHost(node)); |
| 108 return FocusNavigationScope(toElement(node)->shadow()->youngestShadowRoot())
; | 99 return FocusNavigationScope(toElement(node)->shadow()->youngestShadowRoot())
; |
| 109 } | 100 } |
| 110 | 101 |
| 111 FocusNavigationScope FocusNavigationScope::ownedByShadowInsertionPoint(HTMLShado
wElement* shadowInsertionPoint) | |
| 112 { | |
| 113 ASSERT(isShadowInsertionPointFocusScopeOwner(*shadowInsertionPoint)); | |
| 114 return FocusNavigationScope(shadowInsertionPoint->olderShadowRoot()); | |
| 115 } | |
| 116 | |
| 117 static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool
focused) | 102 static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool
focused) |
| 118 { | 103 { |
| 119 // If we have a focused node we should dispatch blur on it before we blur th
e window. | 104 // If we have a focused node we should dispatch blur on it before we blur th
e window. |
| 120 // If we have a focused node we should dispatch focus on it after we focus t
he window. | 105 // If we have a focused node we should dispatch focus on it after we focus t
he window. |
| 121 // https://bugs.webkit.org/show_bug.cgi?id=27105 | 106 // https://bugs.webkit.org/show_bug.cgi?id=27105 |
| 122 | 107 |
| 123 if (!focused && document->focusedElement()) { | 108 if (!focused && document->focusedElement()) { |
| 124 RefPtr<Element> focusedElement(document->focusedElement()); | 109 RefPtr<Element> focusedElement(document->focusedElement()); |
| 125 focusedElement->setFocus(false); | 110 focusedElement->setFocus(false); |
| 126 focusedElement->dispatchBlurEvent(0); | 111 focusedElement->dispatchBlurEvent(0); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 ASSERT(node); | 155 ASSERT(node); |
| 171 if (!node->isElementNode()) | 156 if (!node->isElementNode()) |
| 172 return false; | 157 return false; |
| 173 Element* element = toElement(node); | 158 Element* element = toElement(node); |
| 174 return element->isKeyboardFocusable() && isShadowHost(element); | 159 return element->isKeyboardFocusable() && isShadowHost(element); |
| 175 } | 160 } |
| 176 | 161 |
| 177 static inline bool isNonFocusableFocusScopeOwner(Node* node) | 162 static inline bool isNonFocusableFocusScopeOwner(Node* node) |
| 178 { | 163 { |
| 179 ASSERT(node); | 164 ASSERT(node); |
| 180 return isNonKeyboardFocusableShadowHost(node) || isShadowInsertionPointFocus
ScopeOwner(*node); | 165 return isNonKeyboardFocusableShadowHost(node); |
| 181 } | 166 } |
| 182 | 167 |
| 183 static inline int adjustedTabIndex(Node* node) | 168 static inline int adjustedTabIndex(Node* node) |
| 184 { | 169 { |
| 185 ASSERT(node); | 170 ASSERT(node); |
| 186 return isNonFocusableFocusScopeOwner(node) ? 0 : node->tabIndex(); | 171 return isNonFocusableFocusScopeOwner(node) ? 0 : node->tabIndex(); |
| 187 } | 172 } |
| 188 | 173 |
| 189 static inline bool shouldVisit(Node* node) | 174 static inline bool shouldVisit(Node* node) |
| 190 { | 175 { |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 { | 589 { |
| 605 if (m_isActive == active) | 590 if (m_isActive == active) |
| 606 return; | 591 return; |
| 607 | 592 |
| 608 m_isActive = active; | 593 m_isActive = active; |
| 609 | 594 |
| 610 focusedOrMainFrame()->selection().pageActivationChanged(); | 595 focusedOrMainFrame()->selection().pageActivationChanged(); |
| 611 } | 596 } |
| 612 | 597 |
| 613 } // namespace blink | 598 } // namespace blink |
| OLD | NEW |