diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index 5d246e146c6..9d688900ec4 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -3275,18 +3275,18 @@ nsRuleNode::ComputeBackgroundData(nsStyleStruct* aStartStruct, // background-position: enum, length, percent (flags), inherit if (eCSSUnit_Percent == colorData.mBackPositionX.GetUnit()) { - bg->mBackgroundXPosition = (nscoord)(100.0f * colorData.mBackPositionX.GetPercentValue()); + bg->mBackgroundXPosition.mFloat = colorData.mBackPositionX.GetPercentValue(); bg->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH; } else if (colorData.mBackPositionX.IsLengthUnit()) { - bg->mBackgroundXPosition = CalcLength(colorData.mBackPositionX, nsnull, - aContext, mPresContext, inherited); + bg->mBackgroundXPosition.mCoord = CalcLength(colorData.mBackPositionX, nsnull, + aContext, mPresContext, inherited); bg->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_LENGTH; bg->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_PERCENT; } else if (eCSSUnit_Enumerated == colorData.mBackPositionX.GetUnit()) { - bg->mBackgroundXPosition = (nscoord)colorData.mBackPositionX.GetIntValue(); + bg->mBackgroundXPosition.mFloat = (float)colorData.mBackPositionX.GetIntValue() / 100.0f; bg->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH; } @@ -3298,18 +3298,18 @@ nsRuleNode::ComputeBackgroundData(nsStyleStruct* aStartStruct, } if (eCSSUnit_Percent == colorData.mBackPositionY.GetUnit()) { - bg->mBackgroundYPosition = (nscoord)(100.0f * colorData.mBackPositionY.GetPercentValue()); + bg->mBackgroundYPosition.mFloat = colorData.mBackPositionY.GetPercentValue(); bg->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH; } else if (colorData.mBackPositionY.IsLengthUnit()) { - bg->mBackgroundYPosition = CalcLength(colorData.mBackPositionY, nsnull, - aContext, mPresContext, inherited); + bg->mBackgroundYPosition.mCoord = CalcLength(colorData.mBackPositionY, nsnull, + aContext, mPresContext, inherited); bg->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_LENGTH; bg->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_PERCENT; } else if (eCSSUnit_Enumerated == colorData.mBackPositionY.GetUnit()) { - bg->mBackgroundYPosition = (nscoord)colorData.mBackPositionY.GetIntValue(); + bg->mBackgroundYPosition.mFloat = (float)colorData.mBackPositionY.GetIntValue() / 100.0f; bg->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH; } diff --git a/mozilla/content/base/src/nsStyleContext.cpp b/mozilla/content/base/src/nsStyleContext.cpp index 26c5d2b7a1e..13428a4cd56 100644 --- a/mozilla/content/base/src/nsStyleContext.cpp +++ b/mozilla/content/base/src/nsStyleContext.cpp @@ -939,8 +939,8 @@ void nsStyleContext::DumpRegressionData(nsIPresContext* aPresContext, FILE* out, (int)bg->mBackgroundFlags, (int)bg->mBackgroundRepeat, (long)bg->mBackgroundColor, - (long)bg->mBackgroundXPosition, - (long)bg->mBackgroundYPosition, + (long)bg->mBackgroundXPosition.mCoord, // potentially lossy on some platforms + (long)bg->mBackgroundYPosition.mCoord, // potentially lossy on some platforms NS_ConvertUCS2toUTF8(bg->mBackgroundImage).get()); // SPACING (ie. margin, padding, border, outline) diff --git a/mozilla/content/shared/public/nsStyleStruct.h b/mozilla/content/shared/public/nsStyleStruct.h index d832286c13d..dd99d7931b8 100644 --- a/mozilla/content/shared/public/nsStyleStruct.h +++ b/mozilla/content/shared/public/nsStyleStruct.h @@ -168,9 +168,15 @@ struct nsStyleBackground : public nsStyleStruct { PRUint8 mBackgroundOrigin : 3; // [reset] See nsStyleConsts.h PRUint8 mBackgroundRepeat : 4; // [reset] See nsStyleConsts.h + // Note: a member of this union is valid IFF the appropriate bit flag + // is set in mBackgroundFlags. + union { + nscoord mCoord; + float mFloat; + } mBackgroundXPosition, // [reset] + mBackgroundYPosition; // [reset] + nscolor mBackgroundColor; // [reset] - nscoord mBackgroundXPosition; // [reset] - nscoord mBackgroundYPosition; // [reset] nsString mBackgroundImage; // [reset] absolute url string PRBool IsTransparent() const @@ -179,11 +185,6 @@ struct nsStyleBackground : public nsStyleStruct { (NS_STYLE_BG_COLOR_TRANSPARENT | NS_STYLE_BG_IMAGE_NONE)) == (NS_STYLE_BG_COLOR_TRANSPARENT | NS_STYLE_BG_IMAGE_NONE); } - - PRBool IsPositioned() const - { - return mBackgroundXPosition != 0 || mBackgroundYPosition != 0; - } }; #define BORDER_COLOR_DEFINED 0x80 diff --git a/mozilla/content/shared/src/nsStyleStruct.cpp b/mozilla/content/shared/src/nsStyleStruct.cpp index 51a4616708e..90474e8d897 100644 --- a/mozilla/content/shared/src/nsStyleStruct.cpp +++ b/mozilla/content/shared/src/nsStyleStruct.cpp @@ -974,9 +974,7 @@ nsStyleBackground::nsStyleBackground(nsIPresContext* aPresContext) mBackgroundClip(NS_STYLE_BG_CLIP_BORDER), mBackgroundInlinePolicy(NS_STYLE_BG_INLINE_POLICY_CONTINUOUS), mBackgroundOrigin(NS_STYLE_BG_ORIGIN_PADDING), - mBackgroundRepeat(NS_STYLE_BG_REPEAT_XY), - mBackgroundXPosition(0), - mBackgroundYPosition(0) + mBackgroundRepeat(NS_STYLE_BG_REPEAT_XY) { aPresContext->GetDefaultBackgroundColor(&mBackgroundColor); } @@ -988,9 +986,9 @@ nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource) mBackgroundInlinePolicy(aSource.mBackgroundInlinePolicy), mBackgroundOrigin(aSource.mBackgroundOrigin), mBackgroundRepeat(aSource.mBackgroundRepeat), - mBackgroundColor(aSource.mBackgroundColor), mBackgroundXPosition(aSource.mBackgroundXPosition), mBackgroundYPosition(aSource.mBackgroundYPosition), + mBackgroundColor(aSource.mBackgroundColor), mBackgroundImage(aSource.mBackgroundImage) { } @@ -1007,12 +1005,18 @@ nsChangeHint nsStyleBackground::CalcDifference(const nsStyleBackground& aOther) (mBackgroundFlags == aOther.mBackgroundFlags) && (mBackgroundRepeat == aOther.mBackgroundRepeat) && (mBackgroundColor == aOther.mBackgroundColor) && - (mBackgroundXPosition == aOther.mBackgroundXPosition) && - (mBackgroundYPosition == aOther.mBackgroundYPosition) && (mBackgroundClip == aOther.mBackgroundClip) && (mBackgroundInlinePolicy == aOther.mBackgroundInlinePolicy) && (mBackgroundOrigin == aOther.mBackgroundOrigin) && - (mBackgroundImage == aOther.mBackgroundImage)) + (mBackgroundImage == aOther.mBackgroundImage) && + ((!(mBackgroundFlags & NS_STYLE_BG_X_POSITION_PERCENT) || + (mBackgroundXPosition.mFloat == aOther.mBackgroundXPosition.mFloat)) && + (!(mBackgroundFlags & NS_STYLE_BG_X_POSITION_LENGTH) || + (mBackgroundXPosition.mCoord == aOther.mBackgroundXPosition.mCoord))) && + ((!(mBackgroundFlags & NS_STYLE_BG_Y_POSITION_PERCENT) || + (mBackgroundYPosition.mFloat == aOther.mBackgroundYPosition.mFloat)) && + (!(mBackgroundFlags & NS_STYLE_BG_Y_POSITION_LENGTH) || + (mBackgroundYPosition.mCoord == aOther.mBackgroundYPosition.mCoord)))) return NS_STYLE_HINT_NONE; return NS_STYLE_HINT_VISUAL; } diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index 627916d8edd..60d446d824e 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -2397,14 +2397,16 @@ ComputeBackgroundAnchorPoint(const nsStyleBackground& aColor, { nscoord x; if (NS_STYLE_BG_X_POSITION_LENGTH & aColor.mBackgroundFlags) { - x = aColor.mBackgroundXPosition; + x = aColor.mBackgroundXPosition.mCoord; + } + else if (NS_STYLE_BG_X_POSITION_PERCENT & aColor.mBackgroundFlags) { + PRFloat64 percent = PRFloat64(aColor.mBackgroundXPosition.mFloat); + nscoord tilePos = nscoord(percent * PRFloat64(aTileWidth)); + nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.width)); + x = boxPos - tilePos; } else { - nscoord t = aColor.mBackgroundXPosition; - float pct = float(t) / 100.0f; - nscoord tilePos = nscoord(pct * aTileWidth); - nscoord boxPos = nscoord(pct * aOriginBounds.width); - x = boxPos - tilePos; + x = 0; } x += aOriginBounds.x - aClipBounds.x; if (NS_STYLE_BG_REPEAT_X & aColor.mBackgroundRepeat) { @@ -2434,14 +2436,16 @@ ComputeBackgroundAnchorPoint(const nsStyleBackground& aColor, nscoord y; if (NS_STYLE_BG_Y_POSITION_LENGTH & aColor.mBackgroundFlags) { - y = aColor.mBackgroundYPosition; + y = aColor.mBackgroundYPosition.mCoord; + } + else if (NS_STYLE_BG_Y_POSITION_PERCENT & aColor.mBackgroundFlags){ + PRFloat64 percent = PRFloat64(aColor.mBackgroundYPosition.mFloat); + nscoord tilePos = nscoord(percent * PRFloat64(aTileHeight)); + nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.height)); + y = boxPos - tilePos; } else { - nscoord t = aColor.mBackgroundYPosition; - float pct = float(t) / 100.0f; - nscoord tilePos = nscoord(pct * aTileHeight); - nscoord boxPos = nscoord(pct * aOriginBounds.height); - y = boxPos - tilePos; + y = 0; } y += aOriginBounds.y - aClipBounds.y; if (NS_STYLE_BG_REPEAT_Y & aColor.mBackgroundRepeat) { diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index 627916d8edd..60d446d824e 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -2397,14 +2397,16 @@ ComputeBackgroundAnchorPoint(const nsStyleBackground& aColor, { nscoord x; if (NS_STYLE_BG_X_POSITION_LENGTH & aColor.mBackgroundFlags) { - x = aColor.mBackgroundXPosition; + x = aColor.mBackgroundXPosition.mCoord; + } + else if (NS_STYLE_BG_X_POSITION_PERCENT & aColor.mBackgroundFlags) { + PRFloat64 percent = PRFloat64(aColor.mBackgroundXPosition.mFloat); + nscoord tilePos = nscoord(percent * PRFloat64(aTileWidth)); + nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.width)); + x = boxPos - tilePos; } else { - nscoord t = aColor.mBackgroundXPosition; - float pct = float(t) / 100.0f; - nscoord tilePos = nscoord(pct * aTileWidth); - nscoord boxPos = nscoord(pct * aOriginBounds.width); - x = boxPos - tilePos; + x = 0; } x += aOriginBounds.x - aClipBounds.x; if (NS_STYLE_BG_REPEAT_X & aColor.mBackgroundRepeat) { @@ -2434,14 +2436,16 @@ ComputeBackgroundAnchorPoint(const nsStyleBackground& aColor, nscoord y; if (NS_STYLE_BG_Y_POSITION_LENGTH & aColor.mBackgroundFlags) { - y = aColor.mBackgroundYPosition; + y = aColor.mBackgroundYPosition.mCoord; + } + else if (NS_STYLE_BG_Y_POSITION_PERCENT & aColor.mBackgroundFlags){ + PRFloat64 percent = PRFloat64(aColor.mBackgroundYPosition.mFloat); + nscoord tilePos = nscoord(percent * PRFloat64(aTileHeight)); + nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.height)); + y = boxPos - tilePos; } else { - nscoord t = aColor.mBackgroundYPosition; - float pct = float(t) / 100.0f; - nscoord tilePos = nscoord(pct * aTileHeight); - nscoord boxPos = nscoord(pct * aOriginBounds.height); - y = boxPos - tilePos; + y = 0; } y += aOriginBounds.y - aClipBounds.y; if (NS_STYLE_BG_REPEAT_Y & aColor.mBackgroundRepeat) { diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index 5d246e146c6..9d688900ec4 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -3275,18 +3275,18 @@ nsRuleNode::ComputeBackgroundData(nsStyleStruct* aStartStruct, // background-position: enum, length, percent (flags), inherit if (eCSSUnit_Percent == colorData.mBackPositionX.GetUnit()) { - bg->mBackgroundXPosition = (nscoord)(100.0f * colorData.mBackPositionX.GetPercentValue()); + bg->mBackgroundXPosition.mFloat = colorData.mBackPositionX.GetPercentValue(); bg->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH; } else if (colorData.mBackPositionX.IsLengthUnit()) { - bg->mBackgroundXPosition = CalcLength(colorData.mBackPositionX, nsnull, - aContext, mPresContext, inherited); + bg->mBackgroundXPosition.mCoord = CalcLength(colorData.mBackPositionX, nsnull, + aContext, mPresContext, inherited); bg->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_LENGTH; bg->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_PERCENT; } else if (eCSSUnit_Enumerated == colorData.mBackPositionX.GetUnit()) { - bg->mBackgroundXPosition = (nscoord)colorData.mBackPositionX.GetIntValue(); + bg->mBackgroundXPosition.mFloat = (float)colorData.mBackPositionX.GetIntValue() / 100.0f; bg->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH; } @@ -3298,18 +3298,18 @@ nsRuleNode::ComputeBackgroundData(nsStyleStruct* aStartStruct, } if (eCSSUnit_Percent == colorData.mBackPositionY.GetUnit()) { - bg->mBackgroundYPosition = (nscoord)(100.0f * colorData.mBackPositionY.GetPercentValue()); + bg->mBackgroundYPosition.mFloat = colorData.mBackPositionY.GetPercentValue(); bg->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH; } else if (colorData.mBackPositionY.IsLengthUnit()) { - bg->mBackgroundYPosition = CalcLength(colorData.mBackPositionY, nsnull, - aContext, mPresContext, inherited); + bg->mBackgroundYPosition.mCoord = CalcLength(colorData.mBackPositionY, nsnull, + aContext, mPresContext, inherited); bg->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_LENGTH; bg->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_PERCENT; } else if (eCSSUnit_Enumerated == colorData.mBackPositionY.GetUnit()) { - bg->mBackgroundYPosition = (nscoord)colorData.mBackPositionY.GetIntValue(); + bg->mBackgroundYPosition.mFloat = (float)colorData.mBackPositionY.GetIntValue() / 100.0f; bg->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PERCENT; bg->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH; } diff --git a/mozilla/layout/style/nsStyleContext.cpp b/mozilla/layout/style/nsStyleContext.cpp index 26c5d2b7a1e..13428a4cd56 100644 --- a/mozilla/layout/style/nsStyleContext.cpp +++ b/mozilla/layout/style/nsStyleContext.cpp @@ -939,8 +939,8 @@ void nsStyleContext::DumpRegressionData(nsIPresContext* aPresContext, FILE* out, (int)bg->mBackgroundFlags, (int)bg->mBackgroundRepeat, (long)bg->mBackgroundColor, - (long)bg->mBackgroundXPosition, - (long)bg->mBackgroundYPosition, + (long)bg->mBackgroundXPosition.mCoord, // potentially lossy on some platforms + (long)bg->mBackgroundYPosition.mCoord, // potentially lossy on some platforms NS_ConvertUCS2toUTF8(bg->mBackgroundImage).get()); // SPACING (ie. margin, padding, border, outline) diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index 51a4616708e..90474e8d897 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -974,9 +974,7 @@ nsStyleBackground::nsStyleBackground(nsIPresContext* aPresContext) mBackgroundClip(NS_STYLE_BG_CLIP_BORDER), mBackgroundInlinePolicy(NS_STYLE_BG_INLINE_POLICY_CONTINUOUS), mBackgroundOrigin(NS_STYLE_BG_ORIGIN_PADDING), - mBackgroundRepeat(NS_STYLE_BG_REPEAT_XY), - mBackgroundXPosition(0), - mBackgroundYPosition(0) + mBackgroundRepeat(NS_STYLE_BG_REPEAT_XY) { aPresContext->GetDefaultBackgroundColor(&mBackgroundColor); } @@ -988,9 +986,9 @@ nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource) mBackgroundInlinePolicy(aSource.mBackgroundInlinePolicy), mBackgroundOrigin(aSource.mBackgroundOrigin), mBackgroundRepeat(aSource.mBackgroundRepeat), - mBackgroundColor(aSource.mBackgroundColor), mBackgroundXPosition(aSource.mBackgroundXPosition), mBackgroundYPosition(aSource.mBackgroundYPosition), + mBackgroundColor(aSource.mBackgroundColor), mBackgroundImage(aSource.mBackgroundImage) { } @@ -1007,12 +1005,18 @@ nsChangeHint nsStyleBackground::CalcDifference(const nsStyleBackground& aOther) (mBackgroundFlags == aOther.mBackgroundFlags) && (mBackgroundRepeat == aOther.mBackgroundRepeat) && (mBackgroundColor == aOther.mBackgroundColor) && - (mBackgroundXPosition == aOther.mBackgroundXPosition) && - (mBackgroundYPosition == aOther.mBackgroundYPosition) && (mBackgroundClip == aOther.mBackgroundClip) && (mBackgroundInlinePolicy == aOther.mBackgroundInlinePolicy) && (mBackgroundOrigin == aOther.mBackgroundOrigin) && - (mBackgroundImage == aOther.mBackgroundImage)) + (mBackgroundImage == aOther.mBackgroundImage) && + ((!(mBackgroundFlags & NS_STYLE_BG_X_POSITION_PERCENT) || + (mBackgroundXPosition.mFloat == aOther.mBackgroundXPosition.mFloat)) && + (!(mBackgroundFlags & NS_STYLE_BG_X_POSITION_LENGTH) || + (mBackgroundXPosition.mCoord == aOther.mBackgroundXPosition.mCoord))) && + ((!(mBackgroundFlags & NS_STYLE_BG_Y_POSITION_PERCENT) || + (mBackgroundYPosition.mFloat == aOther.mBackgroundYPosition.mFloat)) && + (!(mBackgroundFlags & NS_STYLE_BG_Y_POSITION_LENGTH) || + (mBackgroundYPosition.mCoord == aOther.mBackgroundYPosition.mCoord)))) return NS_STYLE_HINT_NONE; return NS_STYLE_HINT_VISUAL; } diff --git a/mozilla/layout/style/nsStyleStruct.h b/mozilla/layout/style/nsStyleStruct.h index d832286c13d..dd99d7931b8 100644 --- a/mozilla/layout/style/nsStyleStruct.h +++ b/mozilla/layout/style/nsStyleStruct.h @@ -168,9 +168,15 @@ struct nsStyleBackground : public nsStyleStruct { PRUint8 mBackgroundOrigin : 3; // [reset] See nsStyleConsts.h PRUint8 mBackgroundRepeat : 4; // [reset] See nsStyleConsts.h + // Note: a member of this union is valid IFF the appropriate bit flag + // is set in mBackgroundFlags. + union { + nscoord mCoord; + float mFloat; + } mBackgroundXPosition, // [reset] + mBackgroundYPosition; // [reset] + nscolor mBackgroundColor; // [reset] - nscoord mBackgroundXPosition; // [reset] - nscoord mBackgroundYPosition; // [reset] nsString mBackgroundImage; // [reset] absolute url string PRBool IsTransparent() const @@ -179,11 +185,6 @@ struct nsStyleBackground : public nsStyleStruct { (NS_STYLE_BG_COLOR_TRANSPARENT | NS_STYLE_BG_IMAGE_NONE)) == (NS_STYLE_BG_COLOR_TRANSPARENT | NS_STYLE_BG_IMAGE_NONE); } - - PRBool IsPositioned() const - { - return mBackgroundXPosition != 0 || mBackgroundYPosition != 0; - } }; #define BORDER_COLOR_DEFINED 0x80