Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } | 57 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } |
| 58 void setRelatedTarget(EventTarget*); | 58 void setRelatedTarget(EventTarget*); |
| 59 | 59 |
| 60 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge t(); } | 60 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge t(); } |
| 61 TouchEventContext* ensureTouchEventContext(); | 61 TouchEventContext* ensureTouchEventContext(); |
| 62 | 62 |
| 63 HeapVector<Member<EventTarget>>& ensureEventPath(EventPath&); | 63 HeapVector<Member<EventTarget>>& ensureEventPath(EventPath&); |
| 64 | 64 |
| 65 bool isInclusiveAncestorOf(const TreeScopeEventContext&) const; | 65 bool isInclusiveAncestorOf(const TreeScopeEventContext&) const; |
| 66 bool isDescendantOf(const TreeScopeEventContext&) const; | 66 bool isDescendantOf(const TreeScopeEventContext&) const; |
| 67 #if ENABLE(ASSERT) | 67 #if DCHECK_IS_ON() |
| 68 bool isExclusivePartOf(const TreeScopeEventContext&) const; | 68 bool isExclusivePartOf(const TreeScopeEventContext&) const; |
| 69 #endif | 69 #endif |
| 70 void addChild(TreeScopeEventContext& child) { m_children.append(&child); } | 70 void addChild(TreeScopeEventContext& child) { m_children.append(&child); } |
| 71 | 71 |
| 72 // For ancestor-descendant relationship check in O(1). | 72 // For ancestor-descendant relationship check in O(1). |
| 73 // Preprocessing takes O(N). | 73 // Preprocessing takes O(N). |
| 74 int calculateTreeOrderAndSetNearestAncestorClosedTree(int orderNumber, TreeS copeEventContext* nearestAncestorClosedTreeScopeEventContext); | 74 int calculateTreeOrderAndSetNearestAncestorClosedTree(int orderNumber, TreeS copeEventContext* nearestAncestorClosedTreeScopeEventContext); |
| 75 | 75 |
| 76 TreeScopeEventContext* containingClosedShadowTree() const { return m_contain ingClosedShadowTree.get(); } | 76 TreeScopeEventContext* containingClosedShadowTree() const { return m_contain ingClosedShadowTree.get(); } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 TreeScopeEventContext(TreeScope&); | 79 TreeScopeEventContext(TreeScope&); |
| 80 | 80 |
| 81 #if ENABLE(ASSERT) | 81 #if DCHECK_IS_ON() |
| 82 bool isUnreachableNode(EventTarget&); | 82 bool isUnreachableNode(EventTarget&); |
| 83 #endif | 83 #endif |
| 84 | 84 |
| 85 bool isUnclosedTreeOf(const TreeScopeEventContext& other); | 85 bool isUnclosedTreeOf(const TreeScopeEventContext& other); |
| 86 | 86 |
| 87 Member<TreeScope> m_treeScope; | 87 Member<TreeScope> m_treeScope; |
| 88 Member<Node> m_rootNode; // Prevents TreeScope from being freed. TreeScope i tself isn't RefCounted. | 88 Member<Node> m_rootNode; // Prevents TreeScope from being freed. TreeScope i tself isn't RefCounted. |
| 89 Member<EventTarget> m_target; | 89 Member<EventTarget> m_target; |
| 90 Member<EventTarget> m_relatedTarget; | 90 Member<EventTarget> m_relatedTarget; |
| 91 Member<HeapVector<Member<EventTarget>>> m_eventPath; | 91 Member<HeapVector<Member<EventTarget>>> m_eventPath; |
| 92 Member<TouchEventContext> m_touchEventContext; | 92 Member<TouchEventContext> m_touchEventContext; |
| 93 Member<TreeScopeEventContext> m_containingClosedShadowTree; | 93 Member<TreeScopeEventContext> m_containingClosedShadowTree; |
| 94 | 94 |
| 95 HeapVector<Member<TreeScopeEventContext>> m_children; | 95 HeapVector<Member<TreeScopeEventContext>> m_children; |
| 96 int m_preOrder; | 96 int m_preOrder; |
| 97 int m_postOrder; | 97 int m_postOrder; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 #if ENABLE(ASSERT) | 100 #if DCHECK_IS_ON() |
| 101 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target) | 101 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target) |
| 102 { | 102 { |
| 103 // FIXME: Checks also for SVG elements. | 103 // FIXME: Checks also for SVG elements. |
| 104 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode ()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(treeScope ()); | 104 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode ()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(treeScope ()); |
| 105 } | 105 } |
| 106 #endif | 106 #endif |
| 107 | 107 |
| 108 inline void TreeScopeEventContext::setTarget(EventTarget* target) | 108 inline void TreeScopeEventContext::setTarget(EventTarget* target) |
| 109 { | 109 { |
| 110 ASSERT(target); | 110 #if DCHECK_IS_ON() |
| 111 ASSERT(!isUnreachableNode(*target)); | 111 DCHECK(target); |
|
hayato
2016/08/24 03:42:27
You do not have to guard DCHECK(target) by DCHECK_
tkent
2016/08/24 06:05:23
You're right.
I reconsidered isUnreachableNode(),
| |
| 112 DCHECK(!isUnreachableNode(*target)); | |
| 113 #endif | |
| 112 m_target = target; | 114 m_target = target; |
| 113 } | 115 } |
| 114 | 116 |
| 115 inline void TreeScopeEventContext::setRelatedTarget(EventTarget* relatedTarget) | 117 inline void TreeScopeEventContext::setRelatedTarget(EventTarget* relatedTarget) |
| 116 { | 118 { |
| 117 ASSERT(relatedTarget); | 119 #if DCHECK_IS_ON() |
| 118 ASSERT(!isUnreachableNode(*relatedTarget)); | 120 DCHECK(relatedTarget); |
|
hayato
2016/08/24 03:42:27
You do not have to guard DCHECK(relataedTarget) by
| |
| 121 DCHECK(!isUnreachableNode(*relatedTarget)); | |
| 122 #endif | |
| 119 m_relatedTarget = relatedTarget; | 123 m_relatedTarget = relatedTarget; |
| 120 } | 124 } |
| 121 | 125 |
| 122 inline bool TreeScopeEventContext::isInclusiveAncestorOf(const TreeScopeEventCon text& other) const | 126 inline bool TreeScopeEventContext::isInclusiveAncestorOf(const TreeScopeEventCon text& other) const |
| 123 { | 127 { |
| 124 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot her.m_postOrder != -1); | 128 DCHECK_NE(m_preOrder, -1); |
| 129 DCHECK_NE(m_postOrder, -1); | |
| 130 DCHECK_NE(other.m_preOrder, -1); | |
| 131 DCHECK_NE(other.m_postOrder, -1); | |
| 125 return m_preOrder <= other.m_preOrder && other.m_postOrder <= m_postOrder; | 132 return m_preOrder <= other.m_preOrder && other.m_postOrder <= m_postOrder; |
| 126 } | 133 } |
| 127 | 134 |
| 128 inline bool TreeScopeEventContext::isDescendantOf(const TreeScopeEventContext& o ther) const | 135 inline bool TreeScopeEventContext::isDescendantOf(const TreeScopeEventContext& o ther) const |
| 129 { | 136 { |
| 130 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot her.m_postOrder != -1); | 137 DCHECK_NE(m_preOrder, -1); |
| 138 DCHECK_NE(m_postOrder, -1); | |
| 139 DCHECK_NE(other.m_preOrder, -1); | |
| 140 DCHECK_NE(other.m_postOrder, -1); | |
| 131 return other.m_preOrder < m_preOrder && m_postOrder < other.m_postOrder; | 141 return other.m_preOrder < m_preOrder && m_postOrder < other.m_postOrder; |
| 132 } | 142 } |
| 133 | 143 |
| 134 #if ENABLE(ASSERT) | 144 #if DCHECK_IS_ON() |
| 135 inline bool TreeScopeEventContext::isExclusivePartOf(const TreeScopeEventContext & other) const | 145 inline bool TreeScopeEventContext::isExclusivePartOf(const TreeScopeEventContext & other) const |
| 136 { | 146 { |
| 137 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot her.m_postOrder != -1); | 147 DCHECK_NE(m_preOrder, -1); |
| 148 DCHECK_NE(m_postOrder, -1); | |
| 149 DCHECK_NE(other.m_preOrder, -1); | |
| 150 DCHECK_NE(other.m_postOrder, -1); | |
| 138 return (m_preOrder < other.m_preOrder && m_postOrder < other.m_preOrder) | 151 return (m_preOrder < other.m_preOrder && m_postOrder < other.m_preOrder) |
| 139 || (m_preOrder > other.m_preOrder && m_preOrder > other.m_postOrder); | 152 || (m_preOrder > other.m_preOrder && m_preOrder > other.m_postOrder); |
| 140 } | 153 } |
| 141 #endif | 154 #endif |
| 142 | 155 |
| 143 } // namespace blink | 156 } // namespace blink |
| 144 | 157 |
| 145 #endif // TreeScopeEventContext_h | 158 #endif // TreeScopeEventContext_h |
| OLD | NEW |