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/ElementTraversal.h" | 7 #include "core/dom/ElementTraversal.h" |
8 #include "core/dom/UserGestureIndicator.h" | 8 #include "core/dom/UserGestureIndicator.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 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 size_t ToPointerTypeIndex(WebPointerProperties::PointerType t) { | 29 size_t ToPointerTypeIndex(WebPointerProperties::PointerType t) { |
30 return static_cast<size_t>(t); | 30 return static_cast<size_t>(t); |
31 } | 31 } |
32 bool HasPointerEventListener(const EventHandlerRegistry& registry) { | 32 bool HasPointerEventListener(const EventHandlerRegistry& registry) { |
33 return registry.HasEventHandlers(EventHandlerRegistry::kPointerEvent); | 33 return registry.HasEventHandlers(EventHandlerRegistry::kPointerEvent); |
34 } | 34 } |
35 | 35 |
| 36 Vector<WebPointerEvent> GetCoalescedWebPointerEventsWithNoTransformation( |
| 37 const Vector<WebTouchEvent>& coalesced_events, |
| 38 int id) { |
| 39 Vector<WebPointerEvent> related_pointer_events; |
| 40 for (const auto& touch_event : coalesced_events) { |
| 41 for (unsigned i = 0; i < touch_event.touches_length; ++i) { |
| 42 if (touch_event.touches[i].id == id && |
| 43 touch_event.touches[i].state != WebTouchPoint::kStateStationary) { |
| 44 related_pointer_events.push_back( |
| 45 WebPointerEvent(touch_event, touch_event.touches[i])); |
| 46 } |
| 47 } |
| 48 } |
| 49 return related_pointer_events; |
| 50 } |
| 51 |
36 Vector<std::pair<WebTouchPoint, TimeTicks>> GetCoalescedPoints( | 52 Vector<std::pair<WebTouchPoint, TimeTicks>> GetCoalescedPoints( |
37 const Vector<WebTouchEvent>& coalesced_events, | 53 const Vector<WebTouchEvent>& coalesced_events, |
38 int id) { | 54 int id) { |
39 Vector<std::pair<WebTouchPoint, TimeTicks>> related_points; | 55 Vector<std::pair<WebTouchPoint, TimeTicks>> related_points; |
40 for (const auto& touch_event : coalesced_events) { | 56 for (const auto& touch_event : coalesced_events) { |
41 for (unsigned i = 0; i < touch_event.touches_length; ++i) { | 57 for (unsigned i = 0; i < touch_event.touches_length; ++i) { |
42 if (touch_event.touches[i].id == id && | 58 if (touch_event.touches[i].id == id && |
43 touch_event.touches[i].state != WebTouchPoint::kStateStationary) { | 59 touch_event.touches[i].state != WebTouchPoint::kStateStationary) { |
44 related_points.push_back(std::pair<WebTouchPoint, TimeTicks>( | 60 related_points.push_back(std::pair<WebTouchPoint, TimeTicks>( |
45 touch_event.TouchPointInRootFrame(i), | 61 touch_event.TouchPointInRootFrame(i), |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // associated with so just pick the first finger. | 333 // associated with so just pick the first finger. |
318 RefPtr<UserGestureToken> possible_gesture_token; | 334 RefPtr<UserGestureToken> possible_gesture_token; |
319 if (event.GetType() == WebInputEvent::kTouchEnd && | 335 if (event.GetType() == WebInputEvent::kTouchEnd && |
320 !in_canceled_state_for_pointer_type_touch_ && event.touches_length && | 336 !in_canceled_state_for_pointer_type_touch_ && event.touches_length && |
321 first_pointer_event_target.target_frame) { | 337 first_pointer_event_target.target_frame) { |
322 possible_gesture_token = UserGestureToken::Create( | 338 possible_gesture_token = UserGestureToken::Create( |
323 first_pointer_event_target.target_frame->GetDocument()); | 339 first_pointer_event_target.target_frame->GetDocument()); |
324 } | 340 } |
325 UserGestureIndicator holder(possible_gesture_token); | 341 UserGestureIndicator holder(possible_gesture_token); |
326 | 342 |
327 HeapVector<EventHandlingUtil::PointerEventTarget> pointer_event_targets; | |
328 | 343 |
329 for (unsigned touch_point_idx = 0; touch_point_idx < event.touches_length; | 344 for (unsigned touch_point_idx = 0; touch_point_idx < event.touches_length; |
330 ++touch_point_idx) { | 345 ++touch_point_idx) { |
331 // Do any necessary hit-tests and compute the event targets for all pointers | 346 // Do any necessary hit-tests and compute the event targets for all pointers |
332 // in the event. | 347 // in the event. |
333 const auto& touch_point = event.TouchPointInRootFrame(touch_point_idx); | 348 const auto& touch_point = event.TouchPointInRootFrame(touch_point_idx); |
334 EventHandlingUtil::PointerEventTarget pointer_event_target = | 349 EventHandlingUtil::PointerEventTarget pointer_event_target = |
335 touch_point_idx ? ComputePointerEventTarget(touch_point) | 350 touch_point_idx ? ComputePointerEventTarget(touch_point) |
336 : first_pointer_event_target; | 351 : first_pointer_event_target; |
337 pointer_event_targets.push_back(pointer_event_target); | |
338 | 352 |
339 DispatchTouchPointerEvent( | 353 if (touch_point.state != blink::WebTouchPoint::kStateStationary) { |
340 touch_point, pointer_event_target, | 354 DispatchTouchPointerEvent( |
341 GetCoalescedPoints(coalesced_events, touch_point.id), | 355 touch_point, pointer_event_target, |
342 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), | 356 GetCoalescedPoints(coalesced_events, touch_point.id), |
343 event.TimeStampSeconds(), event.unique_touch_event_id); | 357 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), |
| 358 event.TimeStampSeconds(), event.unique_touch_event_id); |
| 359 |
| 360 touch_event_manager_->HandleTouchPoint( |
| 361 WebPointerEvent(event, event.touches[touch_point_idx]), |
| 362 GetCoalescedWebPointerEventsWithNoTransformation( |
| 363 coalesced_events, event.touches[touch_point_idx].id), |
| 364 pointer_event_target); |
| 365 } |
344 } | 366 } |
345 | 367 |
346 return touch_event_manager_->HandleTouchEvent(event, coalesced_events, | 368 // Calling this function |FlushEvents| will be moved to MainThreadEventQueue |
347 pointer_event_targets); | 369 // class. It will be called before rAF and also whenever we run in low latency |
| 370 // mode as mentioned in crbug.com/728250. |
| 371 return touch_event_manager_->FlushEvents(); |
348 } | 372 } |
349 | 373 |
350 EventHandlingUtil::PointerEventTarget | 374 EventHandlingUtil::PointerEventTarget |
351 PointerEventManager::ComputePointerEventTarget( | 375 PointerEventManager::ComputePointerEventTarget( |
352 const WebTouchPoint& touch_point) { | 376 const WebTouchPoint& touch_point) { |
353 EventHandlingUtil::PointerEventTarget pointer_event_target; | 377 EventHandlingUtil::PointerEventTarget pointer_event_target; |
354 | 378 |
355 int pointer_id = pointer_event_factory_.GetPointerEventId(touch_point); | 379 int pointer_id = pointer_event_factory_.GetPointerEventId(touch_point); |
356 // Do the hit test either when the touch first starts or when the touch | 380 // Do the hit test either when the touch first starts or when the touch |
357 // is not captured. |m_pendingPointerCaptureTarget| indicates the target | 381 // is not captured. |m_pendingPointerCaptureTarget| indicates the target |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 const WebTouchPoint& touch_point, | 427 const WebTouchPoint& touch_point, |
404 const EventHandlingUtil::PointerEventTarget& pointer_event_target, | 428 const EventHandlingUtil::PointerEventTarget& pointer_event_target, |
405 const Vector<std::pair<WebTouchPoint, TimeTicks>>& coalesced_events, | 429 const Vector<std::pair<WebTouchPoint, TimeTicks>>& coalesced_events, |
406 WebInputEvent::Modifiers modifiers, | 430 WebInputEvent::Modifiers modifiers, |
407 double timestamp, | 431 double timestamp, |
408 uint32_t unique_touch_event_id) { | 432 uint32_t unique_touch_event_id) { |
409 // Iterate through the touch points, sending PointerEvents to the targets as | 433 // Iterate through the touch points, sending PointerEvents to the targets as |
410 // required. | 434 // required. |
411 // Do not send pointer events for stationary touches or null targetFrame | 435 // Do not send pointer events for stationary touches or null targetFrame |
412 if (pointer_event_target.target_node && pointer_event_target.target_frame && | 436 if (pointer_event_target.target_node && pointer_event_target.target_frame && |
413 touch_point.state != WebTouchPoint::kStateStationary && | |
414 !in_canceled_state_for_pointer_type_touch_) { | 437 !in_canceled_state_for_pointer_type_touch_) { |
415 PointerEvent* pointer_event = pointer_event_factory_.Create( | 438 PointerEvent* pointer_event = pointer_event_factory_.Create( |
416 touch_point, coalesced_events, | 439 touch_point, coalesced_events, |
417 static_cast<WebInputEvent::Modifiers>(modifiers), | 440 static_cast<WebInputEvent::Modifiers>(modifiers), |
418 TimeTicks::FromSeconds(timestamp), pointer_event_target.target_frame, | 441 TimeTicks::FromSeconds(timestamp), pointer_event_target.target_frame, |
419 pointer_event_target.target_node | 442 pointer_event_target.target_node |
420 ? pointer_event_target.target_node->GetDocument().domWindow() | 443 ? pointer_event_target.target_node->GetDocument().domWindow() |
421 : nullptr); | 444 : nullptr); |
422 | 445 |
423 WebInputEventResult result = | 446 WebInputEventResult result = |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 if (first_id > unique_touch_event_id) | 774 if (first_id > unique_touch_event_id) |
752 return false; | 775 return false; |
753 touch_ids_for_canceled_pointerdowns_.TakeFirst(); | 776 touch_ids_for_canceled_pointerdowns_.TakeFirst(); |
754 if (first_id == unique_touch_event_id) | 777 if (first_id == unique_touch_event_id) |
755 return true; | 778 return true; |
756 } | 779 } |
757 return false; | 780 return false; |
758 } | 781 } |
759 | 782 |
760 } // namespace blink | 783 } // namespace blink |
OLD | NEW |