From ed7978775aed86aa7e8a7882fbe7dd2ce0169066 Mon Sep 17 00:00:00 2001 From: cku Date: Wed, 10 Aug 2016 16:10:45 +0800 Subject: [PATCH] Bug 1277788 - Part 1. Set initial value of mask-position as center. r=dbaron. MozReview-Commit-ID: BflQ6tz8ZjM --HG-- extra : rebase_source : 01b05533f5c791da0987af81d5cca276ec36e3f0 --- layout/style/nsCSSParser.cpp | 37 ++++++++++++++++------------- layout/style/nsComputedDOMStyle.cpp | 2 +- layout/style/nsStyleStruct.cpp | 22 ++++++++++++----- layout/style/nsStyleStruct.h | 2 +- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 45c77f18faa5..453b58d8ae41 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -12083,28 +12083,33 @@ CSSParserImpl::ParseImageLayersItem( aState.mClip->mValue.SetIntValue(NS_STYLE_IMAGELAYER_CLIP_BORDER, eCSSUnit_Enumerated); - - - - 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); - } 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->mXValue.SetIntValue(NS_STYLE_IMAGELAYER_REPEAT_REPEAT, + eCSSUnit_Enumerated); aState.mRepeat->mYValue.Reset(); RefPtr positionXArr = nsCSSValue::Array::Create(2); RefPtr 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); + + 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); + + 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, diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index d21eb57a6879..fddfba2ad219 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -6148,7 +6148,7 @@ nsComputedDOMStyle::DoGetMask() 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 || diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 6522de3740e9..ec652f34b28a 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -2488,12 +2488,21 @@ nsStyleImageLayers::HasLayerWithImage() const } 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; @@ -2658,7 +2667,6 @@ nsStyleImageLayers::Layer::Layer() , 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(); } @@ -2674,9 +2682,11 @@ nsStyleImageLayers::Layer::Initialize(nsStyleImageLayers::LayerType 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%" } } diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 6f3928363abb..ee5b7d1c3550 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -566,7 +566,7 @@ struct nsStyleImageLayers { // 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%")