OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 namespace { | 26 namespace { |
27 | 27 |
28 size_t ToPointerTypeIndex(WebPointerProperties::PointerType t) { | 28 size_t ToPointerTypeIndex(WebPointerProperties::PointerType t) { |
29 return static_cast<size_t>(t); | 29 return static_cast<size_t>(t); |
30 } | 30 } |
31 | 31 |
32 bool IsInDocument(EventTarget* n) { | 32 bool IsInDocument(EventTarget* n) { |
33 return n && n->ToNode() && n->ToNode()->isConnected(); | 33 return n && n->ToNode() && n->ToNode()->isConnected(); |
34 } | 34 } |
35 | 35 |
36 Vector<WebTouchPoint> GetCoalescedPoints( | 36 Vector<std::pair<WebTouchPoint, TimeTicks>> GetCoalescedPoints( |
37 const Vector<WebTouchEvent>& coalesced_events, | 37 const Vector<WebTouchEvent>& coalesced_events, |
38 int id) { | 38 int id) { |
39 Vector<WebTouchPoint> related_points; | 39 Vector<std::pair<WebTouchPoint, TimeTicks>> related_points; |
40 for (const auto& touch_event : coalesced_events) { | 40 for (const auto& touch_event : coalesced_events) { |
41 for (unsigned i = 0; i < touch_event.touches_length; ++i) { | 41 for (unsigned i = 0; i < touch_event.touches_length; ++i) { |
42 if (touch_event.touches[i].id == id && | 42 if (touch_event.touches[i].id == id && |
43 touch_event.touches[i].state != WebTouchPoint::kStateStationary) | 43 touch_event.touches[i].state != WebTouchPoint::kStateStationary) { |
44 related_points.push_back(touch_event.TouchPointInRootFrame(i)); | 44 related_points.push_back(std::pair<WebTouchPoint, TimeTicks>( |
| 45 touch_event.TouchPointInRootFrame(i), |
| 46 TimeTicks::FromSeconds(touch_event.TimeStampSeconds()))); |
| 47 } |
45 } | 48 } |
46 } | 49 } |
47 return related_points; | 50 return related_points; |
48 } | 51 } |
49 | 52 |
50 } // namespace | 53 } // namespace |
51 | 54 |
52 PointerEventManager::PointerEventManager(LocalFrame& frame, | 55 PointerEventManager::PointerEventManager(LocalFrame& frame, |
53 MouseEventManager& mouse_event_manager) | 56 MouseEventManager& mouse_event_manager) |
54 : frame_(frame), | 57 : frame_(frame), |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 EventTargetAttributes(target, false)); | 232 EventTargetAttributes(target, false)); |
230 } | 233 } |
231 SendBoundaryEvents(node.target, target, pointer_event); | 234 SendBoundaryEvents(node.target, target, pointer_event); |
232 } else if (target) { | 235 } else if (target) { |
233 node_under_pointer_.insert(pointer_event->pointerId(), | 236 node_under_pointer_.insert(pointer_event->pointerId(), |
234 EventTargetAttributes(target, false)); | 237 EventTargetAttributes(target, false)); |
235 SendBoundaryEvents(nullptr, target, pointer_event); | 238 SendBoundaryEvents(nullptr, target, pointer_event); |
236 } | 239 } |
237 } | 240 } |
238 | 241 |
239 void PointerEventManager::BlockTouchPointers() { | 242 void PointerEventManager::BlockTouchPointers(TimeTicks platform_time_stamp) { |
240 if (in_canceled_state_for_pointer_type_touch_) | 243 if (in_canceled_state_for_pointer_type_touch_) |
241 return; | 244 return; |
242 in_canceled_state_for_pointer_type_touch_ = true; | 245 in_canceled_state_for_pointer_type_touch_ = true; |
243 | 246 |
244 Vector<int> touch_pointer_ids = pointer_event_factory_.GetPointerIdsOfType( | 247 Vector<int> touch_pointer_ids = pointer_event_factory_.GetPointerIdsOfType( |
245 WebPointerProperties::PointerType::kTouch); | 248 WebPointerProperties::PointerType::kTouch); |
246 | 249 |
247 for (int pointer_id : touch_pointer_ids) { | 250 for (int pointer_id : touch_pointer_ids) { |
248 PointerEvent* pointer_event = | 251 PointerEvent* pointer_event = |
249 pointer_event_factory_.CreatePointerCancelEvent( | 252 pointer_event_factory_.CreatePointerCancelEvent( |
250 pointer_id, WebPointerProperties::PointerType::kTouch); | 253 pointer_id, WebPointerProperties::PointerType::kTouch, |
| 254 platform_time_stamp); |
251 | 255 |
252 DCHECK(node_under_pointer_.Contains(pointer_id)); | 256 DCHECK(node_under_pointer_.Contains(pointer_id)); |
253 EventTarget* target = node_under_pointer_.at(pointer_id).target; | 257 EventTarget* target = node_under_pointer_.at(pointer_id).target; |
254 | 258 |
255 ProcessCaptureAndPositionOfPointerEvent(pointer_event, target); | 259 ProcessCaptureAndPositionOfPointerEvent(pointer_event, target); |
256 | 260 |
257 // TODO(nzolghadr): This event follows implicit TE capture. The actual | 261 // TODO(nzolghadr): This event follows implicit TE capture. The actual |
258 // target would depend on PE capturing. Perhaps need to split TE/PE event | 262 // target would depend on PE capturing. Perhaps need to split TE/PE event |
259 // path upstream? crbug.com/579553. | 263 // path upstream? crbug.com/579553. |
260 DispatchPointerEvent( | 264 DispatchPointerEvent( |
(...skipping 12 matching lines...) Expand all Loading... |
273 } | 277 } |
274 | 278 |
275 void PointerEventManager::UnblockTouchPointers() { | 279 void PointerEventManager::UnblockTouchPointers() { |
276 in_canceled_state_for_pointer_type_touch_ = false; | 280 in_canceled_state_for_pointer_type_touch_ = false; |
277 } | 281 } |
278 | 282 |
279 WebInputEventResult PointerEventManager::HandleTouchEvents( | 283 WebInputEventResult PointerEventManager::HandleTouchEvents( |
280 const WebTouchEvent& event, | 284 const WebTouchEvent& event, |
281 const Vector<WebTouchEvent>& coalesced_events) { | 285 const Vector<WebTouchEvent>& coalesced_events) { |
282 if (event.GetType() == WebInputEvent::kTouchScrollStarted) { | 286 if (event.GetType() == WebInputEvent::kTouchScrollStarted) { |
283 BlockTouchPointers(); | 287 BlockTouchPointers(TimeTicks::FromSeconds(event.TimeStampSeconds())); |
284 return WebInputEventResult::kHandledSystem; | 288 return WebInputEventResult::kHandledSystem; |
285 } | 289 } |
286 | 290 |
287 bool new_touch_sequence = true; | 291 bool new_touch_sequence = true; |
288 for (unsigned i = 0; i < event.touches_length; ++i) { | 292 for (unsigned i = 0; i < event.touches_length; ++i) { |
289 if (event.touches[i].state != WebTouchPoint::kStatePressed) { | 293 if (event.touches[i].state != WebTouchPoint::kStatePressed) { |
290 new_touch_sequence = false; | 294 new_touch_sequence = false; |
291 break; | 295 break; |
292 } | 296 } |
293 } | 297 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 // required. | 389 // required. |
386 for (auto touch_info : touch_infos) { | 390 for (auto touch_info : touch_infos) { |
387 const WebTouchPoint& touch_point = touch_info.point; | 391 const WebTouchPoint& touch_point = touch_info.point; |
388 // Do not send pointer events for stationary touches or null targetFrame | 392 // Do not send pointer events for stationary touches or null targetFrame |
389 if (touch_info.touch_node && touch_info.target_frame && | 393 if (touch_info.touch_node && touch_info.target_frame && |
390 touch_point.state != WebTouchPoint::kStateStationary && | 394 touch_point.state != WebTouchPoint::kStateStationary && |
391 !in_canceled_state_for_pointer_type_touch_) { | 395 !in_canceled_state_for_pointer_type_touch_) { |
392 PointerEvent* pointer_event = pointer_event_factory_.Create( | 396 PointerEvent* pointer_event = pointer_event_factory_.Create( |
393 touch_point, GetCoalescedPoints(coalesced_events, touch_point.id), | 397 touch_point, GetCoalescedPoints(coalesced_events, touch_point.id), |
394 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), | 398 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), |
| 399 TimeTicks::FromSeconds(event.TimeStampSeconds()), |
395 touch_info.target_frame, | 400 touch_info.target_frame, |
396 touch_info.touch_node | 401 touch_info.touch_node |
397 ? touch_info.touch_node->GetDocument().domWindow() | 402 ? touch_info.touch_node->GetDocument().domWindow() |
398 : nullptr); | 403 : nullptr); |
399 | 404 |
400 WebInputEventResult result = | 405 WebInputEventResult result = |
401 SendTouchPointerEvent(touch_info.touch_node, pointer_event); | 406 SendTouchPointerEvent(touch_info.touch_node, pointer_event); |
402 | 407 |
403 // If a pointerdown has been canceled, queue the unique id to allow | 408 // If a pointerdown has been canceled, queue the unique id to allow |
404 // suppressing mouse events from gesture events. For mouse events | 409 // suppressing mouse events from gesture events. For mouse events |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 if (first_id > unique_touch_event_id) | 716 if (first_id > unique_touch_event_id) |
712 return false; | 717 return false; |
713 touch_ids_for_canceled_pointerdowns_.TakeFirst(); | 718 touch_ids_for_canceled_pointerdowns_.TakeFirst(); |
714 if (first_id == unique_touch_event_id) | 719 if (first_id == unique_touch_event_id) |
715 return true; | 720 return true; |
716 } | 721 } |
717 return false; | 722 return false; |
718 } | 723 } |
719 | 724 |
720 } // namespace blink | 725 } // namespace blink |
OLD | NEW |