From 51da5d03da8e462ef91a331453c345c88f961726 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 12 Sep 2021 17:10:27 +0100 Subject: LibWeb: Implement window.matchMedia() --- Userland/Libraries/LibWeb/Bindings/WindowObject.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Userland/Libraries/LibWeb/Bindings/WindowObject.cpp') diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index 640024fff8..01e82d0d09 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,7 @@ void WindowObject::initialize_global_object() define_native_function("btoa", btoa, 1, attr); define_native_function("getComputedStyle", get_computed_style, 1, attr); + define_native_function("matchMedia", match_media, 1, attr); // FIXME: These properties should be [Replaceable] according to the spec, but [Writable+Configurable] is the closest we have. define_native_accessor("scrollX", scroll_x_getter, {}, attr); @@ -483,6 +485,17 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style) return wrap(global_object, impl->get_computed_style(static_cast(object)->impl())); } +JS_DEFINE_NATIVE_FUNCTION(WindowObject::match_media) +{ + auto* impl = impl_from(vm, global_object); + if (!impl) + return {}; + auto media = vm.argument(0).to_string(global_object); + if (vm.exception()) + return {}; + return wrap(global_object, impl->match_media(move(media))); +} + // https://www.w3.org/TR/cssom-view/#dom-window-scrollx JS_DEFINE_NATIVE_GETTER(WindowObject::scroll_x_getter) { -- cgit v1.2.3