OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2010 University of Szeged. All rights reserved. | |
4 * Copyright (C) 2013 Digia Plc. and/or its subsidiary(-ies). | |
5 * | |
6 * Redistribution and use in source and binary forms, with or without | |
7 * modification, are permitted provided that the following conditions | |
8 * are met: | |
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 * | |
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 #include "config.h" | |
29 | |
30 #include "PlatformWebView.h" | |
31 #include "qquickwebpage_p.h" | |
32 #include "qquickwebview_p.h" | |
33 | |
34 #include <WebKit2/WKRetainPtr.h> | |
35 | |
36 #include <QCoreApplication> | |
37 #include <QEventLoop> | |
38 #include <QQmlProperty> | |
39 #include <QtQuick/QQuickView> | |
40 #include <qpa/qwindowsysteminterface.h> | |
41 | |
42 namespace TestWebKitAPI { | |
43 | |
44 class WrapperWindow : public QQuickView { | |
45 Q_OBJECT | |
46 public: | |
47 WrapperWindow(QQuickWebView* view) | |
48 : QQuickView(QUrl(QStringLiteral("data:text/plain,import QtQuick 2.0\nIt
em { objectName: 'root' }"))) | |
49 , m_view(view) | |
50 { | |
51 connect(this, SIGNAL(statusChanged(QQuickView::Status)), SLOT(handleStat
usChanged(QQuickView::Status))); | |
52 } | |
53 | |
54 private Q_SLOTS: | |
55 void handleStatusChanged(QQuickView::Status status) | |
56 { | |
57 if (status != QQuickView::Ready) | |
58 return; | |
59 | |
60 setGeometry(0, 0, 800, 600); | |
61 | |
62 setResizeMode(QQuickView::SizeRootObjectToView); | |
63 m_view->setParentItem(rootObject()); | |
64 QQmlProperty::write(m_view, QStringLiteral("anchors.fill"), qVariantFrom
Value(rootObject())); | |
65 | |
66 m_view->experimental()->setRenderToOffscreenBuffer(true); | |
67 | |
68 QWindowSystemInterface::handleWindowActivated(this); | |
69 m_view->page()->setFocus(true); | |
70 } | |
71 | |
72 private: | |
73 QQuickWebView* m_view; | |
74 }; | |
75 | |
76 PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGro
upRef) | |
77 { | |
78 m_view = new QQuickWebView(contextRef, pageGroupRef); | |
79 m_view->setAllowAnyHTTPSCertificateForLocalHost(true); | |
80 m_view->componentComplete(); | |
81 | |
82 m_window = new WrapperWindow(m_view); | |
83 } | |
84 | |
85 PlatformWebView::~PlatformWebView() | |
86 { | |
87 delete m_window; | |
88 } | |
89 | |
90 void PlatformWebView::resizeTo(unsigned width, unsigned height) | |
91 { | |
92 // If we do not have a platform window we will never get the necessary | |
93 // resize event, so simulate it in that case to make sure the quickview is | |
94 // resized to what the api tests expects. | |
95 if (!m_window->handle()) { | |
96 QRect newGeometry(m_window->x(), m_window->y(), width, height); | |
97 QWindowSystemInterface::handleGeometryChange(m_window, newGeometry); | |
98 QWindowSystemInterface::flushWindowSystemEvents(); | |
99 } | |
100 | |
101 m_window->resize(width, height); | |
102 } | |
103 | |
104 WKPageRef PlatformWebView::page() const | |
105 { | |
106 return m_view->pageRef(); | |
107 } | |
108 | |
109 void PlatformWebView::focus() | |
110 { | |
111 m_view->setFocus(true); | |
112 } | |
113 | |
114 void PlatformWebView::simulateSpacebarKeyPress() | |
115 { | |
116 QKeyEvent event(QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier); | |
117 QCoreApplication::sendEvent(m_window, &event); | |
118 QKeyEvent event2(QEvent::KeyRelease, Qt::Key_Space, Qt::NoModifier); | |
119 QCoreApplication::sendEvent(m_window, &event2); | |
120 } | |
121 | |
122 void PlatformWebView::simulateAltKeyPress() | |
123 { | |
124 QKeyEvent event(QEvent::KeyPress, Qt::Key_Alt, Qt::NoModifier); | |
125 QCoreApplication::sendEvent(m_window, &event); | |
126 QKeyEvent event2(QEvent::KeyRelease, Qt::Key_Alt, Qt::NoModifier); | |
127 QCoreApplication::sendEvent(m_window, &event2); | |
128 } | |
129 | |
130 void PlatformWebView::simulateMouseMove(unsigned x, unsigned y) | |
131 { | |
132 QPointF mousePos(x, y); | |
133 QMouseEvent event(QEvent::MouseMove, mousePos, Qt::NoButton, Qt::NoButton, Q
t::NoModifier); | |
134 QCoreApplication::sendEvent(m_window, &event); | |
135 } | |
136 | |
137 void PlatformWebView::simulateRightClick(unsigned x, unsigned y) | |
138 { | |
139 QPointF mousePos(x, y); | |
140 QMouseEvent event2(QEvent::MouseButtonPress, mousePos, Qt::RightButton, Qt::
RightButton, Qt::NoModifier); | |
141 QCoreApplication::sendEvent(m_window, &event2); | |
142 QMouseEvent event3(QEvent::MouseButtonRelease, mousePos, Qt::RightButton, Q
t::NoButton, Qt::NoModifier); | |
143 QCoreApplication::sendEvent(m_window, &event3); | |
144 } | |
145 | |
146 } // namespace TestWebKitAPI | |
147 | |
148 #include "PlatformWebViewQt.moc" | |
OLD | NEW |