mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:07:34 +00:00
Ladybird+LibWeb: Add MouseEvent screenX and screenY support
This commit is contained in:
parent
e584189b8f
commit
836a7b00dd
19 changed files with 125 additions and 103 deletions
|
@ -16,6 +16,7 @@ namespace Ladybird {
|
|||
|
||||
struct MouseEvent {
|
||||
Gfx::IntPoint position {};
|
||||
Gfx::IntPoint screen_position {};
|
||||
GUI::MouseButton button { GUI::MouseButton::Primary };
|
||||
KeyModifier modifiers { KeyModifier::Mod_None };
|
||||
};
|
||||
|
|
|
@ -39,9 +39,10 @@ static KeyModifier ns_modifiers_to_key_modifiers(NSEventModifierFlags modifier_f
|
|||
MouseEvent ns_event_to_mouse_event(NSEvent* event, NSView* view, GUI::MouseButton button)
|
||||
{
|
||||
auto position = [view convertPoint:event.locationInWindow fromView:nil];
|
||||
auto screen_position = [NSEvent mouseLocation];
|
||||
auto modifiers = ns_modifiers_to_key_modifiers(event.modifierFlags, button);
|
||||
|
||||
return { ns_point_to_gfx_point(position), button, modifiers };
|
||||
return { ns_point_to_gfx_point(position), ns_point_to_gfx_point(screen_position), button, modifiers };
|
||||
}
|
||||
|
||||
NSEvent* create_context_menu_mouse_event(NSView* view, Gfx::IntPoint position)
|
||||
|
|
|
@ -956,58 +956,58 @@ static void copy_text_to_clipboard(StringView text)
|
|||
|
||||
- (void)mouseMoved:(NSEvent*)event
|
||||
{
|
||||
auto [position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::None);
|
||||
m_web_view_bridge->mouse_move_event(position, button, modifiers);
|
||||
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::None);
|
||||
m_web_view_bridge->mouse_move_event(position, screen_position, button, modifiers);
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent*)event
|
||||
{
|
||||
[[self window] makeFirstResponder:self];
|
||||
|
||||
auto [position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Primary);
|
||||
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Primary);
|
||||
|
||||
if (event.clickCount % 2 == 0) {
|
||||
m_web_view_bridge->mouse_double_click_event(position, button, modifiers);
|
||||
m_web_view_bridge->mouse_double_click_event(position, screen_position, button, modifiers);
|
||||
} else {
|
||||
m_web_view_bridge->mouse_down_event(position, button, modifiers);
|
||||
m_web_view_bridge->mouse_down_event(position, screen_position, button, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mouseUp:(NSEvent*)event
|
||||
{
|
||||
auto [position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Primary);
|
||||
m_web_view_bridge->mouse_up_event(position, button, modifiers);
|
||||
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Primary);
|
||||
m_web_view_bridge->mouse_up_event(position, screen_position, button, modifiers);
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(NSEvent*)event
|
||||
{
|
||||
auto [position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Primary);
|
||||
m_web_view_bridge->mouse_move_event(position, button, modifiers);
|
||||
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Primary);
|
||||
m_web_view_bridge->mouse_move_event(position, screen_position, button, modifiers);
|
||||
}
|
||||
|
||||
- (void)rightMouseDown:(NSEvent*)event
|
||||
{
|
||||
[[self window] makeFirstResponder:self];
|
||||
|
||||
auto [position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Secondary);
|
||||
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Secondary);
|
||||
|
||||
if (event.clickCount % 2 == 0) {
|
||||
m_web_view_bridge->mouse_double_click_event(position, button, modifiers);
|
||||
m_web_view_bridge->mouse_double_click_event(position, screen_position, button, modifiers);
|
||||
} else {
|
||||
m_web_view_bridge->mouse_down_event(position, button, modifiers);
|
||||
m_web_view_bridge->mouse_down_event(position, screen_position, button, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)rightMouseUp:(NSEvent*)event
|
||||
{
|
||||
auto [position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Secondary);
|
||||
m_web_view_bridge->mouse_up_event(position, button, modifiers);
|
||||
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Secondary);
|
||||
m_web_view_bridge->mouse_up_event(position, screen_position, button, modifiers);
|
||||
}
|
||||
|
||||
- (void)rightMouseDragged:(NSEvent*)event
|
||||
{
|
||||
auto [position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Secondary);
|
||||
m_web_view_bridge->mouse_move_event(position, button, modifiers);
|
||||
auto [position, screen_position, button, modifiers] = Ladybird::ns_event_to_mouse_event(event, self, GUI::MouseButton::Secondary);
|
||||
m_web_view_bridge->mouse_move_event(position, screen_position, button, modifiers);
|
||||
}
|
||||
|
||||
- (void)keyDown:(NSEvent*)event
|
||||
|
|
|
@ -100,24 +100,24 @@ void WebViewBridge::set_preferred_color_scheme(Web::CSS::PreferredColorScheme co
|
|||
client().async_set_preferred_color_scheme(color_scheme);
|
||||
}
|
||||
|
||||
void WebViewBridge::mouse_down_event(Gfx::IntPoint position, GUI::MouseButton button, KeyModifier modifiers)
|
||||
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), to_underlying(button), to_underlying(button), modifiers);
|
||||
client().async_mouse_down(to_content_position(position), screen_position, to_underlying(button), to_underlying(button), modifiers);
|
||||
}
|
||||
|
||||
void WebViewBridge::mouse_up_event(Gfx::IntPoint position, GUI::MouseButton button, KeyModifier modifiers)
|
||||
void WebViewBridge::mouse_up_event(Gfx::IntPoint position, Gfx::IntPoint screen_position, GUI::MouseButton button, KeyModifier modifiers)
|
||||
{
|
||||
client().async_mouse_up(to_content_position(position), to_underlying(button), to_underlying(button), modifiers);
|
||||
client().async_mouse_up(to_content_position(position), screen_position, to_underlying(button), to_underlying(button), modifiers);
|
||||
}
|
||||
|
||||
void WebViewBridge::mouse_move_event(Gfx::IntPoint position, GUI::MouseButton button, KeyModifier modifiers)
|
||||
void WebViewBridge::mouse_move_event(Gfx::IntPoint position, Gfx::IntPoint screen_position, GUI::MouseButton button, KeyModifier modifiers)
|
||||
{
|
||||
client().async_mouse_move(to_content_position(position), 0, to_underlying(button), modifiers);
|
||||
client().async_mouse_move(to_content_position(position), screen_position, 0, to_underlying(button), modifiers);
|
||||
}
|
||||
|
||||
void WebViewBridge::mouse_double_click_event(Gfx::IntPoint position, GUI::MouseButton button, KeyModifier modifiers)
|
||||
void WebViewBridge::mouse_double_click_event(Gfx::IntPoint position, Gfx::IntPoint screen_position, GUI::MouseButton button, KeyModifier modifiers)
|
||||
{
|
||||
client().async_doubleclick(to_content_position(position), button, to_underlying(button), modifiers);
|
||||
client().async_doubleclick(to_content_position(position), screen_position, button, to_underlying(button), modifiers);
|
||||
}
|
||||
|
||||
void WebViewBridge::key_down_event(KeyCode key_code, KeyModifier modifiers, u32 code_point)
|
||||
|
|
|
@ -39,10 +39,10 @@ public:
|
|||
void update_palette();
|
||||
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
|
||||
|
||||
void mouse_down_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
|
||||
void mouse_up_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
|
||||
void mouse_move_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
|
||||
void mouse_double_click_event(Gfx::IntPoint, GUI::MouseButton, KeyModifier);
|
||||
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);
|
||||
void mouse_double_click_event(Gfx::IntPoint, Gfx::IntPoint, GUI::MouseButton, KeyModifier);
|
||||
|
||||
void key_down_event(KeyCode, KeyModifier, u32);
|
||||
void key_up_event(KeyCode, KeyModifier, u32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue