Bug 1287382 - Hook up the 1-arg version of CSS.supports() to the Servo backend. r=dholbert draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 18 Jul 2016 16:29:04 +0800
changeset 388926 66583e4a5961404d9c6da9a21466041d710a87ed
parent 388925 c8ba6a6eec22033228aad26f08db5ac4ff129461
child 525620 238b817b3621e0904157b1518fb9d2e58d3e9072
push id23260
push userbmo:cam@mcc.id.au
push dateMon, 18 Jul 2016 08:30:10 +0000
reviewersdholbert
bugs1287382
milestone50.0a1
Bug 1287382 - Hook up the 1-arg version of CSS.supports() to the Servo backend. r=dholbert MozReview-Commit-ID: EDQGXOVgWEC
layout/style/CSS.cpp
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
--- a/layout/style/CSS.cpp
+++ b/layout/style/CSS.cpp
@@ -3,31 +3,33 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* DOM object holding utility CSS functions */
 
 #include "CSS.h"
 
 #include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/ServoBindings.h"
 #include "nsCSSParser.h"
 #include "nsGlobalWindow.h"
 #include "nsIDocument.h"
 #include "nsIURI.h"
 #include "nsStyleUtil.h"
 #include "xpcpublic.h"
 
 namespace mozilla {
 namespace dom {
 
 struct SupportsParsingInfo
 {
   nsIURI* mDocURI;
   nsIURI* mBaseURI;
   nsIPrincipal* mPrincipal;
+  StyleBackendType mStyleBackendType;
 };
 
 static nsresult
 GetParsingInfo(const GlobalObject& aGlobal,
                SupportsParsingInfo& aInfo)
 {
   nsGlobalWindow* win = xpc::WindowOrNull(aGlobal.Get());
   if (!win) {
@@ -37,52 +39,67 @@ GetParsingInfo(const GlobalObject& aGlob
   nsCOMPtr<nsIDocument> doc = win->GetDoc();
   if (!doc) {
     return NS_ERROR_FAILURE;
   }
 
   aInfo.mDocURI = nsCOMPtr<nsIURI>(doc->GetDocumentURI()).get();
   aInfo.mBaseURI = nsCOMPtr<nsIURI>(doc->GetBaseURI()).get();
   aInfo.mPrincipal = win->GetPrincipal();
+  aInfo.mStyleBackendType = doc->GetStyleBackendType();
   return NS_OK;
 }
 
 /* static */ bool
 CSS::Supports(const GlobalObject& aGlobal,
               const nsAString& aProperty,
               const nsAString& aValue,
               ErrorResult& aRv)
 {
-  nsCSSParser parser;
   SupportsParsingInfo info;
 
   nsresult rv = GetParsingInfo(aGlobal, info);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return false;
   }
 
+  if (info.mStyleBackendType == StyleBackendType::Servo) {
+    NS_ConvertUTF16toUTF8 property(aProperty);
+    NS_ConvertUTF16toUTF8 value(aValue);
+
+    return Servo_CSSSupports(reinterpret_cast<const uint8_t*>(property.get()),
+                             property.Length(),
+                             reinterpret_cast<const uint8_t*>(value.get()),
+                             value.Length());
+  }
+
+  nsCSSParser parser;
   return parser.EvaluateSupportsDeclaration(aProperty, aValue, info.mDocURI,
                                             info.mBaseURI, info.mPrincipal);
 }
 
 /* static */ bool
 CSS::Supports(const GlobalObject& aGlobal,
               const nsAString& aCondition,
               ErrorResult& aRv)
 {
-  nsCSSParser parser;
   SupportsParsingInfo info;
 
   nsresult rv = GetParsingInfo(aGlobal, info);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return false;
   }
 
+  if (info.mStyleBackendType == StyleBackendType::Servo) {
+    MOZ_CRASH("stylo: CSS.supports() with arguments is not yet implemented");
+  }
+
+  nsCSSParser parser;
   return parser.EvaluateSupportsCondition(aCondition, info.mDocURI,
                                           info.mBaseURI, info.mPrincipal);
 }
 
 /* static */ void
 CSS::Escape(const GlobalObject& aGlobal,
             const nsAString& aIdent,
             nsAString& aReturn)
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -714,16 +714,24 @@ Servo_SetDeclarationBlockImmutable(Servo
 
 void
 Servo_ClearDeclarationBlockCachePointer(ServoDeclarationBlock* declarations)
 {
   MOZ_CRASH("stylo: shouldn't be calling Servo_ClearDeclarationBlockCachePointer in a "
             "non-MOZ_STYLO build");
 }
 
+bool
+Servo_CSSSupports(const uint8_t* name, uint32_t name_length,
+                  const uint8_t* value, uint32_t value_length)
+{
+  MOZ_CRASH("stylo: shouldn't be calling Servo_CSSSupports in a "
+            "non-MOZ_STYLO build");
+}
+
 ServoComputedValues*
 Servo_GetComputedValues(RawGeckoNode* node)
 {
   MOZ_CRASH("stylo: shouldn't be calling Servo_GetComputedValues in a "
             "non-MOZ_STYLO build");
 }
 
 ServoComputedValues*
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -220,16 +220,20 @@ ServoDeclarationBlock* Servo_ParseStyleA
                                                  uint8_t length,
                                                  nsHTMLCSSStyleSheet* cache);
 void Servo_DropDeclarationBlock(ServoDeclarationBlock* declarations);
 nsHTMLCSSStyleSheet* Servo_GetDeclarationBlockCache(
     ServoDeclarationBlock* declarations);
 void Servo_SetDeclarationBlockImmutable(ServoDeclarationBlock* declarations);
 void Servo_ClearDeclarationBlockCachePointer(ServoDeclarationBlock* declarations);
 
+// CSS supports().
+bool Servo_CSSSupports(const uint8_t* name, uint32_t name_length,
+                       const uint8_t* value, uint32_t value_length);
+
 // Computed style data.
 ServoComputedValues* Servo_GetComputedValues(RawGeckoNode* node);
 ServoComputedValues* Servo_GetComputedValuesForAnonymousBox(ServoComputedValues* parentStyleOrNull,
                                                             nsIAtom* pseudoTag,
                                                             RawServoStyleSet* set);
 ServoComputedValues* Servo_GetComputedValuesForPseudoElement(ServoComputedValues* parent_style,
                                                              RawGeckoElement* match_element,
                                                              nsIAtom* pseudo_tag,