Bug 1311270 - Part 6. Handle mask-origin. draft
authorcku <cku@mozilla.com>
Thu, 24 Nov 2016 02:52:44 +0800
changeset 453292 d9925011bd36dc82dccdb9ffb8fdcb7c085ccc33
parent 453291 bfd590b7897c7b1eebda7b642afcdd0bddb3faea
child 453293 cad013dabea9af3f5636f894f867ff913d004cce
push id39618
push userbmo:cku@mozilla.com
push dateFri, 23 Dec 2016 04:25:44 +0000
bugs1311270
milestone53.0a1
Bug 1311270 - Part 6. Handle mask-origin. MozReview-Commit-ID: EGuK4TIy7wp
layout/painting/nsCSSRendering.cpp
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -3463,26 +3463,41 @@ nsCSSRendering::ComputeImageLayerPositio
                                                  const nsStyleImageLayers::Layer& aLayer,
                                                  nsIFrame** aAttachedToFrame,
                                                  bool* aOutIsTransformedFixed)
 {
   // Compute background origin area relative to aBorderArea now as we may need
   // it to compute the effective image size for a CSS gradient.
   nsRect bgPositioningArea;
 
-  StyleGeometryBox backgroundOrigin = aLayer.mOrigin;
-
-  // XXX TODO: bug 1303623 only implements the parser of fill-box|stroke-box|view-box|no-clip.
-  // So we need to fallback to default value when rendering. We should remove this
-  // in bug 1311270.
-  if (backgroundOrigin == StyleGeometryBox::Fill ||
-      backgroundOrigin == StyleGeometryBox::Stroke ||
-      backgroundOrigin == StyleGeometryBox::View) {
-    backgroundOrigin = StyleGeometryBox::Border;
-  }
+  StyleGeometryBox backgroundOrigin =
+    ComputeBoxValue(aForFrame, aLayer.mOrigin);
+
+  if (IsSVGStyleGeometryBox(backgroundOrigin)) {
+    MOZ_ASSERT(aForFrame->IsFrameOfType(nsIFrame::eSVG) &&
+               (aForFrame->GetType() != nsGkAtoms::svgOuterSVGFrame));
+    *aAttachedToFrame = aForFrame;
+
+    bgPositioningArea =
+      nsLayoutUtils::ComputeGeometryBox(aForFrame, backgroundOrigin);
+
+    nsPoint toStrokeBoxOffset = nsPoint(0, 0);
+    if (backgroundOrigin != StyleGeometryBox::Stroke) {
+      nsRect strokeBox =
+        nsLayoutUtils::ComputeGeometryBox(aForFrame,
+                                          StyleGeometryBox::Stroke);
+      toStrokeBoxOffset = bgPositioningArea.TopLeft() - strokeBox.TopLeft();
+    }
+
+    // For SVG frames, the return value is relative to the stroke box
+    return nsRect(toStrokeBoxOffset, bgPositioningArea.Size());
+  }
+
+  MOZ_ASSERT(!aForFrame->IsFrameOfType(nsIFrame::eSVG) ||
+             aForFrame->GetType() == nsGkAtoms::svgOuterSVGFrame);
 
   nsIAtom* frameType = aForFrame->GetType();
   nsIFrame* geometryFrame = aForFrame;
   if (MOZ_UNLIKELY(frameType == nsGkAtoms::scrollFrame &&
                    NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL == aLayer.mAttachment)) {
     nsIScrollableFrame* scrollableFrame = do_QueryFrame(aForFrame);
     bgPositioningArea = nsRect(
       scrollableFrame->GetScrolledFrame()->GetPosition()
@@ -3518,19 +3533,16 @@ nsCSSRendering::ComputeImageLayerPositio
       bgPositioningArea = geometryFrame->GetRect();
     }
   } else {
     bgPositioningArea = nsRect(nsPoint(0,0), aBorderArea.Size());
   }
 
   // Background images are tiled over the 'background-clip' area
   // but the origin of the tiling is based on the 'background-origin' area
-  // XXX: Bug 1303623 will bring in new origin value, we should iterate from
-  // StyleGeometryBox::Margin instead of
-  // StyleGeometryBox::Border.
   if (backgroundOrigin != StyleGeometryBox::Border && geometryFrame) {
     nsMargin border = geometryFrame->GetUsedBorder();
     if (backgroundOrigin != StyleGeometryBox::Padding) {
       border += geometryFrame->GetUsedPadding();
       NS_ASSERTION(backgroundOrigin == StyleGeometryBox::Content,
                    "unknown background-origin value");
     }
     bgPositioningArea.Deflate(border);