summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-03-25 00:12:21 +0000
committerLinus Groh <mail@linusgroh.de>2023-03-25 16:56:04 +0000
commit4c54c5d3dd1d3b51a84a5466766db2225dd5c569 (patch)
tree8deee7972d8d693496041f5cbb80da5521b3ddda /Userland/Libraries/LibWeb/CSS
parent3a2de67c7b151fb61647eeb8738b3731fc3b49c9 (diff)
downloadserenity-4c54c5d3dd1d3b51a84a5466766db2225dd5c569.zip
LibWeb: Split StyleValueList out of StyleValue.{h,cpp}
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp29
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h35
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.cpp42
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.h51
10 files changed, 100 insertions, 63 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index a25f381029..2651908389 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -65,6 +65,7 @@
#include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h>
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
index e55e139ae8..b484fd1a69 100644
--- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
+++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
@@ -30,6 +30,7 @@
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 6288d9bf43..dcc9cabff3 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -43,6 +43,7 @@
#include <LibWeb/CSS/StyleValues/NumericStyleValue.h>
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h>
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
#include <LibWeb/DOM/Document.h>
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
index 33b16a9b3e..ded4425ebb 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
@@ -18,6 +18,7 @@
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
#include <LibWeb/FontCache.h>
#include <LibWeb/Layout/BlockContainer.h>
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index eeda36a8bf..37957c93ac 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -48,6 +48,7 @@
#include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h>
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
@@ -1149,34 +1150,6 @@ ErrorOr<void> PositionValue::serialize(StringBuilder& builder) const
return {};
}
-bool StyleValueList::Properties::operator==(Properties const& other) const
-{
- return separator == other.separator && values.span() == other.values.span();
-}
-
-ErrorOr<String> StyleValueList::to_string() const
-{
- auto separator = ""sv;
- switch (m_properties.separator) {
- case Separator::Space:
- separator = " "sv;
- break;
- case Separator::Comma:
- separator = ", "sv;
- break;
- default:
- VERIFY_NOT_REACHED();
- }
-
- StringBuilder builder;
- 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(separator));
- }
- return builder.to_string();
-}
-
Optional<CSS::Length> absolutized_length(CSS::Length const& length, CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height)
{
if (length.is_px())
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 41f181a56d..c04fcb9a66 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -622,41 +622,6 @@ private:
NonnullOwnPtr<CalcSum> m_expression;
};
-class StyleValueList final : public StyleValueWithDefaultOperators<StyleValueList> {
-public:
- enum class Separator {
- Space,
- Comma,
- };
- static ValueComparingNonnullRefPtr<StyleValueList> create(StyleValueVector&& values, Separator separator) { return adopt_ref(*new StyleValueList(move(values), separator)); }
-
- size_t size() const { return m_properties.values.size(); }
- StyleValueVector const& values() const { return m_properties.values; }
- ValueComparingNonnullRefPtr<StyleValue const> value_at(size_t i, bool allow_loop) const
- {
- if (allow_loop)
- return m_properties.values[i % size()];
- return m_properties.values[i];
- }
-
- virtual ErrorOr<String> to_string() const override;
-
- bool properties_equal(StyleValueList const& other) const { return m_properties == other.m_properties; }
-
-private:
- StyleValueList(StyleValueVector&& values, Separator separator)
- : StyleValueWithDefaultOperators(Type::ValueList)
- , m_properties { .separator = separator, .values = move(values) }
- {
- }
-
- struct Properties {
- Separator separator;
- StyleValueVector values;
- bool operator==(Properties const&) const;
- } m_properties;
-};
-
}
template<>
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp
index aa3a29fb3d..8148bb5212 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp
@@ -8,6 +8,7 @@
*/
#include "BackgroundStyleValue.h"
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
namespace Web::CSS {
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
index e3513fab71..17d6be591a 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ContentStyleValue.cpp
@@ -8,6 +8,7 @@
*/
#include "ContentStyleValue.h"
+#include <LibWeb/CSS/StyleValues/StyleValueList.h>
namespace Web::CSS {
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.cpp
new file mode 100644
index 0000000000..af03150b6d
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.cpp
@@ -0,0 +1,42 @@
+/*
+ * 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 "StyleValueList.h"
+
+namespace Web::CSS {
+
+bool StyleValueList::Properties::operator==(Properties const& other) const
+{
+ return separator == other.separator && values.span() == other.values.span();
+}
+
+ErrorOr<String> StyleValueList::to_string() const
+{
+ auto separator = ""sv;
+ switch (m_properties.separator) {
+ case Separator::Space:
+ separator = " "sv;
+ break;
+ case Separator::Comma:
+ separator = ", "sv;
+ break;
+ default:
+ VERIFY_NOT_REACHED();
+ }
+
+ StringBuilder builder;
+ 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(separator));
+ }
+ return builder.to_string();
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.h b/Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
new file mode 100644
index 0000000000..2006ef1820
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
@@ -0,0 +1,51 @@
+/*
+ * 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 <LibWeb/CSS/StyleValue.h>
+
+namespace Web::CSS {
+
+class StyleValueList final : public StyleValueWithDefaultOperators<StyleValueList> {
+public:
+ enum class Separator {
+ Space,
+ Comma,
+ };
+ static ValueComparingNonnullRefPtr<StyleValueList> create(StyleValueVector&& values, Separator separator) { return adopt_ref(*new StyleValueList(move(values), separator)); }
+
+ size_t size() const { return m_properties.values.size(); }
+ StyleValueVector const& values() const { return m_properties.values; }
+ ValueComparingNonnullRefPtr<StyleValue const> value_at(size_t i, bool allow_loop) const
+ {
+ if (allow_loop)
+ return m_properties.values[i % size()];
+ return m_properties.values[i];
+ }
+
+ virtual ErrorOr<String> to_string() const override;
+
+ bool properties_equal(StyleValueList const& other) const { return m_properties == other.m_properties; }
+
+private:
+ StyleValueList(StyleValueVector&& values, Separator separator)
+ : StyleValueWithDefaultOperators(Type::ValueList)
+ , m_properties { .separator = separator, .values = move(values) }
+ {
+ }
+
+ struct Properties {
+ Separator separator;
+ StyleValueVector values;
+ bool operator==(Properties const&) const;
+ } m_properties;
+};
+
+}