1 /* |
|
2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
|
3 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
15 * its contributors may be used to endorse or promote products derived |
|
16 * from this software without specific prior written permission. |
|
17 * |
|
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 */ |
|
29 #ifndef EventSenderQt_h |
|
30 #define EventSenderQt_h |
|
31 |
|
32 |
|
33 #include "DumpRenderTreeQt.h" |
|
34 |
|
35 #include <QApplication> |
|
36 #include <QBasicTimer> |
|
37 #include <QEvent> |
|
38 #include <QEventLoop> |
|
39 #include <QMouseEvent> |
|
40 #include <QObject> |
|
41 #include <QPoint> |
|
42 #include <QString> |
|
43 #include <QStringList> |
|
44 |
|
45 #include <qwebpage.h> |
|
46 #include <qwebframe.h> |
|
47 |
|
48 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) |
|
49 #include <QTouchEvent> |
|
50 #endif |
|
51 |
|
52 class EventSender : public QObject { |
|
53 Q_OBJECT |
|
54 public: |
|
55 EventSender(QWebPage* parent); |
|
56 virtual bool eventFilter(QObject* watched, QEvent* event); |
|
57 void resetClickCount() { m_clickCount = 0; } |
|
58 |
|
59 public slots: |
|
60 void mouseDown(int button = 0); |
|
61 void mouseUp(int button = 0); |
|
62 void mouseMoveTo(int x, int y); |
|
63 #ifndef QT_NO_WHEELEVENT |
|
64 void mouseScrollBy(int x, int y); |
|
65 void continuousMouseScrollBy(int x, int y); |
|
66 #endif |
|
67 void leapForward(int ms); |
|
68 void keyDown(const QString& string, const QStringList& modifiers = QStringList(), unsigned int location = 0); |
|
69 void clearKillRing() {} |
|
70 void contextClick(); |
|
71 void scheduleAsynchronousClick(); |
|
72 void addTouchPoint(int x, int y); |
|
73 void updateTouchPoint(int index, int x, int y); |
|
74 void setTouchModifier(const QString &modifier, bool enable); |
|
75 void touchStart(); |
|
76 void touchMove(); |
|
77 void touchEnd(); |
|
78 void zoomPageIn(); |
|
79 void zoomPageOut(); |
|
80 void textZoomIn(); |
|
81 void textZoomOut(); |
|
82 void clearTouchPoints(); |
|
83 void releaseTouchPoint(int index); |
|
84 |
|
85 protected: |
|
86 void timerEvent(QTimerEvent*); |
|
87 |
|
88 private: |
|
89 bool isGraphicsBased() const { return qobject_cast<WebCore::WebViewGraphicsBased*>(m_page->view()); } |
|
90 QGraphicsSceneMouseEvent* createGraphicsSceneMouseEvent(QEvent::Type, const QPoint& pos, const QPoint& screenPos, Qt::MouseButton, Qt::MouseButtons, Qt::KeyboardModifiers); |
|
91 QGraphicsSceneWheelEvent* createGraphicsSceneWheelEvent(QEvent::Type, const QPoint& pos, const QPoint& screenPos, int delta, Qt::KeyboardModifiers, Qt::Orientation); |
|
92 void sendEvent(QObject* receiver, QEvent* event); |
|
93 void postEvent(QObject* receiver, QEvent* event); |
|
94 |
|
95 private: |
|
96 void sendTouchEvent(QEvent::Type); |
|
97 void sendOrQueueEvent(QEvent*); |
|
98 void replaySavedEvents(bool flush); |
|
99 QPoint m_mousePos; |
|
100 QPoint m_clickPos; |
|
101 Qt::MouseButtons m_mouseButtons; |
|
102 QWebPage* m_page; |
|
103 int m_clickCount; |
|
104 int m_currentButton; |
|
105 bool m_mouseButtonPressed; |
|
106 bool m_drag; |
|
107 QEventLoop* m_eventLoop; |
|
108 QWebFrame* frameUnderMouse() const; |
|
109 QBasicTimer m_clickTimer; |
|
110 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) |
|
111 QList<QTouchEvent::TouchPoint> m_touchPoints; |
|
112 Qt::KeyboardModifiers m_touchModifiers; |
|
113 bool m_touchActive; |
|
114 #endif |
|
115 }; |
|
116 #endif // EventSenderQt_h |
|