summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-03-23 17:35:44 +0000
committerLinus Groh <mail@linusgroh.de>2023-03-25 16:56:04 +0000
commit92a0d4c0af8cab52ef45a35c355c7f86f8680fc0 (patch)
treef2a673f76d2f22a0ece4eafde385f51d7588feed /Userland
parent777d3e73f9f22c66aed6f631958926fb95e877c8 (diff)
downloadserenity-92a0d4c0af8cab52ef45a35c355c7f86f8680fc0.zip
LibWeb: Split BackgroundStyleValue out of StyleValue.{h,cpp}
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
-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/StyleValue.cpp64
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h56
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp79
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.h72
8 files changed, 156 insertions, 119 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 76ddc31a33..9f95467170 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -65,6 +65,7 @@ set(SOURCES
CSS/StyleSheetList.cpp
CSS/StyleValue.cpp
CSS/StyleValues/AngleStyleValue.cpp
+ CSS/StyleValues/BackgroundStyleValue.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 7362278f3d..bd13f458b6 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -30,6 +30,7 @@
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/CSS/StyleValue.h>
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
+#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.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 753b047003..0e25f087c9 100644
--- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
+++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
@@ -12,6 +12,7 @@
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
#include <LibWeb/CSS/StyleComputer.h>
+#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.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 e3f4ba0f5b..dec8344565 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -25,6 +25,7 @@
#include <LibWeb/CSS/SelectorEngine.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleSheet.h>
+#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.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 77cc6dfa60..25f4ab33a2 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -12,6 +12,7 @@
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/CSS/StyleValue.h>
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
+#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/Loader/LoadRequest.h>
@@ -291,69 +292,6 @@ StyleValueList const& StyleValue::as_value_list() const
return static_cast<StyleValueList const&>(*this);
}
-BackgroundStyleValue::BackgroundStyleValue(
- ValueComparingNonnullRefPtr<StyleValue const> color,
- ValueComparingNonnullRefPtr<StyleValue const> image,
- ValueComparingNonnullRefPtr<StyleValue const> position,
- ValueComparingNonnullRefPtr<StyleValue const> size,
- ValueComparingNonnullRefPtr<StyleValue const> repeat,
- ValueComparingNonnullRefPtr<StyleValue const> attachment,
- ValueComparingNonnullRefPtr<StyleValue const> origin,
- ValueComparingNonnullRefPtr<StyleValue const> clip)
- : StyleValueWithDefaultOperators(Type::Background)
- , m_properties {
- .color = move(color),
- .image = move(image),
- .position = move(position),
- .size = move(size),
- .repeat = move(repeat),
- .attachment = move(attachment),
- .origin = move(origin),
- .clip = move(clip),
- .layer_count = 0
- }
-{
- auto layer_count = [](auto style_value) -> size_t {
- if (style_value->is_value_list())
- return style_value->as_value_list().size();
- else
- return 1;
- };
-
- m_properties.layer_count = max(layer_count(m_properties.image), layer_count(m_properties.position));
- m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.size));
- m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.repeat));
- m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.attachment));
- m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.origin));
- m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.clip));
-
- VERIFY(!m_properties.color->is_value_list());
-}
-
-ErrorOr<String> BackgroundStyleValue::to_string() const
-{
- if (m_properties.layer_count == 1) {
- return String::formatted("{} {} {} {} {} {} {} {}", TRY(m_properties.color->to_string()), TRY(m_properties.image->to_string()), TRY(m_properties.position->to_string()), TRY(m_properties.size->to_string()), TRY(m_properties.repeat->to_string()), TRY(m_properties.attachment->to_string()), TRY(m_properties.origin->to_string()), TRY(m_properties.clip->to_string()));
- }
-
- auto get_layer_value_string = [](ValueComparingNonnullRefPtr<StyleValue const> const& style_value, size_t index) {
- if (style_value->is_value_list())
- return style_value->as_value_list().value_at(index, true)->to_string();
- return style_value->to_string();
- };
-
- StringBuilder builder;
- for (size_t i = 0; i < m_properties.layer_count; i++) {
- if (i)
- TRY(builder.try_append(", "sv));
- if (i == m_properties.layer_count - 1)
- TRY(builder.try_appendff("{} ", TRY(m_properties.color->to_string())));
- TRY(builder.try_appendff("{} {} {} {} {} {} {}", TRY(get_layer_value_string(m_properties.image, i)), TRY(get_layer_value_string(m_properties.position, i)), TRY(get_layer_value_string(m_properties.size, i)), TRY(get_layer_value_string(m_properties.repeat, i)), TRY(get_layer_value_string(m_properties.attachment, i)), TRY(get_layer_value_string(m_properties.origin, i)), TRY(get_layer_value_string(m_properties.clip, i))));
- }
-
- return builder.to_string();
-}
-
ErrorOr<String> BackgroundRepeatStyleValue::to_string() const
{
return String::formatted("{} {}", CSS::to_string(m_properties.repeat_x), CSS::to_string(m_properties.repeat_y));
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 91587cbf35..7fe90724b2 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -502,62 +502,6 @@ struct StyleValueWithDefaultOperators : public StyleValue {
}
};
-class BackgroundStyleValue final : public StyleValueWithDefaultOperators<BackgroundStyleValue> {
-public:
- static ValueComparingNonnullRefPtr<BackgroundStyleValue> create(
- ValueComparingNonnullRefPtr<StyleValue const> color,
- ValueComparingNonnullRefPtr<StyleValue const> image,
- ValueComparingNonnullRefPtr<StyleValue const> position,
- ValueComparingNonnullRefPtr<StyleValue const> size,
- ValueComparingNonnullRefPtr<StyleValue const> repeat,
- ValueComparingNonnullRefPtr<StyleValue const> attachment,
- ValueComparingNonnullRefPtr<StyleValue const> origin,
- ValueComparingNonnullRefPtr<StyleValue const> clip)
- {
- return adopt_ref(*new BackgroundStyleValue(move(color), move(image), move(position), move(size), move(repeat), move(attachment), move(origin), move(clip)));
- }
- virtual ~BackgroundStyleValue() override = default;
-
- size_t layer_count() const { return m_properties.layer_count; }
-
- auto attachment() const { return m_properties.attachment; }
- auto clip() const { return m_properties.clip; }
- auto color() const { return m_properties.color; }
- auto image() const { return m_properties.image; }
- auto origin() const { return m_properties.origin; }
- auto position() const { return m_properties.position; }
- auto repeat() const { return m_properties.repeat; }
- auto size() const { return m_properties.size; }
-
- virtual ErrorOr<String> to_string() const override;
-
- bool properties_equal(BackgroundStyleValue const& other) const { return m_properties == other.m_properties; }
-
-private:
- BackgroundStyleValue(
- ValueComparingNonnullRefPtr<StyleValue const> color,
- ValueComparingNonnullRefPtr<StyleValue const> image,
- ValueComparingNonnullRefPtr<StyleValue const> position,
- ValueComparingNonnullRefPtr<StyleValue const> size,
- ValueComparingNonnullRefPtr<StyleValue const> repeat,
- ValueComparingNonnullRefPtr<StyleValue const> attachment,
- ValueComparingNonnullRefPtr<StyleValue const> origin,
- ValueComparingNonnullRefPtr<StyleValue const> clip);
-
- struct Properties {
- ValueComparingNonnullRefPtr<StyleValue const> color;
- ValueComparingNonnullRefPtr<StyleValue const> image;
- ValueComparingNonnullRefPtr<StyleValue const> position;
- ValueComparingNonnullRefPtr<StyleValue const> size;
- ValueComparingNonnullRefPtr<StyleValue const> repeat;
- ValueComparingNonnullRefPtr<StyleValue const> attachment;
- ValueComparingNonnullRefPtr<StyleValue const> origin;
- ValueComparingNonnullRefPtr<StyleValue const> clip;
- size_t layer_count;
- bool operator==(Properties const&) const = default;
- } m_properties;
-};
-
class BackgroundRepeatStyleValue final : public StyleValueWithDefaultOperators<BackgroundRepeatStyleValue> {
public:
static ValueComparingNonnullRefPtr<BackgroundRepeatStyleValue> create(Repeat repeat_x, Repeat repeat_y)
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp
new file mode 100644
index 0000000000..aa3a29fb3d
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
+ * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "BackgroundStyleValue.h"
+
+namespace Web::CSS {
+
+BackgroundStyleValue::BackgroundStyleValue(
+ ValueComparingNonnullRefPtr<StyleValue const> color,
+ ValueComparingNonnullRefPtr<StyleValue const> image,
+ ValueComparingNonnullRefPtr<StyleValue const> position,
+ ValueComparingNonnullRefPtr<StyleValue const> size,
+ ValueComparingNonnullRefPtr<StyleValue const> repeat,
+ ValueComparingNonnullRefPtr<StyleValue const> attachment,
+ ValueComparingNonnullRefPtr<StyleValue const> origin,
+ ValueComparingNonnullRefPtr<StyleValue const> clip)
+ : StyleValueWithDefaultOperators(Type::Background)
+ , m_properties {
+ .color = move(color),
+ .image = move(image),
+ .position = move(position),
+ .size = move(size),
+ .repeat = move(repeat),
+ .attachment = move(attachment),
+ .origin = move(origin),
+ .clip = move(clip),
+ .layer_count = 0
+ }
+{
+ auto layer_count = [](auto style_value) -> size_t {
+ if (style_value->is_value_list())
+ return style_value->as_value_list().size();
+ else
+ return 1;
+ };
+
+ m_properties.layer_count = max(layer_count(m_properties.image), layer_count(m_properties.position));
+ m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.size));
+ m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.repeat));
+ m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.attachment));
+ m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.origin));
+ m_properties.layer_count = max(m_properties.layer_count, layer_count(m_properties.clip));
+
+ VERIFY(!m_properties.color->is_value_list());
+}
+
+BackgroundStyleValue::~BackgroundStyleValue() = default;
+
+ErrorOr<String> BackgroundStyleValue::to_string() const
+{
+ if (m_properties.layer_count == 1) {
+ return String::formatted("{} {} {} {} {} {} {} {}", TRY(m_properties.color->to_string()), TRY(m_properties.image->to_string()), TRY(m_properties.position->to_string()), TRY(m_properties.size->to_string()), TRY(m_properties.repeat->to_string()), TRY(m_properties.attachment->to_string()), TRY(m_properties.origin->to_string()), TRY(m_properties.clip->to_string()));
+ }
+
+ auto get_layer_value_string = [](ValueComparingNonnullRefPtr<StyleValue const> const& style_value, size_t index) {
+ if (style_value->is_value_list())
+ return style_value->as_value_list().value_at(index, true)->to_string();
+ return style_value->to_string();
+ };
+
+ StringBuilder builder;
+ for (size_t i = 0; i < m_properties.layer_count; i++) {
+ if (i)
+ TRY(builder.try_append(", "sv));
+ if (i == m_properties.layer_count - 1)
+ TRY(builder.try_appendff("{} ", TRY(m_properties.color->to_string())));
+ TRY(builder.try_appendff("{} {} {} {} {} {} {}", TRY(get_layer_value_string(m_properties.image, i)), TRY(get_layer_value_string(m_properties.position, i)), TRY(get_layer_value_string(m_properties.size, i)), TRY(get_layer_value_string(m_properties.repeat, i)), TRY(get_layer_value_string(m_properties.attachment, i)), TRY(get_layer_value_string(m_properties.origin, i)), TRY(get_layer_value_string(m_properties.clip, i))));
+ }
+
+ return builder.to_string();
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.h
new file mode 100644
index 0000000000..21e90f736c
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BackgroundStyleValue.h
@@ -0,0 +1,72 @@
+/*
+ * 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 BackgroundStyleValue final : public StyleValueWithDefaultOperators<BackgroundStyleValue> {
+public:
+ static ValueComparingNonnullRefPtr<BackgroundStyleValue> create(
+ ValueComparingNonnullRefPtr<StyleValue const> color,
+ ValueComparingNonnullRefPtr<StyleValue const> image,
+ ValueComparingNonnullRefPtr<StyleValue const> position,
+ ValueComparingNonnullRefPtr<StyleValue const> size,
+ ValueComparingNonnullRefPtr<StyleValue const> repeat,
+ ValueComparingNonnullRefPtr<StyleValue const> attachment,
+ ValueComparingNonnullRefPtr<StyleValue const> origin,
+ ValueComparingNonnullRefPtr<StyleValue const> clip)
+ {
+ return adopt_ref(*new BackgroundStyleValue(move(color), move(image), move(position), move(size), move(repeat), move(attachment), move(origin), move(clip)));
+ }
+ virtual ~BackgroundStyleValue() override;
+
+ size_t layer_count() const { return m_properties.layer_count; }
+
+ auto attachment() const { return m_properties.attachment; }
+ auto clip() const { return m_properties.clip; }
+ auto color() const { return m_properties.color; }
+ auto image() const { return m_properties.image; }
+ auto origin() const { return m_properties.origin; }
+ auto position() const { return m_properties.position; }
+ auto repeat() const { return m_properties.repeat; }
+ auto size() const { return m_properties.size; }
+
+ virtual ErrorOr<String> to_string() const override;
+
+ bool properties_equal(BackgroundStyleValue const& other) const { return m_properties == other.m_properties; }
+
+private:
+ BackgroundStyleValue(
+ ValueComparingNonnullRefPtr<StyleValue const> color,
+ ValueComparingNonnullRefPtr<StyleValue const> image,
+ ValueComparingNonnullRefPtr<StyleValue const> position,
+ ValueComparingNonnullRefPtr<StyleValue const> size,
+ ValueComparingNonnullRefPtr<StyleValue const> repeat,
+ ValueComparingNonnullRefPtr<StyleValue const> attachment,
+ ValueComparingNonnullRefPtr<StyleValue const> origin,
+ ValueComparingNonnullRefPtr<StyleValue const> clip);
+
+ struct Properties {
+ ValueComparingNonnullRefPtr<StyleValue const> color;
+ ValueComparingNonnullRefPtr<StyleValue const> image;
+ ValueComparingNonnullRefPtr<StyleValue const> position;
+ ValueComparingNonnullRefPtr<StyleValue const> size;
+ ValueComparingNonnullRefPtr<StyleValue const> repeat;
+ ValueComparingNonnullRefPtr<StyleValue const> attachment;
+ ValueComparingNonnullRefPtr<StyleValue const> origin;
+ ValueComparingNonnullRefPtr<StyleValue const> clip;
+ size_t layer_count;
+ bool operator==(Properties const&) const = default;
+ } m_properties;
+};
+
+}