mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
Previously, the LibWeb bindings generator would output multiple per interface files like Prototype/Constructor/Namespace/GlobalMixin depending on the contents of that IDL file. This complicates the build system as it means that it does not know what files will be generated without knowledge of the contents of that IDL file. Instead, for each IDL file only generate a single Bindings/<IDLFile>.h and Bindings/<IDLFile>.cpp.
86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
/*
|
||
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
|
||
* Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org>
|
||
*
|
||
* SPDX-License-Identifier: BSD-2-Clause
|
||
*/
|
||
|
||
#include <LibWeb/Bindings/CSSStyleDeclaration.h>
|
||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||
#include <LibWeb/Bindings/Intrinsics.h>
|
||
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
||
#include <LibWeb/CSS/StyleComputer.h>
|
||
#include <LibWeb/DOM/Document.h>
|
||
#include <LibWeb/DOM/Element.h>
|
||
|
||
namespace Web::CSS {
|
||
|
||
GC_DEFINE_ALLOCATOR(CSSStyleDeclaration);
|
||
|
||
CSSStyleDeclaration::CSSStyleDeclaration(JS::Realm& realm, Computed computed, Readonly readonly)
|
||
: PlatformObject(realm)
|
||
, m_computed(computed == Computed::Yes)
|
||
, m_readonly(readonly == Readonly::Yes)
|
||
{
|
||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
|
||
.supports_indexed_properties = true,
|
||
};
|
||
}
|
||
|
||
void CSSStyleDeclaration::initialize(JS::Realm& realm)
|
||
{
|
||
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSStyleDeclaration);
|
||
Base::initialize(realm);
|
||
}
|
||
|
||
// https://drafts.csswg.org/cssom/#update-style-attribute-for
|
||
void CSSStyleDeclaration::update_style_attribute()
|
||
{
|
||
// 1. Assert: declaration block’s computed flag is unset.
|
||
VERIFY(!is_computed());
|
||
|
||
// 2. Let owner node be declaration block’s owner node.
|
||
// 3. If owner node is null, then return.
|
||
if (!owner_node().has_value())
|
||
return;
|
||
|
||
// 4. Set declaration block’s updating flag.
|
||
set_is_updating(true);
|
||
|
||
// 5. Set an attribute value for owner node using "style" and the result of serializing declaration block.
|
||
owner_node()->element().set_attribute_value(HTML::AttributeNames::style, serialized());
|
||
|
||
// 6. Unset declaration block’s updating flag.
|
||
set_is_updating(false);
|
||
}
|
||
|
||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
|
||
String CSSStyleDeclaration::css_text() const
|
||
{
|
||
// 1. If the computed flag is set, then return the empty string.
|
||
if (is_computed())
|
||
return {};
|
||
|
||
// 2. Return the result of serializing the declarations.
|
||
return serialized();
|
||
}
|
||
|
||
Optional<JS::Value> CSSStyleDeclaration::item_value(size_t index) const
|
||
{
|
||
auto value = item(index);
|
||
if (value.is_empty())
|
||
return {};
|
||
|
||
return JS::PrimitiveString::create(vm(), value);
|
||
}
|
||
|
||
void CSSStyleDeclaration::visit_edges(Visitor& visitor)
|
||
{
|
||
Base::visit_edges(visitor);
|
||
visitor.visit(m_parent_rule);
|
||
if (m_owner_node.has_value())
|
||
m_owner_node->visit(visitor);
|
||
}
|
||
|
||
}
|