mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
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. :^)
This commit is contained in:
parent
1484980f8f
commit
d69133e4ac
4 changed files with 33 additions and 0 deletions
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue