summaryrefslogtreecommitdiffstats
path: root/src/webengine
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2019-02-05 15:07:24 +0100
committerSzabolcs David <davidsz@inf.u-szeged.hu>2019-02-19 14:48:34 +0000
commitfd1a34045b09d9c7e927d814b87617c2424e68a8 (patch)
tree12643f1840f754593d23cacfee35d2a72205b6f0 /src/webengine
parent14988cd6b243986f501edbba678796ea5efe2c28 (diff)
Add a way to customize tooltips in WebEngineView
Implement a tooltipRequested signal and a corresponding request class to expose tooltip information to the users. Task-number: QTBUG-59290 Change-Id: I4e31773c62a65d6f340aaa74237cb0076252cd5b Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/api/qquickwebenginedialogrequests.cpp110
-rw-r--r--src/webengine/api/qquickwebenginedialogrequests_p.h33
-rw-r--r--src/webengine/api/qquickwebengineview.cpp8
-rw-r--r--src/webengine/api/qquickwebengineview_p.h4
-rw-r--r--src/webengine/doc/src/webengineview_lgpl.qdoc12
-rw-r--r--src/webengine/plugin/plugin.cpp3
-rw-r--r--src/webengine/ui_delegates_manager.cpp6
7 files changed, 171 insertions, 5 deletions
diff --git a/src/webengine/api/qquickwebenginedialogrequests.cpp b/src/webengine/api/qquickwebenginedialogrequests.cpp
index b1f52a6b1..01e757375 100644
--- a/src/webengine/api/qquickwebenginedialogrequests.cpp
+++ b/src/webengine/api/qquickwebenginedialogrequests.cpp
@@ -44,6 +44,9 @@
#include "file_picker_controller.h"
#include "web_contents_adapter_client.h"
+#include <QCursor>
+#include <QQuickItem>
+
QT_BEGIN_NAMESPACE
using namespace QtWebEngineCore;
@@ -823,4 +826,111 @@ void QQuickWebEngineFormValidationMessageRequest::setAccepted(bool accepted)
m_accepted = accepted;
}
+///////////////////////////////////////////////////////////////////////////////
+
+/*!
+ \qmltype TooltipRequest
+ \instantiates QQuickWebEngineTooltipRequest
+ \inqmlmodule QtWebEngine
+ \since QtWebEngine 1.10
+
+ \brief A request for showing a tooltip to the user.
+*/
+
+QQuickWebEngineTooltipRequest::QQuickWebEngineTooltipRequest(
+ const QString &text, QObject *parent):
+ QObject(parent)
+ , m_text(text)
+ , m_type(text.isEmpty() ? RequestType::Hide : RequestType::Show)
+ , m_accepted(false)
+{
+ Q_ASSERT(parent);
+ if (QQuickItem *view = qobject_cast<QQuickItem *>(parent))
+ m_position = view->mapFromGlobal(view->cursor().pos()).toPoint();
+}
+
+QQuickWebEngineTooltipRequest::~QQuickWebEngineTooltipRequest()
+{
+
+}
+
+/*!
+ \qmlproperty int TooltipRequest::x
+ \readonly
+
+ The x coordinate of the top-left corner of the requested tooltip.
+*/
+
+int QQuickWebEngineTooltipRequest::x() const
+{
+ return m_position.x();
+}
+
+/*!
+ \qmlproperty int TooltipRequest::y
+ \readonly
+
+ The y coordinate of the top-left corner of the requested tooltip.
+*/
+
+int QQuickWebEngineTooltipRequest::y() const
+{
+ return m_position.y();
+}
+
+/*!
+ \qmlproperty bool TooltipRequest::text
+ \readonly
+
+ The text of the tooltip. It contains an empty string when the
+ tooltip should be hidden.
+*/
+
+
+QString QQuickWebEngineTooltipRequest::text() const
+{
+ return m_text;
+}
+
+/*!
+ \qmlproperty enumeration TooltipRequest::type
+ \readonly
+
+ The type of the tooltip request.
+
+ \value TooltipRequest.Show
+ The tooltip should be shown.
+ \value TooltipRequest.Hide
+ The tooltip should be hidden.
+*/
+
+QQuickWebEngineTooltipRequest::RequestType QQuickWebEngineTooltipRequest::type() const
+{
+ return m_type;
+}
+
+/*!
+ \qmlproperty bool TooltipRequest::accepted
+
+ Indicates whether the tooltip request has been accepted
+ by the signal handler.
+
+ If the property is \c false after any signal handlers
+ for WebEngineView::tooltipRequested have been executed,
+ a default tooltip will be shown.
+ To prevent this, set \c {request.accepted} to \c true.
+
+ The default is \c false.
+*/
+
+bool QQuickWebEngineTooltipRequest::isAccepted() const
+{
+ return m_accepted;
+}
+
+void QQuickWebEngineTooltipRequest::setAccepted(bool accepted)
+{
+ m_accepted = accepted;
+}
+
QT_END_NAMESPACE
diff --git a/src/webengine/api/qquickwebenginedialogrequests_p.h b/src/webengine/api/qquickwebenginedialogrequests_p.h
index cdb10c26b..5e3f7c547 100644
--- a/src/webengine/api/qquickwebenginedialogrequests_p.h
+++ b/src/webengine/api/qquickwebenginedialogrequests_p.h
@@ -260,6 +260,39 @@ private:
friend class QQuickWebEngineViewPrivate;
};
+class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineTooltipRequest : public QObject {
+ Q_OBJECT
+public:
+ enum RequestType {
+ Show,
+ Hide,
+ };
+ Q_ENUM(RequestType)
+ Q_PROPERTY(int x READ x CONSTANT FINAL)
+ Q_PROPERTY(int y READ y CONSTANT FINAL)
+ Q_PROPERTY(QString text READ text CONSTANT FINAL)
+ Q_PROPERTY(RequestType type READ type CONSTANT FINAL)
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted FINAL)
+
+ ~QQuickWebEngineTooltipRequest();
+ int x() const;
+ int y() const;
+ QString text() const;
+ RequestType type() const;
+ bool isAccepted() const;
+ void setAccepted(bool accepted);
+
+private:
+ QQuickWebEngineTooltipRequest(const QString &text = QString(),
+ QObject *parent = nullptr);
+ QPoint m_position;
+ QString m_text;
+ RequestType m_type;
+ bool m_accepted;
+ friend class QQuickWebEngineViewPrivate;
+ Q_DISABLE_COPY(QQuickWebEngineTooltipRequest)
+};
+
QT_END_NAMESPACE
#endif // QQUICKWEBENGINDIALOGREQUESTS_H
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index e7b2d8c9c..b6b542f15 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -1210,7 +1210,13 @@ bool QQuickWebEngineViewPrivate::isEnabled() const
void QQuickWebEngineViewPrivate::setToolTip(const QString &toolTipText)
{
- ui()->showToolTip(toolTipText);
+ Q_Q(QQuickWebEngineView);
+ QQuickWebEngineTooltipRequest *request = new QQuickWebEngineTooltipRequest(toolTipText, q);
+ // mark the object for gc by creating temporary jsvalue
+ qmlEngine(q)->newQObject(request);
+ Q_EMIT q->tooltipRequested(request);
+ if (!request->isAccepted())
+ ui()->showToolTip(toolTipText);
}
QtWebEngineCore::TouchHandleDrawableClient *QQuickWebEngineViewPrivate::createTouchHandle(const QMap<int, QImage> &images)
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index c851dcb8d..abbe40f53 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -76,6 +76,7 @@ class QQuickWebEngineNavigationRequest;
class QQuickWebEngineNewViewRequest;
class QQuickWebEngineProfile;
class QQuickWebEngineSettings;
+class QQuickWebEngineTooltipRequest;
class QQuickWebEngineFormValidationMessageRequest;
class QQuickWebEngineViewPrivate;
class QWebEngineQuotaRequest;
@@ -104,7 +105,7 @@ private:
const bool m_toggleOn;
};
-#define LATEST_WEBENGINEVIEW_REVISION 9
+#define LATEST_WEBENGINEVIEW_REVISION 10
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_OBJECT
@@ -552,6 +553,7 @@ Q_SIGNALS:
Q_REVISION(7) void registerProtocolHandlerRequested(const QWebEngineRegisterProtocolHandlerRequest &request);
Q_REVISION(8) void printRequested();
Q_REVISION(9) void selectClientCertificate(QQuickWebEngineClientCertificateSelection *clientCertSelection);
+ Q_REVISION(10) void tooltipRequested(QQuickWebEngineTooltipRequest *request);
#if QT_CONFIG(webengine_testsupport)
void testSupportChanged();
diff --git a/src/webengine/doc/src/webengineview_lgpl.qdoc b/src/webengine/doc/src/webengineview_lgpl.qdoc
index a6f2af39e..3b375c532 100644
--- a/src/webengine/doc/src/webengineview_lgpl.qdoc
+++ b/src/webengine/doc/src/webengineview_lgpl.qdoc
@@ -1493,3 +1493,15 @@
\sa WebEngineClientCertificateSelection
*/
+
+/*!
+ \qmlsignal WebEngineView::tooltipRequested(TooltipRequest request)
+ \since QtWebEngine 1.10
+
+ This signal is emitted when the web page wants to show a tooltip at
+ a specified position.
+
+ \note Signal handlers need to call \c{request.accepted = true} to prevent a default tooltip from showing up.
+
+ \sa TooltipRequest
+*/
diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp
index 82a76760d..a4f84fe4d 100644
--- a/src/webengine/plugin/plugin.cpp
+++ b/src/webengine/plugin/plugin.cpp
@@ -95,6 +95,7 @@ public:
qmlRegisterType<QQuickWebEngineView, 7>(uri, 1, 7, "WebEngineView");
qmlRegisterType<QQuickWebEngineView, 8>(uri, 1, 8, "WebEngineView");
qmlRegisterType<QQuickWebEngineView, 9>(uri, 1, 9, "WebEngineView");
+ qmlRegisterType<QQuickWebEngineView, 10>(uri, 1, 10, "WebEngineView");
qmlRegisterType<QQuickWebEngineProfile>(uri, 1, 1, "WebEngineProfile");
qmlRegisterType<QQuickWebEngineProfile, 1>(uri, 1, 2, "WebEngineProfile");
qmlRegisterType<QQuickWebEngineProfile, 2>(uri, 1, 3, "WebEngineProfile");
@@ -163,6 +164,8 @@ public:
qmlRegisterUncreatableType<QQuickWebEngineClientCertificateOption>(uri, 1, 9, "WebEngineClientCertificateOption",
tr("Cannot create a separate instance of WebEngineClientCertificateOption"));
qmlRegisterUncreatableType<QWebEngineNotification>(uri, 1, 9, "WebEngineNotification", msgUncreatableType("WebEngineNotification"));
+ qmlRegisterUncreatableType<QQuickWebEngineTooltipRequest>(uri, 1, 10, "TooltipRequest",
+ msgUncreatableType("TooltipRequest"));
}
private:
diff --git a/src/webengine/ui_delegates_manager.cpp b/src/webengine/ui_delegates_manager.cpp
index da120ab69..d324fe75d 100644
--- a/src/webengine/ui_delegates_manager.cpp
+++ b/src/webengine/ui_delegates_manager.cpp
@@ -539,14 +539,14 @@ void UIDelegatesManager::showMenu(QObject *menu)
void UIDelegatesManager::showToolTip(const QString &text)
{
- if (!ensureComponentLoaded(ToolTip))
- return;
-
if (text.isEmpty()) {
m_toolTip.reset();
return;
}
+ if (!ensureComponentLoaded(ToolTip))
+ return;
+
if (!m_toolTip.isNull())
return;