diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 7c054dba37f..059fa781716 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -88,6 +88,7 @@ set(SOURCES CSS/StyleValues/LengthStyleValue.cpp CSS/StyleValues/LinearGradientStyleValue.cpp CSS/StyleValues/ListStyleStyleValue.cpp + CSS/StyleValues/NumericStyleValue.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 f8cc2e04c26..928cb1015f2 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -56,6 +56,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 d126a21e41a..9ecd03486ac 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -25,6 +25,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 ef52ef8d10e..3f8c4852c32 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -40,6 +40,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 f2a59c3be6a..265277e3ad4 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -1136,14 +1137,6 @@ ErrorOr PositionValue::serialize(StringBuilder& builder) const return {}; } -ErrorOr NumericStyleValue::to_string() const -{ - return m_value.visit( - [](auto value) { - return String::formatted("{}", value); - }); -} - ErrorOr OverflowStyleValue::to_string() const { return String::formatted("{} {}", TRY(m_properties.overflow_x->to_string()), TRY(m_properties.overflow_y->to_string())); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index f89379ef86d..fca52733ec5 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -627,46 +627,6 @@ private: NonnullOwnPtr m_expression; }; -class NumericStyleValue : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create_float(float value) - { - return adopt_ref(*new NumericStyleValue(value)); - } - - static ValueComparingNonnullRefPtr create_integer(i64 value) - { - return adopt_ref(*new NumericStyleValue(value)); - } - - virtual bool has_length() const override { return to_number() == 0; } - virtual Length to_length() const override { return Length::make_px(0); } - - virtual bool has_number() const override { return true; } - virtual float to_number() const override - { - return m_value.visit( - [](float value) { return value; }, - [](i64 value) { return (float)value; }); - } - - virtual bool has_integer() const override { return m_value.has(); } - virtual float to_integer() const override { return m_value.get(); } - - virtual ErrorOr to_string() const override; - - bool properties_equal(NumericStyleValue const& other) const { return m_value == other.m_value; } - -private: - explicit NumericStyleValue(Variant value) - : StyleValueWithDefaultOperators(Type::Numeric) - , m_value(move(value)) - { - } - - Variant m_value { (i64)0 }; -}; - class OverflowStyleValue final : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr overflow_x, ValueComparingNonnullRefPtr overflow_y) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.cpp new file mode 100644 index 00000000000..b6a2fbf7d78 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.cpp @@ -0,0 +1,22 @@ +/* + * 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 "NumericStyleValue.h" + +namespace Web::CSS { + +ErrorOr NumericStyleValue::to_string() const +{ + return m_value.visit( + [](auto value) { + return String::formatted("{}", value); + }); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.h new file mode 100644 index 00000000000..268b91eddcb --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.h @@ -0,0 +1,56 @@ +/* + * 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 NumericStyleValue : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create_float(float value) + { + return adopt_ref(*new NumericStyleValue(value)); + } + + static ValueComparingNonnullRefPtr create_integer(i64 value) + { + return adopt_ref(*new NumericStyleValue(value)); + } + + virtual bool has_length() const override { return to_number() == 0; } + virtual Length to_length() const override { return Length::make_px(0); } + + virtual bool has_number() const override { return true; } + virtual float to_number() const override + { + return m_value.visit( + [](float value) { return value; }, + [](i64 value) { return (float)value; }); + } + + virtual bool has_integer() const override { return m_value.has(); } + virtual float to_integer() const override { return m_value.get(); } + + virtual ErrorOr to_string() const override; + + bool properties_equal(NumericStyleValue const& other) const { return m_value == other.m_value; } + +private: + explicit NumericStyleValue(Variant value) + : StyleValueWithDefaultOperators(Type::Numeric) + , m_value(move(value)) + { + } + + Variant m_value { (i64)0 }; +}; + +}