1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibWeb: Use CSS::ValueID for 'text-align' values

Let's start moving away from using raw strings for CSS identifiers.
The idea here is to use IdentifierStyleValue with a CSS::ValueID inside
for all CSS identifier values.
This commit is contained in:
Andreas Kling 2020-12-14 18:38:02 +01:00
parent 08517daa5a
commit 3247ea3581
5 changed files with 32 additions and 11 deletions

View file

@ -350,10 +350,16 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string)
return CSS::ValueID::Bold;
if (string.equals_ignoring_case("bolder"))
return CSS::ValueID::Bolder;
if (string.equals_ignoring_case("center"))
return CSS::ValueID::Center;
if (string.equals_ignoring_case("justify"))
return CSS::ValueID::Justify;
if (string.equals_ignoring_case("large"))
return CSS::ValueID::Large;
if (string.equals_ignoring_case("larger"))
return CSS::ValueID::Larger;
if (string.equals_ignoring_case("left"))
return CSS::ValueID::Left;
if (string.equals_ignoring_case("lighter"))
return CSS::ValueID::Lighter;
if (string.equals_ignoring_case("medium"))
@ -362,6 +368,8 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string)
return CSS::ValueID::Normal;
if (string.equals_ignoring_case("small"))
return CSS::ValueID::Small;
if (string.equals_ignoring_case("right"))
return CSS::ValueID::Right;
if (string.equals_ignoring_case("smaller"))
return CSS::ValueID::Smaller;
if (string.equals_ignoring_case("x-large"))
@ -374,6 +382,8 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string)
return CSS::ValueID::XxSmall;
if (string.equals_ignoring_case("xxx-large"))
return CSS::ValueID::XxxLarge;
if (string.equals_ignoring_case("-libweb-center"))
return CSS::ValueID::VendorSpecificCenter;
if (string.equals_ignoring_case("-libweb-link"))
return CSS::ValueID::VendorSpecificLink;
if (string.starts_with("-libweb-palette-", CaseSensitivity::CaseInsensitive))

View file

@ -261,19 +261,26 @@ bool StyleProperties::operator==(const StyleProperties& other) const
return true;
}
CSS::TextAlign StyleProperties::text_align() const
Optional<CSS::TextAlign> StyleProperties::text_align() const
{
auto string = string_or_fallback(CSS::PropertyID::TextAlign, "left");
if (string == "center")
auto value = property(CSS::PropertyID::TextAlign);
if (!value.has_value() || !value.value()->is_identifier())
return {};
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
case CSS::ValueID::Left:
return CSS::TextAlign::Left;
case CSS::ValueID::Center:
return CSS::TextAlign::Center;
if (string == "right")
case CSS::ValueID::Right:
return CSS::TextAlign::Right;
if (string == "justify")
case CSS::ValueID::Justify:
return CSS::TextAlign::Justify;
if (string == "-libweb-center")
case CSS::ValueID::VendorSpecificCenter:
return CSS::TextAlign::VendorSpecificCenter;
// Otherwise, just assume "left"..
return CSS::TextAlign::Left;
default:
return {};
}
}
Optional<CSS::WhiteSpace> StyleProperties::white_space() const

View file

@ -60,7 +60,7 @@ public:
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id) const;
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
Color color_or_fallback(CSS::PropertyID, const DOM::Document&, Color fallback) const;
CSS::TextAlign text_align() const;
Optional<CSS::TextAlign> text_align() const;
CSS::Display display() const;
Optional<CSS::Float> float_() const;
Optional<CSS::Clear> clear() const;