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