diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 77e1622f0eb..9413a99d05c 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -170,6 +170,7 @@ set(SOURCES CSS/SystemColor.cpp CSS/Time.cpp CSS/Transformation.cpp + CSS/TransitionEvent.cpp CSS/VisualViewport.cpp Cookie/Cookie.cpp Cookie/ParsedCookie.cpp diff --git a/Libraries/LibWeb/CSS/TransitionEvent.cpp b/Libraries/LibWeb/CSS/TransitionEvent.cpp new file mode 100644 index 00000000000..6eaaad214a8 --- /dev/null +++ b/Libraries/LibWeb/CSS/TransitionEvent.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, Lucas Chollet . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "TransitionEvent.h" +#include +#include + +namespace Web::CSS { + +GC_DEFINE_ALLOCATOR(TransitionEvent); + +GC::Ref TransitionEvent::create(JS::Realm& realm, FlyString const& type, TransitionEventInit const& event_init) +{ + auto event = realm.create(realm, type, event_init); + event->set_is_trusted(true); + return event; +} + +GC::Ref TransitionEvent::construct_impl(JS::Realm& realm, FlyString const& type, TransitionEventInit const& event_init) +{ + return realm.create(realm, type, event_init); +} + +TransitionEvent::TransitionEvent(JS::Realm& realm, FlyString const& type, TransitionEventInit const& event_init) + : DOM::Event(realm, type, event_init) + , m_property_name(event_init.property_name) + , m_elapsed_time(event_init.elapsed_time) + , m_pseudo_element(event_init.pseudo_element) +{ +} + +TransitionEvent::~TransitionEvent() = default; + +void TransitionEvent::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(TransitionEvent); +} + +} diff --git a/Libraries/LibWeb/CSS/TransitionEvent.h b/Libraries/LibWeb/CSS/TransitionEvent.h new file mode 100644 index 00000000000..876c71218ad --- /dev/null +++ b/Libraries/LibWeb/CSS/TransitionEvent.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024, Lucas Chollet . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::CSS { + +struct TransitionEventInit : public DOM::EventInit { + String property_name {}; + double elapsed_time = 0.0; + String pseudo_element {}; +}; + +class TransitionEvent final : public DOM::Event { + WEB_PLATFORM_OBJECT(TransitionEvent, DOM::Event); + GC_DECLARE_ALLOCATOR(TransitionEvent); + +public: + [[nodiscard]] static GC::Ref create(JS::Realm&, FlyString const& event_name, TransitionEventInit const& = {}); + [[nodiscard]] static GC::Ref construct_impl(JS::Realm&, FlyString const& event_name, TransitionEventInit const& = {}); + + virtual ~TransitionEvent() override; + + String const& property_name() const { return m_property_name; } + double elapsed_time() const { return m_elapsed_time; } + String const& pseudo_element() const { return m_pseudo_element; } + +private: + TransitionEvent(JS::Realm&, FlyString const& event_name, TransitionEventInit const& event_init); + + virtual void initialize(JS::Realm&) override; + + String m_property_name {}; + double m_elapsed_time {}; + String m_pseudo_element {}; +}; +} diff --git a/Libraries/LibWeb/CSS/TransitionEvent.idl b/Libraries/LibWeb/CSS/TransitionEvent.idl new file mode 100644 index 00000000000..3ead72fccb9 --- /dev/null +++ b/Libraries/LibWeb/CSS/TransitionEvent.idl @@ -0,0 +1,16 @@ +#import + +// https://drafts.csswg.org/css-transitions/#transitionevent +[Exposed=Window] +interface TransitionEvent : Event { + constructor(CSSOMString type, optional TransitionEventInit transitionEventInitDict = {}); + readonly attribute CSSOMString propertyName; + readonly attribute double elapsedTime; + readonly attribute CSSOMString pseudoElement; +}; + +dictionary TransitionEventInit : EventInit { + CSSOMString propertyName = ""; + double elapsedTime = 0.0; + CSSOMString pseudoElement = ""; +}; diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake index 95c1f2ff729..f28e335f6b5 100644 --- a/Libraries/LibWeb/idl_files.cmake +++ b/Libraries/LibWeb/idl_files.cmake @@ -46,6 +46,7 @@ libweb_js_bindings(CSS/Screen) libweb_js_bindings(CSS/ScreenOrientation) libweb_js_bindings(CSS/StyleSheet) libweb_js_bindings(CSS/StyleSheetList) +libweb_js_bindings(CSS/TransitionEvent) libweb_js_bindings(CSS/VisualViewport) libweb_js_bindings(DOM/AbstractRange) libweb_js_bindings(DOM/Attr) diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index 399e330c996..83c75af1c98 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -381,6 +381,7 @@ ToggleEvent TrackEvent TransformStream TransformStreamDefaultController +TransitionEvent TreeWalker TypeError UIEvent diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-transitions/transitionevent-interface.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-transitions/transitionevent-interface.txt new file mode 100644 index 00000000000..c9d096d3812 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-transitions/transitionevent-interface.txt @@ -0,0 +1,46 @@ +Harness status: OK + +Found 41 tests + +41 Pass +Pass the event is an instance of TransitionEvent +Pass the event inherts from Event +Pass Missing type argument +Pass type argument is string +Pass type argument is null +Pass event type set to undefined +Pass propertyName has default value of empty string +Pass elapsedTime has default value of 0.0 +Pass propertyName is readonly +Pass elapsedTime is readonly +Pass animationEventInit argument is null +Pass animationEventInit argument is undefined +Pass animationEventInit argument is empty dictionary +Pass TransitionEvent.pseudoElement initialized from the dictionary +Pass propertyName set to 'sample' +Pass propertyName set to undefined +Pass propertyName set to null +Pass propertyName set to false +Pass propertyName set to true +Pass propertyName set to a number +Pass propertyName set to [] +Pass propertyName set to [1, 2, 3] +Pass propertyName set to an object +Pass propertyName set to an object with a valueOf function +Pass elapsedTime set to 0.5 +Pass elapsedTime set to -0.5 +Pass elapsedTime set to undefined +Pass elapsedTime set to null +Pass elapsedTime set to false +Pass elapsedTime set to true +Pass elapsedTime set to '' +Pass elapsedTime set to [] +Pass elapsedTime set to [0.5] +Pass elapsedTime set to an object with a valueOf function +Pass elapsedTime cannot be set to NaN +Pass elapsedTime cannot be set to Infinity +Pass elapsedTime cannot be set to -Infinity +Pass elapsedTime cannot be set to 'sample' +Pass elapsedTime cannot be set to [0.5, 1.0] +Pass elapsedTime cannot be set to an object +Pass TransitionEventInit properties set value \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-transitions/transitionevent-interface.html b/Tests/LibWeb/Text/input/wpt-import/css/css-transitions/transitionevent-interface.html new file mode 100644 index 00000000000..b72e21d50a8 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-transitions/transitionevent-interface.html @@ -0,0 +1,229 @@ + + +CSS Transitions Test: TransitionEvent interface + + + + + + +