Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: Source/core/events/EventPath.cpp

Issue 637223008: Use C++11 range-based loop in core/events (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/events/EventPath.h ('k') | Source/core/events/EventSender.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 Node* current = m_node; 104 Node* current = m_node;
105 addNodeEventContext(current); 105 addNodeEventContext(current);
106 if (!m_node->inDocument()) 106 if (!m_node->inDocument())
107 return; 107 return;
108 while (current) { 108 while (current) {
109 if (m_event && current->keepEventInNode(m_event)) 109 if (m_event && current->keepEventInNode(m_event))
110 break; 110 break;
111 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints; 111 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints;
112 collectDestinationInsertionPoints(*current, insertionPoints); 112 collectDestinationInsertionPoints(*current, insertionPoints);
113 if (!insertionPoints.isEmpty()) { 113 if (!insertionPoints.isEmpty()) {
114 for (size_t i = 0; i < insertionPoints.size(); ++i) { 114 for (const auto& insertionPoint : insertionPoints) {
115 InsertionPoint* insertionPoint = insertionPoints[i];
116 if (insertionPoint->isShadowInsertionPoint()) { 115 if (insertionPoint->isShadowInsertionPoint()) {
117 ShadowRoot* containingShadowRoot = insertionPoint->containin gShadowRoot(); 116 ShadowRoot* containingShadowRoot = insertionPoint->containin gShadowRoot();
118 ASSERT(containingShadowRoot); 117 ASSERT(containingShadowRoot);
119 if (!containingShadowRoot->isOldest()) 118 if (!containingShadowRoot->isOldest())
120 addNodeEventContext(containingShadowRoot->olderShadowRoo t()); 119 addNodeEventContext(containingShadowRoot->olderShadowRoo t());
121 } 120 }
122 addNodeEventContext(insertionPoint); 121 addNodeEventContext(insertionPoint);
123 } 122 }
124 current = insertionPoints.last(); 123 current = insertionPoints.last();
125 continue; 124 continue;
126 } 125 }
127 if (current->isShadowRoot()) { 126 if (current->isShadowRoot()) {
128 if (m_event && shouldStopAtShadowRoot(*m_event, *toShadowRoot(curren t), *m_node)) 127 if (m_event && shouldStopAtShadowRoot(*m_event, *toShadowRoot(curren t), *m_node))
129 break; 128 break;
130 current = current->shadowHost(); 129 current = current->shadowHost();
131 addNodeEventContext(current); 130 addNodeEventContext(current);
132 } else { 131 } else {
133 current = current->parentNode(); 132 current = current->parentNode();
134 if (current) 133 if (current)
135 addNodeEventContext(current); 134 addNodeEventContext(current);
136 } 135 }
137 } 136 }
138 } 137 }
139 138
140 void EventPath::calculateTreeScopePrePostOrderNumbers() 139 void EventPath::calculateTreeScopePrePostOrderNumbers()
141 { 140 {
142 // Precondition: 141 // Precondition:
143 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the sam e tree of trees. 142 // - TreeScopes in m_treeScopeEventContexts must be *connected* in the sam e tree of trees.
144 // - The root tree must be included. 143 // - The root tree must be included.
145 WillBeHeapHashMap<RawPtrWillBeMember<const TreeScope>, RawPtrWillBeMember<Tr eeScopeEventContext> > treeScopeEventContextMap; 144 WillBeHeapHashMap<RawPtrWillBeMember<const TreeScope>, RawPtrWillBeMember<Tr eeScopeEventContext>> treeScopeEventContextMap;
146 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) 145 for (const auto& treeScopeEventContext : m_treeScopeEventContexts)
147 treeScopeEventContextMap.add(&m_treeScopeEventContexts[i]->treeScope(), m_treeScopeEventContexts[i].get()); 146 treeScopeEventContextMap.add(&treeScopeEventContext->treeScope(), treeSc opeEventContext.get());
148 TreeScopeEventContext* rootTree = 0; 147 TreeScopeEventContext* rootTree = 0;
149 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { 148 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) {
150 TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[ i].get();
151 // Use olderShadowRootOrParentTreeScope here for parent-child relationsh ips. 149 // Use olderShadowRootOrParentTreeScope here for parent-child relationsh ips.
152 // See the definition of trees of trees in the Shado DOM spec: http://w3 c.github.io/webcomponents/spec/shadow/ 150 // See the definition of trees of trees in the Shado DOM spec: http://w3 c.github.io/webcomponents/spec/shadow/
153 TreeScope* parent = treeScopeEventContext->treeScope().olderShadowRootOr ParentTreeScope(); 151 TreeScope* parent = treeScopeEventContext.get()->treeScope().olderShadow RootOrParentTreeScope();
154 if (!parent) { 152 if (!parent) {
155 ASSERT(!rootTree); 153 ASSERT(!rootTree);
156 rootTree = treeScopeEventContext; 154 rootTree = treeScopeEventContext.get();
157 continue; 155 continue;
158 } 156 }
159 ASSERT(treeScopeEventContextMap.find(parent) != treeScopeEventContextMap .end()); 157 ASSERT(treeScopeEventContextMap.find(parent) != treeScopeEventContextMap .end());
160 treeScopeEventContextMap.find(parent)->value->addChild(*treeScopeEventCo ntext); 158 treeScopeEventContextMap.find(parent)->value->addChild(*treeScopeEventCo ntext.get());
161 } 159 }
162 ASSERT(rootTree); 160 ASSERT(rootTree);
163 rootTree->calculatePrePostOrderNumber(0); 161 rootTree->calculatePrePostOrderNumber(0);
164 } 162 }
165 163
166 TreeScopeEventContext* EventPath::ensureTreeScopeEventContext(Node* currentTarge t, TreeScope* treeScope, TreeScopeEventContextMap& treeScopeEventContextMap) 164 TreeScopeEventContext* EventPath::ensureTreeScopeEventContext(Node* currentTarge t, TreeScope* treeScope, TreeScopeEventContextMap& treeScopeEventContextMap)
167 { 165 {
168 if (!treeScope) 166 if (!treeScope)
169 return 0; 167 return 0;
170 TreeScopeEventContext* treeScopeEventContext; 168 TreeScopeEventContext* treeScopeEventContext;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (!relatedNode) 245 if (!relatedNode)
248 return; 246 return;
249 if (target->document() != relatedNode->document()) 247 if (target->document() != relatedNode->document())
250 return; 248 return;
251 if (!target->inDocument() || !relatedNode->inDocument()) 249 if (!target->inDocument() || !relatedNode->inDocument())
252 return; 250 return;
253 251
254 RelatedTargetMap relatedNodeMap; 252 RelatedTargetMap relatedNodeMap;
255 buildRelatedNodeMap(relatedNode, relatedNodeMap); 253 buildRelatedNodeMap(relatedNode, relatedNodeMap);
256 254
257 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { 255 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) {
258 TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[ i].get(); 256 EventTarget* adjustedRelatedTarget = findRelatedNode(&treeScopeEventCont ext.get()->treeScope(), relatedNodeMap);
259 EventTarget* adjustedRelatedTarget = findRelatedNode(&treeScopeEventCont ext->treeScope(), relatedNodeMap);
260 ASSERT(adjustedRelatedTarget); 257 ASSERT(adjustedRelatedTarget);
261 treeScopeEventContext->setRelatedTarget(adjustedRelatedTarget); 258 treeScopeEventContext.get()->setRelatedTarget(adjustedRelatedTarget);
262 } 259 }
263 260
264 shrinkIfNeeded(target, relatedTarget); 261 shrinkIfNeeded(target, relatedTarget);
265 } 262 }
266 263
267 void EventPath::shrinkIfNeeded(const Node* target, const EventTarget* relatedTar get) 264 void EventPath::shrinkIfNeeded(const Node* target, const EventTarget* relatedTar get)
268 { 265 {
269 // Synthetic mouse events can have a relatedTarget which is identical to the target. 266 // Synthetic mouse events can have a relatedTarget which is identical to the target.
270 bool targetIsIdenticalToToRelatedTarget = (target == relatedTarget); 267 bool targetIsIdenticalToToRelatedTarget = (target == relatedTarget);
271 268
272 for (size_t i = 0; i < size(); ++i) { 269 for (size_t i = 0; i < size(); ++i) {
273 if (targetIsIdenticalToToRelatedTarget) { 270 if (targetIsIdenticalToToRelatedTarget) {
274 if (target->treeScope().rootNode() == at(i).node()) { 271 if (target->treeScope().rootNode() == at(i).node()) {
275 shrink(i + 1); 272 shrink(i + 1);
276 break; 273 break;
277 } 274 }
278 } else if (at(i).target() == at(i).relatedTarget()) { 275 } else if (at(i).target() == at(i).relatedTarget()) {
279 // Event dispatching should be stopped here. 276 // Event dispatching should be stopped here.
280 shrink(i); 277 shrink(i);
281 break; 278 break;
282 } 279 }
283 } 280 }
284 } 281 }
285 282
286 void EventPath::adjustForTouchEvent(Node* node, TouchEvent& touchEvent) 283 void EventPath::adjustForTouchEvent(Node* node, TouchEvent& touchEvent)
287 { 284 {
288 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTouches; 285 WillBeHeapVector<RawPtrWillBeMember<TouchList>> adjustedTouches;
289 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTargetTouches; 286 WillBeHeapVector<RawPtrWillBeMember<TouchList>> adjustedTargetTouches;
290 WillBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedChangedTouches; 287 WillBeHeapVector<RawPtrWillBeMember<TouchList>> adjustedChangedTouches;
291 WillBeHeapVector<RawPtrWillBeMember<TreeScope> > treeScopes; 288 WillBeHeapVector<RawPtrWillBeMember<TreeScope>> treeScopes;
292 289
293 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { 290 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) {
294 TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->ensu reTouchEventContext(); 291 TouchEventContext* touchEventContext = treeScopeEventContext->ensureTouc hEventContext();
295 adjustedTouches.append(&touchEventContext->touches()); 292 adjustedTouches.append(&touchEventContext->touches());
296 adjustedTargetTouches.append(&touchEventContext->targetTouches()); 293 adjustedTargetTouches.append(&touchEventContext->targetTouches());
297 adjustedChangedTouches.append(&touchEventContext->changedTouches()); 294 adjustedChangedTouches.append(&touchEventContext->changedTouches());
298 treeScopes.append(&m_treeScopeEventContexts[i]->treeScope()); 295 treeScopes.append(&treeScopeEventContext->treeScope());
299 } 296 }
300 297
301 adjustTouchList(node, touchEvent.touches(), adjustedTouches, treeScopes); 298 adjustTouchList(node, touchEvent.touches(), adjustedTouches, treeScopes);
302 adjustTouchList(node, touchEvent.targetTouches(), adjustedTargetTouches, tre eScopes); 299 adjustTouchList(node, touchEvent.targetTouches(), adjustedTargetTouches, tre eScopes);
303 adjustTouchList(node, touchEvent.changedTouches(), adjustedChangedTouches, t reeScopes); 300 adjustTouchList(node, touchEvent.changedTouches(), adjustedChangedTouches, t reeScopes);
304 301
305 #if ENABLE(ASSERT) 302 #if ENABLE(ASSERT)
306 for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) { 303 for (const auto& treeScopeEventContext : m_treeScopeEventContexts) {
307 TreeScope& treeScope = m_treeScopeEventContexts[i]->treeScope(); 304 TreeScope& treeScope = treeScopeEventContext->treeScope();
308 TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->touc hEventContext(); 305 TouchEventContext* touchEventContext = treeScopeEventContext->touchEvent Context();
309 checkReachability(treeScope, touchEventContext->touches()); 306 checkReachability(treeScope, touchEventContext->touches());
310 checkReachability(treeScope, touchEventContext->targetTouches()); 307 checkReachability(treeScope, touchEventContext->targetTouches());
311 checkReachability(treeScope, touchEventContext->changedTouches()); 308 checkReachability(treeScope, touchEventContext->changedTouches());
312 } 309 }
313 #endif 310 #endif
314 } 311 }
315 312
316 void EventPath::adjustTouchList(const Node* node, const TouchList* touchList, Wi llBeHeapVector<RawPtrWillBeMember<TouchList> > adjustedTouchList, const WillBeHe apVector<RawPtrWillBeMember<TreeScope> >& treeScopes) 313 void EventPath::adjustTouchList(const Node* node, const TouchList* touchList, Wi llBeHeapVector<RawPtrWillBeMember<TouchList>> adjustedTouchList, const WillBeHea pVector<RawPtrWillBeMember<TreeScope>>& treeScopes)
317 { 314 {
318 if (!touchList) 315 if (!touchList)
319 return; 316 return;
320 for (size_t i = 0; i < touchList->length(); ++i) { 317 for (size_t i = 0; i < touchList->length(); ++i) {
321 const Touch& touch = *touchList->item(i); 318 const Touch& touch = *touchList->item(i);
322 RelatedTargetMap relatedNodeMap; 319 RelatedTargetMap relatedNodeMap;
323 buildRelatedNodeMap(touch.target()->toNode(), relatedNodeMap); 320 buildRelatedNodeMap(touch.target()->toNode(), relatedNodeMap);
324 for (size_t j = 0; j < treeScopes.size(); ++j) { 321 for (size_t j = 0; j < treeScopes.size(); ++j) {
325 adjustedTouchList[j]->append(touch.cloneWithNewTarget(findRelatedNod e(treeScopes[j], relatedNodeMap))); 322 adjustedTouchList[j]->append(touch.cloneWithNewTarget(findRelatedNod e(treeScopes[j], relatedNodeMap)));
326 } 323 }
(...skipping 10 matching lines...) Expand all
337 334
338 void EventPath::trace(Visitor* visitor) 335 void EventPath::trace(Visitor* visitor)
339 { 336 {
340 visitor->trace(m_nodeEventContexts); 337 visitor->trace(m_nodeEventContexts);
341 visitor->trace(m_node); 338 visitor->trace(m_node);
342 visitor->trace(m_event); 339 visitor->trace(m_event);
343 visitor->trace(m_treeScopeEventContexts); 340 visitor->trace(m_treeScopeEventContexts);
344 } 341 }
345 342
346 } // namespace 343 } // namespace
OLDNEW
« no previous file with comments | « Source/core/events/EventPath.h ('k') | Source/core/events/EventSender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698