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

Side by Side Diff: third_party/WebKit/Source/core/input/PointerEventManager.cpp

Issue 2709033003: Migrate WTF::HashMap::get() to ::at() (Closed)
Patch Set: rebase Created 3 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/input/PointerEventManager.h" 5 #include "core/input/PointerEventManager.h"
6 6
7 #include "core/dom/DocumentUserGestureToken.h" 7 #include "core/dom/DocumentUserGestureToken.h"
8 #include "core/dom/ElementTraversal.h" 8 #include "core/dom/ElementTraversal.h"
9 #include "core/dom/shadow/FlatTreeTraversal.h" 9 #include "core/dom/shadow/FlatTreeTraversal.h"
10 #include "core/events/MouseEvent.h" 10 #include "core/events/MouseEvent.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (!target) 143 if (!target)
144 return WebInputEventResult::NotHandled; 144 return WebInputEventResult::NotHandled;
145 145
146 // Set whether node under pointer has received pointerover or not. 146 // Set whether node under pointer has received pointerover or not.
147 const int pointerId = pointerEvent->pointerId(); 147 const int pointerId = pointerEvent->pointerId();
148 148
149 const AtomicString& eventType = pointerEvent->type(); 149 const AtomicString& eventType = pointerEvent->type();
150 if ((eventType == EventTypeNames::pointerout || 150 if ((eventType == EventTypeNames::pointerout ||
151 eventType == EventTypeNames::pointerover) && 151 eventType == EventTypeNames::pointerover) &&
152 m_nodeUnderPointer.contains(pointerId)) { 152 m_nodeUnderPointer.contains(pointerId)) {
153 EventTarget* targetUnderPointer = m_nodeUnderPointer.get(pointerId).target; 153 EventTarget* targetUnderPointer = m_nodeUnderPointer.at(pointerId).target;
154 if (targetUnderPointer == target) { 154 if (targetUnderPointer == target) {
155 m_nodeUnderPointer.set( 155 m_nodeUnderPointer.set(
156 pointerId, 156 pointerId,
157 EventTargetAttributes(targetUnderPointer, 157 EventTargetAttributes(targetUnderPointer,
158 eventType == EventTypeNames::pointerover)); 158 eventType == EventTypeNames::pointerover));
159 } 159 }
160 } 160 }
161 161
162 if (!RuntimeEnabledFeatures::pointerEventEnabled()) 162 if (!RuntimeEnabledFeatures::pointerEventEnabled())
163 return WebInputEventResult::NotHandled; 163 return WebInputEventResult::NotHandled;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 PointerEvent* pointerEvent) { 212 PointerEvent* pointerEvent) {
213 PointerEventBoundaryEventDispatcher boundaryEventDispatcher(this, 213 PointerEventBoundaryEventDispatcher boundaryEventDispatcher(this,
214 pointerEvent); 214 pointerEvent);
215 boundaryEventDispatcher.sendBoundaryEvents(exitedTarget, enteredTarget); 215 boundaryEventDispatcher.sendBoundaryEvents(exitedTarget, enteredTarget);
216 } 216 }
217 217
218 void PointerEventManager::setNodeUnderPointer(PointerEvent* pointerEvent, 218 void PointerEventManager::setNodeUnderPointer(PointerEvent* pointerEvent,
219 EventTarget* target) { 219 EventTarget* target) {
220 if (m_nodeUnderPointer.contains(pointerEvent->pointerId())) { 220 if (m_nodeUnderPointer.contains(pointerEvent->pointerId())) {
221 EventTargetAttributes node = 221 EventTargetAttributes node =
222 m_nodeUnderPointer.get(pointerEvent->pointerId()); 222 m_nodeUnderPointer.at(pointerEvent->pointerId());
223 if (!target) { 223 if (!target) {
224 m_nodeUnderPointer.erase(pointerEvent->pointerId()); 224 m_nodeUnderPointer.erase(pointerEvent->pointerId());
225 } else if (target != 225 } else if (target !=
226 m_nodeUnderPointer.get(pointerEvent->pointerId()).target) { 226 m_nodeUnderPointer.at(pointerEvent->pointerId()).target) {
227 m_nodeUnderPointer.set(pointerEvent->pointerId(), 227 m_nodeUnderPointer.set(pointerEvent->pointerId(),
228 EventTargetAttributes(target, false)); 228 EventTargetAttributes(target, false));
229 } 229 }
230 sendBoundaryEvents(node.target, target, pointerEvent); 230 sendBoundaryEvents(node.target, target, pointerEvent);
231 } else if (target) { 231 } else if (target) {
232 m_nodeUnderPointer.insert(pointerEvent->pointerId(), 232 m_nodeUnderPointer.insert(pointerEvent->pointerId(),
233 EventTargetAttributes(target, false)); 233 EventTargetAttributes(target, false));
234 sendBoundaryEvents(nullptr, target, pointerEvent); 234 sendBoundaryEvents(nullptr, target, pointerEvent);
235 } 235 }
236 } 236 }
237 237
238 void PointerEventManager::blockTouchPointers() { 238 void PointerEventManager::blockTouchPointers() {
239 if (m_inCanceledStateForPointerTypeTouch) 239 if (m_inCanceledStateForPointerTypeTouch)
240 return; 240 return;
241 m_inCanceledStateForPointerTypeTouch = true; 241 m_inCanceledStateForPointerTypeTouch = true;
242 242
243 Vector<int> touchPointerIds = m_pointerEventFactory.getPointerIdsOfType( 243 Vector<int> touchPointerIds = m_pointerEventFactory.getPointerIdsOfType(
244 WebPointerProperties::PointerType::Touch); 244 WebPointerProperties::PointerType::Touch);
245 245
246 for (int pointerId : touchPointerIds) { 246 for (int pointerId : touchPointerIds) {
247 PointerEvent* pointerEvent = m_pointerEventFactory.createPointerCancelEvent( 247 PointerEvent* pointerEvent = m_pointerEventFactory.createPointerCancelEvent(
248 pointerId, WebPointerProperties::PointerType::Touch); 248 pointerId, WebPointerProperties::PointerType::Touch);
249 249
250 DCHECK(m_nodeUnderPointer.contains(pointerId)); 250 DCHECK(m_nodeUnderPointer.contains(pointerId));
251 EventTarget* target = m_nodeUnderPointer.get(pointerId).target; 251 EventTarget* target = m_nodeUnderPointer.at(pointerId).target;
252 252
253 processCaptureAndPositionOfPointerEvent(pointerEvent, target); 253 processCaptureAndPositionOfPointerEvent(pointerEvent, target);
254 254
255 // TODO(nzolghadr): This event follows implicit TE capture. The actual 255 // TODO(nzolghadr): This event follows implicit TE capture. The actual
256 // target would depend on PE capturing. Perhaps need to split TE/PE event 256 // target would depend on PE capturing. Perhaps need to split TE/PE event
257 // path upstream? crbug.com/579553. 257 // path upstream? crbug.com/579553.
258 dispatchPointerEvent( 258 dispatchPointerEvent(
259 getEffectiveTargetForPointerEvent(target, pointerEvent->pointerId()), 259 getEffectiveTargetForPointerEvent(target, pointerEvent->pointerId()),
260 pointerEvent); 260 pointerEvent);
261 261
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // refactor it better after this investigation. 360 // refactor it better after this investigation.
361 if (node->isTextNode()) 361 if (node->isTextNode())
362 node = FlatTreeTraversal::parent(*node); 362 node = FlatTreeTraversal::parent(*node);
363 touchInfo.touchNode = node; 363 touchInfo.touchNode = node;
364 } 364 }
365 } else { 365 } else {
366 // Set the target of pointer event to the captured node as this 366 // Set the target of pointer event to the captured node as this
367 // pointer is captured otherwise it would have gone to the if block 367 // pointer is captured otherwise it would have gone to the if block
368 // and perform a hit-test. 368 // and perform a hit-test.
369 touchInfo.touchNode = 369 touchInfo.touchNode =
370 m_pendingPointerCaptureTarget.get(pointerId)->toNode(); 370 m_pendingPointerCaptureTarget.at(pointerId)->toNode();
371 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); 371 touchInfo.targetFrame = touchInfo.touchNode->document().frame();
372 } 372 }
373 373
374 touchInfos.push_back(touchInfo); 374 touchInfos.push_back(touchInfo);
375 } 375 }
376 } 376 }
377 377
378 void PointerEventManager::dispatchTouchPointerEvents( 378 void PointerEventManager::dispatchTouchPointerEvents(
379 const WebTouchEvent& event, 379 const WebTouchEvent& event,
380 const Vector<WebTouchEvent>& coalescedEvents, 380 const Vector<WebTouchEvent>& coalescedEvents,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // active pointer or pointer captures at the same time. 606 // active pointer or pointer captures at the same time.
607 PointerCapturingMap tmp = map; 607 PointerCapturingMap tmp = map;
608 for (PointerCapturingMap::iterator it = tmp.begin(); it != tmp.end(); ++it) { 608 for (PointerCapturingMap::iterator it = tmp.begin(); it != tmp.end(); ++it) {
609 if (it->value == target) 609 if (it->value == target)
610 map.erase(it->key); 610 map.erase(it->key);
611 } 611 }
612 } 612 }
613 613
614 EventTarget* PointerEventManager::getCapturingNode(int pointerId) { 614 EventTarget* PointerEventManager::getCapturingNode(int pointerId) {
615 if (m_pointerCaptureTarget.contains(pointerId)) 615 if (m_pointerCaptureTarget.contains(pointerId))
616 return m_pointerCaptureTarget.get(pointerId); 616 return m_pointerCaptureTarget.at(pointerId);
617 return nullptr; 617 return nullptr;
618 } 618 }
619 619
620 void PointerEventManager::removePointer(PointerEvent* pointerEvent) { 620 void PointerEventManager::removePointer(PointerEvent* pointerEvent) {
621 int pointerId = pointerEvent->pointerId(); 621 int pointerId = pointerEvent->pointerId();
622 if (m_pointerEventFactory.remove(pointerId)) { 622 if (m_pointerEventFactory.remove(pointerId)) {
623 m_pendingPointerCaptureTarget.erase(pointerId); 623 m_pendingPointerCaptureTarget.erase(pointerId);
624 m_pointerCaptureTarget.erase(pointerId); 624 m_pointerCaptureTarget.erase(pointerId);
625 m_nodeUnderPointer.erase(pointerId); 625 m_nodeUnderPointer.erase(pointerId);
626 } 626 }
(...skipping 18 matching lines...) Expand all
645 645
646 void PointerEventManager::releasePointerCapture(int pointerId, 646 void PointerEventManager::releasePointerCapture(int pointerId,
647 EventTarget* target) { 647 EventTarget* target) {
648 // Only the element that is going to get the next pointer event can release 648 // Only the element that is going to get the next pointer event can release
649 // the capture. Note that this might be different from 649 // the capture. Note that this might be different from
650 // |m_pointercaptureTarget|. |m_pointercaptureTarget| holds the element 650 // |m_pointercaptureTarget|. |m_pointercaptureTarget| holds the element
651 // that had the capture until now and has been receiving the pointerevents 651 // that had the capture until now and has been receiving the pointerevents
652 // but |m_pendingPointerCaptureTarget| indicated the element that gets the 652 // but |m_pendingPointerCaptureTarget| indicated the element that gets the
653 // very next pointer event. They will be the same if there was no change in 653 // very next pointer event. They will be the same if there was no change in
654 // capturing of a particular |pointerId|. See crbug.com/614481. 654 // capturing of a particular |pointerId|. See crbug.com/614481.
655 if (m_pendingPointerCaptureTarget.get(pointerId) == target) 655 if (m_pendingPointerCaptureTarget.at(pointerId) == target)
656 releasePointerCapture(pointerId); 656 releasePointerCapture(pointerId);
657 } 657 }
658 658
659 bool PointerEventManager::hasPointerCapture(int pointerId, 659 bool PointerEventManager::hasPointerCapture(int pointerId,
660 const EventTarget* target) const { 660 const EventTarget* target) const {
661 return m_pendingPointerCaptureTarget.get(pointerId) == target; 661 return m_pendingPointerCaptureTarget.at(pointerId) == target;
662 } 662 }
663 663
664 bool PointerEventManager::hasProcessedPointerCapture( 664 bool PointerEventManager::hasProcessedPointerCapture(
665 int pointerId, 665 int pointerId,
666 const EventTarget* target) const { 666 const EventTarget* target) const {
667 return m_pointerCaptureTarget.get(pointerId) == target; 667 return m_pointerCaptureTarget.at(pointerId) == target;
668 } 668 }
669 669
670 void PointerEventManager::releasePointerCapture(int pointerId) { 670 void PointerEventManager::releasePointerCapture(int pointerId) {
671 m_pendingPointerCaptureTarget.erase(pointerId); 671 m_pendingPointerCaptureTarget.erase(pointerId);
672 } 672 }
673 673
674 bool PointerEventManager::isActive(const int pointerId) const { 674 bool PointerEventManager::isActive(const int pointerId) const {
675 return m_pointerEventFactory.isActive(pointerId); 675 return m_pointerEventFactory.isActive(pointerId);
676 } 676 }
677 677
678 // This function checks the type of the pointer event to be touch as touch 678 // This function checks the type of the pointer event to be touch as touch
679 // pointer events are the only ones that are directly dispatched from the main 679 // pointer events are the only ones that are directly dispatched from the main
680 // page managers to their target (event if target is in an iframe) and only 680 // page managers to their target (event if target is in an iframe) and only
681 // those managers will keep track of these pointer events. 681 // those managers will keep track of these pointer events.
682 bool PointerEventManager::isTouchPointerIdActiveOnFrame( 682 bool PointerEventManager::isTouchPointerIdActiveOnFrame(
683 int pointerId, 683 int pointerId,
684 LocalFrame* frame) const { 684 LocalFrame* frame) const {
685 if (m_pointerEventFactory.getPointerType(pointerId) != 685 if (m_pointerEventFactory.getPointerType(pointerId) !=
686 WebPointerProperties::PointerType::Touch) 686 WebPointerProperties::PointerType::Touch)
687 return false; 687 return false;
688 Node* lastNodeReceivingEvent = 688 Node* lastNodeReceivingEvent =
689 m_nodeUnderPointer.contains(pointerId) 689 m_nodeUnderPointer.contains(pointerId)
690 ? m_nodeUnderPointer.get(pointerId).target->toNode() 690 ? m_nodeUnderPointer.at(pointerId).target->toNode()
691 : nullptr; 691 : nullptr;
692 return lastNodeReceivingEvent && 692 return lastNodeReceivingEvent &&
693 lastNodeReceivingEvent->document().frame() == frame; 693 lastNodeReceivingEvent->document().frame() == frame;
694 } 694 }
695 695
696 bool PointerEventManager::isAnyTouchActive() const { 696 bool PointerEventManager::isAnyTouchActive() const {
697 return m_touchEventManager->isAnyTouchActive(); 697 return m_touchEventManager->isAnyTouchActive();
698 } 698 }
699 699
700 bool PointerEventManager::primaryPointerdownCanceled( 700 bool PointerEventManager::primaryPointerdownCanceled(
701 uint32_t uniqueTouchEventId) { 701 uint32_t uniqueTouchEventId) {
702 // It's safe to assume that uniqueTouchEventIds won't wrap back to 0 from 702 // It's safe to assume that uniqueTouchEventIds won't wrap back to 0 from
703 // 2^32-1 (>4.2 billion): even with a generous 100 unique ids per touch 703 // 2^32-1 (>4.2 billion): even with a generous 100 unique ids per touch
704 // sequence & one sequence per 10 second, it takes 13+ years to wrap back. 704 // sequence & one sequence per 10 second, it takes 13+ years to wrap back.
705 while (!m_touchIdsForCanceledPointerdowns.isEmpty()) { 705 while (!m_touchIdsForCanceledPointerdowns.isEmpty()) {
706 uint32_t firstId = m_touchIdsForCanceledPointerdowns.first(); 706 uint32_t firstId = m_touchIdsForCanceledPointerdowns.first();
707 if (firstId > uniqueTouchEventId) 707 if (firstId > uniqueTouchEventId)
708 return false; 708 return false;
709 m_touchIdsForCanceledPointerdowns.takeFirst(); 709 m_touchIdsForCanceledPointerdowns.takeFirst();
710 if (firstId == uniqueTouchEventId) 710 if (firstId == uniqueTouchEventId)
711 return true; 711 return true;
712 } 712 }
713 return false; 713 return false;
714 } 714 }
715 715
716 } // namespace blink 716 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/track/vtt/VTTCue.cpp ('k') | third_party/WebKit/Source/core/input/TouchEventManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698