Bug 1277788 - Part 1. Set initial value of mask-position as center. r=dbaron. draft
authorcku <cku@mozilla.com>
Wed, 10 Aug 2016 16:10:45 +0800
changeset 399184 01b05533f5c791da0987af81d5cca276ec36e3f0
parent 399183 cbdee926460d0e402778da74c97937a067ebe94d
child 399185 8e9d78e537a5af4f51294de701faa97b35c15b66
push id25749
push userbmo:cku@mozilla.com
push dateWed, 10 Aug 2016 15:22:17 +0000
reviewersdbaron
bugs1277788
milestone51.0a1
Bug 1277788 - Part 1. Set initial value of mask-position as center. r=dbaron. MozReview-Commit-ID: BflQ6tz8ZjM
layout/style/nsCSSParser.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -12078,38 +12078,43 @@ CSSParserImpl::ParseImageLayersItem(
   // Fill in the values that the shorthand will set if we don't find
   // other values.
   aState.mImage->mValue.SetNoneValue();
   aState.mAttachment->mValue.SetIntValue(NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL,
                                          eCSSUnit_Enumerated);
   aState.mClip->mValue.SetIntValue(NS_STYLE_IMAGELAYER_CLIP_BORDER,
                                    eCSSUnit_Enumerated);
 
-
-
+  aState.mRepeat->mXValue.SetIntValue(NS_STYLE_IMAGELAYER_REPEAT_REPEAT,
+                                      eCSSUnit_Enumerated);
+  aState.mRepeat->mYValue.Reset();
+
+  RefPtr<nsCSSValue::Array> positionXArr = nsCSSValue::Array::Create(2);
+  RefPtr<nsCSSValue::Array> positionYArr = nsCSSValue::Array::Create(2);
+  aState.mPositionX->mValue.SetArrayValue(positionXArr, eCSSUnit_Array);
+  aState.mPositionY->mValue.SetArrayValue(positionYArr, eCSSUnit_Array);
 
   if (eCSSProperty_mask == aTable[nsStyleImageLayers::shorthand]) {
     aState.mOrigin->mValue.SetIntValue(NS_STYLE_IMAGELAYER_ORIGIN_BORDER,
                                        eCSSUnit_Enumerated);
     aState.mRepeat->mXValue.SetIntValue(NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT,
                                         eCSSUnit_Enumerated);
+
+    positionXArr->Item(1).SetPercentValue(0.5f);
+    positionYArr->Item(1).SetPercentValue(0.5f);
   } else {
     aState.mOrigin->mValue.SetIntValue(NS_STYLE_IMAGELAYER_ORIGIN_PADDING,
                                        eCSSUnit_Enumerated);
     aState.mRepeat->mXValue.SetIntValue(NS_STYLE_IMAGELAYER_REPEAT_REPEAT,
                                         eCSSUnit_Enumerated);
-  }
-  aState.mRepeat->mYValue.Reset();
-
-  RefPtr<nsCSSValue::Array> positionXArr = nsCSSValue::Array::Create(2);
-  RefPtr<nsCSSValue::Array> positionYArr = nsCSSValue::Array::Create(2);
-  aState.mPositionX->mValue.SetArrayValue(positionXArr, eCSSUnit_Array);
-  aState.mPositionY->mValue.SetArrayValue(positionYArr, eCSSUnit_Array);
-  positionXArr->Item(1).SetPercentValue(0.0f);
-  positionYArr->Item(1).SetPercentValue(0.0f);
+
+    positionXArr->Item(1).SetPercentValue(0.0f);
+    positionYArr->Item(1).SetPercentValue(0.0f);
+  }
+
   aState.mSize->mXValue.SetAutoValue();
   aState.mSize->mYValue.SetAutoValue();
   aState.mComposite->mValue.SetIntValue(NS_STYLE_MASK_COMPOSITE_ADD,
                                         eCSSUnit_Enumerated);
   aState.mMode->mValue.SetIntValue(NS_STYLE_MASK_MODE_MATCH_SOURCE,
                                    eCSSUnit_Enumerated);
   bool haveColor = false,
        haveImage = false,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -6143,17 +6143,17 @@ nsComputedDOMStyle::DoGetMask()
   // Mask is now a shorthand, but it used to be a longhand, so that we
   // need to support computed style for the cases where it used to be
   // a longhand.
   if (svg->mMask.mImageCount > 1 ||
       firstLayer.mClip != NS_STYLE_IMAGELAYER_CLIP_BORDER ||
       firstLayer.mOrigin != NS_STYLE_IMAGELAYER_ORIGIN_BORDER ||
       firstLayer.mComposite != NS_STYLE_MASK_COMPOSITE_ADD ||
       firstLayer.mMaskMode != NS_STYLE_MASK_MODE_MATCH_SOURCE ||
-      !firstLayer.mPosition.IsInitialValue() ||
+      !firstLayer.mPosition.IsInitialValue(nsStyleImageLayers::LayerType::Mask) ||
       !firstLayer.mRepeat.IsInitialValue(nsStyleImageLayers::LayerType::Mask) ||
       !firstLayer.mSize.IsInitialValue() ||
       !(firstLayer.mImage.GetType() == eStyleImageType_Null ||
         firstLayer.mImage.GetType() == eStyleImageType_Image)) {
     return nullptr;
   }
 
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -2483,22 +2483,31 @@ nsStyleImageLayers::HasLayerWithImage() 
       return true;
     }
   }
 
   return false;
 }
 
 bool
