diff --git a/Userland/Libraries/LibWeb/CSS/Angle.cpp b/Userland/Libraries/LibWeb/CSS/Angle.cpp index ea07b52aad..36575de260 100644 --- a/Userland/Libraries/LibWeb/CSS/Angle.cpp +++ b/Userland/Libraries/LibWeb/CSS/Angle.cpp @@ -1,12 +1,12 @@ /* - * Copyright (c) 2022, Sam Atkins + * Copyright (c) 2022-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #include "Angle.h" #include -#include +#include namespace Web::CSS { @@ -22,13 +22,6 @@ Angle::Angle(float value, Type type) { } -Angle Angle::make_calculated(NonnullRefPtr calculated_style_value) -{ - Angle angle { 0, Type::Calculated }; - angle.m_calculated_style = move(calculated_style_value); - return angle; -} - Angle Angle::make_degrees(float value) { return { value, Type::Deg }; @@ -36,23 +29,17 @@ Angle Angle::make_degrees(float value) Angle Angle::percentage_of(Percentage const& percentage) const { - VERIFY(!is_calculated()); - return Angle { percentage.as_fraction() * m_value, m_type }; } ErrorOr Angle::to_string() const { - if (is_calculated()) - return m_calculated_style->to_string(); return String::formatted("{}{}", m_value, unit_name()); } float Angle::to_degrees() const { switch (m_type) { - case Type::Calculated: - return m_calculated_style->resolve_angle()->to_degrees(); case Type::Deg: return m_value; case Type::Grad: @@ -68,8 +55,6 @@ float Angle::to_degrees() const StringView Angle::unit_name() const { switch (m_type) { - case Type::Calculated: - return "calculated"sv; case Type::Deg: return "deg"sv; case Type::Grad: @@ -99,10 +84,4 @@ Optional Angle::unit_from_name(StringView name) return {}; } -NonnullRefPtr Angle::calculated_style_value() const -{ - VERIFY(!m_calculated_style.is_null()); - return *m_calculated_style; -} - } diff --git a/Userland/Libraries/LibWeb/CSS/Angle.h b/Userland/Libraries/LibWeb/CSS/Angle.h index 4e80353a9b..740110ba76 100644 --- a/Userland/Libraries/LibWeb/CSS/Angle.h +++ b/Userland/Libraries/LibWeb/CSS/Angle.h @@ -1,12 +1,11 @@ /* - * Copyright (c) 2022, Sam Atkins + * Copyright (c) 2022-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include #include #include @@ -15,7 +14,6 @@ namespace Web::CSS { class Angle { public: enum class Type { - Calculated, Deg, Grad, Rad, @@ -26,20 +24,14 @@ public: Angle(int value, Type type); Angle(float value, Type type); - static Angle make_calculated(NonnullRefPtr); static Angle make_degrees(float); Angle percentage_of(Percentage const&) const; - bool is_calculated() const { return m_type == Type::Calculated; } - NonnullRefPtr calculated_style_value() const; - ErrorOr to_string() const; float to_degrees() const; bool operator==(Angle const& other) const { - if (is_calculated()) - return m_calculated_style == other.m_calculated_style; return m_type == other.m_type && m_value == other.m_value; } @@ -48,7 +40,6 @@ private: Type m_type; float m_value { 0 }; - RefPtr m_calculated_style; }; } diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 84cf817e04..ffd41cce0d 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -105,7 +105,7 @@ public: float width { 0 }; }; -using TransformValue = Variant; +using TransformValue = Variant; struct Transformation { CSS::TransformFunction function; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 2651908389..b2bdd7963a 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -5780,7 +5781,7 @@ RefPtr Parser::parse_transform_value(Vector const& c case TransformFunctionParameterType::Angle: { // These are ` | ` in the spec, so we have to check for both kinds. if (maybe_calc_value && maybe_calc_value->resolves_to_angle()) { - values.append(AngleStyleValue::create(Angle::make_calculated(maybe_calc_value.release_nonnull()))); + values.append(maybe_calc_value.release_nonnull()); } else if (value.is(Token::Type::Number) && value.token().number_value() == 0) { values.append(AngleStyleValue::create(Angle::make_degrees(0))); } else { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 181c3cc777..f9c4d036e5 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index 6de5fcfa01..6820157b14 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -239,8 +239,8 @@ Gfx::FloatMatrix4x4 StackingContext::get_transformation_matrix(CSS::Transformati return value.length().to_px(m_box).value(); }, - [](CSS::Angle const& value) { - return value.to_degrees() * static_cast(M_DEG2RAD); + [this](CSS::AngleOrCalculated const& value) { + return value.resolved(m_box).to_degrees() * static_cast(M_DEG2RAD); }, [](float value) { return value;