summaryrefslogtreecommitdiff
path: root/src/webenginequick/api
diff options
context:
space:
mode:
authorBalazs Egedi <egedib@inf.u-szeged.hu>2022-02-18 13:04:19 +0100
committerKirill Burtsev <kirill.burtsev@qt.io>2022-05-04 03:00:16 +0200
commit828ee197647a7462c10243c0261e7bced9bbcb65 (patch)
tree4c6bc198ea33a753e6af4efa736741ea10cea280 /src/webenginequick/api
parent57a38f05d9a0898bffa077a5caaf48fde370cb02 (diff)
downloadqtwebengine-828ee197647a7462c10243c0261e7bced9bbcb65.tar.gz
Quick: Add support for replacing touch handles with delegates
Task-number: QTBUG-85043 Change-Id: I1c87aff352e07eb309d5ba8747b9e50a191d478e Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/webenginequick/api')
-rw-r--r--src/webenginequick/api/qquickwebenginecustomtouchhandle.cpp83
-rw-r--r--src/webenginequick/api/qquickwebenginecustomtouchhandle_p.h89
-rw-r--r--src/webenginequick/api/qquickwebengineview.cpp71
-rw-r--r--src/webenginequick/api/qquickwebengineview_p.h7
-rw-r--r--src/webenginequick/api/qquickwebengineview_p_p.h11
5 files changed, 239 insertions, 22 deletions
diff --git a/src/webenginequick/api/qquickwebenginecustomtouchhandle.cpp b/src/webenginequick/api/qquickwebenginecustomtouchhandle.cpp
new file mode 100644
index 000000000..5bd12e6d6
--- /dev/null
+++ b/src/webenginequick/api/qquickwebenginecustomtouchhandle.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickwebenginecustomtouchhandle_p.h"
+#include "web_contents_adapter_client.h"
+#include <QtQuick/qquickitem.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QQuickWebEngineCustomTouchHandle
+ \since 6.4
+ \brief The QQuickWebEngineCustomTouchHandle class provides information about the touch handle.
+ \inmodule QtWebEngineQuick
+ QQuickWebEngineCustomTouchHandle is returned after a touch selection event,
+ and contains information about the touch handle.
+*/
+
+QQuickWebEngineCustomTouchHandle::QQuickWebEngineCustomTouchHandle()
+ : QObject(nullptr)
+{
+}
+
+void QQuickWebEngineCustomTouchHandle::setBounds(const QRect &bounds)
+{
+ item->setX(bounds.x());
+ item->setY(bounds.y());
+ item->setWidth(bounds.width());
+ item->setHeight(bounds.height());
+}
+
+void QQuickWebEngineCustomTouchHandle::setOpacity(float opacity)
+{
+ item->setOpacity(opacity);
+}
+
+void QQuickWebEngineCustomTouchHandle::setImage(int orientation)
+{
+ Q_UNUSED(orientation);
+}
+
+void QQuickWebEngineCustomTouchHandle::setVisible(bool visible)
+{
+ item->setVisible(visible);
+}
+
+QT_END_NAMESPACE
diff --git a/src/webenginequick/api/qquickwebenginecustomtouchhandle_p.h b/src/webenginequick/api/qquickwebenginecustomtouchhandle_p.h
new file mode 100644
index 000000000..a2adcea94
--- /dev/null
+++ b/src/webenginequick/api/qquickwebenginecustomtouchhandle_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKWEBENGINECUSTOMTOUCHHANDLE_P_H
+#define QQUICKWEBENGINECUSTOMTOUCHHANDLE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include "touch_handle_drawable_client.h"
+
+#include <QtWebEngineQuick/qtwebenginequickglobal.h>
+#include <QtCore/qobject.h>
+#include <QtQml/qqmlregistration.h>
+#include <QtCore/qrect.h>
+
+namespace QtWebEngineCore {
+class WebContentsAdapterClient;
+}
+
+QT_BEGIN_NAMESPACE
+
+class QQuickItem;
+
+class QQuickWebEngineCustomTouchHandle
+ : public QObject
+ , public QtWebEngineCore::TouchHandleDrawableDelegate
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(CustomTouchHandle)
+ QML_ADDED_IN_VERSION(6, 4)
+
+public:
+ QQuickWebEngineCustomTouchHandle();
+
+ QScopedPointer<QQuickItem> item;
+
+ void setBounds(const QRect &bounds) override;
+ void setVisible(bool visible) override;
+ void setOpacity(float opacity) override;
+ void setImage(int orientation) override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKWEBENGINECUSTOMTOUCHHANDLE_P_H
diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp
index 3aca79672..96b79a5b7 100644
--- a/src/webenginequick/api/qquickwebengineview.cpp
+++ b/src/webenginequick/api/qquickwebengineview.cpp
@@ -49,6 +49,7 @@
#include "qquickwebenginescriptcollection_p_p.h"
#include "qquickwebenginesettings_p.h"
#include "qquickwebenginetouchhandleprovider_p_p.h"
+#include "qquickwebenginecustomtouchhandle_p.h"
#include "qquickwebenginetouchselectionmenurequest_p.h"
#include "qquickwebengineview_p.h"
#include "qquickwebengineview_p_p.h"
@@ -168,6 +169,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
, m_zoomFactor(1.0)
, m_profileInitialized(false)
, m_contextMenuRequest(nullptr)
+ , m_touchHandleDelegate(nullptr)
{
memset(actions, 0, sizeof(actions));
@@ -1260,9 +1262,35 @@ void QQuickWebEngineViewPrivate::setToolTip(const QString &toolTipText)
ui()->showToolTip(toolTipText);
}
-QtWebEngineCore::TouchHandleDrawableClient *QQuickWebEngineViewPrivate::createTouchHandle(const QMap<int, QImage> &images)
+QtWebEngineCore::TouchHandleDrawableDelegate *
+QQuickWebEngineViewPrivate::createTouchHandleDelegate(const QMap<int, QImage> &images)
{
- return new QQuickWebEngineTouchHandle(ui(), images);
+ Q_Q(QQuickWebEngineView);
+ if (m_touchHandleDelegate) {
+ // lifecycle managed by Chromium's TouchHandleDrawable
+ QQmlContext *qmlContext = QQmlEngine::contextForObject(q);
+ QQuickWebEngineCustomTouchHandle *handle = new QQuickWebEngineCustomTouchHandle();
+ QQmlContext *context = new QQmlContext(qmlContext, handle);
+ context->setContextObject(handle);
+ QObject *delegate = m_touchHandleDelegate->create(context);
+ Q_ASSERT(delegate);
+ QQuickItem *item = qobject_cast<QQuickItem *>(delegate);
+ item->setParentItem(q);
+ handle->item.reset(item);
+ return handle;
+ } else {
+ QQuickItem *item = ui()->createTouchHandle();
+ Q_ASSERT(item);
+ QQmlEngine *engine = qmlEngine(item);
+ Q_ASSERT(engine);
+ QQuickWebEngineTouchHandleProvider *touchHandleProvider =
+ static_cast<QQuickWebEngineTouchHandleProvider *>(
+ engine->imageProvider(QQuickWebEngineTouchHandleProvider::identifier()));
+ Q_ASSERT(touchHandleProvider);
+ touchHandleProvider->init(images);
+ return new QQuickWebEngineTouchHandle(item);
+ }
+ return nullptr;
}
void QQuickWebEngineViewPrivate::showTouchSelectionMenu(QtWebEngineCore::TouchSelectionMenuController *menuController, const QRect &selectionBounds, const QSize &handleSize)
@@ -2383,18 +2411,9 @@ bool QQuickContextMenuBuilder::isMenuItemEnabled(ContextMenuItem menuItem)
Q_UNREACHABLE();
}
-
-QQuickWebEngineTouchHandle::QQuickWebEngineTouchHandle(QtWebEngineCore::UIDelegatesManager *ui, const QMap<int, QImage> &images)
+QQuickWebEngineTouchHandle::QQuickWebEngineTouchHandle(QQuickItem *item) : m_item(item)
{
- Q_ASSERT(ui);
- m_item.reset(ui->createTouchHandle());
-
- QQmlEngine *engine = qmlEngine(m_item.data());
- Q_ASSERT(engine);
- QQuickWebEngineTouchHandleProvider *touchHandleProvider =
- static_cast<QQuickWebEngineTouchHandleProvider *>(engine->imageProvider(QQuickWebEngineTouchHandleProvider::identifier()));
- Q_ASSERT(touchHandleProvider);
- touchHandleProvider->init(images);
+ m_item->setProperty("visible", false);
}
void QQuickWebEngineTouchHandle::setImage(int orientation)
@@ -2405,20 +2424,34 @@ void QQuickWebEngineTouchHandle::setImage(int orientation)
void QQuickWebEngineTouchHandle::setBounds(const QRect &bounds)
{
- m_item->setProperty("x", bounds.x());
- m_item->setProperty("y", bounds.y());
- m_item->setProperty("width", bounds.width());
- m_item->setProperty("height", bounds.height());
+ m_item->setX(bounds.x());
+ m_item->setY(bounds.y());
+ m_item->setWidth(bounds.width());
+ m_item->setHeight(bounds.height());
}
void QQuickWebEngineTouchHandle::setVisible(bool visible)
{
- m_item->setProperty("visible", visible);
+ m_item->setVisible(visible);
}
void QQuickWebEngineTouchHandle::setOpacity(float opacity)
{
- m_item->setProperty("opacity", opacity);
+ m_item->setOpacity(opacity);
+}
+
+void QQuickWebEngineView::setTouchHandleDelegate(QQmlComponent *delegate)
+{
+ if (d_ptr->m_touchHandleDelegate != delegate) {
+ d_ptr->m_touchHandleDelegate = delegate;
+ d_ptr->webContentsAdapter()->resetTouchSelectionController();
+ emit touchHandleDelegateChanged();
+ }
+}
+
+QQmlComponent *QQuickWebEngineView::touchHandleDelegate() const
+{
+ return d_ptr->m_touchHandleDelegate;
}
QT_END_NAMESPACE
diff --git a/src/webenginequick/api/qquickwebengineview_p.h b/src/webenginequick/api/qquickwebengineview_p.h
index 1a42726e4..867e37d06 100644
--- a/src/webenginequick/api/qquickwebengineview_p.h
+++ b/src/webenginequick/api/qquickwebengineview_p.h
@@ -64,6 +64,7 @@ class RenderWidgetHostViewQtDelegateQuick;
QT_BEGIN_NAMESPACE
class QQmlWebChannel;
+class QQmlComponent;
class QQuickContextMenuBuilder;
class QQuickWebEngineAction;
class QQuickWebEngineAuthenticationDialogRequest;
@@ -123,6 +124,8 @@ class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_PROPERTY(LifecycleState recommendedState READ recommendedState NOTIFY recommendedStateChanged REVISION(1,10) FINAL)
Q_PROPERTY(qint64 renderProcessPid READ renderProcessPid NOTIFY renderProcessPidChanged FINAL REVISION(1,11))
+ Q_PROPERTY(QQmlComponent *touchHandleDelegate READ touchHandleDelegate WRITE
+ setTouchHandleDelegate NOTIFY touchHandleDelegateChanged REVISION(0) FINAL)
QML_NAMED_ELEMENT(WebEngineView)
QML_ADDED_IN_VERSION(1, 0)
QML_EXTRA_VERSION(2, 0)
@@ -496,6 +499,9 @@ QT_WARNING_POP
LifecycleState recommendedState() const;
+ QQmlComponent *touchHandleDelegate() const;
+ void setTouchHandleDelegate(QQmlComponent *delegagte);
+
public Q_SLOTS:
void runJavaScript(const QString&, const QJSValue & = QJSValue());
Q_REVISION(1,3) void runJavaScript(const QString&, quint32 worldId, const QJSValue & = QJSValue());
@@ -565,6 +571,7 @@ Q_SIGNALS:
Q_REVISION(1,11) void canGoForwardChanged();
Q_REVISION(1,12) void newWindowRequested(QQuickWebEngineNewWindowRequest *request);
Q_REVISION(6,3) void touchSelectionMenuRequested(QQuickWebEngineTouchSelectionMenuRequest *request);
+ Q_REVISION(6,4) void touchHandleDelegateChanged();
protected:
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
diff --git a/src/webenginequick/api/qquickwebengineview_p_p.h b/src/webenginequick/api/qquickwebengineview_p_p.h
index a10c12481..8194dd897 100644
--- a/src/webenginequick/api/qquickwebengineview_p_p.h
+++ b/src/webenginequick/api/qquickwebengineview_p_p.h
@@ -51,9 +51,11 @@
// We mean it.
//
+#include "qquickwebenginecustomtouchhandle_p.h"
#include "qquickwebengineview_p.h"
#include "render_view_context_menu_qt.h"
#include "touch_handle_drawable_client.h"
+#include "ui_delegates_manager.h"
#include "web_contents_adapter_client.h"
#include <QtCore/qcompilerdetection.h>
@@ -153,7 +155,7 @@ public:
QObject *dragSource() const override;
bool isEnabled() const override;
void setToolTip(const QString &toolTipText) override;
- QtWebEngineCore::TouchHandleDrawableClient *createTouchHandle(const QMap<int, QImage> &images) override;
+ QtWebEngineCore::TouchHandleDrawableDelegate *createTouchHandleDelegate(const QMap<int, QImage> &images) override;
void showTouchSelectionMenu(QtWebEngineCore::TouchSelectionMenuController *, const QRect &, const QSize &) override;
void hideTouchSelectionMenu() override;
const QObject *holdingQObject() const override;
@@ -209,6 +211,7 @@ private:
QWebEngineContextMenuRequest *m_contextMenuRequest;
QScopedPointer<QQuickWebEngineScriptCollection> m_scriptCollection;
QPointer<QQuickWebEngineFaviconProvider> m_faviconProvider;
+ QQmlComponent *m_touchHandleDelegate;
};
#ifndef QT_NO_ACCESSIBILITY
@@ -249,9 +252,11 @@ private:
QObject *m_menu;
};
-class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineTouchHandle : public QtWebEngineCore::TouchHandleDrawableClient {
+class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineTouchHandle
+ : public QtWebEngineCore::TouchHandleDrawableDelegate
+{
public:
- QQuickWebEngineTouchHandle(QtWebEngineCore::UIDelegatesManager *ui, const QMap<int, QImage> &images);
+ QQuickWebEngineTouchHandle(QQuickItem *item = nullptr);
void setImage(int orientation) override;
void setBounds(const QRect &bounds) override;