diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index f79729cedd7..6b5dc4fe7fb 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -341,7 +341,7 @@ protected: bool GatherMedia(nsMediaList* aMedia, bool aInAtRule); bool ParseMediaQuery(bool aInAtRule, nsMediaQuery **aQuery, - bool *aParsedSomething, bool *aHitStop); + bool *aHitStop); bool ParseMediaQueryExpression(nsMediaQuery* aQuery); void ProcessImport(const nsString& aURLSpec, nsMediaList* aMedia, @@ -1177,13 +1177,8 @@ CSSParserImpl::ParseMediaList(const nsSubstring& aBuffer, // to a media query. (The main substative difference is the relative // precedence of commas and paretheses.) - if (!GatherMedia(aMediaList, PR_FALSE)) { - aMediaList->Clear(); - aMediaList->SetNonEmpty(); // don't match anything - if (!mHTMLMediaMode) { - OUTPUT_ERROR(); - } - } + GatherMedia(aMediaList, false); // can only fail on low-level error (OOM) + nsresult rv = mScanner.GetLowLevelError(); CLEAR_ERROR(); ReleaseScanner(); @@ -1627,11 +1622,9 @@ CSSParserImpl::ParseURLOrString(nsString& aURL) bool CSSParserImpl::ParseMediaQuery(bool aInAtRule, nsMediaQuery **aQuery, - bool *aParsedSomething, bool *aHitStop) { *aQuery = nsnull; - *aParsedSomething = PR_FALSE; *aHitStop = PR_FALSE; // "If the comma-separated list is the empty list it is assumed to @@ -1656,9 +1649,8 @@ CSSParserImpl::ParseMediaQuery(bool aInAtRule, } UngetToken(); - *aParsedSomething = PR_TRUE; - - nsAutoPtr query(new nsMediaQuery); + nsMediaQuery* query = new nsMediaQuery; + *aQuery = query; if (!query) { mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY); return PR_FALSE; @@ -1735,7 +1727,6 @@ CSSParserImpl::ParseMediaQuery(bool aInAtRule, query->SetHadUnknownExpression(); } } - *aQuery = query.forget(); return PR_TRUE; } @@ -1747,13 +1738,17 @@ CSSParserImpl::GatherMedia(nsMediaList* aMedia, { for (;;) { nsAutoPtr query; - bool parsedSomething, hitStop; + bool hitStop; if (!ParseMediaQuery(aInAtRule, getter_Transfers(query), - &parsedSomething, &hitStop)) { + &hitStop)) { NS_ASSERTION(!hitStop, "should return true when hit stop"); + OUTPUT_ERROR(); if (NS_FAILED(mScanner.GetLowLevelError())) { return PR_FALSE; } + if (query) { + query->SetHadUnknownExpression(); + } if (aInAtRule) { const PRUnichar stopChars[] = { PRUnichar(','), PRUnichar('{'), PRUnichar(';'), PRUnichar(0) }; @@ -1768,9 +1763,6 @@ CSSParserImpl::GatherMedia(nsMediaList* aMedia, hitStop = PR_TRUE; } } - if (parsedSomething) { - aMedia->SetNonEmpty(); - } if (query) { nsresult rv = aMedia->AppendQuery(query); if (NS_FAILED(rv)) { diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index cf6d6df3157..031f59d8212 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -542,8 +542,7 @@ NS_IMPL_RELEASE(nsMediaList) nsMediaList::nsMediaList() - : mIsEmpty(PR_TRUE) - , mStyleSheet(nsnull) + : mStyleSheet(nsnull) { } @@ -556,10 +555,6 @@ nsMediaList::GetText(nsAString& aMediaText) { aMediaText.Truncate(); - if (mArray.Length() == 0 && !mIsEmpty) { - aMediaText.AppendLiteral("not all"); - } - for (PRInt32 i = 0, i_end = mArray.Length(); i < i_end; ++i) { nsMediaQuery* query = mArray[i]; NS_ENSURE_TRUE(query, NS_ERROR_FAILURE); @@ -601,7 +596,7 @@ nsMediaList::Matches(nsPresContext* aPresContext, return PR_TRUE; } } - return mIsEmpty; + return mArray.IsEmpty(); } nsresult @@ -624,7 +619,6 @@ nsMediaList::Clone(nsMediaList** aResult) return NS_ERROR_OUT_OF_MEMORY; } } - result->mIsEmpty = mIsEmpty; NS_ADDREF(*aResult = result); return NS_OK; } diff --git a/layout/style/nsIMediaList.h b/layout/style/nsIMediaList.h index d07f076d2d4..7372c72725e 100644 --- a/layout/style/nsIMediaList.h +++ b/layout/style/nsIMediaList.h @@ -205,11 +205,7 @@ public: PRInt32 Count() { return mArray.Length(); } nsMediaQuery* MediumAt(PRInt32 aIndex) { return mArray[aIndex]; } - void Clear() { mArray.Clear(); mIsEmpty = PR_TRUE; } - // a media list with no items may not represent the lack of a media - // list; it could represent the empty string or something with parser - // errors, which means that the media list should never match - void SetNonEmpty() { mIsEmpty = PR_FALSE; } + void Clear() { mArray.Clear(); } protected: ~nsMediaList(); @@ -218,7 +214,6 @@ protected: nsresult Append(const nsAString & aOldMedium); nsTArray > mArray; - bool mIsEmpty; // not refcounted; sheet will let us know when it goes away // mStyleSheet is the sheet that needs to be dirtied when this medialist // changes diff --git a/layout/style/test/test_media_queries.html b/layout/style/test/test_media_queries.html index a89a2555838..074e323d7d7 100644 --- a/layout/style/test/test_media_queries.html +++ b/layout/style/test/test_media_queries.html @@ -79,7 +79,7 @@ function run() { var sheet = parse_test_style_element.sheet; // XXX yikes, not live! if (sheet.cssRules.length == 1 && sheet.cssRules[0].type == CSSRule.MEDIA_RULE) - return sheet.cssRules[0].media.mediaText != "screen"; + return sheet.cssRules[0].media.mediaText != "screen, not all"; ok(false, "unexpected result testing whether query " + q + " is parseable"); return true; // doesn't matter, we already failed