mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Add Angle::from_style_value
This method takes a `AngleStyleValue`, `PercentageStyleValue` or fully-simplified `CalculatedStyleValue` with a numeric type of angle, as well as a percentage basis and produces the equivalent `Angle` value. This saves us having to reimplement this logic in multiple places
This commit is contained in:
parent
2f0cd9f739
commit
b262902b02
Notes:
github-actions[bot]
2025-11-23 08:45:00 +00:00
Author: https://github.com/Calme1709
Commit: b262902b02
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6854
Reviewed-by: https://github.com/gmta ✅
2 changed files with 27 additions and 0 deletions
|
|
@ -8,7 +8,9 @@
|
|||
#include <LibWeb/CSS/Angle.h>
|
||||
#include <LibWeb/CSS/Percentage.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
|
@ -56,6 +58,30 @@ double Angle::to_radians() const
|
|||
return ratio_between_units(m_unit, AngleUnit::Rad) * m_value;
|
||||
}
|
||||
|
||||
Angle Angle::from_style_value(NonnullRefPtr<StyleValue const> const& style_value, Optional<Angle> percentage_basis)
|
||||
{
|
||||
if (style_value->is_angle())
|
||||
return style_value->as_angle().angle();
|
||||
|
||||
if (style_value->is_calculated()) {
|
||||
CalculationResolutionContext::PercentageBasis resolved_percentage_basis;
|
||||
|
||||
if (percentage_basis.has_value()) {
|
||||
resolved_percentage_basis = percentage_basis.value();
|
||||
}
|
||||
|
||||
return style_value->as_calculated().resolve_angle({ .percentage_basis = resolved_percentage_basis }).value();
|
||||
}
|
||||
|
||||
if (style_value->is_percentage()) {
|
||||
VERIFY(percentage_basis.has_value());
|
||||
|
||||
return percentage_basis.value().percentage_of(style_value->as_percentage().percentage());
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Angle Angle::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Angle const& reference_value)
|
||||
{
|
||||
CalculationResolutionContext context {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static Angle from_style_value(NonnullRefPtr<StyleValue const> const&, Optional<Angle> percentage_basis);
|
||||
static Angle resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, Layout::Node const&, Angle const& reference_value);
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue