From d791eef9791c0286c3eab7e8a4a99816b2535329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 11 Dec 2016 19:27:33 +0100 Subject: [PATCH] Bug 1029867: Remove useless nsCSSParser::mHTMLMediaMode. r=heycam MozReview-Commit-ID: AFtd0G4oP3R --- dom/base/ResponsiveImageSelector.cpp | 2 +- dom/html/HTMLSourceElement.cpp | 4 +-- layout/style/CSSStyleSheet.cpp | 5 +-- layout/style/Loader.cpp | 2 +- layout/style/MediaQueryList.cpp | 2 +- layout/style/nsCSSParser.cpp | 48 +++++----------------------- layout/style/nsCSSParser.h | 15 +++------ 7 files changed, 19 insertions(+), 59 deletions(-) diff --git a/dom/base/ResponsiveImageSelector.cpp b/dom/base/ResponsiveImageSelector.cpp index 84b322f07640..ecdad41ac73e 100644 --- a/dom/base/ResponsiveImageSelector.cpp +++ b/dom/base/ResponsiveImageSelector.cpp @@ -242,7 +242,7 @@ ResponsiveImageSelector::SetSizesFromDescriptor(const nsAString & aSizes) nsCSSParser cssParser; return cssParser.ParseSourceSizeList(aSizes, nullptr, 0, - mSizeQueries, mSizeValues, true); + mSizeQueries, mSizeValues); } void diff --git a/dom/html/HTMLSourceElement.cpp b/dom/html/HTMLSourceElement.cpp index 73d9c9d8cba3..ffddf44ebbd3 100644 --- a/dom/html/HTMLSourceElement.cpp +++ b/dom/html/HTMLSourceElement.cpp @@ -77,7 +77,7 @@ HTMLSourceElement::WouldMatchMediaForDocument(const nsAString& aMedia, nsCSSParser cssParser; RefPtr mediaList = new nsMediaList(); - cssParser.ParseMediaList(aMedia, nullptr, 0, mediaList, false); + cssParser.ParseMediaList(aMedia, nullptr, 0, mediaList); return pctx && mediaList->Matches(pctx, nullptr); } @@ -93,7 +93,7 @@ HTMLSourceElement::UpdateMediaList(const nsAttrValue* aValue) nsCSSParser cssParser; mMediaList = new nsMediaList(); - cssParser.ParseMediaList(mediaStr, nullptr, 0, mMediaList, false); + cssParser.ParseMediaList(mediaStr, nullptr, 0, mMediaList); } nsresult diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 57ad996a08e1..9cff273ee8ca 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -646,10 +646,7 @@ void nsMediaList::SetText(const nsAString& aMediaText) { nsCSSParser parser; - - bool htmlMode = mStyleSheet && mStyleSheet->GetOwnerNode(); - - parser.ParseMediaList(aMediaText, nullptr, 0, this, htmlMode); + parser.ParseMediaList(aMediaText, nullptr, 0, this); } bool diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index a1a0fcfd9092..608255afed63 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1300,7 +1300,7 @@ Loader::PrepareSheet(StyleSheet* aSheet, // We have aMediaString only when linked from link elements, style // elements, or PIs, so pass true. - mediumParser.ParseMediaList(aMediaString, nullptr, 0, mediaList, true); + mediumParser.ParseMediaList(aMediaString, nullptr, 0, mediaList); } sheet->SetMedia(mediaList); diff --git a/layout/style/MediaQueryList.cpp b/layout/style/MediaQueryList.cpp index 069e049c462d..347146f8ba39 100644 --- a/layout/style/MediaQueryList.cpp +++ b/layout/style/MediaQueryList.cpp @@ -24,7 +24,7 @@ MediaQueryList::MediaQueryList(nsIDocument *aDocument, PR_INIT_CLIST(this); nsCSSParser parser; - parser.ParseMediaList(aMediaQueryList, nullptr, 0, mMediaList, false); + parser.ParseMediaList(aMediaQueryList, nullptr, 0, mMediaList); } MediaQueryList::~MediaQueryList() diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 28cbf2d6cf19..c0dc342c83f1 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -202,15 +202,13 @@ public: void ParseMediaList(const nsSubstring& aBuffer, nsIURI* aURL, // for error reporting uint32_t aLineNumber, // for error reporting - nsMediaList* aMediaList, - bool aHTMLMode); + nsMediaList* aMediaList); bool ParseSourceSizeList(const nsAString& aBuffer, nsIURI* aURI, // for error reporting uint32_t aLineNumber, // for error reporting InfallibleTArray< nsAutoPtr >& aQueries, - InfallibleTArray& aValues, - bool aHTMLMode); + InfallibleTArray& aValues); void ParseVariable(const nsAString& aVariableName, const nsAString& aPropValue, @@ -1488,10 +1486,6 @@ protected: // True if viewport units should be allowed. bool mViewportUnitsEnabled : 1; - // True for parsing media lists for HTML attributes, where we have to - // ignore CSS comments. - bool mHTMLMediaMode : 1; - // This flag is set when parsing a non-box shorthand; it's used to not apply // some quirks during shorthand parsing bool mParsingCompoundProperty : 1; @@ -1613,7 +1607,6 @@ CSSParserImpl::CSSParserImpl() mParsingMode(css::eAuthorSheetFeatures), mIsChrome(false), mViewportUnitsEnabled(true), - mHTMLMediaMode(false), mParsingCompoundProperty(false), mInSupportsCondition(false), mInFailingSupportsRule(false), @@ -1687,7 +1680,6 @@ CSSParserImpl::InitScanner(nsCSSScanner& aScanner, nsIURI* aSheetURI, nsIURI* aBaseURI, nsIPrincipal* aSheetPrincipal) { - NS_PRECONDITION(!mHTMLMediaMode, "Bad initial state"); NS_PRECONDITION(!mParsingCompoundProperty, "Bad initial state"); NS_PRECONDITION(!mScanner, "already have scanner"); @@ -2132,8 +2124,7 @@ void CSSParserImpl::ParseMediaList(const nsSubstring& aBuffer, nsIURI* aURI, // for error reporting uint32_t aLineNumber, // for error reporting - nsMediaList* aMediaList, - bool aHTMLMode) + nsMediaList* aMediaList) { // XXX Are there cases where the caller wants to keep what it already // has in case of parser error? If GatherMedia ever changes to return @@ -2145,27 +2136,12 @@ CSSParserImpl::ParseMediaList(const nsSubstring& aBuffer, css::ErrorReporter reporter(scanner, mSheet, mChildLoader, aURI); InitScanner(scanner, reporter, aURI, aURI, nullptr); - mHTMLMediaMode = aHTMLMode; - - // XXXldb We need to make the scanner not skip CSS comments! (Or - // should we?) - - // For aHTMLMode, we used to follow the parsing rules in - // http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-media-descriptors - // which wouldn't work for media queries since they remove all but the - // first word. However, they're changed in - // http://www.whatwg.org/specs/web-apps/current-work/multipage/section-document.html#media2 - // (as of 2008-05-29) which says that the media attribute just points - // to a media query. (The main substative difference is the relative - // precedence of commas and paretheses.) - DebugOnly parsedOK = GatherMedia(aMediaList, false); NS_ASSERTION(parsedOK, "GatherMedia returned false; we probably want to avoid " "trashing aMediaList"); CLEAR_ERROR(); ReleaseScanner(); - mHTMLMediaMode = false; } // = #? @@ -2175,8 +2151,7 @@ CSSParserImpl::ParseSourceSizeList(const nsAString& aBuffer, nsIURI* aURI, // for error reporting uint32_t aLineNumber, // for error reporting InfallibleTArray< nsAutoPtr >& aQueries, - InfallibleTArray& aValues, - bool aHTMLMode) + InfallibleTArray& aValues) { aQueries.Clear(); aValues.Clear(); @@ -2186,9 +2161,6 @@ CSSParserImpl::ParseSourceSizeList(const nsAString& aBuffer, css::ErrorReporter reporter(scanner, mSheet, mChildLoader, aURI); InitScanner(scanner, reporter, aURI, aURI, nullptr); - // See ParseMediaList comment about HTML mode - mHTMLMediaMode = aHTMLMode; - // https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-sizes-attribute bool hitEnd = false; do { @@ -2257,7 +2229,6 @@ CSSParserImpl::ParseSourceSizeList(const nsAString& aBuffer, CLEAR_ERROR(); ReleaseScanner(); - mHTMLMediaMode = false; return !aQueries.IsEmpty(); } @@ -18225,11 +18196,10 @@ void nsCSSParser::ParseMediaList(const nsSubstring& aBuffer, nsIURI* aURI, uint32_t aLineNumber, - nsMediaList* aMediaList, - bool aHTMLMode) + nsMediaList* aMediaList) { static_cast(mImpl)-> - ParseMediaList(aBuffer, aURI, aLineNumber, aMediaList, aHTMLMode); + ParseMediaList(aBuffer, aURI, aLineNumber, aMediaList); } bool @@ -18237,12 +18207,10 @@ nsCSSParser::ParseSourceSizeList(const nsAString& aBuffer, nsIURI* aURI, uint32_t aLineNumber, InfallibleTArray< nsAutoPtr >& aQueries, - InfallibleTArray& aValues, - bool aHTMLMode) + InfallibleTArray& aValues) { return static_cast(mImpl)-> - ParseSourceSizeList(aBuffer, aURI, aLineNumber, aQueries, aValues, - aHTMLMode); + ParseSourceSizeList(aBuffer, aURI, aLineNumber, aQueries, aValues); } bool diff --git a/layout/style/nsCSSParser.h b/layout/style/nsCSSParser.h index 37cd325f20a4..3998daac7f1b 100644 --- a/layout/style/nsCSSParser.h +++ b/layout/style/nsCSSParser.h @@ -152,18 +152,14 @@ public: bool* aChanged, bool aIsImportant); /** - * Parse aBuffer into a media list |aMediaList|, which must be - * non-null, replacing its current contents. If aHTMLMode is true, - * parse according to HTML rules, with commas as the most important - * delimiter. Otherwise, parse according to CSS rules, with - * parentheses and strings more important than commas. |aURL| and - * |aLineNumber| are used for error reporting. + * Parse aBuffer into a media list |aMediaList|, which must be non-null, + * replacing its current contents. |aURL| and |aLineNumber| are used for error + * reporting. */ void ParseMediaList(const nsSubstring& aBuffer, nsIURI* aURL, uint32_t aLineNumber, - nsMediaList* aMediaList, - bool aHTMLMode); + nsMediaList* aMediaList); /* * Parse aBuffer into a list of media queries and their associated values, @@ -181,8 +177,7 @@ public: nsIURI* aURI, // for error reporting uint32_t aLineNumber, // for error reporting InfallibleTArray< nsAutoPtr >& aQueries, - InfallibleTArray& aValues, - bool aHTMLMode); + InfallibleTArray& aValues); /** * Parse aBuffer into a nsCSSValue |aValue|. Will return false