diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-11 00:33:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-11 00:36:37 +0200 |
commit | d69133e4acecae9faef1b803685f19a6ec4cb29f (patch) | |
tree | fac0fe12088137a4be67afac424a1ce893be51b5 /Userland/Libraries/LibWeb/Bindings/WindowObject.cpp | |
parent | 1484980f8fab5c24837844d773acf80cb8c4ad2a (diff) | |
download | serenity-d69133e4acecae9faef1b803685f19a6ec4cb29f.zip |
LibWeb: Stub out a dummy window.getComputedStyle()
This just returns an empty CSSStyleDeclaration for now. The real thing
needs to be a live object that provides a view onto the computed style
of a given element. This is far from that, but it's something. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings/WindowObject.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/WindowObject.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index c0cdd3234b..e643a9b0e0 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -11,7 +11,9 @@ #include <LibJS/Runtime/FunctionObject.h> #include <LibJS/Runtime/Shape.h> #include <LibTextCodec/Decoder.h> +#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h> #include <LibWeb/Bindings/DocumentWrapper.h> +#include <LibWeb/Bindings/ElementWrapper.h> #include <LibWeb/Bindings/EventTargetConstructor.h> #include <LibWeb/Bindings/EventTargetPrototype.h> #include <LibWeb/Bindings/EventWrapper.h> @@ -70,6 +72,8 @@ void WindowObject::initialize_global_object() define_native_function("atob", atob, 1, attr); define_native_function("btoa", btoa, 1, attr); + define_native_function("getComputedStyle", get_computed_style, 1, attr); + // Legacy define_native_accessor("event", event_getter, {}, JS::Attribute::Enumerable); @@ -437,4 +441,21 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_height_getter) return JS::Value(impl->inner_height()); } +JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style) +{ + auto* impl = impl_from(vm, global_object); + if (!impl) + return {}; + auto* object = vm.argument(0).to_object(global_object); + if (vm.exception()) + return {}; + + if (!is<ElementWrapper>(object)) { + vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "DOM element"); + return {}; + } + + return wrap(global_object, impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl())); +} + } |