initial import
[vuplus_webkit] / Source / WebKit2 / UIProcess / API / qt / qtouchwebpage.cpp
1 /*
2  * Copyright (C) 2010, 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 "qtouchwebpage.h"
23 #include "qtouchwebpage_p.h"
24
25 #include "qtouchwebpageproxy.h"
26 #include <QApplication>
27 #include <QGraphicsSceneMouseEvent>
28 #include <QPainter>
29 #include <QSGNode>
30 #include <QUrl>
31
32 QTouchWebPage::QTouchWebPage(QSGItem* parent)
33     : QSGItem(parent)
34     , d(new QTouchWebPagePrivate(this))
35 {
36     setFlag(ItemHasContents);
37
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);
41 }
42
43 QTouchWebPage::~QTouchWebPage()
44 {
45     delete d;
46 }
47
48 void QTouchWebPage::load(const QUrl& url)
49 {
50     d->page->load(url);
51 }
52
53 QUrl QTouchWebPage::url() const
54 {
55     return d->page->url();
56 }
57
58 QString QTouchWebPage::title() const
59 {
60     return d->page->title();
61 }
62
63 int QTouchWebPage::loadProgress() const
64 {
65     return d->page->loadProgress();
66 }
67
68 /*! \reimp
69 */
70 QSGNode* QTouchWebPage::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*)
71 {
72     if (!oldNode)
73         oldNode = new QSGNode;
74
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);
85
86     // QSGItem takes ownership of this return value and it's children between and after updatePaintNode calls.
87     return oldNode;
88 }
89
90 /*! \reimp
91 */
92 bool QTouchWebPage::event(QEvent* ev)
93 {
94     switch (ev->type()) {
95     case QEvent::Show:
96         d->page->setPageIsVisible(true);
97         break;
98     case QEvent::Hide:
99         d->page->setPageIsVisible(false);
100         break;
101     default:
102         break;
103     }
104
105     if (d->page->handleEvent(ev))
106         return true;
107     return QSGItem::event(ev);
108 }
109
110 void QTouchWebPage::keyPressEvent(QKeyEvent* event)
111 {
112     this->event(event);
113 }
114
115 void QTouchWebPage::keyReleaseEvent(QKeyEvent* event)
116 {
117     this->event(event);
118 }
119
120 void QTouchWebPage::inputMethodEvent(QInputMethodEvent* event)
121 {
122     this->event(event);
123 }
124
125 void QTouchWebPage::focusInEvent(QFocusEvent* event)
126 {
127     this->event(event);
128 }
129
130 void QTouchWebPage::focusOutEvent(QFocusEvent* event)
131 {
132     this->event(event);
133 }
134
135 void QTouchWebPage::touchEvent(QTouchEvent* event)
136 {
137     this->event(event);
138 }
139
140 void QTouchWebPage::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
141 {
142     QSGItem::geometryChanged(newGeometry, oldGeometry);
143     if (newGeometry.size() != oldGeometry.size())
144         d->page->setDrawingAreaSize(newGeometry.size().toSize());
145 }
146
147 QWebNavigationController* QTouchWebPage::navigationController() const
148 {
149     if (!d->navigationController)
150         d->navigationController = new QWebNavigationController(d->page);
151     return d->navigationController;
152 }
153
154 QTouchWebPagePrivate::QTouchWebPagePrivate(QTouchWebPage* view)
155     : q(view)
156     , page(0)
157     , navigationController(0)
158     , sgUpdateQueue(view)
159 {
160 }
161
162 void QTouchWebPagePrivate::setPage(QTouchWebPageProxy* page)
163 {
164     ASSERT(!this->page);
165     ASSERT(page);
166     this->page = page;
167 }
168
169 #include "moc_qtouchwebpage.cpp"