Browse Source

Ladybird+LibWebView: Migrate tooltip changes to LibWebView callbacks

Timothy Flynn 1 year ago
parent
commit
5116e97a9d

+ 2 - 2
Ladybird/AppKit/UI/LadybirdWebView.mm

@@ -323,11 +323,11 @@ struct HideCursor {
         [[self tabController] reload:nil];
         [[self tabController] reload:nil];
     };
     };
 
 
-    m_web_view_bridge->on_tooltip_entered = [self](auto const& tooltip) {
+    m_web_view_bridge->on_enter_tooltip_area = [self](auto, auto const& tooltip) {
         self.toolTip = Ladybird::string_to_ns_string(tooltip);
         self.toolTip = Ladybird::string_to_ns_string(tooltip);
     };
     };
 
 
-    m_web_view_bridge->on_tooltip_left = [self]() {
+    m_web_view_bridge->on_leave_tooltip_area = [self]() {
         self.toolTip = nil;
         self.toolTip = nil;
     };
     };
 
 

+ 0 - 12
Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp

@@ -133,18 +133,6 @@ Optional<WebViewBridge::Paintable> WebViewBridge::paintable()
     return Paintable { *bitmap, bitmap_size };
     return Paintable { *bitmap, bitmap_size };
 }
 }
 
 
-void WebViewBridge::notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const& tooltip)
-{
-    if (on_tooltip_entered)
-        on_tooltip_entered(tooltip);
-}
-
-void WebViewBridge::notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>)
-{
-    if (on_tooltip_left)
-        on_tooltip_left();
-}
-
 void WebViewBridge::notify_server_did_finish_handling_input_event(bool)
 void WebViewBridge::notify_server_did_finish_handling_input_event(bool)
 {
 {
 }
 }

+ 0 - 5
Ladybird/AppKit/UI/LadybirdWebViewBridge.h

@@ -49,14 +49,9 @@ public:
     };
     };
     Optional<Paintable> paintable();
     Optional<Paintable> paintable();
 
 
-    Function<void(DeprecatedString const&)> on_tooltip_entered;
-    Function<void()> on_tooltip_left;
-
 private:
 private:
     WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path);
     WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, Optional<StringView> webdriver_content_ipc_path);
 
 
-    virtual void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
-    virtual void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
 
 
     virtual void update_zoom() override;
     virtual void update_zoom() override;

+ 11 - 14
Ladybird/Qt/WebContentView.cpp

@@ -112,6 +112,17 @@ WebContentView::WebContentView(StringView webdriver_content_ipc_path, WebView::E
     on_cursor_change = [this](auto cursor) {
     on_cursor_change = [this](auto cursor) {
         update_cursor(cursor);
         update_cursor(cursor);
     };
     };
+
+    on_enter_tooltip_area = [this](auto position, auto tooltip) {
+        QToolTip::showText(
+            mapToGlobal(QPoint(position.x(), position.y())),
+            qstring_from_ak_deprecated_string(tooltip),
+            this);
+    };
+
+    on_leave_tooltip_area = []() {
+        QToolTip::hideText();
+    };
 }
 }
 
 
 WebContentView::~WebContentView() = default;
 WebContentView::~WebContentView() = default;
@@ -687,20 +698,6 @@ void WebContentView::update_cursor(Gfx::StandardCursor cursor)
     }
     }
 }
 }
 
 
-void WebContentView::notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint content_position, DeprecatedString const& tooltip)
-{
-    auto widget_position = to_widget_position(content_position);
-    QToolTip::showText(
-        mapToGlobal(QPoint(widget_position.x(), widget_position.y())),
-        qstring_from_ak_deprecated_string(tooltip),
-        this);
-}
-
-void WebContentView::notify_server_did_leave_tooltip_area(Badge<WebContentClient>)
-{
-    QToolTip::hideText();
-}
-
 Gfx::IntRect WebContentView::viewport_rect() const
 Gfx::IntRect WebContentView::viewport_rect() const
 {
 {
     return m_viewport_rect;
     return m_viewport_rect;

+ 0 - 2
Ladybird/Qt/WebContentView.h

@@ -76,8 +76,6 @@ public:
     };
     };
     void update_palette(PaletteMode = PaletteMode::Default);
     void update_palette(PaletteMode = PaletteMode::Default);
 
 
-    virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
-    virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
 
 
 signals:
 signals:

+ 8 - 10
Userland/Libraries/LibWebView/OutOfProcessWebView.cpp

@@ -63,6 +63,14 @@ OutOfProcessWebView::OutOfProcessWebView()
     on_cursor_change = [this](auto cursor) {
     on_cursor_change = [this](auto cursor) {
         set_override_cursor(cursor);
         set_override_cursor(cursor);
     };
     };
