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 "content/renderer/input/main_thread_event_queue.h" | 5 #include "content/renderer/input/main_thread_event_queue.h" |
6 #include "content/common/input/event_with_latency_info.h" | 6 #include "content/common/input/event_with_latency_info.h" |
7 #include "content/common/input_messages.h" | 7 #include "content/common/input_messages.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other); | 34 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other); |
35 } | 35 } |
36 | 36 |
37 MainThreadEventQueue::MainThreadEventQueue( | 37 MainThreadEventQueue::MainThreadEventQueue( |
38 int routing_id, | 38 int routing_id, |
39 MainThreadEventQueueClient* client, | 39 MainThreadEventQueueClient* client, |
40 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) | 40 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) |
41 : routing_id_(routing_id), | 41 : routing_id_(routing_id), |
42 client_(client), | 42 client_(client), |
43 is_flinging_(false), | 43 is_flinging_(false), |
| 44 last_touch_start_forced_nonblocking_due_to_fling_(false), |
| 45 enable_fling_passive_listener_flag_(base::FeatureList::IsEnabled( |
| 46 features::kPassiveEventListenersDueToFling)), |
44 main_task_runner_(main_task_runner) {} | 47 main_task_runner_(main_task_runner) {} |
45 | 48 |
46 MainThreadEventQueue::~MainThreadEventQueue() {} | 49 MainThreadEventQueue::~MainThreadEventQueue() {} |
47 | 50 |
48 bool MainThreadEventQueue::HandleEvent( | 51 bool MainThreadEventQueue::HandleEvent( |
49 ui::ScopedWebInputEvent event, | 52 ui::ScopedWebInputEvent event, |
50 const ui::LatencyInfo& latency, | 53 const ui::LatencyInfo& latency, |
51 InputEventDispatchType original_dispatch_type, | 54 InputEventDispatchType original_dispatch_type, |
52 InputEventAckState ack_result) { | 55 InputEventAckState ack_result) { |
53 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || | 56 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || |
54 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); | 57 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); |
55 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING || | 58 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING || |
56 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 59 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
57 | 60 |
58 bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING || | 61 bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING || |
59 ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING; | 62 ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING; |
60 | |
61 InputEventDispatchType dispatch_type = | |
62 non_blocking ? DISPATCH_TYPE_NON_BLOCKING : DISPATCH_TYPE_BLOCKING; | |
63 | |
64 bool is_wheel = event->type == blink::WebInputEvent::MouseWheel; | 63 bool is_wheel = event->type == blink::WebInputEvent::MouseWheel; |
65 bool is_touch = blink::WebInputEvent::isTouchEventType(event->type); | 64 bool is_touch = blink::WebInputEvent::isTouchEventType(event->type); |
66 | 65 |
67 if (is_touch) { | 66 if (is_touch) { |
68 blink::WebTouchEvent* touch_event = | 67 blink::WebTouchEvent* touch_event = |
69 static_cast<blink::WebTouchEvent*>(event.get()); | 68 static_cast<blink::WebTouchEvent*>(event.get()); |
70 touch_event->dispatchedDuringFling = is_flinging_; | 69 touch_event->dispatchedDuringFling = is_flinging_; |
71 // Adjust the |dispatchType| on the event since the compositor | 70 // Adjust the |dispatchType| on the event since the compositor |
72 // determined all event listeners are passive. | 71 // determined all event listeners are passive. |
73 if (non_blocking) { | 72 if (non_blocking) { |
74 touch_event->dispatchType = | 73 touch_event->dispatchType = |
75 blink::WebInputEvent::ListenersNonBlockingPassive; | 74 blink::WebInputEvent::ListenersNonBlockingPassive; |
76 } | 75 } |
| 76 if (touch_event->type == blink::WebInputEvent::TouchStart) |
| 77 last_touch_start_forced_nonblocking_due_to_fling_ = false; |
| 78 |
| 79 if (enable_fling_passive_listener_flag_ && |
| 80 touch_event->touchStartOrFirstTouchMove && |
| 81 touch_event->dispatchType == blink::WebInputEvent::Blocking) { |
| 82 // If the touch start is forced to be passive due to fling, its following |
| 83 // touch move should also be passive. |
| 84 if (is_flinging_ || last_touch_start_forced_nonblocking_due_to_fling_) { |
| 85 touch_event->dispatchType = |
| 86 blink::WebInputEvent::ListenersForcedNonBlockingDueToFling; |
| 87 non_blocking = true; |
| 88 last_touch_start_forced_nonblocking_due_to_fling_ = true; |
| 89 } |
| 90 } |
77 } | 91 } |
78 if (is_wheel && non_blocking) { | 92 if (is_wheel && non_blocking) { |
79 // Adjust the |dispatchType| on the event since the compositor | 93 // Adjust the |dispatchType| on the event since the compositor |
80 // determined all event listeners are passive. | 94 // determined all event listeners are passive. |
81 static_cast<blink::WebMouseWheelEvent*>(event.get()) | 95 static_cast<blink::WebMouseWheelEvent*>(event.get()) |
82 ->dispatchType = blink::WebInputEvent::ListenersNonBlockingPassive; | 96 ->dispatchType = blink::WebInputEvent::ListenersNonBlockingPassive; |
83 } | 97 } |
84 | 98 |
| 99 InputEventDispatchType dispatch_type = |
| 100 non_blocking ? DISPATCH_TYPE_NON_BLOCKING : DISPATCH_TYPE_BLOCKING; |
85 std::unique_ptr<EventWithDispatchType> event_with_dispatch_type( | 101 std::unique_ptr<EventWithDispatchType> event_with_dispatch_type( |
86 new EventWithDispatchType(std::move(event), latency, dispatch_type)); | 102 new EventWithDispatchType(std::move(event), latency, dispatch_type)); |
87 | 103 |
88 QueueEvent(std::move(event_with_dispatch_type)); | 104 QueueEvent(std::move(event_with_dispatch_type)); |
89 | 105 |
90 // send an ack when we are non-blocking. | 106 // send an ack when we are non-blocking. |
91 return non_blocking; | 107 return non_blocking; |
92 } | 108 } |
93 | 109 |
94 void MainThreadEventQueue::PopEventOnMainThread() { | 110 void MainThreadEventQueue::PopEventOnMainThread() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 base::AutoLock lock(event_queue_lock_); | 151 base::AutoLock lock(event_queue_lock_); |
136 size_t size_before = events_.size(); | 152 size_t size_before = events_.size(); |
137 events_.Queue(std::move(event)); | 153 events_.Queue(std::move(event)); |
138 send_notification = events_.size() != size_before; | 154 send_notification = events_.size() != size_before; |
139 } | 155 } |
140 if (send_notification) | 156 if (send_notification) |
141 SendEventNotificationToMainThread(); | 157 SendEventNotificationToMainThread(); |
142 } | 158 } |
143 | 159 |
144 } // namespace content | 160 } // namespace content |
OLD | NEW |