diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index 279ddb5590a..f93dd309815 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -3102,7 +3102,7 @@ nsRuleNode::ComputeMarginData(nsStyleStruct* aStartStruct, // margin: length, percent, auto, inherit nsStyleCoord coord; nsStyleCoord parentCoord; - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentMargin->mMargin.Get(side, parentCoord); if (SetCoord(marginData.mMargin.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPAH, @@ -3171,7 +3171,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, nsStyleCoord coord; nsStyleCoord parentCoord; { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { const nsCSSValue &value = marginData.mBorderWidth.*(nsCSSRect::sides[side]); if (SetCoord(value, coord, parentCoord, SETCOORD_LE, aContext, mPresContext, inherited)) @@ -3186,7 +3186,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, // border-style: enum, none, inhert const nsCSSRect& ourStyle = marginData.mBorderStyle; { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { const nsCSSValue &value = ourStyle.*(nsCSSRect::sides[side]); nsCSSUnit unit = value.GetUnit(); if (eCSSUnit_Enumerated == unit) { @@ -3207,7 +3207,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, nscolor unused = NS_RGB(0,0,0); { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { nsCSSValueList* list = marginData.mBorderColors.*(nsCSSValueListRect::sides[side]); if (list) { @@ -3233,7 +3233,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, PRBool foreground; { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { const nsCSSValue &value = ourBorderColor.*(nsCSSRect::sides[side]); if (eCSSUnit_Inherit == value.GetUnit()) { if (parentContext) { @@ -3274,7 +3274,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, // -moz-border-radius: length, percent, inherit { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentBorder->mBorderRadius.Get(side, parentCoord); if (SetCoord(marginData.mBorderRadius.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPH, aContext, mPresContext, @@ -3337,7 +3337,7 @@ nsRuleNode::ComputePaddingData(nsStyleStruct* aStartStruct, // padding: length, percent, inherit nsStyleCoord coord; nsStyleCoord parentCoord; - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentPadding->mPadding.Get(side, parentCoord); if (SetCoord(marginData.mPadding.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPH, @@ -3591,7 +3591,7 @@ nsRuleNode::ComputePositionData(nsStyleStruct* aStartStruct, // box offsets: length, percent, auto, inherit nsStyleCoord coord; nsStyleCoord parentCoord; - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentPos->mOffset.Get(side, parentCoord); if (SetCoord(posData.mOffset.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPAH, diff --git a/mozilla/content/html/style/src/nsCSSParser.cpp b/mozilla/content/html/style/src/nsCSSParser.cpp index a78b9a98ad5..a4b6e3db1a7 100644 --- a/mozilla/content/html/style/src/nsCSSParser.cpp +++ b/mozilla/content/html/style/src/nsCSSParser.cpp @@ -4908,7 +4908,7 @@ CSSParserImpl::DoParseRect(nsCSSRect& aRect, nsresult& aErrorCode) if (!ExpectSymbol(aErrorCode, '(', PR_TRUE)) { return PR_FALSE; } - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { if (! ParseVariant(aErrorCode, aRect.*(nsCSSRect::sides[side]), VARIANT_AL, nsnull)) { return PR_FALSE; diff --git a/mozilla/content/html/style/src/nsCSSStruct.h b/mozilla/content/html/style/src/nsCSSStruct.h index 8dab8e6e6e1..9de573b152b 100644 --- a/mozilla/content/html/style/src/nsCSSStruct.h +++ b/mozilla/content/html/style/src/nsCSSStruct.h @@ -150,8 +150,6 @@ struct nsCSSText : public nsCSSStruct { struct nsRuleDataText : public nsCSSText { }; -#define FOR_CSS_SIDES(var_) for (PRInt32 var_ = 0; var_ < 4; ++var_) - struct nsCSSRect { nsCSSRect(void); nsCSSRect(const nsCSSRect& aCopy); diff --git a/mozilla/content/shared/src/nsStyleStruct.cpp b/mozilla/content/shared/src/nsStyleStruct.cpp index d500cbe2f10..5374e0da30c 100644 --- a/mozilla/content/shared/src/nsStyleStruct.cpp +++ b/mozilla/content/shared/src/nsStyleStruct.cpp @@ -20,7 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * David Hyatt (hyatt@netscape.com + * David Hyatt (hyatt@netscape.com) * * * Alternatively, the contents of this file may be used under the terms of @@ -270,12 +270,17 @@ nsChangeHint nsStyleFont::CalcFontDifference(const nsFont& aFont1, const nsFont& return NS_STYLE_HINT_REFLOW; } +static nscoord nsMargin::* const gMarginSides[4] = { + &nsMargin::top, &nsMargin::right, &nsMargin::bottom, &nsMargin::left +}; + static PRBool IsFixedData(const nsStyleSides& aSides, PRBool aEnumOK) { - return PRBool(IsFixedUnit(aSides.GetLeftUnit(), aEnumOK) && - IsFixedUnit(aSides.GetTopUnit(), aEnumOK) && - IsFixedUnit(aSides.GetRightUnit(), aEnumOK) && - IsFixedUnit(aSides.GetBottomUnit(), aEnumOK)); + NS_FOR_CSS_SIDES(side) { + if (!IsFixedUnit(aSides.GetUnit(side), aEnumOK)) + return PR_FALSE; + } + return PR_TRUE; } static nscoord CalcCoord(const nsStyleCoord& aCoord, @@ -331,12 +336,11 @@ nsStyleMargin::Destroy(nsIPresContext* aContext) { void nsStyleMargin::RecalcData() { if (IsFixedData(mMargin, PR_FALSE)) { - nsStyleCoord coord; - mCachedMargin.left = CalcCoord(mMargin.GetLeft(coord), nsnull, 0); - mCachedMargin.top = CalcCoord(mMargin.GetTop(coord), nsnull, 0); - mCachedMargin.right = CalcCoord(mMargin.GetRight(coord), nsnull, 0); - mCachedMargin.bottom = CalcCoord(mMargin.GetBottom(coord), nsnull, 0); - + nsStyleCoord coord; + NS_FOR_CSS_SIDES(side) { + mCachedMargin.*(gMarginSides[side]) = + CalcCoord(mMargin.Get(side, coord), nsnull, 0); + } mHasCachedMargin = PR_TRUE; } else @@ -389,12 +393,11 @@ nsStylePadding::Destroy(nsIPresContext* aContext) { void nsStylePadding::RecalcData() { if (IsFixedData(mPadding, PR_FALSE)) { - nsStyleCoord coord; - mCachedPadding.left = CalcCoord(mPadding.GetLeft(coord), nsnull, 0); - mCachedPadding.top = CalcCoord(mPadding.GetTop(coord), nsnull, 0); - mCachedPadding.right = CalcCoord(mPadding.GetRight(coord), nsnull, 0); - mCachedPadding.bottom = CalcCoord(mPadding.GetBottom(coord), nsnull, 0); - + nsStyleCoord coord; + NS_FOR_CSS_SIDES(side) { + mCachedPadding.*(gMarginSides[side]) = + CalcCoord(mPadding.Get(side, coord), nsnull, 0); + } mHasCachedPadding = PR_TRUE; } else @@ -496,38 +499,20 @@ PRBool nsStyleBorder::IsBorderSideVisible(PRUint8 aSide) const void nsStyleBorder::RecalcData() { - if (((!IsBorderSideVisible(NS_SIDE_LEFT))|| - IsFixedUnit(mBorder.GetLeftUnit(), PR_TRUE)) && - ((!IsBorderSideVisible(NS_SIDE_TOP)) || - IsFixedUnit(mBorder.GetTopUnit(), PR_TRUE)) && - ((!IsBorderSideVisible(NS_SIDE_RIGHT)) || - IsFixedUnit(mBorder.GetRightUnit(), PR_TRUE)) && - ((!IsBorderSideVisible(NS_SIDE_BOTTOM)) || - IsFixedUnit(mBorder.GetBottomUnit(), PR_TRUE))) { - nsStyleCoord coord; - if (!IsBorderSideVisible(NS_SIDE_LEFT)) { - mCachedBorder.left = 0; + PRBool allFixed = PR_TRUE; + {NS_FOR_CSS_SIDES(side) { + if (IsBorderSideVisible(side) && + !IsFixedUnit(mBorder.GetUnit(side), PR_TRUE)) { + allFixed = PR_FALSE; + break; } - else { - mCachedBorder.left = CalcCoord(mBorder.GetLeft(coord), mBorderWidths, 3); - } - if (!IsBorderSideVisible(NS_SIDE_TOP)) { - mCachedBorder.top = 0; - } - else { - mCachedBorder.top = CalcCoord(mBorder.GetTop(coord), mBorderWidths, 3); - } - if (!IsBorderSideVisible(NS_SIDE_RIGHT)) { - mCachedBorder.right = 0; - } - else { - mCachedBorder.right = CalcCoord(mBorder.GetRight(coord), mBorderWidths, 3); - } - if (!IsBorderSideVisible(NS_SIDE_BOTTOM)) { - mCachedBorder.bottom = 0; - } - else { - mCachedBorder.bottom = CalcCoord(mBorder.GetBottom(coord), mBorderWidths, 3); + }} + if (allFixed) { + nsStyleCoord coord; + NS_FOR_CSS_SIDES(side) { + mCachedBorder.*(gMarginSides[side]) = IsBorderSideVisible(side) + ? CalcCoord(mBorder.Get(side, coord), mBorderWidths, 3) + : 0; } mHasCachedBorder = PR_TRUE; } @@ -535,25 +520,12 @@ void nsStyleBorder::RecalcData() mHasCachedBorder = PR_FALSE; } - if ((mBorderStyle[NS_SIDE_TOP] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_TOP] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_TOP); - } - if ((mBorderStyle[NS_SIDE_BOTTOM] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_BOTTOM] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_BOTTOM); - } - if ((mBorderStyle[NS_SIDE_LEFT] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_LEFT] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_LEFT); - } - if ((mBorderStyle[NS_SIDE_RIGHT] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_RIGHT] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_RIGHT); + NS_FOR_CSS_SIDES(side) { + if ((mBorderStyle[side] & BORDER_COLOR_DEFINED) == 0) { + NS_ASSERTION(!(mBorderStyle[side] & BORDER_COLOR_SPECIAL), + "Clearing special border because BORDER_COLOR_DEFINED is not set"); + SetBorderToForeground(side); + } } } @@ -561,8 +533,7 @@ nsChangeHint nsStyleBorder::CalcDifference(const nsStyleBorder& aOther) const { if ((mBorder == aOther.mBorder) && (mFloatEdge == aOther.mFloatEdge)) { - PRInt32 ix; - for (ix = 0; ix < 4; ix++) { + NS_FOR_CSS_SIDES(ix) { if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) || (mBorderColor[ix] != aOther.mBorderColor[ix])) { if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) && @@ -584,7 +555,7 @@ nsChangeHint nsStyleBorder::CalcDifference(const nsStyleBorder& aOther) const } if (mBorderColors && aOther.mBorderColors) { - for (ix = 0; ix < 4; ix++) { + NS_FOR_CSS_SIDES(ix) { if (mBorderColors[ix] && !aOther.mBorderColors[ix] || !mBorderColors[ix] && aOther.mBorderColors[ix]) { return NS_STYLE_HINT_VISUAL; diff --git a/mozilla/layout/base/nsStyleConsts.h b/mozilla/layout/base/nsStyleConsts.h index 59d3ae28ad4..f6564141a59 100644 --- a/mozilla/layout/base/nsStyleConsts.h +++ b/mozilla/layout/base/nsStyleConsts.h @@ -47,6 +47,8 @@ #define NS_SIDE_BOTTOM 2 #define NS_SIDE_LEFT 3 +#define NS_FOR_CSS_SIDES(var_) for (PRInt32 var_ = 0; var_ < 4; ++var_) + // {margin,padding}-{left,right}-{ltr,rtl}-source #define NS_BOXPROP_SOURCE_PHYSICAL 0 #define NS_BOXPROP_SOURCE_LOGICAL 1 diff --git a/mozilla/layout/base/public/nsStyleConsts.h b/mozilla/layout/base/public/nsStyleConsts.h index 59d3ae28ad4..f6564141a59 100644 --- a/mozilla/layout/base/public/nsStyleConsts.h +++ b/mozilla/layout/base/public/nsStyleConsts.h @@ -47,6 +47,8 @@ #define NS_SIDE_BOTTOM 2 #define NS_SIDE_LEFT 3 +#define NS_FOR_CSS_SIDES(var_) for (PRInt32 var_ = 0; var_ < 4; ++var_) + // {margin,padding}-{left,right}-{ltr,rtl}-source #define NS_BOXPROP_SOURCE_PHYSICAL 0 #define NS_BOXPROP_SOURCE_LOGICAL 1 diff --git a/mozilla/layout/style/nsCSSParser.cpp b/mozilla/layout/style/nsCSSParser.cpp index a78b9a98ad5..a4b6e3db1a7 100644 --- a/mozilla/layout/style/nsCSSParser.cpp +++ b/mozilla/layout/style/nsCSSParser.cpp @@ -4908,7 +4908,7 @@ CSSParserImpl::DoParseRect(nsCSSRect& aRect, nsresult& aErrorCode) if (!ExpectSymbol(aErrorCode, '(', PR_TRUE)) { return PR_FALSE; } - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { if (! ParseVariant(aErrorCode, aRect.*(nsCSSRect::sides[side]), VARIANT_AL, nsnull)) { return PR_FALSE; diff --git a/mozilla/layout/style/nsCSSStruct.h b/mozilla/layout/style/nsCSSStruct.h index 8dab8e6e6e1..9de573b152b 100644 --- a/mozilla/layout/style/nsCSSStruct.h +++ b/mozilla/layout/style/nsCSSStruct.h @@ -150,8 +150,6 @@ struct nsCSSText : public nsCSSStruct { struct nsRuleDataText : public nsCSSText { }; -#define FOR_CSS_SIDES(var_) for (PRInt32 var_ = 0; var_ < 4; ++var_) - struct nsCSSRect { nsCSSRect(void); nsCSSRect(const nsCSSRect& aCopy); diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index 279ddb5590a..f93dd309815 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -3102,7 +3102,7 @@ nsRuleNode::ComputeMarginData(nsStyleStruct* aStartStruct, // margin: length, percent, auto, inherit nsStyleCoord coord; nsStyleCoord parentCoord; - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentMargin->mMargin.Get(side, parentCoord); if (SetCoord(marginData.mMargin.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPAH, @@ -3171,7 +3171,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, nsStyleCoord coord; nsStyleCoord parentCoord; { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { const nsCSSValue &value = marginData.mBorderWidth.*(nsCSSRect::sides[side]); if (SetCoord(value, coord, parentCoord, SETCOORD_LE, aContext, mPresContext, inherited)) @@ -3186,7 +3186,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, // border-style: enum, none, inhert const nsCSSRect& ourStyle = marginData.mBorderStyle; { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { const nsCSSValue &value = ourStyle.*(nsCSSRect::sides[side]); nsCSSUnit unit = value.GetUnit(); if (eCSSUnit_Enumerated == unit) { @@ -3207,7 +3207,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, nscolor unused = NS_RGB(0,0,0); { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { nsCSSValueList* list = marginData.mBorderColors.*(nsCSSValueListRect::sides[side]); if (list) { @@ -3233,7 +3233,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, PRBool foreground; { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { const nsCSSValue &value = ourBorderColor.*(nsCSSRect::sides[side]); if (eCSSUnit_Inherit == value.GetUnit()) { if (parentContext) { @@ -3274,7 +3274,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, // -moz-border-radius: length, percent, inherit { // scope for compilers with broken |for| loop scoping - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentBorder->mBorderRadius.Get(side, parentCoord); if (SetCoord(marginData.mBorderRadius.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPH, aContext, mPresContext, @@ -3337,7 +3337,7 @@ nsRuleNode::ComputePaddingData(nsStyleStruct* aStartStruct, // padding: length, percent, inherit nsStyleCoord coord; nsStyleCoord parentCoord; - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentPadding->mPadding.Get(side, parentCoord); if (SetCoord(marginData.mPadding.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPH, @@ -3591,7 +3591,7 @@ nsRuleNode::ComputePositionData(nsStyleStruct* aStartStruct, // box offsets: length, percent, auto, inherit nsStyleCoord coord; nsStyleCoord parentCoord; - FOR_CSS_SIDES(side) { + NS_FOR_CSS_SIDES(side) { parentPos->mOffset.Get(side, parentCoord); if (SetCoord(posData.mOffset.*(nsCSSRect::sides[side]), coord, parentCoord, SETCOORD_LPAH, diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index d500cbe2f10..5374e0da30c 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -20,7 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * David Hyatt (hyatt@netscape.com + * David Hyatt (hyatt@netscape.com) * * * Alternatively, the contents of this file may be used under the terms of @@ -270,12 +270,17 @@ nsChangeHint nsStyleFont::CalcFontDifference(const nsFont& aFont1, const nsFont& return NS_STYLE_HINT_REFLOW; } +static nscoord nsMargin::* const gMarginSides[4] = { + &nsMargin::top, &nsMargin::right, &nsMargin::bottom, &nsMargin::left +}; + static PRBool IsFixedData(const nsStyleSides& aSides, PRBool aEnumOK) { - return PRBool(IsFixedUnit(aSides.GetLeftUnit(), aEnumOK) && - IsFixedUnit(aSides.GetTopUnit(), aEnumOK) && - IsFixedUnit(aSides.GetRightUnit(), aEnumOK) && - IsFixedUnit(aSides.GetBottomUnit(), aEnumOK)); + NS_FOR_CSS_SIDES(side) { + if (!IsFixedUnit(aSides.GetUnit(side), aEnumOK)) + return PR_FALSE; + } + return PR_TRUE; } static nscoord CalcCoord(const nsStyleCoord& aCoord, @@ -331,12 +336,11 @@ nsStyleMargin::Destroy(nsIPresContext* aContext) { void nsStyleMargin::RecalcData() { if (IsFixedData(mMargin, PR_FALSE)) { - nsStyleCoord coord; - mCachedMargin.left = CalcCoord(mMargin.GetLeft(coord), nsnull, 0); - mCachedMargin.top = CalcCoord(mMargin.GetTop(coord), nsnull, 0); - mCachedMargin.right = CalcCoord(mMargin.GetRight(coord), nsnull, 0); - mCachedMargin.bottom = CalcCoord(mMargin.GetBottom(coord), nsnull, 0); - + nsStyleCoord coord; + NS_FOR_CSS_SIDES(side) { + mCachedMargin.*(gMarginSides[side]) = + CalcCoord(mMargin.Get(side, coord), nsnull, 0); + } mHasCachedMargin = PR_TRUE; } else @@ -389,12 +393,11 @@ nsStylePadding::Destroy(nsIPresContext* aContext) { void nsStylePadding::RecalcData() { if (IsFixedData(mPadding, PR_FALSE)) { - nsStyleCoord coord; - mCachedPadding.left = CalcCoord(mPadding.GetLeft(coord), nsnull, 0); - mCachedPadding.top = CalcCoord(mPadding.GetTop(coord), nsnull, 0); - mCachedPadding.right = CalcCoord(mPadding.GetRight(coord), nsnull, 0); - mCachedPadding.bottom = CalcCoord(mPadding.GetBottom(coord), nsnull, 0); - + nsStyleCoord coord; + NS_FOR_CSS_SIDES(side) { + mCachedPadding.*(gMarginSides[side]) = + CalcCoord(mPadding.Get(side, coord), nsnull, 0); + } mHasCachedPadding = PR_TRUE; } else @@ -496,38 +499,20 @@ PRBool nsStyleBorder::IsBorderSideVisible(PRUint8 aSide) const void nsStyleBorder::RecalcData() { - if (((!IsBorderSideVisible(NS_SIDE_LEFT))|| - IsFixedUnit(mBorder.GetLeftUnit(), PR_TRUE)) && - ((!IsBorderSideVisible(NS_SIDE_TOP)) || - IsFixedUnit(mBorder.GetTopUnit(), PR_TRUE)) && - ((!IsBorderSideVisible(NS_SIDE_RIGHT)) || - IsFixedUnit(mBorder.GetRightUnit(), PR_TRUE)) && - ((!IsBorderSideVisible(NS_SIDE_BOTTOM)) || - IsFixedUnit(mBorder.GetBottomUnit(), PR_TRUE))) { - nsStyleCoord coord; - if (!IsBorderSideVisible(NS_SIDE_LEFT)) { - mCachedBorder.left = 0; + PRBool allFixed = PR_TRUE; + {NS_FOR_CSS_SIDES(side) { + if (IsBorderSideVisible(side) && + !IsFixedUnit(mBorder.GetUnit(side), PR_TRUE)) { + allFixed = PR_FALSE; + break; } - else { - mCachedBorder.left = CalcCoord(mBorder.GetLeft(coord), mBorderWidths, 3); - } - if (!IsBorderSideVisible(NS_SIDE_TOP)) { - mCachedBorder.top = 0; - } - else { - mCachedBorder.top = CalcCoord(mBorder.GetTop(coord), mBorderWidths, 3); - } - if (!IsBorderSideVisible(NS_SIDE_RIGHT)) { - mCachedBorder.right = 0; - } - else { - mCachedBorder.right = CalcCoord(mBorder.GetRight(coord), mBorderWidths, 3); - } - if (!IsBorderSideVisible(NS_SIDE_BOTTOM)) { - mCachedBorder.bottom = 0; - } - else { - mCachedBorder.bottom = CalcCoord(mBorder.GetBottom(coord), mBorderWidths, 3); + }} + if (allFixed) { + nsStyleCoord coord; + NS_FOR_CSS_SIDES(side) { + mCachedBorder.*(gMarginSides[side]) = IsBorderSideVisible(side) + ? CalcCoord(mBorder.Get(side, coord), mBorderWidths, 3) + : 0; } mHasCachedBorder = PR_TRUE; } @@ -535,25 +520,12 @@ void nsStyleBorder::RecalcData() mHasCachedBorder = PR_FALSE; } - if ((mBorderStyle[NS_SIDE_TOP] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_TOP] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_TOP); - } - if ((mBorderStyle[NS_SIDE_BOTTOM] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_BOTTOM] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_BOTTOM); - } - if ((mBorderStyle[NS_SIDE_LEFT] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_LEFT] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_LEFT); - } - if ((mBorderStyle[NS_SIDE_RIGHT] & BORDER_COLOR_DEFINED) == 0) { - NS_ASSERTION(!(mBorderStyle[NS_SIDE_RIGHT] & BORDER_COLOR_SPECIAL), - "Clearing special border because BORDER_COLOR_DEFINED is not set"); - SetBorderToForeground(NS_SIDE_RIGHT); + NS_FOR_CSS_SIDES(side) { + if ((mBorderStyle[side] & BORDER_COLOR_DEFINED) == 0) { + NS_ASSERTION(!(mBorderStyle[side] & BORDER_COLOR_SPECIAL), + "Clearing special border because BORDER_COLOR_DEFINED is not set"); + SetBorderToForeground(side); + } } } @@ -561,8 +533,7 @@ nsChangeHint nsStyleBorder::CalcDifference(const nsStyleBorder& aOther) const { if ((mBorder == aOther.mBorder) && (mFloatEdge == aOther.mFloatEdge)) { - PRInt32 ix; - for (ix = 0; ix < 4; ix++) { + NS_FOR_CSS_SIDES(ix) { if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) || (mBorderColor[ix] != aOther.mBorderColor[ix])) { if ((mBorderStyle[ix] != aOther.mBorderStyle[ix]) && @@ -584,7 +555,7 @@ nsChangeHint nsStyleBorder::CalcDifference(const nsStyleBorder& aOther) const } if (mBorderColors && aOther.mBorderColors) { - for (ix = 0; ix < 4; ix++) { + NS_FOR_CSS_SIDES(ix) { if (mBorderColors[ix] && !aOther.mBorderColors[ix] || !mBorderColors[ix] && aOther.mBorderColors[ix]) { return NS_STYLE_HINT_VISUAL;