LibWeb: Take UTF-16 names in get_property_value
Change get_property_value() to take a Utf16FlyString so generated CSS property accessors can pass their JS property names through without constructing FlyString instances first. Keep the existing internal descriptor and custom-property storage shape for now, and convert at those boundaries while the remaining CSS property APIs are migrated separately.
This commit is contained in:
parent
ed6aec8dfa
commit
22a26babc5
9 changed files with 62 additions and 41 deletions
|
|
@ -139,7 +139,7 @@ WebIDL::ExceptionOr<String> CSSDescriptors::remove_property(FlyString const& pro
|
|||
// AD-HOC: We compare names case-insensitively instead.
|
||||
|
||||
// 3. Let value be the return value of invoking getPropertyValue() with property as argument.
|
||||
auto value = get_property_value(property);
|
||||
auto value = get_property_value(Utf16FlyString::from_utf8(property));
|
||||
|
||||
// 4. Let removed be false.
|
||||
bool removed = false;
|
||||
|
|
@ -170,14 +170,20 @@ WebIDL::ExceptionOr<String> CSSDescriptors::remove_property(FlyString const& pro
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||
String CSSDescriptors::get_property_value(FlyString const& property) const
|
||||
String CSSDescriptors::get_property_value(Utf16FlyString const& property) const
|
||||
{
|
||||
if (!property.is_ascii())
|
||||
return {};
|
||||
|
||||
auto property_string = property.to_utf16_string();
|
||||
auto property_name = MUST(FlyString::from_utf8(property_string.ascii_view()));
|
||||
|
||||
// 1. If property is not a custom property, follow these substeps: ...
|
||||
// NB: These substeps only apply to shorthands, and descriptors cannot be shorthands.
|
||||
|
||||
// 2. If property is a case-sensitive match for a property name of a CSS declaration in the declarations, then
|
||||
// return the result of invoking serialize a CSS value of that declaration.
|
||||
auto descriptor_name_and_id = DescriptorNameAndID::from_name(m_at_rule_id, property);
|
||||
auto descriptor_name_and_id = DescriptorNameAndID::from_name(m_at_rule_id, property_name);
|
||||
if (descriptor_name_and_id.has_value()) {
|
||||
auto match = m_descriptors.first_matching([descriptor_name_and_id](Descriptor const& entry) { return entry.descriptor_name_and_id == descriptor_name_and_id; });
|
||||
if (match.has_value())
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public:
|
|||
virtual String item(size_t index) const override;
|
||||
virtual WebIDL::ExceptionOr<void> set_property(FlyString const& property, StringView value, StringView priority) override;
|
||||
virtual WebIDL::ExceptionOr<String> remove_property(FlyString const& property) override;
|
||||
virtual String get_property_value(FlyString const& property) const override;
|
||||
virtual String get_property_value(Utf16FlyString const& property) const override;
|
||||
virtual StringView get_property_priority(FlyString const& property) const override;
|
||||
|
||||
Vector<Descriptor> const& descriptors() const { return m_descriptors; }
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_ascent_override(StringView
|
|||
|
||||
String CSSFontFaceDescriptors::ascent_override() const
|
||||
{
|
||||
return get_property_value("ascent-override"_fly_string);
|
||||
return get_property_value("ascent-override"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_descent_override(StringView value)
|
||||
|
|
@ -59,7 +59,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_descent_override(StringVie
|
|||
|
||||
String CSSFontFaceDescriptors::descent_override() const
|
||||
{
|
||||
return get_property_value("descent-override"_fly_string);
|
||||
return get_property_value("descent-override"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_display(StringView value)
|
||||
|
|
@ -69,7 +69,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_display(StringView va
|
|||
|
||||
String CSSFontFaceDescriptors::font_display() const
|
||||
{
|
||||
return get_property_value("font-display"_fly_string);
|
||||
return get_property_value("font-display"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_family(StringView value)
|
||||
|
|
@ -79,7 +79,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_family(StringView val
|
|||
|
||||
String CSSFontFaceDescriptors::font_family() const
|
||||
{
|
||||
return get_property_value("font-family"_fly_string);
|
||||
return get_property_value("font-family"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_feature_settings(StringView value)
|
||||
|
|
@ -89,7 +89,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_feature_settings(Stri
|
|||
|
||||
String CSSFontFaceDescriptors::font_feature_settings() const
|
||||
{
|
||||
return get_property_value("font-feature-settings"_fly_string);
|
||||
return get_property_value("font-feature-settings"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_language_override(StringView value)
|
||||
|
|
@ -99,7 +99,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_language_override(Str
|
|||
|
||||
String CSSFontFaceDescriptors::font_language_override() const
|
||||
{
|
||||
return get_property_value("font-language-override"_fly_string);
|
||||
return get_property_value("font-language-override"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_named_instance(StringView value)
|
||||
|
|
@ -109,7 +109,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_named_instance(String
|
|||
|
||||
String CSSFontFaceDescriptors::font_named_instance() const
|
||||
{
|
||||
return get_property_value("font-named-instance"_fly_string);
|
||||
return get_property_value("font-named-instance"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_style(StringView value)
|
||||
|
|
@ -119,7 +119,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_style(StringView valu
|
|||
|
||||
String CSSFontFaceDescriptors::font_style() const
|
||||
{
|
||||
return get_property_value("font-style"_fly_string);
|
||||
return get_property_value("font-style"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_variation_settings(StringView value)
|
||||
|
|
@ -129,7 +129,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_variation_settings(St
|
|||
|
||||
String CSSFontFaceDescriptors::font_variation_settings() const
|
||||
{
|
||||
return get_property_value("font-variation-settings"_fly_string);
|
||||
return get_property_value("font-variation-settings"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_weight(StringView value)
|
||||
|
|
@ -139,7 +139,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_weight(StringView val
|
|||
|
||||
String CSSFontFaceDescriptors::font_weight() const
|
||||
{
|
||||
return get_property_value("font-weight"_fly_string);
|
||||
return get_property_value("font-weight"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_width(StringView value)
|
||||
|
|
@ -149,7 +149,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_font_width(StringView valu
|
|||
|
||||
String CSSFontFaceDescriptors::font_width() const
|
||||
{
|
||||
return get_property_value("font-width"_fly_string);
|
||||
return get_property_value("font-width"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_line_gap_override(StringView value)
|
||||
|
|
@ -159,7 +159,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_line_gap_override(StringVi
|
|||
|
||||
String CSSFontFaceDescriptors::line_gap_override() const
|
||||
{
|
||||
return get_property_value("line-gap-override"_fly_string);
|
||||
return get_property_value("line-gap-override"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_src(StringView value)
|
||||
|
|
@ -169,7 +169,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_src(StringView value)
|
|||
|
||||
String CSSFontFaceDescriptors::src() const
|
||||
{
|
||||
return get_property_value("src"_fly_string);
|
||||
return get_property_value("src"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_unicode_range(StringView value)
|
||||
|
|
@ -179,7 +179,7 @@ WebIDL::ExceptionOr<void> CSSFontFaceDescriptors::set_unicode_range(StringView v
|
|||
|
||||
String CSSFontFaceDescriptors::unicode_range() const
|
||||
{
|
||||
return get_property_value("unicode-range"_fly_string);
|
||||
return get_property_value("unicode-range"_utf16_fly_string);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void CSSFunctionDescriptors::initialize(JS::Realm& realm)
|
|||
// https://drafts.csswg.org/css-mixins-1/#dom-cssfunctiondescriptors-result
|
||||
String CSSFunctionDescriptors::result() const
|
||||
{
|
||||
return get_property_value("result"_string);
|
||||
return get_property_value("result"_utf16_fly_string);
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-mixins-1/#dom-cssfunctiondescriptors-result
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin(StringView value)
|
|||
|
||||
String CSSPageDescriptors::margin() const
|
||||
{
|
||||
return get_property_value("margin"_fly_string);
|
||||
return get_property_value("margin"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_top(StringView value)
|
||||
|
|
@ -48,7 +48,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_top(StringView value)
|
|||
|
||||
String CSSPageDescriptors::margin_top() const
|
||||
{
|
||||
return get_property_value("margin-top"_fly_string);
|
||||
return get_property_value("margin-top"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_right(StringView value)
|
||||
|
|
@ -58,7 +58,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_right(StringView value)
|
|||
|
||||
String CSSPageDescriptors::margin_right() const
|
||||
{
|
||||
return get_property_value("margin-right"_fly_string);
|
||||
return get_property_value("margin-right"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_bottom(StringView value)
|
||||
|
|
@ -68,7 +68,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_bottom(StringView value
|
|||
|
||||
String CSSPageDescriptors::margin_bottom() const
|
||||
{
|
||||
return get_property_value("margin-bottom"_fly_string);
|
||||
return get_property_value("margin-bottom"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_left(StringView value)
|
||||
|
|
@ -78,7 +78,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_margin_left(StringView value)
|
|||
|
||||
String CSSPageDescriptors::margin_left() const
|
||||
{
|
||||
return get_property_value("margin-left"_fly_string);
|
||||
return get_property_value("margin-left"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_size(StringView value)
|
||||
|
|
@ -88,7 +88,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_size(StringView value)
|
|||
|
||||
String CSSPageDescriptors::size() const
|
||||
{
|
||||
return get_property_value("size"_fly_string);
|
||||
return get_property_value("size"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_page_orientation(StringView value)
|
||||
|
|
@ -98,7 +98,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_page_orientation(StringView va
|
|||
|
||||
String CSSPageDescriptors::page_orientation() const
|
||||
{
|
||||
return get_property_value("page-orientation"_fly_string);
|
||||
return get_property_value("page-orientation"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_marks(StringView value)
|
||||
|
|
@ -108,7 +108,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_marks(StringView value)
|
|||
|
||||
String CSSPageDescriptors::marks() const
|
||||
{
|
||||
return get_property_value("marks"_fly_string);
|
||||
return get_property_value("marks"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSPageDescriptors::set_bleed(StringView value)
|
||||
|
|
@ -118,7 +118,7 @@ WebIDL::ExceptionOr<void> CSSPageDescriptors::set_bleed(StringView value)
|
|||
|
||||
String CSSPageDescriptors::bleed() const
|
||||
{
|
||||
return get_property_value("bleed"_fly_string);
|
||||
return get_property_value("bleed"_utf16_fly_string);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public:
|
|||
virtual WebIDL::ExceptionOr<void> set_property(FlyString const& property_name, StringView css_text, StringView priority) = 0;
|
||||
virtual WebIDL::ExceptionOr<String> remove_property(FlyString const& property_name) = 0;
|
||||
|
||||
virtual String get_property_value(FlyString const& property_name) const = 0;
|
||||
virtual String get_property_value(Utf16FlyString const& property_name) const = 0;
|
||||
virtual StringView get_property_priority(FlyString const& property_name) const = 0;
|
||||
|
||||
String css_text() const;
|
||||
|
|
|
|||
|
|
@ -362,19 +362,34 @@ static RefPtr<StyleValue const> style_value_for_shadow(ShadowStyleValue::ShadowT
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||
String CSSStyleProperties::get_property_value(FlyString const& property_name) const
|
||||
String CSSStyleProperties::get_property_value(Utf16FlyString const& property_name) const
|
||||
{
|
||||
auto property = PropertyNameAndID::from_name(property_name);
|
||||
if (!property.has_value())
|
||||
if (!property_name.is_ascii())
|
||||
return {};
|
||||
if (auto style_property = get_property_internal(property.value()); style_property.has_value()) {
|
||||
return style_property->value->to_string(
|
||||
is_computed() ? SerializationMode::ResolvedValue
|
||||
: SerializationMode::Normal);
|
||||
|
||||
auto property_name_string = property_name.to_utf16_string();
|
||||
auto property_name_view = property_name_string.ascii_view();
|
||||
|
||||
if (auto property_id = property_id_from_string(property_name_view); property_id.has_value()) {
|
||||
if (*property_id == PropertyID::Custom) {
|
||||
auto custom_property_name = MUST(FlyString::from_utf8(property_name_view));
|
||||
if (auto style_property = custom_property(custom_property_name); style_property.has_value()) {
|
||||
return style_property->value->to_string(
|
||||
is_computed() ? SerializationMode::ResolvedValue
|
||||
: SerializationMode::Normal);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
if (auto style_property = get_property_internal(PropertyNameAndID::from_id(*property_id)); style_property.has_value()) {
|
||||
return style_property->value->to_string(
|
||||
is_computed() ? SerializationMode::ResolvedValue
|
||||
: SerializationMode::Normal);
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertypriority
|
||||
StringView CSSStyleProperties::get_property_priority(FlyString const& property_name) const
|
||||
{
|
||||
|
|
@ -1137,7 +1152,7 @@ WebIDL::ExceptionOr<String> CSSStyleProperties::remove_property_internal(Optiona
|
|||
if (property.has_value()) {
|
||||
// 3. Let value be the return value of invoking getPropertyValue() with property as argument.
|
||||
// FIXME: Add an overload that takes PropertyNameAndID?
|
||||
value = get_property_value(property->name());
|
||||
value = get_property_value(Utf16FlyString::from_utf8(property->name()));
|
||||
|
||||
Function<bool(PropertyNameAndID const&)> remove_declaration = [&](PropertyNameAndID const& property_to_remove) {
|
||||
// 4. Let removed be false.
|
||||
|
|
@ -1186,7 +1201,7 @@ WebIDL::ExceptionOr<String> CSSStyleProperties::remove_property(PropertyID prope
|
|||
String CSSStyleProperties::css_float() const
|
||||
{
|
||||
// The cssFloat attribute, on getting, must return the result of invoking getPropertyValue() with float as argument.
|
||||
return get_property_value("float"_fly_string);
|
||||
return get_property_value("float"_utf16_fly_string);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> CSSStyleProperties::set_css_float(StringView value)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public:
|
|||
virtual WebIDL::ExceptionOr<void> set_property(FlyString const& property_name, StringView css_text, StringView priority) override;
|
||||
virtual WebIDL::ExceptionOr<String> remove_property(FlyString const& property_name) override;
|
||||
|
||||
virtual String get_property_value(FlyString const& property_name) const override;
|
||||
virtual String get_property_value(Utf16FlyString const& property_name) const override;
|
||||
virtual StringView get_property_priority(FlyString const& property_name) const override;
|
||||
|
||||
Vector<StyleProperty> const& properties() const { return m_properties; }
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ WebIDL::ExceptionOr<void> GeneratedCSSStyleProperties::set_{name_acceptable_cpp}
|
|||
|
||||
String GeneratedCSSStyleProperties::{name_acceptable_cpp}() const
|
||||
{{
|
||||
return generated_style_properties_to_css_style_properties().get_property_value("{name}"_fly_string);
|
||||
return generated_style_properties_to_css_style_properties().get_property_value("{name}"_utf16_fly_string);
|
||||
}}
|
||||
""")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue