Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: content/browser/renderer_host/input/mouse_wheel_event_queue.cc

Issue 2486673008: Touchpad scroll latching enabled for Mac behind flag. (Closed)
Patch Set: GSE/GSB are not sent when a scroll in inertial phase begins. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/events/blink/web_input_event_traits.h" 10 #include "ui/events/blink/web_input_event_traits.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 if (event_sent_for_gesture_ack_->event.railsMode == 143 if (event_sent_for_gesture_ack_->event.railsMode ==
144 WebInputEvent::RailsModeVertical) 144 WebInputEvent::RailsModeVertical)
145 scroll_update.data.scrollUpdate.deltaX = 0; 145 scroll_update.data.scrollUpdate.deltaX = 0;
146 if (event_sent_for_gesture_ack_->event.railsMode == 146 if (event_sent_for_gesture_ack_->event.railsMode ==
147 WebInputEvent::RailsModeHorizontal) 147 WebInputEvent::RailsModeHorizontal)
148 scroll_update.data.scrollUpdate.deltaY = 0; 148 scroll_update.data.scrollUpdate.deltaY = 0;
149 } 149 }
150 150
151 bool current_phase_ended = false; 151 bool current_phase_ended = false;
152 bool scroll_phase_ended = false;
153 bool momentum_phase_ended = false;
152 bool has_phase_info = false; 154 bool has_phase_info = false;
153 155
154 if (event_sent_for_gesture_ack_->event.phase != 156 if (event_sent_for_gesture_ack_->event.phase !=
155 blink::WebMouseWheelEvent::PhaseNone || 157 blink::WebMouseWheelEvent::PhaseNone ||
156 event_sent_for_gesture_ack_->event.momentumPhase != 158 event_sent_for_gesture_ack_->event.momentumPhase !=
157 blink::WebMouseWheelEvent::PhaseNone) { 159 blink::WebMouseWheelEvent::PhaseNone) {
158 has_phase_info = true; 160 has_phase_info = true;
159 current_phase_ended = event_sent_for_gesture_ack_->event.phase == 161 scroll_phase_ended = event_sent_for_gesture_ack_->event.phase ==
160 blink::WebMouseWheelEvent::PhaseEnded || 162 blink::WebMouseWheelEvent::PhaseEnded ||
161 event_sent_for_gesture_ack_->event.phase == 163 event_sent_for_gesture_ack_->event.phase ==
162 blink::WebMouseWheelEvent::PhaseCancelled || 164 blink::WebMouseWheelEvent::PhaseCancelled;
163 event_sent_for_gesture_ack_->event.momentumPhase == 165 momentum_phase_ended = event_sent_for_gesture_ack_->event.momentumPhase ==
164 blink::WebMouseWheelEvent::PhaseEnded || 166 blink::WebMouseWheelEvent::PhaseEnded ||
165 event_sent_for_gesture_ack_->event.momentumPhase == 167 event_sent_for_gesture_ack_->event.momentumPhase ==
166 blink::WebMouseWheelEvent::PhaseCancelled; 168 blink::WebMouseWheelEvent::PhaseCancelled;
169 current_phase_ended = scroll_phase_ended || momentum_phase_ended;
167 } 170 }
168 171
169 bool needs_update = scroll_update.data.scrollUpdate.deltaX != 0 || 172 bool needs_update = scroll_update.data.scrollUpdate.deltaX != 0 ||
170 scroll_update.data.scrollUpdate.deltaY != 0; 173 scroll_update.data.scrollUpdate.deltaY != 0;
171 174
172 // If there is no update to send and the current phase is ended yet a GSB 175 // If there is no update to send and the current phase is ended yet a GSB
173 // needs to be sent, this event sequence doesn't need to be generated 176 // needs to be sent, this event sequence doesn't need to be generated
174 // because the events generated will be a GSB (non-synthetic) and GSE 177 // because the events generated will be a GSB (non-synthetic) and GSE
175 // (non-synthetic). This situation arises when OSX generates double 178 // (non-synthetic). This situation arises when OSX generates double
176 // phase end information. 179 // phase end information.
177 bool empty_sequence = 180 bool empty_sequence =
178 !needs_update && needs_scroll_begin_ && current_phase_ended; 181 !needs_update && needs_scroll_begin_ && current_phase_ended;
179 182
180 if (needs_update || !empty_sequence) { 183 if (enable_scroll_latching_) {
181 if (needs_scroll_begin_) { 184 if (event_sent_for_gesture_ack_->event.momentumPhase ==
182 // If no GSB has been sent, it will be a non-synthetic GSB. 185 blink::WebMouseWheelEvent::PhaseBegan) {
183 SendScrollBegin(scroll_update, false); 186 // Don't send the pending scrollEnd if a fling starts.
184 } else if (has_phase_info) { 187 if (scroll_end_timer_.IsRunning())
185 // If a GSB has been sent, generate a synthetic GSB if we have phase 188 scroll_end_timer_.Stop();
186 // information. This should be removed once crbug.com/526463 is fully
187 // implemented.
188 SendScrollBegin(scroll_update, true);
189 } 189 }
190 190
191 if (needs_update) { 191 if (needs_update || !empty_sequence) {
192 ui::LatencyInfo latency = ui::LatencyInfo(ui::SourceEventType::WHEEL); 192 if (needs_scroll_begin_) {
193 latency.AddLatencyNumber( 193 SendScrollBegin(scroll_update, false);
194 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0, 194 }
195 0); 195
196 client_->ForwardGestureEventWithLatencyInfo(scroll_update, latency); 196 if (needs_update) {
197 ui::LatencyInfo latency = ui::LatencyInfo(ui::SourceEventType::WHEEL);
198 latency.AddLatencyNumber(
199 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL,
200 0, 0);
201 client_->ForwardGestureEventWithLatencyInfo(scroll_update, latency);
202 }
203
204 if (momentum_phase_ended) {
205 // Send GSE with if scroll latching is enabled and no fling is going
206 // to happen next.
207 SendScrollEnd(scroll_update, false);
208 } else if (scroll_phase_ended || !has_phase_info) {
209 // If scroll latching is enabled and a fling might happen next, or
210 // no phase info exists, start the scroll_end_timer_.
211 scroll_end_timer_.Start(
212 FROM_HERE,
213 base::TimeDelta::FromMilliseconds(scroll_transaction_ms_),
214 base::Bind(&MouseWheelEventQueue::SendScrollEnd,
215 base::Unretained(this), scroll_update, false));
216 }
197 } 217 }
198 218
199 if (current_phase_ended) { 219 } else { // !enable_scroll_latching_
200 // Non-synthetic GSEs are sent when the current phase is canceled or 220 if (needs_update || !empty_sequence) {
201 // ended. 221 if (needs_scroll_begin_) {
202 SendScrollEnd(scroll_update, false); 222 // If no GSB has been sent, it will be a non-synthetic GSB.
203 } else if (has_phase_info) { 223 SendScrollBegin(scroll_update, false);
204 // Generate a synthetic GSE for every update to force hit testing so 224 } else if (has_phase_info) {
205 // that the non-latching behavior is preserved. Remove once 225 // If a GSB has been sent, generate a synthetic GSB if we have phase
206 // crbug.com/526463 is fully implemented. 226 // information. This should be removed once crbug.com/526463 is
207 SendScrollEnd(scroll_update, true); 227 // fully implemented.
208 } else { 228 SendScrollBegin(scroll_update, true);
209 scroll_end_timer_.Start( 229 }
210 FROM_HERE, 230
211 base::TimeDelta::FromMilliseconds(scroll_transaction_ms_), 231 if (needs_update) {
212 base::Bind(&MouseWheelEventQueue::SendScrollEnd, 232 ui::LatencyInfo latency = ui::LatencyInfo(ui::SourceEventType::WHEEL);
213 base::Unretained(this), scroll_update, false)); 233 latency.AddLatencyNumber(
234 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL,
235 0, 0);
236 client_->ForwardGestureEventWithLatencyInfo(scroll_update, latency);
237 }
238
239 if (current_phase_ended) {
240 // Non-synthetic GSEs are sent when the current phase is canceled or
241 // ended.
242 SendScrollEnd(scroll_update, false);
243 } else if (has_phase_info) {
244 // Generate a synthetic GSE for every update to force hit testing so
245 // that the non-latching behavior is preserved. Remove once
246 // crbug.com/526463 is fully implemented.
247 SendScrollEnd(scroll_update, true);
248 } else if (!has_phase_info) {
249 scroll_end_timer_.Start(
250 FROM_HERE,
251 base::TimeDelta::FromMilliseconds(scroll_transaction_ms_),
252 base::Bind(&MouseWheelEventQueue::SendScrollEnd,
253 base::Unretained(this), scroll_update, false));
254 }
214 } 255 }
215 } 256 }
216 } 257 }
217 258
218 event_sent_for_gesture_ack_.reset(); 259 event_sent_for_gesture_ack_.reset();
219 TryForwardNextEventToRenderer(); 260 TryForwardNextEventToRenderer();
220 } 261 }
221 262
222 void MouseWheelEventQueue::OnGestureScrollEvent( 263 void MouseWheelEventQueue::OnGestureScrollEvent(
223 const GestureEventWithLatencyInfo& gesture_event) { 264 const GestureEventWithLatencyInfo& gesture_event) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 scroll_begin.data.scrollBegin.deltaHintUnits = 339 scroll_begin.data.scrollBegin.deltaHintUnits =
299 gesture_update.data.scrollUpdate.deltaUnits; 340 gesture_update.data.scrollUpdate.deltaUnits;
300 341
301 needs_scroll_begin_ = false; 342 needs_scroll_begin_ = false;
302 needs_scroll_end_ = true; 343 needs_scroll_end_ = true;
303 client_->ForwardGestureEventWithLatencyInfo( 344 client_->ForwardGestureEventWithLatencyInfo(
304 scroll_begin, ui::LatencyInfo(ui::SourceEventType::WHEEL)); 345 scroll_begin, ui::LatencyInfo(ui::SourceEventType::WHEEL));
305 } 346 }
306 347
307 } // namespace content 348 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698