LibWeb/Editing: Allow text-decoration-foo to be a CSSKeywordValue

This commit is contained in:
Sam Atkins 2025-02-28 14:10:34 +00:00
commit 7668f91b60
Notes: github-actions[bot] 2025-02-28 16:35:10 +00:00
2 changed files with 12 additions and 14 deletions

View file

@ -1234,8 +1234,7 @@ Optional<String> effective_command_value(GC::Ptr<DOM::Node> node, FlyString cons
auto inclusive_ancestor = node; auto inclusive_ancestor = node;
do { do {
auto text_decoration_line = resolved_value(*node, CSS::PropertyID::TextDecorationLine); auto text_decoration_line = resolved_value(*node, CSS::PropertyID::TextDecorationLine);
if (text_decoration_line.has_value() && text_decoration_line.value()->is_value_list() if (text_decoration_line.has_value() && value_contains_keyword(text_decoration_line.value(), CSS::Keyword::LineThrough))
&& value_list_contains_keyword(text_decoration_line.value()->as_value_list(), CSS::Keyword::LineThrough))
return "line-through"_string; return "line-through"_string;
inclusive_ancestor = inclusive_ancestor->parent(); inclusive_ancestor = inclusive_ancestor->parent();
} while (inclusive_ancestor); } while (inclusive_ancestor);
@ -1249,8 +1248,7 @@ Optional<String> effective_command_value(GC::Ptr<DOM::Node> node, FlyString cons
auto inclusive_ancestor = node; auto inclusive_ancestor = node;
do { do {
auto text_decoration_line = resolved_value(*node, CSS::PropertyID::TextDecorationLine); auto text_decoration_line = resolved_value(*node, CSS::PropertyID::TextDecorationLine);
if (text_decoration_line.has_value() && text_decoration_line.value()->is_value_list() if (text_decoration_line.has_value() && value_contains_keyword(text_decoration_line.value(), CSS::Keyword::Underline))
&& value_list_contains_keyword(text_decoration_line.value()->as_value_list(), CSS::Keyword::Underline))
return "underline"_string; return "underline"_string;
inclusive_ancestor = inclusive_ancestor->parent(); inclusive_ancestor = inclusive_ancestor->parent();
} while (inclusive_ancestor); } while (inclusive_ancestor);
@ -3892,8 +3890,7 @@ Optional<String> specified_command_value(GC::Ref<DOM::Element> element, FlyStrin
if (text_decoration_style.has_value()) { if (text_decoration_style.has_value()) {
// 1. If element's style attribute sets "text-decoration" to a value containing "line-through", return // 1. If element's style attribute sets "text-decoration" to a value containing "line-through", return
// "line-through". // "line-through".
if (text_decoration_style.value()->is_value_list() if (value_contains_keyword(text_decoration_style.value(), CSS::Keyword::LineThrough))
&& value_list_contains_keyword(text_decoration_style.value()->as_value_list(), CSS::Keyword::LineThrough))
return "line-through"_string; return "line-through"_string;
// 2. Return null. // 2. Return null.
@ -3910,8 +3907,7 @@ Optional<String> specified_command_value(GC::Ref<DOM::Element> element, FlyStrin
auto text_decoration_style = property_in_style_attribute(element, CSS::PropertyID::TextDecoration); auto text_decoration_style = property_in_style_attribute(element, CSS::PropertyID::TextDecoration);
if (text_decoration_style.has_value()) { if (text_decoration_style.has_value()) {
// 1. If element's style attribute sets "text-decoration" to a value containing "underline", return "underline". // 1. If element's style attribute sets "text-decoration" to a value containing "underline", return "underline".
if (text_decoration_style.value()->is_value_list() if (value_contains_keyword(text_decoration_style.value(), CSS::Keyword::Underline))
&& value_list_contains_keyword(text_decoration_style.value()->as_value_list(), CSS::Keyword::Underline))
return "underline"_string; return "underline"_string;
// 2. Return null. // 2. Return null.
@ -4776,13 +4772,15 @@ void take_the_action_for_command(DOM::Document& document, FlyString const& comma
command_definition->action(document, value); command_definition->action(document, value);
} }
bool value_list_contains_keyword(CSS::StyleValueList const& value_list, CSS::Keyword keyword) bool value_contains_keyword(CSS::CSSStyleValue const& value, CSS::Keyword keyword)
{ {
for (auto& css_style_value : value_list.values()) { if (value.is_value_list()) {
if (css_style_value->is_keyword() && css_style_value->as_keyword().keyword() == keyword) for (auto& css_style_value : value.as_value_list().values()) {
return true; if (css_style_value->is_keyword() && css_style_value->as_keyword().keyword() == keyword)
return true;
}
} }
return false; return value.to_keyword() == keyword;
} }
} }

View file

@ -138,6 +138,6 @@ Optional<CSS::Display> resolved_display(GC::Ref<DOM::Node>);
Optional<CSS::Keyword> resolved_keyword(GC::Ref<DOM::Node>, CSS::PropertyID); Optional<CSS::Keyword> resolved_keyword(GC::Ref<DOM::Node>, CSS::PropertyID);
Optional<NonnullRefPtr<CSS::CSSStyleValue const>> resolved_value(GC::Ref<DOM::Node>, CSS::PropertyID); Optional<NonnullRefPtr<CSS::CSSStyleValue const>> resolved_value(GC::Ref<DOM::Node>, CSS::PropertyID);
void take_the_action_for_command(DOM::Document&, FlyString const&, String const&); void take_the_action_for_command(DOM::Document&, FlyString const&, String const&);
bool value_list_contains_keyword(CSS::StyleValueList const&, CSS::Keyword); bool value_contains_keyword(CSS::CSSStyleValue const&, CSS::Keyword);
} }