Changeset 59152 in webkit
- Timestamp:
- May 11, 2010 8:45:27 AM (14 years ago)
- Location:
- trunk/WebKit/qt
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/qt/Api/qgraphicswebview.cpp
r59057 r59152 26 26 #include "qwebpage.h" 27 27 #include "qwebpage_p.h" 28 #include " QWebPageClient.h"28 #include "PageClientQt.h" 29 29 #include "FrameView.h" 30 30 #include "GraphicsContext.h" … … 47 47 #include <Settings.h> 48 48 49 // the overlay is here for one reason only: to have the scroll-bars and other 50 // extra UI elements appear on top of any QGraphicsItems created by CSS compositing layers 51 class QGraphicsWebViewOverlay : public QGraphicsItem { 52 public: 53 QGraphicsWebViewOverlay(QGraphicsWebView* view) 54 :QGraphicsItem(view) 55 , q(view) 56 { 57 setPos(0, 0); 58 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) 59 setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); 60 #endif 61 setCacheMode(QGraphicsItem::DeviceCoordinateCache); 62 } 63 64 QRectF boundingRect() const 65 { 66 return q->boundingRect(); 67 } 68 69 void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*) 70 { 71 q->page()->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect()); 72 } 73 74 friend class QGraphicsWebView; 75 QGraphicsWebView* q; 76 }; 77 78 class QGraphicsWebViewPrivate : public QWebPageClient { 49 using namespace WebCore; 50 51 class QGraphicsWebViewPrivate { 79 52 public: 80 53 QGraphicsWebViewPrivate(QGraphicsWebView* parent) 81 54 : q(parent) 82 55 , page(0) 83 , resizesToContents(false) 56 , resizesToContents(false) {} 57 58 virtual ~QGraphicsWebViewPrivate() {}; 59 84 60 #if USE(ACCELERATED_COMPOSITING) 85 , shouldSync(false) 86 #endif 87 { 88 #if USE(ACCELERATED_COMPOSITING) 89 // the overlay and stays alive for the lifetime of 90 // this QGraphicsWebView as the scrollbars are needed when there's no compositing 91 q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); 92 syncMetaMethod = q->metaObject()->method(q->metaObject()->indexOfMethod("syncLayers()")); 93 #endif 94 } 95 96 virtual ~QGraphicsWebViewPrivate(); 97 98 virtual void scroll(int dx, int dy, const QRect&); 99 virtual void update(const QRect& dirtyRect); 100 virtual void setInputMethodEnabled(bool enable); 101 virtual bool inputMethodEnabled() const; 102 #if QT_VERSION >= 0x040600 103 virtual void setInputMethodHint(Qt::InputMethodHint hint, bool enable); 104 #endif 105 106 #ifndef QT_NO_CURSOR 107 virtual QCursor cursor() const; 108 virtual void updateCursor(const QCursor& cursor); 109 #endif 110 111 virtual QPalette palette() const; 112 virtual int screenNumber() const; 113 virtual QWidget* ownerWidget() const; 114 virtual QRect geometryRelativeToOwnerWidget() const; 115 116 virtual QObject* pluginParent() const; 117 118 virtual QStyle* style() const; 119 120 #if USE(ACCELERATED_COMPOSITING) 121 virtual void setRootGraphicsLayer(QGraphicsItem* layer); 122 virtual void markForSync(bool scheduleSync); 123 void updateCompositingScrollPosition(); 124 125 // QGraphicsWebView can render composited layers 126 virtual bool allowsAcceleratedCompositing() const { return true; } 61 void syncLayers(); 127 62 #endif 128 63 129 64 void updateResizesToContentsForPage(); 130 65 QRectF graphicsItemVisibleRect() const; 131 #if ENABLE(TILED_BACKING_STORE)132 void updateTiledBackingStoreScale();133 #endif134 135 void createOrDeleteOverlay();136 137 void syncLayers();138 66 139 67 void unsetPageIfExists(); … … 148 76 QGraphicsWebView* q; 149 77 QWebPage* page; 150 151 78 bool resizesToContents; 152 79 153 // the overlay gets instantiated when the root layer is attached, and get deleted when it's detached 154 QSharedPointer<QGraphicsWebViewOverlay> overlay; 155 156 // we need to put the root graphics layer behind the overlay (which contains the scrollbar) 157 enum { RootGraphicsLayerZValue, OverlayZValue }; 80 // Just a convenience to avoid using page->client->overlay always 81 QSharedPointer<QGraphicsItemOverlay> overlay; 82 }; 158 83 159 84 #if USE(ACCELERATED_COMPOSITING) 160 QWeakPointer<QGraphicsObject> rootGraphicsLayer;161 // we need to sync the layers if we get a special call from the WebCore162 // compositor telling us to do so. We'll get that call from ChromeClientQt163 bool shouldSync;164 165 // we have to flush quite often, so we use a meta-method instead of QTimer::singleShot for putting the event in the queue166 QMetaMethod syncMetaMethod;167 #endif168 };169 170 QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate()171 {172 #if USE(ACCELERATED_COMPOSITING)173 if (!rootGraphicsLayer)174 return;175 // we don't need to delete the root graphics layer. The lifecycle is managed in GraphicsLayerQt.cpp.176 rootGraphicsLayer.data()->setParentItem(0);177 q->scene()->removeItem(rootGraphicsLayer.data());178 #endif179 }180 181 void QGraphicsWebViewPrivate::createOrDeleteOverlay()182 {183 bool useOverlay = false;184 if (!resizesToContents) {185 #if USE(ACCELERATED_COMPOSITING)186 useOverlay = useOverlay || rootGraphicsLayer;187 #endif188 #if ENABLE(TILED_BACKING_STORE)189 useOverlay = useOverlay || QWebFramePrivate::core(q->page()->mainFrame())->tiledBackingStore();190 #endif191 }192 if (useOverlay == !!overlay)193 return;194 if (useOverlay) {195 overlay = QSharedPointer<QGraphicsWebViewOverlay>(new QGraphicsWebViewOverlay(q));196 overlay->setZValue(OverlayZValue);197 } else198 overlay.clear();199 }200 201 #if USE(ACCELERATED_COMPOSITING)202 void QGraphicsWebViewPrivate::setRootGraphicsLayer(QGraphicsItem* layer)203 {204 if (rootGraphicsLayer) {205 rootGraphicsLayer.data()->setParentItem(0);206 q->scene()->removeItem(rootGraphicsLayer.data());207 QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive();208 }209 210 rootGraphicsLayer = layer ? layer->toGraphicsObject() : 0;211 212 if (layer) {213 layer->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);214 layer->setParentItem(q);215 layer->setZValue(RootGraphicsLayerZValue);216 updateCompositingScrollPosition();217 }218 createOrDeleteOverlay();219 }220 221 void QGraphicsWebViewPrivate::markForSync(bool scheduleSync)222 {223 shouldSync = true;224 if (scheduleSync)225 syncMetaMethod.invoke(q, Qt::QueuedConnection);226 }227 228 void QGraphicsWebViewPrivate::updateCompositingScrollPosition()229 {230 if (rootGraphicsLayer && q->page() && q->page()->mainFrame()) {231 const QPoint scrollPosition = q->page()->mainFrame()->scrollPosition();232 rootGraphicsLayer.data()->setPos(-scrollPosition);233 }234 }235 #endif236 237 85 void QGraphicsWebViewPrivate::syncLayers() 238 86 { 239 #if USE(ACCELERATED_COMPOSITING) 240 if (shouldSync) { 241 QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive(); 242 shouldSync = false; 243 } 244 #endif 245 } 87 static_cast<PageClientQGraphicsWidget*>(page->d->client)->syncLayers(); 88 } 89 #endif 246 90 247 91 void QGraphicsWebViewPrivate::_q_doLoadFinished(bool success) … … 274 118 } 275 119 276 void QGraphicsWebViewPrivate::scroll(int dx, int dy, const QRect& rectToScroll)277 {278 q->scroll(qreal(dx), qreal(dy), QRectF(rectToScroll));279 280 #if USE(ACCELERATED_COMPOSITING)281 updateCompositingScrollPosition();282 #endif283 }284 285 void QGraphicsWebViewPrivate::update(const QRect & dirtyRect)286 {287 q->update(QRectF(dirtyRect));288 289 createOrDeleteOverlay();290 if (overlay)291 overlay->update(QRectF(dirtyRect));292 #if USE(ACCELERATED_COMPOSITING)293 updateCompositingScrollPosition();294 syncLayers();295 #endif296 }297 298 299 void QGraphicsWebViewPrivate::setInputMethodEnabled(bool enable)300 {301 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)302 q->setFlag(QGraphicsItem::ItemAcceptsInputMethod, enable);303 #endif304 }305 306 bool QGraphicsWebViewPrivate::inputMethodEnabled() const307 {308 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)309 return q->flags() & QGraphicsItem::ItemAcceptsInputMethod;310 #else311 return false;312 #endif313 }314 315 #if QT_VERSION >= 0x040600316 void QGraphicsWebViewPrivate::setInputMethodHint(Qt::InputMethodHint hint, bool enable)317 {318 if (enable)319 q->setInputMethodHints(q->inputMethodHints() | hint);320 else321 q->setInputMethodHints(q->inputMethodHints() & ~hint);322 }323 #endif324 #ifndef QT_NO_CURSOR325 QCursor QGraphicsWebViewPrivate::cursor() const326 {327 return q->cursor();328 }329 330 void QGraphicsWebViewPrivate::updateCursor(const QCursor& cursor)331 {332 q->setCursor(cursor);333 }334 #endif335 336 QPalette QGraphicsWebViewPrivate::palette() const337 {338 return q->palette();339 }340 341 int QGraphicsWebViewPrivate::screenNumber() const342 {343 #if defined(Q_WS_X11)344 if (QGraphicsScene* scene = q->scene()) {345 const QList<QGraphicsView*> views = scene->views();346 347 if (!views.isEmpty())348 return views.at(0)->x11Info().screen();349 }350 #endif351 352 return 0;353 }354 355 QWidget* QGraphicsWebViewPrivate::ownerWidget() const356 {357 if (QGraphicsScene* scene = q->scene()) {358 const QList<QGraphicsView*> views = scene->views();359 return views.value(0);360 }361 return 0;362 }363 364 QRect QGraphicsWebViewPrivate::geometryRelativeToOwnerWidget() const365 {366 if (!q->scene())367 return QRect();368 369 QList<QGraphicsView*> views = q->scene()->views();370 if (views.isEmpty())371 return QRect();372 373 QGraphicsView* view = views.at(0);374 return view->mapFromScene(q->boundingRect()).boundingRect();375 }376 377 QObject* QGraphicsWebViewPrivate::pluginParent() const378 {379 return q;380 }381 382 QStyle* QGraphicsWebViewPrivate::style() const383 {384 return q->style();385 }386 387 120 void QGraphicsWebViewPrivate::updateResizesToContentsForPage() 388 121 { … … 417 150 { 418 151 #if ENABLE(TILED_BACKING_STORE) 419 updateTiledBackingStoreScale();152 static_cast<PageClientQGraphicsWidget*>(page->d->client)->updateTiledBackingStoreScale(); 420 153 #endif 421 154 } … … 439 172 return q->mapRectFromScene(QRectF(QPoint(xPosition, yPosition), views[0]->viewport()->size())); 440 173 } 441 442 #if ENABLE(TILED_BACKING_STORE)443 void QGraphicsWebViewPrivate::updateTiledBackingStoreScale()444 {445 WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page->mainFrame())->tiledBackingStore();446 if (!backingStore)447 return;448 backingStore->setContentsScale(q->scale());449 }450 #endif451 174 452 175 /*! … … 712 435 // FIXME: Add a QEvent::CursorUnset or similar to Qt. 713 436 if (cursor().shape() == Qt::ArrowCursor) 714 d-> resetCursor();437 d->page->d->client->resetCursor(); 715 438 } 716 439 #endif … … 763 486 return; 764 487 765 d->page->d->client = d; // set the page client 488 d->page->d->client = new PageClientQGraphicsWidget(this, page); // set the page client 489 d->overlay = static_cast<PageClientQGraphicsWidget*>(d->page->d->client)->overlay; 766 490 767 491 if (d->overlay) 768 d->overlay->prepareG eometryChange();492 d->overlay->prepareGraphicsItemGeometryChange(); 769 493 770 494 QSize size = geometry().size().toSize(); … … 877 601 { 878 602 if (d->overlay) 879 d->overlay->prepareG eometryChange();603 d->overlay->prepareGraphicsItemGeometryChange(); 880 604 881 605 QGraphicsWidget::updateGeometry(); … … 895 619 896 620 if (d->overlay) 897 d->overlay->prepareG eometryChange();621 d->overlay->prepareGraphicsItemGeometryChange(); 898 622 899 623 if (!d->page) … … 1129 853 return; 1130 854 d->resizesToContents = enabled; 1131 if (d->page) 855 if (d->page) { 856 static_cast<PageClientQGraphicsWidget*>(d->page->d->client)->viewResizesToContents = enabled; 1132 857 d->updateResizesToContentsForPage(); 858 } 1133 859 } 1134 860 -
trunk/WebKit/qt/ChangeLog
r59057 r59152 1 2010-05-11 Jesus Sanchez-Palencia <jesus@webkit.org> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 Add PageClientQGraphicsWidget specific implementation. 6 QGraphicsWebViewPrivate doesn't inherit QWebPageClient anymore 7 and the needed functions were moved to this new PageClient class, 8 including Tiling and Accelerated Composite specific ones. 9 10 [Qt] PageClientQt specific implementation for QGraphicsWidget 11 https://bugs.webkit.org/show_bug.cgi?id=37866 12 13 * Api/qgraphicswebview.cpp: 14 (QGraphicsWebViewPrivate::QGraphicsWebViewPrivate): 15 (QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate): 16 (QGraphicsWebViewPrivate::syncLayers): 17 (QGraphicsWebViewPrivate::_q_scaleChanged): 18 (QGraphicsWebView::event): 19 (QGraphicsWebView::setPage): 20 (QGraphicsWebView::updateGeometry): 21 (QGraphicsWebView::setGeometry): 22 (QGraphicsWebView::setResizesToContents): 23 * WebCoreSupport/PageClientQt.cpp: 24 (WebCore::PageClientQGraphicsWidget::~PageClientQGraphicsWidget): 25 (WebCore::PageClientQGraphicsWidget::scroll): 26 (WebCore::PageClientQGraphicsWidget::update): 27 (WebCore::PageClientQGraphicsWidget::createOrDeleteOverlay): 28 (WebCore::PageClientQGraphicsWidget::syncLayers): 29 (WebCore::PageClientQGraphicsWidget::setRootGraphicsLayer): 30 (WebCore::PageClientQGraphicsWidget::markForSync): 31 (WebCore::PageClientQGraphicsWidget::updateCompositingScrollPosition): 32 (WebCore::PageClientQGraphicsWidget::updateTiledBackingStoreScale): 33 (WebCore::PageClientQGraphicsWidget::setInputMethodEnabled): 34 (WebCore::PageClientQGraphicsWidget::inputMethodEnabled): 35 (WebCore::PageClientQGraphicsWidget::setInputMethodHint): 36 (WebCore::PageClientQGraphicsWidget::cursor): 37 (WebCore::PageClientQGraphicsWidget::updateCursor): 38 (WebCore::PageClientQGraphicsWidget::palette): 39 (WebCore::PageClientQGraphicsWidget::screenNumber): 40 (WebCore::PageClientQGraphicsWidget::ownerWidget): 41 (WebCore::PageClientQGraphicsWidget::geometryRelativeToOwnerWidget): 42 (WebCore::PageClientQGraphicsWidget::pluginParent): 43 (WebCore::PageClientQGraphicsWidget::style): 44 * WebCoreSupport/PageClientQt.h: 45 (WebCore::QGraphicsItemOverlay::page): 46 (WebCore::QGraphicsItemOverlay::boundingRect): 47 (WebCore::QGraphicsItemOverlay::paint): 48 (WebCore::QGraphicsItemOverlay::prepareGraphicsItemGeometryChange): 49 (WebCore::PageClientQGraphicsWidget::PageClientQGraphicsWidget): 50 (WebCore::PageClientQGraphicsWidget::isQWidgetClient): 51 (WebCore::PageClientQGraphicsWidget::allowsAcceleratedCompositing): 52 (WebCore::PageClientQGraphicsWidget::): 53 1 54 2010-05-09 Noam Rosenthal <noam.rosenthal@nokia.com> 2 55 -
trunk/WebKit/qt/WebCoreSupport/PageClientQt.cpp
r58038 r59152 104 104 } 105 105 106 } 106 PageClientQGraphicsWidget::~PageClientQGraphicsWidget() 107 { 108 #if USE(ACCELERATED_COMPOSITING) 109 if (!rootGraphicsLayer) 110 return; 111 // we don't need to delete the root graphics layer. The lifecycle is managed in GraphicsLayerQt.cpp. 112 rootGraphicsLayer.data()->setParentItem(0); 113 view->scene()->removeItem(rootGraphicsLayer.data()); 114 #endif 115 } 116 117 void PageClientQGraphicsWidget::scroll(int dx, int dy, const QRect& rectToScroll) 118 { 119 #if USE(ACCELERATED_COMPOSITING) 120 updateCompositingScrollPosition(); 121 #endif 122 } 123 124 void PageClientQGraphicsWidget::update(const QRect & dirtyRect) 125 { 126 createOrDeleteOverlay(); 127 if (overlay) 128 overlay->update(QRectF(dirtyRect)); 129 #if USE(ACCELERATED_COMPOSITING) 130 syncLayers(); 131 #endif 132 } 133 134 void PageClientQGraphicsWidget::createOrDeleteOverlay() 135 { 136 bool useOverlay = false; 137 if (!viewResizesToContents) { 138 #if USE(ACCELERATED_COMPOSITING) 139 useOverlay = useOverlay || rootGraphicsLayer; 140 #endif 141 #if ENABLE(TILED_BACKING_STORE) 142 useOverlay = useOverlay || QWebFramePrivate::core(page->mainFrame())->tiledBackingStore(); 143 #endif 144 } 145 if (useOverlay == !!overlay) 146 return; 147 if (useOverlay) { 148 overlay = QSharedPointer<QGraphicsItemOverlay>(new QGraphicsItemOverlay(view, page)); 149 overlay->setZValue(OverlayZValue); 150 } else 151 overlay.clear(); 152 } 153 154 #if USE(ACCELERATED_COMPOSITING) 155 void PageClientQGraphicsWidget::syncLayers() 156 { 157 if (shouldSync) { 158 QWebFramePrivate::core(page->mainFrame())->view()->syncCompositingStateRecursive(); 159 shouldSync = false; 160 } 161 } 162 163 void PageClientQGraphicsWidget::setRootGraphicsLayer(QGraphicsItem* layer) 164 { 165 if (rootGraphicsLayer) { 166 rootGraphicsLayer.data()->setParentItem(0); 167 view->scene()->removeItem(rootGraphicsLayer.data()); 168 QWebFramePrivate::core(page->mainFrame())->view()->syncCompositingStateRecursive(); 169 } 170 171 rootGraphicsLayer = layer ? layer->toGraphicsObject() : 0; 172 173 if (layer) { 174 layer->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); 175 layer->setParentItem(view); 176 layer->setZValue(RootGraphicsLayerZValue); 177 updateCompositingScrollPosition(); 178 } 179 createOrDeleteOverlay(); 180 } 181 182 void PageClientQGraphicsWidget::markForSync(bool scheduleSync) 183 { 184 shouldSync = true; 185 if (scheduleSync) 186 syncMetaMethod.invoke(view, Qt::QueuedConnection); 187 } 188 189 void PageClientQGraphicsWidget::updateCompositingScrollPosition() 190 { 191 if (rootGraphicsLayer && page && page->mainFrame()) { 192 const QPoint scrollPosition = page->mainFrame()->scrollPosition(); 193 rootGraphicsLayer.data()->setPos(-scrollPosition); 194 } 195 } 196 #endif 197 198 #if ENABLE(TILED_BACKING_STORE) 199 void PageClientQGraphicsWidget::updateTiledBackingStoreScale() 200 { 201 WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page->mainFrame())->tiledBackingStore(); 202 if (!backingStore) 203 return; 204 backingStore->setContentsScale(view->scale()); 205 } 206 #endif 207 208 void PageClientQGraphicsWidget::setInputMethodEnabled(bool enable) 209 { 210 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) 211 view->setFlag(QGraphicsItem::ItemAcceptsInputMethod, enable); 212 #endif 213 } 214 215 bool PageClientQGraphicsWidget::inputMethodEnabled() const 216 { 217 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) 218 return view->flags() & QGraphicsItem::ItemAcceptsInputMethod; 219 #else 220 return false; 221 #endif 222 } 223 224 #if QT_VERSION >= 0x040600 225 void PageClientQGraphicsWidget::setInputMethodHint(Qt::InputMethodHint hint, bool enable) 226 { 227 if (enable) 228 view->setInputMethodHints(view->inputMethodHints() | hint); 229 else 230 view->setInputMethodHints(view->inputMethodHints() & ~hint); 231 } 232 #endif 233 234 #ifndef QT_NO_CURSOR 235 QCursor PageClientQGraphicsWidget::cursor() const 236 { 237 return view->cursor(); 238 } 239 240 void PageClientQGraphicsWidget::updateCursor(const QCursor& cursor) 241 { 242 view->setCursor(cursor); 243 } 244 #endif 245 246 QPalette PageClientQGraphicsWidget::palette() const 247 { 248 return view->palette(); 249 } 250 251 int PageClientQGraphicsWidget::screenNumber() const 252 { 253 #if defined(Q_WS_X11) 254 if (QGraphicsScene* scene = view->scene()) { 255 const QList<QGraphicsView*> views = scene->views(); 256 257 if (!views.isEmpty()) 258 return views.at(0)->x11Info().screen(); 259 } 260 #endif 261 262 return 0; 263 } 264 265 QWidget* PageClientQGraphicsWidget::ownerWidget() const 266 { 267 if (QGraphicsScene* scene = view->scene()) { 268 const QList<QGraphicsView*> views = scene->views(); 269 return views.value(0); 270 } 271 return 0; 272 } 273 274 QRect PageClientQGraphicsWidget::geometryRelativeToOwnerWidget() const 275 { 276 if (!view->scene()) 277 return QRect(); 278 279 QList<QGraphicsView*> views = view->scene()->views(); 280 if (views.isEmpty()) 281 return QRect(); 282 283 QGraphicsView* graphicsView = views.at(0); 284 return graphicsView->mapFromScene(view->boundingRect()).boundingRect(); 285 } 286 287 QObject* PageClientQGraphicsWidget::pluginParent() const 288 { 289 return view; 290 } 291 292 QStyle* PageClientQGraphicsWidget::style() const 293 { 294 return view->style(); 295 } 296 297 298 299 } -
trunk/WebKit/qt/WebCoreSupport/PageClientQt.h
r58038 r59152 22 22 #define PageClientQt_h 23 23 24 #include "FrameView.h" 25 #include "GraphicsContext.h" 26 #include "IntRect.h" 27 #include "qwebframe.h" 28 #include "qwebframe_p.h" 29 #include "qwebpage.h" 30 #include "qwebpage_p.h" 24 31 #include "QWebPageClient.h" 25 32 #include "TiledBackingStore.h" 33 34 #include <QtCore/qmetaobject.h> 35 #include <QtCore/qsharedpointer.h> 36 #include <QtGui/qgraphicsscene.h> 37 #include <QtGui/qgraphicsview.h> 38 #include <QtGui/qgraphicswidget.h> 39 #include <QtGui/qscrollbar.h> 40 #include <QtGui/qstyleoption.h> 26 41 #include <QtGui/qwidget.h> 42 43 #include <Settings.h> 27 44 28 45 … … 64 81 }; 65 82 83 // the overlay is here for one reason only: to have the scroll-bars and other 84 // extra UI elements appear on top of any QGraphicsItems created by CSS compositing layers 85 class QGraphicsItemOverlay : public QGraphicsItem { 86 public: 87 QGraphicsItemOverlay(QGraphicsWidget* view, QWebPage* p) 88 :QGraphicsItem(view) 89 , q(view) 90 , page(p) 91 { 92 setPos(0, 0); 93 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) 94 setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); 95 #endif 96 setCacheMode(QGraphicsItem::DeviceCoordinateCache); 97 } 98 99 QRectF boundingRect() const 100 { 101 return q->boundingRect(); 102 } 103 104 void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*) 105 { 106 page->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect()); 107 } 108 109 void prepareGraphicsItemGeometryChange() 110 { 111 prepareGeometryChange(); 112 } 113 114 friend class QGraphicsWidget; 115 QGraphicsWidget* q; 116 QWebPage* page; 117 }; 118 119 120 class PageClientQGraphicsWidget : public QWebPageClient { 121 public: 122 PageClientQGraphicsWidget(QGraphicsWidget* v, QWebPage* p) 123 : view(v) 124 , page(p) 125 , viewResizesToContents(false) 126 #if USE(ACCELERATED_COMPOSITING) 127 , shouldSync(false) 128 #endif 129 { 130 Q_ASSERT(view); 131 #if USE(ACCELERATED_COMPOSITING) 132 // the overlay and stays alive for the lifetime of 133 // this QGraphicsWebView as the scrollbars are needed when there's no compositing 134 view->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); 135 syncMetaMethod = view->metaObject()->method(view->metaObject()->indexOfMethod("syncLayers()")); 136 #endif 137 } 138 139 virtual ~PageClientQGraphicsWidget(); 140 141 virtual bool isQWidgetClient() const { return false; } 142 143 virtual void scroll(int dx, int dy, const QRect&); 144 virtual void update(const QRect& dirtyRect); 145 virtual void setInputMethodEnabled(bool enable); 146 virtual bool inputMethodEnabled() const; 147 #if QT_VERSION >= 0x040600 148 virtual void setInputMethodHint(Qt::InputMethodHint hint, bool enable); 149 #endif 150 151 #ifndef QT_NO_CURSOR 152 virtual QCursor cursor() const; 153 virtual void updateCursor(const QCursor& cursor); 154 #endif 155 156 virtual QPalette palette() const; 157 virtual int screenNumber() const; 158 virtual QWidget* ownerWidget() const; 159 virtual QRect geometryRelativeToOwnerWidget() const; 160 161 virtual QObject* pluginParent() const; 162 163 virtual QStyle* style() const; 164 165 void createOrDeleteOverlay(); 166 167 #if ENABLE(TILED_BACKING_STORE) 168 void updateTiledBackingStoreScale(); 169 #endif 170 171 #if USE(ACCELERATED_COMPOSITING) 172 virtual void setRootGraphicsLayer(QGraphicsItem* layer); 173 virtual void markForSync(bool scheduleSync); 174 void updateCompositingScrollPosition(); 175 void syncLayers(); 176 177 // QGraphicsWebView can render composited layers 178 virtual bool allowsAcceleratedCompositing() const { return true; } 179 #endif 180 181 QGraphicsWidget* view; 182 QWebPage* page; 183 bool viewResizesToContents; 184 185 #if USE(ACCELERATED_COMPOSITING) 186 QWeakPointer<QGraphicsObject> rootGraphicsLayer; 187 188 // we have to flush quite often, so we use a meta-method instead of QTimer::singleShot for putting the event in the queue 189 QMetaMethod syncMetaMethod; 190 191 // we need to sync the layers if we get a special call from the WebCore 192 // compositor telling us to do so. We'll get that call from ChromeClientQt 193 bool shouldSync; 194 #endif 195 // the overlay gets instantiated when the root layer is attached, and get deleted when it's detached 196 QSharedPointer<QGraphicsItemOverlay> overlay; 197 198 // we need to put the root graphics layer behind the overlay (which contains the scrollbar) 199 enum { RootGraphicsLayerZValue, OverlayZValue }; 200 }; 201 66 202 } 67 203 #endif // PageClientQt
Note: See TracChangeset
for help on using the changeset viewer.