summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2019-09-05 03:35:35 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2019-09-05 16:07:12 +0300
commit34c2a6ebc0d579f08c18ce4e895fd3a9fadf7370 (patch)
treed5bd7a5f15e814298ef29920f157155b2ca3e24e /Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp
parent2c94535e5c4dc6ad22bc2f34f76f5a5da6cf652e (diff)
Import QtWebKit commit 55ed4f703de7bfbb0f554cd05dccff4c6db1bba3
Change-Id: I5063dd830f1cedda84e1ae66b0e659ffe7efa22c Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp')
-rw-r--r--Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp b/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp
index 9b2ba7dfd..2d498c5b8 100644
--- a/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp
+++ b/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp
@@ -32,7 +32,14 @@
#include "config.h"
#include "InspectorClientWebPage.h"
+#include <QApplication>
+#include <QClipboard>
+#include <QContextMenuEvent>
+
+#include <qwebelement.h>
#include <qwebframe.h>
+#include <qwebframe_p.h>
+#include <qwebpage_p.h>
using namespace WebKit;
@@ -67,6 +74,18 @@ QWebPage* InspectorClientWebPage::createWindow(QWebPage::WebWindowType)
return page;
}
+bool InspectorClientWebPage::event(QEvent* ev)
+{
+ if (ev->type() == QEvent::ContextMenu) {
+ auto* contextMenuEvent = static_cast<QContextMenuEvent*>(ev);
+
+ if (contextMenuEvent)
+ m_clickPos = contextMenuEvent->pos();
+ }
+
+ return QWebPage::event(ev);
+}
+
void InspectorClientWebPage::javaScriptWindowObjectCleared()
{
QVariant inspectorJavaScriptWindowObjects = property("_q_inspectorJavaScriptWindowObjects");
@@ -83,3 +102,28 @@ void InspectorClientWebPage::javaScriptWindowObjectCleared()
}
}
+void InspectorClientWebPage::triggerAction(WebAction action, bool checked)
+{
+ const QWebHitTestResult hitTestResult = mainFrame()->hitTestContent(m_clickPos);
+
+ if (hitTestResult.imageUrl().isValid() && hitTestResult.element().hasAttribute(QStringLiteral("data-url"))) {
+ switch (action) {
+ case OpenImageInNewWindow: {
+ auto* frame = static_cast<QWebFramePrivate*>(hitTestResult.frame()->d);
+
+ if (frame) {
+ QWebPagePrivate::openNewWindow(QUrl(hitTestResult.element().attribute(QStringLiteral("data-url"))), frame->frame);
+ return;
+ }
+ }
+
+ case CopyImageUrlToClipboard:
+ QApplication::clipboard()->setText(hitTestResult.element().attribute(QStringLiteral("data-url")));
+ return;
+ default:
+ break;
+ }
+ }
+
+ QWebPage::triggerAction(action, checked);
+}