mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Avoid division by zero with small aspect ratios
This commit is contained in:
parent
cd0074528e
commit
5478361ba0
|
|
@ -1609,6 +1609,8 @@ CSSPixels FormattingContext::calculate_inner_width(Layout::Box const& box, Avail
|
|||
CSSPixels FormattingContext::calculate_inner_height(Box const& box, AvailableSpace const& available_space, CSS::Size const& height) const
|
||||
{
|
||||
if (height.is_auto() && box.has_preferred_aspect_ratio()) {
|
||||
if (*box.preferred_aspect_ratio() == 0)
|
||||
return CSSPixels(0);
|
||||
return m_state.get(box).content_width() / *box.preferred_aspect_ratio();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -604,7 +604,7 @@ void LayoutState::UsedValues::set_node(NodeWithStyle& node, UsedValues const* co
|
|||
if (m_has_definite_width && m_has_definite_height) {
|
||||
// Both width and height are definite.
|
||||
} else if (m_has_definite_width) {
|
||||
m_content_height = clamp_to_max_dimension_value(m_content_width / *aspect_ratio);
|
||||
m_content_height = *aspect_ratio == 0 ? 0 : clamp_to_max_dimension_value(m_content_width / *aspect_ratio);
|
||||
m_has_definite_height = true;
|
||||
} else if (m_has_definite_height) {
|
||||
m_content_width = clamp_to_max_dimension_value(m_content_height * *aspect_ratio);
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
element height: 10px
|
||||
element height: 0px
|
||||
element height: 0px
|
||||
|
|
|
|||
|
|
@ -2,11 +2,18 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const element = document.createElement("div");
|
||||
element.style.width = "100px";
|
||||
element.style.aspectRatio = ".0000000000001 / .00000000000001";
|
||||
document.body.appendChild(element);
|
||||
println(`element height: ${element.clientHeight}px`);
|
||||
element.remove();
|
||||
const smallAspectRatios = [
|
||||
".0000000000001 / .00000000000001",
|
||||
"1/0.00000000000001",
|
||||
"0.00000000000001/1",
|
||||
];
|
||||
for (const ratio of smallAspectRatios) {
|
||||
const element = document.createElement("div");
|
||||
element.style.width = "100px";
|
||||
element.style.aspectRatio = ratio;
|
||||
document.body.appendChild(element);
|
||||
println(`element height: ${element.clientHeight}px`);
|
||||
element.remove();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user