diff options
Diffstat (limited to 'Source/WebKit/qt/WidgetSupport')
| -rw-r--r-- | Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.cpp | 44 | ||||
| -rw-r--r-- | Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.h | 7 |
2 files changed, 51 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); +} diff --git a/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.h b/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.h index 59cf74135..d996587cc 100644 --- a/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.h +++ b/Source/WebKit/qt/WidgetSupport/InspectorClientWebPage.h @@ -43,9 +43,16 @@ public: InspectorClientWebPage(); QWebPage* createWindow(QWebPage::WebWindowType) final; + bool event(QEvent*) final; public Q_SLOTS: void javaScriptWindowObjectCleared(); + +protected: + void triggerAction(WebAction, bool checked = false) final; + +private: + QPoint m_clickPos; }; } // namespace WebKit |
