summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-11 16:11:11 +0200
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-25 07:58:58 -0700
commit4e3e5149d52569a75f837016ec80d66463f0b84b (patch)
tree2b7696d944fea003a10b19b4e5a6a6872a20865a
parentce38528fff5e531a8d6c0b5c89dd01aa02a64ba4 (diff)
downloadserenity-4e3e5149d52569a75f837016ec80d66463f0b84b.zip
Ladybird: Show tooltips for <a title> text
-rw-r--r--Ladybird/WebView.cpp16
-rw-r--r--Ladybird/WebView.h5
2 files changed, 16 insertions, 5 deletions
diff --git a/Ladybird/WebView.cpp b/Ladybird/WebView.cpp
index ecaa87d11b..9575bdfa98 100644
--- a/Ladybird/WebView.cpp
+++ b/Ladybird/WebView.cpp
@@ -63,6 +63,7 @@
#include <QPainter>
#include <QScrollBar>
#include <QTextEdit>
+#include <QToolTip>
#include <QVBoxLayout>
AK::String akstring_from_qstring(QString const& qstring)
@@ -235,14 +236,18 @@ public:
{
}
- virtual void page_did_enter_tooltip_area(Gfx::IntPoint const&, String const&) override
+ virtual void page_did_enter_tooltip_area(Gfx::IntPoint const& content_position, String const& tooltip) override
{
- m_view.setCursor(Qt::IBeamCursor);
+ auto widget_position = m_view.to_widget(content_position);
+ QToolTip::showText(
+ m_view.mapToGlobal(QPoint(widget_position.x(), widget_position.y())),
+ qstring_from_akstring(tooltip),
+ &m_view);
}
virtual void page_did_leave_tooltip_area() override
{
- m_view.setCursor(Qt::ArrowCursor);
+ QToolTip::hideText();
}
virtual void page_did_hover_link(AK::URL const& url) override
@@ -613,6 +618,11 @@ Gfx::IntPoint WebView::to_content(Gfx::IntPoint viewport_position) const
return viewport_position.translated(horizontalScrollBar()->value(), verticalScrollBar()->value());
}
+Gfx::IntPoint WebView::to_widget(Gfx::IntPoint content_position) const
+{
+ return content_position.translated(-horizontalScrollBar()->value(), -verticalScrollBar()->value());
+}
+
void WebView::paintEvent(QPaintEvent* event)
{
QPainter painter(viewport());
diff --git a/Ladybird/WebView.h b/Ladybird/WebView.h
index 92c0706736..f1a02fa901 100644
--- a/Ladybird/WebView.h
+++ b/Ladybird/WebView.h
@@ -46,6 +46,9 @@ public:
void show_js_console();
+ Gfx::IntPoint to_content(Gfx::IntPoint) const;
+ Gfx::IntPoint to_widget(Gfx::IntPoint) const;
+
signals:
void linkHovered(QString, int timeout = 0);
void linkUnhovered();
@@ -54,8 +57,6 @@ signals:
void favicon_changed(QIcon);
private:
- Gfx::IntPoint to_content(Gfx::IntPoint) const;
-
OwnPtr<HeadlessBrowserPageClient> m_page_client;
qreal m_inverse_pixel_scaling_ratio { 1.0 };