mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +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:
parent
08517daa5a
commit
3247ea3581
5 changed files with 32 additions and 11 deletions
|
@ -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))
|
||||
|
|
|
@ -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")
|
||||
return CSS::TextAlign::Center;
|
||||
if (string == "right")
|
||||
return CSS::TextAlign::Right;
|
||||
if (string == "justify")
|
||||
return CSS::TextAlign::Justify;
|
||||
if (string == "-libweb-center")
|
||||
return CSS::TextAlign::VendorSpecificCenter;
|
||||
// Otherwise, just assume "left"..
|
||||
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;
|
||||
case CSS::ValueID::Right:
|
||||
return CSS::TextAlign::Right;
|
||||
case CSS::ValueID::Justify:
|
||||
return CSS::TextAlign::Justify;
|
||||
case CSS::ValueID::VendorSpecificCenter:
|
||||
return CSS::TextAlign::VendorSpecificCenter;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Optional<CSS::WhiteSpace> StyleProperties::white_space() const
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
static CSS::Float float_() { return CSS::Float::None; }
|
||||
static CSS::Clear clear() { return CSS::Clear::None; }
|
||||
static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
|
||||
static CSS::TextAlign text_align() { return CSS::TextAlign::Left; }
|
||||
};
|
||||
|
||||
struct BorderData {
|
||||
|
@ -74,7 +75,7 @@ protected:
|
|||
CSS::Float m_float { InitialValues::float_() };
|
||||
CSS::Clear m_clear { InitialValues::clear() };
|
||||
Optional<int> m_z_index;
|
||||
CSS::TextAlign m_text_align;
|
||||
CSS::TextAlign m_text_align { InitialValues::text_align() };
|
||||
CSS::Position m_position;
|
||||
CSS::WhiteSpace m_white_space { InitialValues::white_space() };
|
||||
CSS::Length m_width;
|
||||
|
|
|
@ -220,7 +220,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
|||
auto& style = static_cast<MutableLayoutStyle&>(m_style);
|
||||
|
||||
style.set_position(specified_style.position());
|
||||
style.set_text_align(specified_style.text_align());
|
||||
|
||||
auto text_align = specified_style.text_align();
|
||||
if (text_align.has_value())
|
||||
style.set_text_align(text_align.value());
|
||||
|
||||
auto white_space = specified_style.white_space();
|
||||
if (white_space.has_value())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue