| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 double GetNextEventTimeSeconds() { | 108 double GetNextEventTimeSeconds() { |
| 109 last_event_time_seconds_ += event_time_delta_seconds_; | 109 last_event_time_seconds_ += event_time_delta_seconds_; |
| 110 return last_event_time_seconds_; | 110 return last_event_time_seconds_; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void set_event_time_delta_seconds_(double delta) { | 113 void set_event_time_delta_seconds_(double delta) { |
| 114 event_time_delta_seconds_ = delta; | 114 event_time_delta_seconds_ = delta; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void SendKeyboardEvent(WebInputEvent::Type type) { | 117 void SendKeyboardEvent(WebInputEvent::Type type) { |
| 118 WebKeyboardEvent event; | 118 WebKeyboardEvent event(type, modifiers(), GetNextEventTimeSeconds()); |
| 119 event.timeStampSeconds = GetNextEventTimeSeconds(); | |
| 120 event.type = type; | |
| 121 event.modifiers = modifiers(); | |
| 122 emulator()->HandleKeyboardEvent(event); | 119 emulator()->HandleKeyboardEvent(event); |
| 123 } | 120 } |
| 124 | 121 |
| 125 void PressShift() { | 122 void PressShift() { |
| 126 DCHECK(!shift_pressed_); | 123 DCHECK(!shift_pressed_); |
| 127 shift_pressed_ = true; | 124 shift_pressed_ = true; |
| 128 SendKeyboardEvent(WebInputEvent::KeyDown); | 125 SendKeyboardEvent(WebInputEvent::KeyDown); |
| 129 } | 126 } |
| 130 | 127 |
| 131 void ReleaseShift() { | 128 void ReleaseShift() { |
| 132 DCHECK(shift_pressed_); | 129 DCHECK(shift_pressed_); |
| 133 shift_pressed_ = false; | 130 shift_pressed_ = false; |
| 134 SendKeyboardEvent(WebInputEvent::KeyUp); | 131 SendKeyboardEvent(WebInputEvent::KeyUp); |
| 135 } | 132 } |
| 136 | 133 |
| 137 void SendMouseEvent(WebInputEvent::Type type, int x, int y) { | 134 void SendMouseEvent(WebInputEvent::Type type, int x, int y) { |
| 138 WebMouseEvent event; | 135 WebMouseEvent event(type, modifiers(), GetNextEventTimeSeconds()); |
| 139 event.timeStampSeconds = GetNextEventTimeSeconds(); | |
| 140 event.type = type; | |
| 141 event.button = mouse_pressed_ ? WebMouseEvent::Button::Left : | 136 event.button = mouse_pressed_ ? WebMouseEvent::Button::Left : |
| 142 WebMouseEvent::Button::NoButton; | 137 WebMouseEvent::Button::NoButton; |
| 143 event.modifiers = modifiers(); | |
| 144 last_mouse_x_ = x; | 138 last_mouse_x_ = x; |
| 145 last_mouse_y_ = y; | 139 last_mouse_y_ = y; |
| 146 event.x = event.windowX = event.globalX = x; | 140 event.x = event.windowX = event.globalX = x; |
| 147 event.y = event.windowY = event.globalY = y; | 141 event.y = event.windowY = event.globalY = y; |
| 148 emulator()->HandleMouseEvent(event); | 142 emulator()->HandleMouseEvent(event); |
| 149 } | 143 } |
| 150 | 144 |
| 151 bool SendMouseWheelEvent() { | 145 bool SendMouseWheelEvent() { |
| 152 WebMouseWheelEvent event; | 146 WebMouseWheelEvent event(WebInputEvent::MouseWheel, modifiers(), |
| 153 event.type = WebInputEvent::MouseWheel; | 147 GetNextEventTimeSeconds()); |
| 154 event.timeStampSeconds = GetNextEventTimeSeconds(); | |
| 155 // Return whether mouse wheel is forwarded. | 148 // Return whether mouse wheel is forwarded. |
| 156 return !emulator()->HandleMouseWheelEvent(event); | 149 return !emulator()->HandleMouseWheelEvent(event); |
| 157 } | 150 } |
| 158 | 151 |
| 159 void MouseDown(int x, int y) { | 152 void MouseDown(int x, int y) { |
| 160 DCHECK(!mouse_pressed_); | 153 DCHECK(!mouse_pressed_); |
| 161 if (x != last_mouse_x_ || y != last_mouse_y_) | 154 if (x != last_mouse_x_ || y != last_mouse_y_) |
| 162 SendMouseEvent(WebInputEvent::MouseMove, x, y); | 155 SendMouseEvent(WebInputEvent::MouseMove, x, y); |
| 163 mouse_pressed_ = true; | 156 mouse_pressed_ = true; |
| 164 SendMouseEvent(WebInputEvent::MouseDown, x, y); | 157 SendMouseEvent(WebInputEvent::MouseDown, x, y); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 192 WebInputEvent::TouchMove, WebTouchPoint::StateMoved, x, y, ack); | 185 WebInputEvent::TouchMove, WebTouchPoint::StateMoved, x, y, ack); |
| 193 } | 186 } |
| 194 | 187 |
| 195 bool TouchEnd(int x, int y, bool ack) { | 188 bool TouchEnd(int x, int y, bool ack) { |
| 196 return SendTouchEvent( | 189 return SendTouchEvent( |
| 197 WebInputEvent::TouchEnd, WebTouchPoint::StateReleased, x, y, ack); | 190 WebInputEvent::TouchEnd, WebTouchPoint::StateReleased, x, y, ack); |
| 198 } | 191 } |
| 199 | 192 |
| 200 WebTouchEvent MakeTouchEvent(WebInputEvent::Type type, | 193 WebTouchEvent MakeTouchEvent(WebInputEvent::Type type, |
| 201 WebTouchPoint::State state, int x, int y) { | 194 WebTouchPoint::State state, int x, int y) { |
| 202 WebTouchEvent event; | 195 WebTouchEvent event(type, modifiers(), GetNextEventTimeSeconds()); |
| 203 event.type = type; | |
| 204 event.timeStampSeconds = GetNextEventTimeSeconds(); | |
| 205 event.touchesLength = 1; | 196 event.touchesLength = 1; |
| 206 event.touches[0].id = 0; | 197 event.touches[0].id = 0; |
| 207 event.touches[0].state = state; | 198 event.touches[0].state = state; |
| 208 event.touches[0].position.x = x; | 199 event.touches[0].position.x = x; |
| 209 event.touches[0].position.y = y; | 200 event.touches[0].position.y = y; |
| 210 event.touches[0].screenPosition.x = x; | 201 event.touches[0].screenPosition.x = x; |
| 211 event.touches[0].screenPosition.y = y; | 202 event.touches[0].screenPosition.y = y; |
| 212 return event; | 203 return event; |
| 213 } | 204 } |
| 214 | 205 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 emulator()->SetDeviceScaleFactor(1.0f); | 585 emulator()->SetDeviceScaleFactor(1.0f); |
| 595 EXPECT_EQ(1.0f, GetCursorScaleFactor()); | 586 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 596 | 587 |
| 597 TouchEmulator another(this, 4.0f); | 588 TouchEmulator another(this, 4.0f); |
| 598 EXPECT_EQ(1.0f, GetCursorScaleFactor()); | 589 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 599 another.Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); | 590 another.Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
| 600 EXPECT_EQ(2.0f, GetCursorScaleFactor()); | 591 EXPECT_EQ(2.0f, GetCursorScaleFactor()); |
| 601 } | 592 } |
| 602 | 593 |
| 603 } // namespace content | 594 } // namespace content |
| OLD | NEW |