mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:27:45 +00:00
LibWeb+WebContent: Forbid access to underlying type of CSSPixels
Although DistinctNumeric, which is supposed to abstract the underlying type, was used to represent CSSPixels, we have a whole bunch of places in the layout code that assume CSSPixels::value() returns a floating-point type. This assumption makes it difficult to replace the underlying type in CSSPixels with a non-floating type. To make it easier to transition CSSPixels to fixed-point math, one step we can take is to prevent access to the underlying type using value() and instead use explicit conversions with the to_float(), to_double(), and to_int() methods.
This commit is contained in:
parent
5a54c686a7
commit
147c3b3d97
43 changed files with 340 additions and 220 deletions
|
@ -30,7 +30,7 @@ static double resolve_value(CalculatedStyleValue::CalculationResult::Value value
|
|||
[](Number const& number) { return number.value(); },
|
||||
[](Angle const& angle) { return angle.to_degrees(); },
|
||||
[](Frequency const& frequency) { return frequency.to_hertz(); },
|
||||
[&context](Length const& length) { return length.to_px(*context).value(); },
|
||||
[&context](Length const& length) { return length.to_px(*context).to_double(); },
|
||||
[](Percentage const& percentage) { return percentage.value(); },
|
||||
[](Time const& time) { return time.to_seconds(); });
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ float Filter::Blur::resolved_radius(Layout::Node const& node) const
|
|||
// Default value when omitted is 0px.
|
||||
auto sigma = 0;
|
||||
if (radius.has_value())
|
||||
sigma = radius->to_px(node).value();
|
||||
sigma = radius->to_px(node).to_int();
|
||||
// Note: The radius/sigma of the blur needs to be doubled for LibGfx's blur functions.
|
||||
return sigma * 2;
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ Filter::DropShadow::Resolved Filter::DropShadow::resolved(Layout::Node const& no
|
|||
// The default value for omitted values is missing length values set to 0
|
||||
// and the missing used color is taken from the color property.
|
||||
return Resolved {
|
||||
offset_x.to_px(node).value(),
|
||||
offset_y.to_px(node).value(),
|
||||
radius.has_value() ? radius->to_px(node).value() : 0.0,
|
||||
offset_x.to_px(node).to_double(),
|
||||
offset_y.to_px(node).to_double(),
|
||||
radius.has_value() ? radius->to_px(node).to_double() : 0.0,
|
||||
color.has_value() ? *color : node.computed_values().color()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ bool LinearGradientStyleValue::equals(StyleValue const& other_) const
|
|||
float LinearGradientStyleValue::angle_degrees(CSSPixelSize gradient_size) const
|
||||
{
|
||||
auto corner_angle_degrees = [&] {
|
||||
return atan2(gradient_size.height().value(), gradient_size.width().value()) * 180 / AK::Pi<double>;
|
||||
return atan2(gradient_size.height().to_double(), gradient_size.width().to_double()) * 180 / AK::Pi<double>;
|
||||
};
|
||||
return m_properties.direction.visit(
|
||||
[&](SideOrCorner side_or_corner) {
|
||||
|
|
|
@ -146,12 +146,12 @@ Gfx::FloatSize RadialGradientStyleValue::resolve_size(Layout::Node const& node,
|
|||
},
|
||||
[&](CircleSize const& circle_size) {
|
||||
auto radius = circle_size.radius.to_px(node);
|
||||
return Gfx::FloatSize { radius.value(), radius.value() };
|
||||
return Gfx::FloatSize { radius.to_float(), radius.to_float() };
|
||||
},
|
||||
[&](EllipseSize const& ellipse_size) {
|
||||
auto radius_a = ellipse_size.radius_a.resolved(node, CSS::Length::make_px(size.width())).to_px(node);
|
||||
auto radius_b = ellipse_size.radius_b.resolved(node, CSS::Length::make_px(size.height())).to_px(node);
|
||||
return Gfx::FloatSize { radius_a.value(), radius_b.value() };
|
||||
return Gfx::FloatSize { radius_a.to_float(), radius_b.to_float() };
|
||||
});
|
||||
|
||||
// Handle degenerate cases
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue