From f95d3a13e2657bc6c6fc25539e2c5d0a18ec6812 Mon Sep 17 00:00:00 2001 From: "harishd%netscape.com" Date: Fri, 22 Jan 1999 22:24:05 +0000 Subject: [PATCH] Got stylecontext info into PaintBorder() for displaying CSS borders. git-svn-id: svn://10.0.0.236/trunk@18351 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCSSRendering.cpp | 108 ++++++++++++------ .../layout/html/style/src/nsCSSRendering.cpp | 108 ++++++++++++------ 2 files changed, 148 insertions(+), 68 deletions(-) diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index cba2f38b02d..54b342ea476 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -27,6 +27,7 @@ #include "nsIFrameImageLoader.h" #include "nsIStyleContext.h" #include "nsGlobalVariables.h" +#include "nsStyleUtil.h" #define BORDER_FULL 0 //entire side #define BORDER_INSIDE 1 //inside half @@ -36,7 +37,6 @@ #define DOT_LENGTH 1 //square #define DASH_LENGTH 3 //3 times longer than dot - // Draw a line, skipping that portion which crosses aGap. aGap defines a rectangle gap // This services fieldset legends and only works for coords defining horizontal lines. void nsCSSRendering::DrawLine (nsIRenderingContext& aContext, @@ -124,8 +124,9 @@ void nsCSSRendering::FillPolygon (nsIRenderingContext& aContext, * Make a bevel color */ nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style, - nscolor baseColor, - PRBool printing) + nscolor aBackgroundColor, + nscolor aElementColor, + PRBool printing,PRBool aSpecialCase) { PRBool blackLines = nsGlobalVariables::Instance()->GetBlackLines(); @@ -142,11 +143,15 @@ nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style, { // Given a background color and a border color // calculate the color used for the shading - NS_Get3DColors(colors, baseColor); + if(aSpecialCase) + NS_GetSpecial3DColors(colors, aBackgroundColor, aElementColor); + else + NS_Get3DColors(colors, aBackgroundColor); } - if ((style == NS_STYLE_BORDER_STYLE_OUTSET) || + if ((style == NS_STYLE_BORDER_STYLE_BG_OUTSET) || + (style == NS_STYLE_BORDER_STYLE_OUTSET) || (style == NS_STYLE_BORDER_STYLE_RIDGE)) { // Flip colors for these two border style switch (whichSide) { @@ -354,8 +359,10 @@ PRIntn nsCSSRendering::MakeSide(nsPoint aPoints[], void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, PRIntn whichSide, const PRUint8 borderStyle, - const nscolor borderColor, - const nsRect& borderOutside, + const nscolor borderColor, + const nscolor aElementColor, + const nscolor aBackgroundColor, + const nsRect& borderOutside, const nsRect& borderInside, PRBool printing, nscoord twipsPerPixel, @@ -382,7 +389,8 @@ void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, ((theStyle == NS_STYLE_BORDER_STYLE_RIDGE) ? NS_STYLE_BORDER_STYLE_GROOVE : NS_STYLE_BORDER_STYLE_RIDGE), - theColor, printing)); + aBackgroundColor, aElementColor, + printing, PR_TRUE)); if (2 == np) { //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); @@ -392,7 +400,8 @@ void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, } np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside, BORDER_OUTSIDE, 0.5f, twipsPerPixel); - aContext.SetColor ( MakeBevelColor (whichSide, theStyle, theColor,printing)); + aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor, + aElementColor, printing, PR_TRUE)); if (2 == np) { //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); @@ -437,11 +446,26 @@ void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, } break; - case NS_STYLE_BORDER_STYLE_OUTSET: - case NS_STYLE_BORDER_STYLE_INSET: + case NS_STYLE_BORDER_STYLE_BG_OUTSET: + case NS_STYLE_BORDER_STYLE_BG_INSET: np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside, BORDER_FULL, 1.0f, twipsPerPixel); - aContext.SetColor ( MakeBevelColor (whichSide, theStyle, theColor,printing)); + aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor, + aElementColor,printing, PR_FALSE)); + if (2 == np) { + //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); + DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); + } else { + //aContext.FillPolygon (theSide, np); + FillPolygon (aContext, theSide, np, aGap); + } + break; + case NS_STYLE_BORDER_STYLE_OUTSET: + case NS_STYLE_BORDER_STYLE_INSET: + np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside, + BORDER_FULL, 1.0f, twipsPerPixel); + aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor, + aElementColor,printing, PR_TRUE)); if (2 == np) { //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); @@ -1336,14 +1360,18 @@ void nsCSSRendering::PaintBorder(nsIPresContext& aPresContext, nsIFrame* aForFrame, const nsRect& aDirtyRect, const nsRect& aBorderArea, - const nsStyleSpacing& aStyle, - PRIntn aSkipSides, + const nsStyleSpacing& aBorderStyle, + nsIStyleContext* aStyleContext, + PRIntn aSkipSides, nsRect* aGap) { PRIntn cnt; nsMargin border; PRBool printing = nsGlobalVariables::Instance()->GetPrinting(&aPresContext); - aStyle.CalcBorderFor(aForFrame, border); + const nsStyleColor* elemColor = (const nsStyleColor*)aStyleContext->GetStyleData(eStyleStruct_Color); + const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext); + + aBorderStyle.CalcBorderFor(aForFrame, border); if ((0 == border.left) && (0 == border.right) && (0 == border.top) && (0 == border.bottom)) { // Empty border area @@ -1362,13 +1390,13 @@ void nsCSSRendering::PaintBorder(nsIPresContext& aPresContext, //see if any sides are dotted or dashed for (cnt = 0; cnt < 4; cnt++) { - if ((aStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DOTTED) || - (aStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DASHED)) { + if ((aBorderStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DOTTED) || + (aBorderStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DASHED)) { break; } } if (cnt < 4) { - DrawDashedSides(cnt, aRenderingContext,aStyle, + DrawDashedSides(cnt, aRenderingContext,aBorderStyle, inside, outside, aSkipSides, aGap); } @@ -1376,27 +1404,31 @@ void nsCSSRendering::PaintBorder(nsIPresContext& aPresContext, nscoord twipsPerPixel = (nscoord)aPresContext.GetPixelsToTwips(); if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside,outside, printing,twipsPerPixel, aGap); } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } } @@ -1416,10 +1448,14 @@ void nsCSSRendering::PaintBorderEdges(nsIPresContext& aPresContext, const nsRect& aDirtyRect, const nsRect& aBorderArea, nsBorderEdges * aBorderEdges, + nsIStyleContext* aStyleContext, PRIntn aSkipSides, nsRect* aGap) { + const nsStyleColor* elemColor = (const nsStyleColor*)aStyleContext->GetStyleData(eStyleStruct_Color); + const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext); PRBool printing = nsGlobalVariables::Instance()->GetPrinting(&aPresContext); + if (nsnull==aBorderEdges) { // Empty border segments return; } @@ -1458,7 +1494,8 @@ void nsCSSRendering::PaintBorderEdges(nsIPresContext& aPresContext, DrawSide(aRenderingContext, NS_SIDE_TOP, borderEdge->mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside,printing, twipsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside,printing,twipsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside,printing,twipsPerPixel, aGap); } } } diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index cba2f38b02d..54b342ea476 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -27,6 +27,7 @@ #include "nsIFrameImageLoader.h" #include "nsIStyleContext.h" #include "nsGlobalVariables.h" +#include "nsStyleUtil.h" #define BORDER_FULL 0 //entire side #define BORDER_INSIDE 1 //inside half @@ -36,7 +37,6 @@ #define DOT_LENGTH 1 //square #define DASH_LENGTH 3 //3 times longer than dot - // Draw a line, skipping that portion which crosses aGap. aGap defines a rectangle gap // This services fieldset legends and only works for coords defining horizontal lines. void nsCSSRendering::DrawLine (nsIRenderingContext& aContext, @@ -124,8 +124,9 @@ void nsCSSRendering::FillPolygon (nsIRenderingContext& aContext, * Make a bevel color */ nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style, - nscolor baseColor, - PRBool printing) + nscolor aBackgroundColor, + nscolor aElementColor, + PRBool printing,PRBool aSpecialCase) { PRBool blackLines = nsGlobalVariables::Instance()->GetBlackLines(); @@ -142,11 +143,15 @@ nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style, { // Given a background color and a border color // calculate the color used for the shading - NS_Get3DColors(colors, baseColor); + if(aSpecialCase) + NS_GetSpecial3DColors(colors, aBackgroundColor, aElementColor); + else + NS_Get3DColors(colors, aBackgroundColor); } - if ((style == NS_STYLE_BORDER_STYLE_OUTSET) || + if ((style == NS_STYLE_BORDER_STYLE_BG_OUTSET) || + (style == NS_STYLE_BORDER_STYLE_OUTSET) || (style == NS_STYLE_BORDER_STYLE_RIDGE)) { // Flip colors for these two border style switch (whichSide) { @@ -354,8 +359,10 @@ PRIntn nsCSSRendering::MakeSide(nsPoint aPoints[], void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, PRIntn whichSide, const PRUint8 borderStyle, - const nscolor borderColor, - const nsRect& borderOutside, + const nscolor borderColor, + const nscolor aElementColor, + const nscolor aBackgroundColor, + const nsRect& borderOutside, const nsRect& borderInside, PRBool printing, nscoord twipsPerPixel, @@ -382,7 +389,8 @@ void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, ((theStyle == NS_STYLE_BORDER_STYLE_RIDGE) ? NS_STYLE_BORDER_STYLE_GROOVE : NS_STYLE_BORDER_STYLE_RIDGE), - theColor, printing)); + aBackgroundColor, aElementColor, + printing, PR_TRUE)); if (2 == np) { //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); @@ -392,7 +400,8 @@ void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, } np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside, BORDER_OUTSIDE, 0.5f, twipsPerPixel); - aContext.SetColor ( MakeBevelColor (whichSide, theStyle, theColor,printing)); + aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor, + aElementColor, printing, PR_TRUE)); if (2 == np) { //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); @@ -437,11 +446,26 @@ void nsCSSRendering::DrawSide(nsIRenderingContext& aContext, } break; - case NS_STYLE_BORDER_STYLE_OUTSET: - case NS_STYLE_BORDER_STYLE_INSET: + case NS_STYLE_BORDER_STYLE_BG_OUTSET: + case NS_STYLE_BORDER_STYLE_BG_INSET: np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside, BORDER_FULL, 1.0f, twipsPerPixel); - aContext.SetColor ( MakeBevelColor (whichSide, theStyle, theColor,printing)); + aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor, + aElementColor,printing, PR_FALSE)); + if (2 == np) { + //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); + DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); + } else { + //aContext.FillPolygon (theSide, np); + FillPolygon (aContext, theSide, np, aGap); + } + break; + case NS_STYLE_BORDER_STYLE_OUTSET: + case NS_STYLE_BORDER_STYLE_INSET: + np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside, + BORDER_FULL, 1.0f, twipsPerPixel); + aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor, + aElementColor,printing, PR_TRUE)); if (2 == np) { //aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y); DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap); @@ -1336,14 +1360,18 @@ void nsCSSRendering::PaintBorder(nsIPresContext& aPresContext, nsIFrame* aForFrame, const nsRect& aDirtyRect, const nsRect& aBorderArea, - const nsStyleSpacing& aStyle, - PRIntn aSkipSides, + const nsStyleSpacing& aBorderStyle, + nsIStyleContext* aStyleContext, + PRIntn aSkipSides, nsRect* aGap) { PRIntn cnt; nsMargin border; PRBool printing = nsGlobalVariables::Instance()->GetPrinting(&aPresContext); - aStyle.CalcBorderFor(aForFrame, border); + const nsStyleColor* elemColor = (const nsStyleColor*)aStyleContext->GetStyleData(eStyleStruct_Color); + const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext); + + aBorderStyle.CalcBorderFor(aForFrame, border); if ((0 == border.left) && (0 == border.right) && (0 == border.top) && (0 == border.bottom)) { // Empty border area @@ -1362,13 +1390,13 @@ void nsCSSRendering::PaintBorder(nsIPresContext& aPresContext, //see if any sides are dotted or dashed for (cnt = 0; cnt < 4; cnt++) { - if ((aStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DOTTED) || - (aStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DASHED)) { + if ((aBorderStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DOTTED) || + (aBorderStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DASHED)) { break; } } if (cnt < 4) { - DrawDashedSides(cnt, aRenderingContext,aStyle, + DrawDashedSides(cnt, aRenderingContext,aBorderStyle, inside, outside, aSkipSides, aGap); } @@ -1376,27 +1404,31 @@ void nsCSSRendering::PaintBorder(nsIPresContext& aPresContext, nscoord twipsPerPixel = (nscoord)aPresContext.GetPixelsToTwips(); if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside,outside, printing,twipsPerPixel, aGap); } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } if (0 == (aSkipSides & (1<mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } } @@ -1416,10 +1448,14 @@ void nsCSSRendering::PaintBorderEdges(nsIPresContext& aPresContext, const nsRect& aDirtyRect, const nsRect& aBorderArea, nsBorderEdges * aBorderEdges, + nsIStyleContext* aStyleContext, PRIntn aSkipSides, nsRect* aGap) { + const nsStyleColor* elemColor = (const nsStyleColor*)aStyleContext->GetStyleData(eStyleStruct_Color); + const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext); PRBool printing = nsGlobalVariables::Instance()->GetPrinting(&aPresContext); + if (nsnull==aBorderEdges) { // Empty border segments return; } @@ -1458,7 +1494,8 @@ void nsCSSRendering::PaintBorderEdges(nsIPresContext& aPresContext, DrawSide(aRenderingContext, NS_SIDE_TOP, borderEdge->mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside,printing, twipsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside, printing,twipsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside,printing,twipsPerPixel, aGap); } } if (0 == (aSkipSides & (1<mStyle, borderEdge->mColor, - inside, outside, printing, twipsPerPixel, aGap); + elemColor->mColor, bgColor->mBackgroundColor, + inside, outside,printing,twipsPerPixel, aGap); } } }