mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-16 15:21:56 +00:00
LibWeb: Generate IDL attributes for all supported CSS properties
The CSSOM spec tells us to potentially add up to three different IDL attributes to CSSStyleDeclaration for every CSS property we support: - A camelCased attribute, where a dash indicates the next character should be uppercase - A camelCased attribute for every -webkit- prefixed property, with the first letter always being lowercase - A dashed-attribute for every property with a dash in it. Additionally, every attribute must have the CEReactions and LegacyNullToEmptyString extended attributes specified on it. Since we specify every property we support with Properties.json, we can use that file to generate the IDL file and it's implementation. We import it from the Build directory with the help of multiple import base paths. Then, we add it to CSSStyleDeclaration via the mixin functionality and inheriting the generated class in CSSStyleDeclaration.
This commit is contained in:
parent
d95ae629ee
commit
aacf9b08ed
Notes:
github-actions[bot]
2024-11-14 18:51:20 +00:00
Author: https://github.com/Lubrsi
Commit: aacf9b08ed
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2346
12 changed files with 909 additions and 60 deletions
|
@ -314,6 +314,20 @@ String CSSStyleDeclaration::css_text() const
|
|||
return serialized();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstyleproperties-cssfloat
|
||||
String CSSStyleDeclaration::css_float() const
|
||||
{
|
||||
// The cssFloat attribute, on getting, must return the result of invoking getPropertyValue() with float as argument.
|
||||
return get_property_value("float"sv);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSStyleDeclaration::set_css_float(StringView value)
|
||||
{
|
||||
// On setting, the attribute must invoke setProperty() with float as first argument, as second argument the given value,
|
||||
// and no third argument. Any exceptions thrown must be re-thrown.
|
||||
return set_property("float"sv, value, ""sv);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration
|
||||
static String serialize_a_css_declaration(CSS::PropertyID property, StringView value, Important important)
|
||||
{
|
||||
|
@ -436,55 +450,6 @@ String PropertyOwningCSSStyleDeclaration::serialized() const
|
|||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
static CSS::PropertyID property_id_from_name(StringView name)
|
||||
{
|
||||
// FIXME: Perhaps this should go in the code generator.
|
||||
if (name == "cssFloat"sv)
|
||||
return CSS::PropertyID::Float;
|
||||
|
||||
if (auto property_id = CSS::property_id_from_camel_case_string(name); property_id.has_value())
|
||||
return property_id.value();
|
||||
|
||||
if (auto property_id = CSS::property_id_from_string(name); property_id.has_value())
|
||||
return property_id.value();
|
||||
|
||||
return CSS::PropertyID::Invalid;
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_has_property(JS::PropertyKey const& name) const
|
||||
{
|
||||
if (!name.is_string())
|
||||
return Base::internal_has_property(name);
|
||||
return property_id_from_name(name.to_string()) != CSS::PropertyID::Invalid;
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<JS::Value> CSSStyleDeclaration::internal_get(JS::PropertyKey const& name, JS::Value receiver, JS::CacheablePropertyMetadata* cacheable_metadata, PropertyLookupPhase phase) const
|
||||
{
|
||||
if (name.is_number())
|
||||
return { JS::PrimitiveString::create(vm(), item(name.as_number())) };
|
||||
if (!name.is_string())
|
||||
return Base::internal_get(name, receiver, cacheable_metadata, phase);
|
||||
auto property_id = property_id_from_name(name.to_string());
|
||||
if (property_id == CSS::PropertyID::Invalid)
|
||||
return Base::internal_get(name, receiver, cacheable_metadata, phase);
|
||||
return JS::PrimitiveString::create(vm(), get_property_value(string_from_property_id(property_id)));
|
||||
}
|
||||
|
||||
JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_set(JS::PropertyKey const& name, JS::Value value, JS::Value receiver, JS::CacheablePropertyMetadata* cacheable_metadata)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
if (!name.is_string())
|
||||
return Base::internal_set(name, value, receiver, cacheable_metadata);
|
||||
auto property_id = property_id_from_name(name.to_string());
|
||||
if (property_id == CSS::PropertyID::Invalid)
|
||||
return Base::internal_set(name, value, receiver, cacheable_metadata);
|
||||
|
||||
auto css_text = value.is_null() ? String {} : TRY(value.to_string(vm));
|
||||
|
||||
TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return set_property(property_id, css_text); }));
|
||||
return true;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> PropertyOwningCSSStyleDeclaration::set_css_text(StringView css_text)
|
||||
{
|
||||
dbgln("(STUBBED) PropertyOwningCSSStyleDeclaration::set_css_text(css_text='{}')", css_text);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue