diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 1e0b26d62aa..d01584d7314 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -90,6 +90,7 @@ set(SOURCES CSS/StyleValues/ListStyleStyleValue.cpp CSS/StyleValues/NumericStyleValue.cpp CSS/StyleValues/OverflowStyleValue.cpp + CSS/StyleValues/PositionStyleValue.cpp CSS/StyleValues/RadialGradientStyleValue.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 028646910e7..7f716df6341 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 7820ffbdaed..e59c5995855 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -27,6 +27,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 4b53111becf..1e42bc81b48 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -1139,25 +1140,6 @@ ErrorOr PositionValue::serialize(StringBuilder& builder) const return {}; } -ErrorOr PositionStyleValue::to_string() const -{ - auto to_string = [](PositionEdge edge) { - switch (edge) { - case PositionEdge::Left: - return "left"; - case PositionEdge::Right: - return "right"; - case PositionEdge::Top: - return "top"; - case PositionEdge::Bottom: - return "bottom"; - } - VERIFY_NOT_REACHED(); - }; - - return String::formatted("{} {} {} {}", to_string(m_properties.edge_x), TRY(m_properties.offset_x.to_string()), to_string(m_properties.edge_y), TRY(m_properties.offset_y.to_string())); -} - ErrorOr RectStyleValue::to_string() const { return String::formatted("rect({} {} {} {})", m_rect.top_edge, m_rect.right_edge, m_rect.bottom_edge, m_rect.left_edge); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 3a82ce3e009..847f74b1791 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -627,39 +627,6 @@ private: NonnullOwnPtr m_expression; }; -class PositionStyleValue final : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create(PositionEdge edge_x, LengthPercentage const& offset_x, PositionEdge edge_y, LengthPercentage const& offset_y) - { - return adopt_ref(*new PositionStyleValue(edge_x, offset_x, edge_y, offset_y)); - } - virtual ~PositionStyleValue() override = default; - - PositionEdge edge_x() const { return m_properties.edge_x; } - LengthPercentage const& offset_x() const { return m_properties.offset_x; } - PositionEdge edge_y() const { return m_properties.edge_y; } - LengthPercentage const& offset_y() const { return m_properties.offset_y; } - - virtual ErrorOr to_string() const override; - - bool properties_equal(PositionStyleValue const& other) const { return m_properties == other.m_properties; } - -private: - PositionStyleValue(PositionEdge edge_x, LengthPercentage const& offset_x, PositionEdge edge_y, LengthPercentage const& offset_y) - : StyleValueWithDefaultOperators(Type::Position) - , m_properties { .edge_x = edge_x, .offset_x = offset_x, .edge_y = edge_y, .offset_y = offset_y } - { - } - - struct Properties { - PositionEdge edge_x; - LengthPercentage offset_x; - PositionEdge edge_y; - LengthPercentage offset_y; - bool operator==(Properties const&) const = default; - } m_properties; -}; - class ResolutionStyleValue : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create(Resolution resolution) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.cpp new file mode 100644 index 00000000000..543c13de312 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.cpp @@ -0,0 +1,33 @@ +/* + * 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 "PositionStyleValue.h" + +namespace Web::CSS { + +ErrorOr PositionStyleValue::to_string() const +{ + auto to_string = [](PositionEdge edge) { + switch (edge) { + case PositionEdge::Left: + return "left"; + case PositionEdge::Right: + return "right"; + case PositionEdge::Top: + return "top"; + case PositionEdge::Bottom: + return "bottom"; + } + VERIFY_NOT_REACHED(); + }; + + return String::formatted("{} {} {} {}", to_string(m_properties.edge_x), TRY(m_properties.offset_x.to_string()), to_string(m_properties.edge_y), TRY(m_properties.offset_y.to_string())); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h new file mode 100644 index 00000000000..77bfb4737a8 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h @@ -0,0 +1,51 @@ +/* + * 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 +#include +#include + +namespace Web::CSS { + +class PositionStyleValue final : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create(PositionEdge edge_x, LengthPercentage const& offset_x, PositionEdge edge_y, LengthPercentage const& offset_y) + { + return adopt_ref(*new PositionStyleValue(edge_x, offset_x, edge_y, offset_y)); + } + virtual ~PositionStyleValue() override = default; + + PositionEdge edge_x() const { return m_properties.edge_x; } + LengthPercentage const& offset_x() const { return m_properties.offset_x; } + PositionEdge edge_y() const { return m_properties.edge_y; } + LengthPercentage const& offset_y() const { return m_properties.offset_y; } + + virtual ErrorOr to_string() const override; + + bool properties_equal(PositionStyleValue const& other) const { return m_properties == other.m_properties; } + +private: + PositionStyleValue(PositionEdge edge_x, LengthPercentage const& offset_x, PositionEdge edge_y, LengthPercentage const& offset_y) + : StyleValueWithDefaultOperators(Type::Position) + , m_properties { .edge_x = edge_x, .offset_x = offset_x, .edge_y = edge_y, .offset_y = offset_y } + { + } + + struct Properties { + PositionEdge edge_x; + LengthPercentage offset_x; + PositionEdge edge_y; + LengthPercentage offset_y; + bool operator==(Properties const&) const = default; + } m_properties; +}; + +} diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index f2ad64c6dcf..f0634c8d4a8 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include