Bug 1940938: Expand definition of Invalid overflow rect to be zero-sized rects that are offset from origin as well. r=layout-reviewers,TYLin a=RyanVM

`IsValidOverflowRect` was originally introduced to consider only zero-sized
rects that are located at origin to be invalid in Bug 1800907. However,
it doesn't make sense for a zero-sized rect located away from origin to
contribute to overflow.
This commit is contained in:
David Shin 2025-01-15 19:42:07 +00:00
parent 13231c2182
commit 12867126c7
2 changed files with 23 additions and 9 deletions

View file

@ -13,15 +13,11 @@
namespace mozilla {
static bool IsValidOverflowRect(const nsRect& aRect) {
// `IsEmpty` in the context of `nsRect` means "width OR height is zero."
// However, in the context of overflow, the rect having one axis as zero is
// NOT considered empty.
if (MOZ_LIKELY(!aRect.IsEmpty())) {
return true;
}
// Be defensive and consider rects with any negative size as invalid.
return !aRect.IsEqualEdges(nsRect()) && aRect.Width() >= 0 &&
// The reason we can't simply use `nsRect::IsEmpty` is that any one dimension
// being zero is considered empty by it - On the other hand, an overflow rect
// is valid if it has non-negative dimensions and at least one of them is
// non-zero.
return aRect.Size() != nsSize{0, 0} && aRect.Width() >= 0 &&
aRect.Height() >= 0;
}

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html class="reftest-wait">
<link rel="author" title="David Shin" href="dshin@mozilla.com">
<link rel="help" href="bugzilla.mozilla.org/show_bug.cgi?id=1940938">
<link rel="match" href="../reference/ref-filled-green-100px-square-only.html">
<p>Test passes if there is a filled green square.</p>
<div id="dut" style="overflow: hidden; height: 100px; width: 100px; background: red;">
<div style="width: 100px; height: 100px; background: green;"></div>
<div style="font-size: 200px;"><span>
</span></div>
</div>
<script>
onload = function () {
dut.scrollTop = 100;
document.documentElement.className = "";
}
</script>
</html>