From e950ac1c5c0b9e6b573ca812244a493d4f8d6732 Mon Sep 17 00:00:00 2001 From: "hewitt%netscape.com" Date: Tue, 11 Dec 2001 11:13:16 +0000 Subject: [PATCH] 113789 - -moz-border-colors doesn't recognize transparent, r=ben, sr=hyatt git-svn-id: svn://10.0.0.236/trunk@110251 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsRuleNode.cpp | 8 +- mozilla/content/shared/public/nsStyleStruct.h | 19 +- mozilla/layout/base/nsCSSRendering.cpp | 277 +++++++++++------- .../layout/html/style/src/nsCSSRendering.cpp | 277 +++++++++++------- mozilla/layout/style/nsRuleNode.cpp | 8 +- mozilla/layout/style/nsStyleStruct.h | 19 +- 6 files changed, 376 insertions(+), 232 deletions(-) diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index f2f1694d500..1b647378ca1 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -3333,7 +3333,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, const nsCSSStruct& aD } } - // border-colors: color, string + // border-colors: color, string, enum if (marginData.mBorderColors) { nscolor borderColor; nscolor unused = NS_RGB(0,0,0); @@ -3343,10 +3343,14 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, const nsCSSStruct& aD // Some composite border color information has been specified for this // border side. border->EnsureBorderColors(); + border->ClearBorderColors(i); nsCSSValueList* list = marginData.mBorderColors[i]; while (list) { if (SetColor(list->mValue, unused, mPresContext, borderColor, inherited)) - border->AppendBorderColor(i, borderColor); + border->AppendBorderColor(i, borderColor, PR_FALSE); + else if (eCSSUnit_Enumerated == list->mValue.GetUnit() && + NS_STYLE_COLOR_TRANSPARENT == list->mValue.GetIntValue()) + border->AppendBorderColor(i, nsnull, PR_TRUE); list = list->mNext; } } diff --git a/mozilla/content/shared/public/nsStyleStruct.h b/mozilla/content/shared/public/nsStyleStruct.h index c8914df4608..5c7dbb4b92b 100644 --- a/mozilla/content/shared/public/nsStyleStruct.h +++ b/mozilla/content/shared/public/nsStyleStruct.h @@ -284,18 +284,20 @@ protected: struct nsBorderColors { nsBorderColors* mNext; nscolor mColor; - + PRBool mTransparent; + nsBorderColors* CopyColors() { nsBorderColors* next = nsnull; if (mNext) next = mNext->CopyColors(); - return new nsBorderColors(mColor, next); + return new nsBorderColors(mColor, mTransparent, next); } nsBorderColors() :mNext(nsnull) { mColor = NS_RGB(0,0,0); }; - nsBorderColors(const nscolor& aColor, nsBorderColors* aNext=nsnull) { + nsBorderColors(const nscolor& aColor, PRBool aTransparent, nsBorderColors* aNext=nsnull) { mColor = aColor; + mTransparent = aTransparent; mNext = aNext; } @@ -339,6 +341,13 @@ struct nsStyleBorder: public nsStyleStruct { } } + void ClearBorderColors(PRUint8 aSide) { + if (mBorderColors[aSide]) { + delete mBorderColors[aSide]; + mBorderColors[aSide] = nsnull; + } + } + PRBool GetBorder(nsMargin& aBorder) const { if (mHasCachedBorder) { @@ -391,10 +400,10 @@ struct nsStyleBorder: public nsStyleStruct { *aColors = mBorderColors[aIndex]; } - void AppendBorderColor(PRInt32 aIndex, nscolor aColor) + void AppendBorderColor(PRInt32 aIndex, nscolor aColor, PRBool aTransparent) { NS_ASSERTION(aIndex >= 0 && aIndex <= 3, "bad side for composite border color"); - nsBorderColors* colorEntry = new nsBorderColors(aColor); + nsBorderColors* colorEntry = new nsBorderColors(aColor, aTransparent); if (!mBorderColors[aIndex]) mBorderColors[aIndex] = colorEntry; else { diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index 5be6e1147be..917faad2d87 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -1764,11 +1764,29 @@ void nsCSSRendering::DrawCompositeSide(nsIRenderingContext& aRenderingContext, // up the -moz-border-radius gauntlet. // Alternatively we could add support for a -moz-border-diagonal property, which is // what this code actually draws (instead of a curve). - nscoord startRadius, endRadius; - startRadius = aBorderRadii[aWhichSide]; - endRadius = (aWhichSide == NS_SIDE_LEFT) ? aBorderRadii[0] : aBorderRadii[aWhichSide+1]; - PRInt32 level = 0; - while (currOuterRect.width > aInnerRect.width) { + + // determine the the number of pixels we need to draw for this side + // and the start and end radii + nscoord shrinkage, startRadius, endRadius; + if (aWhichSide == NS_SIDE_TOP) { + shrinkage = aInnerRect.y - aOuterRect.y; + startRadius = aBorderRadii[0]; + endRadius = aBorderRadii[1]; + } else if (aWhichSide == NS_SIDE_BOTTOM) { + shrinkage = (aOuterRect.height+aOuterRect.y) - (aInnerRect.height+aInnerRect.y); + startRadius = aBorderRadii[3]; + endRadius = aBorderRadii[2]; + } else if (aWhichSide == NS_SIDE_RIGHT) { + shrinkage = (aOuterRect.width+aOuterRect.x) - (aInnerRect.width+aInnerRect.x); + startRadius = aBorderRadii[1]; + endRadius = aBorderRadii[2]; + } else if (aWhichSide == NS_SIDE_LEFT) { + shrinkage = aInnerRect.x - aOuterRect.x; + startRadius = aBorderRadii[0]; + endRadius = aBorderRadii[3]; + } + + while (shrinkage) { nscoord xshrink = 0; nscoord yshrink = 0; nscoord widthshrink = 0; @@ -1785,122 +1803,163 @@ void nsCSSRendering::DrawCompositeSide(nsIRenderingContext& aRenderingContext, } } + // subtract any rounded pixels from the outer rect nsRect newOuterRect(currOuterRect); newOuterRect.x += xshrink; newOuterRect.y += yshrink; newOuterRect.width -= widthshrink; newOuterRect.height -= heightshrink; - nsRect borderInside(newOuterRect.x+twipsPerPixel, newOuterRect.y+twipsPerPixel, - newOuterRect.width - 2*twipsPerPixel, - newOuterRect.height - 2*twipsPerPixel); - nsPoint theSide[MAX_POLY_POINTS]; - PRInt32 np = MakeSide(theSide, aRenderingContext, aWhichSide, newOuterRect, borderInside, 0, - BORDER_FULL, 1.0f, twipsPerPixel); - NS_ASSERTION(np == 2, "Composite border should always be single pixel!"); - aRenderingContext.SetColor(aCompositeColors->mColor); - DrawLine(aRenderingContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); - - if (aWhichSide == NS_SIDE_TOP) { - if (startRadius) { - // Connecting line between top/left - nscoord distance = (startRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+startRadius, currOuterRect.y, - currOuterRect.x+(startRadius-distance), currOuterRect.y+distance, aGap); - } - if (endRadius) { - // Connecting line between top/right - nscoord distance = (endRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel, currOuterRect.y, - currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance, - currOuterRect.y+distance, aGap); - } - } - else if (aWhichSide == NS_SIDE_BOTTOM) { - if (startRadius) { - // Connecting line between bottom/right - nscoord distance = (endRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-startRadius-twipsPerPixel, - currOuterRect.y+currOuterRect.height-twipsPerPixel, - currOuterRect.x+currOuterRect.width-(startRadius-distance)-twipsPerPixel, - currOuterRect.y+currOuterRect.height-distance-twipsPerPixel, aGap); - } - if (endRadius) { - nscoord distance = (startRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+endRadius, - currOuterRect.y+currOuterRect.height-twipsPerPixel, currOuterRect.x+(endRadius-distance), - currOuterRect.y+currOuterRect.height-distance-twipsPerPixel, aGap); - } + nsRect borderInside(currOuterRect); + // try to subtract one pixel from each side of the outer rect, but only if + // that side has any extra space left to shrink + if (aInnerRect.x > borderInside.x) { // shrink left + borderInside.x += twipsPerPixel; + borderInside.width -= twipsPerPixel; } - else if (aWhichSide == NS_SIDE_LEFT) { - if (startRadius) { - // Connecting line between left/bottom - nscoord distance = (endRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+distance, - currOuterRect.y+currOuterRect.height-twipsPerPixel-(startRadius-distance), - currOuterRect.x, currOuterRect.y+currOuterRect.height-twipsPerPixel-startRadius, aGap); - } - if (endRadius) { - // Connecting line between left/top - nscoord distance = (endRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+distance, currOuterRect.y+(endRadius-distance), - currOuterRect.x, currOuterRect.y+endRadius, aGap); - } - } - else if (aWhichSide == NS_SIDE_RIGHT) { - if (startRadius) { - // Connecting line between right/top - nscoord distance = (startRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-distance-twipsPerPixel, - //currOuterRect.y-2, - currOuterRect.y+(startRadius-distance), - currOuterRect.x+currOuterRect.width-twipsPerPixel, - //currOuterRect.y-2, aGap); - currOuterRect.y+startRadius, aGap); - } - if (endRadius) { - // Connecting line between right/bottom - nscoord distance = (endRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-twipsPerPixel-distance, - currOuterRect.y+currOuterRect.height-twipsPerPixel-(endRadius-distance), - currOuterRect.x+currOuterRect.width-twipsPerPixel, - currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius, aGap); - } + if (borderInside.x+borderInside.width > aInnerRect.x+aInnerRect.width) // shrink right + borderInside.width -= twipsPerPixel; + + if (aInnerRect.y > borderInside.y) { // shrink top + borderInside.y += twipsPerPixel; + borderInside.height -= twipsPerPixel; } + if (borderInside.y+borderInside.height > aInnerRect.y+aInnerRect.height) // shrink bottom + borderInside.height -= twipsPerPixel; + if (!aCompositeColors->mTransparent) { + nsPoint theSide[MAX_POLY_POINTS]; + PRInt32 np = MakeSide(theSide, aRenderingContext, aWhichSide, newOuterRect, borderInside, 0, + BORDER_FULL, 1.0f, twipsPerPixel); + NS_ASSERTION(np == 2, "Composite border should always be single pixel!"); + aRenderingContext.SetColor(aCompositeColors->mColor); + DrawLine(aRenderingContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); + + if (aWhichSide == NS_SIDE_TOP) { + if (startRadius) { + // Connecting line between top/left + nscoord distance = (startRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+startRadius, + currOuterRect.y, + currOuterRect.x+startRadius-distance, + currOuterRect.y+distance, + aGap); + } + if (endRadius) { + // Connecting line between top/right + nscoord distance = (endRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel, + currOuterRect.y, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance, + currOuterRect.y+distance, + aGap); + } + } + else if (aWhichSide == NS_SIDE_BOTTOM) { + if (startRadius) { + // Connecting line between bottom/left + nscoord distance = (startRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+startRadius, + currOuterRect.y+currOuterRect.height-twipsPerPixel, + currOuterRect.x+startRadius-distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-distance, + aGap); + } + if (endRadius) { + // Connecting line between bottom/right + nscoord distance = (endRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel, + currOuterRect.y+currOuterRect.height-twipsPerPixel, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-distance, + aGap); + } + } + else if (aWhichSide == NS_SIDE_LEFT) { + if (startRadius) { + // Connecting line between left/top + nscoord distance = (startRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+distance, + currOuterRect.y+startRadius-distance, + currOuterRect.x, + currOuterRect.y+startRadius, + aGap); + } + if (endRadius) { + // Connecting line between left/bottom + nscoord distance = (endRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius+distance, + currOuterRect.x, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius, + aGap); + } + } + else if (aWhichSide == NS_SIDE_RIGHT) { + if (startRadius) { + // Connecting line between right/top + nscoord distance = (startRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-twipsPerPixel-distance, + currOuterRect.y+startRadius-distance, + currOuterRect.x+currOuterRect.width-twipsPerPixel, + currOuterRect.y+startRadius, + aGap); + } + if (endRadius) { + // Connecting line between right/bottom + nscoord distance = (endRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-twipsPerPixel-distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius+distance, + currOuterRect.x+currOuterRect.width-twipsPerPixel, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius, + aGap); + } + } + } + if (aCompositeColors->mNext) aCompositeColors = aCompositeColors->mNext; - currOuterRect.x += twipsPerPixel; - currOuterRect.y += twipsPerPixel; - currOuterRect.width -= 2*twipsPerPixel; - currOuterRect.height -= 2*twipsPerPixel; - startRadius -= twipsPerPixel; if (startRadius < 0) startRadius = 0; - endRadius -= twipsPerPixel; if (endRadius < 0) endRadius = 0; + + currOuterRect = borderInside; + shrinkage -= twipsPerPixel; + + startRadius -= twipsPerPixel; + if (startRadius < 0) startRadius = 0; + endRadius -= twipsPerPixel; + if (endRadius < 0) endRadius = 0; } } diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index 5be6e1147be..917faad2d87 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -1764,11 +1764,29 @@ void nsCSSRendering::DrawCompositeSide(nsIRenderingContext& aRenderingContext, // up the -moz-border-radius gauntlet. // Alternatively we could add support for a -moz-border-diagonal property, which is // what this code actually draws (instead of a curve). - nscoord startRadius, endRadius; - startRadius = aBorderRadii[aWhichSide]; - endRadius = (aWhichSide == NS_SIDE_LEFT) ? aBorderRadii[0] : aBorderRadii[aWhichSide+1]; - PRInt32 level = 0; - while (currOuterRect.width > aInnerRect.width) { + + // determine the the number of pixels we need to draw for this side + // and the start and end radii + nscoord shrinkage, startRadius, endRadius; + if (aWhichSide == NS_SIDE_TOP) { + shrinkage = aInnerRect.y - aOuterRect.y; + startRadius = aBorderRadii[0]; + endRadius = aBorderRadii[1]; + } else if (aWhichSide == NS_SIDE_BOTTOM) { + shrinkage = (aOuterRect.height+aOuterRect.y) - (aInnerRect.height+aInnerRect.y); + startRadius = aBorderRadii[3]; + endRadius = aBorderRadii[2]; + } else if (aWhichSide == NS_SIDE_RIGHT) { + shrinkage = (aOuterRect.width+aOuterRect.x) - (aInnerRect.width+aInnerRect.x); + startRadius = aBorderRadii[1]; + endRadius = aBorderRadii[2]; + } else if (aWhichSide == NS_SIDE_LEFT) { + shrinkage = aInnerRect.x - aOuterRect.x; + startRadius = aBorderRadii[0]; + endRadius = aBorderRadii[3]; + } + + while (shrinkage) { nscoord xshrink = 0; nscoord yshrink = 0; nscoord widthshrink = 0; @@ -1785,122 +1803,163 @@ void nsCSSRendering::DrawCompositeSide(nsIRenderingContext& aRenderingContext, } } + // subtract any rounded pixels from the outer rect nsRect newOuterRect(currOuterRect); newOuterRect.x += xshrink; newOuterRect.y += yshrink; newOuterRect.width -= widthshrink; newOuterRect.height -= heightshrink; - nsRect borderInside(newOuterRect.x+twipsPerPixel, newOuterRect.y+twipsPerPixel, - newOuterRect.width - 2*twipsPerPixel, - newOuterRect.height - 2*twipsPerPixel); - nsPoint theSide[MAX_POLY_POINTS]; - PRInt32 np = MakeSide(theSide, aRenderingContext, aWhichSide, newOuterRect, borderInside, 0, - BORDER_FULL, 1.0f, twipsPerPixel); - NS_ASSERTION(np == 2, "Composite border should always be single pixel!"); - aRenderingContext.SetColor(aCompositeColors->mColor); - DrawLine(aRenderingContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); - - if (aWhichSide == NS_SIDE_TOP) { - if (startRadius) { - // Connecting line between top/left - nscoord distance = (startRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+startRadius, currOuterRect.y, - currOuterRect.x+(startRadius-distance), currOuterRect.y+distance, aGap); - } - if (endRadius) { - // Connecting line between top/right - nscoord distance = (endRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel, currOuterRect.y, - currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance, - currOuterRect.y+distance, aGap); - } - } - else if (aWhichSide == NS_SIDE_BOTTOM) { - if (startRadius) { - // Connecting line between bottom/right - nscoord distance = (endRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-startRadius-twipsPerPixel, - currOuterRect.y+currOuterRect.height-twipsPerPixel, - currOuterRect.x+currOuterRect.width-(startRadius-distance)-twipsPerPixel, - currOuterRect.y+currOuterRect.height-distance-twipsPerPixel, aGap); - } - if (endRadius) { - nscoord distance = (startRadius+twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance += twipsPerPixel - remainder; - DrawLine(aRenderingContext, currOuterRect.x+endRadius, - currOuterRect.y+currOuterRect.height-twipsPerPixel, currOuterRect.x+(endRadius-distance), - currOuterRect.y+currOuterRect.height-distance-twipsPerPixel, aGap); - } + nsRect borderInside(currOuterRect); + // try to subtract one pixel from each side of the outer rect, but only if + // that side has any extra space left to shrink + if (aInnerRect.x > borderInside.x) { // shrink left + borderInside.x += twipsPerPixel; + borderInside.width -= twipsPerPixel; } - else if (aWhichSide == NS_SIDE_LEFT) { - if (startRadius) { - // Connecting line between left/bottom - nscoord distance = (endRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+distance, - currOuterRect.y+currOuterRect.height-twipsPerPixel-(startRadius-distance), - currOuterRect.x, currOuterRect.y+currOuterRect.height-twipsPerPixel-startRadius, aGap); - } - if (endRadius) { - // Connecting line between left/top - nscoord distance = (endRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+distance, currOuterRect.y+(endRadius-distance), - currOuterRect.x, currOuterRect.y+endRadius, aGap); - } - } - else if (aWhichSide == NS_SIDE_RIGHT) { - if (startRadius) { - // Connecting line between right/top - nscoord distance = (startRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-distance-twipsPerPixel, - //currOuterRect.y-2, - currOuterRect.y+(startRadius-distance), - currOuterRect.x+currOuterRect.width-twipsPerPixel, - //currOuterRect.y-2, aGap); - currOuterRect.y+startRadius, aGap); - } - if (endRadius) { - // Connecting line between right/bottom - nscoord distance = (endRadius-twipsPerPixel)/2; - nscoord remainder = distance%twipsPerPixel; - if (remainder) - distance -= remainder; - DrawLine(aRenderingContext, currOuterRect.x+currOuterRect.width-twipsPerPixel-distance, - currOuterRect.y+currOuterRect.height-twipsPerPixel-(endRadius-distance), - currOuterRect.x+currOuterRect.width-twipsPerPixel, - currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius, aGap); - } + if (borderInside.x+borderInside.width > aInnerRect.x+aInnerRect.width) // shrink right + borderInside.width -= twipsPerPixel; + + if (aInnerRect.y > borderInside.y) { // shrink top + borderInside.y += twipsPerPixel; + borderInside.height -= twipsPerPixel; } + if (borderInside.y+borderInside.height > aInnerRect.y+aInnerRect.height) // shrink bottom + borderInside.height -= twipsPerPixel; + if (!aCompositeColors->mTransparent) { + nsPoint theSide[MAX_POLY_POINTS]; + PRInt32 np = MakeSide(theSide, aRenderingContext, aWhichSide, newOuterRect, borderInside, 0, + BORDER_FULL, 1.0f, twipsPerPixel); + NS_ASSERTION(np == 2, "Composite border should always be single pixel!"); + aRenderingContext.SetColor(aCompositeColors->mColor); + DrawLine(aRenderingContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); + + if (aWhichSide == NS_SIDE_TOP) { + if (startRadius) { + // Connecting line between top/left + nscoord distance = (startRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+startRadius, + currOuterRect.y, + currOuterRect.x+startRadius-distance, + currOuterRect.y+distance, + aGap); + } + if (endRadius) { + // Connecting line between top/right + nscoord distance = (endRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel, + currOuterRect.y, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance, + currOuterRect.y+distance, + aGap); + } + } + else if (aWhichSide == NS_SIDE_BOTTOM) { + if (startRadius) { + // Connecting line between bottom/left + nscoord distance = (startRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+startRadius, + currOuterRect.y+currOuterRect.height-twipsPerPixel, + currOuterRect.x+startRadius-distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-distance, + aGap); + } + if (endRadius) { + // Connecting line between bottom/right + nscoord distance = (endRadius+twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance += twipsPerPixel - remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel, + currOuterRect.y+currOuterRect.height-twipsPerPixel, + currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-distance, + aGap); + } + } + else if (aWhichSide == NS_SIDE_LEFT) { + if (startRadius) { + // Connecting line between left/top + nscoord distance = (startRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+distance, + currOuterRect.y+startRadius-distance, + currOuterRect.x, + currOuterRect.y+startRadius, + aGap); + } + if (endRadius) { + // Connecting line between left/bottom + nscoord distance = (endRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius+distance, + currOuterRect.x, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius, + aGap); + } + } + else if (aWhichSide == NS_SIDE_RIGHT) { + if (startRadius) { + // Connecting line between right/top + nscoord distance = (startRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-twipsPerPixel-distance, + currOuterRect.y+startRadius-distance, + currOuterRect.x+currOuterRect.width-twipsPerPixel, + currOuterRect.y+startRadius, + aGap); + } + if (endRadius) { + // Connecting line between right/bottom + nscoord distance = (endRadius-twipsPerPixel)/2; + nscoord remainder = distance%twipsPerPixel; + if (remainder) + distance -= remainder; + DrawLine(aRenderingContext, + currOuterRect.x+currOuterRect.width-twipsPerPixel-distance, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius+distance, + currOuterRect.x+currOuterRect.width-twipsPerPixel, + currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius, + aGap); + } + } + } + if (aCompositeColors->mNext) aCompositeColors = aCompositeColors->mNext; - currOuterRect.x += twipsPerPixel; - currOuterRect.y += twipsPerPixel; - currOuterRect.width -= 2*twipsPerPixel; - currOuterRect.height -= 2*twipsPerPixel; - startRadius -= twipsPerPixel; if (startRadius < 0) startRadius = 0; - endRadius -= twipsPerPixel; if (endRadius < 0) endRadius = 0; + + currOuterRect = borderInside; + shrinkage -= twipsPerPixel; + + startRadius -= twipsPerPixel; + if (startRadius < 0) startRadius = 0; + endRadius -= twipsPerPixel; + if (endRadius < 0) endRadius = 0; } } diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index f2f1694d500..1b647378ca1 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -3333,7 +3333,7 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, const nsCSSStruct& aD } } - // border-colors: color, string + // border-colors: color, string, enum if (marginData.mBorderColors) { nscolor borderColor; nscolor unused = NS_RGB(0,0,0); @@ -3343,10 +3343,14 @@ nsRuleNode::ComputeBorderData(nsStyleStruct* aStartStruct, const nsCSSStruct& aD // Some composite border color information has been specified for this // border side. border->EnsureBorderColors(); + border->ClearBorderColors(i); nsCSSValueList* list = marginData.mBorderColors[i]; while (list) { if (SetColor(list->mValue, unused, mPresContext, borderColor, inherited)) - border->AppendBorderColor(i, borderColor); + border->AppendBorderColor(i, borderColor, PR_FALSE); + else if (eCSSUnit_Enumerated == list->mValue.GetUnit() && + NS_STYLE_COLOR_TRANSPARENT == list->mValue.GetIntValue()) + border->AppendBorderColor(i, nsnull, PR_TRUE); list = list->mNext; } } diff --git a/mozilla/layout/style/nsStyleStruct.h b/mozilla/layout/style/nsStyleStruct.h index c8914df4608..5c7dbb4b92b 100644 --- a/mozilla/layout/style/nsStyleStruct.h +++ b/mozilla/layout/style/nsStyleStruct.h @@ -284,18 +284,20 @@ protected: struct nsBorderColors { nsBorderColors* mNext; nscolor mColor; - + PRBool mTransparent; + nsBorderColors* CopyColors() { nsBorderColors* next = nsnull; if (mNext) next = mNext->CopyColors(); - return new nsBorderColors(mColor, next); + return new nsBorderColors(mColor, mTransparent, next); } nsBorderColors() :mNext(nsnull) { mColor = NS_RGB(0,0,0); }; - nsBorderColors(const nscolor& aColor, nsBorderColors* aNext=nsnull) { + nsBorderColors(const nscolor& aColor, PRBool aTransparent, nsBorderColors* aNext=nsnull) { mColor = aColor; + mTransparent = aTransparent; mNext = aNext; } @@ -339,6 +341,13 @@ struct nsStyleBorder: public nsStyleStruct { } } + void ClearBorderColors(PRUint8 aSide) { + if (mBorderColors[aSide]) { + delete mBorderColors[aSide]; + mBorderColors[aSide] = nsnull; + } + } + PRBool GetBorder(nsMargin& aBorder) const { if (mHasCachedBorder) { @@ -391,10 +400,10 @@ struct nsStyleBorder: public nsStyleStruct { *aColors = mBorderColors[aIndex]; } - void AppendBorderColor(PRInt32 aIndex, nscolor aColor) + void AppendBorderColor(PRInt32 aIndex, nscolor aColor, PRBool aTransparent) { NS_ASSERTION(aIndex >= 0 && aIndex <= 3, "bad side for composite border color"); - nsBorderColors* colorEntry = new nsBorderColors(aColor); + nsBorderColors* colorEntry = new nsBorderColors(aColor, aTransparent); if (!mBorderColors[aIndex]) mBorderColors[aIndex] = colorEntry; else {