diff options
13 files changed, 89 insertions, 47 deletions
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 <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/Dump.h> #include <LibWeb/Infra/Strings.h> 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 <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/Layout/Viewport.h> 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 <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/FontCache.h> 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 <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/BrowsingContext.h> #include <LibWeb/Loader/LoadRequest.h> @@ -1020,11 +1021,6 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW return value->resolve(layout_node, percentage_basis); } -ErrorOr<String> ColorStyleValue::to_string() const -{ - return serialize_a_srgb_value(m_color); -} - ErrorOr<String> ContentStyleValue::to_string() const { if (has_alt_text()) @@ -2088,26 +2084,6 @@ ErrorOr<String> StyleValueList::to_string() const return builder.to_string(); } -ValueComparingNonnullRefPtr<ColorStyleValue> 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> GridTemplateAreaStyleValue::create(Vector<Vector<String>> 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<CalcSum> m_expression; }; -class ColorStyleValue : public StyleValueWithDefaultOperators<ColorStyleValue> { -public: - static ValueComparingNonnullRefPtr<ColorStyleValue> create(Color color); - virtual ~ColorStyleValue() override = default; - - Color color() const { return m_color; } - virtual ErrorOr<String> 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<ContentStyleValue> { public: static ValueComparingNonnullRefPtr<ContentStyleValue> create(ValueComparingNonnullRefPtr<StyleValueList> content, ValueComparingRefPtr<StyleValueList> 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 <kling@serenityos.org> + * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "ColorStyleValue.h" +#include <LibWeb/CSS/Serialize.h> + +namespace Web::CSS { + +ValueComparingNonnullRefPtr<ColorStyleValue> 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<String> 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 <kling@serenityos.org> + * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibGfx/Color.h> +#include <LibWeb/CSS/StyleValue.h> + +namespace Web::CSS { + +class ColorStyleValue : public StyleValueWithDefaultOperators<ColorStyleValue> { +public: + static ValueComparingNonnullRefPtr<ColorStyleValue> create(Color color); + virtual ~ColorStyleValue() override = default; + + Color color() const { return m_color; } + virtual ErrorOr<String> 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 <LibWeb/CSS/StyleProperties.h> #include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/HTMLBodyElement.h> #include <LibWeb/HTML/Window.h> 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 <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/CSS/StyleProperties.h> #include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/HTML/HTMLFontElement.h> 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 <LibWeb/Bindings/Intrinsics.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/HTML/HTMLMarqueeElement.h> 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 <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/CSS/Parser/Parser.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/HTML/HTMLTableCellElement.h> #include <LibWeb/HTML/Parser/HTMLParser.h> 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 <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/CSS/Parser/Parser.h> +#include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/DOM/ElementFactory.h> #include <LibWeb/DOM/HTMLCollection.h> #include <LibWeb/HTML/HTMLTableColElement.h> |