From cd06b1341b26fcff4ac67fb706a9136fdbcb7f63 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 24 Mar 2023 17:59:33 +0000 Subject: LibWeb: Split TransformationStyleValue out of StyleValue.{h,cpp} --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 1 + .../LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 1 + Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 1 + Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 21 +--------- Userland/Libraries/LibWeb/CSS/StyleValue.h | 29 -------------- .../CSS/StyleValues/TransformationStyleValue.cpp | 35 ++++++++++++++++ .../CSS/StyleValues/TransformationStyleValue.h | 46 ++++++++++++++++++++++ 7 files changed, 85 insertions(+), 49 deletions(-) create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h (limited to 'Userland/Libraries/LibWeb/CSS') diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 466178e169..ffb64202cb 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -65,6 +65,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 086cb711b4..d58cd832ce 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 6245117c8f..6cece5f3f6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -17,6 +17,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 82017b1ce4..bc42278698 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -1149,26 +1150,6 @@ ErrorOr RectStyleValue::to_string() const return String::formatted("rect({} {} {} {})", m_rect.top_edge, m_rect.right_edge, m_rect.bottom_edge, m_rect.left_edge); } -ErrorOr TransformationStyleValue::to_string() const -{ - StringBuilder builder; - TRY(builder.try_append(CSS::to_string(m_properties.transform_function))); - TRY(builder.try_append('(')); - for (size_t i = 0; i < m_properties.values.size(); ++i) { - TRY(builder.try_append(TRY(m_properties.values[i]->to_string()))); - if (i != m_properties.values.size() - 1) - TRY(builder.try_append(", "sv)); - } - TRY(builder.try_append(')')); - - return builder.to_string(); -} - -bool TransformationStyleValue::Properties::operator==(Properties const& other) const -{ - return transform_function == other.transform_function && values.span() == other.values.span(); -} - ErrorOr UnresolvedStyleValue::to_string() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index eab2ce6fe0..14221a67b0 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -646,35 +646,6 @@ private: Time m_time; }; -class TransformationStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create(CSS::TransformFunction transform_function, StyleValueVector&& values) - { - return adopt_ref(*new TransformationStyleValue(transform_function, move(values))); - } - virtual ~TransformationStyleValue() override = default; - - CSS::TransformFunction transform_function() const { return m_properties.transform_function; } - StyleValueVector values() const { return m_properties.values; } - - virtual ErrorOr to_string() const override; - - bool properties_equal(TransformationStyleValue const& other) const { return m_properties == other.m_properties; } - -private: - TransformationStyleValue(CSS::TransformFunction transform_function, StyleValueVector&& values) - : StyleValueWithDefaultOperators(Type::Transformation) - , m_properties { .transform_function = transform_function, .values = move(values) } - { - } - - struct Properties { - CSS::TransformFunction transform_function; - StyleValueVector values; - bool operator==(Properties const& other) const; - } m_properties; -}; - class UnresolvedStyleValue final : public StyleValue { public: static ValueComparingNonnullRefPtr create(Vector&& values, bool contains_var_or_attr) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp new file mode 100644 index 0000000000..dfa33429bb --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.cpp @@ -0,0 +1,35 @@ +/* + * 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 "TransformationStyleValue.h" +#include + +namespace Web::CSS { + +ErrorOr TransformationStyleValue::to_string() const +{ + StringBuilder builder; + TRY(builder.try_append(CSS::to_string(m_properties.transform_function))); + TRY(builder.try_append('(')); + for (size_t i = 0; i < m_properties.values.size(); ++i) { + TRY(builder.try_append(TRY(m_properties.values[i]->to_string()))); + if (i != m_properties.values.size() - 1) + TRY(builder.try_append(", "sv)); + } + TRY(builder.try_append(')')); + + return builder.to_string(); +} + +bool TransformationStyleValue::Properties::operator==(Properties const& other) const +{ + return transform_function == other.transform_function && values.span() == other.values.span(); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h new file mode 100644 index 0000000000..c7986a7df9 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/TransformationStyleValue.h @@ -0,0 +1,46 @@ +/* + * 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 TransformationStyleValue final : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create(CSS::TransformFunction transform_function, StyleValueVector&& values) + { + return adopt_ref(*new TransformationStyleValue(transform_function, move(values))); + } + virtual ~TransformationStyleValue() override = default; + + CSS::TransformFunction transform_function() const { return m_properties.transform_function; } + StyleValueVector values() const { return m_properties.values; } + + virtual ErrorOr to_string() const override; + + bool properties_equal(TransformationStyleValue const& other) const { return m_properties == other.m_properties; } + +private: + TransformationStyleValue(CSS::TransformFunction transform_function, StyleValueVector&& values) + : StyleValueWithDefaultOperators(Type::Transformation) + , m_properties { .transform_function = transform_function, .values = move(values) } + { + } + + struct Properties { + CSS::TransformFunction transform_function; + StyleValueVector values; + bool operator==(Properties const& other) const; + } m_properties; +}; + +} -- cgit v1.2.3