1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:27:34 +00:00

LibWeb: Use IdentifierStyleValue for CSS 'text-decoration-line'

Also 'text-decoration' is actually a shorthand, so treat it that way.
This commit is contained in:
Andreas Kling 2020-12-15 13:36:27 +01:00
parent dd9a77099f
commit 4d7ce81835
9 changed files with 96 additions and 3 deletions

View file

@ -446,6 +446,14 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string)
return CSS::ValueID::TableHeaderGroup;
if (string.equals_ignoring_case("table-footer-group"))
return CSS::ValueID::TableFooterGroup;
if (string.equals_ignoring_case("underline"))
return CSS::ValueID::Underline;
if (string.equals_ignoring_case("overline"))
return CSS::ValueID::Overline;
if (string.equals_ignoring_case("line-through"))
return CSS::ValueID::LineThrough;
if (string.equals_ignoring_case("blink"))
return CSS::ValueID::Blink;
if (string.starts_with("-libweb-palette-", CaseSensitivity::CaseInsensitive))
return value_id_for_palette_string(string.substring_view(16, string.length() - 16));
return {};

View file

@ -304,6 +304,28 @@
"initial": "left"
},
"text-decoration": {
"inherited": false,
"initial": "none",
"longhands": [
"text-decoration-color",
"text-decoration-line",
"text-decoration-style",
"text-decoration-thickness"
]
},
"text-decoration-color": {
"inherited": false,
"initial": "none"
},
"text-decoration-line": {
"inherited": false,
"initial": "none"
},
"text-decoration-style": {
"inherited": false,
"initial": "none"
},
"text-decoration-thickness": {
"inherited": false,
"initial": "none"
},

View file

@ -409,4 +409,25 @@ CSS::Display StyleProperties::display() const
}
}
Optional<CSS::TextDecorationLine> StyleProperties::text_decoration_line() const
{
auto value = property(CSS::PropertyID::TextDecorationLine);
if (!value.has_value() || !value.value()->is_identifier())
return {};
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
case CSS::ValueID::None:
return CSS::TextDecorationLine::None;
case CSS::ValueID::Underline:
return CSS::TextDecorationLine::Underline;
case CSS::ValueID::Overline:
return CSS::TextDecorationLine::Overline;
case CSS::ValueID::LineThrough:
return CSS::TextDecorationLine::LineThrough;
case CSS::ValueID::Blink:
return CSS::TextDecorationLine::Blink;
default:
return {};
}
}
}

View file

@ -66,6 +66,7 @@ public:
Optional<CSS::Clear> clear() const;
Optional<CSS::WhiteSpace> white_space() const;
Optional<CSS::LineStyle> line_style(CSS::PropertyID) const;
Optional<CSS::TextDecorationLine> text_decoration_line() const;
const Gfx::Font& font() const
{

View file

@ -229,6 +229,20 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
{
CSS::ParsingContext context(document);
if (property_id == CSS::PropertyID::TextDecoration) {
switch (value.to_identifier()) {
case CSS::ValueID::None:
case CSS::ValueID::Underline:
case CSS::ValueID::Overline:
case CSS::ValueID::LineThrough:
case CSS::ValueID::Blink:
set_property_expanding_shorthands(style, CSS::PropertyID::TextDecorationLine, value, document);
default:
break;
}
return;
}
if (property_id == CSS::PropertyID::Border) {
set_property_expanding_shorthands(style, CSS::PropertyID::BorderTop, value, document);
set_property_expanding_shorthands(style, CSS::PropertyID::BorderRight, value, document);

View file

@ -147,6 +147,10 @@ enum class ValueID {
TableHeaderGroup,
TableRowGroup,
TableFooterGroup,
Underline,
Overline,
LineThrough,
Blink,
};
enum class Position {
@ -165,6 +169,14 @@ enum class TextAlign {
VendorSpecificCenter,
};
enum class TextDecorationLine {
None,
Underline,
Overline,
LineThrough,
Blink,
};
enum class Display {
None,
Block,
@ -244,6 +256,8 @@ public:
virtual Length to_length() const { return Length::make_auto(); }
virtual Color to_color(const DOM::Document&) const { return {}; }
CSS::ValueID to_identifier() const;
virtual bool is_auto() const { return false; }
bool operator==(const StyleValue& other) const { return equals(other); }
@ -410,4 +424,11 @@ private:
RefPtr<Gfx::Bitmap> m_bitmap;
};
inline CSS::ValueID StyleValue::to_identifier() const
{
if (is_identifier())
return static_cast<const IdentifierStyleValue&>(*this).id();
return CSS::ValueID::Invalid;
}
}