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/browser/renderer_host/input/mouse_wheel_event_queue.h" | 5 #include "content/browser/renderer_host/input/mouse_wheel_event_queue.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "content/common/input/input_event_dispatch_type.h" |
| 11 #include "content/public/common/content_features.h" |
10 #include "ui/events/base_event_utils.h" | 12 #include "ui/events/base_event_utils.h" |
11 #include "ui/events/blink/web_input_event_traits.h" | 13 #include "ui/events/blink/web_input_event_traits.h" |
12 | 14 |
13 using blink::WebGestureEvent; | 15 using blink::WebGestureEvent; |
14 using blink::WebInputEvent; | 16 using blink::WebInputEvent; |
15 using blink::WebMouseWheelEvent; | 17 using blink::WebMouseWheelEvent; |
16 using ui::LatencyInfo; | 18 using ui::LatencyInfo; |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 | 21 |
(...skipping 13 matching lines...) Expand all Loading... |
33 private: | 35 private: |
34 DISALLOW_COPY_AND_ASSIGN(QueuedWebMouseWheelEvent); | 36 DISALLOW_COPY_AND_ASSIGN(QueuedWebMouseWheelEvent); |
35 }; | 37 }; |
36 | 38 |
37 MouseWheelEventQueue::MouseWheelEventQueue(MouseWheelEventQueueClient* client, | 39 MouseWheelEventQueue::MouseWheelEventQueue(MouseWheelEventQueueClient* client, |
38 bool enable_scroll_latching) | 40 bool enable_scroll_latching) |
39 : client_(client), | 41 : client_(client), |
40 needs_scroll_begin_(true), | 42 needs_scroll_begin_(true), |
41 needs_scroll_end_(false), | 43 needs_scroll_end_(false), |
42 enable_scroll_latching_(enable_scroll_latching), | 44 enable_scroll_latching_(enable_scroll_latching), |
| 45 enable_async_wheel_events_( |
| 46 base::FeatureList::IsEnabled(features::kAsyncWheelEvents)), |
| 47 send_wheel_events_async_(false), |
43 scrolling_device_(blink::kWebGestureDeviceUninitialized) { | 48 scrolling_device_(blink::kWebGestureDeviceUninitialized) { |
44 DCHECK(client); | 49 DCHECK(client); |
45 } | 50 } |
46 | 51 |
47 MouseWheelEventQueue::~MouseWheelEventQueue() { | 52 MouseWheelEventQueue::~MouseWheelEventQueue() { |
48 } | 53 } |
49 | 54 |
50 void MouseWheelEventQueue::QueueEvent( | 55 void MouseWheelEventQueue::QueueEvent( |
51 const MouseWheelEventWithLatencyInfo& event) { | 56 const MouseWheelEventWithLatencyInfo& event) { |
52 TRACE_EVENT0("input", "MouseWheelEventQueue::QueueEvent"); | 57 TRACE_EVENT0("input", "MouseWheelEventQueue::QueueEvent"); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 blink::WebMouseWheelEvent::kPhaseCancelled; | 174 blink::WebMouseWheelEvent::kPhaseCancelled; |
170 current_phase_ended = scroll_phase_ended || momentum_phase_ended; | 175 current_phase_ended = scroll_phase_ended || momentum_phase_ended; |
171 } | 176 } |
172 | 177 |
173 bool needs_update = scroll_update.data.scroll_update.delta_x != 0 || | 178 bool needs_update = scroll_update.data.scroll_update.delta_x != 0 || |
174 scroll_update.data.scroll_update.delta_y != 0; | 179 scroll_update.data.scroll_update.delta_y != 0; |
175 | 180 |
176 if (enable_scroll_latching_) { | 181 if (enable_scroll_latching_) { |
177 if (event_sent_for_gesture_ack_->event.phase == | 182 if (event_sent_for_gesture_ack_->event.phase == |
178 blink::WebMouseWheelEvent::kPhaseBegan) { | 183 blink::WebMouseWheelEvent::kPhaseBegan) { |
| 184 send_wheel_events_async_ = true; |
179 SendScrollBegin(scroll_update, false); | 185 SendScrollBegin(scroll_update, false); |
180 } | 186 } |
181 | 187 |
182 if (needs_update) { | 188 if (needs_update) { |
183 ui::LatencyInfo latency = ui::LatencyInfo(ui::SourceEventType::WHEEL); | 189 ui::LatencyInfo latency = ui::LatencyInfo(ui::SourceEventType::WHEEL); |
184 latency.AddLatencyNumber( | 190 latency.AddLatencyNumber( |
185 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0, | 191 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0, |
186 0); | 192 0); |
187 client_->ForwardGestureEventWithLatencyInfo(scroll_update, latency); | 193 client_->ForwardGestureEventWithLatencyInfo(scroll_update, latency); |
188 } | 194 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 266 |
261 void MouseWheelEventQueue::TryForwardNextEventToRenderer() { | 267 void MouseWheelEventQueue::TryForwardNextEventToRenderer() { |
262 TRACE_EVENT0("input", "MouseWheelEventQueue::TryForwardNextEventToRenderer"); | 268 TRACE_EVENT0("input", "MouseWheelEventQueue::TryForwardNextEventToRenderer"); |
263 | 269 |
264 if (wheel_queue_.empty() || event_sent_for_gesture_ack_) | 270 if (wheel_queue_.empty() || event_sent_for_gesture_ack_) |
265 return; | 271 return; |
266 | 272 |
267 event_sent_for_gesture_ack_ = std::move(wheel_queue_.front()); | 273 event_sent_for_gesture_ack_ = std::move(wheel_queue_.front()); |
268 wheel_queue_.pop_front(); | 274 wheel_queue_.pop_front(); |
269 | 275 |
| 276 if (enable_async_wheel_events_) { |
| 277 DCHECK(event_sent_for_gesture_ack_->event.phase != |
| 278 blink::WebMouseWheelEvent::kPhaseNone || |
| 279 event_sent_for_gesture_ack_->event.momentum_phase != |
| 280 blink::WebMouseWheelEvent::kPhaseNone); |
| 281 if (event_sent_for_gesture_ack_->event.phase == |
| 282 blink::WebMouseWheelEvent::kPhaseBegan) { |
| 283 send_wheel_events_async_ = false; |
| 284 } else if (send_wheel_events_async_) { |
| 285 event_sent_for_gesture_ack_->event.dispatch_type = |
| 286 WebInputEvent::kEventNonBlocking; |
| 287 } |
| 288 } |
| 289 |
270 client_->SendMouseWheelEventImmediately(*event_sent_for_gesture_ack_); | 290 client_->SendMouseWheelEventImmediately(*event_sent_for_gesture_ack_); |
271 } | 291 } |
272 | 292 |
273 void MouseWheelEventQueue::SendScrollEnd(WebGestureEvent update_event, | 293 void MouseWheelEventQueue::SendScrollEnd(WebGestureEvent update_event, |
274 bool synthetic) { | 294 bool synthetic) { |
275 DCHECK((synthetic && !needs_scroll_end_) || needs_scroll_end_); | 295 DCHECK((synthetic && !needs_scroll_end_) || needs_scroll_end_); |
276 | 296 |
277 WebGestureEvent scroll_end(update_event); | 297 WebGestureEvent scroll_end(update_event); |
278 scroll_end.SetTimeStampSeconds( | 298 scroll_end.SetTimeStampSeconds( |
279 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); | 299 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 scroll_begin.data.scroll_begin.delta_hint_units = | 331 scroll_begin.data.scroll_begin.delta_hint_units = |
312 gesture_update.data.scroll_update.delta_units; | 332 gesture_update.data.scroll_update.delta_units; |
313 | 333 |
314 needs_scroll_begin_ = false; | 334 needs_scroll_begin_ = false; |
315 needs_scroll_end_ = true; | 335 needs_scroll_end_ = true; |
316 client_->ForwardGestureEventWithLatencyInfo( | 336 client_->ForwardGestureEventWithLatencyInfo( |
317 scroll_begin, ui::LatencyInfo(ui::SourceEventType::WHEEL)); | 337 scroll_begin, ui::LatencyInfo(ui::SourceEventType::WHEEL)); |
318 } | 338 } |
319 | 339 |
320 } // namespace content | 340 } // namespace content |
OLD | NEW |