From a47578fd0ac9b4e162d44a382cbd58df65eaf81a Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Mon, 30 Apr 2007 20:50:31 -0700 Subject: [PATCH] Fixing parsing of opacity components of rgba() and hsla() that are out of the0 <= x <= 1 range. Bug 379316, r+sr=dbaron --- layout/reftests/bugs/379316-1-ref.html | 25 +++++++++++++++++++++++++ layout/reftests/bugs/379316-1.html | 25 +++++++++++++++++++++++++ layout/reftests/bugs/reftest.list | 1 + layout/style/nsCSSParser.cpp | 14 ++++++++++---- 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 layout/reftests/bugs/379316-1-ref.html create mode 100644 layout/reftests/bugs/379316-1.html diff --git a/layout/reftests/bugs/379316-1-ref.html b/layout/reftests/bugs/379316-1-ref.html new file mode 100644 index 00000000000..7f5316f2d4b --- /dev/null +++ b/layout/reftests/bugs/379316-1-ref.html @@ -0,0 +1,25 @@ + + + +
Test 1
+
Test 2
+
Test 3
+
Test 4
+
Test 5
+
Test 6
+
Test 7
+
Test 8
+ +
Test 9
+
Test 10
+
Test 11
+
Test 12
+ +
Test 13
+
Test 14
+
Test 15
+
Test 16
+ +
Test 17
+ + diff --git a/layout/reftests/bugs/379316-1.html b/layout/reftests/bugs/379316-1.html new file mode 100644 index 00000000000..6e713a7af0f --- /dev/null +++ b/layout/reftests/bugs/379316-1.html @@ -0,0 +1,25 @@ + + + +
Test 1
+
Test 2
+
Test 3
+
Test 4
+
Test 5
+
Test 6
+
Test 7
+
Test 8
+ +
Test 9
+
Test 10
+
Test 11
+
Test 12
+ +
Test 13
+
Test 14
+
Test 15
+
Test 16
+ +
Test 17
+ + diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 3612a398388..cb088901ac2 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -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 diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index b84028f2c56..a55b6c3af75 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -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; }