Part of fix to allow background on BODY element to be inherited. b=47127 r=pierre

This commit is contained in:
attinasi%netscape.com 2000-08-04 20:44:08 +00:00
parent 7f0e5cf2cb
commit 7701e70031
7 changed files with 120 additions and 72 deletions

View File

@ -566,7 +566,8 @@ BodyFixupRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aP
canvasStyleColor->mBackgroundXPosition = styleColor->mBackgroundXPosition; canvasStyleColor->mBackgroundXPosition = styleColor->mBackgroundXPosition;
canvasStyleColor->mBackgroundYPosition = styleColor->mBackgroundYPosition; canvasStyleColor->mBackgroundYPosition = styleColor->mBackgroundYPosition;
canvasStyleColor->mBackgroundImage = styleColor->mBackgroundImage; canvasStyleColor->mBackgroundImage = styleColor->mBackgroundImage;
canvasStyleColor->mBackgroundFlags = styleColor->mBackgroundFlags; canvasStyleColor->mBackgroundFlags = (styleColor->mBackgroundFlags & ~NS_STYLE_BG_PROPAGATED_TO_PARENT);
canvasStyleColor->mBackgroundFlags |= NS_STYLE_BG_PROPAGATED_FROM_CHILD;
bFixedBackground = bFixedBackground =
canvasStyleColor->mBackgroundAttachment == NS_STYLE_BG_ATTACHMENT_FIXED ? PR_TRUE : PR_FALSE; canvasStyleColor->mBackgroundAttachment == NS_STYLE_BG_ATTACHMENT_FIXED ? PR_TRUE : PR_FALSE;
@ -579,7 +580,14 @@ BodyFixupRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aP
NS_STYLE_BG_PROPAGATED_TO_PARENT; NS_STYLE_BG_PROPAGATED_TO_PARENT;
// NOTE: if this was the BODY then // NOTE: if this was the BODY then
// this flag is somewhat erroneous // this flag is somewhat erroneous
// as it was propogated to the GRANDPARENT // as it was propogated to the GRANDPARENT!
// We patch this next by marking the HTML's
// background as propagated too, so we can walk
// up the chain of contexts that have to propagation
// bit set (see nsCSSStyleRule.cpp MapDeclarationColorInto)
if (styleColor == bodyStyleColor) {
htmlStyleColor->mBackgroundFlags |= NS_STYLE_BG_PROPAGATED_TO_PARENT;
}
} }
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;

View File

