| 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 27 matching lines...) Expand all Loading... |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class EventPath; | 40 class EventPath; |
| 41 class EventTarget; | 41 class EventTarget; |
| 42 class Node; | 42 class Node; |
| 43 template <typename NodeType> class StaticNodeTypeList; | 43 template <typename NodeType> class StaticNodeTypeList; |
| 44 using StaticNodeList = StaticNodeTypeList<Node>; | 44 using StaticNodeList = StaticNodeTypeList<Node>; |
| 45 class TouchEventContext; | 45 class TouchEventContext; |
| 46 class TreeScope; | 46 class TreeScope; |
| 47 | 47 |
| 48 class CORE_EXPORT TreeScopeEventContext final : public RefCountedWillBeGarbageCo
llected<TreeScopeEventContext> { | 48 class CORE_EXPORT TreeScopeEventContext final : public GarbageCollected<TreeScop
eEventContext> { |
| 49 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(TreeScopeEventContext); | |
| 50 public: | 49 public: |
| 51 static PassRefPtrWillBeRawPtr<TreeScopeEventContext> create(TreeScope&); | 50 static RawPtr<TreeScopeEventContext> create(TreeScope&); |
| 52 DECLARE_TRACE(); | 51 DECLARE_TRACE(); |
| 53 | 52 |
| 54 TreeScope& treeScope() const { return *m_treeScope; } | 53 TreeScope& treeScope() const { return *m_treeScope; } |
| 55 Node& rootNode() const { return *m_rootNode; } | 54 Node& rootNode() const { return *m_rootNode; } |
| 56 | 55 |
| 57 EventTarget* target() const { return m_target.get(); } | 56 EventTarget* target() const { return m_target.get(); } |
| 58 void setTarget(PassRefPtrWillBeRawPtr<EventTarget>); | 57 void setTarget(RawPtr<EventTarget>); |
| 59 | 58 |
| 60 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } | 59 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } |
| 61 void setRelatedTarget(PassRefPtrWillBeRawPtr<EventTarget>); | 60 void setRelatedTarget(RawPtr<EventTarget>); |
| 62 | 61 |
| 63 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge
t(); } | 62 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge
t(); } |
| 64 TouchEventContext* ensureTouchEventContext(); | 63 TouchEventContext* ensureTouchEventContext(); |
| 65 | 64 |
| 66 WillBeHeapVector<RefPtrWillBeMember<EventTarget>>& ensureEventPath(EventPath
&); | 65 HeapVector<Member<EventTarget>>& ensureEventPath(EventPath&); |
| 67 | 66 |
| 68 bool isInclusiveAncestorOf(const TreeScopeEventContext&) const; | 67 bool isInclusiveAncestorOf(const TreeScopeEventContext&) const; |
| 69 bool isDescendantOf(const TreeScopeEventContext&) const; | 68 bool isDescendantOf(const TreeScopeEventContext&) const; |
| 70 #if ENABLE(ASSERT) | 69 #if ENABLE(ASSERT) |
| 71 bool isExclusivePartOf(const TreeScopeEventContext&) const; | 70 bool isExclusivePartOf(const TreeScopeEventContext&) const; |
| 72 #endif | 71 #endif |
| 73 void addChild(TreeScopeEventContext& child) { m_children.append(&child); } | 72 void addChild(TreeScopeEventContext& child) { m_children.append(&child); } |
| 74 | 73 |
| 75 // For ancestor-descendant relationship check in O(1). | 74 // For ancestor-descendant relationship check in O(1). |
| 76 // Preprocessing takes O(N). | 75 // Preprocessing takes O(N). |
| 77 int calculateTreeOrderAndSetNearestAncestorClosedTree(int orderNumber, TreeS
copeEventContext* nearestAncestorClosedTreeScopeEventContext); | 76 int calculateTreeOrderAndSetNearestAncestorClosedTree(int orderNumber, TreeS
copeEventContext* nearestAncestorClosedTreeScopeEventContext); |
| 78 | 77 |
| 79 TreeScopeEventContext* containingClosedShadowTree() const { return m_contain
ingClosedShadowTree.get(); } | 78 TreeScopeEventContext* containingClosedShadowTree() const { return m_contain
ingClosedShadowTree.get(); } |
| 80 | 79 |
| 81 private: | 80 private: |
| 82 TreeScopeEventContext(TreeScope&); | 81 TreeScopeEventContext(TreeScope&); |
| 83 | 82 |
| 84 #if ENABLE(ASSERT) | 83 #if ENABLE(ASSERT) |
| 85 bool isUnreachableNode(EventTarget&); | 84 bool isUnreachableNode(EventTarget&); |
| 86 #endif | 85 #endif |
| 87 | 86 |
| 88 bool isUnclosedTreeOf(const TreeScopeEventContext& other); | 87 bool isUnclosedTreeOf(const TreeScopeEventContext& other); |
| 89 | 88 |
| 90 RawPtrWillBeMember<TreeScope> m_treeScope; | 89 Member<TreeScope> m_treeScope; |
| 91 RefPtrWillBeMember<Node> m_rootNode; // Prevents TreeScope from being freed.
TreeScope itself isn't RefCounted. | 90 Member<Node> m_rootNode; // Prevents TreeScope from being freed. TreeScope i
tself isn't RefCounted. |
| 92 RefPtrWillBeMember<EventTarget> m_target; | 91 Member<EventTarget> m_target; |
| 93 RefPtrWillBeMember<EventTarget> m_relatedTarget; | 92 Member<EventTarget> m_relatedTarget; |
| 94 OwnPtrWillBeMember<WillBeHeapVector<RefPtrWillBeMember<EventTarget>>> m_even
tPath; | 93 Member<HeapVector<Member<EventTarget>>> m_eventPath; |
| 95 RefPtrWillBeMember<TouchEventContext> m_touchEventContext; | 94 Member<TouchEventContext> m_touchEventContext; |
| 96 RawPtrWillBeMember<TreeScopeEventContext> m_containingClosedShadowTree; | 95 Member<TreeScopeEventContext> m_containingClosedShadowTree; |
| 97 | 96 |
| 98 WillBeHeapVector<RawPtrWillBeMember<TreeScopeEventContext>> m_children; | 97 HeapVector<Member<TreeScopeEventContext>> m_children; |
| 99 int m_preOrder; | 98 int m_preOrder; |
| 100 int m_postOrder; | 99 int m_postOrder; |
| 101 }; | 100 }; |
| 102 | 101 |
| 103 #if ENABLE(ASSERT) | 102 #if ENABLE(ASSERT) |
| 104 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target) | 103 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target) |
| 105 { | 104 { |
| 106 // FIXME: Checks also for SVG elements. | 105 // FIXME: Checks also for SVG elements. |
| 107 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode
()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(treeScope
()); | 106 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode
()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(treeScope
()); |
| 108 } | 107 } |
| 109 #endif | 108 #endif |
| 110 | 109 |
| 111 inline void TreeScopeEventContext::setTarget(PassRefPtrWillBeRawPtr<EventTarget>
target) | 110 inline void TreeScopeEventContext::setTarget(RawPtr<EventTarget> target) |
| 112 { | 111 { |
| 113 ASSERT(target); | 112 ASSERT(target); |
| 114 ASSERT(!isUnreachableNode(*target)); | 113 ASSERT(!isUnreachableNode(*target)); |
| 115 m_target = target; | 114 m_target = target; |
| 116 } | 115 } |
| 117 | 116 |
| 118 inline void TreeScopeEventContext::setRelatedTarget(PassRefPtrWillBeRawPtr<Event
Target> relatedTarget) | 117 inline void TreeScopeEventContext::setRelatedTarget(RawPtr<EventTarget> relatedT
arget) |
| 119 { | 118 { |
| 120 ASSERT(relatedTarget); | 119 ASSERT(relatedTarget); |
| 121 ASSERT(!isUnreachableNode(*relatedTarget)); | 120 ASSERT(!isUnreachableNode(*relatedTarget)); |
| 122 m_relatedTarget = relatedTarget; | 121 m_relatedTarget = relatedTarget; |
| 123 } | 122 } |
| 124 | 123 |
| 125 inline bool TreeScopeEventContext::isInclusiveAncestorOf(const TreeScopeEventCon
text& other) const | 124 inline bool TreeScopeEventContext::isInclusiveAncestorOf(const TreeScopeEventCon
text& other) const |
| 126 { | 125 { |
| 127 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot
her.m_postOrder != -1); | 126 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot
her.m_postOrder != -1); |
| 128 return m_preOrder <= other.m_preOrder && other.m_postOrder <= m_postOrder; | 127 return m_preOrder <= other.m_preOrder && other.m_postOrder <= m_postOrder; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 139 { | 138 { |
| 140 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot
her.m_postOrder != -1); | 139 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot
her.m_postOrder != -1); |
| 141 return (m_preOrder < other.m_preOrder && m_postOrder < other.m_preOrder) | 140 return (m_preOrder < other.m_preOrder && m_postOrder < other.m_preOrder) |
| 142 || (m_preOrder > other.m_preOrder && m_preOrder > other.m_postOrder); | 141 || (m_preOrder > other.m_preOrder && m_preOrder > other.m_postOrder); |
| 143 } | 142 } |
| 144 #endif | 143 #endif |
| 145 | 144 |
| 146 } // namespace blink | 145 } // namespace blink |
| 147 | 146 |
| 148 #endif // TreeScopeEventContext_h | 147 #endif // TreeScopeEventContext_h |
| OLD | NEW |