1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:08:12 +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

@ -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