summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2013-03-11 18:59:50 +0100
committerAndrea Diamantini <adjam7@gmail.com>2013-03-11 18:59:50 +0100
commitc7fa562d5e2bf312700b1f02863535887f80ba48 (patch)
tree6aeba501ef3981a09ed1217b072e08a4b593de7c
parentSupporting panel (again) :) (diff)
downloadrekonq-c7fa562d5e2bf312700b1f02863535887f80ba48.tar.xz
Guess if url is on target blank and show different contextual actions
I would not re-enable the "describing" icon part because it is NOT really working here. I'm having troubles when I show the icon and switch pages. Hope this is enough BUG: 237095 BUG: 303911
-rw-r--r--src/webtab/webview.cpp78
-rw-r--r--src/webtab/webview.h4
2 files changed, 73 insertions, 9 deletions
diff --git a/src/webtab/webview.cpp b/src/webtab/webview.cpp
index c6aa94e6..44a54156 100644
--- a/src/webtab/webview.cpp
+++ b/src/webtab/webview.cpp
@@ -64,6 +64,7 @@
#include <QTimer>
#include <QApplication>
+#include <QBitmap>
#include <QClipboard>
#include <QContextMenuEvent>
#include <QLabel>
@@ -72,6 +73,11 @@
#include <QWebHistory>
#include <QNetworkRequest>
+#ifdef Q_WS_X11
+#include <X11/Xlib.h>
+#include <fixx11h.h>
+#endif
+
// needed for the spellCheck
static QVariant execJScript(QWebHitTestResult result, const QString& script)
@@ -99,6 +105,7 @@ WebView::WebView(QWidget* parent, bool isPrivateBrowsing)
, m_isViewSmoothScrolling(false)
, m_accessKeysPressed(false)
, m_accessKeysActive(false)
+ , m_isExternalLinkHovered(false)
, m_parentTab(qobject_cast<WebTab *>(parent))
, m_isPrivateBrowsing(isPrivateBrowsing)
{
@@ -372,15 +379,26 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
sendByMailAction->setData(m_contextMenuHitResult.linkUrl());
sendByMailAction->setText(i18n("Share link"));
- a = new KAction(KIcon("tab-new"), i18n("Open in New &Tab"), &menu);
- a->setData(m_contextMenuHitResult.linkUrl());
- connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewTab()));
- menu.addAction(a);
- a = new KAction(KIcon("window-new"), i18n("Open in New &Window"), &menu);
- a->setData(m_contextMenuHitResult.linkUrl());
- connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewWindow()));
- menu.addAction(a);
+ if (m_isExternalLinkHovered)
+ {
+ a = new KAction(KIcon("view-close"), i18n("Open &Here"), this);
+ a->setData(m_contextMenuHitResult.linkUrl());
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkHere()));
+ menu.addAction(a);
+ }
+ else
+ {
+ a = new KAction(KIcon("tab-new"), i18n("Open in New &Tab"), &menu);
+ a->setData(m_contextMenuHitResult.linkUrl());
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewTab()));
+ menu.addAction(a);
+
+ a = new KAction(KIcon("window-new"), i18n("Open in New &Window"), &menu);
+ a->setData(m_contextMenuHitResult.linkUrl());
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewWindow()));
+ menu.addAction(a);
+ }
if (webwin)
{
@@ -482,7 +500,8 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
openInNewTabAction->setData( QUrl::fromUserInput(selectedText()) );
connect(openInNewTabAction, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewTab()));
menu.addAction(openInNewTabAction);
- //open selected text url in a new window
+
+ // open selected text url in a new window
QAction * const openInNewWindowAction = new KAction(KIcon("window-new"),
i18n("Open '%1' in New Window", truncatedUrl), &menu);
openInNewWindowAction->setData( QUrl::fromUserInput(selectedText()) );
@@ -646,6 +665,8 @@ void WebView::mouseMoveEvent(QMouseEvent *event)
{
QPoint mousePos = event->pos();
+ guessHoveredLink(mousePos);
+
if (m_isViewAutoScrolling)
{
QPoint r = mousePos - m_clickPos;
@@ -759,6 +780,15 @@ void WebView::slotCopyImageLocation()
}
+void WebView::openLinkHere()
+{
+ KAction *a = qobject_cast<KAction*>(sender());
+ KUrl url(a->data().toUrl());
+
+ emit loadUrl(url, Rekonq::CurrentTab);
+}
+
+
void WebView::openLinkInNewWindow()
{
KAction *a = qobject_cast<KAction*>(sender());
@@ -1511,3 +1541,33 @@ void WebView::saveImage()
QString(),
!settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled));
}
+
+
+void WebView::guessHoveredLink(QPoint p)
+{
+ QWebHitTestResult hitTest = page()->mainFrame()->hitTestContent(p);
+ const QUrl url = hitTest.linkUrl();
+ bool emptyUrl = url.isEmpty();
+
+ if (!m_isExternalLinkHovered && emptyUrl)
+ return;
+
+ // if url is empty, reset
+ if (emptyUrl)
+ {
+ kDebug() << "EMPTY LINK";
+ m_isExternalLinkHovered = false;
+ return;
+ }
+
+ QWebFrame *frame = hitTest.linkTargetFrame();
+ if (!frame && m_isExternalLinkHovered)
+ return;
+
+ if (!frame)
+ {
+ kDebug() << "EXTERNAL LINK";
+ m_isExternalLinkHovered = true;
+ return;
+ }
+}
diff --git a/src/webtab/webview.h b/src/webtab/webview.h
index af199195..8f4eb029 100644
--- a/src/webtab/webview.h
+++ b/src/webtab/webview.h
@@ -98,6 +98,7 @@ protected:
private Q_SLOTS:
void search();
+ void openLinkHere();
void openLinkInNewTab();
void openLinkInNewWindow();
void openLinkInPrivateWindow();
@@ -127,6 +128,7 @@ private Q_SLOTS:
void blockImage();
+ void guessHoveredLink(QPoint);
Q_SIGNALS:
void loadUrl(const KUrl &, const Rekonq::OpenType &);
@@ -169,6 +171,8 @@ private:
bool m_accessKeysPressed;
bool m_accessKeysActive;
+ bool m_isExternalLinkHovered;
+
WebTab *m_parentTab;
bool m_isPrivateBrowsing;