LibWeb: Rename CSSColorValue::create() to create_from_color()

Soon, CSSColorValue will be an abstract class, and we'll instead create
a CSSRGB, CSSHSL, or other specific color type from the Typed-OM spec.
However, it's still useful to have an easy "just give me a style value
for this color" method. So change the name to distinguish this from the
usual StyleValue::create() methods.
This commit is contained in:
Sam Atkins 2024-08-15 11:15:44 +01:00 committed by Sam Atkins
parent 4e48afd9a7
commit 37ea4e3b5f
Notes: github-actions[bot] 2024-08-21 09:53:06 +00:00
11 changed files with 24 additions and 24 deletions

View file

@ -2995,7 +2995,7 @@ Optional<Color> Parser::parse_color(TokenStream<ComponentValue>& tokens)
RefPtr<CSSStyleValue> Parser::parse_color_value(TokenStream<ComponentValue>& tokens)
{
if (auto color = parse_color(tokens); color.has_value())
return CSSColorValue::create(color.value());
return CSSColorValue::create_from_color(color.value());
auto transaction = tokens.begin_transaction();
if (auto keyword = parse_keyword_value(tokens); keyword && keyword->has_color()) {

View file

@ -175,7 +175,7 @@ static RefPtr<CSSStyleValue const> style_value_for_shadow(Vector<ShadowData> con
auto make_shadow_style_value = [](ShadowData const& shadow) {
return ShadowStyleValue::create(
CSSColorValue::create(shadow.color),
CSSColorValue::create_from_color(shadow.color),
style_value_for_length_percentage(shadow.offset_x),
style_value_for_length_percentage(shadow.offset_y),
style_value_for_length_percentage(shadow.blur_radius),
@ -237,23 +237,23 @@ RefPtr<CSSStyleValue const> ResolvedCSSStyleDeclaration::style_value_for_propert
// -> A resolved value special case property like color defined in another specification
// The resolved value is the used value.
case PropertyID::BackgroundColor:
return CSSColorValue::create(layout_node.computed_values().background_color());
return CSSColorValue::create_from_color(layout_node.computed_values().background_color());
case PropertyID::BorderBottomColor:
return CSSColorValue::create(layout_node.computed_values().border_bottom().color);
return CSSColorValue::create_from_color(layout_node.computed_values().border_bottom().color);
case PropertyID::BorderLeftColor:
return CSSColorValue::create(layout_node.computed_values().border_left().color);
return CSSColorValue::create_from_color(layout_node.computed_values().border_left().color);
case PropertyID::BorderRightColor:
return CSSColorValue::create(layout_node.computed_values().border_right().color);
return CSSColorValue::create_from_color(layout_node.computed_values().border_right().color);
case PropertyID::BorderTopColor:
return CSSColorValue::create(layout_node.computed_values().border_top().color);
return CSSColorValue::create_from_color(layout_node.computed_values().border_top().color);
case PropertyID::BoxShadow:
return style_value_for_shadow(layout_node.computed_values().box_shadow());
case PropertyID::Color:
return CSSColorValue::create(layout_node.computed_values().color());
return CSSColorValue::create_from_color(layout_node.computed_values().color());
case PropertyID::OutlineColor:
return CSSColorValue::create(layout_node.computed_values().outline_color());
return CSSColorValue::create_from_color(layout_node.computed_values().outline_color());
case PropertyID::TextDecorationColor:
return CSSColorValue::create(layout_node.computed_values().text_decoration_color());
return CSSColorValue::create_from_color(layout_node.computed_values().text_decoration_color());
// NOTE: text-shadow isn't listed, but is computed the same as box-shadow.
case PropertyID::TextShadow:
return style_value_for_shadow(layout_node.computed_values().text_shadow());
@ -513,7 +513,7 @@ RefPtr<CSSStyleValue const> ResolvedCSSStyleDeclaration::style_value_for_propert
return style_value_for_sided_shorthand(top.release_nonnull(), right.release_nonnull(), bottom.release_nonnull(), left.release_nonnull());
}
case PropertyID::WebkitTextFillColor:
return CSSColorValue::create(layout_node.computed_values().webkit_text_fill_color());
return CSSColorValue::create_from_color(layout_node.computed_values().webkit_text_fill_color());
case PropertyID::Invalid:
return CSSKeywordValue::create(Keyword::Invalid);
case PropertyID::Custom:

View file

@ -1316,7 +1316,7 @@ static NonnullRefPtr<CSSStyleValue const> interpolate_box_shadow(DOM::Element& e
values.ensure_capacity(other.size());
for (size_t i = values.size(); i < other.size(); i++) {
values.unchecked_append(ShadowStyleValue::create(
CSSColorValue::create(Color::Transparent),
CSSColorValue::create_from_color(Color::Transparent),
LengthStyleValue::create(Length::make_px(0)),
LengthStyleValue::create(Length::make_px(0)),
LengthStyleValue::create(Length::make_px(0)),
@ -1339,7 +1339,7 @@ static NonnullRefPtr<CSSStyleValue const> interpolate_box_shadow(DOM::Element& e
auto const& from_shadow = from_shadows[i]->as_shadow();
auto const& to_shadow = to_shadows[i]->as_shadow();
auto result_shadow = ShadowStyleValue::create(
CSSColorValue::create(interpolate_color(from_shadow.color()->to_color({}), to_shadow.color()->to_color({}), delta)),
CSSColorValue::create_from_color(interpolate_color(from_shadow.color()->to_color({}), to_shadow.color()->to_color({}), delta)),
interpolate_value(element, from_shadow.offset_x(), to_shadow.offset_x(), delta),
interpolate_value(element, from_shadow.offset_y(), to_shadow.offset_y(), delta),
interpolate_value(element, from_shadow.blur_radius(), to_shadow.blur_radius(), delta),
@ -1432,7 +1432,7 @@ static NonnullRefPtr<CSSStyleValue const> interpolate_value(DOM::Element& elemen
case CSSStyleValue::Type::Angle:
return AngleStyleValue::create(Angle::make_degrees(interpolate_raw(from.as_angle().angle().to_degrees(), to.as_angle().angle().to_degrees(), delta)));
case CSSStyleValue::Type::Color:
return CSSColorValue::create(interpolate_color(from.as_color().color(), to.as_color().color(), delta));
return CSSColorValue::create_from_color(interpolate_color(from.as_color().color(), to.as_color().color(), delta));
case CSSStyleValue::Type::Integer:
return IntegerStyleValue::create(interpolate_raw(from.as_integer().integer(), to.as_integer().integer(), delta));
case CSSStyleValue::Type::Length: {

View file

@ -12,7 +12,7 @@
namespace Web::CSS {
ValueComparingNonnullRefPtr<CSSColorValue> CSSColorValue::create(Color color)
ValueComparingNonnullRefPtr<CSSColorValue> CSSColorValue::create_from_color(Color color)
{
if (color.value() == 0) {
static auto transparent = adopt_ref(*new (nothrow) CSSColorValue(color));

View file

@ -17,7 +17,7 @@ namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#csscolorvalue
class CSSColorValue : public StyleValueWithDefaultOperators<CSSColorValue> {
public:
static ValueComparingNonnullRefPtr<CSSColorValue> create(Color color);
static ValueComparingNonnullRefPtr<CSSColorValue> create_from_color(Color color);
virtual ~CSSColorValue() override = default;
Color color() const { return m_color; }

View file

@ -46,12 +46,12 @@ void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) co
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
} else if (name.equals_ignoring_ascii_case("text"sv)) {
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-2
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create(color.value()));
style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(color.value()));
} else if (name.equals_ignoring_ascii_case("background"sv)) {
VERIFY(m_background_style_value);
style.set_property(CSS::PropertyID::BackgroundImage, *m_background_style_value);

View file

@ -119,7 +119,7 @@ void HTMLFontElement::apply_presentational_hints(CSS::StyleProperties& style) co
// https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create(color.value()));
style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(color.value()));
} else if (name.equals_ignoring_ascii_case("size"sv)) {
// When a font element has a size attribute, the user agent is expected to use the following steps, known as the rules for parsing a legacy font size, to treat the attribute as a presentational hint setting the element's 'font-size' property:
auto font_size_or_empty = parse_legacy_font_size(value);

View file

@ -38,7 +38,7 @@ void HTMLMarqueeElement::apply_presentational_hints(CSS::StyleProperties& style)
// https://html.spec.whatwg.org/multipage/rendering.html#the-marquee-element-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
}
});
}

View file

@ -44,7 +44,7 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
return;
}
if (name == HTML::AttributeNames::valign) {

View file

@ -76,7 +76,7 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
return;
}
if (name == HTML::AttributeNames::cellspacing) {
@ -92,7 +92,7 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
auto legacy_line_style = CSS::CSSKeywordValue::create(CSS::Keyword::Outset);
style.set_property(style_property, legacy_line_style);
style.set_property(width_property, CSS::LengthStyleValue::create(CSS::Length::make_px(border)));
style.set_property(color_property, CSS::CSSColorValue::create(Color(128, 128, 128)));
style.set_property(color_property, CSS::CSSColorValue::create_from_color(Color(128, 128, 128)));
};
apply_border_style(CSS::PropertyID::BorderLeftStyle, CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor);
apply_border_style(CSS::PropertyID::BorderTopStyle, CSS::PropertyID::BorderTopWidth, CSS::PropertyID::BorderTopColor);

View file

@ -47,7 +47,7 @@ void HTMLTableRowElement::apply_presentational_hints(CSS::StyleProperties& style
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
return;
} else if (name == HTML::AttributeNames::background) {
if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())