diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index b409f1a681..bca88a83b9 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -628,13 +628,6 @@ CSS::CSSStyleDeclaration* Window::get_computed_style_impl(DOM::Element& element) return CSS::ResolvedCSSStyleDeclaration::create(element).release_value_but_fixme_should_propagate_errors().ptr(); } -JS::NonnullGCPtr Window::match_media_impl(DeprecatedString media) -{ - auto media_query_list = CSS::MediaQueryList::create(associated_document(), parse_media_query_list(CSS::Parser::ParsingContext(associated_document()), media)).release_value_but_fixme_should_propagate_errors(); - associated_document().add_media_query_list(*media_query_list); - return media_query_list; -} - Optional Window::query_media_feature(CSS::MediaFeatureID media_feature) const { // FIXME: Many of these should be dependent on the hardware @@ -1063,7 +1056,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge, JS::Value> Window::event() const return JS::js_undefined(); } +// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-matchmedia +WebIDL::ExceptionOr> Window::match_media(String const& query) +{ + // 1. Let parsed media query list be the result of parsing query. + auto parsed_media_query_list = parse_media_query_list(CSS::Parser::ParsingContext(associated_document()), query); + + // 2. Return a new MediaQueryList object, with this's associated Document as the document, with parsed media query list as its associated media query list. + auto media_query_list = MUST_OR_THROW_OOM(heap().allocate(realm(), associated_document(), move(parsed_media_query_list))); + associated_document().add_media_query_list(media_query_list); + return media_query_list; +} + // https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance WebIDL::ExceptionOr> Window::performance() { @@ -1573,13 +1577,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::get_selection) return impl->associated_document().get_selection(); } -JS_DEFINE_NATIVE_FUNCTION(Window::match_media) -{ - auto* impl = TRY(impl_from(vm)); - auto media = TRY(vm.argument(0).to_deprecated_string(vm)); - return impl->match_media_impl(move(media)); -} - // https://www.w3.org/TR/cssom-view/#dom-window-scrollx JS_DEFINE_NATIVE_FUNCTION(Window::scroll_x_getter) { diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 032a943509..35ca5b42ef 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -103,7 +103,6 @@ public: void set_current_event(DOM::Event* event); CSS::CSSStyleDeclaration* get_computed_style_impl(DOM::Element&) const; - JS::NonnullGCPtr match_media_impl(DeprecatedString); Optional query_media_feature(CSS::MediaFeatureID) const; float scroll_x() const; @@ -165,6 +164,8 @@ public: Variant, JS::Value> event() const; + WebIDL::ExceptionOr> match_media(String const& query); + WebIDL::ExceptionOr> performance(); WebIDL::ExceptionOr> crypto(); @@ -266,7 +267,6 @@ private: JS_DECLARE_NATIVE_FUNCTION(focus); JS_DECLARE_NATIVE_FUNCTION(get_computed_style); - JS_DECLARE_NATIVE_FUNCTION(match_media); JS_DECLARE_NATIVE_FUNCTION(get_selection); JS_DECLARE_NATIVE_FUNCTION(queue_microtask); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 19eb2a20a7..18a1c0920a 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -1,4 +1,5 @@ #import +#import #import #import #import @@ -42,6 +43,9 @@ interface Window : EventTarget { // https://dom.spec.whatwg.org/#interface-window-extensions [Replaceable] readonly attribute (Event or undefined) event; // legacy + // https://w3c.github.io/csswg-drafts/cssom-view/#extensions-to-the-window-interface + [NewObject] MediaQueryList matchMedia(CSSOMString query); + // FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope // https://w3c.github.io/hr-time/#the-performance-attribute [Replaceable] readonly attribute Performance performance;