mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
LibWeb: Expose the MouseEvent::{clientX, clientY} attributes
These provide the cursor coordinate within the viewport at which the event occurred (as opposed to the page relative coordinates exposed via offsetX, offsetY).
This commit is contained in:
parent
815934a95d
commit
ad8e2f481d
5 changed files with 16 additions and 8 deletions
|
@ -660,7 +660,7 @@ NonnullRefPtr<Event> Document::create_event(const String& interface)
|
||||||
} else if (interface_lowercase == "messageevent") {
|
} else if (interface_lowercase == "messageevent") {
|
||||||
event = Event::create(""); // FIXME: Create MessageEvent
|
event = Event::create(""); // FIXME: Create MessageEvent
|
||||||
} else if (interface_lowercase.is_one_of("mouseevent", "mouseevents")) {
|
} else if (interface_lowercase.is_one_of("mouseevent", "mouseevents")) {
|
||||||
event = UIEvents::MouseEvent::create("", 0, 0);
|
event = UIEvents::MouseEvent::create("", 0, 0, 0, 0);
|
||||||
} else if (interface_lowercase == "storageevent") {
|
} else if (interface_lowercase == "storageevent") {
|
||||||
event = Event::create(""); // FIXME: Create StorageEvent
|
event = Event::create(""); // FIXME: Create StorageEvent
|
||||||
} else if (interface_lowercase == "svgevents") {
|
} else if (interface_lowercase == "svgevents") {
|
||||||
|
|
|
@ -182,7 +182,7 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
||||||
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mouseup, offset.x(), offset.y()));
|
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mouseup, offset.x(), offset.y(), position.x(), position.y()));
|
||||||
handled_event = true;
|
handled_event = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
|
||||||
page->set_focused_frame({}, m_frame);
|
page->set_focused_frame({}, m_frame);
|
||||||
|
|
||||||
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
||||||
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mousedown, offset.x(), offset.y()));
|
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mousedown, offset.x(), offset.y(), position.x(), position.y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Dispatching an event may have disturbed the world.
|
// NOTE: Dispatching an event may have disturbed the world.
|
||||||
|
@ -337,7 +337,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
|
||||||
hovered_node_cursor = cursor_css_to_gfx(cursor);
|
hovered_node_cursor = cursor_css_to_gfx(cursor);
|
||||||
|
|
||||||
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
||||||
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mousemove, offset.x(), offset.y()));
|
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mousemove, offset.x(), offset.y(), position.x(), position.y()));
|
||||||
// NOTE: Dispatching an event may have disturbed the world.
|
// NOTE: Dispatching an event may have disturbed the world.
|
||||||
if (!layout_root() || layout_root() != node->document().layout_node())
|
if (!layout_root() || layout_root() != node->document().layout_node())
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -30,10 +30,12 @@
|
||||||
|
|
||||||
namespace Web::UIEvents {
|
namespace Web::UIEvents {
|
||||||
|
|
||||||
MouseEvent::MouseEvent(const FlyString& event_name, i32 offset_x, i32 offset_y)
|
MouseEvent::MouseEvent(const FlyString& event_name, i32 offset_x, i32 offset_y, i32 client_x, i32 client_y)
|
||||||
: UIEvent(event_name)
|
: UIEvent(event_name)
|
||||||
, m_offset_x(offset_x)
|
, m_offset_x(offset_x)
|
||||||
, m_offset_y(offset_y)
|
, m_offset_y(offset_y)
|
||||||
|
, m_client_x(client_x)
|
||||||
|
, m_client_y(client_y)
|
||||||
{
|
{
|
||||||
set_event_characteristics();
|
set_event_characteristics();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,24 +35,28 @@ class MouseEvent final : public UIEvents::UIEvent {
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::MouseEventWrapper;
|
using WrapperType = Bindings::MouseEventWrapper;
|
||||||
|
|
||||||
static NonnullRefPtr<MouseEvent> create(const FlyString& event_name, i32 offset_x, i32 offset_y)
|
static NonnullRefPtr<MouseEvent> create(const FlyString& event_name, i32 offset_x, i32 offset_y, i32 client_x, i32 client_y)
|
||||||
{
|
{
|
||||||
return adopt(*new MouseEvent(event_name, offset_x, offset_y));
|
return adopt(*new MouseEvent(event_name, offset_x, offset_y, client_x, client_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~MouseEvent() override;
|
virtual ~MouseEvent() override;
|
||||||
|
|
||||||
i32 offset_x() const { return m_offset_x; }
|
i32 offset_x() const { return m_offset_x; }
|
||||||
i32 offset_y() const { return m_offset_y; }
|
i32 offset_y() const { return m_offset_y; }
|
||||||
|
i32 client_x() const { return m_client_x; }
|
||||||
|
i32 client_y() const { return m_client_y; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MouseEvent(const FlyString& event_name, i32 offset_x, i32 offset_y);
|
MouseEvent(const FlyString& event_name, i32 offset_x, i32 offset_y, i32 client_x, i32 client_y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set_event_characteristics();
|
void set_event_characteristics();
|
||||||
|
|
||||||
i32 m_offset_x { 0 };
|
i32 m_offset_x { 0 };
|
||||||
i32 m_offset_y { 0 };
|
i32 m_offset_y { 0 };
|
||||||
|
i32 m_client_x { 0 };
|
||||||
|
i32 m_client_y { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,7 @@ interface MouseEvent : Event {
|
||||||
|
|
||||||
readonly attribute double offsetX;
|
readonly attribute double offsetX;
|
||||||
readonly attribute double offsetY;
|
readonly attribute double offsetY;
|
||||||
|
readonly attribute double clientX;
|
||||||
|
readonly attribute double clientY;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue