Bug 1208951 - Part 4: Add an nsCSSParser entry point to parse a single longhand property and return an nsCSSValue. r=birtles
authorCameron McCormack <cam@mcc.id.au>
Thu, 22 Oct 2015 19:22:37 +1100
changeset 304129 6dcecb56b9d932c3c90bd036e79c41f05c71055c
parent 304128 b703a449fd3a3a503dd1eddf51474f9931f2dcba
child 304130 d35cde8a623eb6d6a5136673aae4881b9e7d65cd
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1208951
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1208951 - Part 4: Add an nsCSSParser entry point to parse a single longhand property and return an nsCSSValue. r=birtles It is a slight hassle for code to have to create a Declaration object to pass in to nsCSSParser::ParseProperty when all it wants is the resulting single nsCSSValue, if parsing a longhand property. Declaration is also inaccessible outside layout/style/.
layout/style/nsCSSParser.cpp
layout/style/nsCSSParser.h
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -163,16 +163,22 @@ public:
                      const nsAString& aPropValue,
                      nsIURI* aSheetURL,
                      nsIURI* aBaseURL,
                      nsIPrincipal* aSheetPrincipal,
                      css::Declaration* aDeclaration,
                      bool* aChanged,
                      bool aIsImportant,
                      bool aIsSVGMode);
+  void ParseLonghandProperty(const nsCSSProperty aPropID,
+                             const nsAString& aPropValue,
+                             nsIURI* aSheetURL,
+                             nsIURI* aBaseURL,
+                             nsIPrincipal* aSheetPrincipal,
+                             nsCSSValue& aValue);
 
   void ParseMediaList(const nsSubstring& aBuffer,
                       nsIURI* aURL, // for error reporting
                       uint32_t aLineNumber, // for error reporting
                       nsMediaList* aMediaList,
                       bool aHTMLMode);
 
   bool ParseSourceSizeList(const nsAString& aBuffer,
@@ -1752,16 +1758,43 @@ CSSParserImpl::ParseRule(const nsAString
     }
   }
 
   ReleaseScanner();
   return rv;
 }
 
 void
+CSSParserImpl::ParseLonghandProperty(const nsCSSProperty aPropID,
+                                     const nsAString& aPropValue,
+                                     nsIURI* aSheetURL,
+                                     nsIURI* aBaseURL,
+                                     nsIPrincipal* aSheetPrincipal,
+                                     nsCSSValue& aValue)
+{
+  MOZ_ASSERT(aPropID < eCSSProperty_COUNT_no_shorthands,
+             "ParseLonghandProperty must only take a longhand property");
+
+  Declaration declaration;
+  declaration.InitializeEmpty();
+
+  bool changed;
+  ParseProperty(aPropID, aPropValue, aSheetURL, aBaseURL, aSheetPrincipal,
+                &declaration, &changed,
+                /* aIsImportant */ false,
+                /* aIsSVGMode */ false);
+
+  if (changed) {
+    aValue = *declaration.GetNormalBlock()->ValueFor(aPropID);
+  } else {
+    aValue.Reset();
+  }
+}
+
+void
 CSSParserImpl::ParseProperty(const nsCSSProperty aPropID,
                              const nsAString& aPropValue,
                              nsIURI* aSheetURI,
                              nsIURI* aBaseURI,
                              nsIPrincipal* aSheetPrincipal,
                              css::Declaration* aDeclaration,
                              bool* aChanged,
                              bool aIsImportant,
@@ -16092,16 +16125,29 @@ nsCSSParser::ParseProperty(const nsCSSPr
 {
   static_cast<CSSParserImpl*>(mImpl)->
     ParseProperty(aPropID, aPropValue, aSheetURI, aBaseURI,
                   aSheetPrincipal, aDeclaration, aChanged,
                   aIsImportant, aIsSVGMode);
 }
 
 void
+nsCSSParser::ParseLonghandProperty(const nsCSSProperty aPropID,
+                                   const nsAString&    aPropValue,
+                                   nsIURI*             aSheetURI,
+                                   nsIURI*             aBaseURI,
+                                   nsIPrincipal*       aSheetPrincipal,
+                                   nsCSSValue&         aResult)
+{
+  static_cast<CSSParserImpl*>(mImpl)->
+    ParseLonghandProperty(aPropID, aPropValue, aSheetURI, aBaseURI,
+                          aSheetPrincipal, aResult);
+}
+
+void
 nsCSSParser::ParseVariable(const nsAString&    aVariableName,
                            const nsAString&    aPropValue,
                            nsIURI*             aSheetURI,
                            nsIURI*             aBaseURI,
                            nsIPrincipal*       aSheetPrincipal,
                            css::Declaration*   aDeclaration,
                            bool*               aChanged,
                            bool                aIsImportant)
--- a/layout/style/nsCSSParser.h
+++ b/layout/style/nsCSSParser.h
@@ -130,16 +130,26 @@ public:
                      nsIURI*             aSheetURL,
                      nsIURI*             aBaseURL,
                      nsIPrincipal*       aSheetPrincipal,
                      mozilla::css::Declaration* aDeclaration,
                      bool*               aChanged,
                      bool                aIsImportant,
                      bool                aIsSVGMode = false);
 
+  // Same as ParseProperty but returns an nsCSSValue in aResult
+  // rather than storing the property in a Declaration.  aPropID
+  // must be a longhand property.
+  void ParseLonghandProperty(const nsCSSProperty aPropID,
+                             const nsAString&    aPropValue,
+                             nsIURI*             aSheetURL,
+                             nsIURI*             aBaseURL,
+                             nsIPrincipal*       aSheetPrincipal,
+                             nsCSSValue&         aResult);
+
   // The same as ParseProperty but for a variable.
   void ParseVariable(const nsAString&    aVariableName,
                      const nsAString&    aPropValue,
                      nsIURI*             aSheetURL,
                      nsIURI*             aBaseURL,
                      nsIPrincipal*       aSheetPrincipal,
                      mozilla::css::Declaration* aDeclaration,
                      bool*               aChanged,