Bug 1261062 - When constraining the displayport by the max texture size, maintain the relative distribution of the margins. r=dvander, a=ritu
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 01 Apr 2016 08:03:28 -0400
changeset 323808 b8a888b7858ac9dd12c06875f0803bf82d196d25
parent 323807 e747410012445c980fd18e9b323c475d11ee2ea6
child 323809 f80143d36adf669258f4047b12015e76f27b55fd
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander, ritu
bugs1261062
milestone47.0a2
Bug 1261062 - When constraining the displayport by the max texture size, maintain the relative distribution of the margins. r=dvander, a=ritu MozReview-Commit-ID: GsQBy0rIlP5
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -991,27 +991,29 @@ GetDisplayPortFromMarginsData(nsIContent
       MAX_ALIGN_ROUNDING * alignment.width;
     int32_t maxHeightScreenPx = floor(double(maxSizeDevPx) * res.yScale) -
       MAX_ALIGN_ROUNDING * alignment.height;
 
     // For each axis, inflate the margins up to the maximum size.
     const ScreenMargin& margins = aMarginsData->mMargins;
     if (screenRect.height < maxHeightScreenPx) {
       int32_t budget = maxHeightScreenPx - screenRect.height;
-
-      float top = std::min(margins.top, float(budget));
-      float bottom = std::min(margins.bottom, budget - top);
+      // Scale the margins down to fit into the budget if necessary, maintaining
+      // their relative ratio.
+      float scale = std::min(1.0f, float(budget) / margins.TopBottom());
+      float top = margins.top * scale;
+      float bottom = margins.bottom * scale;
       screenRect.y -= top;
       screenRect.height += top + bottom;
     }
     if (screenRect.width < maxWidthScreenPx) {
       int32_t budget = maxWidthScreenPx - screenRect.width;
-
-      float left = std::min(margins.left, float(budget));
-      float right = std::min(margins.right, budget - left);
+      float scale = std::min(1.0f, float(budget) / margins.LeftRight());
+      float left = margins.left * scale;
+      float right = margins.right * scale;
       screenRect.x -= left;
       screenRect.width += left + right;
     }
   }
 
   ScreenPoint scrollPosScreen = LayoutDevicePoint::FromAppUnits(scrollPos, auPerDevPixel)
                               * res;