From 318fc62b533f9f223d2908996e3d202061f71245 Mon Sep 17 00:00:00 2001 From: ronak69 Date: Sat, 20 Apr 2024 10:13:39 +0000 Subject: [PATCH] LibWeb: Remember page's cursor and request change only when it changes Before, on *every* mouse-move event, `page_did_request_cursor_change()` virtual function would get called, requesting to change cursor to the event's mouse position's cursor. Now, the page keeps track of the last cursor change that was requested ("page's current cursor") and only requests cursor change again if and only if the current cursor is not already the one that is required. --- Libraries/LibWeb/Page/EventHandler.cpp | 5 ++++- Libraries/LibWeb/Page/Page.h | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 6a6c4d7a8ec..913968c0e58 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -619,7 +619,10 @@ EventResult EventHandler::handle_mousemove(CSSPixelPoint viewport_position, CSSP auto& page = m_navigable->page(); - page.client().page_did_request_cursor_change(hovered_node_cursor); + if (page.current_cursor() != hovered_node_cursor) { + page.set_current_cursor(hovered_node_cursor); + page.client().page_did_request_cursor_change(hovered_node_cursor); + } if (hovered_node_changed) { GC::Ptr hovered_html_element = document.hovered_node() ? document.hovered_node()->enclosing_html_element_with_attribute(HTML::AttributeNames::title) : nullptr; diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h index 5892ec90981..3200c763da9 100644 --- a/Libraries/LibWeb/Page/Page.h +++ b/Libraries/LibWeb/Page/Page.h @@ -121,6 +121,9 @@ public: bool is_webdriver_active() const { return m_is_webdriver_active; } void set_is_webdriver_active(bool b) { m_is_webdriver_active = b; } + Gfx::StandardCursor current_cursor() const { return m_current_cursor; } + void set_current_cursor(Gfx::StandardCursor cursor) { m_current_cursor = cursor; } + DevicePixelPoint window_position() const { return m_window_position; } void set_window_position(DevicePixelPoint position) { m_window_position = position; } @@ -246,6 +249,8 @@ private: // The webdriver-active flag is set to true when the user agent is under remote control. It is initially false. bool m_is_webdriver_active { false }; + Gfx::StandardCursor m_current_cursor { Gfx::StandardCursor::Arrow }; + DevicePixelPoint m_window_position {}; DevicePixelSize m_window_size {}; GC::Ptr> m_window_rect_observer;