diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-09-09 15:21:23 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-27 19:28:35 +0200 |
commit | a3eaa1530feed293f966bb2a886d9efb6bed5f44 (patch) | |
tree | e5f22ddb66270598a86e43728be96608a2de091d /lib/quick | |
parent | b7dc59562ccd44c57114415b6a121f04f84a40a3 (diff) |
Ground work for splitting RenderWidgetHostViewQtDelegateQuick.
This prepares the addition of a delegated renderer implementation
for the QtQuick view.
Use a template for the base class since the accelerated delegate
will derive from QQuickItem instead of QQuickPaintedItem.
Change-Id: I5619290c0023bafdd27f18dab9edc10f5fbbf838
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'lib/quick')
-rw-r--r-- | lib/quick/qquickwebengineview.cpp | 4 | ||||
-rw-r--r-- | lib/quick/qquickwebengineview_p_p.h | 4 | ||||
-rw-r--r-- | lib/quick/render_widget_host_view_qt_delegate_quick.cpp | 133 | ||||
-rw-r--r-- | lib/quick/render_widget_host_view_qt_delegate_quick.h | 168 |
4 files changed, 141 insertions, 168 deletions
diff --git a/lib/quick/qquickwebengineview.cpp b/lib/quick/qquickwebengineview.cpp index 3856cbb8e..708a7ecb6 100644 --- a/lib/quick/qquickwebengineview.cpp +++ b/lib/quick/qquickwebengineview.cpp @@ -57,7 +57,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHostViewQtDelegate(CompositingMode) { - return new RenderWidgetHostViewQtDelegateQuick; + return new RenderWidgetHostViewQtDelegateQuickPainted; } void QQuickWebEngineViewPrivate::titleChanged(const QString &title) @@ -180,7 +180,7 @@ void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRect QQuickItem::geometryChanged(newGeometry, oldGeometry); Q_FOREACH(QQuickItem *child, childItems()) { - Q_ASSERT(qobject_cast<RenderWidgetHostViewQtDelegateQuick *>(child)); + Q_ASSERT(qobject_cast<RenderWidgetHostViewQtDelegateQuickPainted *>(child)); child->setSize(newGeometry.size()); } } diff --git a/lib/quick/qquickwebengineview_p_p.h b/lib/quick/qquickwebengineview_p_p.h index 7ea45f2fe..9831fa0f3 100644 --- a/lib/quick/qquickwebengineview_p_p.h +++ b/lib/quick/qquickwebengineview_p_p.h @@ -47,7 +47,6 @@ #include <QSharedData> #include <QtQuick/private/qquickitem_p.h> -class RenderWidgetHostViewQtDelegateQuick; class WebContentsAdapter; QT_BEGIN_NAMESPACE @@ -55,8 +54,8 @@ class QQuickWebEngineView; class QQuickWebEngineViewPrivate : public QQuickItemPrivate, public WebContentsAdapterClient { - Q_DECLARE_PUBLIC(QQuickWebEngineView) public: + Q_DECLARE_PUBLIC(QQuickWebEngineView) QQuickWebEngineViewPrivate(); virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(CompositingMode mode) Q_DECL_OVERRIDE; @@ -69,7 +68,6 @@ public: virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition) Q_DECL_OVERRIDE; QExplicitlySharedDataPointer<WebContentsAdapter> adapter; - friend class ::RenderWidgetHostViewQtDelegateQuick; }; QT_END_NAMESPACE diff --git a/lib/quick/render_widget_host_view_qt_delegate_quick.cpp b/lib/quick/render_widget_host_view_qt_delegate_quick.cpp index 1a6759ff1..6f8243690 100644 --- a/lib/quick/render_widget_host_view_qt_delegate_quick.cpp +++ b/lib/quick/render_widget_host_view_qt_delegate_quick.cpp @@ -41,56 +41,12 @@ #include "render_widget_host_view_qt_delegate_quick.h" -#include "qquickwebengineview_p.h" -#include "qquickwebengineview_p_p.h" -#include <QQuickWindow> -#include <QWindow> - -RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(QQuickItem *parent) - : QQuickPaintedItem(parent) -{ - setAcceptedMouseButtons(Qt::AllButtons); - setAcceptHoverEvents(true); -} - -void RenderWidgetHostViewQtDelegateQuick::initAsChild(WebContentsAdapterClient* container) -{ - QQuickWebEngineViewPrivate *viewPrivate = static_cast<QQuickWebEngineViewPrivate *>(container); - setParentItem(viewPrivate->q_func()); -} - -QRectF RenderWidgetHostViewQtDelegateQuick::screenRect() const -{ - QPointF pos = mapToScene(QPointF(0,0)); - return QRectF(pos.x(), pos.y(), width(), height()); -} - -void RenderWidgetHostViewQtDelegateQuick::setKeyboardFocus() -{ - setFocus(true); -} - -bool RenderWidgetHostViewQtDelegateQuick::hasKeyboardFocus() -{ - return hasFocus(); -} - -void RenderWidgetHostViewQtDelegateQuick::show() -{ - setVisible(true); -} - -void RenderWidgetHostViewQtDelegateQuick::hide() -{ - setVisible(false); -} - -bool RenderWidgetHostViewQtDelegateQuick::isVisible() const +RenderWidgetHostViewQtDelegateQuickPainted::RenderWidgetHostViewQtDelegateQuickPainted(QQuickItem *parent) + : RenderWidgetHostViewQtDelegateQuickBase<QQuickPaintedItem>(parent) { - return QQuickPaintedItem::isVisible(); } -WId RenderWidgetHostViewQtDelegateQuick::nativeWindowIdForCompositor() const +WId RenderWidgetHostViewQtDelegateQuickPainted::nativeWindowIdForCompositor() const { // Only used to enable accelerated compositing by the compositor // directly on our native window, which we want to eventually do @@ -98,98 +54,21 @@ WId RenderWidgetHostViewQtDelegateQuick::nativeWindowIdForCompositor() const return 0; } -QWindow* RenderWidgetHostViewQtDelegateQuick::window() const -{ - return QQuickPaintedItem::window(); -} - -void RenderWidgetHostViewQtDelegateQuick::update(const QRect& rect) +void RenderWidgetHostViewQtDelegateQuickPainted::update(const QRect& rect) { polish(); QQuickPaintedItem::update(rect); } -void RenderWidgetHostViewQtDelegateQuick::updateCursor(const QCursor &cursor) -{ - QQuickPaintedItem::setCursor(cursor); -} - -void RenderWidgetHostViewQtDelegateQuick::resize(int width, int height) -{ - setSize(QSizeF(width, height)); -} - -void RenderWidgetHostViewQtDelegateQuick::paint(QPainter *painter) +void RenderWidgetHostViewQtDelegateQuickPainted::paint(QPainter *painter) { RenderWidgetHostViewQtDelegate::paint(painter, boundingRect()); } -void RenderWidgetHostViewQtDelegateQuick::updatePolish() +void RenderWidgetHostViewQtDelegateQuickPainted::updatePolish() { // paint will be called from the scene graph thread and this doesn't play well // with chromium's use of TLS while getting the backing store. // updatePolish() should be called from the GUI thread right before the rendering thread starts. fetchBackingStore(); } - -void RenderWidgetHostViewQtDelegateQuick::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); - notifyResize(); -} - -void RenderWidgetHostViewQtDelegateQuick::focusInEvent(QFocusEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::focusOutEvent(QFocusEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::mousePressEvent(QMouseEvent *event) -{ - setFocus(true); - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::mouseMoveEvent(QMouseEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::mouseReleaseEvent(QMouseEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::mouseDoubleClickEvent(QMouseEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::keyPressEvent(QKeyEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::keyReleaseEvent(QKeyEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::wheelEvent(QWheelEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::touchEvent(QTouchEvent *event) -{ - forwardEvent(event); -} - -void RenderWidgetHostViewQtDelegateQuick::hoverMoveEvent(QHoverEvent *event) -{ - forwardEvent(event); -} diff --git a/lib/quick/render_widget_host_view_qt_delegate_quick.h b/lib/quick/render_widget_host_view_qt_delegate_quick.h index b90cc1971..67c38a75d 100644 --- a/lib/quick/render_widget_host_view_qt_delegate_quick.h +++ b/lib/quick/render_widget_host_view_qt_delegate_quick.h @@ -53,56 +53,152 @@ #include "render_widget_host_view_qt_delegate.h" +#include "qquickwebengineview_p.h" +#include "qquickwebengineview_p_p.h" #include <QQuickPaintedItem> +#include <QQuickWindow> +#include <QWindow> -class BackingStoreQt; +template<typename ItemBaseT> +class RenderWidgetHostViewQtDelegateQuickBase : public ItemBaseT, public RenderWidgetHostViewQtDelegate +{ +public: + RenderWidgetHostViewQtDelegateQuickBase(QQuickItem *parent = 0) + : ItemBaseT(parent) + { + this->setAcceptedMouseButtons(Qt::AllButtons); + this->setAcceptHoverEvents(true); + } + + virtual void initAsChild(WebContentsAdapterClient* container) + { + QQuickWebEngineViewPrivate *viewPrivate = static_cast<QQuickWebEngineViewPrivate *>(container); + this->setParentItem(viewPrivate->q_func()); + } + + virtual QRectF screenRect() const + { + QPointF pos = this->mapToScene(QPointF(0,0)); + return QRectF(pos.x(), pos.y(), this->width(), this->height()); + } + + virtual void setKeyboardFocus() + { + this->setFocus(true); + } + + virtual bool hasKeyboardFocus() + { + return this->hasFocus(); + } + + virtual void show() + { + this->setVisible(true); + } + + virtual void hide() + { + this->setVisible(false); + } + + virtual bool isVisible() const + { + return ItemBaseT::isVisible(); + } + + virtual QWindow* window() const + { + return ItemBaseT::window(); + } + + virtual void updateCursor(const QCursor &cursor) + { + this->setCursor(cursor); + } + + virtual void resize(int width, int height) + { + this->setSize(QSizeF(width, height)); + } + + void focusInEvent(QFocusEvent *event) + { + forwardEvent(event); + } + + void focusOutEvent(QFocusEvent *event) + { + forwardEvent(event); + } -QT_BEGIN_NAMESPACE -class QWindow; -class QQuickItem; -class QFocusEvent; -class QMouseEvent; -class QKeyEvent; -class QWheelEvent; -QT_END_NAMESPACE + void mousePressEvent(QMouseEvent *event) + { + this->setFocus(true); + forwardEvent(event); + } -class RenderWidgetHostViewQtDelegateQuick : public QQuickPaintedItem, public RenderWidgetHostViewQtDelegate + void mouseMoveEvent(QMouseEvent *event) + { + forwardEvent(event); + } + + void mouseReleaseEvent(QMouseEvent *event) + { + forwardEvent(event); + } + + void mouseDoubleClickEvent(QMouseEvent *event) + { + forwardEvent(event); + } + + void keyPressEvent(QKeyEvent *event) + { + forwardEvent(event); + } + + void keyReleaseEvent(QKeyEvent *event) + { + forwardEvent(event); + } + + void wheelEvent(QWheelEvent *event) + { + forwardEvent(event); + } + + void touchEvent(QTouchEvent *event) + { + forwardEvent(event); + } + + void hoverMoveEvent(QHoverEvent *event) + { + forwardEvent(event); + } + +protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) + { + ItemBaseT::geometryChanged(newGeometry, oldGeometry); + notifyResize(); + } +}; + +class RenderWidgetHostViewQtDelegateQuickPainted : public RenderWidgetHostViewQtDelegateQuickBase<QQuickPaintedItem> { Q_OBJECT public: - RenderWidgetHostViewQtDelegateQuick(QQuickItem *parent = 0); - - virtual void initAsChild(WebContentsAdapterClient* container); - virtual QRectF screenRect() const; - virtual void setKeyboardFocus(); - virtual bool hasKeyboardFocus(); - virtual void show(); - virtual void hide(); - virtual bool isVisible() const; + RenderWidgetHostViewQtDelegateQuickPainted(QQuickItem *parent = 0); + virtual WId nativeWindowIdForCompositor() const; - virtual QWindow* window() const; virtual void update(const QRect& rect = QRect()); - virtual void updateCursor(const QCursor &); - virtual void resize(int width, int height); void paint(QPainter *painter); - void focusInEvent(QFocusEvent*); - void focusOutEvent(QFocusEvent*); - void mousePressEvent(QMouseEvent*); - void mouseMoveEvent(QMouseEvent*); - void mouseReleaseEvent(QMouseEvent*); - void mouseDoubleClickEvent(QMouseEvent*); - void keyPressEvent(QKeyEvent*); - void keyReleaseEvent(QKeyEvent*); - void wheelEvent(QWheelEvent*); - void touchEvent(QTouchEvent*); - void hoverMoveEvent(QHoverEvent*); - protected: void updatePolish(); - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - }; #endif |