2 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
22 #include "qtouchwebpage.h"
23 #include "qtouchwebpage_p.h"
25 #include "qtouchwebpageproxy.h"
26 #include <QApplication>
27 #include <QGraphicsSceneMouseEvent>
32 QTouchWebPage::QTouchWebPage(QSGItem* parent)
34 , d(new QTouchWebPagePrivate(this))
36 setFlag(ItemHasContents);
38 // We do the transform from the top left so the viewport can assume the position 0, 0
39 // is always where rendering starts.
40 setTransformOrigin(TopLeft);
43 QTouchWebPage::~QTouchWebPage()
48 void QTouchWebPage::load(const QUrl& url)
53 QUrl QTouchWebPage::url() const
55 return d->page->url();
58 QString QTouchWebPage::title() const
60 return d->page->title();
63 int QTouchWebPage::loadProgress() const
65 return d->page->loadProgress();
70 QSGNode* QTouchWebPage::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*)
73 oldNode = new QSGNode;
75 // A swap is on the queue, and SGUpdateQueue::applyUpdates will empty the queue, so we know that
76 // the old frame's buffers won't be used anymore (for buffers used all the way from the web process
77 // to the graphic card). Notify the web process that it can render the next frame.
78 if (d->sgUpdateQueue.isSwapPending())
79 // The UI thread is currently locked and calling this from the rendering thread didn't crash
80 // yet, so I'm assuming that this is OK. Else we have to wait until the SG update is over
81 // and the UI thread returns to the event loop picking our event before it can be sent to
82 // the web process. This would increase our chances of missing a frame.
83 d->page->renderNextFrame();
84 d->sgUpdateQueue.applyUpdates(oldNode);
86 // QSGItem takes ownership of this return value and it's children between and after updatePaintNode calls.
92 bool QTouchWebPage::event(QEvent* ev)
96 d->page->setPageIsVisible(true);
99 d->page->setPageIsVisible(false);
105 if (d->page->handleEvent(ev))
107 return QSGItem::event(ev);
110 void QTouchWebPage::keyPressEvent(QKeyEvent* event)
115 void QTouchWebPage::keyReleaseEvent(QKeyEvent* event)
120 void QTouchWebPage::inputMethodEvent(QInputMethodEvent* event)
125 void QTouchWebPage::focusInEvent(QFocusEvent* event)
130 void QTouchWebPage::focusOutEvent(QFocusEvent* event)
135 void QTouchWebPage::touchEvent(QTouchEvent* event)
140 void QTouchWebPage::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
142 QSGItem::geometryChanged(newGeometry, oldGeometry);
143 if (newGeometry.size() != oldGeometry.size())
144 d->page->setDrawingAreaSize(newGeometry.size().toSize());
147 QWebNavigationController* QTouchWebPage::navigationController() const
149 if (!d->navigationController)
150 d->navigationController = new QWebNavigationController(d->page);
151 return d->navigationController;
154 QTouchWebPagePrivate::QTouchWebPagePrivate(QTouchWebPage* view)
157 , navigationController(0)
158 , sgUpdateQueue(view)
162 void QTouchWebPagePrivate::setPage(QTouchWebPageProxy* page)
169 #include "moc_qtouchwebpage.cpp"