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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class TreeScope; | 44 class TreeScope; |
45 | 45 |
46 class TreeScopeEventContext : public RefCounted<TreeScopeEventContext> { | 46 class TreeScopeEventContext : public RefCounted<TreeScopeEventContext> { |
47 public: | 47 public: |
48 static PassRefPtr<TreeScopeEventContext> create(TreeScope&); | 48 static PassRefPtr<TreeScopeEventContext> create(TreeScope&); |
49 ~TreeScopeEventContext(); | 49 ~TreeScopeEventContext(); |
50 | 50 |
51 TreeScope& treeScope() const { return m_treeScope; } | 51 TreeScope& treeScope() const { return m_treeScope; } |
52 | 52 |
53 EventTarget* target() const { return m_target.get(); } | 53 EventTarget* target() const { return m_target.get(); } |
54 void setTarget(PassRefPtr<EventTarget>); | 54 void setTarget(PassRefPtrWillBeRawPtr<EventTarget>); |
55 | 55 |
56 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } | 56 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } |
57 void setRelatedTarget(PassRefPtr<EventTarget>); | 57 void setRelatedTarget(PassRefPtrWillBeRawPtr<EventTarget>); |
58 | 58 |
59 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge
t(); } | 59 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge
t(); } |
60 TouchEventContext* ensureTouchEventContext(); | 60 TouchEventContext* ensureTouchEventContext(); |
61 | 61 |
62 PassRefPtrWillBeRawPtr<NodeList> ensureEventPath(EventPath&); | 62 PassRefPtrWillBeRawPtr<NodeList> ensureEventPath(EventPath&); |
63 | 63 |
64 bool isInclusiveAncestorOf(const TreeScopeEventContext&); | 64 bool isInclusiveAncestorOf(const TreeScopeEventContext&); |
65 void addChild(TreeScopeEventContext& child) { m_children.append(&child); } | 65 void addChild(TreeScopeEventContext& child) { m_children.append(&child); } |
66 | 66 |
67 // For ancestor-descendant relationship check in Q(1). | 67 // For ancestor-descendant relationship check in Q(1). |
68 // Preprocessing takes O(N). | 68 // Preprocessing takes O(N). |
69 int calculatePrePostOrderNumber(int orderNumber); | 69 int calculatePrePostOrderNumber(int orderNumber); |
70 | 70 |
71 private: | 71 private: |
72 TreeScopeEventContext(TreeScope&); | 72 TreeScopeEventContext(TreeScope&); |
73 | 73 |
74 #ifndef NDEBUG | 74 #ifndef NDEBUG |
75 bool isUnreachableNode(EventTarget&); | 75 bool isUnreachableNode(EventTarget&); |
76 #endif | 76 #endif |
77 | 77 |
78 TreeScope& m_treeScope; | 78 TreeScope& m_treeScope; |
79 RefPtr<EventTarget> m_target; | 79 RefPtrWillBePersistent<EventTarget> m_target; |
80 RefPtr<EventTarget> m_relatedTarget; | 80 RefPtrWillBePersistent<EventTarget> m_relatedTarget; |
81 RefPtrWillBePersistent<NodeList> m_eventPath; | 81 RefPtrWillBePersistent<NodeList> m_eventPath; |
82 RefPtrWillBePersistent<TouchEventContext> m_touchEventContext; | 82 RefPtrWillBePersistent<TouchEventContext> m_touchEventContext; |
83 | 83 |
84 Vector<TreeScopeEventContext*> m_children; | 84 Vector<TreeScopeEventContext*> m_children; |
85 int m_preOrder; | 85 int m_preOrder; |
86 int m_postOrder; | 86 int m_postOrder; |
87 }; | 87 }; |
88 | 88 |
89 #ifndef NDEBUG | 89 #ifndef NDEBUG |
90 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target) | 90 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target) |
91 { | 91 { |
92 // FIXME: Checks also for SVG elements. | 92 // FIXME: Checks also for SVG elements. |
93 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode
()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(m_treeSco
pe); | 93 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode
()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(m_treeSco
pe); |
94 } | 94 } |
95 #endif | 95 #endif |
96 | 96 |
97 inline void TreeScopeEventContext::setTarget(PassRefPtr<EventTarget> target) | 97 inline void TreeScopeEventContext::setTarget(PassRefPtrWillBeRawPtr<EventTarget>
target) |
98 { | 98 { |
99 ASSERT(target); | 99 ASSERT(target); |
100 ASSERT(!isUnreachableNode(*target)); | 100 ASSERT(!isUnreachableNode(*target)); |
101 m_target = target; | 101 m_target = target; |
102 } | 102 } |
103 | 103 |
104 inline void TreeScopeEventContext::setRelatedTarget(PassRefPtr<EventTarget> rela
tedTarget) | 104 inline void TreeScopeEventContext::setRelatedTarget(PassRefPtrWillBeRawPtr<Event
Target> relatedTarget) |
105 { | 105 { |
106 ASSERT(relatedTarget); | 106 ASSERT(relatedTarget); |
107 ASSERT(!isUnreachableNode(*relatedTarget)); | 107 ASSERT(!isUnreachableNode(*relatedTarget)); |
108 m_relatedTarget = relatedTarget; | 108 m_relatedTarget = relatedTarget; |
109 } | 109 } |
110 | 110 |
111 inline bool TreeScopeEventContext::isInclusiveAncestorOf(const TreeScopeEventCon
text& other) | 111 inline bool TreeScopeEventContext::isInclusiveAncestorOf(const TreeScopeEventCon
text& other) |
112 { | 112 { |
113 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot
her.m_postOrder != -1); | 113 ASSERT(m_preOrder != -1 && m_postOrder != -1 && other.m_preOrder != -1 && ot
her.m_postOrder != -1); |
114 return m_preOrder <= other.m_preOrder && other.m_postOrder <= m_postOrder; | 114 return m_preOrder <= other.m_preOrder && other.m_postOrder <= m_postOrder; |
115 } | 115 } |
116 | 116 |
117 } | 117 } |
118 | 118 |
119 #endif // TreeScopeEventContext_h | 119 #endif // TreeScopeEventContext_h |
OLD | NEW |