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