Skip to content

Commit

Permalink
LibWeb: Use WindowProxy instead of Window in UI Events IDL
Browse files Browse the repository at this point in the history
I believe this is an error in the UI Events spec, and it should be
updated to match the HTML spec (which uses WindowProxy everywhere).

This fixes a bunch of issues already covered by existing WPT tests.

Spec bug: w3c/uievents#388

Note that WebKit has been using WindowProxy instead of Window in
UI Events IDL since 2018:
WebKit/WebKit@816158b
  • Loading branch information
awesomekling committed Nov 17, 2024
1 parent 5a4d657 commit 2dcecdf
Show file tree
Hide file tree
Showing 20 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Libraries/LibWeb/HTML/Focus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void fire_a_focus_event(GC::Ptr<DOM::EventTarget> focus_event_target, GC:
// object, and the composed flag set.
UIEvents::FocusEventInit focus_event_init {};
focus_event_init.related_target = related_focus_target;
focus_event_init.view = verify_cast<HTML::Window>(focus_event_target->realm().global_object());
focus_event_init.view = verify_cast<HTML::Window>(focus_event_target->realm().global_object()).window();

auto focus_event = UIEvents::FocusEvent::create(focus_event_target->realm(), event_name, focus_event_init);
// AD-HOC: support bubbling focus events, used for focusin & focusout.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/Page/DragAndDropEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ GC::Ref<HTML::DragEvent> DragAndDropEventHandler::fire_a_drag_and_drop_event(

if (target) {
auto& window = static_cast<HTML::Window&>(HTML::relevant_global_object(*target));
event_init.view = window;
event_init.view = window.window();
}

// If e is not dragleave or dragend, then initialize event's cancelable attribute to true.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/CompositionEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void CompositionEvent::initialize(JS::Realm& realm)
}

// https://w3c.github.io/uievents/#dom-compositionevent-initcompositionevent
void CompositionEvent::init_composition_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data)
void CompositionEvent::init_composition_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, String const& data)
{
// Initializes attributes of a CompositionEvent object. This method has the same behavior as UIEvent.initUIEvent().
// The value of detail remains undefined.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/CompositionEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CompositionEvent final : public UIEvent {
// https://w3c.github.io/uievents/#dom-compositionevent-data
String data() const { return m_data; }

void init_composition_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data);
void init_composition_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, String const& data);

private:
CompositionEvent(JS::Realm&, FlyString const& event_name, CompositionEventInit const&);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/CompositionEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface CompositionEvent : UIEvent {

// https://w3c.github.io/uievents/#dom-compositionevent-initcompositionevent
// FIXME: The spec uses WindowProxy rather than Window (see https://github.com/w3c/uievents/pull/379).
undefined initCompositionEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional Window? viewArg = null, optional DOMString dataArg = "");
undefined initCompositionEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional WindowProxy? viewArg = null, optional DOMString dataArg = "");
};

// https://w3c.github.io/uievents/#dictdef-compositioneventinit
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/KeyboardEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ bool KeyboardEvent::get_modifier_state(String const& key_arg) const
}

// https://w3c.github.io/uievents/#dom-keyboardevent-initkeyboardevent
void KeyboardEvent::init_keyboard_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& key, WebIDL::UnsignedLong location, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key)
void KeyboardEvent::init_keyboard_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, String const& key, WebIDL::UnsignedLong location, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key)
{
// Initializes attributes of a KeyboardEvent object. This method has the same behavior as UIEvent.initUIEvent().
// The value of detail remains undefined.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/KeyboardEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class KeyboardEvent final : public UIEvent {

virtual u32 which() const override { return m_key_code; }

void init_keyboard_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& key, WebIDL::UnsignedLong location, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key);
void init_keyboard_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, String const& key, WebIDL::UnsignedLong location, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key);

private:
KeyboardEvent(JS::Realm&, FlyString const& event_name, KeyboardEventInit const& event_init);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/KeyboardEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface KeyboardEvent : UIEvent {
boolean getModifierState(DOMString keyArg);

// https://w3c.github.io/uievents/#dom-keyboardevent-initkeyboardevent
undefined initKeyboardEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional Window? viewArg = null, optional DOMString keyArg = "", optional unsigned long locationArg = 0, optional boolean ctrlKey = false, optional boolean altKey = false, optional boolean shiftKey = false, optional boolean metaKey = false);
undefined initKeyboardEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional WindowProxy? viewArg = null, optional DOMString keyArg = "", optional unsigned long locationArg = 0, optional boolean ctrlKey = false, optional boolean altKey = false, optional boolean shiftKey = false, optional boolean metaKey = false);

};

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/MouseEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool MouseEvent::get_modifier_state(String const& key_arg) const
}

