From 581d00293c184e47015a5d7e9c4230410567db45 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 14 Aug 2024 16:37:02 +0100 Subject: [PATCH] LibWeb: Rename ColorStyleValue -> CSSColorValue This matches the name in the CSS Typed OM spec. https://drafts.css-houdini.org/css-typed-om-1/#csscolorvalue This is not (yet) the same as the CSSColorValue, but one step at a time. --- .../Libraries/LibWeb/CSS/StyleValues/BUILD.gn | 2 +- Userland/Libraries/LibWeb/CMakeLists.txt | 2 +- .../Libraries/LibWeb/CSS/CSSStyleValue.cpp | 6 +++--- Userland/Libraries/LibWeb/CSS/CSSStyleValue.h | 4 ++-- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 4 ++-- .../CSS/ResolvedCSSStyleDeclaration.cpp | 20 +++++++++---------- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 4 ++-- ...{ColorStyleValue.cpp => CSSColorValue.cpp} | 16 +++++++-------- .../{ColorStyleValue.h => CSSColorValue.h} | 13 ++++++------ Userland/Libraries/LibWeb/Forward.h | 2 +- .../Libraries/LibWeb/HTML/HTMLBodyElement.cpp | 6 +++--- .../Libraries/LibWeb/HTML/HTMLFontElement.cpp | 4 ++-- .../LibWeb/HTML/HTMLMarqueeElement.cpp | 4 ++-- .../Libraries/LibWeb/HTML/HTMLMetaElement.cpp | 2 +- .../LibWeb/HTML/HTMLTableCellElement.cpp | 4 ++-- .../LibWeb/HTML/HTMLTableElement.cpp | 6 +++--- .../LibWeb/HTML/HTMLTableRowElement.cpp | 4 ++-- 17 files changed, 52 insertions(+), 51 deletions(-) rename Userland/Libraries/LibWeb/CSS/StyleValues/{ColorStyleValue.cpp => CSSColorValue.cpp} (52%) rename Userland/Libraries/LibWeb/CSS/StyleValues/{ColorStyleValue.h => CSSColorValue.h} (61%) diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn index 56560c6aa1e..357b217cff9 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn @@ -7,9 +7,9 @@ source_set("StyleValues") { "BackgroundSizeStyleValue.cpp", "BasicShapeStyleValue.cpp", "BorderRadiusStyleValue.cpp", + "CSSColorValue.cpp", "CSSKeywordValue.cpp", "CalculatedStyleValue.cpp", - "ColorStyleValue.cpp", "ConicGradientStyleValue.cpp", "ContentStyleValue.cpp", "DisplayStyleValue.cpp", diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 6ee0426333e..7171fcc95ff 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -108,11 +108,11 @@ set(SOURCES CSS/StyleValues/BasicShapeStyleValue.cpp CSS/StyleValues/BorderRadiusStyleValue.cpp CSS/StyleValues/CalculatedStyleValue.cpp - CSS/StyleValues/ColorStyleValue.cpp CSS/StyleValues/ConicGradientStyleValue.cpp CSS/StyleValues/ContentStyleValue.cpp CSS/StyleValues/CounterDefinitionsStyleValue.cpp CSS/StyleValues/CounterStyleValue.cpp + CSS/StyleValues/CSSColorValue.cpp CSS/StyleValues/CSSKeywordValue.cpp CSS/StyleValues/DisplayStyleValue.cpp CSS/StyleValues/EasingStyleValue.cpp diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp index 5276ab6fc6e..bf72264a46b 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp @@ -16,9 +16,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -106,10 +106,10 @@ CalculatedStyleValue const& CSSStyleValue::as_calculated() const return static_cast(*this); } -ColorStyleValue const& CSSStyleValue::as_color() const +CSSColorValue const& CSSStyleValue::as_color() const { VERIFY(is_color()); - return static_cast(*this); + return static_cast(*this); } ConicGradientStyleValue const& CSSStyleValue::as_conic_gradient() const diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h index 479ff2db64f..0b9e3de9bd5 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h @@ -169,8 +169,8 @@ public: CalculatedStyleValue& as_calculated() { return const_cast(const_cast(*this).as_calculated()); } bool is_color() const { return type() == Type::Color; } - ColorStyleValue const& as_color() const; - ColorStyleValue& as_color() { return const_cast(const_cast(*this).as_color()); } + CSSColorValue const& as_color() const; + CSSColorValue& as_color() { return const_cast(const_cast(*this).as_color()); } bool is_conic_gradient() const { return type() == Type::ConicGradient; } ConicGradientStyleValue const& as_conic_gradient() const; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 4ee9c6f0dde..ef285748332 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -42,8 +42,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -2995,7 +2995,7 @@ Optional Parser::parse_color(TokenStream& tokens) RefPtr Parser::parse_color_value(TokenStream& tokens) { if (auto color = parse_color(tokens); color.has_value()) - return ColorStyleValue::create(color.value()); + return CSSColorValue::create(color.value()); auto transaction = tokens.begin_transaction(); if (auto keyword = parse_keyword_value(tokens); keyword && keyword->has_color()) { diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 01dcffb0040..5471ea8ddb7 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -15,9 +15,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -237,23 +237,23 @@ RefPtr 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 ColorStyleValue::create(layout_node.computed_values().background_color()); + return CSSColorValue::create(layout_node.computed_values().background_color()); case PropertyID::BorderBottomColor: - return ColorStyleValue::create(layout_node.computed_values().border_bottom().color); + return CSSColorValue::create(layout_node.computed_values().border_bottom().color); case PropertyID::BorderLeftColor: - return ColorStyleValue::create(layout_node.computed_values().border_left().color); + return CSSColorValue::create(layout_node.computed_values().border_left().color); case PropertyID::BorderRightColor: - return ColorStyleValue::create(layout_node.computed_values().border_right().color); + return CSSColorValue::create(layout_node.computed_values().border_right().color); case PropertyID::BorderTopColor: - return ColorStyleValue::create(layout_node.computed_values().border_top().color); + return CSSColorValue::create(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 ColorStyleValue::create(layout_node.computed_values().color()); + return CSSColorValue::create(layout_node.computed_values().color()); case PropertyID::OutlineColor: - return ColorStyleValue::create(layout_node.computed_values().outline_color()); + return CSSColorValue::create(layout_node.computed_values().outline_color()); case PropertyID::TextDecorationColor: - return ColorStyleValue::create(layout_node.computed_values().text_decoration_color()); + return CSSColorValue::create(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 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 ColorStyleValue::create(layout_node.computed_values().webkit_text_fill_color()); + return CSSColorValue::create(layout_node.computed_values().webkit_text_fill_color()); case PropertyID::Invalid: return CSSKeywordValue::create(Keyword::Invalid); case PropertyID::Custom: diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 4a479544e75..29bb545934c 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -37,8 +37,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -1432,7 +1432,7 @@ static NonnullRefPtr 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 ColorStyleValue::create(interpolate_color(from.as_color().color(), to.as_color().color(), delta)); + return CSSColorValue::create(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: { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.cpp similarity index 52% rename from Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp rename to Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.cpp index dbeb3f2cace..1187881b19c 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.cpp @@ -1,38 +1,38 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Tobias Christiansen - * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2021-2024, Sam Atkins * Copyright (c) 2022-2023, MacDue * * SPDX-License-Identifier: BSD-2-Clause */ -#include "ColorStyleValue.h" +#include "CSSColorValue.h" #include namespace Web::CSS { -ValueComparingNonnullRefPtr ColorStyleValue::create(Color color) +ValueComparingNonnullRefPtr CSSColorValue::create(Color color) { if (color.value() == 0) { - static auto transparent = adopt_ref(*new (nothrow) ColorStyleValue(color)); + static auto transparent = adopt_ref(*new (nothrow) CSSColorValue(color)); return transparent; } if (color == Color::from_rgb(0x000000)) { - static auto black = adopt_ref(*new (nothrow) ColorStyleValue(color)); + static auto black = adopt_ref(*new (nothrow) CSSColorValue(color)); return black; } if (color == Color::from_rgb(0xffffff)) { - static auto white = adopt_ref(*new (nothrow) ColorStyleValue(color)); + static auto white = adopt_ref(*new (nothrow) CSSColorValue(color)); return white; } - return adopt_ref(*new (nothrow) ColorStyleValue(color)); + return adopt_ref(*new (nothrow) CSSColorValue(color)); } -String ColorStyleValue::to_string() const +String CSSColorValue::to_string() const { return serialize_a_srgb_value(m_color); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h similarity index 61% rename from Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h rename to Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h index d80b3af6257..505b31551fa 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Tobias Christiansen - * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2021-2024, Sam Atkins * Copyright (c) 2022-2023, MacDue * * SPDX-License-Identifier: BSD-2-Clause @@ -14,20 +14,21 @@ namespace Web::CSS { -class ColorStyleValue : public StyleValueWithDefaultOperators { +// https://drafts.css-houdini.org/css-typed-om-1/#csscolorvalue +class CSSColorValue : public StyleValueWithDefaultOperators { public: - static ValueComparingNonnullRefPtr create(Color color); - virtual ~ColorStyleValue() override = default; + static ValueComparingNonnullRefPtr create(Color color); + virtual ~CSSColorValue() override = default; Color color() const { return m_color; } virtual String to_string() const override; virtual bool has_color() const override { return true; } virtual Color to_color(Optional) const override { return m_color; } - bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; } + bool properties_equal(CSSColorValue const& other) const { return m_color == other.m_color; } private: - explicit ColorStyleValue(Color color) + explicit CSSColorValue(Color color) : StyleValueWithDefaultOperators(Type::Color) , m_color(color) { diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index bc83276e464..90c6a2d733b 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -102,6 +102,7 @@ class BackgroundSizeStyleValue; class BasicShapeStyleValue; class BorderRadiusStyleValue; class CSSAnimation; +class CSSColorValue; class CSSConditionRule; class CSSFontFaceRule; class CSSGroupingRule; @@ -120,7 +121,6 @@ class CSSStyleValue; class CSSSupportsRule; class CalculatedStyleValue; class Clip; -class ColorStyleValue; class ConicGradientStyleValue; class ContentStyleValue; class CounterStyleValue; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp index bb8ea8ec6b5..2701eae768c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -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::ColorStyleValue::create(color.value())); + style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(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::ColorStyleValue::create(color.value())); + style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create(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); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp index 5daeb0a2102..11111aef242 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -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::ColorStyleValue::create(color.value())); + style.set_property(CSS::PropertyID::Color, CSS::CSSColorValue::create(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); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp index 0ae41d657fa..14008c83060 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -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::ColorStyleValue::create(color.value())); + style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value())); } }); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp index 181474594ed..e062412c9c8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index 8e1467707c3..a9a72aa30ff 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -9,8 +9,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -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::ColorStyleValue::create(color.value())); + style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value())); return; } if (name == HTML::AttributeNames::valign) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 4f8b6aecbe6..cfda2d77c0e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -9,8 +9,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -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::ColorStyleValue::create(color.value())); + style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(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::ColorStyleValue::create(Color(128, 128, 128))); + style.set_property(color_property, CSS::CSSColorValue::create(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); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp index 1f600cc71e6..ff6aea3617e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp @@ -9,8 +9,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -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::ColorStyleValue::create(color.value())); + style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create(color.value())); return; } else if (name == HTML::AttributeNames::background) { if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())