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

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

Issue 821223002: Pass gesture detector config type when enabling touch emulator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@touch-emulator-enabled
Patch Set: Fixed cursor reset, rebased Created 5 years, 11 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
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"
11 #include "content/public/common/content_client.h" 11 #include "content/public/common/content_client.h"
12 #include "content/public/common/content_switches.h" 12 #include "content/public/common/content_switches.h"
13 #include "third_party/WebKit/public/platform/WebCursorInfo.h" 13 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
14 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 14 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
15 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/screen.h" 16 #include "ui/gfx/screen.h"
17 17
18 using blink::WebGestureEvent; 18 using blink::WebGestureEvent;
19 using blink::WebInputEvent; 19 using blink::WebInputEvent;
20 using blink::WebKeyboardEvent; 20 using blink::WebKeyboardEvent;
21 using blink::WebMouseEvent; 21 using blink::WebMouseEvent;
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 GetEmulatorGestureProviderConfig(
31 // TODO(dgozman): Use different configs to emulate mobile/desktop as 31 ui::GestureProviderConfigType config_type) {
32 // requested by renderer, crbug/425586. 32 ui::GestureProvider::Config config =
33 ui::GestureProvider::Config config = ui::GetGestureProviderConfig( 33 ui::GetGestureProviderConfig(config_type);
34 ui::GestureProviderConfigType::GENERIC_MOBILE);
35 config.gesture_begin_end_types_enabled = false; 34 config.gesture_begin_end_types_enabled = false;
36 config.gesture_detector_config.swipe_enabled = false; 35 config.gesture_detector_config.swipe_enabled = false;
37 config.gesture_detector_config.two_finger_tap_enabled = false; 36 config.gesture_detector_config.two_finger_tap_enabled = false;
38 return config; 37 return config;
39 } 38 }
40 39
41 // Time between two consecutive mouse moves, during which second mouse move 40 // Time between two consecutive mouse moves, during which second mouse move
42 // is not converted to touch. 41 // is not converted to touch.
43 const double kMouseMoveDropIntervalSeconds = 5.f / 1000; 42 const double kMouseMoveDropIntervalSeconds = 5.f / 1000;
44 43
45 } // namespace 44 } // namespace
46 45
47 TouchEmulator::TouchEmulator(TouchEmulatorClient* client) 46 TouchEmulator::TouchEmulator(TouchEmulatorClient* client)
48 : client_(client), 47 : client_(client),
48 gesture_provider_config_type_(
49 ui::GestureProviderConfigType::CURRENT_PLATFORM),
49 emulated_stream_active_sequence_count_(0), 50 emulated_stream_active_sequence_count_(0),
50 native_stream_active_sequence_count_(0) { 51 native_stream_active_sequence_count_(0) {
51 DCHECK(client_); 52 DCHECK(client_);
52 ResetState(); 53 ResetState();
53 54
54 bool use_2x = gfx::Screen::GetNativeScreen()-> 55 bool use_2x = gfx::Screen::GetNativeScreen()->
55 GetPrimaryDisplay().device_scale_factor() > 1.5f; 56 GetPrimaryDisplay().device_scale_factor() > 1.5f;
56 float cursor_scale_factor = use_2x ? 2.f : 1.f; 57 float cursor_scale_factor = use_2x ? 2.f : 1.f;
57 cursor_size_ = InitCursorFromResource(&touch_cursor_, 58 cursor_size_ = InitCursorFromResource(&touch_cursor_,
58 cursor_scale_factor, 59 cursor_scale_factor,
(...skipping 18 matching lines...) Expand all
77 void TouchEmulator::ResetState() { 78 void TouchEmulator::ResetState() {
78 last_mouse_event_was_move_ = false; 79 last_mouse_event_was_move_ = false;
79 last_mouse_move_timestamp_ = 0; 80 last_mouse_move_timestamp_ = 0;
80 mouse_pressed_ = false; 81 mouse_pressed_ = false;
81 shift_pressed_ = false; 82 shift_pressed_ = false;
82 suppress_next_fling_cancel_ = false; 83 suppress_next_fling_cancel_ = false;
83 pinch_scale_ = 1.f; 84 pinch_scale_ = 1.f;
84 pinch_gesture_active_ = false; 85 pinch_gesture_active_ = false;
85 } 86 }
86 87
87 void TouchEmulator::Enable() { 88 void TouchEmulator::Enable(ui::GestureProviderConfigType config_type) {
88 if (!enabled()) { 89 if (!gesture_provider_ || gesture_provider_config_type_ != config_type) {
90 gesture_provider_config_type_ = config_type;
89 gesture_provider_.reset(new ui::FilteredGestureProvider( 91 gesture_provider_.reset(new ui::FilteredGestureProvider(
90 GetGestureProviderConfig(), this)); 92 GetEmulatorGestureProviderConfig(config_type), this));
91 // TODO(dgozman): Use synthetic secondary touch to support multi-touch. 93 // TODO(dgozman): Use synthetic secondary touch to support multi-touch.
92 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 94 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
93 // TODO(dgozman): Enable double tap if requested by the renderer. 95 // TODO(dgozman): Enable double tap if requested by the renderer.
94 // TODO(dgozman): Don't break double-tap-based pinch with shift handling. 96 // TODO(dgozman): Don't break double-tap-based pinch with shift handling.
95 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 97 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
96
97 ResetState();
98 } 98 }
99 UpdateCursor(); 99 UpdateCursor();
100 } 100 }
101 101
102 void TouchEmulator::Disable() { 102 void TouchEmulator::Disable() {
103 if (!enabled()) 103 if (!enabled())
104 return; 104 return;
105 105
106 UpdateCursor();
107 CancelTouch(); 106 CancelTouch();
108 gesture_provider_.reset(); 107 gesture_provider_.reset();
108 UpdateCursor();
109 ResetState();
109 } 110 }
110 111
111 gfx::SizeF TouchEmulator::InitCursorFromResource( 112 gfx::SizeF TouchEmulator::InitCursorFromResource(
112 WebCursor* cursor, float scale, int resource_id) { 113 WebCursor* cursor, float scale, int resource_id) {
113 gfx::Image& cursor_image = 114 gfx::Image& cursor_image =
114 content::GetContentClient()->GetNativeImageNamed(resource_id); 115 content::GetContentClient()->GetNativeImageNamed(resource_id);
115 WebCursor::CursorInfo cursor_info; 116 WebCursor::CursorInfo cursor_info;
116 cursor_info.type = blink::WebCursorInfo::TypeCustom; 117 cursor_info.type = blink::WebCursorInfo::TypeCustom;
117 cursor_info.image_scale_factor = scale; 118 cursor_info.image_scale_factor = scale;
118 cursor_info.custom_image = cursor_image.AsBitmap(); 119 cursor_info.custom_image = cursor_image.AsBitmap();
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 point.screenPosition.x = mouse_event.globalX; 436 point.screenPosition.x = mouse_event.globalX;
436 point.position.y = mouse_event.y; 437 point.position.y = mouse_event.y;
437 point.screenPosition.y = mouse_event.globalY; 438 point.screenPosition.y = mouse_event.globalY;
438 } 439 }
439 440
440 bool TouchEmulator::InPinchGestureMode() const { 441 bool TouchEmulator::InPinchGestureMode() const {
441 return shift_pressed_; 442 return shift_pressed_;
442 } 443 }
443 444
444 } // namespace content 445 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_emulator.h ('k') | content/browser/renderer_host/input/touch_emulator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698