From 273b9b4ca17c38bf807ca0857205cf0fd51a7539 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 23 Mar 2023 21:33:13 +0000 Subject: LibWeb: Split FlexStyleValue out of StyleValue.{h,cpp} --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 1 + Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 1 + Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 6 +-- Userland/Libraries/LibWeb/CSS/StyleValue.h | 37 --------------- .../LibWeb/CSS/StyleValues/FlexStyleValue.cpp | 19 ++++++++ .../LibWeb/CSS/StyleValues/FlexStyleValue.h | 53 ++++++++++++++++++++++ 7 files changed, 76 insertions(+), 42 deletions(-) create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.cpp create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h (limited to 'Userland') 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 #include #include +#include #include #include #include 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 #include #include +#include #include #include #include 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 #include #include +#include #include #include #include @@ -1023,11 +1024,6 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW return value->resolve(layout_node, percentage_basis); } -ErrorOr 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 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 m_expression; }; -class FlexStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create( - ValueComparingNonnullRefPtr grow, - ValueComparingNonnullRefPtr shrink, - ValueComparingNonnullRefPtr basis) - { - return adopt_ref(*new FlexStyleValue(move(grow), move(shrink), move(basis))); - } - virtual ~FlexStyleValue() override = default; - - ValueComparingNonnullRefPtr grow() const { return m_properties.grow; } - ValueComparingNonnullRefPtr shrink() const { return m_properties.shrink; } - ValueComparingNonnullRefPtr basis() const { return m_properties.basis; } - - virtual ErrorOr to_string() const override; - - bool properties_equal(FlexStyleValue const& other) const { return m_properties == other.m_properties; }; - -private: - FlexStyleValue( - ValueComparingNonnullRefPtr grow, - ValueComparingNonnullRefPtr shrink, - ValueComparingNonnullRefPtr basis) - : StyleValueWithDefaultOperators(Type::Flex) - , m_properties { .grow = move(grow), .shrink = move(shrink), .basis = move(basis) } - { - } - - struct Properties { - ValueComparingNonnullRefPtr grow; - ValueComparingNonnullRefPtr shrink; - ValueComparingNonnullRefPtr basis; - bool operator==(Properties const&) const = default; - } m_properties; -}; - class FlexFlowStyleValue final : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr flex_direction, ValueComparingNonnullRefPtr 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 + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2022-2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "FlexStyleValue.h" + +namespace Web::CSS { + +ErrorOr 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 + * 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 + +namespace Web::CSS { + +class FlexStyleValue final : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create( + ValueComparingNonnullRefPtr grow, + ValueComparingNonnullRefPtr shrink, + ValueComparingNonnullRefPtr basis) + { + return adopt_ref(*new FlexStyleValue(move(grow), move(shrink), move(basis))); + } + virtual ~FlexStyleValue() override = default; + + ValueComparingNonnullRefPtr grow() const { return m_properties.grow; } + ValueComparingNonnullRefPtr shrink() const { return m_properties.shrink; } + ValueComparingNonnullRefPtr basis() const { return m_properties.basis; } + + virtual ErrorOr to_string() const override; + + bool properties_equal(FlexStyleValue const& other) const { return m_properties == other.m_properties; }; + +private: + FlexStyleValue( + ValueComparingNonnullRefPtr grow, + ValueComparingNonnullRefPtr shrink, + ValueComparingNonnullRefPtr basis) + : StyleValueWithDefaultOperators(Type::Flex) + , m_properties { .grow = move(grow), .shrink = move(shrink), .basis = move(basis) } + { + } + + struct Properties { + ValueComparingNonnullRefPtr grow; + ValueComparingNonnullRefPtr shrink; + ValueComparingNonnullRefPtr basis; + bool operator==(Properties const&) const = default; + } m_properties; +}; + +} -- cgit v1.2.3