1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:47:44 +00:00

LibWeb: Make property_id_from_string() return Optional

This commit is contained in:
Sam Atkins 2023-05-10 13:01:30 +01:00 committed by Andreas Kling
parent 03613dc14d
commit 465ecf37c2
5 changed files with 29 additions and 29 deletions

View file

@ -27,8 +27,8 @@ bool supports(JS::VM& vm, StringView property, StringView value)
// 1. If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
// and value successfully parses according to that propertys grammar, return true.
if (auto property_id = property_id_from_string(property); property_id != PropertyID::Invalid) {
if (parse_css_value(Parser::ParsingContext { realm }, value, property_id).release_value_but_fixme_should_propagate_errors())
if (auto property_id = property_id_from_string(property); property_id.has_value()) {
if (parse_css_value(Parser::ParsingContext { realm }, value, property_id.value()).release_value_but_fixme_should_propagate_errors())
return true;
}

View file

@ -206,9 +206,9 @@ bool PropertyOwningCSSStyleDeclaration::set_a_css_declaration(PropertyID propert
DeprecatedString CSSStyleDeclaration::get_property_value(StringView property_name) const
{
auto property_id = property_id_from_string(property_name);
if (property_id == CSS::PropertyID::Invalid)
if (!property_id.has_value())
return {};
auto maybe_property = property(property_id);
auto maybe_property = property(property_id.value());
if (!maybe_property.has_value())
return {};
return maybe_property->value->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
@ -218,9 +218,9 @@ DeprecatedString CSSStyleDeclaration::get_property_value(StringView property_nam
DeprecatedString CSSStyleDeclaration::get_property_priority(StringView property_name) const
{
auto property_id = property_id_from_string(property_name);
if (property_id == CSS::PropertyID::Invalid)
if (!property_id.has_value())
return {};
auto maybe_property = property(property_id);
auto maybe_property = property(property_id.value());
if (!maybe_property.has_value())
return {};
return maybe_property->important == Important::Yes ? "important" : "";
@ -229,17 +229,17 @@ DeprecatedString CSSStyleDeclaration::get_property_priority(StringView property_
WebIDL::ExceptionOr<void> CSSStyleDeclaration::set_property(StringView property_name, StringView css_text, StringView priority)
{
auto property_id = property_id_from_string(property_name);
if (property_id == CSS::PropertyID::Invalid)
if (!property_id.has_value())
return {};
return set_property(property_id, css_text, priority);
return set_property(property_id.value(), css_text, priority);
}
WebIDL::ExceptionOr<DeprecatedString> CSSStyleDeclaration::remove_property(StringView property_name)
{
auto property_id = property_id_from_string(property_name);
if (property_id == CSS::PropertyID::Invalid)
if (!property_id.has_value())
return DeprecatedString::empty();
return remove_property(property_id);
return remove_property(property_id.value());
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
@ -326,11 +326,11 @@ static CSS::PropertyID property_id_from_name(StringView name)
if (name == "cssFloat"sv)
return CSS::PropertyID::Float;
if (auto property_id = CSS::property_id_from_camel_case_string(name); property_id != CSS::PropertyID::Invalid)
return property_id;
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 != CSS::PropertyID::Invalid)
return property_id;
if (auto property_id = CSS::property_id_from_string(name); property_id.has_value())
return property_id.value();
return CSS::PropertyID::Invalid;
}

View file

@ -3235,7 +3235,7 @@ Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& dec
auto property_name = declaration.name();
auto property_id = property_id_from_string(property_name);
if (property_id == PropertyID::Invalid) {
if (!property_id.has_value()) {
if (property_name.starts_with("--"sv)) {
property_id = PropertyID::Custom;
} else if (has_ignored_vendor_prefix(property_name)) {
@ -3247,7 +3247,7 @@ Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& dec
}
auto value_token_stream = TokenStream(declaration.values());
auto value = parse_css_value(property_id, value_token_stream);
auto value = parse_css_value(property_id.value(), value_token_stream);
if (value.is_error()) {
if (value.error() == ParseError::SyntaxError) {
dbgln_if(CSS_PARSER_DEBUG, "Unable to parse value for CSS property '{}'.", property_name);
@ -3258,10 +3258,10 @@ Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& dec
return {};
}
if (property_id == PropertyID::Custom)
return StyleProperty { declaration.importance(), property_id, value.release_value(), declaration.name() };
if (property_id.value() == PropertyID::Custom)
return StyleProperty { declaration.importance(), property_id.value(), value.release_value(), declaration.name() };
return StyleProperty { declaration.importance(), property_id, value.release_value(), {} };
return StyleProperty { declaration.importance(), property_id.value(), value.release_value(), {} };
}
ErrorOr<RefPtr<StyleValue>> Parser::parse_builtin_value(ComponentValue const& component_value)