-nsStyleImageLayers::Position::IsInitialValue() const
+nsStyleImageLayers::Position::IsInitialValue(LayerType aType) const
 {
-  if (mXPosition.mPercent == 0.0 && mXPosition.mLength == 0 &&
-      mXPosition.mHasPercent && mYPosition.mPercent == 0.0 &&
-      mYPosition.mLength == 0 && mYPosition.mHasPercent) {
-    return true;
+  if (aType == LayerType::Background) {
+    if (mXPosition.mPercent == 0.0 && mXPosition.mLength == 0 &&
+        mXPosition.mHasPercent && mYPosition.mPercent == 0.0 &&
+        mYPosition.mLength == 0 && mYPosition.mHasPercent) {
+      return true;
+    }
+  } else {
+    MOZ_ASSERT(aType == LayerType::Mask);
+    if (mXPosition.mPercent == 0.5f && mXPosition.mLength == 0 &&
+        mXPosition.mHasPercent && mYPosition.mPercent == 0.5f &&
+        mYPosition.mLength == 0 && mYPosition.mHasPercent) {
+      return true;
+    }
   }
 
   return false;
 }
 
 void
 nsStyleImageLayers::Position::SetInitialPercentValues(float aPercentVal)
 {
@@ -2653,35 +2662,36 @@ nsStyleImageLayers::Repeat::SetInitialVa
 
 nsStyleImageLayers::Layer::Layer()
   : mClip(NS_STYLE_IMAGELAYER_CLIP_BORDER)
   , mAttachment(NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL)
   , mBlendMode(NS_STYLE_BLEND_NORMAL)
   , mComposite(NS_STYLE_MASK_COMPOSITE_ADD)
   , mMaskMode(NS_STYLE_MASK_MODE_MATCH_SOURCE)
 {
-  mPosition.SetInitialPercentValues(0.0f); // Initial value is "0% 0%"
   mImage.SetNull();
   mSize.SetInitialValues();
 }
 
 nsStyleImageLayers::Layer::~Layer()
 {
 }
 
 void
 nsStyleImageLayers::Layer::Initialize(nsStyleImageLayers::LayerType aType)
 {
   mRepeat.SetInitialValues(aType);
 
   if (aType == LayerType::Background) {
     mOrigin = NS_STYLE_IMAGELAYER_ORIGIN_PADDING;
+    mPosition.SetInitialPercentValues(0.0f); // Initial value is "0% 0%"
   } else {
     MOZ_ASSERT(aType == LayerType::Mask, "unsupported layer type.");
     mOrigin = NS_STYLE_IMAGELAYER_ORIGIN_BORDER;
+    mPosition.SetInitialPercentValues(0.5f); // Initial value is "50% 50%"
   }
 }
 
 bool
 nsStyleImageLayers::Layer::RenderingMightDependOnPositioningAreaSizeChange() const
 {
   // Do we even have an image?
   if (mImage.IsEmpty()) {
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -561,17 +561,17 @@ struct nsStyleImageLayers {
   friend struct Position;
   struct Position {
     typedef nsStyleCoord::CalcValue PositionCoord;
     PositionCoord mXPosition, mYPosition;
 
     // Initialize nothing
     Position() {}
 
-    bool IsInitialValue() const;
+    bool IsInitialValue(LayerType aType) const;
 
     // Sets both mXPosition and mYPosition to the given percent value for the
     // initial property-value (e.g. 0.0f for "0% 0%", or 0.5f for "50% 50%")
     void SetInitialPercentValues(float aPercentVal);
 
     // Sets both mXPosition and mYPosition to 0 (app units) for the
     // initial property-value as a length with no percentage component.
     void SetInitialZeroValues();