2
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3
* Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
30
#include "EventSenderQt.h"
32
#include <QGestureEvent>
33
#include <QGraphicsSceneMouseEvent>
34
#include <QtTest/QtTest>
36
#include <qpa/qwindowsysteminterface.h>
39
#define KEYCODE_DEL 127
40
#define KEYCODE_BACKSPACE 8
41
#define KEYCODE_LEFTARROW 0xf702
42
#define KEYCODE_RIGHTARROW 0xf703
43
#define KEYCODE_UPARROW 0xf700
44
#define KEYCODE_DOWNARROW 0xf701
46
// Ports like Gtk and Windows expose a different approach for their zooming
47
// API if compared to Qt: they have specific methods for zooming in and out,
48
// as well as a settable zoom factor, while Qt has only a 'setZoomValue' method.
49
// Hence Qt DRT adopts a fixed zoom-factor (1.2) for compatibility.
52
#define DRT_MESSAGE_DONE (QEvent::User + 1)
54
struct DRTEventQueue {
59
static DRTEventQueue eventQueue[1024];
60
static unsigned endOfQueue;
61
static unsigned startOfQueue;
63
EventSender::EventSender(QWebPage* parent)
65
#ifndef QT_NO_GESTURES
66
, m_tapGesture(parent)
67
, m_tapAndHoldGesture(parent)
71
m_mouseButtonPressed = false;
73
memset(eventQueue, 0, sizeof(eventQueue));
78
m_currentDragActionsAllowed = 0;
80
m_page->view()->installEventFilter(this);
81
// This is a hack that works because we normally scroll 60 pixels (3*20) per tick, but Apple scrolls 120.
82
// But Apple also has a bug where they report lines instead of ticks in PlatformWheelEvent, making 2 lines = 40 pixels match.
83
QApplication::setWheelScrollLines(2);
86
static Qt::KeyboardModifiers getModifiers(const QStringList& modifiers)
88
Qt::KeyboardModifiers modifs = 0;
89
for (int i = 0; i < modifiers.size(); ++i) {
90
const QString& m = modifiers.at(i);
92
modifs |= Qt::ControlModifier;
93
else if (m == "shiftKey")
94
modifs |= Qt::ShiftModifier;
95
else if (m == "altKey")
96
modifs |= Qt::AltModifier;
97
else if (m == "metaKey")
98
modifs |= Qt::MetaModifier;
103
void EventSender::mouseDown(int button, const QStringList& modifiers)
105
Qt::KeyboardModifiers modifs = getModifiers(modifiers);
106
Qt::MouseButton mouseButton;
109
mouseButton = Qt::LeftButton;
112
mouseButton = Qt::MidButton;
115
mouseButton = Qt::RightButton;
118
// fast/events/mouse-click-events expects the 4th button to be treated as the middle button
119
mouseButton = Qt::MidButton;
122
mouseButton = Qt::LeftButton;
126
// only consider a click to count, an event originated by the
127
// same previous button and at the same position.
128
if (m_currentButton == button
129
&& m_mousePos == m_clickPos
130
&& m_clickTimer.isActive())
135
m_currentButton = button;
136
m_clickPos = m_mousePos;
137
m_mouseButtons |= mouseButton;
139
// qDebug() << "EventSender::mouseDown" << frame;
141
if (isGraphicsBased()) {
142
event = createGraphicsSceneMouseEvent((m_clickCount == 2) ?
143
QEvent::GraphicsSceneMouseDoubleClick : QEvent::GraphicsSceneMousePress,
144
m_mousePos, m_mousePos, mouseButton, m_mouseButtons, modifs);
146
event = new QMouseEvent((m_clickCount == 2) ? QEvent::MouseButtonDblClick :
147
QEvent::MouseButtonPress, m_mousePos, m_mousePos,
148
mouseButton, m_mouseButtons, modifs);
151
sendOrQueueEvent(event);
153
m_clickTimer.start(QApplication::doubleClickInterval(), this);
156
void EventSender::mouseUp(int button)
158
Qt::MouseButton mouseButton;
161
mouseButton = Qt::LeftButton;
164
mouseButton = Qt::MidButton;
167
mouseButton = Qt::RightButton;
170
// fast/events/mouse-click-events expects the 4th button to be treated as the middle button
171
mouseButton = Qt::MidButton;
174
mouseButton = Qt::LeftButton;
178
m_mouseButtons &= ~mouseButton;
180
// qDebug() << "EventSender::mouseUp" << frame;
182
if (isGraphicsBased()) {
183
event = createGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseRelease,
184
m_mousePos, m_mousePos, mouseButton, m_mouseButtons, Qt::NoModifier);
186
event = new QMouseEvent(QEvent::MouseButtonRelease,
187
m_mousePos, m_mousePos, mouseButton, m_mouseButtons, Qt::NoModifier);
190
sendOrQueueEvent(event);
192
if (m_currentDragData.urls().isEmpty())
195
event = new QDropEvent(m_mousePos, m_currentDragActionsAllowed, &m_currentDragData, m_mouseButtons, Qt::NoModifier);
196
sendEvent(m_page, event);
197
m_currentDragData.clear();
200
void EventSender::mouseMoveTo(int x, int y)
202
// qDebug() << "EventSender::mouseMoveTo" << x << y;
203
m_mousePos = QPoint(x, y);
206
if (isGraphicsBased()) {
207
event = createGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove,
208
m_mousePos, m_mousePos, Qt::NoButton, m_mouseButtons, Qt::NoModifier);
210
event = new QMouseEvent(QEvent::MouseMove,
211
m_mousePos, m_mousePos, Qt::NoButton, m_mouseButtons, Qt::NoModifier);
214
sendOrQueueEvent(event);
216
if (m_currentDragData.urls().isEmpty())
219
Qt::MouseButtons mouseButtons = m_mouseButtons | Qt::LeftButton;
220
event = new QDragMoveEvent(m_mousePos, m_currentDragActionsAllowed, &m_currentDragData, mouseButtons, Qt::NoModifier);
221
sendEvent(m_page, event);
224
// Simulates a mouse down event for drag without sending an actual mouse down event.
225
void EventSender::beginDragWithFiles(const QStringList& files)
227
m_currentDragData.clear();
228
QList<QUrl> fileUrls;
229
QUrl baseUrl = m_page->mainFrame()->baseUrl();
230
foreach (const QString& file, files) {
231
QUrl resolvedUrl = baseUrl.resolved(file);
232
fileUrls.append(resolvedUrl);
235
m_currentDragData.setUrls(fileUrls);
236
m_currentDragActionsAllowed = Qt::CopyAction;
237
Qt::MouseButtons mouseButtons = m_mouseButtons | Qt::LeftButton;
238
QDragEnterEvent* event = new QDragEnterEvent(m_mousePos, m_currentDragActionsAllowed, &m_currentDragData, mouseButtons, Qt::NoModifier);
239
sendEvent(m_page, event);
242
#ifndef QT_NO_WHEELEVENT
243
void EventSender::mouseScrollBy(int ticksX, int ticksY)
245
const int tickStep = QApplication::wheelScrollLines() * 20;
246
continuousMouseScrollBy((ticksX * tickStep), (ticksY * tickStep));
249
void EventSender::continuousMouseScrollBy(int x, int y)
251
// continuousMouseScrollBy() mimics devices that send fine-grained scroll events where the 'delta' specified is not the usual
252
// multiple of 120. See http://doc.qt.nokia.com/4.6/qwheelevent.html#delta for a good explanation of this.
254
// A wheel delta of 120 (in 1/8 degrees) corresponds to one wheel tick, and we scroll tickStep pixels per wheel tick.
255
const int tickStep = QApplication::wheelScrollLines() * 20;
258
if (isGraphicsBased()) {
259
event = createGraphicsSceneWheelEvent(QEvent::GraphicsSceneWheel,
260
m_mousePos, m_mousePos, (x * 120) / tickStep, Qt::NoModifier, Qt::Horizontal);
262
event = new QWheelEvent(m_mousePos, m_mousePos, (x * 120) / tickStep, m_mouseButtons, Qt::NoModifier, Qt::Horizontal);
264
sendOrQueueEvent(event);
268
if (isGraphicsBased()) {
269
event = createGraphicsSceneWheelEvent(QEvent::GraphicsSceneWheel,
270
m_mousePos, m_mousePos, (y * 120) / tickStep, Qt::NoModifier, Qt::Vertical);
272
event = new QWheelEvent(m_mousePos, m_mousePos, (y * 120) / tickStep, m_mouseButtons, Qt::NoModifier, Qt::Vertical);
274
sendOrQueueEvent(event);
279
void EventSender::leapForward(int ms)
281
eventQueue[endOfQueue].m_delay = ms;
282
//qDebug() << "EventSender::leapForward" << ms;
285
void EventSender::keyDown(const QString& string, const QStringList& modifiers, unsigned int location)
288
Qt::KeyboardModifiers modifs = getModifiers(modifiers);
290
modifs |= Qt::KeypadModifier;
292
if (string.length() == 1) {
293
code = string.unicode()->unicode();
294
//qDebug() << ">>>>>>>>> keyDown" << code << (char)code;
295
// map special keycodes used by the tests to something that works for Qt/X11
297
code = Qt::Key_Return;
298
} else if (code == '\t') {
300
if (modifs == Qt::ShiftModifier)
301
code = Qt::Key_Backtab;
303
} else if (code == KEYCODE_DEL || code == KEYCODE_BACKSPACE) {
304
code = Qt::Key_Backspace;
305
if (modifs == Qt::AltModifier)
306
modifs = Qt::ControlModifier;
308
} else if (code == 'o' && modifs == Qt::ControlModifier) {
309
// Mimic the emacs ctrl-o binding on Mac by inserting a paragraph
310
// separator and then putting the cursor back to its original
311
// position. Allows us to pass emacs-ctrl-o.html
312
s = QLatin1String("\n");
315
QKeyEvent event(QEvent::KeyPress, code, modifs, s);
316
sendEvent(m_page, &event);
317
QKeyEvent event2(QEvent::KeyRelease, code, modifs, s);
318
sendEvent(m_page, &event2);
321
} else if (code == 'y' && modifs == Qt::ControlModifier) {
322
s = QLatin1String("c");
324
} else if (code == 'k' && modifs == Qt::ControlModifier) {
325
s = QLatin1String("x");
327
} else if (code == 'a' && modifs == Qt::ControlModifier) {
331
} else if (code == KEYCODE_LEFTARROW) {
334
if (modifs & Qt::MetaModifier) {
336
modifs &= ~Qt::MetaModifier;
338
} else if (code == KEYCODE_RIGHTARROW) {
340
code = Qt::Key_Right;
341
if (modifs & Qt::MetaModifier) {
343
modifs &= ~Qt::MetaModifier;
345
} else if (code == KEYCODE_UPARROW) {
348
if (modifs & Qt::MetaModifier) {
349
code = Qt::Key_PageUp;
350
modifs &= ~Qt::MetaModifier;
352
} else if (code == KEYCODE_DOWNARROW) {
355
if (modifs & Qt::MetaModifier) {
356
code = Qt::Key_PageDown;
357
modifs &= ~Qt::MetaModifier;
359
} else if (code == 'a' && modifs == Qt::ControlModifier) {
364
code = string.unicode()->toUpper().unicode();
366
//qDebug() << ">>>>>>>>> keyDown" << string;
368
if (string.startsWith(QLatin1Char('F')) && string.count() <= 3) {
370
int functionKey = s.toInt();
371
Q_ASSERT(functionKey >= 1 && functionKey <= 35);
372
code = Qt::Key_F1 + (functionKey - 1);
373
// map special keycode strings used by the tests to something that works for Qt/X11
374
} else if (string == QLatin1String("leftArrow")) {
377
} else if (string == QLatin1String("rightArrow")) {
379
code = Qt::Key_Right;
380
} else if (string == QLatin1String("upArrow")) {
383
} else if (string == QLatin1String("downArrow")) {
386
} else if (string == QLatin1String("pageUp")) {
388
code = Qt::Key_PageUp;
389
} else if (string == QLatin1String("pageDown")) {
391
code = Qt::Key_PageDown;
392
} else if (string == QLatin1String("home")) {
395
} else if (string == QLatin1String("end")) {
398
} else if (string == QLatin1String("insert")) {
400
code = Qt::Key_Insert;
401
} else if (string == QLatin1String("delete")) {
403
code = Qt::Key_Delete;
404
} else if (string == QLatin1String("printScreen")) {
406
code = Qt::Key_Print;
407
} else if (string == QLatin1String("menu")) {
412
QKeyEvent event(QEvent::KeyPress, code, modifs, s);
413
sendEvent(m_page, &event);
414
QKeyEvent event2(QEvent::KeyRelease, code, modifs, s);
415
sendEvent(m_page, &event2);
418
QStringList EventSender::contextClick()
420
QMouseEvent event(QEvent::MouseButtonPress, m_mousePos, Qt::RightButton, Qt::RightButton, Qt::NoModifier);
421
sendEvent(m_page, &event);
422
QMouseEvent event2(QEvent::MouseButtonRelease, m_mousePos, Qt::RightButton, Qt::RightButton, Qt::NoModifier);
423
sendEvent(m_page, &event2);
425
if (isGraphicsBased()) {
426
QGraphicsSceneContextMenuEvent ctxEvent(QEvent::GraphicsSceneContextMenu);
427
ctxEvent.setReason(QGraphicsSceneContextMenuEvent::Mouse);
428
ctxEvent.setPos(m_mousePos);
429
WebCore::WebViewGraphicsBased* view = qobject_cast<WebCore::WebViewGraphicsBased*>(m_page->view());
431
sendEvent(view->graphicsView(), &ctxEvent);
433
QContextMenuEvent ctxEvent(QContextMenuEvent::Mouse, m_mousePos);
434
sendEvent(m_page->view(), &ctxEvent);
436
return DumpRenderTreeSupportQt::contextMenu(m_page);
439
void EventSender::scheduleAsynchronousClick()
441
QMouseEvent* event = new QMouseEvent(QEvent::MouseButtonPress, m_mousePos, Qt::LeftButton, Qt::RightButton, Qt::NoModifier);
442
postEvent(m_page, event);
443
QMouseEvent* event2 = new QMouseEvent(QEvent::MouseButtonRelease, m_mousePos, Qt::LeftButton, Qt::RightButton, Qt::NoModifier);
444
postEvent(m_page, event2);
447
void EventSender::addTouchPoint(int x, int y)
449
const int id = m_touchPoints.isEmpty() ? 0 : m_touchPoints.last().id() + 1;
450
const QPointF pos(x, y);
451
QTouchEvent::TouchPoint point(id);
453
point.setStartPos(pos);
454
point.setState(Qt::TouchPointPressed);
455
if (!m_touchPointRadius.isNull())
456
point.setRect(QRectF(pos - m_touchPointRadius, pos + m_touchPointRadius));
457
m_touchPoints.append(point);
460
void EventSender::updateTouchPoint(int index, int x, int y)
462
if (index < 0 || index >= m_touchPoints.count())
465
const QPointF pos(x, y);
466
QTouchEvent::TouchPoint &point = m_touchPoints[index];
468
point.setState(Qt::TouchPointMoved);
469
if (!m_touchPointRadius.isNull())
470
point.setRect(QRectF(pos - m_touchPointRadius, pos + m_touchPointRadius));
473
void EventSender::setTouchModifier(const QString &modifier, bool enable)
475
Qt::KeyboardModifier mod = Qt::NoModifier;
476
if (!modifier.compare(QLatin1String("shift"), Qt::CaseInsensitive))
477
mod = Qt::ShiftModifier;
478
else if (!modifier.compare(QLatin1String("alt"), Qt::CaseInsensitive))
479
mod = Qt::AltModifier;
480
else if (!modifier.compare(QLatin1String("meta"), Qt::CaseInsensitive))
481
mod = Qt::MetaModifier;
482
else if (!modifier.compare(QLatin1String("ctrl"), Qt::CaseInsensitive))
483
mod = Qt::ControlModifier;
486
m_touchModifiers |= mod;
488
m_touchModifiers &= ~mod;
491
void EventSender::setTouchPointRadius(int radiusX, int radiusY)
493
m_touchPointRadius = QPoint(radiusX, radiusY);
496
void EventSender::touchStart()
498
if (!m_touchActive) {
499
sendTouchEvent(QEvent::TouchBegin);
500
m_touchActive = true;
502
sendTouchEvent(QEvent::TouchUpdate);
505
void EventSender::touchMove()
507
sendTouchEvent(QEvent::TouchUpdate);
510
void EventSender::touchEnd()
512
for (int i = 0; i < m_touchPoints.count(); ++i)
513
if (m_touchPoints[i].state() != Qt::TouchPointReleased) {
514
sendTouchEvent(QEvent::TouchUpdate);
517
sendTouchEvent(QEvent::TouchEnd);
518
m_touchActive = false;
521
#if QT_VERSION >= 0x050000
522
void EventSender::touchCancel()
524
sendTouchEvent(QEvent::TouchCancel);
525
m_touchActive = false;
529
void EventSender::clearTouchPoints()
531
m_touchPoints.clear();
532
m_touchModifiers = Qt::KeyboardModifiers();
533
m_touchActive = false;
534
m_touchPointRadius = QPoint();
537
void EventSender::releaseTouchPoint(int index)
539
if (index < 0 || index >= m_touchPoints.count())
542
m_touchPoints[index].setState(Qt::TouchPointReleased);
545
void EventSender::cancelTouchPoint(int index)
547
// FIXME: No cancellation state in Qt 5, mapped to release instead.
548
// PlatformTouchEvent conversion later will map all touch points to
550
releaseTouchPoint(index);
553
void EventSender::sendTouchEvent(QEvent::Type type)
556
static QTouchDevice* device = 0;
558
device = new QTouchDevice;
559
device->setType(QTouchDevice::TouchScreen);
560
QWindowSystemInterface::registerTouchDevice(device);
563
QTouchEvent event(type, device, m_touchModifiers);
565
QTouchEvent event(type, QTouchEvent::TouchScreen, m_touchModifiers);
567
event.setTouchPoints(m_touchPoints);
568
sendEvent(m_page, &event);
569
QList<QTouchEvent::TouchPoint>::Iterator it = m_touchPoints.begin();
570
while (it != m_touchPoints.end()) {
571
if (it->state() == Qt::TouchPointReleased)
572
it = m_touchPoints.erase(it);
574
it->setState(Qt::TouchPointStationary);
580
#ifndef QT_NO_GESTURES
581
void EventSender::gestureTap(int x, int y)
583
m_tapGesture.setPosition(QPointF(x, y));
585
m_gestures.append(&m_tapGesture);
586
QGestureEvent event(m_gestures);
588
event.setWidget(m_page->view());
590
sendEvent(m_page, &event);
593
void EventSender::gestureLongPress(int x, int y)
595
m_tapAndHoldGesture.setPosition(QPointF(x, y));
597
m_gestures.append(&m_tapAndHoldGesture);
598
QGestureEvent event(m_gestures);
600
event.setWidget(m_page->view());
602
sendEvent(m_page, &event);
606
void EventSender::zoomPageIn()
608
if (QWebFrame* frame = m_page->mainFrame())
609
frame->setZoomFactor(frame->zoomFactor() * ZOOM_STEP);
612
void EventSender::zoomPageOut()
614
if (QWebFrame* frame = m_page->mainFrame())
615
frame->setZoomFactor(frame->zoomFactor() / ZOOM_STEP);
618
void EventSender::textZoomIn()
620
if (QWebFrame* frame = m_page->mainFrame())
621
frame->setTextSizeMultiplier(frame->textSizeMultiplier() * ZOOM_STEP);
624
void EventSender::textZoomOut()
626
if (QWebFrame* frame = m_page->mainFrame())
627
frame->setTextSizeMultiplier(frame->textSizeMultiplier() / ZOOM_STEP);
630
void EventSender::scalePageBy(float scaleFactor, float x, float y)
632
if (QWebFrame* frame = m_page->mainFrame())
633
DumpRenderTreeSupportQt::scalePageBy(frame, scaleFactor, QPoint(x, y));
636
QWebFrame* EventSender::frameUnderMouse() const
638
QWebFrame* frame = m_page->mainFrame();
641
QList<QWebFrame*> children = frame->childFrames();
642
for (int i = 0; i < children.size(); ++i) {
643
if (children.at(i)->geometry().contains(m_mousePos)) {
644
frame = children.at(i);
648
if (frame->geometry().contains(m_mousePos))
653
void EventSender::sendOrQueueEvent(QEvent* event)
655
// Mouse move events are queued if
656
// 1. A previous event was queued.
657
// 2. A delay was set-up by leapForward().
658
// 3. A call to mouseMoveTo while the mouse button is pressed could initiate a drag operation, and that does not return until mouseUp is processed.
659
// To be safe and avoid a deadlock, this event is queued.
660
if (endOfQueue == startOfQueue && !eventQueue[endOfQueue].m_delay && (!(m_mouseButtonPressed && (m_eventLoop && event->type() == QEvent::MouseButtonRelease)))) {
661
sendEvent(m_page->view(), event);
665
eventQueue[endOfQueue++].m_event = event;
666
eventQueue[endOfQueue].m_delay = 0;
667
replaySavedEvents(event->type() != QEvent::MouseMove);
670
void EventSender::replaySavedEvents(bool flush)
672
if (startOfQueue < endOfQueue) {
673
// First send all the events that are ready to be sent
674
while (!eventQueue[startOfQueue].m_delay && startOfQueue < endOfQueue) {
675
QEvent* ev = eventQueue[startOfQueue++].m_event;
676
postEvent(m_page->view(), ev);
678
if (startOfQueue == endOfQueue) {
683
QTest::qWait(eventQueue[startOfQueue].m_delay);
684
eventQueue[startOfQueue].m_delay = 0;
690
// Send a marker event, it will tell us when it is safe to exit the new event loop
691
QEvent* drtEvent = new QEvent((QEvent::Type)DRT_MESSAGE_DONE);
692
QApplication::postEvent(m_page->view(), drtEvent);
694
// Start an event loop for async handling of Drag & Drop
695
m_eventLoop = new QEventLoop;
701
bool EventSender::eventFilter(QObject* watched, QEvent* event)
703
if (watched != m_page->view())
705
switch (event->type()) {
708
case QEvent::MouseButtonPress:
709
case QEvent::GraphicsSceneMousePress:
710
m_mouseButtonPressed = true;
712
case QEvent::MouseMove:
713
case QEvent::GraphicsSceneMouseMove:
714
if (m_mouseButtonPressed)
717
case QEvent::MouseButtonRelease:
718
case QEvent::GraphicsSceneMouseRelease:
719
m_mouseButtonPressed = false;
722
case DRT_MESSAGE_DONE:
729
void EventSender::timerEvent(QTimerEvent* ev)
734
QGraphicsSceneMouseEvent* EventSender::createGraphicsSceneMouseEvent(QEvent::Type type, const QPoint& pos, const QPoint& screenPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
736
QGraphicsSceneMouseEvent* event;
737
event = new QGraphicsSceneMouseEvent(type);
739
event->setScreenPos(screenPos);
740
event->setButton(button);
741
event->setButtons(buttons);
742
event->setModifiers(modifiers);
747
QGraphicsSceneWheelEvent* EventSender::createGraphicsSceneWheelEvent(QEvent::Type type, const QPoint& pos, const QPoint& screenPos, int delta, Qt::KeyboardModifiers modifiers, Qt::Orientation orientation)
749
QGraphicsSceneWheelEvent* event;
750
event = new QGraphicsSceneWheelEvent(type);
752
event->setScreenPos(screenPos);
753
event->setDelta(delta);
754
event->setModifiers(modifiers);
755
event->setOrientation(orientation);
760
void EventSender::sendEvent(QObject* receiver, QEvent* event)
762
if (WebCore::WebViewGraphicsBased* view = qobject_cast<WebCore::WebViewGraphicsBased*>(receiver))
763
view->scene()->sendEvent(view->graphicsView(), event);
765
QApplication::sendEvent(receiver, event);
768
void EventSender::postEvent(QObject* receiver, QEvent* event)
770
// QGraphicsScene does not have a postEvent method, so send the event in this case
771
// and delete it after that.
772
if (WebCore::WebViewGraphicsBased* view = qobject_cast<WebCore::WebViewGraphicsBased*>(receiver)) {
773
view->scene()->sendEvent(view->graphicsView(), event);
776
QApplication::postEvent(receiver, event); // event deleted by the system