2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 Bound to a JavaScript window.eventSender object using
34 CppBoundClass::bindToJavascript(), this allows layout tests to fire DOM events.
40 #include "CppBoundClass.h"
42 #include "WebDragOperation.h"
43 #include "WebInputEvent.h"
53 class EventSender : public CppBoundClass {
55 // Builds the property and method lists needed to bind this class to a JS
57 EventSender(TestShell*);
59 // Resets some static variable state.
62 // Simulate drag&drop system call.
63 void doDragDrop(const WebKit::WebDragData&, WebKit::WebDragOperationsMask);
65 // Test helper for dragging out images.
66 void dumpFilenameBeingDragged(const CppArgumentList&, CppVariant*);
68 // JS callback methods.
69 void mouseDown(const CppArgumentList&, CppVariant*);
70 void mouseUp(const CppArgumentList&, CppVariant*);
71 void mouseMoveTo(const CppArgumentList&, CppVariant*);
72 void leapForward(const CppArgumentList&, CppVariant*);
73 void keyDown(const CppArgumentList&, CppVariant*);
74 void dispatchMessage(const CppArgumentList&, CppVariant*);
75 void textZoomIn(const CppArgumentList&, CppVariant*);
76 void textZoomOut(const CppArgumentList&, CppVariant*);
77 void zoomPageIn(const CppArgumentList&, CppVariant*);
78 void zoomPageOut(const CppArgumentList&, CppVariant*);
79 void scalePageBy(const CppArgumentList&, CppVariant*);
80 void mouseScrollBy(const CppArgumentList&, CppVariant*);
81 void continuousMouseScrollBy(const CppArgumentList&, CppVariant*);
82 void scheduleAsynchronousClick(const CppArgumentList&, CppVariant*);
83 void beginDragWithFiles(const CppArgumentList&, CppVariant*);
86 void addTouchPoint(const CppArgumentList&, CppVariant*);
87 void cancelTouchPoint(const CppArgumentList&, CppVariant*);
88 void clearTouchPoints(const CppArgumentList&, CppVariant*);
89 void releaseTouchPoint(const CppArgumentList&, CppVariant*);
90 void setTouchModifier(const CppArgumentList&, CppVariant*);
91 void touchCancel(const CppArgumentList&, CppVariant*);
92 void touchEnd(const CppArgumentList&, CppVariant*);
93 void touchMove(const CppArgumentList&, CppVariant*);
94 void touchStart(const CppArgumentList&, CppVariant*);
95 void updateTouchPoint(const CppArgumentList&, CppVariant*);
97 // Unimplemented stubs
98 void contextClick(const CppArgumentList&, CppVariant*);
99 void enableDOMUIEventLogging(const CppArgumentList&, CppVariant*);
100 void fireKeyboardEventsToElement(const CppArgumentList&, CppVariant*);
101 void clearKillRing(const CppArgumentList&, CppVariant*);
103 // Properties used in layout tests.
105 CppVariant wmKeyDown;
108 CppVariant wmDeadChar;
109 CppVariant wmSysKeyDown;
110 CppVariant wmSysKeyUp;
111 CppVariant wmSysChar;
112 CppVariant wmSysDeadChar;
115 TaskList* taskList() { return &m_taskList; }
118 // Returns the test shell's webview.
119 WebKit::WebView* webview();
121 // Returns true if dragMode is true.
122 bool isDragMode() { return dragMode.isBool() && dragMode.toBoolean(); }
124 // Sometimes we queue up mouse move and mouse up events for drag drop
125 // handling purposes. These methods dispatch the event.
126 void doMouseMove(const WebKit::WebMouseEvent&);
127 void doMouseUp(const WebKit::WebMouseEvent&);
128 static void doLeapForward(int milliseconds);
129 void replaySavedEvents();
131 // Helper to return the button type given a button code
132 static WebKit::WebMouseEvent::Button getButtonTypeFromButtonNumber(int);
134 // Helper to extract the button number from the optional argument in
135 // mouseDown and mouseUp
136 static int getButtonNumberFromSingleArg(const CppArgumentList&);
138 // Returns true if the specified key code passed in needs a shift key
139 // modifier to be passed into the generated event.
140 bool needsShiftModifier(int);
142 void updateClickCountForButton(WebKit::WebMouseEvent::Button);
144 // Compose a touch event from the current touch points and send it.
145 void sendCurrentTouchEvent(const WebKit::WebInputEvent::Type);
147 // Handle a request to send a wheel event.
148 void handleMouseWheel(const CppArgumentList&, CppVariant*, bool continuous);
152 // Non-owning pointer. The EventSender is owned by the TestShell.
155 // Location of last mouseMoveTo event.
156 static WebKit::WebPoint lastMousePos;
158 // Currently pressed mouse button (Left/Right/Middle or None)
159 static WebKit::WebMouseEvent::Button pressedButton;
161 // The last button number passed to mouseDown and mouseUp.
162 // Used to determine whether the click count continues to
164 static WebKit::WebMouseEvent::Button lastButtonType;
167 #endif // EventSender_h