summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-04-15 20:50:02 +0300
committerAndreas Kling <kling@serenityos.org>2021-04-15 20:22:08 +0200
commitad8e2f481d72b70a9a68b09f95a9e306d8c6a7c3 (patch)
tree7f799d26493e62783b0af84642717000c95596fa
parent815934a95dc7f3bc540a6c66988073d0dddfb87e (diff)
downloadserenity-ad8e2f481d72b70a9a68b09f95a9e306d8c6a7c3.zip
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).
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Page/EventHandler.cpp6
-rw-r--r--Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp4
-rw-r--r--Userland/Libraries/LibWeb/UIEvents/MouseEvent.h10
-rw-r--r--Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl2
5 files changed, 16 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index a4f77872a4..59c2407904 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -660,7 +660,7 @@ NonnullRefPtr<Event> Document::create_event(const String& interface)
} else if (interface_lowercase == "messageevent") {
event = Event::create(""); // FIXME: Create MessageEvent
} 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") {
event = Event::create(""); // FIXME: Create StorageEvent
} else if (interface_lowercase == "svgevents") {
diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
index e751a468ea..65936c285f 100644
--- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
@@ -182,7 +182,7 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
return false;
}
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;
}
@@ -230,7 +230,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
page->set_focused_frame({}, m_frame);
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.
@@ -337,7 +337,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
hovered_node_cursor = cursor_css_to_gfx(cursor);
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.
if (!layout_root() || layout_root() != node->document().layout_node())
return true;
diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp
index e102a4e138..8b3aab45b4 100644
--- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp
+++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp
@@ -30,10 +30,12 @@
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)
, m_offset_x(offset_x)
, m_offset_y(offset_y)
+ , m_client_x(client_x)
+ , m_client_y(client_y)
{
set_event_characteristics();
}
diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h
index 13fc8d3322..4c2d216fc7 100644
--- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h
+++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h
@@ -35,24 +35,28 @@ class MouseEvent final : public UIEvents::UIEvent {
public:
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;
i32 offset_x() const { return m_offset_x; }
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:
- 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:
void set_event_characteristics();
i32 m_offset_x { 0 };
i32 m_offset_y { 0 };
+ i32 m_client_x { 0 };
+ i32 m_client_y { 0 };
};
}
diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl
index 2751f2353a..452ef261d4 100644
--- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl
+++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl
@@ -2,5 +2,7 @@ interface MouseEvent : Event {
readonly attribute double offsetX;
readonly attribute double offsetY;
+ readonly attribute double clientX;
+ readonly attribute double clientY;
};