LibWeb: Parse and propagate extended text-indent property values

CSS Text 3 gives `text-indent` a couple of optional keywords to control
which lines are affected. This commit parses them, but doesn't yet do
anything with them.
This commit is contained in:
Sam Atkins 2025-11-18 10:53:25 +00:00 committed by Jelle Raaijmakers
parent eea1d4e1d2
commit c4b9e7eadf
Notes: github-actions[bot] 2025-11-20 15:03:53 +00:00
16 changed files with 199 additions and 9 deletions

View file

@ -57,6 +57,7 @@
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/TextIndentStyleValue.h>
#include <LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h>
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
@ -721,6 +722,8 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue const>> Parser::parse_css_value(Pr
return parse_all_as(tokens, [this](auto& tokens) { return parse_text_decoration_value(tokens); });
case PropertyID::TextDecorationLine:
return parse_all_as(tokens, [this](auto& tokens) { return parse_text_decoration_line_value(tokens); });
case PropertyID::TextIndent:
return parse_all_as(tokens, [this](auto& tokens) { return parse_text_indent_value(tokens); });
case PropertyID::TextShadow:
return parse_all_as(tokens, [this](auto& tokens) { return parse_shadow_value(tokens, ShadowStyleValue::ShadowType::Text); });
case PropertyID::TextUnderlinePosition:
@ -4731,6 +4734,51 @@ RefPtr<StyleValue const> Parser::parse_text_decoration_line_value(TokenStream<Co
return StyleValueList::create(move(style_values), StyleValueList::Separator::Space);
}
// https://drafts.csswg.org/css-text-3/#text-indent-property
RefPtr<StyleValue const> Parser::parse_text_indent_value(TokenStream<ComponentValue>& tokens)
{
// [ <length-percentage> ] && hanging? && each-line?
auto transaction = tokens.begin_transaction();
RefPtr<StyleValue const> length_percentage;
bool has_hanging = false;
bool has_each_line = false;
tokens.discard_whitespace();
while (tokens.has_next_token()) {
if (!length_percentage) {
if (auto parsed = parse_length_percentage_value(tokens)) {
length_percentage = parsed.release_nonnull();
tokens.discard_whitespace();
continue;
}
}
if (auto keyword = parse_keyword_value(tokens)) {
if (!has_hanging && keyword->to_keyword() == Keyword::Hanging) {
has_hanging = true;
continue;
}
if (!has_each_line && keyword->to_keyword() == Keyword::EachLine) {
has_each_line = true;
continue;
}
return nullptr;
}
return nullptr;
}
if (!length_percentage)
return nullptr;
transaction.commit();
return TextIndentStyleValue::create(length_percentage.release_nonnull(),
has_hanging ? TextIndentStyleValue::Hanging::Yes : TextIndentStyleValue::Hanging::No,
has_each_line ? TextIndentStyleValue::EachLine::Yes : TextIndentStyleValue::EachLine::No);
}
// https://drafts.csswg.org/css-text-decor-4/#text-underline-position-property
RefPtr<StyleValue const> Parser::parse_text_underline_position_value(TokenStream<ComponentValue>& tokens)
{