From 90c285c1ac4aaec02d15bec2c16d1e3f035a9273 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 7 Apr 2013 20:19:21 +0200 Subject: [PATCH] Added function to return focused element on page. WebView/WebPage::activeElement --- src/lib/webview/webpage.cpp | 6 ++++++ src/lib/webview/webpage.h | 1 + src/lib/webview/webview.cpp | 6 ++++++ src/lib/webview/webview.h | 1 + 4 files changed, 14 insertions(+) diff --git a/src/lib/webview/webpage.cpp b/src/lib/webview/webpage.cpp index 6079c912c..ac094f834 100644 --- a/src/lib/webview/webpage.cpp +++ b/src/lib/webview/webpage.cpp @@ -186,6 +186,12 @@ bool WebPage::containsRejectedCerts(const QList &certs) return matches == certs.count(); } +QWebElement WebPage::activeElement() const +{ + QRect activeRect = inputMethodQuery(Qt::ImMicroFocus).toRect(); + return mainFrame()->hitTestContent(activeRect.center()).element(); +} + bool WebPage::isRunningLoop() { return m_runningLoop; diff --git a/src/lib/webview/webpage.h b/src/lib/webview/webpage.h index 5ac4811ae..edd48474b 100644 --- a/src/lib/webview/webpage.h +++ b/src/lib/webview/webpage.h @@ -78,6 +78,7 @@ public: void addRejectedCerts(const QList &certs); bool containsRejectedCerts(const QList &certs); + QWebElement activeElement() const; QString userAgentForUrl(const QUrl &url) const; static bool isPointerSafeToUse(WebPage* page); diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index 13f065660..7a4901168 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -225,6 +225,12 @@ bool WebView::hasRss() const return m_hasRss; } +QWebElement WebView::activeElement() const +{ + QRect activeRect = inputMethodQuery(Qt::ImMicroFocus).toRect(); + return page()->mainFrame()->hitTestContent(activeRect.center()).element(); +} + bool WebView::isUrlValid(const QUrl &url) { const QString &urlScheme = url.scheme(); diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index 0d288b127..1ffc036a3 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -49,6 +49,7 @@ public: void fakeLoadingProgress(int progress); bool hasRss() const; + QWebElement activeElement() const; void addNotification(QWidget* notif); bool eventFilter(QObject* obj, QEvent* event);