// https://w3c.github.io/uievents/#dom-mouseevent-initmouseevent
void MouseEvent::init_mouse_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, WebIDL::Long detail, WebIDL::Long screen_x, WebIDL::Long screen_y, WebIDL::Long client_x, WebIDL::Long client_y, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key, WebIDL::Short button, DOM::EventTarget* related_target)
void MouseEvent::init_mouse_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, WebIDL::Long detail, WebIDL::Long screen_x, WebIDL::Long screen_y, WebIDL::Long client_x, WebIDL::Long client_y, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key, WebIDL::Short button, DOM::EventTarget* related_target)
{
// Initializes attributes of a MouseEvent object. This method has the same behavior as UIEvent.initUIEvent().

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/MouseEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MouseEvent : public UIEvent {

virtual u32 which() const override { return m_button + 1; }

void init_mouse_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, WebIDL::Long detail, WebIDL::Long screen_x, WebIDL::Long screen_y, WebIDL::Long client_x, WebIDL::Long client_y, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key, WebIDL::Short button, DOM::EventTarget* related_target);
void init_mouse_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, WebIDL::Long detail, WebIDL::Long screen_x, WebIDL::Long screen_y, WebIDL::Long client_x, WebIDL::Long client_y, bool ctrl_key, bool alt_key, bool shift_key, bool meta_key, WebIDL::Short button, DOM::EventTarget* related_target);

protected:
MouseEvent(JS::Realm&, FlyString const& event_name, MouseEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/MouseEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface MouseEvent : UIEvent {
boolean getModifierState(DOMString keyArg);

// https://w3c.github.io/uievents/#dom-mouseevent-initmouseevent
undefined initMouseEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional Window? viewArg = null, optional long detailArg = 0, optional long screenXArg = 0, optional long screenYArg = 0, optional long clientXArg = 0, optional long clientYArg = 0, optional boolean ctrlKeyArg = false, optional boolean altKeyArg = false, optional boolean shiftKeyArg = false, optional boolean metaKeyArg = false, optional short buttonArg = 0, optional EventTarget? relatedTargetArg = null);
undefined initMouseEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional WindowProxy? viewArg = null, optional long detailArg = 0, optional long screenXArg = 0, optional long screenYArg = 0, optional long clientXArg = 0, optional long clientYArg = 0, optional boolean ctrlKeyArg = false, optional boolean altKeyArg = false, optional boolean shiftKeyArg = false, optional boolean metaKeyArg = false, optional short buttonArg = 0, optional EventTarget? relatedTargetArg = null);
};

// https://w3c.github.io/uievents/#idl-mouseeventinit
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/TextEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void TextEvent::initialize(JS::Realm& realm)
}

// https://w3c.github.io/uievents/#dom-textevent-inittextevent
void TextEvent::init_text_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data)
void TextEvent::init_text_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, String const& data)
{
// Initializes attributes of a TextEvent object. This method has the same behavior as UIEvent.initUIEvent().
// The value of detail remains undefined.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/TextEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TextEvent final : public UIEvent {
// https://w3c.github.io/uievents/#dom-textevent-data
String data() const { return m_data; }

void init_text_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, String const& data);
void init_text_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, String const& data);

private:
TextEvent(JS::Realm&, FlyString const& event_name);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibWeb/UIEvents/TextEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
[Exposed=Window]
interface TextEvent : UIEvent {
readonly attribute DOMString data;
undefined initTextEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional Window? view = null, optional DOMString data = "undefined");
undefined initTextEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional WindowProxy? view = null, optional DOMString data = "undefined");
};
1 change: 1 addition & 0 deletions Libraries/LibWeb/UIEvents/UIEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/UIEventPrototype.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/UIEvents/UIEvent.h>

