1 /* |
|
2 * Copyright (C) 2010 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
8 * * Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * * Redistributions in binary form must reproduce the above |
|
11 * copyright notice, this list of conditions and the following disclaimer |
|
12 * in the documentation and/or other materials provided with the |
|
13 * distribution. |
|
14 * * Neither the name of Google Inc. nor the names of its |
|
15 * contributors may be used to endorse or promote products derived from |
|
16 * this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 */ |
|
30 |
|
31 /* |
|
32 EventSender class: |
|
33 Bound to a JavaScript window.eventSender object using |
|
34 CppBoundClass::bindToJavascript(), this allows layout tests to fire DOM events. |
|
35 */ |
|
36 |
|
37 #ifndef EventSender_h |
|
38 #define EventSender_h |
|
39 |
|
40 #include "CppBoundClass.h" |
|
41 #include "base/task.h" |
|
42 #include "public/WebDragOperation.h" |
|
43 #include "public/WebInputEvent.h" |
|
44 #include "public/WebPoint.h" |
|
45 |
|
46 class TestShell; |
|
47 |
|
48 namespace WebKit { |
|
49 class WebDragData; |
|
50 class WebView; |
|
51 } |
|
52 |
|
53 class EventSender : public CppBoundClass { |
|
54 public: |
|
55 // Builds the property and method lists needed to bind this class to a JS |
|
56 // object. |
|
57 EventSender(TestShell*); |
|
58 |
|
59 // Resets some static variable state. |
|
60 void reset(); |
|
61 |
|
62 // Simulate drag&drop system call. |
|
63 void doDragDrop(const WebKit::WebDragData&, WebKit::WebDragOperationsMask); |
|
64 |
|
65 // JS callback methods. |
|
66 void mouseDown(const CppArgumentList&, CppVariant*); |
|
67 void mouseUp(const CppArgumentList&, CppVariant*); |
|
68 void mouseMoveTo(const CppArgumentList&, CppVariant*); |
|
69 void mouseWheelTo(const CppArgumentList&, CppVariant*); |
|
70 void leapForward(const CppArgumentList&, CppVariant*); |
|
71 void keyDown(const CppArgumentList&, CppVariant*); |
|
72 void dispatchMessage(const CppArgumentList&, CppVariant*); |
|
73 void textZoomIn(const CppArgumentList&, CppVariant*); |
|
74 void textZoomOut(const CppArgumentList&, CppVariant*); |
|
75 void zoomPageIn(const CppArgumentList&, CppVariant*); |
|
76 void zoomPageOut(const CppArgumentList&, CppVariant*); |
|
77 void scheduleAsynchronousClick(const CppArgumentList&, CppVariant*); |
|
78 void beginDragWithFiles(const CppArgumentList&, CppVariant*); |
|
79 CppVariant dragMode; |
|
80 |
|
81 void addTouchPoint(const CppArgumentList&, CppVariant*); |
|
82 void cancelTouchPoint(const CppArgumentList&, CppVariant*); |
|
83 void clearTouchPoints(const CppArgumentList&, CppVariant*); |
|
84 void releaseTouchPoint(const CppArgumentList&, CppVariant*); |
|
85 void setTouchModifier(const CppArgumentList&, CppVariant*); |
|
86 void touchCancel(const CppArgumentList&, CppVariant*); |
|
87 void touchEnd(const CppArgumentList&, CppVariant*); |
|
88 void touchMove(const CppArgumentList&, CppVariant*); |
|
89 void touchStart(const CppArgumentList&, CppVariant*); |
|
90 void updateTouchPoint(const CppArgumentList&, CppVariant*); |
|
91 |
|
92 // Unimplemented stubs |
|
93 void contextClick(const CppArgumentList&, CppVariant*); |
|
94 void enableDOMUIEventLogging(const CppArgumentList&, CppVariant*); |
|
95 void fireKeyboardEventsToElement(const CppArgumentList&, CppVariant*); |
|
96 void clearKillRing(const CppArgumentList&, CppVariant*); |
|
97 |
|
98 // Properties used in layout tests. |
|
99 #if defined(OS_WIN) |
|
100 CppVariant wmKeyDown; |
|
101 CppVariant wmKeyUp; |
|
102 CppVariant wmChar; |
|
103 CppVariant wmDeadChar; |
|
104 CppVariant wmSysKeyDown; |
|
105 CppVariant wmSysKeyUp; |
|
106 CppVariant wmSysChar; |
|
107 CppVariant wmSysDeadChar; |
|
108 #endif |
|
109 |
|
110 private: |
|
111 // Returns the test shell's webview. |
|
112 WebKit::WebView* webview(); |
|
113 |
|
114 // Returns true if dragMode is true. |
|
115 bool isDragMode() { return dragMode.isBool() && dragMode.toBoolean(); } |
|
116 |
|
117 // Sometimes we queue up mouse move and mouse up events for drag drop |
|
118 // handling purposes. These methods dispatch the event. |
|
119 void doMouseMove(const WebKit::WebMouseEvent&); |
|
120 void doMouseUp(const WebKit::WebMouseEvent&); |
|
121 static void doLeapForward(int milliseconds); |
|
122 void replaySavedEvents(); |
|
123 |
|
124 // Helper to return the button type given a button code |
|
125 static WebKit::WebMouseEvent::Button getButtonTypeFromButtonNumber(int); |
|
126 |
|
127 // Helper to extract the button number from the optional argument in |
|
128 // mouseDown and mouseUp |
|
129 static int getButtonNumberFromSingleArg(const CppArgumentList&); |
|
130 |
|
131 // Returns true if the specified key code passed in needs a shift key |
|
132 // modifier to be passed into the generated event. |
|
133 bool needsShiftModifier(int); |
|
134 |
|
135 void updateClickCountForButton(WebKit::WebMouseEvent::Button); |
|
136 |
|
137 // Compose a touch event from the current touch points and send it. |
|
138 void sendCurrentTouchEvent(const WebKit::WebInputEvent::Type); |
|
139 |
|
140 ScopedRunnableMethodFactory<EventSender> m_methodFactory; |
|
141 |
|
142 // Non-owning pointer. The EventSender is owned by the TestShell. |
|
143 TestShell* m_shell; |
|
144 |
|
145 // Location of last mouseMoveTo event. |
|
146 static WebKit::WebPoint lastMousePos; |
|
147 |
|
148 // Currently pressed mouse button (Left/Right/Middle or None) |
|
149 static WebKit::WebMouseEvent::Button pressedButton; |
|
150 |
|
151 // The last button number passed to mouseDown and mouseUp. |
|
152 // Used to determine whether the click count continues to |
|
153 // increment or not. |
|
154 static WebKit::WebMouseEvent::Button lastButtonType; |
|
155 }; |
|
156 |
|
157 #endif // EventSender_h |
|