OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_EVENT_SENDER_H_ | |
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_EVENT_SENDER_H_ | |
7 | |
8 #include <queue> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "build/build_config.h" | |
16 #include "content/shell/renderer/test_runner/web_task.h" | |
17 #include "third_party/WebKit/public/platform/WebDragData.h" | |
18 #include "third_party/WebKit/public/platform/WebPoint.h" | |
19 #include "third_party/WebKit/public/web/WebDragOperation.h" | |
20 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
21 #include "third_party/WebKit/public/web/WebTouchPoint.h" | |
22 | |
23 namespace blink { | |
24 class WebFrame; | |
25 class WebView; | |
26 struct WebContextMenuData; | |
27 } | |
28 | |
29 namespace gin { | |
30 class Arguments; | |
31 } | |
32 | |
33 namespace content { | |
34 | |
35 class TestInterfaces; | |
36 class WebTestDelegate; | |
37 | |
38 // Key event location code introduced in DOM Level 3. | |
39 // See also: http://www.w3.org/TR/DOM-Level-3-Events/#events-keyboardevents | |
40 enum KeyLocationCode { | |
41 DOMKeyLocationStandard = 0x00, | |
42 DOMKeyLocationLeft = 0x01, | |
43 DOMKeyLocationRight = 0x02, | |
44 DOMKeyLocationNumpad = 0x03 | |
45 }; | |
46 | |
47 class EventSender : public base::SupportsWeakPtr<EventSender> { | |
48 public: | |
49 explicit EventSender(TestInterfaces*); | |
50 virtual ~EventSender(); | |
51 | |
52 void Reset(); | |
53 void Install(blink::WebFrame*); | |
54 void SetDelegate(WebTestDelegate*); | |
55 void SetWebView(blink::WebView*); | |
56 | |
57 void SetContextMenuData(const blink::WebContextMenuData&); | |
58 | |
59 void DoDragDrop(const blink::WebDragData&, blink::WebDragOperationsMask); | |
60 | |
61 void MouseDown(int button_number, int modifiers); | |
62 void MouseUp(int button_number, int modifiers); | |
63 void KeyDown(const std::string& code_str, | |
64 int modifiers, | |
65 KeyLocationCode location); | |
66 | |
67 WebTaskList* mutable_task_list() { return &task_list_; } | |
68 | |
69 private: | |
70 friend class EventSenderBindings; | |
71 | |
72 struct SavedEvent { | |
73 enum SavedEventType { | |
74 TYPE_UNSPECIFIED, | |
75 TYPE_MOUSE_UP, | |
76 TYPE_MOUSE_MOVE, | |
77 TYPE_LEAP_FORWARD | |
78 }; | |
79 | |
80 SavedEvent(); | |
81 | |
82 SavedEventType type; | |
83 blink::WebMouseEvent::Button button_type; // For MouseUp. | |
84 blink::WebPoint pos; // For MouseMove. | |
85 int milliseconds; // For LeapForward. | |
86 int modifiers; | |
87 }; | |
88 | |
89 void EnableDOMUIEventLogging(); | |
90 void FireKeyboardEventsToElement(); | |
91 void ClearKillRing(); | |
92 | |
93 std::vector<std::string> ContextClick(); | |
94 | |
95 void TextZoomIn(); | |
96 void TextZoomOut(); | |
97 | |
98 void ZoomPageIn(); | |
99 void ZoomPageOut(); | |
100 void SetPageZoomFactor(double zoom_factor); | |
101 | |
102 // TODO: Move these into Internals once PageScaleConstraints are moved out of | |
103 // Source/web. crbug.com/434450. | |
104 void SetPageScaleFactor(float scale_factor, int x, int y); | |
105 void SetPageScaleFactorLimits(float min_scale, float max_scale); | |
106 | |
107 void ClearTouchPoints(); | |
108 void ReleaseTouchPoint(unsigned index); | |
109 void UpdateTouchPoint(unsigned index, float x, float y); | |
110 void CancelTouchPoint(unsigned index); | |
111 void SetTouchModifier(const std::string& key_name, bool set_mask); | |
112 void SetTouchCancelable(bool cancelable); | |
113 void ThrowTouchPointError(); | |
114 | |
115 void DumpFilenameBeingDragged(); | |
116 | |
117 void GestureFlingCancel(); | |
118 void GestureFlingStart(float x, | |
119 float y, | |
120 float velocity_x, | |
121 float velocity_y, | |
122 gin::Arguments* args); | |
123 void GestureScrollFirstPoint(int x, int y); | |
124 | |
125 void TouchStart(); | |
126 void TouchMove(); | |
127 void TouchCancel(); | |
128 void TouchEnd(); | |
129 | |
130 void LeapForward(int milliseconds); | |
131 | |
132 void BeginDragWithFiles(const std::vector<std::string>& files); | |
133 | |
134 void AddTouchPoint(gin::Arguments* args); | |
135 | |
136 void MouseDragBegin(); | |
137 void MouseDragEnd(); | |
138 | |
139 void GestureScrollBegin(gin::Arguments* args); | |
140 void GestureScrollEnd(gin::Arguments* args); | |
141 void GestureScrollUpdate(gin::Arguments* args); | |
142 void GesturePinchBegin(gin::Arguments* args); | |
143 void GesturePinchEnd(gin::Arguments* args); | |
144 void GesturePinchUpdate(gin::Arguments* args); | |
145 void GestureTap(gin::Arguments* args); | |
146 void GestureTapDown(gin::Arguments* args); | |
147 void GestureShowPress(gin::Arguments* args); | |
148 void GestureTapCancel(gin::Arguments* args); | |
149 void GestureLongPress(gin::Arguments* args); | |
150 void GestureLongTap(gin::Arguments* args); | |
151 void GestureTwoFingerTap(gin::Arguments* args); | |
152 | |
153 void ContinuousMouseScrollBy(gin::Arguments* args); | |
154 void MouseMoveTo(gin::Arguments* args); | |
155 void MouseLeave(); | |
156 void TrackpadScrollBegin(); | |
157 void TrackpadScroll(gin::Arguments* args); | |
158 void TrackpadScrollEnd(); | |
159 void MouseScrollBy(gin::Arguments* args); | |
160 void MouseMomentumBegin(); | |
161 void MouseMomentumBegin2(gin::Arguments* args); | |
162 void MouseMomentumScrollBy(gin::Arguments* args); | |
163 void MouseMomentumEnd(); | |
164 void ScheduleAsynchronousClick(int button_number, int modifiers); | |
165 void ScheduleAsynchronousKeyDown(const std::string& code_str, | |
166 int modifiers, | |
167 KeyLocationCode location); | |
168 | |
169 double GetCurrentEventTimeSec(); | |
170 | |
171 void DoLeapForward(int milliseconds); | |
172 | |
173 void SendCurrentTouchEvent(blink::WebInputEvent::Type); | |
174 | |
175 void GestureEvent(blink::WebInputEvent::Type, | |
176 gin::Arguments*); | |
177 | |
178 void UpdateClickCountForButton(blink::WebMouseEvent::Button); | |
179 | |
180 void InitMouseWheelEvent(gin::Arguments* args, | |
181 bool continuous, | |
182 blink::WebMouseWheelEvent* event); | |
183 | |
184 void FinishDragAndDrop(const blink::WebMouseEvent&, blink::WebDragOperation); | |
185 | |
186 void DoMouseUp(const blink::WebMouseEvent&); | |
187 void DoMouseMove(const blink::WebMouseEvent&); | |
188 void ReplaySavedEvents(); | |
189 bool HandleInputEventOnViewOrPopup(const blink::WebInputEvent&); | |
190 | |
191 bool force_layout_on_events() const { return force_layout_on_events_; } | |
192 void set_force_layout_on_events(bool force) { | |
193 force_layout_on_events_ = force; | |
194 } | |
195 | |
196 bool is_drag_mode() const { return is_drag_mode_; } | |
197 void set_is_drag_mode(bool drag_mode) { is_drag_mode_ = drag_mode; } | |
198 | |
199 #if defined(OS_WIN) | |
200 int wm_key_down() const { return wm_key_down_; } | |
201 void set_wm_key_down(int key_down) { wm_key_down_ = key_down; } | |
202 | |
203 int wm_key_up() const { return wm_key_up_; } | |
204 void set_wm_key_up(int key_up) { wm_key_up_ = key_up; } | |
205 | |
206 int wm_char() const { return wm_char_; } | |
207 void set_wm_char(int wm_char) { wm_char_ = wm_char; } | |
208 | |
209 int wm_dead_char() const { return wm_dead_char_; } | |
210 void set_wm_dead_char(int dead_char) { | |
211 wm_dead_char_ = dead_char; | |
212 } | |
213 | |
214 int wm_sys_key_down() const { return wm_sys_key_down_; } | |
215 void set_wm_sys_key_down(int key_down) { wm_sys_key_down_ = key_down; } | |
216 | |
217 int wm_sys_key_up() const { return wm_sys_key_up_; } | |
218 void set_wm_sys_key_up(int key_up) { wm_sys_key_up_ = key_up; } | |
219 | |
220 int wm_sys_char() const { return wm_sys_char_; } | |
221 void set_wm_sys_char(int sys_char) { wm_sys_char_ = sys_char; } | |
222 | |
223 int wm_sys_dead_char() const { return wm_sys_dead_char_; } | |
224 void set_wm_sys_dead_char(int sys_dead_char) { | |
225 wm_sys_dead_char_ = sys_dead_char; | |
226 } | |
227 | |
228 int wm_key_down_; | |
229 int wm_key_up_; | |
230 int wm_char_; | |
231 int wm_dead_char_; | |
232 int wm_sys_key_down_; | |
233 int wm_sys_key_up_; | |
234 int wm_sys_char_; | |
235 int wm_sys_dead_char_; | |
236 #endif | |
237 | |
238 WebTaskList task_list_; | |
239 | |
240 TestInterfaces* interfaces_; | |
241 WebTestDelegate* delegate_; | |
242 blink::WebView* view_; | |
243 | |
244 bool force_layout_on_events_; | |
245 | |
246 // When set to true (the default value), we batch mouse move and mouse up | |
247 // events so we can simulate drag & drop. | |
248 bool is_drag_mode_; | |
249 | |
250 int touch_modifiers_; | |
251 bool touch_cancelable_; | |
252 std::vector<blink::WebTouchPoint> touch_points_; | |
253 | |
254 scoped_ptr<blink::WebContextMenuData> last_context_menu_data_; | |
255 | |
256 blink::WebDragData current_drag_data_; | |
257 | |
258 // Location of the touch point that initiated a gesture. | |
259 blink::WebPoint current_gesture_location_; | |
260 | |
261 // Currently pressed mouse button (Left/Right/Middle or None). | |
262 static blink::WebMouseEvent::Button pressed_button_; | |
263 static int modifiers_; | |
264 | |
265 bool replaying_saved_events_; | |
266 | |
267 std::deque<SavedEvent> mouse_event_queue_; | |
268 | |
269 blink::WebDragOperationsMask current_drag_effects_allowed_; | |
270 | |
271 // Location of last mouseMoveTo event. | |
272 static blink::WebPoint last_mouse_pos_; | |
273 | |
274 // Time and place of the last mouse up event. | |
275 double last_click_time_sec_; | |
276 blink::WebPoint last_click_pos_; | |
277 | |
278 // The last button number passed to mouseDown and mouseUp. | |
279 // Used to determine whether the click count continues to increment or not. | |
280 static blink::WebMouseEvent::Button last_button_type_; | |
281 | |
282 blink::WebDragOperation current_drag_effect_; | |
283 | |
284 uint32 time_offset_ms_; | |
285 int click_count_; | |
286 | |
287 base::WeakPtrFactory<EventSender> weak_factory_; | |
288 | |
289 DISALLOW_COPY_AND_ASSIGN(EventSender); | |
290 }; | |
291 | |
292 } // namespace content | |
293 | |
294 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_EVENT_SENDER_H_ | |
OLD | NEW |