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 is_last_touch_start_force_passive_(false), | |
44 main_task_runner_(main_task_runner) {} | 45 main_task_runner_(main_task_runner) {} |
45 | 46 |
46 MainThreadEventQueue::~MainThreadEventQueue() {} | 47 MainThreadEventQueue::~MainThreadEventQueue() {} |
47 | 48 |
48 bool MainThreadEventQueue::HandleEvent( | 49 bool MainThreadEventQueue::HandleEvent( |
49 ScopedWebInputEvent event, | 50 ScopedWebInputEvent event, |
50 const ui::LatencyInfo& latency, | 51 const ui::LatencyInfo& latency, |
51 InputEventDispatchType original_dispatch_type, | 52 InputEventDispatchType original_dispatch_type, |
52 InputEventAckState ack_result) { | 53 InputEventAckState ack_result) { |
53 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || | 54 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || |
54 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); | 55 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); |
55 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING || | 56 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING || |
56 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 57 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
57 | 58 |
58 bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING || | 59 bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING || |
59 ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING; | 60 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; | 61 bool is_wheel = event->type == blink::WebInputEvent::MouseWheel; |
65 bool is_touch = blink::WebInputEvent::isTouchEventType(event->type); | 62 bool is_touch = blink::WebInputEvent::isTouchEventType(event->type); |
66 | 63 |
67 if (is_touch) { | 64 if (is_touch) { |
68 blink::WebTouchEvent* touch_event = | 65 blink::WebTouchEvent* touch_event = |
69 static_cast<blink::WebTouchEvent*>(event.get()); | 66 static_cast<blink::WebTouchEvent*>(event.get()); |
70 touch_event->dispatchedDuringFling = is_flinging_; | 67 touch_event->dispatchedDuringFling = is_flinging_; |
71 // Adjust the |dispatchType| on the event since the compositor | 68 // Adjust the |dispatchType| on the event since the compositor |
72 // determined all event listeners are passive. | 69 // determined all event listeners are passive. |
73 if (non_blocking) { | 70 if (non_blocking) { |
74 touch_event->dispatchType = | 71 touch_event->dispatchType = |
75 blink::WebInputEvent::ListenersNonBlockingPassive; | 72 blink::WebInputEvent::ListenersNonBlockingPassive; |
76 } | 73 } |
74 | |
75 if (base::FeatureList::IsEnabled( | |
76 features::kPassiveEventListenersDueToFling) && | |
tdresser
2016/08/17 14:32:27
Let's read this flag once, and store the result in
lanwei
2016/08/18 12:31:47
Done.
| |
77 is_flinging_ && touch_event->touchStartOrFirstTouchMove && | |
78 touch_event->dispatchType == blink::WebInputEvent::Blocking) { | |
79 // If the touch start is forced to be passive due to fling, its following | |
80 // touch move should also be passive. | |
81 if (touch_event->type == blink::WebInputEvent::TouchStart || | |
82 is_last_touch_start_force_passive_) { | |
83 touch_event->dispatchType = | |
84 blink::WebInputEvent::ListenersForcedNonBlockingPassiveDueToFling; | |
85 non_blocking = true; | |
86 is_last_touch_start_force_passive_ = true; | |
tdresser
2016/08/17 14:32:27
This variable name is a bit confusing, as the tens
lanwei
2016/08/18 12:31:47
Done.
| |
87 } | |
88 } else if (touch_event->type == blink::WebInputEvent::TouchStart) { | |
89 is_last_touch_start_force_passive_ = false; | |
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 |