mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:17:35 +00:00
LibWeb: Avoid conversion from floating point in CSS position resolution
We can just use division here, since fixed-point division by 2 will compile down to a shift by 1.
This commit is contained in:
parent
99c90e49b6
commit
f57c42fad7
1 changed files with 20 additions and 24 deletions
|
@ -15,36 +15,32 @@ CSSPixelPoint PositionValue::resolved(Layout::Node const& node, CSSPixelRect con
|
||||||
// Note: A preset + a none default x/y_relative_to is impossible in the syntax (and makes little sense)
|
// Note: A preset + a none default x/y_relative_to is impossible in the syntax (and makes little sense)
|
||||||
CSSPixels x = horizontal_position.visit(
|
CSSPixels x = horizontal_position.visit(
|
||||||
[&](HorizontalPreset preset) -> CSSPixels {
|
[&](HorizontalPreset preset) -> CSSPixels {
|
||||||
return rect.width() * [&] {
|
switch (preset) {
|
||||||
switch (preset) {
|
case HorizontalPreset::Left:
|
||||||
case HorizontalPreset::Left:
|
return 0;
|
||||||
return CSSPixels(0.0);
|
case HorizontalPreset::Center:
|
||||||
case HorizontalPreset::Center:
|
return rect.width() / 2;
|
||||||
return CSSPixels(0.5);
|
case HorizontalPreset::Right:
|
||||||
case HorizontalPreset::Right:
|
return rect.width();
|
||||||
return CSSPixels(1.0);
|
default:
|
||||||
default:
|
VERIFY_NOT_REACHED();
|
||||||
VERIFY_NOT_REACHED();
|
}
|
||||||
}
|
|
||||||
}();
|
|
||||||
},
|
},
|
||||||
[&](LengthPercentage length_percentage) -> CSSPixels {
|
[&](LengthPercentage length_percentage) -> CSSPixels {
|
||||||
return length_percentage.to_px(node, rect.width());
|
return length_percentage.to_px(node, rect.width());
|
||||||
});
|
});
|
||||||
CSSPixels y = vertical_position.visit(
|
CSSPixels y = vertical_position.visit(
|
||||||
[&](VerticalPreset preset) -> CSSPixels {
|
[&](VerticalPreset preset) -> CSSPixels {
|
||||||
return rect.height() * [&] {
|
switch (preset) {
|
||||||
switch (preset) {
|
case VerticalPreset::Top:
|
||||||
case VerticalPreset::Top:
|
return 0;
|
||||||
return CSSPixels(0.0);
|
case VerticalPreset::Center:
|
||||||
case VerticalPreset::Center:
|
return rect.height() / 2;
|
||||||
return CSSPixels(0.5);
|
case VerticalPreset::Bottom:
|
||||||
case VerticalPreset::Bottom:
|
return rect.height();
|
||||||
return CSSPixels(1.0);
|
default:
|
||||||
default:
|
VERIFY_NOT_REACHED();
|
||||||
VERIFY_NOT_REACHED();
|
}
|
||||||
}
|
|
||||||
}();
|
|
||||||
},
|
},
|
||||||
[&](LengthPercentage length_percentage) -> CSSPixels {
|
[&](LengthPercentage length_percentage) -> CSSPixels {
|
||||||
return length_percentage.to_px(node, rect.height());
|
return length_percentage.to_px(node, rect.height());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue