Bug 1294299 part 5 - Implement getter and setter of cssText. r=heycam
authorXidorn Quan <me@upsuper.org>
Thu, 03 Nov 2016 14:41:02 +1100
changeset 347529 dc84ed83a79b821663ccf481c024d1a76cabd194
parent 347528 6a582c5930e5a201920deb133358703ff0c891eb
child 347530 f3df5f8f176755095d3695472ef08993baa63435
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1294299
milestone52.0a1
Bug 1294299 part 5 - Implement getter and setter of cssText. r=heycam MozReview-Commit-ID: Bho5PKtrT1I
dom/base/nsAttrValue.cpp
layout/style/DeclarationBlock.h
layout/style/DeclarationBlockInlines.h
layout/style/ServoBindingList.h
layout/style/ServoDeclarationBlock.cpp
layout/style/ServoDeclarationBlock.h
layout/style/nsDOMCSSDeclaration.cpp
--- a/dom/base/nsAttrValue.cpp
+++ b/dom/base/nsAttrValue.cpp
@@ -1715,17 +1715,17 @@ nsAttrValue::ParseStyleAttribute(const n
       NS_ADDREF(cont);
       SetPtrValueAndType(cont, eOtherBase);
       return true;
     }
   }
 
   RefPtr<DeclarationBlock> decl;
   if (ownerDoc->GetStyleBackendType() == StyleBackendType::Servo) {
-    decl = ServoDeclarationBlock::FromStyleAttribute(aString);
+    decl = ServoDeclarationBlock::FromCssText(aString);
   } else {
     css::Loader* cssLoader = ownerDoc->CSSLoader();
     nsCSSParser cssParser(cssLoader);
     decl = cssParser.ParseStyleAttribute(aString, docURI, baseURI,
                                          aElement->NodePrincipal());
   }
   if (!decl) {
     return false;
--- a/layout/style/DeclarationBlock.h
+++ b/layout/style/DeclarationBlock.h
@@ -87,16 +87,18 @@ public:
     if (!(mContainer.mRaw & 0x1)) {
       return nullptr;
     }
     auto c = mContainer;
     c.mRaw &= ~uintptr_t(1);
     return c.mHTMLCSSStyleSheet;
   }
 
+  inline void ToString(nsAString& aString) const;
+
   inline uint32_t Count() const;
   inline bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const;
 
 private:
   union {
     // We only ever have one of these since we have an
     // nsHTMLCSSStyleSheet only for style attributes, and style
     // attributes never have an owning rule.
--- a/layout/style/DeclarationBlockInlines.h
+++ b/layout/style/DeclarationBlockInlines.h
@@ -21,16 +21,22 @@ DeclarationBlock::AddRef()
 }
 
 MozExternalRefCountType
 DeclarationBlock::Release()
 {
   MOZ_STYLO_FORWARD(Release, ())
 }
 
+void
+DeclarationBlock::ToString(nsAString& aString) const
+{
+  MOZ_STYLO_FORWARD(ToString, (aString))
+}
+
 uint32_t
 DeclarationBlock::Count() const
 {
   MOZ_STYLO_FORWARD(Count, ())
 }
 
 bool
 DeclarationBlock::GetNthProperty(uint32_t aIndex, nsAString& aReturn) const
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -66,16 +66,19 @@ SERVO_BINDING_FUNC(Servo_DeclarationBloc
                    RawServoDeclarationBlockStrong)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_AddRef, void,
                    RawServoDeclarationBlockBorrowed declarations)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_Release, void,
                    RawServoDeclarationBlockBorrowed declarations)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_Equals, bool,
                    RawServoDeclarationBlockBorrowed a,
                    RawServoDeclarationBlockBorrowed b)
+SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetCssText, void,
+                   RawServoDeclarationBlockBorrowed declarations,
+                   nsAString* result)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_SerializeOneValue, void,
                    RawServoDeclarationBlockBorrowed declarations,
                    nsString* buffer)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_Count, uint32_t,
                    RawServoDeclarationBlockBorrowed declarations)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_GetNthProperty, bool,
                    RawServoDeclarationBlockBorrowed declarations,
                    uint32_t index, nsAString* result)
--- a/layout/style/ServoDeclarationBlock.cpp
+++ b/layout/style/ServoDeclarationBlock.cpp
@@ -5,18 +5,18 @@
 
 #include "mozilla/ServoDeclarationBlock.h"
 
 #include "mozilla/ServoBindings.h"
 
 namespace mozilla {
 
 /* static */ already_AddRefed<ServoDeclarationBlock>
-ServoDeclarationBlock::FromStyleAttribute(const nsAString& aString)
+ServoDeclarationBlock::FromCssText(const nsAString& aCssText)
 {
-  NS_ConvertUTF16toUTF8 value(aString);
+  NS_ConvertUTF16toUTF8 value(aCssText);
   RefPtr<RawServoDeclarationBlock>
     raw = Servo_ParseStyleAttribute(&value).Consume();
   RefPtr<ServoDeclarationBlock> decl = new ServoDeclarationBlock(raw.forget());
   return decl.forget();
 }
 
 } // namespace mozilla
