Fixing parsing of opacity components of rgba() and hsla() that are out of the0 <= x <= 1 range. Bug 379316, r+sr=dbaron

This commit is contained in:
bzbarsky@mit.edu 2007-04-30 20:50:31 -07:00
Родитель ba88c35259
Коммит 982141e191
4 изменённых файлов: 61 добавлений и 4 удалений

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

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<body style="color: black; background: white;">
<div style="opacity: 0">Test 1</div>
<div style="opacity: 0">Test 2</div>
<div style="opacity: 0">Test 3</div>
<div style="opacity: 0">Test 4</div>
<div style="opacity: 1">Test 5</div>
<div style="opacity: 1">Test 6</div>
<div style="opacity: 1">Test 7</div>
<div style="opacity: 1">Test 8</div>
<div style="opacity: 0">Test 9</div>
<div style="opacity: 0">Test 10</div>
<div style="opacity: 0">Test 11</div>
<div style="opacity: 0">Test 12</div>
<div style="opacity: 1">Test 13</div>
<div style="opacity: 1">Test 14</div>
<div style="opacity: 1">Test 15</div>
<div style="opacity: 1">Test 16</div>
<div style="opacity: 0.5">Test 17</div>
</body>
</html>

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

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<body style="background: white">
<div style="opacity: 0">Test 1</div>
<div style="opacity: -1">Test 2</div>
<div style="opacity: -0.5">Test 3</div>
<div style="opacity: -6.7">Test 4</div>
<div style="opacity: 1">Test 5</div>
<div style="opacity: 1.5">Test 6</div>
<div style="opacity: 2">Test 7</div>
<div style="opacity: 7.3">Test 8</div>
<div style="color: rgba(0, 0, 0, 0)">Test 9</div>
<div style="color: rgba(0, 0, 0, -1)">Test 10</div>
<div style="color: rgba(0, 0, 0, -0.5)">Test 11</div>
<div style="color: rgba(0, 0, 0, -6.7)">Test 12</div>
<div style="color: rgba(0, 0, 0, 1)">Test 13</div>
<div style="color: rgba(0, 0, 0, 1.5)">Test 14</div>
<div style="color: rgba(0, 0, 0, 2)">Test 15</div>
<div style="color: rgba(0, 0, 0, 7.3)">Test 16</div>
<div style="color: rgba(0, 0, 0, 0.5)">Test 17</div>
</body>
</html>

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

@ -223,3 +223,4 @@ fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 372037-1.html 372037-1-ref.html # bug 3
fails == 376484-1.html 376484-1-ref.html
== 377603-1.html 377603-1-ref.html
== 378535-1.html 378535-1-ref.html
== 379316-1.html 379316-1-ref.html

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

@ -3155,16 +3155,22 @@ PRBool CSSParserImpl::ParseColorOpacity(nsresult& aErrorCode, PRUint8& aOpacity)
return PR_FALSE;
}
PRInt32 value = nsStyleUtil::FloatToColorComponent(mToken.mNumber);
if (mToken.mNumber < 0.0f) {
mToken.mNumber = 0.0f;
} else if (mToken.mNumber > 1.0f) {
mToken.mNumber = 1.0f;
}
PRUint8 value = nsStyleUtil::FloatToColorComponent(mToken.mNumber);
NS_ASSERTION(fabs(mToken.mNumber - value/255.0f) <= 0.5f,
"FloatToColorComponent did something weird");
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
REPORT_UNEXPECTED_TOKEN(PEExpectedCloseParen);
return PR_FALSE;
}
if (value < 0) value = 0;
if (value > 255) value = 255;
aOpacity = (PRUint8)value;
aOpacity = value;
return PR_TRUE;
}