summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-04-01 10:27:13 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-08 14:00:06 +0200
commit84f31c11b77a62212451cb77adae63219e06de96 (patch)
tree97d252eee0ee8716d1a7165cd714b0d5b9552ebb /src/webenginewidgets
parent3cb5203cb7a4bee9a867e8616c23ce635d6a8506 (diff)
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 <simon.hausmann@digia.com>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp81
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h5
-rw-r--r--src/webenginewidgets/api/qwebengineview.cpp37
-rw-r--r--src/webenginewidgets/api/qwebengineview.h2
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.cpp162
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_webpage.h94
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp (renamed from src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp)106
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h (renamed from src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h)19
-rw-r--r--src/webenginewidgets/webenginewidgets.pro6
9 files changed, 98 insertions, 414 deletions
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 <QAction>
@@ -38,6 +37,7 @@
#include <QFileDialog>
#include <QIcon>
#include <QInputDialog>
+#include <QLayout>
#include <QMenu>
#include <QMessageBox>
#include <QStandardPaths>
@@ -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 <QtCore/private/qobject_p.h>
#include <QtCore/qcompilerdetection.h>
#include <QSharedData>
@@ -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<RenderWidgetHostViewQtDelegateWebPage> 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 <QAction>
#include <QMenu>
#include <QContextMenuEvent>
+#include <QStackedLayout>
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_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 <QtGlobal>
-#include <QResizeEvent>
-#include <QPainter>
-#include <QPaintEvent>
-#include <QWindow>
-#include <QtWidgets/QApplication>
-
-RenderWidgetHostViewQtDelegateWebPage::RenderWidgetHostViewQtDelegateWebPage(RenderWidgetHostViewQtDelegateClient *client)
- : m_client(client)
- , m_page(0)
- , m_pagePrivate(0)
-{
-}
-
-void RenderWidgetHostViewQtDelegateWebPage::initAsChild(WebContentsAdapterClient* container)
-{
- m_pagePrivate = static_cast<QWebEnginePagePrivate *>(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 <QObject>
-
-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_popup.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
index eae3b8a6d..71d6e235e 100644
--- a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.cpp
+++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include "render_widget_host_view_qt_delegate_popup.h"
+#include "render_widget_host_view_qt_delegate_widget.h"
#include "qwebengineview.h"
#include "qwebenginepage_p.h"
@@ -51,112 +51,142 @@
#include <QWindow>
#include <QtWidgets/QApplication>
-RenderWidgetHostViewQtDelegatePopup::RenderWidgetHostViewQtDelegatePopup(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent)
- : m_client(client)
- , m_parentView(parent)
+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<QWebEnginePagePrivate *>(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);
- 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();
+ setGeometry(screenRect);
show();
}
-QRectF RenderWidgetHostViewQtDelegatePopup::screenRect() const
+QRectF RenderWidgetHostViewQtDelegateWidget::screenRect() const
{
return QRectF(x(), y(), width(), height());
}
-void RenderWidgetHostViewQtDelegatePopup::setKeyboardFocus()
+void RenderWidgetHostViewQtDelegateWidget::setKeyboardFocus()
{
- Q_UNREACHABLE();
+ setFocus();
}
-bool RenderWidgetHostViewQtDelegatePopup::hasKeyboardFocus()
+bool RenderWidgetHostViewQtDelegateWidget::hasKeyboardFocus()
{
- return false;
+ return hasFocus();
}
-void RenderWidgetHostViewQtDelegatePopup::show()
+void RenderWidgetHostViewQtDelegateWidget::show()
{
- QWidget::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 RenderWidgetHostViewQtDelegatePopup::hide()
+void RenderWidgetHostViewQtDelegateWidget::hide()
{
QWidget::hide();
}
-bool RenderWidgetHostViewQtDelegatePopup::isVisible() const
+bool RenderWidgetHostViewQtDelegateWidget::isVisible() const
{
return QWidget::isVisible();
}
-QWindow* RenderWidgetHostViewQtDelegatePopup::window() const
+QWindow* RenderWidgetHostViewQtDelegateWidget::window() const
{
const QWidget* root = QWidget::window();
- return root ? root->windowHandle() : Q_NULLPTR;
+ return root ? root->windowHandle() : 0;
}
-void RenderWidgetHostViewQtDelegatePopup::update(const QRect& rect)
+void RenderWidgetHostViewQtDelegateWidget::update(const QRect& rect)
{
QWidget::update(rect);
}
-void RenderWidgetHostViewQtDelegatePopup::updateCursor(const QCursor &cursor)
+void RenderWidgetHostViewQtDelegateWidget::updateCursor(const QCursor &cursor)
{
QWidget::setCursor(cursor);
}
-void RenderWidgetHostViewQtDelegatePopup::resize(int width, int height)
+void RenderWidgetHostViewQtDelegateWidget::resize(int width, int height)
{
QWidget::resize(width, height);
}
-void RenderWidgetHostViewQtDelegatePopup::move(const QPoint &pos)
+void RenderWidgetHostViewQtDelegateWidget::move(const QPoint &screenPos)
+{
+ Q_ASSERT(m_isPopup);
+ QOpenGLWidget::move(screenPos);
+}
+
+void RenderWidgetHostViewQtDelegateWidget::inputMethodStateChanged(bool editorVisible)
{
- QPoint mapped = m_parentView ? m_parentView->mapToGlobal(pos) : pos;
- QWidget::move(mapped);
+ 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 RenderWidgetHostViewQtDelegatePopup::setTooltip(const QString &tooltip)
+void RenderWidgetHostViewQtDelegateWidget::setTooltip(const QString &tooltip)
{
setToolTip(tooltip);
}
-void RenderWidgetHostViewQtDelegatePopup::paintEvent(QPaintEvent *event)
+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 RenderWidgetHostViewQtDelegatePopup::resizeEvent(QResizeEvent *resizeEvent)
+void RenderWidgetHostViewQtDelegateWidget::resizeEvent(QResizeEvent *resizeEvent)
{
Q_UNUSED(resizeEvent);
m_client->notifyResize();
}
-bool RenderWidgetHostViewQtDelegatePopup::event(QEvent *event)
+bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event)
{
if (!m_client->forwardEvent(event))
return QWidget::event(event);
diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
index 5f3e6595c..77a594d61 100644
--- a/src/webenginewidgets/render_widget_host_view_qt_delegate_popup.h
+++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
@@ -39,13 +39,12 @@
**
****************************************************************************/
-#ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_POPUP_H
-#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_POPUP_H
+#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 <QBasicTimer>
#include <QWidget>
class BackingStoreQt;
@@ -54,10 +53,10 @@ QT_BEGIN_NAMESPACE
class QWindow;
QT_END_NAMESPACE
-class RenderWidgetHostViewQtDelegatePopup : public QWidget, public RenderWidgetHostViewQtDelegate
+class RenderWidgetHostViewQtDelegateWidget : public QWidget, public RenderWidgetHostViewQtDelegate
{
public:
- RenderWidgetHostViewQtDelegatePopup(RenderWidgetHostViewQtDelegateClient *client, QWidget *);
+ RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent = 0);
virtual void initAsChild(WebContentsAdapterClient* container) Q_DECL_OVERRIDE;
virtual void initAsPopup(const QRect&) Q_DECL_OVERRIDE;
@@ -71,9 +70,9 @@ 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 inputMethodStateChanged(bool) Q_DECL_OVERRIDE {}
- virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE { return false; }
+ 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:
@@ -81,9 +80,11 @@ protected:
bool event(QEvent *event);
void resizeEvent(QResizeEvent *resizeEvent);
+ QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
+
private:
RenderWidgetHostViewQtDelegateClient *m_client;
- QWidget *m_parentView;
+ 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)