| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 || eventType == EventTypeNames::resize | 81 || eventType == EventTypeNames::resize |
| 82 || eventType == EventTypeNames::scroll | 82 || eventType == EventTypeNames::scroll |
| 83 || eventType == EventTypeNames::select | 83 || eventType == EventTypeNames::select |
| 84 || eventType == EventTypeNames::selectstart)) | 84 || eventType == EventTypeNames::selectstart)) |
| 85 return StayInsideShadowDOM; | 85 return StayInsideShadowDOM; |
| 86 | 86 |
| 87 return RetargetEvent; | 87 return RetargetEvent; |
| 88 } | 88 } |
| 89 | 89 |
| 90 EventPath::EventPath(Event* event) | 90 EventPath::EventPath(Event* event) |
| 91 : m_node(0) | 91 : m_node(nullptr) |
| 92 , m_event(event) | 92 , m_event(event) |
| 93 { | 93 { |
| 94 } | 94 } |
| 95 | 95 |
| 96 EventPath::EventPath(Node* node) | 96 EventPath::EventPath(Node* node) |
| 97 : m_node(node) | 97 : m_node(node) |
| 98 , m_event(nullptr) | 98 , m_event(nullptr) |
| 99 { | 99 { |
| 100 resetWith(node); | 100 resetWith(node); |
| 101 } | 101 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 | 114 |
| 115 void EventPath::addNodeEventContext(Node* node) | 115 void EventPath::addNodeEventContext(Node* node) |
| 116 { | 116 { |
| 117 m_nodeEventContexts.append(NodeEventContext(node, eventTargetRespectingTarge
tRules(node))); | 117 m_nodeEventContexts.append(NodeEventContext(node, eventTargetRespectingTarge
tRules(node))); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void EventPath::calculatePath() | 120 void EventPath::calculatePath() |
| 121 { | 121 { |
| 122 ASSERT(m_node); | 122 ASSERT(m_node); |
| 123 ASSERT(m_nodeEventContexts.isEmpty()); | 123 ASSERT(m_nodeEventContexts.isEmpty()); |
| 124 m_node->document().updateDistributionForNodeIfNeeded(const_cast<Node*>(m_nod
e)); | 124 m_node->document().updateDistributionForNodeIfNeeded(const_cast<Node*>(m_nod
e.get())); |
| 125 | 125 |
| 126 Node* current = m_node; | 126 Node* current = m_node; |
| 127 addNodeEventContext(current); | 127 addNodeEventContext(current); |
| 128 if (!m_node->inDocument()) | 128 if (!m_node->inDocument()) |
| 129 return; | 129 return; |
| 130 while (current) { | 130 while (current) { |
| 131 if (current->isShadowRoot() && m_event && determineDispatchBehavior(m_ev
ent, toShadowRoot(current), m_node) == StayInsideShadowDOM) | 131 if (current->isShadowRoot() && m_event && determineDispatchBehavior(m_ev
ent, toShadowRoot(current), m_node) == StayInsideShadowDOM) |
| 132 break; | 132 break; |
| 133 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints; | 133 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints; |
| 134 collectDestinationInsertionPoints(*current, insertionPoints); | 134 collectDestinationInsertionPoints(*current, insertionPoints); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 addNodeEventContext(current); | 155 addNodeEventContext(current); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 void EventPath::calculateTreeScopePrePostOrderNumbers() | 160 void EventPath::calculateTreeScopePrePostOrderNumbers() |
| 161 { | 161 { |
| 162 // Precondition: | 162 // Precondition: |
| 163 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the sam
e tree of trees. | 163 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the sam
e tree of trees. |
| 164 // - The root tree must be included. | 164 // - The root tree must be included. |
| 165 HashMap<const TreeScope*, TreeScopeEventContext*> treeScopeEventContextMap; | 165 WillBeHeapHashMap<RawPtrWillBeMember<const TreeScope>, RawPtrWillBeMember<Tr
eeScopeEventContext> > treeScopeEventContextMap; |
| 166 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) | 166 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) |
| 167 treeScopeEventContextMap.add(&m_treeScopeEventContexts[i]->treeScope(),
m_treeScopeEventContexts[i].get()); | 167 treeScopeEventContextMap.add(&m_treeScopeEventContexts[i]->treeScope(),
m_treeScopeEventContexts[i].get()); |
| 168 TreeScopeEventContext* rootTree = 0; | 168 TreeScopeEventContext* rootTree = 0; |
| 169 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { | 169 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { |
| 170 TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[
i].get(); | 170 TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[
i].get(); |
| 171 // Use olderShadowRootOrParentTreeScope here for parent-child relationsh
ips. | 171 // Use olderShadowRootOrParentTreeScope here for parent-child relationsh
ips. |
| 172 // See the definition of trees of trees in the Shado DOM spec: http://w3
c.github.io/webcomponents/spec/shadow/ | 172 // See the definition of trees of trees in the Shado DOM spec: http://w3
c.github.io/webcomponents/spec/shadow/ |
| 173 TreeScope* parent = treeScopeEventContext->treeScope().olderShadowRootOr
ParentTreeScope(); | 173 TreeScope* parent = treeScopeEventContext->treeScope().olderShadowRootOr
ParentTreeScope(); |
| 174 if (!parent) { | 174 if (!parent) { |
| 175 ASSERT(!rootTree); | 175 ASSERT(!rootTree); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 { | 242 { |
| 243 EventPath relatedTargetEventPath(const_cast<Node*>(relatedNode)); | 243 EventPath relatedTargetEventPath(const_cast<Node*>(relatedNode)); |
| 244 for (size_t i = 0; i < relatedTargetEventPath.m_treeScopeEventContexts.size(
); ++i) { | 244 for (size_t i = 0; i < relatedTargetEventPath.m_treeScopeEventContexts.size(
); ++i) { |
| 245 TreeScopeEventContext* treeScopeEventContext = relatedTargetEventPath.m_
treeScopeEventContexts[i].get(); | 245 TreeScopeEventContext* treeScopeEventContext = relatedTargetEventPath.m_
treeScopeEventContexts[i].get(); |
| 246 relatedTargetMap.add(&treeScopeEventContext->treeScope(), treeScopeEvent
Context->target()); | 246 relatedTargetMap.add(&treeScopeEventContext->treeScope(), treeScopeEvent
Context->target()); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 EventTarget* EventPath::findRelatedNode(TreeScope* scope, RelatedTargetMap& rela
tedTargetMap) | 250 EventTarget* EventPath::findRelatedNode(TreeScope* scope, RelatedTargetMap& rela
tedTargetMap) |
| 251 { | 251 { |
| 252 Vector<TreeScope*, 32> parentTreeScopes; | 252 WillBeHeapVector<RawPtrWillBeMember<TreeScope>, 32> parentTreeScopes; |
| 253 EventTarget* relatedNode = 0; | 253 EventTarget* relatedNode = 0; |
| 254 while (scope) { | 254 while (scope) { |
| 255 parentTreeScopes.append(scope); | 255 parentTreeScopes.append(scope); |
| 256 RelatedTargetMap::const_iterator iter = relatedTargetMap.find(scope); | 256 RelatedTargetMap::const_iterator iter = relatedTargetMap.find(scope); |
| 257 if (iter != relatedTargetMap.end() && iter->value) { | 257 if (iter != relatedTargetMap.end() && iter->value) { |
| 258 relatedNode = iter->value; | 258 relatedNode = iter->value; |
| 259 break; | 259 break; |
| 260 } | 260 } |
| 261 scope = scope->olderShadowRootOrParentTreeScope(); | 261 scope = scope->olderShadowRootOrParentTreeScope(); |
| 262 } | 262 } |
| 263 ASSERT(relatedNode); | 263 ASSERT(relatedNode); |
| 264 for (Vector<TreeScope*, 32>::iterator iter = parentTreeScopes.begin(); iter
< parentTreeScopes.end(); ++iter) | 264 for (WillBeHeapVector<RawPtrWillBeMember<TreeScope>, 32>::iterator iter = pa
rentTreeScopes.begin(); iter < parentTreeScopes.end(); ++iter) |
| 265 relatedTargetMap.add(*iter, relatedNode); | 265 relatedTargetMap.add(*iter, relatedNode); |
| 266 return relatedNode; | 266 return relatedNode; |
| 267 } | 267 } |
| 268 | 268 |
| 269 void EventPath::adjustForRelatedTarget(Node* target, EventTarget* relatedTarget) | 269 void EventPath::adjustForRelatedTarget(Node* target, EventTarget* relatedTarget) |
| 270 { | 270 { |
| 271 if (!target) | 271 if (!target) |
| 272 return; | 272 return; |
| 273 if (!relatedTarget) | 273 if (!relatedTarget) |
| 274 return; | 274 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 break; | 310 break; |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 void EventPath::adjustForTouchEvent(Node* node, TouchEvent& touchEvent) | 315 void EventPath::adjustForTouchEvent(Node* node, TouchEvent& touchEvent) |
| 316 { | 316 { |
| 317 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTouches; | 317 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTouches; |
| 318 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTargetTouches; | 318 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTargetTouches; |
| 319 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedChangedTouches; | 319 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedChangedTouches; |
| 320 Vector<TreeScope*> treeScopes; | 320 WillBeHeapVector<RawPtrWillBeMember<TreeScope> > treeScopes; |
| 321 | 321 |
| 322 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { | 322 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { |
| 323 TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->ensu
reTouchEventContext(); | 323 TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->ensu
reTouchEventContext(); |
| 324 adjustedTouches.append(&touchEventContext->touches()); | 324 adjustedTouches.append(&touchEventContext->touches()); |
| 325 adjustedTargetTouches.append(&touchEventContext->targetTouches()); | 325 adjustedTargetTouches.append(&touchEventContext->targetTouches()); |
| 326 adjustedChangedTouches.append(&touchEventContext->changedTouches()); | 326 adjustedChangedTouches.append(&touchEventContext->changedTouches()); |
| 327 treeScopes.append(&m_treeScopeEventContexts[i]->treeScope()); | 327 treeScopes.append(&m_treeScopeEventContexts[i]->treeScope()); |
| 328 } | 328 } |
| 329 | 329 |
| 330 adjustTouchList(node, touchEvent.touches(), adjustedTouches, treeScopes); | 330 adjustTouchList(node, touchEvent.touches(), adjustedTouches, treeScopes); |
| 331 adjustTouchList(node, touchEvent.targetTouches(), adjustedTargetTouches, tre
eScopes); | 331 adjustTouchList(node, touchEvent.targetTouches(), adjustedTargetTouches, tre
eScopes); |
| 332 adjustTouchList(node, touchEvent.changedTouches(), adjustedChangedTouches, t
reeScopes); | 332 adjustTouchList(node, touchEvent.changedTouches(), adjustedChangedTouches, t
reeScopes); |
| 333 | 333 |
| 334 #ifndef NDEBUG | 334 #ifndef NDEBUG |
| 335 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { | 335 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { |
| 336 TreeScope& treeScope = m_treeScopeEventContexts[i]->treeScope(); | 336 TreeScope& treeScope = m_treeScopeEventContexts[i]->treeScope(); |
| 337 TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->touc
hEventContext(); | 337 TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->touc
hEventContext(); |
| 338 checkReachability(treeScope, touchEventContext->touches()); | 338 checkReachability(treeScope, touchEventContext->touches()); |
| 339 checkReachability(treeScope, touchEventContext->targetTouches()); | 339 checkReachability(treeScope, touchEventContext->targetTouches()); |
| 340 checkReachability(treeScope, touchEventContext->changedTouches()); | 340 checkReachability(treeScope, touchEventContext->changedTouches()); |
| 341 } | 341 } |
| 342 #endif | 342 #endif |
| 343 } | 343 } |
| 344 | 344 |
| 345 void EventPath::adjustTouchList(const Node* node, const TouchList* touchList, Wi
llBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTouchList, const Vector<T
reeScope*>& treeScopes) | 345 void EventPath::adjustTouchList(const Node* node, const TouchList* touchList, Wi
llBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTouchList, const WillBeHe
apVector<RawPtrWillBeMember<TreeScope> >& treeScopes) |
| 346 { | 346 { |
| 347 if (!touchList) | 347 if (!touchList) |
| 348 return; | 348 return; |
| 349 for (size_t i = 0; i < touchList->length(); ++i) { | 349 for (size_t i = 0; i < touchList->length(); ++i) { |
| 350 const Touch& touch = *touchList->item(i); | 350 const Touch& touch = *touchList->item(i); |
| 351 RelatedTargetMap relatedNodeMap; | 351 RelatedTargetMap relatedNodeMap; |
| 352 buildRelatedNodeMap(touch.target()->toNode(), relatedNodeMap); | 352 buildRelatedNodeMap(touch.target()->toNode(), relatedNodeMap); |
| 353 for (size_t j = 0; j < treeScopes.size(); ++j) { | 353 for (size_t j = 0; j < treeScopes.size(); ++j) { |
| 354 adjustedTouchList[j]->append(touch.cloneWithNewTarget(findRelatedNod
e(treeScopes[j], relatedNodeMap))); | 354 adjustedTouchList[j]->append(touch.cloneWithNewTarget(findRelatedNod
e(treeScopes[j], relatedNodeMap))); |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 | 358 |
| 359 #ifndef NDEBUG | 359 #ifndef NDEBUG |
| 360 void EventPath::checkReachability(TreeScope& treeScope, TouchList& touchList) | 360 void EventPath::checkReachability(TreeScope& treeScope, TouchList& touchList) |
| 361 { | 361 { |
| 362 for (size_t i = 0; i < touchList.length(); ++i) | 362 for (size_t i = 0; i < touchList.length(); ++i) |
| 363 ASSERT(touchList.item(i)->target()->toNode()->treeScope().isInclusiveOld
erSiblingShadowRootOrAncestorTreeScopeOf(treeScope)); | 363 ASSERT(touchList.item(i)->target()->toNode()->treeScope().isInclusiveOld
erSiblingShadowRootOrAncestorTreeScopeOf(treeScope)); |
| 364 } | 364 } |
| 365 #endif | 365 #endif |
| 366 | 366 |
| 367 void EventPath::trace(Visitor* visitor) | 367 void EventPath::trace(Visitor* visitor) |
| 368 { | 368 { |
| 369 visitor->trace(m_nodeEventContexts); | 369 visitor->trace(m_nodeEventContexts); |
| 370 visitor->trace(m_node); |
| 370 visitor->trace(m_event); | 371 visitor->trace(m_event); |
| 372 visitor->trace(m_treeScopeEventContexts); |
| 371 } | 373 } |
| 372 | 374 |
| 373 } // namespace | 375 } // namespace |
| OLD | NEW |