1/*
2    Copyright (C) 2012 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 library 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 library; 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#include "config.h"
21#include "qrawwebview_p.h"
22
23#include "CoordinatedLayerTreeHostProxy.h"
24#include "Cursor.h"
25#include "DrawingAreaProxyImpl.h"
26#include "NativeWebKeyboardEvent.h"
27#include "NativeWebMouseEvent.h"
28#if ENABLE(TOUCH_EVENTS)
29#include "NativeWebTouchEvent.h"
30#endif
31#include "NativeWebWheelEvent.h"
32#include "NotImplemented.h"
33#include "WebContext.h"
34#include "WebPageGroup.h"
35#include "WebPreferences.h"
36#include "qrawwebview_p_p.h"
37#include <WebCore/CoordinatedGraphicsScene.h>
38#include <WebKit2/qrawwebview_p.h>
39
40void QRawWebViewPrivate::didChangeViewportProperties(const WebCore::ViewportAttributes& attr)
41{
42    notImplemented();
43}
44
45void QRawWebViewPrivate::handleDownloadRequest(WebKit::DownloadProxy* download)
46{
47    notImplemented();
48}
49
50void QRawWebViewPrivate::handleAuthenticationRequiredRequest(const String& hostname, const String& realm, const String& prefilledUsername, String& username, String& password)
51{
52    notImplemented();
53}
54
55void QRawWebViewPrivate::handleCertificateVerificationRequest(const String& hostname, bool& ignoreErrors)
56{
57    notImplemented();
58}
59
60void QRawWebViewPrivate::handleProxyAuthenticationRequiredRequest(const String& hostname, uint16_t port, const String& prefilledUsername, String& username, String& password)
61{
62    notImplemented();
63}
64
65void QRawWebViewPrivate::registerEditCommand(PassRefPtr<WebKit::WebEditCommandProxy>, WebKit::WebPageProxy::UndoOrRedo)
66{
67    notImplemented();
68}
69
70bool QRawWebViewPrivate::canUndoRedo(WebKit::WebPageProxy::UndoOrRedo undoOrRedo)
71{
72    notImplemented();
73    return false;
74}
75
76void QRawWebViewPrivate::executeUndoRedo(WebKit::WebPageProxy::UndoOrRedo undoOrRedo)
77{
78    notImplemented();
79}
80
81WebCore::FloatRect QRawWebViewPrivate::convertToDeviceSpace(const WebCore::FloatRect& rect)
82{
83    notImplemented();
84    return rect;
85}
86
87WebCore::FloatRect QRawWebViewPrivate::convertToUserSpace(const WebCore::FloatRect& rect)
88{
89    notImplemented();
90    return rect;
91}
92
93WebCore::IntPoint QRawWebViewPrivate::screenToWindow(const WebCore::IntPoint& point)
94{
95    notImplemented();
96    return point;
97}
98
99WebCore::IntRect QRawWebViewPrivate::windowToScreen(const WebCore::IntRect& rect)
100{
101    notImplemented();
102    return rect;
103}
104
105#if USE(ACCELERATED_COMPOSITING)
106void QRawWebViewPrivate::enterAcceleratedCompositingMode(const WebKit::LayerTreeContext&)
107{
108    notImplemented();
109}
110
111void QRawWebViewPrivate::exitAcceleratedCompositingMode()
112{
113    notImplemented();
114}
115
116void QRawWebViewPrivate::updateAcceleratedCompositingMode(const WebKit::LayerTreeContext&)
117{
118    notImplemented();
119}
120
121#endif // USE(ACCELERATED_COMPOSITING)
122
123void QRawWebViewPrivate::updateTextInputState()
124{
125    notImplemented();
126}
127
128void QRawWebViewPrivate::handleWillSetInputMethodState()
129{
130    notImplemented();
131}
132
133#if ENABLE(GESTURE_EVENTS)
134void QRawWebViewPrivate::doneWithGestureEvent(const WebKit::WebGestureEvent& event, bool wasEventHandled)
135{
136    notImplemented();
137}
138
139#endif
140void QRawWebViewPrivate::displayView()
141{
142    notImplemented();
143}
144
145void QRawWebViewPrivate::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset)
146{
147    notImplemented();
148}
149
150void QRawWebViewPrivate::flashBackingStoreUpdates(const Vector<WebCore::IntRect>&)
151{
152    notImplemented();
153}
154
155void QRawWebViewPrivate::didFindZoomableArea(const WebCore::IntPoint& target, const WebCore::IntRect& area)
156{
157    notImplemented();
158}
159
160void QRawWebViewPrivate::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
161{
162    notImplemented();
163}
164
165void QRawWebViewPrivate::toolTipChanged(const String&, const String& newTooltip)
166{
167    notImplemented();
168}
169
170void QRawWebViewPrivate::pageTransitionViewportReady()
171{
172    m_webPageProxy->commitPageTransitionViewport();
173}
174
175void QRawWebViewPrivate::startDrag(const WebCore::DragData& dragData, PassRefPtr<WebKit::ShareableBitmap> dragImage)
176{
177    notImplemented();
178}
179
180PassRefPtr<WebKit::WebPopupMenuProxy> QRawWebViewPrivate::createPopupMenuProxy(WebKit::WebPageProxy* webPageProxy)
181{
182    notImplemented();
183    return PassRefPtr<WebKit::WebPopupMenuProxy>();
184}
185
186PassRefPtr<WebKit::WebContextMenuProxy> QRawWebViewPrivate::createContextMenuProxy(WebKit::WebPageProxy* webPageProxy)
187{
188    notImplemented();
189    return PassRefPtr<WebKit::WebContextMenuProxy>();
190}
191
192#if ENABLE(INPUT_TYPE_COLOR)
193PassRefPtr<WebKit::WebColorChooserProxy> QRawWebViewPrivate::createColorChooserProxy(WebKit::WebPageProxy*, const WebCore::Color& intialColor, const WebCore::IntRect&)
194{
195    notImplemented();
196    return PassRefPtr<WebKit::WebColorChooserProxy>();
197}
198#endif
199
200void QRawWebViewPrivate::pageDidRequestScroll(const WebCore::IntPoint& pos)
201{
202    m_client->viewRequestedScroll(pos);
203
204}
205void QRawWebViewPrivate::processDidCrash()
206{
207    m_client->viewProcessCrashed();
208}
209
210void QRawWebViewPrivate::didRelaunchProcess()
211{
212    m_client->viewProcessRelaunched();
213}
214
215void QRawWebViewPrivate::setViewNeedsDisplay(const WebCore::IntRect& rect)
216{
217    m_client->viewNeedsDisplay(rect);
218}
219
220void QRawWebViewPrivate::didChangeContentsSize(const WebCore::IntSize& newSize)
221{
222    m_client->viewContentSizeChanged(newSize);
223}
224
225void QRawWebViewPrivate::setCursor(const WebCore::Cursor& cursor)
226{
227    m_client->viewRequestedCursorOverride(*cursor.platformCursor());
228}
229
230#if ENABLE(TOUCH_EVENTS)
231void QRawWebViewPrivate::doneWithTouchEvent(const WebKit::NativeWebTouchEvent& event, bool wasEventHandled)
232{
233    m_client->doneWithTouchEvent(event.nativeEvent(), wasEventHandled);
234}
235#endif
236
237void QRawWebViewPrivate::doneWithKeyEvent(const WebKit::NativeWebKeyboardEvent& event, bool wasEventHandled)
238{
239    m_client->doneWithKeyEvent(event.nativeEvent(), wasEventHandled);
240}
241
242PassOwnPtr<WebKit::DrawingAreaProxy> QRawWebViewPrivate::createDrawingAreaProxy()
243{
244    return WebKit::DrawingAreaProxyImpl::create(m_webPageProxy.get());
245}
246
247QRawWebViewPrivate::QRawWebViewPrivate(WebKit::WebContext* context, WebKit::WebPageGroup* pageGroup, QRawWebViewClient* client)
248    : m_focused(false)
249    , m_visible(false)
250    , m_active(false)
251    , m_client(client)
252    , m_webPageProxy(context->createWebPage(this, pageGroup))
253{
254    m_webPageProxy->pageGroup()->preferences()->setForceCompositingMode(true);
255}
256
257QRawWebViewPrivate::~QRawWebViewPrivate()
258{
259}
260
261QRawWebView::QRawWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef, QRawWebViewClient* client)
262    : d(new QRawWebViewPrivate(WebKit::toImpl(contextRef), WebKit::toImpl(pageGroupRef), client))
263{
264}
265
266QRawWebView::~QRawWebView()
267{
268    delete d;
269}
270
271void QRawWebView::create()
272{
273    d->m_webPageProxy->initializeWebPage();
274}
275
276void QRawWebView::setTransparentBackground(bool value)
277{
278    d->m_webPageProxy->setDrawsTransparentBackground(value);
279}
280
281bool QRawWebView::transparentBackground() const
282{
283    return d->m_webPageProxy->drawsTransparentBackground();
284}
285
286void QRawWebView::setDrawBackground(bool value)
287{
288    d->m_webPageProxy->setDrawsBackground(value);
289}
290
291bool QRawWebView::drawBackground() const
292{
293    return d->m_webPageProxy->drawsBackground();
294}
295
296bool QRawWebView::isFocused() const
297{
298    return d->m_focused;
299}
300
301void QRawWebView::setFocused(bool focused)
302{
303    d->m_focused = focused;
304    d->m_webPageProxy->viewStateDidChange(WebKit::WebPageProxy::ViewIsFocused);
305}
306
307bool QRawWebView::isVisible() const
308{
309    return d->m_visible;
310}
311
312void QRawWebView::setVisible(bool visible)
313{
314    d->m_visible = visible;
315    d->m_webPageProxy->viewStateDidChange(WebKit::WebPageProxy::ViewIsVisible);
316}
317
318bool QRawWebView::isActive() const
319{
320    return d->m_active;
321}
322
323void QRawWebView::setActive(bool active)
324{
325    d->m_active = active;
326    d->m_webPageProxy->viewStateDidChange(WebKit::WebPageProxy::ViewWindowIsActive);
327    coordinatedGraphicsScene()->setActive(active);
328}
329
330QSize QRawWebView::size() const
331{
332    return d->m_size;
333}
334
335void QRawWebView::setSize(const QSize& size)
336{
337    WebKit::DrawingAreaProxy* drawingArea = d->m_webPageProxy->drawingArea();
338    if (!drawingArea)
339        return;
340
341    if (d->m_webPageProxy->useFixedLayout())
342        drawingArea->setSize(size, WebCore::IntSize(), WebCore::IntSize());
343
344    d->m_size = size;
345
346    drawingArea->setSize(d->m_size, WebCore::IntSize(), WebCore::IntSize());
347    drawingArea->setVisibleContentsRect(WebCore::IntRect(WebCore::IntPoint(), d->m_size), WebCore::FloatPoint());
348}
349
350WKPageRef QRawWebView::pageRef()
351{
352    return toAPI(d->m_webPageProxy.get());
353}
354
355WebCore::CoordinatedGraphicsScene* QRawWebView::coordinatedGraphicsScene() const
356{
357    WebKit::DrawingAreaProxy* drawingArea = d->m_webPageProxy->drawingArea();
358    if (!drawingArea)
359        return 0;
360    WebKit::CoordinatedLayerTreeHostProxy* coordinatedLayerTreeHostProxy = drawingArea->coordinatedLayerTreeHostProxy();
361    if (!coordinatedLayerTreeHostProxy)
362        return 0;
363    return coordinatedLayerTreeHostProxy->coordinatedGraphicsScene();
364}
365
366void QRawWebView::paint(const QMatrix4x4& transform, float opacity, unsigned paintFlags)
367{
368    WebCore::CoordinatedGraphicsScene* scene = coordinatedGraphicsScene();
369    if (!scene)
370        return;
371
372    scene->setActive(true);
373
374    WebCore::FloatRect rect(0, 0, d->m_size.width(), d->m_size.height());
375
376    scene->paintToCurrentGLContext(transform, opacity, transform.mapRect(rect), paintFlags);
377}
378
379void QRawWebView::sendKeyEvent(QKeyEvent* event)
380{
381    d->m_webPageProxy->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(event));
382}
383
384void QRawWebView::sendMouseEvent(QMouseEvent* event, int clickCount)
385{
386    d->m_webPageProxy->handleMouseEvent(WebKit::NativeWebMouseEvent(event, QTransform(), clickCount));
387}
388
389void QRawWebView::sendWheelEvent(QWheelEvent* event)
390{
391    d->m_webPageProxy->handleWheelEvent(WebKit::NativeWebWheelEvent(event, QTransform()));
392}
393
394void QRawWebView::sendTouchEvent(QTouchEvent* event)
395{
396#if ENABLE(TOUCH_EVENTS)
397    d->m_webPageProxy->handleTouchEvent(WebKit::NativeWebTouchEvent(event, QTransform()));
398#endif
399}
400