+
+    on_enter_tooltip_area = [](auto, auto tooltip) {
+        GUI::Application::the()->show_tooltip(tooltip, nullptr);
+    };
+
+    on_leave_tooltip_area = []() {
+        GUI::Application::the()->hide_tooltip();
+    };
 }
 }
 
 
 OutOfProcessWebView::~OutOfProcessWebView() = default;
 OutOfProcessWebView::~OutOfProcessWebView() = default;
@@ -201,16 +209,6 @@ void OutOfProcessWebView::screen_rects_change_event(GUI::ScreenRectsChangeEvent&
     client().async_update_screen_rects(event.rects(), event.main_screen_index());
     client().async_update_screen_rects(event.rects(), event.main_screen_index());
 }
 }
 
 
-void OutOfProcessWebView::notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const& title)
-{
-    GUI::Application::the()->show_tooltip(title, nullptr);
-}
-
-void OutOfProcessWebView::notify_server_did_leave_tooltip_area(Badge<WebContentClient>)
-{
-    GUI::Application::the()->hide_tooltip();
-}
-
 void OutOfProcessWebView::did_scroll()
 void OutOfProcessWebView::did_scroll()
 {
 {
     client().async_set_viewport_rect(visible_content_rect());
     client().async_set_viewport_rect(visible_content_rect());

+ 0 - 2
Userland/Libraries/LibWebView/OutOfProcessWebView.h

@@ -82,8 +82,6 @@ private:
     // ^WebView::ViewImplementation
     // ^WebView::ViewImplementation
     virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) override;
     virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) override;
     virtual void update_zoom() override;
     virtual void update_zoom() override;
-    virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
-    virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
 
 
     virtual Gfx::IntRect viewport_rect() const override;
     virtual Gfx::IntRect viewport_rect() const override;

+ 2 - 2
Userland/Libraries/LibWebView/ViewImplementation.h

@@ -119,6 +119,8 @@ public:
     Function<void(Gfx::IntPoint)> on_scroll_to_point;
     Function<void(Gfx::IntPoint)> on_scroll_to_point;
     Function<void(Gfx::IntRect)> on_scroll_into_view;
     Function<void(Gfx::IntRect)> on_scroll_into_view;
     Function<void(Gfx::StandardCursor)> on_cursor_change;
     Function<void(Gfx::StandardCursor)> on_cursor_change;
+    Function<void(Gfx::IntPoint, DeprecatedString const&)> on_enter_tooltip_area;
+    Function<void()> on_leave_tooltip_area;
     Function<void(String const& message)> on_request_alert;
     Function<void(String const& message)> on_request_alert;
     Function<void(String const& message)> on_request_confirm;
     Function<void(String const& message)> on_request_confirm;
     Function<void(String const& message, String const& default_)> on_request_prompt;
     Function<void(String const& message, String const& default_)> on_request_prompt;
@@ -144,8 +146,6 @@ public:
     Function<Gfx::IntRect()> on_minimize_window;
     Function<Gfx::IntRect()> on_minimize_window;
     Function<Gfx::IntRect()> on_fullscreen_window;
     Function<Gfx::IntRect()> on_fullscreen_window;
 
 
-    virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) = 0;
-    virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) = 0;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0;
     virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0;
 
 
     virtual Gfx::IntRect viewport_rect() const = 0;
     virtual Gfx::IntRect viewport_rect() const = 0;

+ 4 - 2
Userland/Libraries/LibWebView/WebContentClient.cpp

@@ -128,12 +128,14 @@ void WebContentClient::did_request_scroll_into_view(Gfx::IntRect const& rect)
 
 
 void WebContentClient::did_enter_tooltip_area(Gfx::IntPoint content_position, DeprecatedString const& title)
 void WebContentClient::did_enter_tooltip_area(Gfx::IntPoint content_position, DeprecatedString const& title)
 {
 {
-    m_view.notify_server_did_enter_tooltip_area({}, content_position, title);
+    if (m_view.on_enter_tooltip_area)
+        m_view.on_enter_tooltip_area(m_view.to_widget_position(content_position), title);
 }
 }
 
 
 void WebContentClient::did_leave_tooltip_area()
 void WebContentClient::did_leave_tooltip_area()
 {
 {
-    m_view.notify_server_did_leave_tooltip_area({});
+    if (m_view.on_leave_tooltip_area)
+        m_view.on_leave_tooltip_area();
 }
 }
 
 
 void WebContentClient::did_hover_link(AK::URL const& url)
 void WebContentClient::did_hover_link(AK::URL const& url)

+ 0 - 2
Userland/Utilities/headless-browser.cpp

@@ -102,8 +102,6 @@ public:
 private:
 private:
     HeadlessWebContentView() = default;
     HeadlessWebContentView() = default;
 
 
-    void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override { }
-    void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override { }
     void notify_server_did_finish_handling_input_event(bool) override { }
     void notify_server_did_finish_handling_input_event(bool) override { }
     void update_zoom() override { }
     void update_zoom() override { }
     void create_client(WebView::EnableCallgrindProfiling) override { }
     void create_client(WebView::EnableCallgrindProfiling) override { }