Bug 1311270 - Part 6. Handle mask-origin. draft
authorcku <cku@mozilla.com>
Thu, 24 Nov 2016 02:52:44 +0800
changeset 445795 076d298f361a9f3eede7924e10fdbbda234bbe57
parent 445794 f51ece633f96b01989276dd1bbab04a08f573534
child 445796 4b448f086ad0825e46bb4be82aecfbe889d00466
push id37609
push userbmo:cku@mozilla.com
push dateWed, 30 Nov 2016 08:03:11 +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
@@ -3467,26 +3467,37 @@ 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);
+    nsRect strokeBox =
+      nsLayoutUtils::ComputeGeometryBox(aForFrame,
+                                        StyleGeometryBox::Stroke);
+    nsPoint toStrokeBoxOffset =
+      bgPositioningArea.TopLeft() - strokeBox.TopLeft();
+
+    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()
@@ -3522,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);