Skip to content

Commit 67cc02a

Browse files
trflynn89awesomekling
authored andcommitted
LibWeb+UI: Add an explicit IPC to handle mouse leave events
The faux position we created here is adjusted by the device pixel ratio later on, which would invoke integer overflow on screens with a DPR greater than 1. Instead of creating special data for a mouse move event, let's just add an explicit leave event handler.
1 parent 8600925 commit 67cc02a

File tree

11 files changed

+66
-7
lines changed

11 files changed

+66
-7
lines changed

Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ void EventLoop::process_input_events() const
279279
return page.handle_mouseup(mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers);
280280
case MouseEvent::Type::MouseMove:
281281
return page.handle_mousemove(mouse_event.position, mouse_event.screen_position, mouse_event.buttons, mouse_event.modifiers);
282+
case MouseEvent::Type::MouseLeave:
283+
return page.handle_mouseleave();
282284
case MouseEvent::Type::MouseWheel:
283285
return page.handle_mousewheel(mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y);
284286
case MouseEvent::Type::DoubleClick:

Libraries/LibWeb/Page/EventHandler.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,44 @@ EventResult EventHandler::handle_mousemove(CSSPixelPoint viewport_position, CSSP
861861
return EventResult::Handled;
862862
}
863863

864+
EventResult EventHandler::handle_mouseleave()
865+
{
866+
if (should_ignore_device_input_event())
867+
return EventResult::Dropped;
868+
869+
if (!m_navigable->active_document())
870+
return EventResult::Dropped;
871+
if (!m_navigable->active_document()->is_fully_active())
872+
return EventResult::Dropped;
873+
874+
m_navigable->active_document()->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseMove);
875+
876+
if (!paint_root())
877+
return EventResult::Dropped;
878+
879+
auto& document = *m_navigable->active_document();
880+
auto& page = m_navigable->page();
881+
882+
if (auto* hovered_node = document.hovered_node()) {
883+
if (auto* paintable = hovered_node->paintable(); paintable && paintable->wants_mouse_events())
884+
paintable->handle_mouseleave({});
885+
886+
document.set_hovered_node(nullptr);
887+
}
888+
889+
if (page.is_in_tooltip_area()) {
890+
page.set_is_in_tooltip_area(false);
891+
page.client().page_did_leave_tooltip_area();
892+
}
893+
894+
if (page.is_hovering_link()) {
895+
page.set_is_hovering_link(false);
896+
page.client().page_did_unhover_link();
897+
}
898+
899+
return EventResult::Handled;
900+
}
901+
864902
EventResult EventHandler::handle_doubleclick(CSSPixelPoint viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers)
865903
{
866904
if (should_ignore_device_input_event())

Libraries/LibWeb/Page/EventHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class EventHandler {
2929
EventResult handle_mouseup(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
3030
EventResult handle_mousedown(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
3131
EventResult handle_mousemove(CSSPixelPoint, CSSPixelPoint screen_position, unsigned buttons, unsigned modifiers);
32+
EventResult handle_mouseleave();
3233
EventResult handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
3334
EventResult handle_doubleclick(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
3435

Libraries/LibWeb/Page/InputEvent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct MouseEvent {
4444
MouseDown,
4545
MouseUp,
4646
MouseMove,
47+
MouseLeave,
4748
MouseWheel,
4849
DoubleClick,
4950
};

Libraries/LibWeb/Page/Page.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ EventResult Page::handle_mousemove(DevicePixelPoint position, DevicePixelPoint s
209209
return top_level_traversable()->event_handler().handle_mousemove(device_to_css_point(position), device_to_css_point(screen_position), buttons, modifiers);
210210
}
211211

212+
EventResult Page::handle_mouseleave()
213+
{
214+
return top_level_traversable()->event_handler().handle_mouseleave();
215+
}
216+
212217
EventResult Page::handle_mousewheel(DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, DevicePixels wheel_delta_x, DevicePixels wheel_delta_y)
213218
{
214219
return top_level_traversable()->event_handler().handle_mousewheel(device_to_css_point(position), device_to_css_point(screen_position), button, buttons, modifiers, wheel_delta_x.value(), wheel_delta_y.value());

Libraries/LibWeb/Page/Page.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Page final : public JS::Cell {
9292
EventResult handle_mouseup(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
9393
EventResult handle_mousedown(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
9494
EventResult handle_mousemove(DevicePixelPoint, DevicePixelPoint screen_position, unsigned buttons, unsigned modifiers);
95+
EventResult handle_mouseleave();
9596
EventResult handle_mousewheel(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, DevicePixels wheel_delta_x, DevicePixels wheel_delta_y);
9697
EventResult handle_doubleclick(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers);
9798

Libraries/LibWeb/Painting/Paintable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class Paintable
8989
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers);
9090
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers);
9191
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers);
92+
virtual void handle_mouseleave(Badge<EventHandler>) { }
9293

9394
virtual bool handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
9495

Libraries/LibWeb/Painting/PaintableBox.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,19 @@ Paintable::DispatchEventOfSameName PaintableBox::handle_mousemove(Badge<EventHan
979979
return Paintable::DispatchEventOfSameName::Yes;
980980
}
981981

982+
void PaintableBox::handle_mouseleave(Badge<EventHandler>)
983+
{
984+
auto previous_draw_enlarged_horizontal_scrollbar = m_draw_enlarged_horizontal_scrollbar;
985+
m_draw_enlarged_horizontal_scrollbar = false;
986+
if (previous_draw_enlarged_horizontal_scrollbar != m_draw_enlarged_horizontal_scrollbar)
987+
set_needs_display();
988+
989+
auto previous_draw_enlarged_vertical_scrollbar = m_draw_enlarged_vertical_scrollbar;
990+
m_draw_enlarged_vertical_scrollbar = false;
991+
if (previous_draw_enlarged_vertical_scrollbar != m_draw_enlarged_vertical_scrollbar)
992+
set_needs_display();
993+
}
994+
982995
bool PaintableBox::scrollbar_contains_mouse_position(ScrollDirection direction, CSSPixelPoint position)
983996
{
984997
TemporaryChange force_enlarged_horizontal_scrollbar { m_draw_enlarged_horizontal_scrollbar, true };

Libraries/LibWeb/Painting/PaintableBox.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class PaintableBox : public Paintable
301301
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
302302
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
303303
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers) override;
304+
virtual void handle_mouseleave(Badge<EventHandler>) override;
304305

305306
bool scrollbar_contains_mouse_position(ScrollDirection, CSSPixelPoint);
306307
void scroll_to_mouse_position(CSSPixelPoint);

UI/AppKit/Interface/LadybirdWebView.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,9 +1576,7 @@ - (BOOL)isFlipped
15761576

15771577
- (void)mouseExited:(NSEvent*)event
15781578
{
1579-
static constexpr Web::DevicePixelPoint point { NumericLimits<Web::DevicePixels::Type>::max(), NumericLimits<Web::DevicePixels::Type>::max() };
1580-
1581-
Web::MouseEvent mouse_event { Web::MouseEvent::Type::MouseMove, point, point, Web::UIEvents::MouseButton::None, Web::UIEvents::MouseButton::None, Web::UIEvents::KeyModifier::Mod_None, 0, 0, nullptr };
1579+
Web::MouseEvent mouse_event { Web::MouseEvent::Type::MouseLeave, {}, {}, Web::UIEvents::MouseButton::None, Web::UIEvents::MouseButton::None, Web::UIEvents::KeyModifier::Mod_None, 0, 0, nullptr };
15821580
m_web_view_bridge->enqueue_input_event(move(mouse_event));
15831581
}
15841582

0 commit comments

Comments
 (0)