[Qt][WK2] Move non-api classes to WebKit namespace at WebKit2/UiProcess/qt
[WebKit-https.git] / Source / WebKit2 / UIProcess / qt / QtPageClient.cpp
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #include "config.h"
22 #include "QtPageClient.h"
23
24 #include "DrawingAreaProxy.h"
25 #include "LayerTreeContext.h"
26 #include "QtWebPageEventHandler.h"
27 #include "QtWebUndoController.h"
28 #include "ShareableBitmap.h"
29 #include "WebContextMenuProxyQt.h"
30 #include "WebEditCommandProxy.h"
31 #include "WebPopupMenuProxyQt.h"
32 #include "qquickwebview_p.h"
33 #include "qquickwebview_p_p.h"
34 #include <QGuiApplication>
35 #include <QQuickCanvas>
36 #include <WebCore/Cursor.h>
37 #include <WebCore/DragData.h>
38 #include <WebCore/FloatRect.h>
39 #include <WebCore/NotImplemented.h>
40
41 using namespace WebCore;
42
43 namespace WebKit {
44
45 QtPageClient::QtPageClient()
46     : m_webView(0)
47     , m_eventHandler(0)
48     , m_undoController(0)
49 {
50 }
51
52 QtPageClient::~QtPageClient()
53 {
54 }
55
56 void QtPageClient::initialize(QQuickWebView* webView, QtWebPageEventHandler* eventHandler, QtWebUndoController* undoController)
57 {
58     m_webView = webView;
59     m_eventHandler = eventHandler;
60     m_undoController = undoController;
61 }
62
63 PassOwnPtr<DrawingAreaProxy> QtPageClient::createDrawingAreaProxy()
64 {
65     return QQuickWebViewPrivate::get(m_webView)->createDrawingAreaProxy();
66 }
67
68 void QtPageClient::setViewNeedsDisplay(const WebCore::IntRect& rect)
69 {
70     QQuickWebViewPrivate::get(m_webView)->setNeedsDisplay();
71 }
72
73 void QtPageClient::pageDidRequestScroll(const IntPoint& pos)
74 {
75     QQuickWebViewPrivate::get(m_webView)->pageDidRequestScroll(pos);
76 }
77
78 void QtPageClient::processDidCrash()
79 {
80     QQuickWebViewPrivate::get(m_webView)->processDidCrash();
81 }
82
83 void QtPageClient::didRelaunchProcess()
84 {
85     QQuickWebViewPrivate::get(m_webView)->didRelaunchProcess();
86 }
87
88 void QtPageClient::didChangeContentsSize(const IntSize& newSize)
89 {
90     QQuickWebViewPrivate::get(m_webView)->didChangeContentsSize(newSize);
91 }
92
93 void QtPageClient::didChangeViewportProperties(const WebCore::ViewportAttributes& attr)
94 {
95     QQuickWebViewPrivate::get(m_webView)->didChangeViewportProperties(attr);
96 }
97
98 void QtPageClient::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
99 {
100     m_eventHandler->startDrag(dragData, dragImage);
101 }
102
103 void QtPageClient::handleDownloadRequest(DownloadProxy* download)
104 {
105     QQuickWebViewPrivate::get(m_webView)->handleDownloadRequest(download);
106 }
107
108 void QtPageClient::handleApplicationSchemeRequest(PassRefPtr<QtRefCountedNetworkRequestData> requestData)
109 {
110     if (!m_webView || !m_webView->experimental())
111         return;
112     m_webView->experimental()->invokeApplicationSchemeHandler(requestData);
113 }
114
115 void QtPageClient::handleAuthenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password)
116 {
117     QString qUsername;
118     QString qPassword;
119
120     QQuickWebViewPrivate::get(m_webView)->handleAuthenticationRequiredRequest(hostname, realm, prefilledUsername, qUsername, qPassword);
121
122     username = qUsername;
123     password = qPassword;
124 }
125
126 void QtPageClient::handleCertificateVerificationRequest(const String& hostname, bool& ignoreErrors)
127 {
128     ignoreErrors = QQuickWebViewPrivate::get(m_webView)->handleCertificateVerificationRequest(hostname);
129 }
130
131 void QtPageClient::handleProxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password)
132 {
133     QString qUsername;
134     QString qPassword;
135
136     QQuickWebViewPrivate::get(m_webView)->handleProxyAuthenticationRequiredRequest(hostname, port, prefilledUsername, qUsername, qPassword);
137
138     username = qUsername;
139     password = qPassword;
140 }
141
142 void QtPageClient::setCursor(const WebCore::Cursor& cursor)
143 {
144     // FIXME: This is a temporary fix until we get cursor support in QML items.
145     QGuiApplication::setOverrideCursor(*cursor.platformCursor());
146 }
147
148 void QtPageClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
149 {
150     notImplemented();
151 }
152
153 void QtPageClient::toolTipChanged(const String&, const String& newTooltip)
154 {
155     // There is not yet any UI defined for the tooltips for mobile so we ignore the change.
156 }
157
158 void QtPageClient::registerEditCommand(PassRefPtr<WebEditCommandProxy> command, WebPageProxy::UndoOrRedo undoOrRedo)
159 {
160     m_undoController->registerEditCommand(command, undoOrRedo);
161 }
162
163 void QtPageClient::clearAllEditCommands()
164 {
165     m_undoController->clearAllEditCommands();
166 }
167
168 bool QtPageClient::canUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
169 {
170     return m_undoController->canUndoRedo(undoOrRedo);
171 }
172
173 void QtPageClient::executeUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
174 {
175     m_undoController->executeUndoRedo(undoOrRedo);
176 }
177
178 FloatRect QtPageClient::convertToDeviceSpace(const FloatRect& rect)
179 {
180     return rect;
181 }
182
183 FloatRect QtPageClient::convertToUserSpace(const FloatRect& rect)
184 {
185     return rect;
186 }
187
188 IntPoint QtPageClient::screenToWindow(const IntPoint& point)
189 {
190     return point;
191 }
192
193 IntRect QtPageClient::windowToScreen(const IntRect& rect)
194 {
195     return rect;
196 }
197
198 PassRefPtr<WebPopupMenuProxy> QtPageClient::createPopupMenuProxy(WebPageProxy* webPageProxy)
199 {
200     return WebPopupMenuProxyQt::create(webPageProxy, m_webView);
201 }
202
203 PassRefPtr<WebContextMenuProxy> QtPageClient::createContextMenuProxy(WebPageProxy* webPageProxy)
204 {
205     return WebContextMenuProxyQt::create(webPageProxy);
206 }
207
208 void QtPageClient::flashBackingStoreUpdates(const Vector<IntRect>&)
209 {
210     notImplemented();
211 }
212
213 void QtPageClient::didFindZoomableArea(const IntPoint& target, const IntRect& area)
214 {
215     ASSERT(m_eventHandler);
216     m_eventHandler->didFindZoomableArea(target, area);
217 }
218
219 void QtPageClient::didReceiveMessageFromNavigatorQtObject(const String& message)
220 {
221     QQuickWebViewPrivate::get(m_webView)->didReceiveMessageFromNavigatorQtObject(message);
222 }
223
224 void QtPageClient::updateTextInputState()
225 {
226     ASSERT(m_eventHandler);
227     m_eventHandler->updateTextInputState();
228 }
229
230 #if ENABLE(GESTURE_EVENTS)
231 void QtPageClient::doneWithGestureEvent(const WebGestureEvent& event, bool wasEventHandled)
232 {
233     ASSERT(m_eventHandler);
234     m_eventHandler->doneWithGestureEvent(event, wasEventHandled);
235 }
236 #endif
237
238 #if ENABLE(TOUCH_EVENTS)
239 void QtPageClient::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
240 {
241     ASSERT(m_eventHandler);
242     m_eventHandler->doneWithTouchEvent(event, wasEventHandled);
243 }
244 #endif
245
246 void QtPageClient::displayView()
247 {
248     // FIXME: Implement.
249 }
250
251 void QtPageClient::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset)
252 {
253     // FIXME: Implement.
254 }
255
256 WebCore::IntSize QtPageClient::viewSize()
257 {
258     return QQuickWebViewPrivate::get(m_webView)->viewSize();
259 }
260
261 bool QtPageClient::isViewWindowActive()
262 {
263     // FIXME: The scene graph does not have the concept of being active or not when this was written.
264     return true;
265 }
266
267 bool QtPageClient::isViewFocused()
268 {
269     if (!m_webView)
270         return false;
271     return m_webView->hasFocus();
272 }
273
274 bool QtPageClient::isViewVisible()
275 {
276     if (!m_webView)
277         return false;
278
279     // FIXME: this is a workaround while QWindow::isExposed() is not ready.
280     if (m_webView->canvas() && m_webView->canvas()->windowState() == Qt::WindowMinimized)
281         return false;
282
283     return m_webView->isVisible() && m_webView->page()->isVisible();
284 }
285
286 bool QtPageClient::isViewInWindow()
287 {
288     // FIXME: Implement.
289     return true;
290 }
291
292 void QtPageClient::enterAcceleratedCompositingMode(const LayerTreeContext&)
293 {
294     // FIXME: Implement.
295 }
296
297 void QtPageClient::exitAcceleratedCompositingMode()
298 {
299     // FIXME: Implement.
300 }
301
302 void QtPageClient::updateAcceleratedCompositingMode(const LayerTreeContext&)
303 {
304     // FIXME: Implement.
305 }
306
307 } // namespace WebKit