diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-30 15:33:37 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-30 21:29:50 +0200 |
commit | 7a1a97f153c2b005629a3b9643fa45822e237ef4 (patch) | |
tree | f1e84b14cf1a522bd203f83cac57d8569d8098f3 /Userland/Libraries/LibWeb/CSS | |
parent | fa90a3bb4fc3e4a8a0caa0b80a7ac87765ab67f9 (diff) | |
download | serenity-7a1a97f153c2b005629a3b9643fa45822e237ef4.zip |
LibWeb: Remove CalculatedStyleValue from Angle
...and replace it with AngleOrCalculated.
This has the nice bonus effect of actually handling `calc()` for angles
in a transform function. :^) (Previously we just would have asserted.)
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Angle.cpp | 25 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Angle.h | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ComputedValues.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 1 |
5 files changed, 7 insertions, 35 deletions
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 <atkinssj@serenityos.org> + * Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #include "Angle.h" #include <AK/Math.h> -#include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/Percentage.h> namespace Web::CSS { @@ -22,13 +22,6 @@ Angle::Angle(float value, Type type) { } -Angle Angle::make_calculated(NonnullRefPtr<CalculatedStyleValue> 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<String> 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::Type> Angle::unit_from_name(StringView name) return {}; } -NonnullRefPtr<CalculatedStyleValue> 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 <atkinssj@serenityos.org> + * Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include <AK/RefPtr.h> #include <AK/String.h> #include <LibWeb/Forward.h> @@ -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<CalculatedStyleValue>); static Angle make_degrees(float); Angle percentage_of(Percentage const&) const; - bool is_calculated() const { return m_type == Type::Calculated; } - NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const; - ErrorOr<String> 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<CalculatedStyleValue> 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<CSS::Angle, CSS::LengthPercentage, float>; +using TransformValue = Variant<CSS::AngleOrCalculated, CSS::LengthPercentage, float>; 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 <LibWeb/CSS/CSSStyleRule.h> #include <LibWeb/CSS/CSSStyleSheet.h> #include <LibWeb/CSS/CSSSupportsRule.h> +#include <LibWeb/CSS/CalculatedOr.h> #include <LibWeb/CSS/MediaList.h> #include <LibWeb/CSS/Parser/Block.h> #include <LibWeb/CSS/Parser/ComponentValue.h> @@ -5780,7 +5781,7 @@ RefPtr<StyleValue> Parser::parse_transform_value(Vector<ComponentValue> const& c case TransformFunctionParameterType::Angle: { // These are `<angle> | <zero>` 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 <AK/WeakPtr.h> #include <LibGfx/Painter.h> #include <LibWeb/CSS/Angle.h> +#include <LibWeb/CSS/CalculatedOr.h> #include <LibWeb/CSS/Enums.h> #include <LibWeb/CSS/Frequency.h> #include <LibWeb/CSS/Length.h> |