1 /* 2 * Copyright (C) 2010 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 21 #ifndef PageClientQt_h 22 #define PageClientQt_h 23 24 #include "FrameView.h" 25 #include "GraphicsContext.h" 26 #include "IntRect.h" 27 #include "QWebPageClient.h" 28 #include "TiledBackingStore.h" 29 #include "qgraphicswebview.h" 30 #include "qwebframe.h" 31 #include "qwebframe_p.h" 32 #include "qwebpage.h" 33 #include "qwebpage_p.h" 34 #include <QtCore/qmetaobject.h> 35 #include <QtGui/qgraphicsscene.h> 36 #include <QtGui/qgraphicsview.h> 37 #include <QtGui/qgraphicswidget.h> 38 #include <QtGui/qscrollbar.h> 39 #include <QtGui/qstyleoption.h> 40 #include <QtGui/qwidget.h> 41 42 #include <Settings.h> 43 44 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 45 #include "texmap/TextureMapperPlatformLayer.h" 46 #endif 47 48 namespace WebCore { 49 50 class PageClientQWidget : public QWebPageClient { 51 public: 52 PageClientQWidget(QWidget* newView, QWebPage* newPage) 53 : view(newView) 54 , page(newPage) 55 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 56 , syncTimer(this, &PageClientQWidget::syncLayers) 57 , platformLayerProxy(0) 58 #endif 59 { 60 Q_ASSERT(view); 61 } 62 virtual ~PageClientQWidget(); 63 64 virtual bool isQWidgetClient() const { return true; } 65 66 virtual void scroll(int dx, int dy, const QRect&); 67 virtual void update(const QRect& dirtyRect); 68 virtual void setInputMethodEnabled(bool enable); 69 virtual bool inputMethodEnabled() const; 70 virtual void setInputMethodHints(Qt::InputMethodHints hints); 71 72 #ifndef QT_NO_CURSOR 73 virtual QCursor cursor() const; 74 virtual void updateCursor(const QCursor& cursor); 75 #endif 76 77 virtual QPalette palette() const; 78 virtual int screenNumber() const; 79 virtual QWidget* ownerWidget() const; 80 virtual QRect geometryRelativeToOwnerWidget() const; 81 82 virtual QObject* pluginParent() const; 83 84 virtual QStyle* style() const; 85 86 virtual bool viewResizesToContentsEnabled() const { return false; } 87 88 virtual QRectF windowRect() const; 89 90 QWidget* view; 91 QWebPage* page; 92 93 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 94 virtual void setRootGraphicsLayer(TextureMapperPlatformLayer* layer); 95 virtual void markForSync(bool scheduleSync); 96 void syncLayers(Timer<PageClientQWidget>*); 97 #endif 98 99 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 100 virtual bool allowsAcceleratedCompositing() const { return true; } 101 #else 102 virtual bool allowsAcceleratedCompositing() const { return false; } 103 #endif 104 105 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) 106 Timer<PageClientQWidget> syncTimer; 107 PlatformLayerProxyQt* platformLayerProxy; 108 #endif 109 }; 110 111 #if !defined(QT_NO_GRAPHICSVIEW) 112 // the overlay is here for one reason only: to have the scroll-bars and other 113 // extra UI elements appear on top of any QGraphicsItems created by CSS compositing layers 114 class QGraphicsItemOverlay : public QGraphicsObject { 115 public: 116 QGraphicsItemOverlay(QGraphicsWidget* view, QWebPage* p) 117 :QGraphicsObject(view) 118 , q(view) 119 , page(p) 120 { 121 setPos(0, 0); 122 setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); 123 setCacheMode(QGraphicsItem::DeviceCoordinateCache); 124 } 125 126 QRectF boundingRect() const 127 { 128 return q->boundingRect(); 129 } 130 131 void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*) 132 { 133 page->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect()); 134 } 135 136 void prepareGraphicsItemGeometryChange() 137 { 138 prepareGeometryChange(); 139 } 140 141 QGraphicsWidget* q; 142 QWebPage* page; 143 }; 144 145 146 class PageClientQGraphicsWidget : public QWebPageClient { 147 public: 148 PageClientQGraphicsWidget(QGraphicsWebView* newView, QWebPage* newPage) 149 : view(newView) 150 , page(newPage) 151 , viewResizesToContents(false) 152 #if USE(ACCELERATED_COMPOSITING) 153 #if USE(TEXTURE_MAPPER) 154 , platformLayerProxy(0) 155 #endif 156 , shouldSync(false) 157 #endif 158 , overlay(0) 159 { 160 Q_ASSERT(view); 161 #if USE(ACCELERATED_COMPOSITING) 162 // the overlay and stays alive for the lifetime of 163 // this QGraphicsWebView as the scrollbars are needed when there's no compositing 164 view->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); 165 syncMetaMethod = view->metaObject()->method(view->metaObject()->indexOfMethod("syncLayers()")); 166 #endif 167 } 168 169 virtual ~PageClientQGraphicsWidget(); 170 171 virtual bool isQWidgetClient() const { return false; } 172 173 virtual void scroll(int dx, int dy, const QRect&); 174 virtual void update(const QRect& dirtyRect); 175 virtual void setInputMethodEnabled(bool enable); 176 virtual bool inputMethodEnabled() const; 177 virtual void setInputMethodHints(Qt::InputMethodHints hints); 178 179 #ifndef QT_NO_CURSOR 180 virtual QCursor cursor() const; 181 virtual void updateCursor(const QCursor& cursor); 182 #endif 183 184 virtual QPalette palette() const; 185 virtual int screenNumber() const; 186 virtual QWidget* ownerWidget() const; 187 virtual QRect geometryRelativeToOwnerWidget() const; 188 189 virtual QObject* pluginParent() const; 190 191 virtual QStyle* style() const; 192 193 virtual bool viewResizesToContentsEnabled() const { return viewResizesToContents; } 194 195 void createOrDeleteOverlay(); 196 197 #if ENABLE(TILED_BACKING_STORE) 198 void updateTiledBackingStoreScale(); 199 virtual QRectF graphicsItemVisibleRect() const; 200 #endif 201 202 #if USE(ACCELERATED_COMPOSITING) 203 virtual void setRootGraphicsLayer(PlatformLayer* layer); 204 virtual void markForSync(bool scheduleSync); 205 void syncLayers(); 206 207 // QGraphicsWebView can render composited layers 208 virtual bool allowsAcceleratedCompositing() const { return true; } 209 #endif 210 211 virtual QRectF windowRect() const; 212 213 QGraphicsWebView* view; 214 QWebPage* page; 215 bool viewResizesToContents; 216 217 #if USE(ACCELERATED_COMPOSITING) 218 #if USE(TEXTURE_MAPPER) 219 PlatformLayerProxyQt* platformLayerProxy; 220 #else 221 QWeakPointer<QGraphicsObject> rootGraphicsLayer; 222 #endif 223 // we have to flush quite often, so we use a meta-method instead of QTimer::singleShot for putting the event in the queue 224 QMetaMethod syncMetaMethod; 225 226 // we need to sync the layers if we get a special call from the WebCore 227 // compositor telling us to do so. We'll get that call from ChromeClientQt 228 bool shouldSync; 229 #endif 230 // the overlay gets instantiated when the root layer is attached, and get deleted when it's detached 231 QGraphicsItemOverlay* overlay; 232 233 // we need to put the root graphics layer behind the overlay (which contains the scrollbar) 234 enum { RootGraphicsLayerZValue, OverlayZValue }; 235 }; 236 #endif // QT_NO_GRAPHICSVIEW 237 238 } 239 #endif // PageClientQt 240