@ -2032,11 +2032,23 @@ MapDeclarationColorInto(nsICSSDeclaration* aDeclaration,
if (eCSSUnit_Inherit == ourColor->mBackColor.GetUnit()) { // do inherit first, so SetColor doesn't do it if (eCSSUnit_Inherit == ourColor->mBackColor.GetUnit()) { // do inherit first, so SetColor doesn't do it
const nsStyleColor* inheritColor = parentColor; const nsStyleColor* inheritColor = parentColor;
if (inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT) { if (inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT) {
// walk up the contexts until we get to a context that does not have its
// background propagated to its parent (or a context that has had its background
// propagated from its child)
if (nsnull != aParentContext) { if (nsnull != aParentContext) {
nsIStyleContext* grandParentContext = aParentContext->GetParent(); nsCOMPtr<nsIStyleContext> higherContext = getter_AddRefs(aParentContext->GetParent());
if (nsnull != grandParentContext) { do {
inheritColor = (const nsStyleColor*)grandParentContext->GetStyleData(eStyleStruct_Color); if (higherContext) {
} inheritColor = (const nsStyleColor*)higherContext->GetStyleData(eStyleStruct_Color);
if (inheritColor &&
(!(inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT)) ||
(inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_FROM_CHILD)) {
// done walking up the higher contexts
break;
}
higherContext = getter_AddRefs(higherContext->GetParent());
}
} while (higherContext);
} }
} }
color->mBackgroundColor = inheritColor->mBackgroundColor; color->mBackgroundColor = inheritColor->mBackgroundColor;

View File

@ -2072,8 +2072,10 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
{ {
NS_ASSERTION(aForFrame, "Frame is expected to be provided to PaintBackground"); NS_ASSERTION(aForFrame, "Frame is expected to be provided to PaintBackground");
PRBool transparentBG = NS_STYLE_BG_COLOR_TRANSPARENT == // consider it transparent if transparent is set, or if it is propagated to the parent
(aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT); PRBool transparentBG =
(NS_STYLE_BG_COLOR_TRANSPARENT == (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)) ||
(aColor.mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT);
float percent; float percent;
nsStyleCoord bordStyleRadius[4]; nsStyleCoord bordStyleRadius[4];
PRInt16 borderRadii[4],i; PRInt16 borderRadii[4],i;
@ -2208,7 +2210,6 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
if (scrollFrame) { if (scrollFrame) {
nsCOMPtr<nsIScrollableFrame> scrollableFrame ( do_QueryInterface(scrollFrame) ); nsCOMPtr<nsIScrollableFrame> scrollableFrame ( do_QueryInterface(scrollFrame) );
if ( scrollableFrame ) { if ( scrollableFrame ) {
scrollableFrame->GetScrolledFrame(aPresContext, scrolledFrame); scrollableFrame->GetScrolledFrame(aPresContext, scrolledFrame);
if (scrolledFrame) { if (scrolledFrame) {
nsRect rect; nsRect rect;
@ -2231,8 +2232,8 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
NS_RELEASE(presShell); NS_RELEASE(presShell);
rootFrame->GetView(aPresContext, (nsIView**)&viewportView); rootFrame->GetView(aPresContext, (nsIView**)&viewportView);
NS_ASSERTION(viewportView, "no viewport view"); NS_ASSERTION(viewportView, "no viewport view");
viewportView->GetDimensions(&viewportArea.width, &viewportArea.height); viewportView->GetDimensions(&viewportArea.width, &viewportArea.height);
} }
} }
@ -2477,30 +2478,28 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
// See if there's a background color specified. The background color // See if there's a background color specified. The background color
// is rendered over the 'border' 'padding' and 'content' areas // is rendered over the 'border' 'padding' and 'content' areas
if (!transparentBG) { if (!transparentBG) {
// get the radius for our border
aSpacing.mBorderRadius.GetTop(bordStyleRadius[0]); //topleft
aSpacing.mBorderRadius.GetRight(bordStyleRadius[1]); //topright
aSpacing.mBorderRadius.GetBottom(bordStyleRadius[2]); //bottomright
aSpacing.mBorderRadius.GetLeft(bordStyleRadius[3]); //bottomleft
for(i=0;i<4;i++) {
// get the radius for our border borderRadii[i] = 0;
aSpacing.mBorderRadius.GetTop(bordStyleRadius[0]); //topleft switch ( bordStyleRadius[i].GetUnit()) {
aSpacing.mBorderRadius.GetRight(bordStyleRadius[1]); //topright case eStyleUnit_Inherit:
aSpacing.mBorderRadius.GetBottom(bordStyleRadius[2]); //bottomright break;
aSpacing.mBorderRadius.GetLeft(bordStyleRadius[3]); //bottomleft case eStyleUnit_Percent:
percent = bordStyleRadius[i].GetPercentValue();
for(i=0;i<4;i++) { borderRadii[i] = (nscoord)(percent * aBorderArea.width);
borderRadii[i] = 0; break;
switch ( bordStyleRadius[i].GetUnit()) { case eStyleUnit_Coord:
case eStyleUnit_Inherit: borderRadii[i] = bordStyleRadius[i].GetCoordValue();
break; break;
case eStyleUnit_Percent: default:
percent = bordStyleRadius[i].GetPercentValue(); break;
borderRadii[i] = (nscoord)(percent * aBorderArea.width); }
break;
case eStyleUnit_Coord:
borderRadii[i] = bordStyleRadius[i].GetCoordValue();
break;
default:
break;
} }
}
// rounded version of the border // rounded version of the border
@ -2515,7 +2514,6 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
aRenderingContext.FillRect(aBorderArea); aRenderingContext.FillRect(aBorderArea);
} }
} }
} }
/** --------------------------------------------------- /** ---------------------------------------------------

View File

@ -566,7 +566,8 @@ BodyFixupRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aP
canvasStyleColor->mBackgroundXPosition = styleColor->mBackgroundXPosition; canvasStyleColor->mBackgroundXPosition = styleColor->mBackgroundXPosition;
canvasStyleColor->mBackgroundYPosition = styleColor->mBackgroundYPosition; canvasStyleColor->mBackgroundYPosition = styleColor->mBackgroundYPosition;
canvasStyleColor->mBackgroundImage = styleColor->mBackgroundImage; canvasStyleColor->mBackgroundImage = styleColor->mBackgroundImage;
canvasStyleColor->mBackgroundFlags = styleColor->mBackgroundFlags; canvasStyleColor->mBackgroundFlags = (styleColor->mBackgroundFlags & ~NS_STYLE_BG_PROPAGATED_TO_PARENT);
canvasStyleColor->mBackgroundFlags |= NS_STYLE_BG_PROPAGATED_FROM_CHILD;
bFixedBackground = bFixedBackground =
canvasStyleColor->mBackgroundAttachment == NS_STYLE_BG_ATTACHMENT_FIXED ? PR_TRUE : PR_FALSE; canvasStyleColor->mBackgroundAttachment == NS_STYLE_BG_ATTACHMENT_FIXED ? PR_TRUE : PR_FALSE;
@ -579,7 +580,14 @@ BodyFixupRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aP
NS_STYLE_BG_PROPAGATED_TO_PARENT; NS_STYLE_BG_PROPAGATED_TO_PARENT;
// NOTE: if this was the BODY then // NOTE: if this was the BODY then
// this flag is somewhat erroneous // this flag is somewhat erroneous
// as it was propogated to the GRANDPARENT // as it was propogated to the GRANDPARENT!
// We patch this next by marking the HTML's
// background as propagated too, so we can walk
// up the chain of contexts that have to propagation
// bit set (see nsCSSStyleRule.cpp MapDeclarationColorInto)
if (styleColor == bodyStyleColor) {
htmlStyleColor->mBackgroundFlags |= NS_STYLE_BG_PROPAGATED_TO_PARENT;
}
} }
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;

View File

@ -2072,8 +2072,10 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
{ {
NS_ASSERTION(aForFrame, "Frame is expected to be provided to PaintBackground"); NS_ASSERTION(aForFrame, "Frame is expected to be provided to PaintBackground");
PRBool transparentBG = NS_STYLE_BG_COLOR_TRANSPARENT == // consider it transparent if transparent is set, or if it is propagated to the parent
(aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT); PRBool transparentBG =
(NS_STYLE_BG_COLOR_TRANSPARENT == (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)) ||
(aColor.mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT);
float percent; float percent;
nsStyleCoord bordStyleRadius[4]; nsStyleCoord bordStyleRadius[4];
PRInt16 borderRadii[4],i; PRInt16 borderRadii[4],i;
@ -2208,7 +2210,6 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
if (scrollFrame) { if (scrollFrame) {
nsCOMPtr<nsIScrollableFrame> scrollableFrame ( do_QueryInterface(scrollFrame) ); nsCOMPtr<nsIScrollableFrame> scrollableFrame ( do_QueryInterface(scrollFrame) );
if ( scrollableFrame ) { if ( scrollableFrame ) {
scrollableFrame->GetScrolledFrame(aPresContext, scrolledFrame); scrollableFrame->GetScrolledFrame(aPresContext, scrolledFrame);
if (scrolledFrame) { if (scrolledFrame) {
nsRect rect; nsRect rect;
@ -2231,8 +2232,8 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
NS_RELEASE(presShell); NS_RELEASE(presShell);
rootFrame->GetView(aPresContext, (nsIView**)&viewportView); rootFrame->GetView(aPresContext, (nsIView**)&viewportView);
NS_ASSERTION(viewportView, "no viewport view"); NS_ASSERTION(viewportView, "no viewport view");
viewportView->GetDimensions(&viewportArea.width, &viewportArea.height); viewportView->GetDimensions(&viewportArea.width, &viewportArea.height);
} }
} }
@ -2477,30 +2478,28 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
// See if there's a background color specified. The background color // See if there's a background color specified. The background color
// is rendered over the 'border' 'padding' and 'content' areas // is rendered over the 'border' 'padding' and 'content' areas
if (!transparentBG) { if (!transparentBG) {
// get the radius for our border
aSpacing.mBorderRadius.GetTop(bordStyleRadius[0]); //topleft
aSpacing.mBorderRadius.GetRight(bordStyleRadius[1]); //topright
aSpacing.mBorderRadius.GetBottom(bordStyleRadius[2]); //bottomright
aSpacing.mBorderRadius.GetLeft(bordStyleRadius[3]); //bottomleft
for(i=0;i<4;i++) {
// get the radius for our border borderRadii[i] = 0;
aSpacing.mBorderRadius.GetTop(bordStyleRadius[0]); //topleft switch ( bordStyleRadius[i].GetUnit()) {
aSpacing.mBorderRadius.GetRight(bordStyleRadius[1]); //topright case eStyleUnit_Inherit:
aSpacing.mBorderRadius.GetBottom(bordStyleRadius[2]); //bottomright break;
aSpacing.mBorderRadius.GetLeft(bordStyleRadius[3]); //bottomleft case eStyleUnit_Percent:
percent = bordStyleRadius[i].GetPercentValue();
for(i=0;i<4;i++) { borderRadii[i] = (nscoord)(percent * aBorderArea.width);
borderRadii[i] = 0; break;
switch ( bordStyleRadius[i].GetUnit()) { case eStyleUnit_Coord:
case eStyleUnit_Inherit: borderRadii[i] = bordStyleRadius[i].GetCoordValue();
break; break;
case eStyleUnit_Percent: default:
percent = bordStyleRadius[i].GetPercentValue(); break;
borderRadii[i] = (nscoord)(percent * aBorderArea.width); }
break;
case eStyleUnit_Coord:
borderRadii[i] = bordStyleRadius[i].GetCoordValue();
break;
default:
break;
} }
}
// rounded version of the border // rounded version of the border
@ -2515,7 +2514,6 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
aRenderingContext.FillRect(aBorderArea); aRenderingContext.FillRect(aBorderArea);
} }
} }
} }
/** --------------------------------------------------- /** ---------------------------------------------------

View File

@ -2032,11 +2032,23 @@ MapDeclarationColorInto(nsICSSDeclaration* aDeclaration,
if (eCSSUnit_Inherit == ourColor->mBackColor.GetUnit()) { // do inherit first, so SetColor doesn't do it if (eCSSUnit_Inherit == ourColor->mBackColor.GetUnit()) { // do inherit first, so SetColor doesn't do it
const nsStyleColor* inheritColor = parentColor; const nsStyleColor* inheritColor = parentColor;
if (inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT) { if (inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT) {
// walk up the contexts until we get to a context that does not have its
// background propagated to its parent (or a context that has had its background
// propagated from its child)
if (nsnull != aParentContext) { if (nsnull != aParentContext) {
nsIStyleContext* grandParentContext = aParentContext->GetParent(); nsCOMPtr<nsIStyleContext> higherContext = getter_AddRefs(aParentContext->GetParent());
if (nsnull != grandParentContext) { do {
inheritColor = (const nsStyleColor*)grandParentContext->GetStyleData(eStyleStruct_Color); if (higherContext) {
} inheritColor = (const nsStyleColor*)higherContext->GetStyleData(eStyleStruct_Color);
if (inheritColor &&
(!(inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT)) ||
(inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_FROM_CHILD)) {
// done walking up the higher contexts
break;
}
higherContext = getter_AddRefs(higherContext->GetParent());
}
} while (higherContext);
} }
} }
color->mBackgroundColor = inheritColor->mBackgroundColor; color->mBackgroundColor = inheritColor->mBackgroundColor;

View File

@ -2032,11 +2032,23 @@ MapDeclarationColorInto(nsICSSDeclaration* aDeclaration,
if (eCSSUnit_Inherit == ourColor->mBackColor.GetUnit()) { // do inherit first, so SetColor doesn't do it if (eCSSUnit_Inherit == ourColor->mBackColor.GetUnit()) { // do inherit first, so SetColor doesn't do it
const nsStyleColor* inheritColor = parentColor; const nsStyleColor* inheritColor = parentColor;
if (inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT) { if (inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT) {
// walk up the contexts until we get to a context that does not have its
// background propagated to its parent (or a context that has had its background
// propagated from its child)
if (nsnull != aParentContext) { if (nsnull != aParentContext) {
nsIStyleContext* grandParentContext = aParentContext->GetParent(); nsCOMPtr<nsIStyleContext> higherContext = getter_AddRefs(aParentContext->GetParent());
if (nsnull != grandParentContext) { do {
inheritColor = (const nsStyleColor*)grandParentContext->GetStyleData(eStyleStruct_Color); if (higherContext) {
} inheritColor = (const nsStyleColor*)higherContext->GetStyleData(eStyleStruct_Color);
if (inheritColor &&
(!(inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_TO_PARENT)) ||
(inheritColor->mBackgroundFlags & NS_STYLE_BG_PROPAGATED_FROM_CHILD)) {
// done walking up the higher contexts
break;
}
higherContext = getter_AddRefs(higherContext->GetParent());
}
} while (higherContext);
} }
} }
color->mBackgroundColor = inheritColor->mBackgroundColor; color->mBackgroundColor = inheritColor->mBackgroundColor;