| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2014 Google Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/events/TreeScopeEventContext.h" | 28 #include "core/events/TreeScopeEventContext.h" |
| 29 | 29 |
| 30 #include "core/dom/StaticNodeList.h" | 30 #include "core/dom/StaticNodeList.h" |
| 31 #include "core/dom/shadow/ShadowRoot.h" | 31 #include "core/dom/shadow/ShadowRoot.h" |
| 32 #include "core/events/EventPath.h" | 32 #include "core/events/EventPath.h" |
| 33 #include "core/events/TouchEventContext.h" | 33 #include "core/events/TouchEventContext.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 bool TreeScopeEventContext::shouldIncludeTreeScope(const TreeScopeEventContext&
other) |
| 38 { |
| 39 const Node& rootNode = other.rootNode(); |
| 40 |
| 41 // Exclude nodes in UA shadow. E.g. <details> distributes elements under it
s tree. |
| 42 if (rootNode.isShadowRoot() && (toShadowRoot(rootNode).type() == ShadowRootT
ype::UserAgent)) |
| 43 return false; |
| 44 |
| 45 // Exclude closed nodes if necessary. |
| 46 |
| 47 // If a node is in a closed shadow root, or in a tree whose ancestor has a c
losed shadow root, |
| 48 // it should not be visible to nodes above the closed shadow root. |
| 49 |
| 50 // (1) If |other| is an ancestor in tree-of-trees, include it. |
| 51 if (other.isInclusiveAncestorOf(*this)) |
| 52 return true; |
| 53 |
| 54 // (2) If no closed shadow root in ancestors of |other|, include it. |
| 55 if (!other.containingClosedShadowTree()) |
| 56 return true; |
| 57 |
| 58 // (3) If |other| is descendent of |this|, exclude if any closed shadow root
in between. |
| 59 if (other.isDescendantOf(*this)) |
| 60 return !other.containingClosedShadowTree()->isDescendantOf(*this); |
| 61 |
| 62 // (4) |this| and |other| must be in exclusive branches. |
| 63 ASSERT(isExclusivePartOf(other)); |
| 64 return false; |
| 65 } |
| 66 |
| 37 WillBeHeapVector<RefPtrWillBeMember<EventTarget>>& TreeScopeEventContext::ensure
EventPath(EventPath& path) | 67 WillBeHeapVector<RefPtrWillBeMember<EventTarget>>& TreeScopeEventContext::ensure
EventPath(EventPath& path) |
| 38 { | 68 { |
| 39 if (m_eventPath) | 69 if (m_eventPath) |
| 40 return *m_eventPath; | 70 return *m_eventPath; |
| 41 | 71 |
| 42 m_eventPath = adoptPtrWillBeNoop(new WillBeHeapVector<RefPtrWillBeMember<Eve
ntTarget>>()); | 72 m_eventPath = adoptPtrWillBeNoop(new WillBeHeapVector<RefPtrWillBeMember<Eve
ntTarget>>()); |
| 43 LocalDOMWindow* window = path.windowEventContext().window(); | 73 LocalDOMWindow* window = path.windowEventContext().window(); |
| 44 m_eventPath->reserveCapacity(path.size() + (window ? 1 : 0)); | 74 m_eventPath->reserveCapacity(path.size() + (window ? 1 : 0)); |
| 75 |
| 45 for (size_t i = 0; i < path.size(); ++i) { | 76 for (size_t i = 0; i < path.size(); ++i) { |
| 46 Node& rootNode = path[i].treeScopeEventContext().rootNode(); | 77 if (shouldIncludeTreeScope(path[i].treeScopeEventContext())) |
| 47 if (rootNode.isShadowRoot() && (toShadowRoot(rootNode).type() == ShadowR
ootType::OpenByDefault || toShadowRoot(rootNode).type() == ShadowRootType::Open)
) | |
| 48 m_eventPath->append(path[i].node()); | |
| 49 else if (path[i].treeScopeEventContext().isInclusiveAncestorOf(*this)) | |
| 50 m_eventPath->append(path[i].node()); | 78 m_eventPath->append(path[i].node()); |
| 51 } | 79 } |
| 52 if (window) | 80 if (window) |
| 53 m_eventPath->append(window); | 81 m_eventPath->append(window); |
| 54 return *m_eventPath; | 82 return *m_eventPath; |
| 55 } | 83 } |
| 56 | 84 |
| 57 TouchEventContext* TreeScopeEventContext::ensureTouchEventContext() | 85 TouchEventContext* TreeScopeEventContext::ensureTouchEventContext() |
| 58 { | 86 { |
| 59 if (!m_touchEventContext) | 87 if (!m_touchEventContext) |
| 60 m_touchEventContext = TouchEventContext::create(); | 88 m_touchEventContext = TouchEventContext::create(); |
| 61 return m_touchEventContext.get(); | 89 return m_touchEventContext.get(); |
| 62 } | 90 } |
| 63 | 91 |
| 64 PassRefPtrWillBeRawPtr<TreeScopeEventContext> TreeScopeEventContext::create(Tree
Scope& treeScope) | 92 PassRefPtrWillBeRawPtr<TreeScopeEventContext> TreeScopeEventContext::create(Tree
Scope& treeScope) |
| 65 { | 93 { |
| 66 return adoptRefWillBeNoop(new TreeScopeEventContext(treeScope)); | 94 return adoptRefWillBeNoop(new TreeScopeEventContext(treeScope)); |
| 67 } | 95 } |
| 68 | 96 |
| 69 TreeScopeEventContext::TreeScopeEventContext(TreeScope& treeScope) | 97 TreeScopeEventContext::TreeScopeEventContext(TreeScope& treeScope) |
| 70 : m_treeScope(treeScope) | 98 : m_treeScope(treeScope) |
| 71 , m_rootNode(treeScope.rootNode()) | 99 , m_rootNode(treeScope.rootNode()) |
| 100 , m_containingClosedShadowTree(nullptr) |
| 72 , m_preOrder(-1) | 101 , m_preOrder(-1) |
| 73 , m_postOrder(-1) | 102 , m_postOrder(-1) |
| 74 { | 103 { |
| 75 } | 104 } |
| 76 | 105 |
| 77 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(TreeScopeEventContext) | 106 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(TreeScopeEventContext) |
| 78 | 107 |
| 79 DEFINE_TRACE(TreeScopeEventContext) | 108 DEFINE_TRACE(TreeScopeEventContext) |
| 80 { | 109 { |
| 81 visitor->trace(m_treeScope); | 110 visitor->trace(m_treeScope); |
| 82 visitor->trace(m_rootNode); | 111 visitor->trace(m_rootNode); |
| 83 visitor->trace(m_target); | 112 visitor->trace(m_target); |
| 84 visitor->trace(m_relatedTarget); | 113 visitor->trace(m_relatedTarget); |
| 85 visitor->trace(m_eventPath); | 114 visitor->trace(m_eventPath); |
| 86 visitor->trace(m_touchEventContext); | 115 visitor->trace(m_touchEventContext); |
| 116 visitor->trace(m_containingClosedShadowTree); |
| 87 #if ENABLE(OILPAN) | 117 #if ENABLE(OILPAN) |
| 88 visitor->trace(m_children); | 118 visitor->trace(m_children); |
| 89 #endif | 119 #endif |
| 90 } | 120 } |
| 91 | 121 |
| 92 int TreeScopeEventContext::calculatePrePostOrderNumber(int orderNumber) | 122 int TreeScopeEventContext::calculateTreeOrderAndFindClosedTrees(int orderNumber,
TreeScopeEventContext* parentClosedTreeScopeEventContext) |
| 93 { | 123 { |
| 94 m_preOrder = orderNumber; | 124 m_preOrder = orderNumber; |
| 125 m_containingClosedShadowTree = (rootNode().isShadowRoot() && toShadowRoot(ro
otNode()).type() == ShadowRootType::Closed) ? this : parentClosedTreeScopeEventC
ontext; |
| 95 for (size_t i = 0; i < m_children.size(); ++i) | 126 for (size_t i = 0; i < m_children.size(); ++i) |
| 96 orderNumber = m_children[i]->calculatePrePostOrderNumber(orderNumber + 1
); | 127 orderNumber = m_children[i]->calculateTreeOrderAndFindClosedTrees(orderN
umber + 1, containingClosedShadowTree()); |
| 97 m_postOrder = orderNumber + 1; | 128 m_postOrder = orderNumber + 1; |
| 129 |
| 98 return orderNumber + 1; | 130 return orderNumber + 1; |
| 99 } | 131 } |
| 100 | 132 |
| 101 } | 133 } // namespace blink |
| OLD | NEW |