2
* Copyright (C) 2010 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 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.
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.
22
#include "PageClientQt.h"
24
#include <QGraphicsScene>
25
#include <QGraphicsView>
40
static void createPlatformGraphicsContext3DFromWidget(QWidget* widget, PlatformGraphicsContext3D* context,
41
PlatformGraphicsSurface3D* surface, QObject** surfaceOwner)
49
QGLWidget* glViewport = 0;
51
QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
54
glViewport = qobject_cast<QGLWidget*>(scrollArea->viewport());
56
QGLWidget* glWidget = 0;
58
glWidget = new QGLWidget(0, glViewport);
60
glWidget = new QGLWidget();
62
if (glWidget->isValid()) {
63
// Geometry can be set to zero because m_glWidget is used only for its QGLContext.
64
glWidget->setGeometry(0, 0, 0, 0);
66
*surfaceOwner = glWidget;
68
*surface = glWidget->windowHandle();
69
*context = glWidget->context()->contextHandle();
72
*context = const_cast<QGLContext*>(glWidget->context());
82
#if USE(ACCELERATED_COMPOSITING)
83
#include "TextureMapper.h"
84
#include "texmap/TextureMapperLayer.h"
88
QWindow* QWebPageClient::ownerWindow() const
90
QWidget* widget = ownerWidget();
93
if (QWindow *window = widget->windowHandle())
95
if (const QWidget *nativeParent = widget->nativeParentWidget())
96
return nativeParent->windowHandle();
103
#if USE(ACCELERATED_COMPOSITING)
104
TextureMapperLayerClientQt::TextureMapperLayerClientQt(QWebFrame* frame, GraphicsLayer* layer)
106
, m_rootGraphicsLayer(GraphicsLayer::create(0))
108
m_frame->d->rootTextureMapperLayer = rootLayer();
109
m_rootGraphicsLayer->addChild(layer);
110
m_rootGraphicsLayer->setDrawsContent(false);
111
m_rootGraphicsLayer->setMasksToBounds(false);
112
m_rootGraphicsLayer->setSize(IntSize(1, 1));
115
void TextureMapperLayerClientQt::setTextureMapper(const PassOwnPtr<TextureMapper>& textureMapper)
117
m_frame->d->textureMapper = textureMapper;
118
m_frame->d->rootTextureMapperLayer->setTextureMapper(m_frame->d->textureMapper.get());
122
TextureMapperLayerClientQt::~TextureMapperLayerClientQt()
124
m_frame->d->rootTextureMapperLayer = 0;
127
void TextureMapperLayerClientQt::syncRootLayer()
129
m_rootGraphicsLayer->flushCompositingStateForThisLayerOnly();
132
TextureMapperLayer* TextureMapperLayerClientQt::rootLayer()
134
return toTextureMapperLayer(m_rootGraphicsLayer.get());
138
void PageClientQWidget::setRootGraphicsLayer(GraphicsLayer* layer)
141
TextureMapperLayerClient = adoptPtr(new TextureMapperLayerClientQt(page->mainFrame(), layer));
142
TextureMapperLayerClient->setTextureMapper(TextureMapper::create());
145
TextureMapperLayerClient.clear();
148
void PageClientQWidget::markForSync(bool scheduleSync)
150
if (syncTimer.isActive())
152
syncTimer.startOneShot(0);
155
void PageClientQWidget::syncLayers(Timer<PageClientQWidget>*)
157
if (TextureMapperLayerClient)
158
TextureMapperLayerClient->syncRootLayer();
159
QWebFramePrivate::core(page->mainFrame())->view()->flushCompositingStateIncludingSubframes();
160
if (!TextureMapperLayerClient)
162
if (TextureMapperLayerClient->rootLayer()->descendantsOrSelfHaveRunningAnimations() && !syncTimer.isActive())
163
syncTimer.startOneShot(1.0 / 60.0);
164
update(view->rect());
168
void PageClientQWidget::scroll(int dx, int dy, const QRect& rectToScroll)
170
view->scroll(qreal(dx), qreal(dy), rectToScroll);
173
void PageClientQWidget::update(const QRect & dirtyRect)
175
view->update(dirtyRect);
178
void PageClientQWidget::setInputMethodEnabled(bool enable)
180
view->setAttribute(Qt::WA_InputMethodEnabled, enable);
183
bool PageClientQWidget::inputMethodEnabled() const
185
return view->testAttribute(Qt::WA_InputMethodEnabled);
188
void PageClientQWidget::setInputMethodHints(Qt::InputMethodHints hints)
190
view->setInputMethodHints(hints);
193
PageClientQWidget::~PageClientQWidget()
198
QCursor PageClientQWidget::cursor() const
200
return view->cursor();
203
void PageClientQWidget::updateCursor(const QCursor& cursor)
205
view->setCursor(cursor);
209
QPalette PageClientQWidget::palette() const
211
return view->palette();
214
int PageClientQWidget::screenNumber() const
216
#if defined(Q_WS_X11)
217
return view->x11Info().screen();
222
QWidget* PageClientQWidget::ownerWidget() const
227
QRect PageClientQWidget::geometryRelativeToOwnerWidget() const
229
return view->geometry();
232
QObject* PageClientQWidget::pluginParent() const
237
QStyle* PageClientQWidget::style() const
239
return view->style();
242
QRectF PageClientQWidget::windowRect() const
244
return QRectF(view->window()->geometry());
247
void PageClientQWidget::setWidgetVisible(Widget* widget, bool visible)
249
QWidget* qtWidget = qobject_cast<QWidget*>(widget->platformWidget());
252
qtWidget->setVisible(visible);
256
void PageClientQWidget::createPlatformGraphicsContext3D(PlatformGraphicsContext3D* context,
257
PlatformGraphicsSurface3D* surface,
258
QObject** surfaceOwner)
260
createPlatformGraphicsContext3DFromWidget(view, context, surface, surfaceOwner);
264
#if !defined(QT_NO_GRAPHICSVIEW)
265
PageClientQGraphicsWidget::~PageClientQGraphicsWidget()
270
void PageClientQGraphicsWidget::scroll(int dx, int dy, const QRect& rectToScroll)
272
view->scroll(qreal(dx), qreal(dy), rectToScroll);
275
void PageClientQGraphicsWidget::update(const QRect& dirtyRect)
277
view->update(dirtyRect);
280
overlay->update(QRectF(dirtyRect));
283
#if USE(ACCELERATED_COMPOSITING)
284
void PageClientQGraphicsWidget::syncLayers()
286
if (TextureMapperLayerClient)
287
TextureMapperLayerClient->syncRootLayer();
289
QWebFramePrivate::core(page->mainFrame())->view()->flushCompositingStateIncludingSubframes();
291
if (!TextureMapperLayerClient)
294
if (TextureMapperLayerClient->rootLayer()->descendantsOrSelfHaveRunningAnimations() && !syncTimer.isActive())
295
syncTimer.startOneShot(1.0 / 60.0);
296
update(view->boundingRect().toAlignedRect());
299
void PageClientQGraphicsWidget::setRootGraphicsLayer(GraphicsLayer* layer)
302
TextureMapperLayerClient = adoptPtr(new TextureMapperLayerClientQt(page->mainFrame(), layer));
303
#if USE(TEXTURE_MAPPER_GL) && defined(QT_OPENGL_LIB)
304
QGraphicsView* graphicsView = view->scene()->views()[0];
305
if (graphicsView && graphicsView->viewport()) {
306
QGLWidget* glWidget = qobject_cast<QGLWidget*>(graphicsView->viewport());
308
// The GL context belonging to the QGLWidget viewport must be current when TextureMapper is being created.
309
glWidget->makeCurrent();
310
TextureMapperLayerClient->setTextureMapper(TextureMapper::create(TextureMapper::OpenGLMode));
315
TextureMapperLayerClient->setTextureMapper(TextureMapper::create());
318
TextureMapperLayerClient.clear();
321
void PageClientQGraphicsWidget::markForSync(bool scheduleSync)
323
if (syncTimer.isActive())
325
syncTimer.startOneShot(0);
330
#if USE(TILED_BACKING_STORE)
331
void PageClientQGraphicsWidget::updateTiledBackingStoreScale()
333
WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page->mainFrame())->tiledBackingStore();
336
backingStore->setContentsScale(view->scale());
340
void PageClientQGraphicsWidget::setInputMethodEnabled(bool enable)
342
view->setFlag(QGraphicsItem::ItemAcceptsInputMethod, enable);
345
bool PageClientQGraphicsWidget::inputMethodEnabled() const
347
return view->flags() & QGraphicsItem::ItemAcceptsInputMethod;
350
void PageClientQGraphicsWidget::setInputMethodHints(Qt::InputMethodHints hints)
352
view->setInputMethodHints(hints);
356
QCursor PageClientQGraphicsWidget::cursor() const
358
return view->cursor();
361
void PageClientQGraphicsWidget::updateCursor(const QCursor& cursor)
363
view->setCursor(cursor);
367
QPalette PageClientQGraphicsWidget::palette() const
369
return view->palette();
372
int PageClientQGraphicsWidget::screenNumber() const
374
#if defined(Q_WS_X11)
375
if (QGraphicsScene* scene = view->scene()) {
376
const QList<QGraphicsView*> views = scene->views();
378
if (!views.isEmpty())
379
return views.at(0)->x11Info().screen();
386
QWidget* PageClientQGraphicsWidget::ownerWidget() const
388
if (QGraphicsScene* scene = view->scene()) {
389
const QList<QGraphicsView*> views = scene->views();
390
return views.value(0);
395
QRect PageClientQGraphicsWidget::geometryRelativeToOwnerWidget() const
400
QList<QGraphicsView*> views = view->scene()->views();
404
QGraphicsView* graphicsView = views.at(0);
405
return graphicsView->mapFromScene(view->boundingRect()).boundingRect();
408
#if USE(TILED_BACKING_STORE)
409
QRectF PageClientQGraphicsWidget::graphicsItemVisibleRect() const
414
QList<QGraphicsView*> views = view->scene()->views();
418
QGraphicsView* graphicsView = views.at(0);
419
int xOffset = graphicsView->horizontalScrollBar()->value();
420
int yOffset = graphicsView->verticalScrollBar()->value();
421
return view->mapRectFromScene(QRectF(QPointF(xOffset, yOffset), graphicsView->viewport()->size()));
425
QObject* PageClientQGraphicsWidget::pluginParent() const
430
QStyle* PageClientQGraphicsWidget::style() const
432
return view->style();
435
void PageClientQGraphicsWidget::setWidgetVisible(Widget*, bool)
437
// Doesn't make sense, does it?
440
QRectF PageClientQGraphicsWidget::windowRect() const
445
// The sceneRect is a good approximation of the size of the application, independent of the view.
446
return view->scene()->sceneRect();
448
#endif // QT_NO_GRAPHICSVIEW
451
void PageClientQGraphicsWidget::createPlatformGraphicsContext3D(PlatformGraphicsContext3D* context,
452
PlatformGraphicsSurface3D* surface,
453
QObject** surfaceOwner)
455
createPlatformGraphicsContext3DFromWidget(ownerWidget(), context, surface, surfaceOwner);
459
} // namespace WebCore