mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
LibWeb: Make property_id_from_string()
return Optional
This commit is contained in:
parent
03613dc14d
commit
465ecf37c2
5 changed files with 29 additions and 29 deletions
|
@ -109,8 +109,8 @@ enum class PropertyID {
|
|||
generator.append(R"~~~(
|
||||
};
|
||||
|
||||
PropertyID property_id_from_camel_case_string(StringView);
|
||||
PropertyID property_id_from_string(StringView);
|
||||
Optional<PropertyID> property_id_from_camel_case_string(StringView);
|
||||
Optional<PropertyID> property_id_from_string(StringView);
|
||||
StringView string_from_property_id(PropertyID);
|
||||
bool is_inherited_property(PropertyID);
|
||||
ErrorOr<NonnullRefPtr<StyleValue>> property_initial_value(JS::Realm&, PropertyID);
|
||||
|
@ -186,7 +186,7 @@ ErrorOr<void> generate_implementation_file(JsonObject& properties, Core::File& f
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
PropertyID property_id_from_camel_case_string(StringView string)
|
||||
Optional<PropertyID> property_id_from_camel_case_string(StringView string)
|
||||
{
|
||||
)~~~");
|
||||
|
||||
|
@ -204,10 +204,10 @@ PropertyID property_id_from_camel_case_string(StringView string)
|
|||
});
|
||||
|
||||
generator.append(R"~~~(
|
||||
return PropertyID::Invalid;
|
||||
return {};
|
||||
}
|
||||
|
||||
PropertyID property_id_from_string(StringView string)
|
||||
Optional<PropertyID> property_id_from_string(StringView string)
|
||||
{
|
||||
)~~~");
|
||||
|
||||
|
@ -224,7 +224,7 @@ PropertyID property_id_from_string(StringView string)
|
|||
});
|
||||
|
||||
generator.append(R"~~~(
|
||||
return PropertyID::Invalid;
|
||||
return {};
|
||||
}
|
||||
|
||||
StringView string_from_property_id(PropertyID property_id) {
|
||||
|
|
|
@ -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 property’s 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1132,10 +1132,10 @@ Messages::WebDriverClient::GetElementCssValueResponse WebDriverConnection::get_e
|
|||
// -> current browsing context’s active document’s type is not "xml"
|
||||
if (!m_page_client.page().top_level_browsing_context().active_document()->is_xml_document()) {
|
||||
// computed value of parameter property name from element’s style declarations. property name is obtained from url variables.
|
||||
auto property = Web::CSS::property_id_from_string(name);
|
||||
|
||||
if (auto property = Web::CSS::property_id_from_string(name); property.has_value()) {
|
||||
if (auto* computed_values = element->computed_css_values())
|
||||
computed_value = computed_values->property(property)->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
|
||||
computed_value = computed_values->property(property.value())->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
|
||||
}
|
||||
}
|
||||
// -> Otherwise
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue