Bug 1754323 - Ensure safe-area calculations aren't too off. r=m_kato a=pascalc
The fix here is the EnsureAtMost call, but we can simplify a bit of the
related code by replacing the four conditionals with an
EnsureAtLeast call too, and using Deflate() rather than the manual
calculations.
This is sort of a wall paper over
bug 1754323, but should be safe and
prevents ridiculously big safe areas.
Differential Revision:
https://phabricator.services.mozilla.com/D138453
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -10484,40 +10484,44 @@ ScreenIntMargin nsContentUtils::GetWindo
int32_t screenLeft, screenTop, screenWidth, screenHeight;
nsresult rv =
aScreen->GetRect(&screenLeft, &screenTop, &screenWidth, &screenHeight);
if (NS_WARN_IF(NS_FAILED(rv))) {
return windowSafeAreaInsets;
}
- // Screen's rect of safe area
- LayoutDeviceIntRect safeAreaRect(
- screenLeft + aSafeAreaInsets.left, screenTop + aSafeAreaInsets.top,
- screenWidth - aSafeAreaInsets.right - aSafeAreaInsets.left,
- screenHeight - aSafeAreaInsets.bottom - aSafeAreaInsets.top);
+ const ScreenIntRect screenRect(screenLeft, screenTop, screenWidth,
+ screenHeight);
+
+ ScreenIntRect safeAreaRect = screenRect;
+ safeAreaRect.Deflate(aSafeAreaInsets);
+
+ ScreenIntRect windowRect = ViewAs<ScreenPixel>(
+ aWindowRect, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
+
+ // FIXME(bug 1754323): This can trigger because the screen rect is not
+ // orientation-aware.
+ // MOZ_ASSERT(screenRect.Contains(windowRect),
+ // "Screen doesn't contain window rect? Something seems off");
+
// window's rect of safe area
- safeAreaRect = safeAreaRect.Intersect(aWindowRect);
-
- windowSafeAreaInsets.top =
- aSafeAreaInsets.top ? std::max(safeAreaRect.y - aWindowRect.y, 0) : 0;
- windowSafeAreaInsets.left =
- aSafeAreaInsets.left ? std::max(safeAreaRect.x - aWindowRect.x, 0) : 0;
+ safeAreaRect = safeAreaRect.Intersect(windowRect);
+
+ windowSafeAreaInsets.top = safeAreaRect.y - aWindowRect.y;
+ windowSafeAreaInsets.left = safeAreaRect.x - aWindowRect.x;
windowSafeAreaInsets.right =
- aSafeAreaInsets.right
- ? std::max((aWindowRect.x + aWindowRect.width) -
- (safeAreaRect.x + safeAreaRect.width),
- 0)
- : 0;
- windowSafeAreaInsets.bottom =
- aSafeAreaInsets.bottom
- ? std::max(aWindowRect.y + aWindowRect.height -
- (safeAreaRect.y + safeAreaRect.height),
- 0)
- : 0;
+ aWindowRect.x + aWindowRect.width - (safeAreaRect.x + safeAreaRect.width);
+ windowSafeAreaInsets.bottom = aWindowRect.y + aWindowRect.height -
+ (safeAreaRect.y + safeAreaRect.height);
+
+ windowSafeAreaInsets.EnsureAtLeast(ScreenIntMargin());
+ // This shouldn't be needed, but it wallpapers orientation issues, see bug
+ // 1754323.
+ windowSafeAreaInsets.EnsureAtMost(aSafeAreaInsets);
return windowSafeAreaInsets;
}
/* static */
nsContentUtils::SubresourceCacheValidationInfo
nsContentUtils::GetSubresourceCacheValidationInfo(nsIRequest* aRequest,
nsIURI* aURI) {