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

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

Issue 718153002: Indicate whether a touch event will cause scrolling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/touch_emulator.h" 5 #include "content/browser/renderer_host/input/touch_emulator.h"
6 6
7 #include "content/browser/renderer_host/input/motion_event_web.h" 7 #include "content/browser/renderer_host/input/motion_event_web.h"
8 #include "content/browser/renderer_host/input/web_input_event_util.h" 8 #include "content/browser/renderer_host/input/web_input_event_util.h"
9 #include "content/common/input/web_touch_event_traits.h" 9 #include "content/common/input/web_touch_event_traits.h"
10 #include "content/grit/content_resources.h" 10 #include "content/grit/content_resources.h"
(...skipping 11 matching lines...) Expand all
22 using blink::WebMouseWheelEvent; 22 using blink::WebMouseWheelEvent;
23 using blink::WebTouchEvent; 23 using blink::WebTouchEvent;
24 using blink::WebTouchPoint; 24 using blink::WebTouchPoint;
25 25
26 namespace content { 26 namespace content {
27 27
28 namespace { 28 namespace {
29 29
30 ui::GestureProvider::Config GetGestureProviderConfig() { 30 ui::GestureProvider::Config GetGestureProviderConfig() {
31 // TODO(dgozman): Use different configs to emulate mobile/desktop as 31 // TODO(dgozman): Use different configs to emulate mobile/desktop as
32 // requested by renderer. 32 // requested by renderer, crbug/425586.
33 ui::GestureProvider::Config config = ui::DefaultGestureProviderConfig(); 33 ui::GestureProvider::Config config = ui::DefaultGestureProviderConfig();
34 config.gesture_begin_end_types_enabled = false; 34 config.gesture_begin_end_types_enabled = false;
35 config.gesture_detector_config.swipe_enabled = false; 35 config.gesture_detector_config.swipe_enabled = false;
36 config.gesture_detector_config.two_finger_tap_enabled = false; 36 config.gesture_detector_config.two_finger_tap_enabled = false;
37 return config; 37 return config;
38 } 38 }
39 39
40 // Time between two consecutive mouse moves, during which second mouse move 40 // Time between two consecutive mouse moves, during which second mouse move
41 // is not converted to touch. 41 // is not converted to touch.
42 const double kMouseMoveDropIntervalSeconds = 5.f / 1000; 42 const double kMouseMoveDropIntervalSeconds = 5.f / 1000;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 last_mouse_event_was_move_ = false; 150 last_mouse_event_was_move_ = false;
151 } 151 }
152 152
153 if (mouse_event.type == WebInputEvent::MouseDown) 153 if (mouse_event.type == WebInputEvent::MouseDown)
154 mouse_pressed_ = true; 154 mouse_pressed_ = true;
155 else if (mouse_event.type == WebInputEvent::MouseUp) 155 else if (mouse_event.type == WebInputEvent::MouseUp)
156 mouse_pressed_ = false; 156 mouse_pressed_ = false;
157 157
158 UpdateShiftPressed((mouse_event.modifiers & WebInputEvent::ShiftKey) != 0); 158 UpdateShiftPressed((mouse_event.modifiers & WebInputEvent::ShiftKey) != 0);
159 159
160 if (FillTouchEventAndPoint(mouse_event) && 160 if (mouse_event.type != WebInputEvent::MouseDown &&
161 gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) { 161 mouse_event.type != WebInputEvent::MouseMove &&
162 ForwardTouchEventToClient(); 162 mouse_event.type != WebInputEvent::MouseUp) {
163 return true;
163 } 164 }
164 165
166 FillTouchEventAndPoint(mouse_event);
167 HandleEmulatedTouchEvent(touch_event_);
168
165 // Do not pass mouse events to the renderer. 169 // Do not pass mouse events to the renderer.
166 return true; 170 return true;
167 } 171 }
168 172
169 bool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) { 173 bool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) {
170 if (!enabled_) 174 if (!enabled_)
171 return false; 175 return false;
172 176
173 // Send mouse wheel for easy scrolling when there is no active touch. 177 // Send mouse wheel for easy scrolling when there is no active touch.
174 return emulated_stream_active_sequence_count_ > 0; 178 return emulated_stream_active_sequence_count_ > 0;
(...skipping 30 matching lines...) Expand all
205 bool is_sequence_start = WebTouchEventTraits::IsTouchSequenceStart(event); 209 bool is_sequence_start = WebTouchEventTraits::IsTouchSequenceStart(event);
206 // Do not allow middle-sequence event to pass through, if start was blocked. 210 // Do not allow middle-sequence event to pass through, if start was blocked.
207 if (!native_stream_active_sequence_count_ && !is_sequence_start) 211 if (!native_stream_active_sequence_count_ && !is_sequence_start)
208 return true; 212 return true;
209 213
210 if (is_sequence_start) 214 if (is_sequence_start)
211 native_stream_active_sequence_count_++; 215 native_stream_active_sequence_count_++;
212 return false; 216 return false;
213 } 217 }
214 218
215 void TouchEmulator::ForwardTouchEventToClient() { 219 void TouchEmulator::HandleEmulatedTouchEvent(blink::WebTouchEvent event) {
220 auto result = gesture_provider_.OnTouchEvent(MotionEventWeb(event));
221 if (!result.succeeded)
222 return;
223
216 const bool event_consumed = true; 224 const bool event_consumed = true;
217 // Block emulated event when emulated native stream is active. 225 // Block emulated event when emulated native stream is active.
218 if (native_stream_active_sequence_count_) { 226 if (native_stream_active_sequence_count_) {
219 gesture_provider_.OnTouchEventAck(event_consumed); 227 gesture_provider_.OnTouchEventAck(event_consumed);
220 return; 228 return;
221 } 229 }
222 230
223 bool is_sequence_start = 231 bool is_sequence_start = WebTouchEventTraits::IsTouchSequenceStart(event);
224 WebTouchEventTraits::IsTouchSequenceStart(touch_event_);
225 // Do not allow middle-sequence event to pass through, if start was blocked. 232 // Do not allow middle-sequence event to pass through, if start was blocked.
226 if (!emulated_stream_active_sequence_count_ && !is_sequence_start) { 233 if (!emulated_stream_active_sequence_count_ && !is_sequence_start) {
227 gesture_provider_.OnTouchEventAck(event_consumed); 234 gesture_provider_.OnTouchEventAck(event_consumed);
228 return; 235 return;
229 } 236 }
230 237
231 if (is_sequence_start) 238 if (is_sequence_start)
232 emulated_stream_active_sequence_count_++; 239 emulated_stream_active_sequence_count_++;
233 client_->ForwardEmulatedTouchEvent(touch_event_); 240
241 event.causesScrollingIfUncanceled = result.did_generate_scroll;
242 client_->ForwardEmulatedTouchEvent(event);
234 } 243 }
235 244
236 bool TouchEmulator::HandleTouchEventAck( 245 bool TouchEmulator::HandleTouchEventAck(
237 const blink::WebTouchEvent& event, InputEventAckState ack_result) { 246 const blink::WebTouchEvent& event, InputEventAckState ack_result) {
238 bool is_sequence_end = WebTouchEventTraits::IsTouchSequenceEnd(event); 247 bool is_sequence_end = WebTouchEventTraits::IsTouchSequenceEnd(event);
239 if (emulated_stream_active_sequence_count_) { 248 if (emulated_stream_active_sequence_count_) {
240 if (is_sequence_end) 249 if (is_sequence_end)
241 emulated_stream_active_sequence_count_--; 250 emulated_stream_active_sequence_count_--;
242 251
243 const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; 252 const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 328 }
320 329
321 void TouchEmulator::CancelTouch() { 330 void TouchEmulator::CancelTouch() {
322 if (!emulated_stream_active_sequence_count_) 331 if (!emulated_stream_active_sequence_count_)
323 return; 332 return;
324 333
325 WebTouchEventTraits::ResetTypeAndTouchStates( 334 WebTouchEventTraits::ResetTypeAndTouchStates(
326 WebInputEvent::TouchCancel, 335 WebInputEvent::TouchCancel,
327 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(), 336 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(),
328 &touch_event_); 337 &touch_event_);
329 if (gesture_provider_.GetCurrentDownEvent() && 338 if (gesture_provider_.GetCurrentDownEvent())
330 gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) 339 HandleEmulatedTouchEvent(touch_event_);
331 ForwardTouchEventToClient();
332 } 340 }
333 341
334 void TouchEmulator::UpdateCursor() { 342 void TouchEmulator::UpdateCursor() {
335 if (!enabled_) 343 if (!enabled_)
336 client_->SetCursor(pointer_cursor_); 344 client_->SetCursor(pointer_cursor_);
337 else 345 else
338 client_->SetCursor(InPinchGestureMode() ? pinch_cursor_ : touch_cursor_); 346 client_->SetCursor(InPinchGestureMode() ? pinch_cursor_ : touch_cursor_);
339 } 347 }
340 348
341 bool TouchEmulator::UpdateShiftPressed(bool shift_pressed) { 349 bool TouchEmulator::UpdateShiftPressed(bool shift_pressed) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 394
387 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { 395 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) {
388 WebGestureEvent scroll_event; 396 WebGestureEvent scroll_event;
389 scroll_event.timeStampSeconds = event.timeStampSeconds; 397 scroll_event.timeStampSeconds = event.timeStampSeconds;
390 scroll_event.modifiers = event.modifiers; 398 scroll_event.modifiers = event.modifiers;
391 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen; 399 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
392 scroll_event.type = WebInputEvent::GestureScrollEnd; 400 scroll_event.type = WebInputEvent::GestureScrollEnd;
393 client_->ForwardGestureEvent(scroll_event); 401 client_->ForwardGestureEvent(scroll_event);
394 } 402 }
395 403
396 bool TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) { 404 void TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) {
397 if (mouse_event.type != WebInputEvent::MouseDown &&
398 mouse_event.type != WebInputEvent::MouseMove &&
399 mouse_event.type != WebInputEvent::MouseUp) {
400 return false;
401 }
402
403 WebInputEvent::Type eventType; 405 WebInputEvent::Type eventType;
404 switch (mouse_event.type) { 406 switch (mouse_event.type) {
405 case WebInputEvent::MouseDown: 407 case WebInputEvent::MouseDown:
406 eventType = WebInputEvent::TouchStart; 408 eventType = WebInputEvent::TouchStart;
407 break; 409 break;
408 case WebInputEvent::MouseMove: 410 case WebInputEvent::MouseMove:
409 eventType = WebInputEvent::TouchMove; 411 eventType = WebInputEvent::TouchMove;
410 break; 412 break;
411 case WebInputEvent::MouseUp: 413 case WebInputEvent::MouseUp:
412 eventType = WebInputEvent::TouchEnd; 414 eventType = WebInputEvent::TouchEnd;
413 break; 415 break;
414 default: 416 default:
415 eventType = WebInputEvent::Undefined; 417 eventType = WebInputEvent::Undefined;
416 NOTREACHED(); 418 NOTREACHED() << "Invalid event for touch emulation: " << mouse_event.type;
417 } 419 }
418 touch_event_.touchesLength = 1; 420 touch_event_.touchesLength = 1;
419 touch_event_.modifiers = mouse_event.modifiers; 421 touch_event_.modifiers = mouse_event.modifiers;
420 WebTouchEventTraits::ResetTypeAndTouchStates( 422 WebTouchEventTraits::ResetTypeAndTouchStates(
421 eventType, mouse_event.timeStampSeconds, &touch_event_); 423 eventType, mouse_event.timeStampSeconds, &touch_event_);
422 424
423 WebTouchPoint& point = touch_event_.touches[0]; 425 WebTouchPoint& point = touch_event_.touches[0];
424 point.id = 0; 426 point.id = 0;
425 point.radiusX = 0.5f * cursor_size_.width(); 427 point.radiusX = 0.5f * cursor_size_.width();
426 point.radiusY = 0.5f * cursor_size_.height(); 428 point.radiusY = 0.5f * cursor_size_.height();
427 point.force = 1.f; 429 point.force = 1.f;
428 point.rotationAngle = 0.f; 430 point.rotationAngle = 0.f;
429 point.position.x = mouse_event.x; 431 point.position.x = mouse_event.x;
430 point.screenPosition.x = mouse_event.globalX; 432 point.screenPosition.x = mouse_event.globalX;
431 point.position.y = mouse_event.y; 433 point.position.y = mouse_event.y;
432 point.screenPosition.y = mouse_event.globalY; 434 point.screenPosition.y = mouse_event.globalY;
433
434 return true;
435 } 435 }
436 436
437 bool TouchEmulator::InPinchGestureMode() const { 437 bool TouchEmulator::InPinchGestureMode() const {
438 return shift_pressed_; 438 return shift_pressed_;
439 } 439 }
440 440
441 } // namespace content 441 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_emulator.h ('k') | content/browser/renderer_host/input/touch_event_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698