summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2022-05-04 23:02:58 +0200
committerMichal Klocek <michal.klocek@qt.io>2022-05-10 19:54:01 +0000
commitf02fb09627a0023c5b6988c1067486fef3957d83 (patch)
treedf4bb6029412be8e1572facd634d0310d0e13274 /src
parentc92314eecb1c6140c80ab232197d5bd0ddfa26fa (diff)
Cleanup custom touch handles implementation
Do not introduce extra class nor dummy QML element. Fix docs. Change-Id: I9848f6865cd585779d89fe387ad97c27e7450eb9 Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/webenginequick/CMakeLists.txt2
-rw-r--r--src/webenginequick/api/qquickwebenginetouchhandle.cpp (renamed from src/webenginequick/api/qquickwebenginecustomtouchhandle.cpp)42
-rw-r--r--src/webenginequick/api/qquickwebenginetouchhandle_p.h (renamed from src/webenginequick/api/qquickwebenginecustomtouchhandle_p.h)32
-rw-r--r--src/webenginequick/api/qquickwebengineview.cpp42
-rw-r--r--src/webenginequick/api/qquickwebengineview_p_p.h17
-rw-r--r--src/webenginequick/doc/src/custom_touch_handle.qdoc52
-rw-r--r--src/webenginequick/doc/src/webengineview_lgpl.qdoc24
-rw-r--r--src/webenginequick/ui_delegates_manager.h1
8 files changed, 62 insertions, 150 deletions
diff --git a/src/webenginequick/CMakeLists.txt b/src/webenginequick/CMakeLists.txt
index fa5ea3f53..fb62d21b2 100644
--- a/src/webenginequick/CMakeLists.txt
+++ b/src/webenginequick/CMakeLists.txt
@@ -24,7 +24,7 @@ qt_internal_add_qml_module(WebEngineQuick
api/qquickwebenginesingleton.cpp api/qquickwebenginesingleton_p.h
api/qquickwebenginetouchhandleprovider.cpp
api/qquickwebenginetouchhandleprovider_p_p.h
- api/qquickwebenginecustomtouchhandle.cpp api/qquickwebenginecustomtouchhandle_p.h
+ api/qquickwebenginetouchhandle.cpp api/qquickwebenginetouchhandle_p.h
api/qquickwebenginetouchselectionmenurequest.cpp
api/qquickwebenginetouchselectionmenurequest_p.h
api/qquickwebenginetouchselectionmenurequest_p_p.h
diff --git a/src/webenginequick/api/qquickwebenginecustomtouchhandle.cpp b/src/webenginequick/api/qquickwebenginetouchhandle.cpp
index 5bd12e6d6..fb00384e3 100644
--- a/src/webenginequick/api/qquickwebenginecustomtouchhandle.cpp
+++ b/src/webenginequick/api/qquickwebenginetouchhandle.cpp
@@ -37,47 +37,45 @@
**
****************************************************************************/
-#include "qquickwebenginecustomtouchhandle_p.h"
+#include "qquickwebenginetouchhandle_p.h"
+#include "qquickwebenginetouchhandleprovider_p_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.
-*/
+QQuickWebEngineTouchHandle::QQuickWebEngineTouchHandle() : QObject(nullptr), m_hasImage(false) { }
-QQuickWebEngineCustomTouchHandle::QQuickWebEngineCustomTouchHandle()
- : QObject(nullptr)
+void QQuickWebEngineTouchHandle::setBounds(const QRect &bounds)
{
+ m_item->setX(bounds.x());
+ m_item->setY(bounds.y());
+ m_item->setWidth(bounds.width());
+ m_item->setHeight(bounds.height());
}
-void QQuickWebEngineCustomTouchHandle::setBounds(const QRect &bounds)
+void QQuickWebEngineTouchHandle::setOpacity(float opacity)
{
- item->setX(bounds.x());
- item->setY(bounds.y());
- item->setWidth(bounds.width());
- item->setHeight(bounds.height());
+ m_item->setOpacity(opacity);
}
-void QQuickWebEngineCustomTouchHandle::setOpacity(float opacity)
+void QQuickWebEngineTouchHandle::setImage(int orientation)
{
- item->setOpacity(opacity);
+ if (m_hasImage) {
+ QUrl url = QQuickWebEngineTouchHandleProvider::url(orientation);
+ m_item->setProperty("source", url);
+ }
}
-void QQuickWebEngineCustomTouchHandle::setImage(int orientation)
+void QQuickWebEngineTouchHandle::setVisible(bool visible)
{
- Q_UNUSED(orientation);
+ m_item->setVisible(visible);
}
-void QQuickWebEngineCustomTouchHandle::setVisible(bool visible)
+void QQuickWebEngineTouchHandle::setItem(QQuickItem *item, bool hasImage)
{
- item->setVisible(visible);
+ m_hasImage = hasImage;
+ m_item.reset(item);
}
QT_END_NAMESPACE
diff --git a/src/webenginequick/api/qquickwebenginecustomtouchhandle_p.h b/src/webenginequick/api/qquickwebenginetouchhandle_p.h
index a2adcea94..7a5cbe6d9 100644
--- a/src/webenginequick/api/qquickwebenginecustomtouchhandle_p.h
+++ b/src/webenginequick/api/qquickwebenginetouchhandle_p.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QQUICKWEBENGINECUSTOMTOUCHHANDLE_P_H
-#define QQUICKWEBENGINECUSTOMTOUCHHANDLE_P_H
+#ifndef QQUICKWEBENGINETOUCHHANDLE_P_H
+#define QQUICKWEBENGINETOUCHHANDLE_P_H
//
// W A R N I N G
@@ -51,11 +51,9 @@
// 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>
+#include <QtCore/qobject.h>
namespace QtWebEngineCore {
class WebContentsAdapterClient;
@@ -64,26 +62,22 @@ class WebContentsAdapterClient;
QT_BEGIN_NAMESPACE
class QQuickItem;
-
-class QQuickWebEngineCustomTouchHandle
- : public QObject
- , public QtWebEngineCore::TouchHandleDrawableDelegate
+class QQuickWebEngineTouchHandle : public QtWebEngineCore::TouchHandleDrawableDelegate,
+ public QObject
{
- Q_OBJECT
- QML_NAMED_ELEMENT(CustomTouchHandle)
- QML_ADDED_IN_VERSION(6, 4)
-
public:
- QQuickWebEngineCustomTouchHandle();
-
- QScopedPointer<QQuickItem> item;
-
+ QQuickWebEngineTouchHandle();
+ void setImage(int orintation) override;
void setBounds(const QRect &bounds) override;
void setVisible(bool visible) override;
void setOpacity(float opacity) override;
- void setImage(int orientation) override;
+ void setItem(QQuickItem *item, bool hasImage);
+
+private:
+ QScopedPointer<QQuickItem> m_item;
+ bool m_hasImage;
};
QT_END_NAMESPACE
-#endif // QQUICKWEBENGINECUSTOMTOUCHHANDLE_P_H
+#endif // QQUICKWEBENGINETOUCHHANDLE_P_H
diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp
index 96b79a5b7..e0e6b0372 100644
--- a/src/webenginequick/api/qquickwebengineview.cpp
+++ b/src/webenginequick/api/qquickwebengineview.cpp
@@ -49,7 +49,7 @@
#include "qquickwebenginescriptcollection_p_p.h"
#include "qquickwebenginesettings_p.h"
#include "qquickwebenginetouchhandleprovider_p_p.h"
-#include "qquickwebenginecustomtouchhandle_p.h"
+#include "qquickwebenginetouchhandle_p.h"
#include "qquickwebenginetouchselectionmenurequest_p.h"
#include "qquickwebengineview_p.h"
#include "qquickwebengineview_p_p.h"
@@ -1266,18 +1266,17 @@ QtWebEngineCore::TouchHandleDrawableDelegate *
QQuickWebEngineViewPrivate::createTouchHandleDelegate(const QMap<int, QImage> &images)
{
Q_Q(QQuickWebEngineView);
+ // lifecycle managed by Chromium's TouchHandleDrawable
+ QQuickWebEngineTouchHandle *handle = new QQuickWebEngineTouchHandle();
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;
+ handle->setItem(item, false);
} else {
QQuickItem *item = ui()->createTouchHandle();
Q_ASSERT(item);
@@ -1288,9 +1287,9 @@ QQuickWebEngineViewPrivate::createTouchHandleDelegate(const QMap<int, QImage> &i
engine->imageProvider(QQuickWebEngineTouchHandleProvider::identifier()));
Q_ASSERT(touchHandleProvider);
touchHandleProvider->init(images);
- return new QQuickWebEngineTouchHandle(item);
+ handle->setItem(item, true);
}
- return nullptr;
+ return handle;
}
void QQuickWebEngineViewPrivate::showTouchSelectionMenu(QtWebEngineCore::TouchSelectionMenuController *menuController, const QRect &selectionBounds, const QSize &handleSize)
@@ -2411,35 +2410,6 @@ bool QQuickContextMenuBuilder::isMenuItemEnabled(ContextMenuItem menuItem)
Q_UNREACHABLE();
}
-QQuickWebEngineTouchHandle::QQuickWebEngineTouchHandle(QQuickItem *item) : m_item(item)
-{
- m_item->setProperty("visible", false);
-}
-
-void QQuickWebEngineTouchHandle::setImage(int orientation)
-{
- QUrl url = QQuickWebEngineTouchHandleProvider::url(orientation);
- m_item->setProperty("source", url);
-}
-
-void QQuickWebEngineTouchHandle::setBounds(const QRect &bounds)
-{
- 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->setVisible(visible);
-}
-
-void QQuickWebEngineTouchHandle::setOpacity(float opacity)
-{
- m_item->setOpacity(opacity);
-}
-
void QQuickWebEngineView::setTouchHandleDelegate(QQmlComponent *delegate)
{
if (d_ptr->m_touchHandleDelegate != delegate) {
diff --git a/src/webenginequick/api/qquickwebengineview_p_p.h b/src/webenginequick/api/qquickwebengineview_p_p.h
index 8194dd897..a48fb1c2c 100644
--- a/src/webenginequick/api/qquickwebengineview_p_p.h
+++ b/src/webenginequick/api/qquickwebengineview_p_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include "qquickwebenginecustomtouchhandle_p.h"
+#include "qquickwebenginetouchhandle_p.h"
#include "qquickwebengineview_p.h"
#include "render_view_context_menu_qt.h"
#include "touch_handle_drawable_client.h"
@@ -252,21 +252,6 @@ private:
QObject *m_menu;
};
-class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineTouchHandle
- : public QtWebEngineCore::TouchHandleDrawableDelegate
-{
-public:
- QQuickWebEngineTouchHandle(QQuickItem *item = nullptr);
-
- void setImage(int orientation) override;
- void setBounds(const QRect &bounds) override;
- void setVisible(bool visible) override;
- void setOpacity(float opacity) override;
-
-private:
- QScopedPointer<QQuickItem> m_item;
-};
-
QT_END_NAMESPACE
#endif // QQUICKWEBENGINEVIEW_P_P_H
diff --git a/src/webenginequick/doc/src/custom_touch_handle.qdoc b/src/webenginequick/doc/src/custom_touch_handle.qdoc
deleted file mode 100644
index 8ef193d16..000000000
--- a/src/webenginequick/doc/src/custom_touch_handle.qdoc
+++ /dev/null
@@ -1,52 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2022 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \qmltype CustomTouchHandle
- \inqmlmodule QtWebEngine
- \since QtWebEngine 6.4
-
- \brief Data class for representing the touch handle QML delegate.
-
- The handle's position, opacity, and visibility are updated automatically.
- The delegate should be a QML Item or any QML type which inherits it.
-
- The following code uses a custom touch handle delegate:
-
- \code
- WebEngineView {
- // ...
- touchHandleDelegate: Rectangle {
- color: "red"
- }
- // ...
- }
- \endcode
-
- \note The bounding box which propagates the touch event is provided by
- Chromium and the text selection can be moved even if there is no handle drawn.
-*/
diff --git a/src/webenginequick/doc/src/webengineview_lgpl.qdoc b/src/webenginequick/doc/src/webengineview_lgpl.qdoc
index ae3ea1c23..6e3d9ebe3 100644
--- a/src/webenginequick/doc/src/webengineview_lgpl.qdoc
+++ b/src/webenginequick/doc/src/webengineview_lgpl.qdoc
@@ -1493,11 +1493,29 @@
*/
/*!
- \qmlproperty CustomTouchHandle WebEngineView::touchHandleDelegate
+ \qmlproperty Component WebEngineView::touchHandleDelegate
\since QtWebEngine 6.4
- If a QML Item is set, the default touch handles will not be shown and
- this item will be displayed as touch handles.
+ The \a touchHandleDelegate provides a template defining visual touch handles instantiated by the view
+ whenever touch selection handling is required.
+
+ The handle's position, opacity, and visibility are updated automatically.
+ The delegate should be a QML Item or any QML type which inherits it.
+
+ \note If no QML Item is set, the default touch handles will be shown.
+
+ The following code uses a custom touch handle delegate:
+
+ \code
+ WebEngineView {
+ // ...
+ touchHandleDelegate: Rectangle {
+ color: "red"
+ }
+ // ...
+ }
+ \endcode
+*/
\sa {WebEngine Qt Quick Custom Touch Handle Example}
*/
diff --git a/src/webenginequick/ui_delegates_manager.h b/src/webenginequick/ui_delegates_manager.h
index 1632a9568..0f515d4be 100644
--- a/src/webenginequick/ui_delegates_manager.h
+++ b/src/webenginequick/ui_delegates_manager.h
@@ -46,7 +46,6 @@
#include <QtCore/qsharedpointer.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
-#include "api/qquickwebenginecustomtouchhandle_p.h"
#define FOR_EACH_COMPONENT_TYPE(F, SEPARATOR) \
F(Menu, menu) SEPARATOR \