From 84f31c11b77a62212451cb77adae63219e06de96 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Tue, 1 Apr 2014 10:27:13 +0200 Subject: Revert part of the RenderWidgetHostViewQtDelegate refactoring This reverts parts of commit 9c198939be1ef064d1a2430a4b9991f2fe16f359. This does keeps the popup fixes and removes support for QWebEnginePage::setViewportSize and QWebEnginePage::render until we can evaluate the needs vs the cost of such feature. Change-Id: I1b55b751d463717b1462393ea8cd353422f8fdbb Reviewed-by: Simon Hausmann --- src/core/backing_store_qt.cpp | 3 +- src/core/render_widget_host_view_qt.cpp | 6 +- src/core/type_conversion.h | 5 + src/core/web_contents_adapter.cpp | 7 + src/core/web_contents_adapter.h | 1 + src/core/web_contents_adapter_client.h | 1 + src/core/web_contents_view_qt.cpp | 3 + src/webengine/api/qquickwebengineview.cpp | 10 +- src/webengine/api/qquickwebengineview_p_p.h | 1 + ...er_widget_host_view_qt_delegate_quickwindow.cpp | 20 +-- ...nder_widget_host_view_qt_delegate_quickwindow.h | 5 +- src/webenginewidgets/api/qwebenginepage.cpp | 81 ++------- src/webenginewidgets/api/qwebenginepage_p.h | 5 +- src/webenginewidgets/api/qwebengineview.cpp | 37 +--- src/webenginewidgets/api/qwebengineview.h | 2 - .../render_widget_host_view_qt_delegate_popup.cpp | 164 ----------------- .../render_widget_host_view_qt_delegate_popup.h | 89 ---------- ...render_widget_host_view_qt_delegate_webpage.cpp | 162 ----------------- .../render_widget_host_view_qt_delegate_webpage.h | 94 ---------- .../render_widget_host_view_qt_delegate_widget.cpp | 194 +++++++++++++++++++++ .../render_widget_host_view_qt_delegate_widget.h | 90 ++++++++++ src/webenginewidgets/webenginewidgets.pro | 6 +- 22 files changed, 344 insertions(+), 642 deletions(-) delete mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp delete mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h delete mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp delete mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h create mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp create mode 100644 src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h (limited to 'src') diff --git a/src/core/backing_store_qt.cpp b/src/core/backing_store_qt.cpp index fda60d094..613dfdbbc 100644 --- a/src/core/backing_store_qt.cpp +++ b/src/core/backing_store_qt.cpp @@ -70,12 +70,11 @@ BackingStoreQt::~BackingStoreQt() { } -void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& clipRect) +void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& rect) { if (m_pixelBuffer.isNull()) return; - QRectF rect = clipRect.isNull() ? m_pixelBuffer.rect() : clipRect; qreal x = rect.x() * m_deviceScaleFactor; qreal y = rect.y() * m_deviceScaleFactor; qreal w = rect.width() * m_deviceScaleFactor; diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index f04a2089e..7430f6756 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -218,7 +218,9 @@ void RenderWidgetHostViewQt::InitAsChild(gfx::NativeView) void RenderWidgetHostViewQt::InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect& rect) { - m_delegate->initAsPopup(toQt(rect)); + QRect screenRect = toQt(rect); + screenRect.moveTo(m_adapterClient->mapToGlobal(screenRect.topLeft())); + m_delegate->initAsPopup(screenRect); } void RenderWidgetHostViewQt::InitAsFullscreen(content::RenderWidgetHostView*) @@ -242,7 +244,7 @@ void RenderWidgetHostViewQt::SetBounds(const gfx::Rect& rect) { // This is called when webkit has sent us a Move message. if (IsPopup()) - m_delegate->move(QPoint(rect.x(), rect.y())); + m_delegate->move(m_adapterClient->mapToGlobal(toQt(rect.origin()))); SetSize(rect.size()); } diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h index 5d5dc356d..f00628074 100644 --- a/src/core/type_conversion.h +++ b/src/core/type_conversion.h @@ -89,6 +89,11 @@ inline GURL toGurl(const QUrl& url) return GURL(url.toString().toStdString()); } +inline QPoint toQt(const gfx::Point &point) +{ + return QPoint(point.x(), point.y()); +} + inline QRect toQt(const gfx::Rect &rect) { return QRect(rect.x(), rect.y(), rect.width(), rect.height()); diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 7fbda1ab6..6c3b68b6a 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -383,6 +383,13 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient) } +void WebContentsAdapter::reattachRWHV() +{ + Q_D(WebContentsAdapter); + if (content::RenderWidgetHostView *rwhv = d->webContents->GetRenderWidgetHostView()) + rwhv->InitAsChild(0); +} + bool WebContentsAdapter::canGoBack() const { Q_D(const WebContentsAdapter); diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index 6ce15aa6a..6e274f4e3 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -61,6 +61,7 @@ public: WebContentsAdapter(WebContentsAdapterClient::RenderingMode renderingMode, content::WebContents *webContents = 0); ~WebContentsAdapter(); void initialize(WebContentsAdapterClient *adapterClient); + void reattachRWHV(); bool canGoBack() const; bool canGoForward() const; diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 0cb4e3d10..3a9d9dd93 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -122,6 +122,7 @@ public: virtual void loadProgressChanged(int progress) = 0; virtual void selectionChanged() = 0; virtual QRectF viewportRect() const = 0; + virtual QPoint mapToGlobal(const QPoint &posInView) const = 0; virtual qreal dpiScale() const = 0; virtual void loadStarted(const QUrl &provisionalUrl) = 0; virtual void loadCommitted() = 0; diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp index e3cc5963b..8a9daeec0 100644 --- a/src/core/web_contents_view_qt.cpp +++ b/src/core/web_contents_view_qt.cpp @@ -76,8 +76,11 @@ content::RenderWidgetHostView* WebContentsViewQt::CreateViewForWidget(content::R content::RenderWidgetHostView* WebContentsViewQt::CreateViewForPopupWidget(content::RenderWidgetHost* render_widget_host) { RenderWidgetHostViewQt *view = new RenderWidgetHostViewQt(render_widget_host); + Q_ASSERT(m_client); view->setDelegate(m_client->CreateRenderWidgetHostViewQtDelegateForPopup(view, WebEngineContext::current()->renderingMode())); + view->setAdapterClient(m_client); + return view; } diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index ac19de15d..587d3aa9f 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -133,7 +133,7 @@ RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHo if (mode == HardwareAccelerationMode) { RenderWidgetHostViewQtDelegateQuick *quickDelegate = new RenderWidgetHostViewQtDelegateQuick(client, /*isPopup = */true); if (hasWindowCapability) { - RenderWidgetHostViewQtDelegateQuickWindow *wrapperWindow = new RenderWidgetHostViewQtDelegateQuickWindow(quickDelegate, q); + RenderWidgetHostViewQtDelegateQuickWindow *wrapperWindow = new RenderWidgetHostViewQtDelegateQuickWindow(quickDelegate); quickDelegate->setParentItem(wrapperWindow->contentItem()); return wrapperWindow; } @@ -142,7 +142,7 @@ RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHo } RenderWidgetHostViewQtDelegateQuickPainted *paintedDelegate = new RenderWidgetHostViewQtDelegateQuickPainted(client, /*isPopup = */true); if (hasWindowCapability) { - RenderWidgetHostViewQtDelegateQuickWindow *wrapperWindow = new RenderWidgetHostViewQtDelegateQuickWindow(paintedDelegate, q); + RenderWidgetHostViewQtDelegateQuickWindow *wrapperWindow = new RenderWidgetHostViewQtDelegateQuickWindow(paintedDelegate); paintedDelegate->setParentItem(wrapperWindow->contentItem()); return wrapperWindow; } @@ -252,6 +252,12 @@ QRectF QQuickWebEngineViewPrivate::viewportRect() const return QRectF(q->x(), q->y(), q->width(), q->height()); } +QPoint QQuickWebEngineViewPrivate::mapToGlobal(const QPoint &posInView) const +{ + Q_Q(const QQuickWebEngineView); + return q->window() ? q->window()->mapToGlobal(posInView) : QPoint(); +} + qreal QQuickWebEngineViewPrivate::dpiScale() const { return m_dpiScale; diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index be5318af4..cf9d58e68 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -133,6 +133,7 @@ public: virtual void loadProgressChanged(int progress) Q_DECL_OVERRIDE; virtual void selectionChanged() Q_DECL_OVERRIDE { } virtual QRectF viewportRect() const Q_DECL_OVERRIDE; + virtual QPoint mapToGlobal(const QPoint &posInView) const Q_DECL_OVERRIDE; virtual qreal dpiScale() const Q_DECL_OVERRIDE; virtual void loadStarted(const QUrl &provisionalUrl) Q_DECL_OVERRIDE; virtual void loadCommitted() Q_DECL_OVERRIDE; diff --git a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp index b1f2d7cea..7bf19d17a 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp @@ -44,9 +44,8 @@ #include -RenderWidgetHostViewQtDelegateQuickWindow::RenderWidgetHostViewQtDelegateQuickWindow(RenderWidgetHostViewQtDelegate *realDelegate, QQuickItem *parent) +RenderWidgetHostViewQtDelegateQuickWindow::RenderWidgetHostViewQtDelegateQuickWindow(RenderWidgetHostViewQtDelegate *realDelegate) : m_realDelegate(realDelegate) - , m_parentView(parent) { setFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); } @@ -62,13 +61,10 @@ void RenderWidgetHostViewQtDelegateQuickWindow::initAsChild(WebContentsAdapterCl Q_UNREACHABLE(); } -void RenderWidgetHostViewQtDelegateQuickWindow::initAsPopup(const QRect &rect) +void RenderWidgetHostViewQtDelegateQuickWindow::initAsPopup(const QRect &screenRect) { - Q_ASSERT(m_parentView); - QPoint pos = m_parentView->window()->mapToGlobal(rect.topLeft()); - QRect geometry = QRect(pos, rect.size()); - m_realDelegate->initAsPopup(QRect(QPoint(0, 0), rect.size())); - setGeometry(geometry); + m_realDelegate->initAsPopup(QRect(QPoint(0, 0), screenRect.size())); + setGeometry(screenRect); raise(); show(); } @@ -95,7 +91,7 @@ bool RenderWidgetHostViewQtDelegateQuickWindow::isVisible() const QWindow *RenderWidgetHostViewQtDelegateQuickWindow::window() const { - return m_parentView->window(); + return const_cast(this); } void RenderWidgetHostViewQtDelegateQuickWindow::update(const QRect &rect) @@ -116,11 +112,9 @@ void RenderWidgetHostViewQtDelegateQuickWindow::resize(int width, int height) m_realDelegate->resize(width, height); } -void RenderWidgetHostViewQtDelegateQuickWindow::move(const QPoint &pos) +void RenderWidgetHostViewQtDelegateQuickWindow::move(const QPoint &screenPos) { - Q_ASSERT(m_parentView); - QPoint mapped = m_parentView->window()->mapToGlobal(pos); - QQuickWindow::setPosition(mapped.x(), mapped.y()); + QQuickWindow::setPosition(screenPos); } void RenderWidgetHostViewQtDelegateQuickWindow::setTooltip(const QString &tooltip) diff --git a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h index 9b959f02b..6adac5e95 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h +++ b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h @@ -52,7 +52,7 @@ class RenderWidgetHostViewQtDelegateQuickWindow : public QQuickWindow , public RenderWidgetHostViewQtDelegate { public: - RenderWidgetHostViewQtDelegateQuickWindow(RenderWidgetHostViewQtDelegate *realDelegate, QQuickItem *parent); + RenderWidgetHostViewQtDelegateQuickWindow(RenderWidgetHostViewQtDelegate *realDelegate); ~RenderWidgetHostViewQtDelegateQuickWindow(); virtual void initAsChild(WebContentsAdapterClient* container) Q_DECL_OVERRIDE; @@ -67,7 +67,7 @@ public: virtual void update(const QRect& rect = QRect()) Q_DECL_OVERRIDE; virtual void updateCursor(const QCursor &) Q_DECL_OVERRIDE; virtual void resize(int width, int height) Q_DECL_OVERRIDE; - virtual void move(const QPoint &) Q_DECL_OVERRIDE; + virtual void move(const QPoint &screenPos) Q_DECL_OVERRIDE; virtual void inputMethodStateChanged(bool) Q_DECL_OVERRIDE {} virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE { @@ -78,7 +78,6 @@ public: private: QScopedPointer m_realDelegate; - QQuickItem *m_parentView; }; #endif // RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_QUICKWINDOW_H diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 0ed9d0135..a5e5f8320 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -28,8 +28,7 @@ #include "qwebenginehistory_p.h" #include "qwebengineview.h" #include "qwebengineview_p.h" -#include "render_widget_host_view_qt_delegate_popup.h" -#include "render_widget_host_view_qt_delegate_webpage.h" +#include "render_widget_host_view_qt_delegate_widget.h" #include "web_contents_adapter.h" #include @@ -38,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -152,6 +152,7 @@ QWebEnginePagePrivate::QWebEnginePagePrivate() , history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this))) , view(0) { + adapter->initialize(this); memset(actions, 0, sizeof(actions)); } @@ -163,13 +164,7 @@ QWebEnginePagePrivate::~QWebEnginePagePrivate() RenderWidgetHostViewQtDelegate *QWebEnginePagePrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) { Q_UNUSED(mode); - return new RenderWidgetHostViewQtDelegateWebPage(client); -} - -RenderWidgetHostViewQtDelegate *QWebEnginePagePrivate::CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client, WebContentsAdapterClient::RenderingMode) -{ - Q_ASSERT(m_rwhvDelegate); - return new RenderWidgetHostViewQtDelegatePopup(client, view); + return new RenderWidgetHostViewQtDelegateWidget(client); } void QWebEnginePagePrivate::titleChanged(const QString &title) @@ -204,10 +199,12 @@ void QWebEnginePagePrivate::selectionChanged() QRectF QWebEnginePagePrivate::viewportRect() const { - QRectF rect(QPointF(), viewportSize); - if (view) - rect.setTopLeft(view->rect().topLeft()); - return rect; + return view ? view->rect() : QRectF(); +} + +QPoint QWebEnginePagePrivate::mapToGlobal(const QPoint &posInView) const +{ + return view ? view->mapToGlobal(posInView) : QPoint(); } qreal QWebEnginePagePrivate::dpiScale() const @@ -366,8 +363,6 @@ void QWebEnginePagePrivate::recreateFromSerializedHistory(QDataStream &input) QWebEnginePage::QWebEnginePage(QObject* parent) : QObject(*new QWebEnginePagePrivate, parent) { - Q_D(QWebEnginePage); - d->adapter->initialize(d); } QWebEnginePage::~QWebEnginePage() @@ -528,32 +523,9 @@ void QWebEnginePage::findText(const QString &subString, FindFlags options, const } } -QSize QWebEnginePage::viewportSize() const -{ - Q_D(const QWebEnginePage); - return d->viewportSize; -} - -void QWebEnginePage::setViewportSize(const QSize &size) -{ - Q_D(QWebEnginePage); - d->viewportSize = size; - if (d->m_rwhvDelegate) - d->m_rwhvDelegate->notifyResize(); -} - bool QWebEnginePage::event(QEvent *e) { - Q_D(QWebEnginePage); - if (!d->m_rwhvDelegate) { - // FIXME: implement a signal when the render process crashes and keep track of it at this level - // Ideally, this should be Q_ASSERT(!d->m_renderProcessLive) or something along those lines - qWarning("%s: no render process running?\n", Q_FUNC_INFO); - return false; - } - if (!d->m_rwhvDelegate->forwardEvent(e)) - return QObject::event(e); - return true; + return QObject::event(e); } bool QWebEnginePagePrivate::contextMenuRequested(const WebEngineContextMenuData &data) @@ -759,22 +731,6 @@ QUrl QWebEnginePage::requestedUrl() const return d->adapter->requestedUrl(); } -void QWebEnginePage::render(QPainter *p, const QRegion &clip) -{ - Q_D(const QWebEnginePage); - if (!d->m_rwhvDelegate) { - // Most likely the render process crashed. See QWebEnginePage::event - return; - } - if (!clip.isNull()) { - p->save(); - p->setClipRegion(clip); - } - d->m_rwhvDelegate->paint(p, QRectF(clip.boundingRect())); - if (!clip.isNull()) - p->restore(); -} - qreal QWebEnginePage::zoomFactor() const { Q_D(const QWebEnginePage); @@ -787,21 +743,6 @@ void QWebEnginePage::setZoomFactor(qreal factor) d->adapter->setZoomFactor(factor); } -bool QWebEnginePage::hasFocus() const -{ - Q_D(const QWebEnginePage); - if (d->view) - return d->view->hasFocus(); - return false; -} - -void QWebEnginePage::setFocus() -{ - Q_D(QWebEnginePage); - if (d->view) - d->view->setFocus(); -} - void QWebEnginePage::runJavaScript(const QString &scriptSource, const QString &xPath) { Q_D(QWebEnginePage); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 927519008..e487ff37c 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -45,7 +45,6 @@ #include "qwebenginepage.h" #include "web_contents_adapter_client.h" -#include "render_widget_host_view_qt_delegate_webpage.h" #include #include #include @@ -110,13 +109,14 @@ public: ~QWebEnginePagePrivate(); virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) Q_DECL_OVERRIDE; - virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client, RenderingMode) Q_DECL_OVERRIDE; + virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) Q_DECL_OVERRIDE { return CreateRenderWidgetHostViewQtDelegate(client, mode); } virtual void titleChanged(const QString&) Q_DECL_OVERRIDE; virtual void urlChanged(const QUrl&) Q_DECL_OVERRIDE; virtual void iconChanged(const QUrl&) Q_DECL_OVERRIDE; virtual void loadProgressChanged(int progress) Q_DECL_OVERRIDE; virtual void selectionChanged() Q_DECL_OVERRIDE; virtual QRectF viewportRect() const Q_DECL_OVERRIDE; + virtual QPoint mapToGlobal(const QPoint &posInView) const Q_DECL_OVERRIDE; virtual qreal dpiScale() const Q_DECL_OVERRIDE; virtual void loadStarted(const QUrl &provisionalUrl) Q_DECL_OVERRIDE; virtual void loadCommitted() Q_DECL_OVERRIDE; @@ -150,7 +150,6 @@ public: QSize viewportSize; QUrl m_explicitUrl; WebEngineContextMenuData m_menuData; - QPointer m_rwhvDelegate; mutable CallbackDirectory m_callbacks; mutable QAction *actions[QWebEnginePage::WebActionCount]; diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index 3f3fdd7cd..c8fe9c383 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -48,6 +48,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -63,6 +64,7 @@ void QWebEngineViewPrivate::bind(QWebEngineView *view, QWebEnginePage *page) oldView->d_func()->page = 0; } page->d_func()->view = view; + page->d_func()->adapter->reattachRWHV(); } if (view) { @@ -81,7 +83,6 @@ void QWebEngineViewPrivate::bind(QWebEngineView *view, QWebEnginePage *page) QObject::connect(page, &QWebEnginePage::loadProgress, view, &QWebEngineView::loadProgress); QObject::connect(page, &QWebEnginePage::loadFinished, view, &QWebEngineView::loadFinished); QObject::connect(page, &QWebEnginePage::selectionChanged, view, &QWebEngineView::selectionChanged); - page->setViewportSize(view->size()); } } @@ -94,10 +95,8 @@ QWebEngineViewPrivate::QWebEngineViewPrivate() QWebEngineView::QWebEngineView(QWidget *parent) : QWidget(*(new QWebEngineViewPrivate), parent, 0) { - setFocusPolicy(Qt::ClickFocus); - setMouseTracking(true); - setAttribute(Qt::WA_AcceptTouchEvents); - setAttribute(Qt::WA_OpaquePaintEvent); + // This causes the child RenderWidgetHostViewQtDelegateWidgets to fill this widget. + setLayout(new QStackedLayout); } QWebEngineView::~QWebEngineView() @@ -222,41 +221,15 @@ void QWebEngineView::setZoomFactor(qreal factor) bool QWebEngineView::event(QEvent *ev) { - Q_D(QWebEngineView); // We swallow spontaneous contextMenu events and synthethize those back later on when we get the // HandleContextMenu callback from chromium if (ev->type() == QEvent::ContextMenu) { ev->accept(); return true; - - // Meta calls are not safe to forward to the page, as they could be widget specific (e.g. QWidgetPrivate::_q_showIfNotHidden) - // ToolTip events need to be processed at the widget level for the tooltip to show. - } else if (ev->type() == QEvent::MetaCall - || ev->type() == QEvent::ToolTip) - return QWidget::event(ev); - if (d->page && d->page->event(ev)) - return true; - + } return QWidget::event(ev); } -void QWebEngineView::paintEvent(QPaintEvent *ev) -{ - Q_D(QWebEngineView); - if (!d->page) - return; - QPainter painter(this); - d->page->render(&painter, QRegion(ev->rect())); -} - -void QWebEngineView::resizeEvent(QResizeEvent *ev) -{ - Q_D(QWebEngineView); - if (!d->page) - return; - d->page->setViewportSize(ev->size()); -} - void QWebEngineView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = page()->createStandardContextMenu(); diff --git a/src/webenginewidgets/api/qwebengineview.h b/src/webenginewidgets/api/qwebengineview.h index 836e61be3..5e7dfa0e9 100644 --- a/src/webenginewidgets/api/qwebengineview.h +++ b/src/webenginewidgets/api/qwebengineview.h @@ -132,8 +132,6 @@ protected: virtual QWebEngineView *createWindow(QWebEnginePage::WebWindowType type); virtual void contextMenuEvent(QContextMenuEvent*) Q_DECL_OVERRIDE; virtual bool event(QEvent*) Q_DECL_OVERRIDE; - virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; private: Q_DECLARE_PRIVATE(QWebEngineView); diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp deleted file mode 100644 index eae3b8a6d..000000000 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "render_widget_host_view_qt_delegate_popup.h" - -#include "qwebengineview.h" -#include "qwebenginepage_p.h" -#include -#include -#include -#include -#include -#include -#include - -RenderWidgetHostViewQtDelegatePopup::RenderWidgetHostViewQtDelegatePopup(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent) - : m_client(client) - , m_parentView(parent) -{ - setMouseTracking(true); - setAttribute(Qt::WA_AcceptTouchEvents); - // The keyboard events are supposed to go to the parent RenderHostView - // so the WebUI popups should never have focus. Besides, if the parent view - // loses focus, WebKit will cause its associated popups (including this one) - // to be destroyed. - setAttribute(Qt::WA_ShowWithoutActivating); - setAttribute(Qt::WA_AlwaysShowToolTips); - setFocusPolicy(Qt::NoFocus); - setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); -} - -void RenderWidgetHostViewQtDelegatePopup::initAsChild(WebContentsAdapterClient*) -{ - Q_UNREACHABLE(); -} - -void RenderWidgetHostViewQtDelegatePopup::initAsPopup(const QRect& rect) -{ - QPoint pos = m_parentView ? m_parentView->mapToGlobal(rect.topLeft()) : QPoint(0,0); - QRect qrect = QRect(pos, rect.size()); - setGeometry(qrect); - raise(); - show(); -} - -QRectF RenderWidgetHostViewQtDelegatePopup::screenRect() const -{ - return QRectF(x(), y(), width(), height()); -} - -void RenderWidgetHostViewQtDelegatePopup::setKeyboardFocus() -{ - Q_UNREACHABLE(); -} - -bool RenderWidgetHostViewQtDelegatePopup::hasKeyboardFocus() -{ - return false; -} - -void RenderWidgetHostViewQtDelegatePopup::show() -{ - QWidget::show(); -} - -void RenderWidgetHostViewQtDelegatePopup::hide() -{ - QWidget::hide(); -} - -bool RenderWidgetHostViewQtDelegatePopup::isVisible() const -{ - return QWidget::isVisible(); -} - -QWindow* RenderWidgetHostViewQtDelegatePopup::window() const -{ - const QWidget* root = QWidget::window(); - return root ? root->windowHandle() : Q_NULLPTR; -} - -void RenderWidgetHostViewQtDelegatePopup::update(const QRect& rect) -{ - QWidget::update(rect); -} - -void RenderWidgetHostViewQtDelegatePopup::updateCursor(const QCursor &cursor) -{ - QWidget::setCursor(cursor); -} - -void RenderWidgetHostViewQtDelegatePopup::resize(int width, int height) -{ - QWidget::resize(width, height); -} - -void RenderWidgetHostViewQtDelegatePopup::move(const QPoint &pos) -{ - QPoint mapped = m_parentView ? m_parentView->mapToGlobal(pos) : pos; - QWidget::move(mapped); -} - -void RenderWidgetHostViewQtDelegatePopup::setTooltip(const QString &tooltip) -{ - setToolTip(tooltip); -} - -void RenderWidgetHostViewQtDelegatePopup::paintEvent(QPaintEvent *event) -{ - QPainter painter(this); - m_client->fetchBackingStore(); - m_client->paint(&painter, event->rect()); -} - -void RenderWidgetHostViewQtDelegatePopup::resizeEvent(QResizeEvent *resizeEvent) -{ - Q_UNUSED(resizeEvent); - m_client->notifyResize(); -} - -bool RenderWidgetHostViewQtDelegatePopup::event(QEvent *event) -{ - if (!m_client->forwardEvent(event)) - return QWidget::event(event); - return true; -} diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h deleted file mode 100644 index 5f3e6595c..000000000 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_POPUP_H -#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_POPUP_H - -#include "render_widget_host_view_qt_delegate.h" -#include "web_contents_adapter_client.h" - -#include -#include - -class BackingStoreQt; - -QT_BEGIN_NAMESPACE -class QWindow; -QT_END_NAMESPACE - -class RenderWidgetHostViewQtDelegatePopup : public QWidget, public RenderWidgetHostViewQtDelegate -{ -public: - RenderWidgetHostViewQtDelegatePopup(RenderWidgetHostViewQtDelegateClient *client, QWidget *); - - virtual void initAsChild(WebContentsAdapterClient* container) Q_DECL_OVERRIDE; - virtual void initAsPopup(const QRect&) Q_DECL_OVERRIDE; - virtual QRectF screenRect() const Q_DECL_OVERRIDE; - virtual void setKeyboardFocus() Q_DECL_OVERRIDE; - virtual bool hasKeyboardFocus() Q_DECL_OVERRIDE; - virtual void show() Q_DECL_OVERRIDE; - virtual void hide() Q_DECL_OVERRIDE; - virtual bool isVisible() const Q_DECL_OVERRIDE; - virtual QWindow* window() const Q_DECL_OVERRIDE; - virtual void update(const QRect& rect = QRect()) Q_DECL_OVERRIDE; - virtual void updateCursor(const QCursor &) Q_DECL_OVERRIDE; - virtual void resize(int width, int height) Q_DECL_OVERRIDE; - virtual void move(const QPoint &) Q_DECL_OVERRIDE; - virtual void inputMethodStateChanged(bool) Q_DECL_OVERRIDE {} - virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE { return false; } - virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; - -protected: - void paintEvent(QPaintEvent * event); - bool event(QEvent *event); - void resizeEvent(QResizeEvent *resizeEvent); - -private: - RenderWidgetHostViewQtDelegateClient *m_client; - QWidget *m_parentView; -}; - -#endif diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp deleted file mode 100644 index e8a3e7d44..000000000 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "render_widget_host_view_qt_delegate_webpage.h" - -#include "qwebengineview.h" -#include "qwebenginepage.h" -#include "qwebenginepage_p.h" -#include -#include -#include -#include -#include -#include - -RenderWidgetHostViewQtDelegateWebPage::RenderWidgetHostViewQtDelegateWebPage(RenderWidgetHostViewQtDelegateClient *client) - : m_client(client) - , m_page(0) - , m_pagePrivate(0) -{ -} - -void RenderWidgetHostViewQtDelegateWebPage::initAsChild(WebContentsAdapterClient* container) -{ - m_pagePrivate = static_cast(container); - m_pagePrivate->m_rwhvDelegate = this; - m_page = m_pagePrivate->q_func(); - Q_ASSERT(m_page); -} - -QRectF RenderWidgetHostViewQtDelegateWebPage::screenRect() const -{ - if (m_pagePrivate) - return m_pagePrivate->viewportRect(); - // FIXME: figure out what to do with QWebFrame::contentsSize vs. preferedContentsSize - return QRectF(0, 0, 800, 600); -} - -void RenderWidgetHostViewQtDelegateWebPage::setKeyboardFocus() -{ - if (m_page) - m_page->setFocus(); -} - -bool RenderWidgetHostViewQtDelegateWebPage::hasKeyboardFocus() -{ - return m_page && m_page->hasFocus(); -} - -bool RenderWidgetHostViewQtDelegateWebPage::isVisible() const -{ - if (m_page && m_page->view()) - return m_page->view()->isVisible(); - return false; -} - -QWindow* RenderWidgetHostViewQtDelegateWebPage::window() const -{ - if (!m_page || !m_page->view()) - return Q_NULLPTR; - return m_page->view()->window()->windowHandle(); -} - -void RenderWidgetHostViewQtDelegateWebPage::update(const QRect& rect) -{ - if (m_page->view()) - m_page->view()->update(rect); -} - -void RenderWidgetHostViewQtDelegateWebPage::updateCursor(const QCursor &cursor) -{ - if (m_page->view()) - m_page->view()->setCursor(cursor); -} - -void RenderWidgetHostViewQtDelegateWebPage::resize(int width, int height) -{ - Q_UNUSED(width) - Q_UNUSED(height) - QT_NOT_YET_IMPLEMENTED; -} - -void RenderWidgetHostViewQtDelegateWebPage::inputMethodStateChanged(bool editorVisible) -{ - if (qApp->inputMethod()->isVisible() == editorVisible) - return; - - if (m_page && m_page->view()) - m_page->view()->setAttribute(Qt::WA_InputMethodEnabled, editorVisible); - qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); - qApp->inputMethod()->setVisible(editorVisible); -} - -QVariant RenderWidgetHostViewQtDelegateWebPage::inputMethodQuery(Qt::InputMethodQuery query) const -{ - return m_client->inputMethodQuery(query); -} - -bool RenderWidgetHostViewQtDelegateWebPage::supportsHardwareAcceleration() const -{ - return false; -} - -void RenderWidgetHostViewQtDelegateWebPage::setTooltip(const QString &tooltip) -{ - if (m_page && m_page->view()) - m_page->view()->setToolTip(tooltip); -} - -void RenderWidgetHostViewQtDelegateWebPage::paint(QPainter *painter, const QRectF &boundingRect) -{ - m_client->fetchBackingStore(); - m_client->paint(painter, boundingRect); -} - -void RenderWidgetHostViewQtDelegateWebPage::notifyResize() -{ - m_client->notifyResize(); -} - -bool RenderWidgetHostViewQtDelegateWebPage::forwardEvent(QEvent *event) -{ - return m_client->forwardEvent(event); -} diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h deleted file mode 100644 index 80da9d727..000000000 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WEBPAGE_H -#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WEBPAGE_H - -#include "render_widget_host_view_qt_delegate.h" -#include "web_contents_adapter_client.h" - -#include - -class BackingStoreQt; - -QT_BEGIN_NAMESPACE -class QWindow; -class QWebEnginePage; -class QWebEnginePagePrivate; -QT_END_NAMESPACE - -class RenderWidgetHostViewQtDelegateWebPage : public QObject, public RenderWidgetHostViewQtDelegate -{ -public: - RenderWidgetHostViewQtDelegateWebPage(RenderWidgetHostViewQtDelegateClient *client); - - virtual void initAsChild(WebContentsAdapterClient* container) Q_DECL_OVERRIDE; - virtual void initAsPopup(const QRect&) Q_DECL_OVERRIDE { Q_UNREACHABLE(); } - virtual QRectF screenRect() const Q_DECL_OVERRIDE; - virtual void setKeyboardFocus() Q_DECL_OVERRIDE; - virtual bool hasKeyboardFocus() Q_DECL_OVERRIDE; - virtual void show() Q_DECL_OVERRIDE {} - virtual void hide() Q_DECL_OVERRIDE {} - virtual bool isVisible() const Q_DECL_OVERRIDE; - virtual QWindow* window() const Q_DECL_OVERRIDE; - virtual void update(const QRect& rect = QRect()) Q_DECL_OVERRIDE; - virtual void updateCursor(const QCursor &) Q_DECL_OVERRIDE; - virtual void resize(int width, int height) Q_DECL_OVERRIDE; - virtual void move(const QPoint&) Q_DECL_OVERRIDE {} - virtual void inputMethodStateChanged(bool editorVisible) Q_DECL_OVERRIDE; - virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE; - virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; - - void paint(QPainter *painter, const QRectF &boundingRect); - void notifyResize(); - bool forwardEvent(QEvent *event); - -protected: - - QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - -private: - RenderWidgetHostViewQtDelegateClient *m_client; - QWebEnginePage *m_page; - QWebEnginePagePrivate *m_pagePrivate; -}; - -#endif diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp new file mode 100644 index 000000000..71d6e235e --- /dev/null +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp @@ -0,0 +1,194 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "render_widget_host_view_qt_delegate_widget.h" + +#include "qwebengineview.h" +#include "qwebenginepage_p.h" +#include +#include +#include +#include +#include +#include +#include + +RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent) + : QWidget(parent) + , m_client(client) + , m_isPopup(false) +{ + setFocusPolicy(Qt::ClickFocus); + setMouseTracking(true); + setAttribute(Qt::WA_AcceptTouchEvents); + setAttribute(Qt::WA_OpaquePaintEvent); + setAttribute(Qt::WA_AlwaysShowToolTips); +} + +void RenderWidgetHostViewQtDelegateWidget::initAsChild(WebContentsAdapterClient* container) +{ + QWebEnginePagePrivate *pagePrivate = static_cast(container); + if (pagePrivate->view) { + pagePrivate->view->layout()->addWidget(this); + QWidget::show(); + } else + setParent(0); +} + +void RenderWidgetHostViewQtDelegateWidget::initAsPopup(const QRect& screenRect) +{ + m_isPopup = true; + // The keyboard events are supposed to go to the parent RenderHostView + // so the WebUI popups should never have focus. Besides, if the parent view + // loses focus, WebKit will cause its associated popups (including this one) + // to be destroyed. + setAttribute(Qt::WA_ShowWithoutActivating); + setFocusPolicy(Qt::NoFocus); + setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); + + setGeometry(screenRect); + show(); +} + +QRectF RenderWidgetHostViewQtDelegateWidget::screenRect() const +{ + return QRectF(x(), y(), width(), height()); +} + +void RenderWidgetHostViewQtDelegateWidget::setKeyboardFocus() +{ + setFocus(); +} + +bool RenderWidgetHostViewQtDelegateWidget::hasKeyboardFocus() +{ + return hasFocus(); +} + +void RenderWidgetHostViewQtDelegateWidget::show() +{ + // Check if we're attached to a QWebEngineView, we don't + // want to show anything else than popups as top-level. + if (parent() || m_isPopup) + QWidget::show(); +} + +void RenderWidgetHostViewQtDelegateWidget::hide() +{ + QWidget::hide(); +} + +bool RenderWidgetHostViewQtDelegateWidget::isVisible() const +{ + return QWidget::isVisible(); +} + +QWindow* RenderWidgetHostViewQtDelegateWidget::window() const +{ + const QWidget* root = QWidget::window(); + return root ? root->windowHandle() : 0; +} + +void RenderWidgetHostViewQtDelegateWidget::update(const QRect& rect) +{ + QWidget::update(rect); +} + +void RenderWidgetHostViewQtDelegateWidget::updateCursor(const QCursor &cursor) +{ + QWidget::setCursor(cursor); +} + +void RenderWidgetHostViewQtDelegateWidget::resize(int width, int height) +{ + QWidget::resize(width, height); +} + +void RenderWidgetHostViewQtDelegateWidget::move(const QPoint &screenPos) +{ + Q_ASSERT(m_isPopup); + QOpenGLWidget::move(screenPos); +} + +void RenderWidgetHostViewQtDelegateWidget::inputMethodStateChanged(bool editorVisible) +{ + if (qApp->inputMethod()->isVisible() == editorVisible) + return; + + QWidget::setAttribute(Qt::WA_InputMethodEnabled, editorVisible); + qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); + qApp->inputMethod()->setVisible(editorVisible); +} + +void RenderWidgetHostViewQtDelegateWidget::setTooltip(const QString &tooltip) +{ + setToolTip(tooltip); +} + +QVariant RenderWidgetHostViewQtDelegateWidget::inputMethodQuery(Qt::InputMethodQuery query) const +{ + return m_client->inputMethodQuery(query); +} + +bool RenderWidgetHostViewQtDelegateWidget::supportsHardwareAcceleration() const +{ + return false; +} + +void RenderWidgetHostViewQtDelegateWidget::paintEvent(QPaintEvent * event) +{ + QPainter painter(this); + m_client->fetchBackingStore(); + m_client->paint(&painter, event->rect()); +} + +void RenderWidgetHostViewQtDelegateWidget::resizeEvent(QResizeEvent *resizeEvent) +{ + Q_UNUSED(resizeEvent); + m_client->notifyResize(); +} + +bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event) +{ + if (!m_client->forwardEvent(event)) + return QWidget::event(event); + return true; +} diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h new file mode 100644 index 000000000..77a594d61 --- /dev/null +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WIDGET_H +#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WIDGET_H + +#include "render_widget_host_view_qt_delegate.h" +#include "web_contents_adapter_client.h" + +#include + +class BackingStoreQt; + +QT_BEGIN_NAMESPACE +class QWindow; +QT_END_NAMESPACE + +class RenderWidgetHostViewQtDelegateWidget : public QWidget, public RenderWidgetHostViewQtDelegate +{ +public: + RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent = 0); + + virtual void initAsChild(WebContentsAdapterClient* container) Q_DECL_OVERRIDE; + virtual void initAsPopup(const QRect&) Q_DECL_OVERRIDE; + virtual QRectF screenRect() const Q_DECL_OVERRIDE; + virtual void setKeyboardFocus() Q_DECL_OVERRIDE; + virtual bool hasKeyboardFocus() Q_DECL_OVERRIDE; + virtual void show() Q_DECL_OVERRIDE; + virtual void hide() Q_DECL_OVERRIDE; + virtual bool isVisible() const Q_DECL_OVERRIDE; + virtual QWindow* window() const Q_DECL_OVERRIDE; + virtual void update(const QRect& rect = QRect()) Q_DECL_OVERRIDE; + virtual void updateCursor(const QCursor &) Q_DECL_OVERRIDE; + virtual void resize(int width, int height) Q_DECL_OVERRIDE; + virtual void move(const QPoint &screenPos) Q_DECL_OVERRIDE; + virtual void inputMethodStateChanged(bool editorVisible) Q_DECL_OVERRIDE; + virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE; + virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; + +protected: + void paintEvent(QPaintEvent * event); + bool event(QEvent *event); + void resizeEvent(QResizeEvent *resizeEvent); + + QVariant inputMethodQuery(Qt::InputMethodQuery query) const; + +private: + RenderWidgetHostViewQtDelegateClient *m_client; + bool m_isPopup; +}; + +#endif diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro index 5de78c270..182cb5500 100644 --- a/src/webenginewidgets/webenginewidgets.pro +++ b/src/webenginewidgets/webenginewidgets.pro @@ -14,8 +14,7 @@ SOURCES = \ api/qwebenginehistory.cpp \ api/qwebenginepage.cpp \ api/qwebengineview.cpp\ - render_widget_host_view_qt_delegate_popup.cpp \ - render_widget_host_view_qt_delegate_webpage.cpp + render_widget_host_view_qt_delegate_widget.cpp HEADERS = \ api/qtwebenginewidgetsglobal.h \ @@ -23,7 +22,6 @@ HEADERS = \ api/qwebenginepage.h \ api/qwebengineview.h \ api/qwebengineview_p.h \ - render_widget_host_view_qt_delegate_popup.h \ - render_widget_host_view_qt_delegate_webpage.h + render_widget_host_view_qt_delegate_widget.h load(qt_module) -- cgit v1.2.3