diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index cec6ceb6d2..fc440d6d5a 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -71,6 +71,7 @@ set(SOURCES CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp CSS/StyleValues/BorderRadiusStyleValue.cpp CSS/StyleValues/BorderStyleValue.cpp + CSS/StyleValues/ColorStyleValue.cpp CSS/Supports.cpp CSS/SyntaxHighlighter/SyntaxHighlighter.cpp CSS/Time.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index c5c0b64109..e5c64e6dbb 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 82275d8583..f0ae4b87ed 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 496e76ccc5..c04837ee15 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index a8e61df653..7dae224edf 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1020,11 +1021,6 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW return value->resolve(layout_node, percentage_basis); } -ErrorOr ColorStyleValue::to_string() const -{ - return serialize_a_srgb_value(m_color); -} - ErrorOr ContentStyleValue::to_string() const { if (has_alt_text()) @@ -2088,26 +2084,6 @@ ErrorOr StyleValueList::to_string() const return builder.to_string(); } -ValueComparingNonnullRefPtr ColorStyleValue::create(Color color) -{ - if (color.value() == 0) { - static auto transparent = adopt_ref(*new ColorStyleValue(color)); - return transparent; - } - - if (color == Color::from_rgb(0x000000)) { - static auto black = adopt_ref(*new ColorStyleValue(color)); - return black; - } - - if (color == Color::from_rgb(0xffffff)) { - static auto white = adopt_ref(*new ColorStyleValue(color)); - return white; - } - - return adopt_ref(*new ColorStyleValue(color)); -} - ValueComparingNonnullRefPtr GridTemplateAreaStyleValue::create(Vector> grid_template_area) { return adopt_ref(*new GridTemplateAreaStyleValue(grid_template_area)); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 3c0709408b..4d862b64c1 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -713,28 +713,6 @@ private: NonnullOwnPtr m_expression; }; -class ColorStyleValue : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create(Color color); - virtual ~ColorStyleValue() override = default; - - Color color() const { return m_color; } - virtual ErrorOr to_string() const override; - virtual bool has_color() const override { return true; } - virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; } - - bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; }; - -private: - explicit ColorStyleValue(Color color) - : StyleValueWithDefaultOperators(Type::Color) - , m_color(color) - { - } - - Color m_color; -}; - class ContentStyleValue final : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr content, ValueComparingRefPtr alt_text) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp new file mode 100644 index 0000000000..180adcc922 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2022-2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "ColorStyleValue.h" +#include + +namespace Web::CSS { + +ValueComparingNonnullRefPtr ColorStyleValue::create(Color color) +{ + if (color.value() == 0) { + static auto transparent = adopt_ref(*new ColorStyleValue(color)); + return transparent; + } + + if (color == Color::from_rgb(0x000000)) { + static auto black = adopt_ref(*new ColorStyleValue(color)); + return black; + } + + if (color == Color::from_rgb(0xffffff)) { + static auto white = adopt_ref(*new ColorStyleValue(color)); + return white; + } + + return adopt_ref(*new ColorStyleValue(color)); +} + +ErrorOr ColorStyleValue::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/ColorStyleValue.h new file mode 100644 index 0000000000..acb8fca621 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2022-2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::CSS { + +class ColorStyleValue : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create(Color color); + virtual ~ColorStyleValue() override = default; + + Color color() const { return m_color; } + virtual ErrorOr to_string() const override; + virtual bool has_color() const override { return true; } + virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; } + + bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; }; + +private: + explicit ColorStyleValue(Color color) + : StyleValueWithDefaultOperators(Type::Color) + , m_color(color) + { + } + + Color m_color; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp index d9ef279904..0a0be578f1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp index ece4239b09..0d606678b5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace Web::HTML { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp index 31f6e8df48..f102be7a6e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp @@ -5,6 +5,7 @@ */ #include +#include #include namespace Web::HTML { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index 64b07ffad0..e62d5bc7d9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 880c7e0701..417fd6f0e8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include