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 // JS callback methods.
66 void mouseDown(const CppArgumentList&, CppVariant*);
67 void mouseUp(const CppArgumentList&, CppVariant*);
68 void mouseMoveTo(const CppArgumentList&, CppVariant*);
69 void leapForward(const CppArgumentList&, CppVariant*);
70 void keyDown(const CppArgumentList&, CppVariant*);
71 void dispatchMessage(const CppArgumentList&, CppVariant*);
72 void textZoomIn(const CppArgumentList&, CppVariant*);
73 void textZoomOut(const CppArgumentList&, CppVariant*);
74 void zoomPageIn(const CppArgumentList&, CppVariant*);
75 void zoomPageOut(const CppArgumentList&, CppVariant*);
76 void mouseScrollBy(const CppArgumentList&, CppVariant*);
77 void continuousMouseScrollBy(const CppArgumentList&, CppVariant*);
78 void scheduleAsynchronousClick(const CppArgumentList&, CppVariant*);
79 void beginDragWithFiles(const CppArgumentList&, CppVariant*);
82 void addTouchPoint(const CppArgumentList&, CppVariant*);
83 void cancelTouchPoint(const CppArgumentList&, CppVariant*);
84 void clearTouchPoints(const CppArgumentList&, CppVariant*);
85 void releaseTouchPoint(const CppArgumentList&, CppVariant*);
86 void setTouchModifier(const CppArgumentList&, CppVariant*);
87 void touchCancel(const CppArgumentList&, CppVariant*);
88 void touchEnd(const CppArgumentList&, CppVariant*);
89 void touchMove(const CppArgumentList&, CppVariant*);
90 void touchStart(const CppArgumentList&, CppVariant*);
91 void updateTouchPoint(const CppArgumentList&, CppVariant*);
93 // Unimplemented stubs
94 void contextClick(const CppArgumentList&, CppVariant*);
95 void enableDOMUIEventLogging(const CppArgumentList&, CppVariant*);
96 void fireKeyboardEventsToElement(const CppArgumentList&, CppVariant*);
97 void clearKillRing(const CppArgumentList&, CppVariant*);
99 // Properties used in layout tests.
101 CppVariant wmKeyDown;
104 CppVariant wmDeadChar;
105 CppVariant wmSysKeyDown;
106 CppVariant wmSysKeyUp;
107 CppVariant wmSysChar;
108 CppVariant wmSysDeadChar;
111 TaskList* taskList() { return &m_taskList; }
114 // Returns the test shell's webview.
115 WebKit::WebView* webview();
117 // Returns true if dragMode is true.
118 bool isDragMode() { return dragMode.isBool() && dragMode.toBoolean(); }
120 // Sometimes we queue up mouse move and mouse up events for drag drop
121 // handling purposes. These methods dispatch the event.
122 void doMouseMove(const WebKit::WebMouseEvent&);
123 void doMouseUp(const WebKit::WebMouseEvent&);
124 static void doLeapForward(int milliseconds);
125 void replaySavedEvents();
127 // Helper to return the button type given a button code
128 static WebKit::WebMouseEvent::Button getButtonTypeFromButtonNumber(int);
130 // Helper to extract the button number from the optional argument in
131 // mouseDown and mouseUp
132 static int getButtonNumberFromSingleArg(const CppArgumentList&);
134 // Returns true if the specified key code passed in needs a shift key
135 // modifier to be passed into the generated event.
136 bool needsShiftModifier(int);
138 void updateClickCountForButton(WebKit::WebMouseEvent::Button);
140 // Compose a touch event from the current touch points and send it.
141 void sendCurrentTouchEvent(const WebKit::WebInputEvent::Type);
143 // Handle a request to send a wheel event.
144 void handleMouseWheel(const CppArgumentList&, CppVariant*, bool continuous);
148 // Non-owning pointer. The EventSender is owned by the TestShell.
151 // Location of last mouseMoveTo event.
152 static WebKit::WebPoint lastMousePos;
154 // Currently pressed mouse button (Left/Right/Middle or None)
155 static WebKit::WebMouseEvent::Button pressedButton;
157 // The last button number passed to mouseDown and mouseUp.
158 // Used to determine whether the click count continues to
160 static WebKit::WebMouseEvent::Button lastButtonType;
163 #endif // EventSender_h