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

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

Issue 2084043003: Touch emulator: clear mouse buttons modifiers on emulated touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, renamed function Created 4 years, 6 months 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
« no previous file with comments | « no previous file | content/browser/renderer_host/input/touch_emulator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 7 #include "build/build_config.h"
8 #include "content/browser/renderer_host/input/motion_event_web.h" 8 #include "content/browser/renderer_host/input/motion_event_web.h"
9 #include "content/browser/renderer_host/input/web_input_event_util.h" 9 #include "content/browser/renderer_host/input/web_input_event_util.h"
10 #include "content/common/input/web_touch_event_traits.h" 10 #include "content/common/input/web_touch_event_traits.h"
(...skipping 21 matching lines...) Expand all
32 ui::GestureProvider::Config GetEmulatorGestureProviderConfig( 32 ui::GestureProvider::Config GetEmulatorGestureProviderConfig(
33 ui::GestureProviderConfigType config_type) { 33 ui::GestureProviderConfigType config_type) {
34 ui::GestureProvider::Config config = 34 ui::GestureProvider::Config config =
35 ui::GetGestureProviderConfig(config_type); 35 ui::GetGestureProviderConfig(config_type);
36 config.gesture_begin_end_types_enabled = false; 36 config.gesture_begin_end_types_enabled = false;
37 config.gesture_detector_config.swipe_enabled = false; 37 config.gesture_detector_config.swipe_enabled = false;
38 config.gesture_detector_config.two_finger_tap_enabled = false; 38 config.gesture_detector_config.two_finger_tap_enabled = false;
39 return config; 39 return config;
40 } 40 }
41 41
42 int ModifiersWithoutMouseButtons(const WebInputEvent& event) {
43 const int all_buttons = WebInputEvent::LeftButtonDown |
44 WebInputEvent::MiddleButtonDown | WebInputEvent::RightButtonDown;
45 return event.modifiers & ~all_buttons;
46 }
47
42 // Time between two consecutive mouse moves, during which second mouse move 48 // Time between two consecutive mouse moves, during which second mouse move
43 // is not converted to touch. 49 // is not converted to touch.
44 const double kMouseMoveDropIntervalSeconds = 5.f / 1000; 50 const double kMouseMoveDropIntervalSeconds = 5.f / 1000;
45 51
46 } // namespace 52 } // namespace
47 53
48 TouchEmulator::TouchEmulator(TouchEmulatorClient* client, 54 TouchEmulator::TouchEmulator(TouchEmulatorClient* client,
49 float device_scale_factor) 55 float device_scale_factor)
50 : client_(client), 56 : client_(client),
51 gesture_provider_config_type_( 57 gesture_provider_config_type_(
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 void TouchEmulator::PinchEnd(const WebGestureEvent& event) { 397 void TouchEmulator::PinchEnd(const WebGestureEvent& event) {
392 DCHECK(pinch_gesture_active_); 398 DCHECK(pinch_gesture_active_);
393 pinch_gesture_active_ = false; 399 pinch_gesture_active_ = false;
394 FillPinchEvent(event); 400 FillPinchEvent(event);
395 pinch_event_.type = WebInputEvent::GesturePinchEnd; 401 pinch_event_.type = WebInputEvent::GesturePinchEnd;
396 client_->ForwardEmulatedGestureEvent(pinch_event_); 402 client_->ForwardEmulatedGestureEvent(pinch_event_);
397 } 403 }
398 404
399 void TouchEmulator::FillPinchEvent(const WebInputEvent& event) { 405 void TouchEmulator::FillPinchEvent(const WebInputEvent& event) {
400 pinch_event_.timeStampSeconds = event.timeStampSeconds; 406 pinch_event_.timeStampSeconds = event.timeStampSeconds;
401 pinch_event_.modifiers = event.modifiers; 407 pinch_event_.modifiers = ModifiersWithoutMouseButtons(event);
402 pinch_event_.sourceDevice = blink::WebGestureDeviceTouchscreen; 408 pinch_event_.sourceDevice = blink::WebGestureDeviceTouchscreen;
403 pinch_event_.x = pinch_anchor_.x(); 409 pinch_event_.x = pinch_anchor_.x();
404 pinch_event_.y = pinch_anchor_.y(); 410 pinch_event_.y = pinch_anchor_.y();
405 } 411 }
406 412
407 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) { 413 void TouchEmulator::ScrollEnd(const WebGestureEvent& event) {
408 WebGestureEvent scroll_event; 414 WebGestureEvent scroll_event;
409 scroll_event.timeStampSeconds = event.timeStampSeconds; 415 scroll_event.timeStampSeconds = event.timeStampSeconds;
410 scroll_event.modifiers = event.modifiers; 416 scroll_event.modifiers = ModifiersWithoutMouseButtons(event);
411 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen; 417 scroll_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
412 scroll_event.type = WebInputEvent::GestureScrollEnd; 418 scroll_event.type = WebInputEvent::GestureScrollEnd;
413 client_->ForwardEmulatedGestureEvent(scroll_event); 419 client_->ForwardEmulatedGestureEvent(scroll_event);
414 } 420 }
415 421
416 void TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) { 422 void TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) {
417 WebInputEvent::Type eventType; 423 WebInputEvent::Type eventType;
418 switch (mouse_event.type) { 424 switch (mouse_event.type) {
419 case WebInputEvent::MouseDown: 425 case WebInputEvent::MouseDown:
420 eventType = WebInputEvent::TouchStart; 426 eventType = WebInputEvent::TouchStart;
421 break; 427 break;
422 case WebInputEvent::MouseMove: 428 case WebInputEvent::MouseMove:
423 eventType = WebInputEvent::TouchMove; 429 eventType = WebInputEvent::TouchMove;
424 break; 430 break;
425 case WebInputEvent::MouseUp: 431 case WebInputEvent::MouseUp:
426 eventType = WebInputEvent::TouchEnd; 432 eventType = WebInputEvent::TouchEnd;
427 break; 433 break;
428 default: 434 default:
429 eventType = WebInputEvent::Undefined; 435 eventType = WebInputEvent::Undefined;
430 NOTREACHED() << "Invalid event for touch emulation: " << mouse_event.type; 436 NOTREACHED() << "Invalid event for touch emulation: " << mouse_event.type;
431 } 437 }
432 touch_event_.touchesLength = 1; 438 touch_event_.touchesLength = 1;
433 touch_event_.modifiers = mouse_event.modifiers; 439 touch_event_.modifiers = ModifiersWithoutMouseButtons(mouse_event);
434 WebTouchEventTraits::ResetTypeAndTouchStates( 440 WebTouchEventTraits::ResetTypeAndTouchStates(
435 eventType, mouse_event.timeStampSeconds, &touch_event_); 441 eventType, mouse_event.timeStampSeconds, &touch_event_);
436 442
437 WebTouchPoint& point = touch_event_.touches[0]; 443 WebTouchPoint& point = touch_event_.touches[0];
438 point.id = 0; 444 point.id = 0;
439 point.radiusX = 0.5f * cursor_size_.width(); 445 point.radiusX = 0.5f * cursor_size_.width();
440 point.radiusY = 0.5f * cursor_size_.height(); 446 point.radiusY = 0.5f * cursor_size_.height();
441 point.force = 1.f; 447 point.force = 1.f;
442 point.rotationAngle = 0.f; 448 point.rotationAngle = 0.f;
443 point.position.x = mouse_event.x; 449 point.position.x = mouse_event.x;
444 point.screenPosition.x = mouse_event.globalX; 450 point.screenPosition.x = mouse_event.globalX;
445 point.position.y = mouse_event.y; 451 point.position.y = mouse_event.y;
446 point.screenPosition.y = mouse_event.globalY; 452 point.screenPosition.y = mouse_event.globalY;
447 point.tiltX = 0; 453 point.tiltX = 0;
448 point.tiltY = 0; 454 point.tiltY = 0;
449 point.pointerType = blink::WebPointerProperties::PointerType::Touch; 455 point.pointerType = blink::WebPointerProperties::PointerType::Touch;
450 } 456 }
451 457
452 bool TouchEmulator::InPinchGestureMode() const { 458 bool TouchEmulator::InPinchGestureMode() const {
453 return shift_pressed_; 459 return shift_pressed_;
454 } 460 }
455 461
456 } // namespace content 462 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/input/touch_emulator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698