mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
LibWeb: Add MouseEvent JavaScript constructor
This commit is contained in:
parent
9aadc6c8c9
commit
e2bc606eeb
|
@ -0,0 +1,4 @@
|
|||
1. 10
|
||||
2. true
|
||||
3. true
|
||||
4. true
|
22
Tests/LibWeb/Text/input/UIEvents/custom-mouse-event.html
Normal file
22
Tests/LibWeb/Text/input/UIEvents/custom-mouse-event.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let testCounter = 1;
|
||||
function testPart(part) {
|
||||
println(`${testCounter}. ${JSON.stringify(part())}`);
|
||||
testCounter++;
|
||||
}
|
||||
|
||||
// 1. Creating a MouseEvent
|
||||
testPart(() => new MouseEvent('click', { clientX: 10 }).clientX);
|
||||
|
||||
// 2. Creating a MouseEvent with modifier
|
||||
testPart(() => new MouseEvent('click', { ctrlKey: true }).getModifierState('Control'));
|
||||
|
||||
// 3. Creating a MouseEvent with modifier
|
||||
testPart(() => new MouseEvent('click', { modifierAltGraph: true }).getModifierState('AltGraph'));
|
||||
|
||||
// 4. Creating a MouseEvent with modifier
|
||||
testPart(() => new MouseEvent('click', { modifierSymbolLock: true }).getModifierState('SymbolLock'));
|
||||
});
|
||||
</script>
|
|
@ -113,6 +113,11 @@ JS::NonnullGCPtr<MouseEvent> MouseEvent::create(JS::Realm& realm, FlyString cons
|
|||
return realm.heap().allocate<MouseEvent>(realm, realm, event_name, event_init, page_x, page_y, offset_x, offset_y);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MouseEventInit const& event_init)
|
||||
{
|
||||
return create(realm, event_name, event_init);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, Optional<CSSPixelPoint> movement, unsigned button, unsigned buttons, unsigned modifiers)
|
||||
{
|
||||
MouseEventInit event_init {};
|
||||
|
|
|
@ -31,6 +31,7 @@ class MouseEvent : public UIEvent {
|
|||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<MouseEvent> create(JS::Realm&, FlyString const& event_name, MouseEventInit const& = {}, double page_x = 0, double page_y = 0, double offset_x = 0, double offset_y = 0);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> create_from_platform_event(JS::Realm&, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, Optional<CSSPixelPoint> movement, unsigned button, unsigned buttons, unsigned modifiers);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> construct_impl(JS::Realm&, FlyString const& event_name, MouseEventInit const&);
|
||||
|
||||
virtual ~MouseEvent() override;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// https://w3c.github.io/uievents/#mouseevent
|
||||
[Exposed=Window]
|
||||
interface MouseEvent : UIEvent {
|
||||
// FIXME: constructor(DOMString type, optional MouseEventInit eventInitDict = {});
|
||||
constructor(DOMString type, optional MouseEventInit eventInitDict = {});
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#extensions-to-the-mouseevent-interface
|
||||
readonly attribute double screenX;
|
||||
|
|
Loading…
Reference in a new issue