diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index f7f07dde62..77c13a040b 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -51,7 +51,7 @@ set(SOURCES CSS/Parser/Rule.cpp CSS/Parser/Token.cpp CSS/Parser/Tokenizer.cpp - CSS/Percentage.cpp + CSS/PercentageOr.cpp CSS/Position.cpp CSS/PreferredColorScheme.cpp CSS/Ratio.cpp diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 48bb3e206d..f742d79bce 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -8,13 +8,14 @@ #include #include +#include #include #include #include #include #include +#include #include -#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp index 128651f1af..64396ade9d 100644 --- a/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp +++ b/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp @@ -6,9 +6,6 @@ #include "GridTrackSize.h" #include -#include -#include -#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/LengthBox.cpp b/Userland/Libraries/LibWeb/CSS/LengthBox.cpp index f6ced27f35..7d271763e3 100644 --- a/Userland/Libraries/LibWeb/CSS/LengthBox.cpp +++ b/Userland/Libraries/LibWeb/CSS/LengthBox.cpp @@ -6,7 +6,6 @@ */ #include "LengthBox.h" -#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/LengthBox.h b/Userland/Libraries/LibWeb/CSS/LengthBox.h index 6d5bdd8e67..87f6d3cc05 100644 --- a/Userland/Libraries/LibWeb/CSS/LengthBox.h +++ b/Userland/Libraries/LibWeb/CSS/LengthBox.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.h b/Userland/Libraries/LibWeb/CSS/MediaQuery.h index 99a95808b6..942b8296b2 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.h +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.h @@ -11,9 +11,10 @@ #include #include #include +#include #include #include -#include +#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/Percentage.h b/Userland/Libraries/LibWeb/CSS/Percentage.h index 48fbc067f9..6769ccf1ca 100644 --- a/Userland/Libraries/LibWeb/CSS/Percentage.h +++ b/Userland/Libraries/LibWeb/CSS/Percentage.h @@ -42,232 +42,4 @@ private: float m_value; }; -bool calculated_style_value_contains_percentage(CalculatedStyleValue const&); - -template -class PercentageOr { -public: - PercentageOr(T t) - : m_value(move(t)) - { - } - - PercentageOr(Percentage percentage) - : m_value(move(percentage)) - { - } - - PercentageOr(NonnullRefPtr calculated) - : m_value(move(calculated)) - { - } - - virtual ~PercentageOr() = default; - - PercentageOr& operator=(T t) - { - m_value = move(t); - return *this; - } - - PercentageOr& operator=(Percentage percentage) - { - m_value = move(percentage); - return *this; - } - - bool is_percentage() const { return m_value.template has(); } - bool is_calculated() const { return m_value.template has>(); } - - bool contains_percentage() const - { - return m_value.visit( - [&](T const& t) { - if constexpr (requires { t.is_calculated(); }) { - if (t.is_calculated()) - return calculated_style_value_contains_percentage(*t.calculated_style_value()); - } - return false; - }, - [&](Percentage const&) { - return true; - }, - [&](NonnullRefPtr const& calculated) { - return calculated_style_value_contains_percentage(*calculated); - }); - } - - Percentage const& percentage() const - { - VERIFY(is_percentage()); - return m_value.template get(); - } - - NonnullRefPtr const& calculated() const - { - VERIFY(is_calculated()); - return m_value.template get>(); - } - - virtual T resolve_calculated(NonnullRefPtr const&, [[maybe_unused]] Layout::Node const&, [[maybe_unused]] T const& reference_value) const - { - VERIFY_NOT_REACHED(); - } - - T resolved(Layout::Node const& layout_node, T const& reference_value) const - { - return m_value.visit( - [&](T const& t) { - if constexpr (requires { t.is_calculated(); }) { - if (t.is_calculated()) - return resolve_calculated(t.calculated_style_value(), layout_node, reference_value); - } - - return t; - }, - [&](Percentage const& percentage) { - return reference_value.percentage_of(percentage); - }, - [&](NonnullRefPtr const& calculated) { - return resolve_calculated(calculated, layout_node, reference_value); - }); - } - - ErrorOr to_string() const - { - if (is_percentage()) - return m_value.template get().to_string(); - - return m_value.template get().to_string(); - } - - bool operator==(PercentageOr const& other) const - { - if (is_calculated()) - return false; - if (is_percentage() != other.is_percentage()) - return false; - if (is_percentage()) - return (m_value.template get() == other.m_value.template get()); - return (m_value.template get() == other.m_value.template get()); - } - -protected: - bool is_t() const { return m_value.template has(); } - T const& get_t() const { return m_value.template get(); } - -private: - Variant> m_value; -}; - -template -bool operator==(PercentageOr const& percentage_or, T const& t) -{ - return percentage_or == PercentageOr { t }; } - -template -bool operator==(T const& t, PercentageOr const& percentage_or) -{ - return t == percentage_or; -} - -template -bool operator==(PercentageOr const& percentage_or, Percentage const& percentage) -{ - return percentage_or == PercentageOr { percentage }; -} - -template -bool operator==(Percentage const& percentage, PercentageOr const& percentage_or) -{ - return percentage == percentage_or; -} - -class AnglePercentage : public PercentageOr { -public: - using PercentageOr::PercentageOr; - - bool is_angle() const { return is_t(); } - Angle const& angle() const { return get_t(); } - virtual Angle resolve_calculated(NonnullRefPtr const&, Layout::Node const&, Angle const& reference_value) const override; -}; - -class FrequencyPercentage : public PercentageOr { -public: - using PercentageOr::PercentageOr; - - bool is_frequency() const { return is_t(); } - Frequency const& frequency() const { return get_t(); } - virtual Frequency resolve_calculated(NonnullRefPtr const&, Layout::Node const&, Frequency const& reference_value) const override; -}; - -class LengthPercentage : public PercentageOr { -public: - using PercentageOr::PercentageOr; - - bool is_auto() const { return is_length() && length().is_auto(); } - - bool is_length() const { return is_t(); } - Length const& length() const { return get_t(); } - virtual Length resolve_calculated(NonnullRefPtr const&, Layout::Node const&, Length const& reference_value) const override; -}; - -class TimePercentage : public PercentageOr