diff options
Diffstat (limited to 'src/webengine')
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 31 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p_p.h | 2 | ||||
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quick.cpp | 10 | ||||
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quick.h | 27 | ||||
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp | 129 | ||||
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quickwindow.h | 84 | ||||
-rw-r--r-- | src/webengine/webengine.pro | 2 |
7 files changed, 270 insertions, 15 deletions
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 27282e111..f9a47a618 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -47,6 +47,7 @@ #include "qquickwebengineloadrequest_p.h" #include "qquickwebenginenewviewrequest_p.h" #include "render_widget_host_view_qt_delegate_quick.h" +#include "render_widget_host_view_qt_delegate_quickwindow.h" #include "ui_delegates_manager.h" #include "web_contents_adapter.h" #include "web_engine_error.h" @@ -61,6 +62,8 @@ #include <QQmlEngine> #include <private/qqmlmetatype_p.h> +#include <private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> QT_BEGIN_NAMESPACE @@ -119,8 +122,32 @@ UIDelegatesManager *QQuickWebEngineViewPrivate::ui() RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) { if (mode == HardwareAccelerationMode) - return new RenderWidgetHostViewQtDelegateQuick(client); - return new RenderWidgetHostViewQtDelegateQuickPainted(client); + return new RenderWidgetHostViewQtDelegateQuick(client, /*isPopup = */ false); + return new RenderWidgetHostViewQtDelegateQuickPainted(client, false); +} + +RenderWidgetHostViewQtDelegate *QQuickWebEngineViewPrivate::CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client, WebContentsAdapterClient::RenderingMode mode) +{ + Q_Q(QQuickWebEngineView); + const bool hasWindowCapability = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MultipleWindows); + if (mode == HardwareAccelerationMode) { + RenderWidgetHostViewQtDelegateQuick *quickDelegate = new RenderWidgetHostViewQtDelegateQuick(client, /*isPopup = */true); + if (hasWindowCapability) { + RenderWidgetHostViewQtDelegateQuickWindow *wrapperWindow = new RenderWidgetHostViewQtDelegateQuickWindow(quickDelegate, q); + quickDelegate->setParentItem(wrapperWindow->contentItem()); + return wrapperWindow; + } + quickDelegate->setParentItem(q); + return quickDelegate; + } + RenderWidgetHostViewQtDelegateQuickPainted *paintedDelegate = new RenderWidgetHostViewQtDelegateQuickPainted(client, /*isPopup = */true); + if (hasWindowCapability) { + RenderWidgetHostViewQtDelegateQuickWindow *wrapperWindow = new RenderWidgetHostViewQtDelegateQuickWindow(paintedDelegate, q); + paintedDelegate->setParentItem(wrapperWindow->contentItem()); + return wrapperWindow; + } + paintedDelegate->setParentItem(q); + return paintedDelegate; } bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenuData &data) diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 1b1d7994e..9a7736d1d 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -126,7 +126,7 @@ public: UIDelegatesManager *ui(); virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client, RenderingMode) Q_DECL_OVERRIDE; - virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) Q_DECL_OVERRIDE { return CreateRenderWidgetHostViewQtDelegate(client, mode); } + virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegateForPopup(RenderWidgetHostViewQtDelegateClient *client, RenderingMode mode) Q_DECL_OVERRIDE; virtual void titleChanged(const QString&) Q_DECL_OVERRIDE; virtual void urlChanged(const QUrl&) Q_DECL_OVERRIDE; virtual void iconChanged(const QUrl&) Q_DECL_OVERRIDE; diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp index 3aea86378..693b12e07 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -41,8 +41,8 @@ #include "render_widget_host_view_qt_delegate_quick.h" -RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(RenderWidgetHostViewQtDelegateClient *client, QQuickItem *parent) - : RenderWidgetHostViewQtDelegateQuickBase<QQuickItem>(client, parent) +RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(RenderWidgetHostViewQtDelegateClient *client, bool isPopup) + : RenderWidgetHostViewQtDelegateQuickBase<QQuickItem>(client, isPopup) { setFlag(ItemHasContents); } @@ -60,7 +60,7 @@ bool RenderWidgetHostViewQtDelegateQuick::supportsHardwareAcceleration() const void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const ItemChangeData &value) { QQuickItem::itemChange(change, value); - if (change == QQuickItem::ItemSceneChange) + if (m_initialized && change == QQuickItem::ItemSceneChange) m_client->windowChanged(); } @@ -69,8 +69,8 @@ QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, return m_client->updatePaintNode(oldNode, QQuickItem::window()); } -RenderWidgetHostViewQtDelegateQuickPainted::RenderWidgetHostViewQtDelegateQuickPainted(RenderWidgetHostViewQtDelegateClient *client, QQuickItem *parent) - : RenderWidgetHostViewQtDelegateQuickBase<QQuickPaintedItem>(client, parent) +RenderWidgetHostViewQtDelegateQuickPainted::RenderWidgetHostViewQtDelegateQuickPainted(RenderWidgetHostViewQtDelegateClient *client, bool isPopup) + : RenderWidgetHostViewQtDelegateQuickBase<QQuickPaintedItem>(client, isPopup) { } diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.h b/src/webengine/render_widget_host_view_qt_delegate_quick.h index f4d72117a..47884068e 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.h +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.h @@ -56,12 +56,18 @@ template<typename ItemBaseT> class RenderWidgetHostViewQtDelegateQuickBase : public ItemBaseT, public RenderWidgetHostViewQtDelegate { public: - RenderWidgetHostViewQtDelegateQuickBase(RenderWidgetHostViewQtDelegateClient *client, QQuickItem *parent = 0) - : ItemBaseT(parent) - , m_client(client) + RenderWidgetHostViewQtDelegateQuickBase(RenderWidgetHostViewQtDelegateClient *client, bool isPopup) + : m_client(client) + , m_isPopup(isPopup) + , m_initialized(false) { this->setAcceptedMouseButtons(Qt::AllButtons); this->setAcceptHoverEvents(true); + if (isPopup) + return; + this->setFocus(true); + this->setActiveFocusOnTab(true); + this->setFlag(QQuickItem::ItemIsFocusScope); } virtual void initAsChild(WebContentsAdapterClient* container) Q_DECL_OVERRIDE @@ -69,15 +75,19 @@ public: QQuickWebEngineViewPrivate *viewPrivate = static_cast<QQuickWebEngineViewPrivate *>(container); this->setParentItem(viewPrivate->q_func()); this->setSize(viewPrivate->q_func()->boundingRect().size()); + m_initialized = true; } - virtual void initAsPopup(const QRect& rect) Q_DECL_OVERRIDE + virtual void initAsPopup(const QRect &r) Q_DECL_OVERRIDE { + Q_ASSERT(m_isPopup && this->parentItem()); + QRectF rect(this->parentItem()->mapRectFromScene(r)); this->setX(rect.x()); this->setY(rect.y()); this->setWidth(rect.width()); this->setHeight(rect.height()); this->setVisible(true); + m_initialized = true; } virtual QRectF screenRect() const Q_DECL_OVERRIDE @@ -145,7 +155,8 @@ public: void mousePressEvent(QMouseEvent *event) { - this->forceActiveFocus(); + if (!m_isPopup) + this->forceActiveFocus(); m_client->forwardEvent(event); } @@ -219,13 +230,15 @@ protected: } RenderWidgetHostViewQtDelegateClient *m_client; + bool m_isPopup; + bool m_initialized; }; class RenderWidgetHostViewQtDelegateQuick : public RenderWidgetHostViewQtDelegateQuickBase<QQuickItem> { Q_OBJECT public: - RenderWidgetHostViewQtDelegateQuick(RenderWidgetHostViewQtDelegateClient *client, QQuickItem *parent = 0); + RenderWidgetHostViewQtDelegateQuick(RenderWidgetHostViewQtDelegateClient *client, bool isPopup); virtual void update(const QRect& rect = QRect()) Q_DECL_OVERRIDE; virtual bool supportsHardwareAcceleration() const Q_DECL_OVERRIDE; @@ -238,7 +251,7 @@ class RenderWidgetHostViewQtDelegateQuickPainted : public RenderWidgetHostViewQt { Q_OBJECT public: - RenderWidgetHostViewQtDelegateQuickPainted(RenderWidgetHostViewQtDelegateClient *client, QQuickItem *parent = 0); + RenderWidgetHostViewQtDelegateQuickPainted(RenderWidgetHostViewQtDelegateClient *client, bool isPopup); virtual void update(const QRect& rect = QRect()) 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 new file mode 100644 index 000000000..b1f2d7cea --- /dev/null +++ b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** 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_quickwindow.h" + +#include <QQuickItem> + + +RenderWidgetHostViewQtDelegateQuickWindow::RenderWidgetHostViewQtDelegateQuickWindow(RenderWidgetHostViewQtDelegate *realDelegate, QQuickItem *parent) + : m_realDelegate(realDelegate) + , m_parentView(parent) +{ + setFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); +} + +RenderWidgetHostViewQtDelegateQuickWindow::~RenderWidgetHostViewQtDelegateQuickWindow() +{ +} + +void RenderWidgetHostViewQtDelegateQuickWindow::initAsChild(WebContentsAdapterClient *container) +{ + Q_UNUSED(container); + // We should only use this wrapper class for webUI popups. + Q_UNREACHABLE(); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::initAsPopup(const QRect &rect) +{ + 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); + raise(); + show(); +} + +QRectF RenderWidgetHostViewQtDelegateQuickWindow::screenRect() const +{ + return QRectF(x(), y(), width(), height()); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::show() +{ + QQuickWindow::show(); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::hide() +{ + QQuickWindow::hide(); +} + +bool RenderWidgetHostViewQtDelegateQuickWindow::isVisible() const +{ + return QQuickWindow::isVisible(); +} + +QWindow *RenderWidgetHostViewQtDelegateQuickWindow::window() const +{ + return m_parentView->window(); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::update(const QRect &rect) +{ + Q_UNUSED(rect); + QQuickWindow::update(); + m_realDelegate->update(); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::updateCursor(const QCursor &cursor) +{ + setCursor(cursor); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::resize(int width, int height) +{ + QQuickWindow::resize(width, height); + m_realDelegate->resize(width, height); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::move(const QPoint &pos) +{ + Q_ASSERT(m_parentView); + QPoint mapped = m_parentView->window()->mapToGlobal(pos); + QQuickWindow::setPosition(mapped.x(), mapped.y()); +} + +void RenderWidgetHostViewQtDelegateQuickWindow::setTooltip(const QString &tooltip) +{ + Q_UNUSED(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 new file mode 100644 index 000000000..9b959f02b --- /dev/null +++ b/src/webengine/render_widget_host_view_qt_delegate_quickwindow.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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_QUICKWINDOW_H +#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_QUICKWINDOW_H + +#include "render_widget_host_view_qt_delegate.h" + +#include "render_widget_host_view_qt_delegate_quick.h" + +#include <QQuickWindow> +#include <QScopedPointer> + +class RenderWidgetHostViewQtDelegateQuickWindow : public QQuickWindow , public RenderWidgetHostViewQtDelegate { + +public: + RenderWidgetHostViewQtDelegateQuickWindow(RenderWidgetHostViewQtDelegate *realDelegate, QQuickItem *parent); + ~RenderWidgetHostViewQtDelegateQuickWindow(); + + 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 { return false; } + 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 m_realDelegate->supportsHardwareAcceleration(); + } + virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; + + +private: + QScopedPointer<RenderWidgetHostViewQtDelegate> m_realDelegate; + QQuickItem *m_parentView; +}; + +#endif // RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_QUICKWINDOW_H diff --git a/src/webengine/webengine.pro b/src/webengine/webengine.pro index ad1a31b54..36ef1b67a 100644 --- a/src/webengine/webengine.pro +++ b/src/webengine/webengine.pro @@ -17,6 +17,7 @@ SOURCES = \ api/qquickwebengineview.cpp \ api/qtwebengineglobal.cpp \ render_widget_host_view_qt_delegate_quick.cpp \ + render_widget_host_view_qt_delegate_quickwindow.cpp \ ui_delegates_manager.cpp HEADERS = \ @@ -28,6 +29,7 @@ HEADERS = \ api/qquickwebengineview_p.h \ api/qquickwebengineview_p_p.h \ render_widget_host_view_qt_delegate_quick.h \ + render_widget_host_view_qt_delegate_quickwindow.h \ ui_delegates_manager.h load(qt_module) |