| OLD | NEW |
| 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/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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 const double kMouseMoveDropIntervalSeconds = 5.f / 1000; | 49 const double kMouseMoveDropIntervalSeconds = 5.f / 1000; |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 TouchEmulator::TouchEmulator(TouchEmulatorClient* client, | 53 TouchEmulator::TouchEmulator(TouchEmulatorClient* client, |
| 54 float device_scale_factor) | 54 float device_scale_factor) |
| 55 : client_(client), | 55 : client_(client), |
| 56 gesture_provider_config_type_( | 56 gesture_provider_config_type_( |
| 57 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 57 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
| 58 double_tap_enabled_(true), | 58 double_tap_enabled_(true), |
| 59 use_2x_cursors_(false), |
| 59 emulated_stream_active_sequence_count_(0), | 60 emulated_stream_active_sequence_count_(0), |
| 60 native_stream_active_sequence_count_(0) { | 61 native_stream_active_sequence_count_(0) { |
| 61 DCHECK(client_); | 62 DCHECK(client_); |
| 62 ResetState(); | 63 ResetState(); |
| 63 | 64 InitCursors(device_scale_factor, true); |
| 64 bool use_2x = device_scale_factor > 1.5f; | |
| 65 float cursor_scale_factor = use_2x ? 2.f : 1.f; | |
| 66 cursor_size_ = InitCursorFromResource(&touch_cursor_, | |
| 67 cursor_scale_factor, | |
| 68 use_2x ? IDR_DEVTOOLS_TOUCH_CURSOR_ICON_2X : | |
| 69 IDR_DEVTOOLS_TOUCH_CURSOR_ICON); | |
| 70 InitCursorFromResource(&pinch_cursor_, | |
| 71 cursor_scale_factor, | |
| 72 use_2x ? IDR_DEVTOOLS_PINCH_CURSOR_ICON_2X : | |
| 73 IDR_DEVTOOLS_PINCH_CURSOR_ICON); | |
| 74 | |
| 75 WebCursor::CursorInfo cursor_info; | |
| 76 cursor_info.type = blink::WebCursorInfo::TypePointer; | |
| 77 pointer_cursor_.InitFromCursorInfo(cursor_info); | |
| 78 } | 65 } |
| 79 | 66 |
| 80 TouchEmulator::~TouchEmulator() { | 67 TouchEmulator::~TouchEmulator() { |
| 81 // We cannot cleanup properly in destructor, as we need roundtrip to the | 68 // We cannot cleanup properly in destructor, as we need roundtrip to the |
| 82 // renderer for ack. Instead, the owner should call Disable, and only | 69 // renderer for ack. Instead, the owner should call Disable, and only |
| 83 // destroy this object when renderer is dead. | 70 // destroy this object when renderer is dead. |
| 84 } | 71 } |
| 85 | 72 |
| 86 void TouchEmulator::ResetState() { | 73 void TouchEmulator::ResetState() { |
| 87 last_mouse_event_was_move_ = false; | 74 last_mouse_event_was_move_ = false; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 108 void TouchEmulator::Disable() { | 95 void TouchEmulator::Disable() { |
| 109 if (!enabled()) | 96 if (!enabled()) |
| 110 return; | 97 return; |
| 111 | 98 |
| 112 CancelTouch(); | 99 CancelTouch(); |
| 113 gesture_provider_.reset(); | 100 gesture_provider_.reset(); |
| 114 UpdateCursor(); | 101 UpdateCursor(); |
| 115 ResetState(); | 102 ResetState(); |
| 116 } | 103 } |
| 117 | 104 |
| 105 void TouchEmulator::SetDeviceScaleFactor(float device_scale_factor) { |
| 106 if (!InitCursors(device_scale_factor, false)) |
| 107 return; |
| 108 if (enabled()) |
| 109 UpdateCursor(); |
| 110 } |
| 111 |
| 118 void TouchEmulator::SetDoubleTapSupportForPageEnabled(bool enabled) { | 112 void TouchEmulator::SetDoubleTapSupportForPageEnabled(bool enabled) { |
| 119 double_tap_enabled_ = enabled; | 113 double_tap_enabled_ = enabled; |
| 120 if (gesture_provider_) | 114 if (gesture_provider_) |
| 121 gesture_provider_->SetDoubleTapSupportForPageEnabled(enabled); | 115 gesture_provider_->SetDoubleTapSupportForPageEnabled(enabled); |
| 122 } | 116 } |
| 123 | 117 |
| 118 bool TouchEmulator::InitCursors(float device_scale_factor, bool force) { |
| 119 bool use_2x = device_scale_factor > 1.5f; |
| 120 if (use_2x == use_2x_cursors_ && !force) |
| 121 return false; |
| 122 use_2x_cursors_ = use_2x; |
| 123 float cursor_scale_factor = use_2x ? 2.f : 1.f; |
| 124 cursor_size_ = InitCursorFromResource(&touch_cursor_, |
| 125 cursor_scale_factor, |
| 126 use_2x ? IDR_DEVTOOLS_TOUCH_CURSOR_ICON_2X : |
| 127 IDR_DEVTOOLS_TOUCH_CURSOR_ICON); |
| 128 InitCursorFromResource(&pinch_cursor_, |
| 129 cursor_scale_factor, |
| 130 use_2x ? IDR_DEVTOOLS_PINCH_CURSOR_ICON_2X : |
| 131 IDR_DEVTOOLS_PINCH_CURSOR_ICON); |
| 132 |
| 133 WebCursor::CursorInfo cursor_info; |
| 134 cursor_info.type = blink::WebCursorInfo::TypePointer; |
| 135 pointer_cursor_.InitFromCursorInfo(cursor_info); |
| 136 return true; |
| 137 } |
| 138 |
| 124 gfx::SizeF TouchEmulator::InitCursorFromResource( | 139 gfx::SizeF TouchEmulator::InitCursorFromResource( |
| 125 WebCursor* cursor, float scale, int resource_id) { | 140 WebCursor* cursor, float scale, int resource_id) { |
| 126 gfx::Image& cursor_image = | 141 gfx::Image& cursor_image = |
| 127 content::GetContentClient()->GetNativeImageNamed(resource_id); | 142 content::GetContentClient()->GetNativeImageNamed(resource_id); |
| 128 WebCursor::CursorInfo cursor_info; | 143 WebCursor::CursorInfo cursor_info; |
| 129 cursor_info.type = blink::WebCursorInfo::TypeCustom; | 144 cursor_info.type = blink::WebCursorInfo::TypeCustom; |
| 130 cursor_info.image_scale_factor = scale; | 145 cursor_info.image_scale_factor = scale; |
| 131 cursor_info.custom_image = cursor_image.AsBitmap(); | 146 cursor_info.custom_image = cursor_image.AsBitmap(); |
| 132 cursor_info.hotspot = | 147 cursor_info.hotspot = |
| 133 gfx::Point(cursor_image.Width() / 2, cursor_image.Height() / 2); | 148 gfx::Point(cursor_image.Width() / 2, cursor_image.Height() / 2); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 point.tiltX = 0; | 467 point.tiltX = 0; |
| 453 point.tiltY = 0; | 468 point.tiltY = 0; |
| 454 point.pointerType = blink::WebPointerProperties::PointerType::Touch; | 469 point.pointerType = blink::WebPointerProperties::PointerType::Touch; |
| 455 } | 470 } |
| 456 | 471 |
| 457 bool TouchEmulator::InPinchGestureMode() const { | 472 bool TouchEmulator::InPinchGestureMode() const { |
| 458 return shift_pressed_; | 473 return shift_pressed_; |
| 459 } | 474 } |
| 460 | 475 |
| 461 } // namespace content | 476 } // namespace content |
| OLD | NEW |