Skip to content

Commit

Permalink
Ladybird/AppKit: Add mouse wheel events
Browse files Browse the repository at this point in the history
  • Loading branch information
bplaat authored and awesomekling committed Sep 20, 2023
1 parent f6c52f6 commit 69482f1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Ladybird/AppKit/UI/LadybirdWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,18 @@ - (void)mouseMoved:(NSEvent*)event
m_web_view_bridge->mouse_move_event(position, screen_position, button, modifiers);
}

- (void)scrollWheel:(NSEvent*)event
{
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Middle);
CGFloat delta_x = [event scrollingDeltaX];
CGFloat delta_y = -[event scrollingDeltaY];
if (![event hasPreciseScrollingDeltas]) {
delta_x *= [self scrollView].horizontalLineScroll;
delta_y *= [self scrollView].verticalLineScroll;
}
m_web_view_bridge->mouse_wheel_event(position, screen_position, button, modifiers, delta_x, delta_y);
}

- (void)mouseDown:(NSEvent*)event
{
[[self window] makeFirstResponder:self];
Expand Down
5 changes: 5 additions & 0 deletions Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ void WebViewBridge::set_preferred_color_scheme(Web::CSS::PreferredColorScheme co
client().async_set_preferred_color_scheme(color_scheme);
}

void WebViewBridge::mouse_wheel_event(Gfx::IntPoint position, Gfx::IntPoint screen_position, GUI::MouseButton button, KeyModifier modifiers, int wheel_delta_x, int wheel_delta_y)
{
client().async_mouse_wheel(to_content_position(position), screen_position, to_underlying(button), to_underlying(button), modifiers, wheel_delta_x, wheel_delta_y);
}

void WebViewBridge::mouse_down_event(Gfx::IntPoint position, Gfx::IntPoint screen_position, GUI::MouseButton button, KeyModifier modifiers)
{
client().async_mouse_down(to_content_position(position), screen_position, to_underlying(button), to_underlying(button), modifiers);
Expand Down
1 change: 1 addition & 0 deletions Ladybird/AppKit/UI/LadybirdWebViewBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WebViewBridge final : public WebView::ViewImplementation {
void update_palette();
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);

void mouse_wheel_event(Gfx::IntPoint, Gfx::IntPoint, GUI::MouseButton, KeyModifier, int, int);
void mouse_down_event(Gfx::IntPoint, Gfx::IntPoint, GUI::MouseButton, KeyModifier);
void mouse_up_event(Gfx::IntPoint, Gfx::IntPoint, GUI::MouseButton, KeyModifier);
void mouse_move_event(Gfx::IntPoint, Gfx::IntPoint, GUI::MouseButton, KeyModifier);
Expand Down

0 comments on commit 69482f1

Please sign in to comment.