--- a/layout/style/ServoDeclarationBlock.h
+++ b/layout/style/ServoDeclarationBlock.h
@@ -15,25 +15,29 @@ class ServoDeclarationBlock final : publ
 {
 public:
   ServoDeclarationBlock()
     : ServoDeclarationBlock(Servo_DeclarationBlock_CreateEmpty().Consume()) {}
 
   NS_INLINE_DECL_REFCOUNTING(ServoDeclarationBlock)
 
   static already_AddRefed<ServoDeclarationBlock>
-  FromStyleAttribute(const nsAString& aString);
+  FromCssText(const nsAString& aCssText);
 
   RawServoDeclarationBlock* const* RefRaw() const {
     static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
                   sizeof(RawServoDeclarationBlock*),
                   "RefPtr should just be a pointer");
     return reinterpret_cast<RawServoDeclarationBlock* const*>(&mRaw);
   }
 
+  void ToString(nsAString& aResult) const {
+    Servo_DeclarationBlock_GetCssText(mRaw, &aResult);
+  }
+
   uint32_t Count() const {
     return Servo_DeclarationBlock_Count(mRaw);
   }
   bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const {
     aReturn.Truncate();
     return Servo_DeclarationBlock_GetNthProperty(mRaw, aIndex, &aReturn);
   }
 
--- a/layout/style/nsDOMCSSDeclaration.cpp
+++ b/layout/style/nsDOMCSSDeclaration.cpp
@@ -111,32 +111,32 @@ nsDOMCSSDeclaration::SetPropertyValue(co
 
   return ParsePropertyValue(aPropID, aValue, false);
 }
 
 
 NS_IMETHODIMP
 nsDOMCSSDeclaration::GetCssText(nsAString& aCssText)
 {
-  css::Declaration* decl = GetCSSDeclaration(eOperation_Read)->AsGecko();
+  DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read);
   aCssText.Truncate();
 
   if (decl) {
     decl->ToString(aCssText);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
 {
   // We don't need to *do* anything with the old declaration, but we need
   // to ensure that it exists, or else SetCSSDeclaration may crash.
-  css::Declaration* olddecl = GetCSSDeclaration(eOperation_Modify)->AsGecko();
+  DeclarationBlock* olddecl = GetCSSDeclaration(eOperation_Modify);
   if (!olddecl) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   CSSParsingEnvironment env;
   GetCSSParsingEnvironment(env);
   if (!env.mPrincipal) {
     return NS_ERROR_NOT_AVAILABLE;
@@ -144,28 +144,34 @@ nsDOMCSSDeclaration::SetCssText(const ns
 
   // For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
   // Attribute setting code, which leads in turn to BeginUpdate.  We
   // need to start the update now so that the old rule doesn't get used
   // between when we mutate the declaration and when we set the new
   // rule (see stack in bug 209575).
   mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
 
-  RefPtr<css::Declaration> decl(new css::Declaration());
-  decl->InitializeEmpty();
-  nsCSSParser cssParser(env.mCSSLoader);
-  bool changed;
-  nsresult result = cssParser.ParseDeclarations(aCssText, env.mSheetURI,
-                                                env.mBaseURI,
-                                                env.mPrincipal, decl, &changed);
-  if (NS_FAILED(result) || !changed) {
-    return result;
+  RefPtr<DeclarationBlock> newdecl;
+  if (olddecl->IsServo()) {
+    newdecl = ServoDeclarationBlock::FromCssText(aCssText);
+  } else {
+    RefPtr<css::Declaration> decl(new css::Declaration());
+    decl->InitializeEmpty();
+    nsCSSParser cssParser(env.mCSSLoader);
+    bool changed;
+    nsresult result = cssParser.ParseDeclarations(aCssText, env.mSheetURI,
+                                                  env.mBaseURI, env.mPrincipal,
+                                                  decl, &changed);
+    if (NS_FAILED(result) || !changed) {
+      return result;
+    }
+    newdecl = decl.forget();
   }
 
-  return SetCSSDeclaration(decl);
+  return SetCSSDeclaration(newdecl);
 }
 
 NS_IMETHODIMP
 nsDOMCSSDeclaration::GetLength(uint32_t* aLength)
 {
   DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read);
 
   if (decl) {