1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibWeb/HTML: Port Window.getComputedStyle() to IDL

This commit is contained in:
Linus Groh 2023-03-06 22:18:29 +00:00
parent 8454eb874f
commit b59505aba5
3 changed files with 13 additions and 18 deletions

View file

@ -596,11 +596,6 @@ Page const* Window::page() const
return associated_document().page();
}
CSS::CSSStyleDeclaration* Window::get_computed_style_impl(DOM::Element& element) const
{
return CSS::ResolvedCSSStyleDeclaration::create(element).release_value_but_fixme_should_propagate_errors().ptr();
}
Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID media_feature) const
{
// FIXME: Many of these should be dependent on the hardware
@ -964,7 +959,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
define_native_function(realm, "requestIdleCallback", request_idle_callback, 1, attr);
define_native_function(realm, "cancelIdleCallback", cancel_idle_callback, 1, attr);
define_native_function(realm, "getComputedStyle", get_computed_style, 1, attr);
define_native_function(realm, "getSelection", get_selection, 0, attr);
define_native_function(realm, "structuredClone", structured_clone, 1, attr);
@ -1213,6 +1207,14 @@ Variant<JS::Handle<DOM::Event>, JS::Value> Window::event() const
return JS::js_undefined();
}
// https://w3c.github.io/csswg-drafts/cssom/#dom-window-getcomputedstyle
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::CSSStyleDeclaration>> Window::get_computed_style(DOM::Element& element, Optional<String> const& pseudo_element) const
{
// FIXME: Make this fully spec compliant.
(void)pseudo_element;
return MUST_OR_THROW_OOM(heap().allocate<CSS::ResolvedCSSStyleDeclaration>(realm(), element));
}
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-matchmedia
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::MediaQueryList>> Window::match_media(String const& query)
{
@ -1654,16 +1656,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
return JS::js_undefined();
}
JS_DEFINE_NATIVE_FUNCTION(Window::get_computed_style)
{
auto* impl = TRY(impl_from(vm));
auto* object = TRY(vm.argument(0).to_object(vm));
if (!is<DOM::Element>(object))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element");
return impl->get_computed_style_impl(*static_cast<DOM::Element*>(object));
}
// https://w3c.github.io/selection-api/#dom-window-getselection
JS_DEFINE_NATIVE_FUNCTION(Window::get_selection)
{