189533, background-position has low accuracy. Specifically, it was not allowing fractional percentages.

r+sr=dbaron
This commit is contained in:
caillon%returnzero.com 2003-01-19 02:36:04 +00:00
Родитель 3e987a87ce
Коммит 6134063f7b
10 изменённых файлов: 90 добавлений и 72 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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