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.
21 #ifndef PageClientQt_h
22 #define PageClientQt_h
24 #include "FrameView.h"
25 #include "GraphicsContext.h"
27 #include "QWebPageClient.h"
28 #include "TiledBackingStore.h"
29 #include "qgraphicswebview.h"
30 #include "qwebframe.h"
31 #include "qwebframe_p.h"
33 #include "qwebpage_p.h"
34 #include <qgraphicsscene.h>
35 #include <qgraphicsview.h>
36 #include <qgraphicswidget.h>
37 #include <qscrollbar.h>
38 #include <qstyleoption.h>
40 #include <QtCore/qmetaobject.h>
46 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
47 class TextureMapperNodeClientQt {
49 TextureMapperNodeClientQt(QWebFrame*, GraphicsLayer*);
50 virtual ~TextureMapperNodeClientQt();
51 void setTextureMapper(const PassOwnPtr<TextureMapper>&);
53 TextureMapperNode* rootNode();
57 OwnPtr<GraphicsLayer> m_rootGraphicsLayer;
61 class PageClientQWidget : public QWebPageClient {
63 PageClientQWidget(QWidget* newView, QWebPage* newPage)
66 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
67 , syncTimer(this, &PageClientQWidget::syncLayers)
72 virtual ~PageClientQWidget();
74 virtual bool isQWidgetClient() const { return true; }
76 virtual void scroll(int dx, int dy, const QRect&);
77 virtual void update(const QRect& dirtyRect);
78 virtual void setInputMethodEnabled(bool enable);
79 virtual bool inputMethodEnabled() const;
80 virtual void setInputMethodHints(Qt::InputMethodHints hints);
83 virtual QCursor cursor() const;
84 virtual void updateCursor(const QCursor& cursor);
87 virtual QPalette palette() const;
88 virtual int screenNumber() const;
89 virtual QWidget* ownerWidget() const;
90 virtual QRect geometryRelativeToOwnerWidget() const;
92 virtual QObject* pluginParent() const;
94 virtual QStyle* style() const;
96 virtual bool viewResizesToContentsEnabled() const { return false; }
98 virtual QRectF windowRect() const;
103 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
104 virtual void setRootGraphicsLayer(GraphicsLayer*);
105 virtual void markForSync(bool scheduleSync);
106 void syncLayers(Timer<PageClientQWidget>*);
109 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
110 virtual bool allowsAcceleratedCompositing() const { return true; }
112 virtual bool allowsAcceleratedCompositing() const { return false; }
115 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
116 Timer<PageClientQWidget> syncTimer;
117 OwnPtr<TextureMapperNodeClientQt> textureMapperNodeClient;
121 #if !defined(QT_NO_GRAPHICSVIEW)
122 // the overlay is here for one reason only: to have the scroll-bars and other
123 // extra UI elements appear on top of any QGraphicsItems created by CSS compositing layers
124 class QGraphicsItemOverlay : public QGraphicsObject {
126 QGraphicsItemOverlay(QGraphicsWidget* view, QWebPage* p)
127 :QGraphicsObject(view)
132 setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
133 setCacheMode(QGraphicsItem::DeviceCoordinateCache);
136 QRectF boundingRect() const
138 return q->boundingRect();
141 void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*)
143 page->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect());
146 void prepareGraphicsItemGeometryChange()
148 prepareGeometryChange();
156 class PageClientQGraphicsWidget : public QWebPageClient {
158 PageClientQGraphicsWidget(QGraphicsWebView* newView, QWebPage* newPage)
161 , viewResizesToContents(false)
162 #if USE(ACCELERATED_COMPOSITING)
163 , syncTimer(this, &PageClientQGraphicsWidget::syncLayersTimeout)
169 #if USE(ACCELERATED_COMPOSITING)
170 // the overlay and stays alive for the lifetime of
171 // this QGraphicsWebView as the scrollbars are needed when there's no compositing
172 view->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
176 virtual ~PageClientQGraphicsWidget();
178 virtual bool isQWidgetClient() const { return false; }
180 virtual void scroll(int dx, int dy, const QRect&);
181 virtual void update(const QRect& dirtyRect);
182 virtual void setInputMethodEnabled(bool enable);
183 virtual bool inputMethodEnabled() const;
184 virtual void setInputMethodHints(Qt::InputMethodHints hints);
187 virtual QCursor cursor() const;
188 virtual void updateCursor(const QCursor& cursor);
191 virtual QPalette palette() const;
192 virtual int screenNumber() const;
193 virtual QWidget* ownerWidget() const;
194 virtual QRect geometryRelativeToOwnerWidget() const;
196 virtual QObject* pluginParent() const;
198 virtual QStyle* style() const;
200 virtual bool viewResizesToContentsEnabled() const { return viewResizesToContents; }
202 void createOrDeleteOverlay();
204 #if USE(TILED_BACKING_STORE)
205 void updateTiledBackingStoreScale();
206 virtual QRectF graphicsItemVisibleRect() const;
209 #if USE(ACCELERATED_COMPOSITING)
210 virtual void setRootGraphicsLayer(GraphicsLayer*);
211 virtual void markForSync(bool scheduleSync);
213 void syncLayersTimeout(Timer<PageClientQGraphicsWidget>*) { syncLayers(); }
215 // QGraphicsWebView can render composited layers
216 virtual bool allowsAcceleratedCompositing() const { return true; }
219 virtual QRectF windowRect() const;
221 QGraphicsWebView* view;
223 bool viewResizesToContents;
225 #if USE(ACCELERATED_COMPOSITING)
226 #if USE(TEXTURE_MAPPER)
227 OwnPtr<TextureMapperNodeClientQt> textureMapperNodeClient;
229 QWeakPointer<QGraphicsObject> rootGraphicsLayer;
231 // we have to flush quite often, so we use a meta-method instead of QTimer::singleShot for putting the event in the queue
232 Timer<PageClientQGraphicsWidget> syncTimer;
234 // we need to sync the layers if we get a special call from the WebCore
235 // compositor telling us to do so. We'll get that call from ChromeClientQt
238 // the overlay gets instantiated when the root layer is attached, and get deleted when it's detached
239 QGraphicsItemOverlay* overlay;
241 // we need to put the root graphics layer behind the overlay (which contains the scrollbar)
242 enum { RootGraphicsLayerZValue, OverlayZValue };
244 #endif // QT_NO_GRAPHICSVIEW
247 #endif // PageClientQt