namespace Web::UIEvents {
Expand Down
8 changes: 4 additions & 4 deletions Libraries/LibWeb/UIEvents/UIEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Web::UIEvents {

struct UIEventInit : public DOM::EventInit {
GC::Ptr<HTML::Window> view;
GC::Ptr<HTML::WindowProxy> view;
int detail { 0 };
};

Expand All @@ -27,11 +27,11 @@ class UIEvent : public DOM::Event {

virtual ~UIEvent() override;

HTML::Window const* view() const { return m_view.ptr(); }
GC::Ptr<HTML::WindowProxy> const view() const { return m_view; }
int detail() const { return m_detail; }
virtual u32 which() const { return 0; }

void init_ui_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, int detail)
void init_ui_event(String const& type, bool bubbles, bool cancelable, GC::Ptr<HTML::WindowProxy> view, int detail)
{
// Initializes attributes of an UIEvent object. This method has the same behavior as initEvent().

Expand All @@ -54,7 +54,7 @@ class UIEvent : public DOM::Event {
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;

GC::Ptr<HTML::Window> m_view;
GC::Ptr<HTML::WindowProxy> m_view;
int m_detail { 0 };
};

Expand Down
6 changes: 3 additions & 3 deletions Libraries/LibWeb/UIEvents/UIEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
[Exposed=Window]
interface UIEvent : Event {
constructor(DOMString type, optional UIEventInit eventInitDict = {});
readonly attribute Window? view;
readonly attribute WindowProxy? view;
readonly attribute long detail;

// Obsolete
[ImplementedAs=init_ui_event] undefined initUIEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional Window? viewArg = null, optional long detailArg = 0);
[ImplementedAs=init_ui_event] undefined initUIEvent(DOMString typeArg, optional boolean bubblesArg = false, optional boolean cancelableArg = false, optional WindowProxy? viewArg = null, optional long detailArg = 0);
readonly attribute unsigned long which;
};

// https://w3c.github.io/uievents/#idl-uieventinit
dictionary UIEventInit : EventInit {
Window? view = null;
WindowProxy? view = null;
long detail = 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static bool is_platform_object(Type const& type)
"VideoTrackList"sv,
"WebGLRenderingContext"sv,
"Window"sv,
"WindowProxy"sv,
"WritableStream"sv,
};
if (type.name().ends_with("Element"sv))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ Rerun

Found 5 tests

4 Pass
1 Fail
5 Pass
Details
Result Test Name MessagePass Calling initKeyboardEvent while dispatching.
Pass Calling initMouseEvent while dispatching.
Pass Calling initCustomEvent while dispatching.
Fail Calling initUIEvent while dispatching. Not an object of type Window
Pass Calling initUIEvent while dispatching.
Pass Calling initEvent while dispatching.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Rerun

Found 49 tests

43 Pass
6 Fail
49 Pass
Details
Result Test Name MessagePass Event constructor (no argument)
Pass Event constructor (undefined argument)
Expand All @@ -20,37 +19,37 @@ Pass UIEvent constructor (undefined argument)
Pass UIEvent constructor (null argument)
Pass UIEvent constructor (empty argument)
Pass UIEvent constructor (argument with default values)
Fail UIEvent constructor (argument with non-default values) Not an object of type Window
Pass UIEvent constructor (argument with non-default values)
Pass FocusEvent constructor (no argument)
Pass FocusEvent constructor (undefined argument)
Pass FocusEvent constructor (null argument)
Pass FocusEvent constructor (empty argument)
Pass FocusEvent constructor (argument with default values)
Fail FocusEvent constructor (argument with non-default values) Not an object of type Window
Pass FocusEvent constructor (argument with non-default values)
Pass MouseEvent constructor (no argument)
Pass MouseEvent constructor (undefined argument)
Pass MouseEvent constructor (null argument)
Pass MouseEvent constructor (empty argument)
Pass MouseEvent constructor (argument with default values)
Fail MouseEvent constructor (argument with non-default values) Not an object of type Window
Pass MouseEvent constructor (argument with non-default values)
Pass WheelEvent constructor (no argument)
Pass WheelEvent constructor (undefined argument)
Pass WheelEvent constructor (null argument)
Pass WheelEvent constructor (empty argument)
Pass WheelEvent constructor (argument with default values)
Fail WheelEvent constructor (argument with non-default values) Not an object of type Window
Pass WheelEvent constructor (argument with non-default values)
Pass KeyboardEvent constructor (no argument)
Pass KeyboardEvent constructor (undefined argument)
Pass KeyboardEvent constructor (null argument)
Pass KeyboardEvent constructor (empty argument)
Pass KeyboardEvent constructor (argument with default values)
Fail KeyboardEvent constructor (argument with non-default values) Not an object of type Window
Pass KeyboardEvent constructor (argument with non-default values)
Pass CompositionEvent constructor (no argument)
Pass CompositionEvent constructor (undefined argument)
Pass CompositionEvent constructor (null argument)
Pass CompositionEvent constructor (empty argument)
Pass CompositionEvent constructor (argument with default values)
Fail CompositionEvent constructor (argument with non-default values) Not an object of type Window
Pass CompositionEvent constructor (argument with non-default values)
Pass SubclassedEvent constructor (no argument)
Pass SubclassedEvent constructor (undefined argument)
Pass SubclassedEvent constructor (null argument)
Expand Down

0 comments on commit 2dcecdf

Please sign in to comment.