1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

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.)
This commit is contained in:
Sam Atkins 2023-03-30 15:33:37 +01:00 committed by Andreas Kling
parent fa90a3bb4f
commit 7a1a97f153
6 changed files with 9 additions and 37 deletions

View file

@ -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;
}
}