diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp index 44876546ca..5cc89376ba 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp @@ -918,6 +918,8 @@ static NonnullOwnPtr parse_interface(StringView filename, StringView static bool is_wrappable_type(Type const& type) { + if (type.name == "EventTarget") + return true; if (type.name == "Node") return true; if (type.name == "Document") diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index 10028a0c93..cac70f5aad 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -60,6 +60,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 7451212877..1f59aa84ee 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -272,6 +272,7 @@ set(SOURCES Selection/Selection.cpp StylePropertiesModel.cpp UIEvents/EventNames.cpp + UIEvents/FocusEvent.cpp UIEvents/KeyboardEvent.cpp UIEvents/MouseEvent.cpp URL/URL.cpp @@ -504,6 +505,7 @@ libweb_js_wrapper(SVG/SVGGraphicsElement) libweb_js_wrapper(SVG/SVGPathElement) libweb_js_wrapper(SVG/SVGSVGElement) libweb_js_wrapper(Selection/Selection) +libweb_js_wrapper(UIEvents/FocusEvent) libweb_js_wrapper(UIEvents/KeyboardEvent) libweb_js_wrapper(UIEvents/MouseEvent) libweb_js_wrapper(UIEvents/UIEvent) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f6d6fae338..7e66f898b2 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -748,7 +749,7 @@ NonnullRefPtr Document::create_event(const String& interface) } else if (interface_lowercase.is_one_of("event", "events")) { event = Event::create(""); } else if (interface_lowercase == "focusevent") { - event = Event::create(""); // FIXME: Create FocusEvent + event = UIEvents::FocusEvent::create(""); } else if (interface_lowercase == "hashchangeevent") { event = Event::create(""); // FIXME: Create HashChangeEvent } else if (interface_lowercase == "htmlevents") { diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index e9b1786257..414b387d10 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -333,6 +333,7 @@ class ElementWrapper; class EventListenerWrapper; class EventTargetWrapper; class EventWrapper; +class FocusEventWrapper; class HistoryWrapper; class HTMLAnchorElementWrapper; class HTMLAreaElementWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 8ab7f37af2..fd77b0e57d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace Web::HTML { @@ -226,7 +227,7 @@ static void run_focus_update_steps(Vector old_chain, Vectorset_related_target(related_blur_target); blur_event_target->dispatch_event(move(blur_event)); } @@ -269,7 +270,7 @@ static void run_focus_update_steps(Vector old_chain, Vectorset_related_target(related_focus_target); focus_event_target->dispatch_event(move(focus_event)); } diff --git a/Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp new file mode 100644 index 0000000000..3397fc7b60 --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::UIEvents { + +FocusEvent::FocusEvent(FlyString const& event_name, FocusEventInit const& event_init) + : UIEvent(event_name) +{ + set_related_target(const_cast(event_init.related_target.ptr())); +} + +FocusEvent::~FocusEvent() +{ +} + +} diff --git a/Userland/Libraries/LibWeb/UIEvents/FocusEvent.h b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.h new file mode 100644 index 0000000000..4a244dbede --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::UIEvents { + +struct FocusEventInit : public UIEventInit { + RefPtr related_target; +}; + +class FocusEvent final : public UIEvent { +public: + using WrapperType = Bindings::FocusEventWrapper; + + virtual ~FocusEvent() override; + + static NonnullRefPtr create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, FocusEventInit const& event_init) + { + return adopt_ref(*new FocusEvent(event_name, event_init)); + } + +private: + FocusEvent(FlyString const& event_name, FocusEventInit const&); +}; + +} diff --git a/Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl new file mode 100644 index 0000000000..1cba0af8fd --- /dev/null +++ b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl @@ -0,0 +1,15 @@ +#import + +[Exposed=Window] +interface FocusEvent : UIEvent { + + constructor(DOMString type, optional FocusEventInit eventInitDict = {}); + readonly attribute EventTarget? relatedTarget; + +}; + +dictionary FocusEventInit : UIEventInit { + + EventTarget? relatedTarget = null; + +};