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 send_wheel_events_async_(false), | |
43 scrolling_device_(blink::kWebGestureDeviceUninitialized) { | 46 scrolling_device_(blink::kWebGestureDeviceUninitialized) { |
44 DCHECK(client); | 47 DCHECK(client); |
45 } | 48 } |
46 | 49 |
47 MouseWheelEventQueue::~MouseWheelEventQueue() { | 50 MouseWheelEventQueue::~MouseWheelEventQueue() { |
48 } | 51 } |
49 | 52 |
50 void MouseWheelEventQueue::QueueEvent( | 53 void MouseWheelEventQueue::QueueEvent( |
51 const MouseWheelEventWithLatencyInfo& event) { | 54 const MouseWheelEventWithLatencyInfo& event) { |
52 TRACE_EVENT0("input", "MouseWheelEventQueue::QueueEvent"); | 55 TRACE_EVENT0("input", "MouseWheelEventQueue::QueueEvent"); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 blink::WebMouseWheelEvent::kPhaseCancelled; | 172 blink::WebMouseWheelEvent::kPhaseCancelled; |
170 current_phase_ended = scroll_phase_ended || momentum_phase_ended; | 173 current_phase_ended = scroll_phase_ended || momentum_phase_ended; |
171 } | 174 } |
172 | 175 |
173 bool needs_update = scroll_update.data.scroll_update.delta_x != 0 || | 176 bool needs_update = scroll_update.data.scroll_update.delta_x != 0 || |
174 scroll_update.data.scroll_update.delta_y != 0; | 177 scroll_update.data.scroll_update.delta_y != 0; |
175 | 178 |
176 if (enable_scroll_latching_) { | 179 if (enable_scroll_latching_) { |
177 if (event_sent_for_gesture_ack_->event.phase == | 180 if (event_sent_for_gesture_ack_->event.phase == |
178 blink::WebMouseWheelEvent::kPhaseBegan) { | 181 blink::WebMouseWheelEvent::kPhaseBegan) { |
182 send_wheel_events_async_ = true; | |
179 SendScrollBegin(scroll_update, false); | 183 SendScrollBegin(scroll_update, false); |
180 } | 184 } |
181 | 185 |
182 if (needs_update) { | 186 if (needs_update) { |
183 ui::LatencyInfo latency = ui::LatencyInfo(ui::SourceEventType::WHEEL); | 187 ui::LatencyInfo latency = ui::LatencyInfo(ui::SourceEventType::WHEEL); |
184 latency.AddLatencyNumber( | 188 latency.AddLatencyNumber( |
185 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0, | 189 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0, |
186 0); | 190 0); |
187 client_->ForwardGestureEventWithLatencyInfo(scroll_update, latency); | 191 client_->ForwardGestureEventWithLatencyInfo(scroll_update, latency); |
188 } | 192 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 | 264 |
261 void MouseWheelEventQueue::TryForwardNextEventToRenderer() { | 265 void MouseWheelEventQueue::TryForwardNextEventToRenderer() { |
262 TRACE_EVENT0("input", "MouseWheelEventQueue::TryForwardNextEventToRenderer"); | 266 TRACE_EVENT0("input", "MouseWheelEventQueue::TryForwardNextEventToRenderer"); |
263 | 267 |
264 if (wheel_queue_.empty() || event_sent_for_gesture_ack_) | 268 if (wheel_queue_.empty() || event_sent_for_gesture_ack_) |
265 return; | 269 return; |
266 | 270 |
267 event_sent_for_gesture_ack_ = std::move(wheel_queue_.front()); | 271 event_sent_for_gesture_ack_ = std::move(wheel_queue_.front()); |
268 wheel_queue_.pop_front(); | 272 wheel_queue_.pop_front(); |
269 | 273 |
274 if (base::FeatureList::IsEnabled(features::kAsyncWheelEvents)) { | |
dtapuska
2017/06/16 17:36:09
don't check the feature list on every event. stash
sahel
2017/06/20 19:22:33
Done.
| |
275 DCHECK(event_sent_for_gesture_ack_->event.phase != | |
276 blink::WebMouseWheelEvent::kPhaseNone || | |
277 event_sent_for_gesture_ack_->event.momentum_phase != | |
278 blink::WebMouseWheelEvent::kPhaseNone); | |
279 if (event_sent_for_gesture_ack_->event.phase == | |
280 blink::WebMouseWheelEvent::kPhaseBegan) { | |
281 send_wheel_events_async_ = false; | |
282 } else if (send_wheel_events_async_) { | |
283 event_sent_for_gesture_ack_->event.dispatch_type = | |
284 WebInputEvent::kEventNonBlocking; | |
285 } | |
286 } | |
287 | |
270 client_->SendMouseWheelEventImmediately(*event_sent_for_gesture_ack_); | 288 client_->SendMouseWheelEventImmediately(*event_sent_for_gesture_ack_); |
271 } | 289 } |
272 | 290 |
273 void MouseWheelEventQueue::SendScrollEnd(WebGestureEvent update_event, | 291 void MouseWheelEventQueue::SendScrollEnd(WebGestureEvent update_event, |
274 bool synthetic) { | 292 bool synthetic) { |
275 DCHECK((synthetic && !needs_scroll_end_) || needs_scroll_end_); | 293 DCHECK((synthetic && !needs_scroll_end_) || needs_scroll_end_); |
276 | 294 |
277 WebGestureEvent scroll_end(update_event); | 295 WebGestureEvent scroll_end(update_event); |
278 scroll_end.SetTimeStampSeconds( | 296 scroll_end.SetTimeStampSeconds( |
279 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); | 297 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 = | 329 scroll_begin.data.scroll_begin.delta_hint_units = |
312 gesture_update.data.scroll_update.delta_units; | 330 gesture_update.data.scroll_update.delta_units; |
313 | 331 |
314 needs_scroll_begin_ = false; | 332 needs_scroll_begin_ = false; |
315 needs_scroll_end_ = true; | 333 needs_scroll_end_ = true; |
316 client_->ForwardGestureEventWithLatencyInfo( | 334 client_->ForwardGestureEventWithLatencyInfo( |
317 scroll_begin, ui::LatencyInfo(ui::SourceEventType::WHEEL)); | 335 scroll_begin, ui::LatencyInfo(ui::SourceEventType::WHEEL)); |
318 } | 336 } |
319 | 337 |
320 } // namespace content | 338 } // namespace content |
OLD | NEW |