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

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

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