From e24679f8701482efe2f3c8cdee7406a8513ebf0f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 23 Mar 2023 21:39:08 +0000 Subject: [PATCH] LibWeb: Split FlexFlowStyleValue out of StyleValue.{h,cpp} --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 1 + .../Libraries/LibWeb/CSS/StyleComputer.cpp | 1 + Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 6 +-- Userland/Libraries/LibWeb/CSS/StyleValue.h | 29 ------------ .../CSS/StyleValues/FlexFlowStyleValue.cpp | 19 ++++++++ .../CSS/StyleValues/FlexFlowStyleValue.h | 45 +++++++++++++++++++ 7 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/FlexFlowStyleValue.cpp create mode 100644 Userland/Libraries/LibWeb/CSS/StyleValues/FlexFlowStyleValue.h diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 903211490d..62c0d4a5e1 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/FlexFlowStyleValue.cpp CSS/StyleValues/FlexStyleValue.cpp CSS/Supports.cpp CSS/SyntaxHighlighter/SyntaxHighlighter.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index be7c45e628..2020233021 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 456df1225f..a248ed1c4b 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 d01661d98c..0f7281a2d8 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 @@ -1024,11 +1025,6 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW return value->resolve(layout_node, percentage_basis); } -ErrorOr FlexFlowStyleValue::to_string() const -{ - return String::formatted("{} {}", TRY(m_properties.flex_direction->to_string()), TRY(m_properties.flex_wrap->to_string())); -} - ErrorOr FontStyleValue::to_string() const { return String::formatted("{} {} {} / {} {}", TRY(m_properties.font_style->to_string()), TRY(m_properties.font_weight->to_string()), TRY(m_properties.font_size->to_string()), TRY(m_properties.line_height->to_string()), TRY(m_properties.font_families->to_string())); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 80ff2ebaae..dba988568d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -661,35 +661,6 @@ private: NonnullOwnPtr m_expression; }; -class FlexFlowStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr flex_direction, ValueComparingNonnullRefPtr flex_wrap) - { - return adopt_ref(*new FlexFlowStyleValue(move(flex_direction), move(flex_wrap))); - } - virtual ~FlexFlowStyleValue() override = default; - - ValueComparingNonnullRefPtr flex_direction() const { return m_properties.flex_direction; } - ValueComparingNonnullRefPtr flex_wrap() const { return m_properties.flex_wrap; } - - virtual ErrorOr to_string() const override; - - bool properties_equal(FlexFlowStyleValue const& other) const { return m_properties == other.m_properties; }; - -private: - FlexFlowStyleValue(ValueComparingNonnullRefPtr flex_direction, ValueComparingNonnullRefPtr flex_wrap) - : StyleValueWithDefaultOperators(Type::FlexFlow) - , m_properties { .flex_direction = move(flex_direction), .flex_wrap = move(flex_wrap) } - { - } - - struct Properties { - ValueComparingNonnullRefPtr flex_direction; - ValueComparingNonnullRefPtr flex_wrap; - bool operator==(Properties const&) const = default; - } m_properties; -}; - class FontStyleValue final : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr font_stretch, ValueComparingNonnullRefPtr font_style, ValueComparingNonnullRefPtr font_weight, ValueComparingNonnullRefPtr font_size, ValueComparingNonnullRefPtr line_height, ValueComparingNonnullRefPtr font_families) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/FlexFlowStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexFlowStyleValue.cpp new file mode 100644 index 0000000000..604a816607 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexFlowStyleValue.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 "FlexFlowStyleValue.h" + +namespace Web::CSS { + +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/StyleValues/FlexFlowStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexFlowStyleValue.h new file mode 100644 index 0000000000..18dc960664 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/FlexFlowStyleValue.h @@ -0,0 +1,45 @@ +/* + * 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 FlexFlowStyleValue final : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr flex_direction, ValueComparingNonnullRefPtr flex_wrap) + { + return adopt_ref(*new FlexFlowStyleValue(move(flex_direction), move(flex_wrap))); + } + virtual ~FlexFlowStyleValue() override = default; + + ValueComparingNonnullRefPtr flex_direction() const { return m_properties.flex_direction; } + ValueComparingNonnullRefPtr flex_wrap() const { return m_properties.flex_wrap; } + + virtual ErrorOr to_string() const override; + + bool properties_equal(FlexFlowStyleValue const& other) const { return m_properties == other.m_properties; }; + +private: + FlexFlowStyleValue(ValueComparingNonnullRefPtr flex_direction, ValueComparingNonnullRefPtr flex_wrap) + : StyleValueWithDefaultOperators(Type::FlexFlow) + , m_properties { .flex_direction = move(flex_direction), .flex_wrap = move(flex_wrap) } + { + } + + struct Properties { + ValueComparingNonnullRefPtr flex_direction; + ValueComparingNonnullRefPtr flex_wrap; + bool operator==(Properties const&) const = default; + } m_properties; +}; + +}