diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-23 21:33:13 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-25 16:56:04 +0000 |
commit | 273b9b4ca17c38bf807ca0857205cf0fd51a7539 (patch) | |
tree | 2a81386d3011fbbca599c51913caf47595d401ac /Userland | |
parent | 89ed8e59f94e5c2be227510eda17a3d6e13f63f2 (diff) | |
download | serenity-273b9b4ca17c38bf807ca0857205cf0fd51a7539.zip |
LibWeb: Split FlexStyleValue out of StyleValue.{h,cpp}
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 37 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.cpp | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h | 53 |
7 files changed, 76 insertions, 42 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 450c8b59ac..903211490d 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -74,6 +74,7 @@ set(SOURCES CSS/StyleValues/ColorStyleValue.cpp CSS/StyleValues/ContentStyleValue.cpp CSS/StyleValues/FilterValueListStyleValue.cpp + CSS/StyleValues/FlexStyleValue.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 1a2883164a..be7c45e628 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -39,6 +39,7 @@ #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/CSS/StyleValues/ContentStyleValue.h> #include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h> +#include <LibWeb/CSS/StyleValues/FlexStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/Dump.h> #include <LibWeb/Infra/Strings.h> diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 61d8a4b754..456df1225f 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -31,6 +31,7 @@ #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h> +#include <LibWeb/CSS/StyleValues/FlexStyleValue.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 f13b0db3a2..d01661d98c 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -21,6 +21,7 @@ #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> #include <LibWeb/CSS/StyleValues/ContentStyleValue.h> #include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h> +#include <LibWeb/CSS/StyleValues/FlexStyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/BrowsingContext.h> #include <LibWeb/Loader/LoadRequest.h> @@ -1023,11 +1024,6 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW return value->resolve(layout_node, percentage_basis); } -ErrorOr<String> FlexStyleValue::to_string() const -{ - return String::formatted("{} {} {}", TRY(m_properties.grow->to_string()), TRY(m_properties.shrink->to_string()), TRY(m_properties.basis->to_string())); -} - ErrorOr<String> FlexFlowStyleValue::to_string() const { return String::formatted("{} {}", TRY(m_properties.flex_direction->to_string()), TRY(m_properties.flex_wrap->to_string())); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 1a40817745..80ff2ebaae 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -661,43 +661,6 @@ private: NonnullOwnPtr<CalcSum> m_expression; }; -class FlexStyleValue final : public StyleValueWithDefaultOperators<FlexStyleValue> { -public: - static ValueComparingNonnullRefPtr<FlexStyleValue> create( - ValueComparingNonnullRefPtr<StyleValue> grow, - ValueComparingNonnullRefPtr<StyleValue> shrink, - ValueComparingNonnullRefPtr<StyleValue> basis) - { - return adopt_ref(*new FlexStyleValue(move(grow), move(shrink), move(basis))); - } - virtual ~FlexStyleValue() override = default; - - ValueComparingNonnullRefPtr<StyleValue> grow() const { return m_properties.grow; } - ValueComparingNonnullRefPtr<StyleValue> shrink() const { return m_properties.shrink; } - ValueComparingNonnullRefPtr<StyleValue> basis() const { return m_properties.basis; } - - virtual ErrorOr<String> to_string() const override; - - bool properties_equal(FlexStyleValue const& other) const { return m_properties == other.m_properties; }; - -private: - FlexStyleValue( - ValueComparingNonnullRefPtr<StyleValue> grow, - ValueComparingNonnullRefPtr<StyleValue> shrink, - ValueComparingNonnullRefPtr<StyleValue> basis) - : StyleValueWithDefaultOperators(Type::Flex) - , m_properties { .grow = move(grow), .shrink = move(shrink), .basis = move(basis) } - { - } - - struct Properties { - ValueComparingNonnullRefPtr<StyleValue> grow; - ValueComparingNonnullRefPtr<StyleValue> shrink; - ValueComparingNonnullRefPtr<StyleValue> basis; - bool operator==(Properties const&) const = default; - } m_properties; -}; - class FlexFlowStyleValue final : public StyleValueWithDefaultOperators<FlexFlowStyleValue> { public: static ValueComparingNonnullRefPtr<FlexFlowStyleValue> create(ValueComparingNonnullRefPtr<StyleValue> flex_direction, ValueComparingNonnullRefPtr<StyleValue> flex_wrap) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.cpp new file mode 100644 index 0000000000..6f4a8c3995 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.cpp @@ -0,0 +1,19 @@ +/* + * 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 "FlexStyleValue.h" + +namespace Web::CSS { + +ErrorOr<String> FlexStyleValue::to_string() const +{ + return String::formatted("{} {} {}", TRY(m_properties.grow->to_string()), TRY(m_properties.shrink->to_string()), TRY(m_properties.basis->to_string())); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h new file mode 100644 index 0000000000..18c8591060 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h @@ -0,0 +1,53 @@ +/* + * 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 FlexStyleValue final : public StyleValueWithDefaultOperators<FlexStyleValue> { +public: + static ValueComparingNonnullRefPtr<FlexStyleValue> create( + ValueComparingNonnullRefPtr<StyleValue> grow, + ValueComparingNonnullRefPtr<StyleValue> shrink, + ValueComparingNonnullRefPtr<StyleValue> basis) + { + return adopt_ref(*new FlexStyleValue(move(grow), move(shrink), move(basis))); + } + virtual ~FlexStyleValue() override = default; + + ValueComparingNonnullRefPtr<StyleValue> grow() const { return m_properties.grow; } + ValueComparingNonnullRefPtr<StyleValue> shrink() const { return m_properties.shrink; } + ValueComparingNonnullRefPtr<StyleValue> basis() const { return m_properties.basis; } + + virtual ErrorOr<String> to_string() const override; + + bool properties_equal(FlexStyleValue const& other) const { return m_properties == other.m_properties; }; + +private: + FlexStyleValue( + ValueComparingNonnullRefPtr<StyleValue> grow, + ValueComparingNonnullRefPtr<StyleValue> shrink, + ValueComparingNonnullRefPtr<StyleValue> basis) + : StyleValueWithDefaultOperators(Type::Flex) + , m_properties { .grow = move(grow), .shrink = move(shrink), .basis = move(basis) } + { + } + + struct Properties { + ValueComparingNonnullRefPtr<StyleValue> grow; + ValueComparingNonnullRefPtr<StyleValue> shrink; + ValueComparingNonnullRefPtr<StyleValue> basis; + bool operator==(Properties const&) const = default; + } m_properties; +}; + +} |