Bug 1327095 - Shift the rootCompBounds to maximize overlap with the displayportBase before intersecting. r?tnikkel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 09 Jan 2017 11:14:45 -0500
changeset 457701 8bdf7761cb65b65ffee004fb233f540ca589b955
parent 457660 2977ca1224525680cbfb5c3ce3018818b6dfd8f2
child 541571 ff32906dba6bc602a76628b0d5c84d92dbd711e5
push id40872
push userkgupta@mozilla.com
push dateMon, 09 Jan 2017 18:33:48 +0000
reviewerstnikkel
bugs1327095
milestone53.0a1
Bug 1327095 - Shift the rootCompBounds to maximize overlap with the displayportBase before intersecting. r?tnikkel MozReview-Commit-ID: 457RfGOwRZU
layout/generic/nsGfxScrollFrame.cpp
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -3680,16 +3680,40 @@ ScrollFrameHelper::DecideScrollableLayer
               // an overflow:hidden document) it is not (see bug 1280013).
               // XXX: Eventually we may want to create a modified version of
               // TransformRect that includes the APZ callback transforms
               // directly.
               nsLayoutUtils::TransformRect(rootFrame, mOuter, rootCompBounds);
               rootCompBounds += CSSPoint::ToAppUnits(
                   nsLayoutUtils::GetCumulativeApzCallbackTransform(mOuter));
 
+              // We want to limit displayportBase to be no larger than rootCompBounds on
+              // either axis, but we don't want to just blindly intersect the two, because
+              // rootCompBounds might be offset from where displayportBase is (see bug
+              // 1327095 comment 8). Instead, we translate rootCompBounds so as to
+              // maximize the overlap with displayportBase, and *then* do the intersection.
+              if (rootCompBounds.x > displayportBase.x && rootCompBounds.XMost() > displayportBase.XMost()) {
+                // rootCompBounds is at a greater x-position for both left and right, so translate it such
+                // that the XMost() values are the same. This will line up the right edge of the two rects,
+                // and might mean that rootCompbounds.x is smaller than displayportBase.x. We can avoid that
+                // by taking the min of the x delta and XMost() delta, but it doesn't really matter because
+                // the intersection between the two rects below will end up the same.
+                rootCompBounds.x -= (rootCompBounds.XMost() - displayportBase.XMost());
+              } else if (rootCompBounds.x < displayportBase.x && rootCompBounds.XMost() < displayportBase.XMost()) {
+                // Analaogous code for when the rootCompBounds is at a smaller x-position.
+                rootCompBounds.x = displayportBase.x;
+              }
+              // Do the same for y-axis
+              if (rootCompBounds.y > displayportBase.y && rootCompBounds.YMost() > displayportBase.YMost()) {
+                rootCompBounds.y -= (rootCompBounds.YMost() - displayportBase.YMost());
+              } else if (rootCompBounds.y < displayportBase.y && rootCompBounds.YMost() < displayportBase.YMost()) {
+                rootCompBounds.y = displayportBase.y;
+              }
+
+              // Now we can do the intersection
               displayportBase = displayportBase.Intersect(rootCompBounds);
             }
           }
         }
 
         displayportBase -= mScrollPort.TopLeft();
       }