Bug 1294299 part 9 - Implement Clone for ServoDeclarationBlock. r=heycam
authorXidorn Quan <me@upsuper.org>
Thu, 03 Nov 2016 14:41:02 +1100
changeset 347533 dfe544496b0e0fba07889fd05d0265f20aea5aa1
parent 347532 257cfb683437c031d4cb210146cb8c4b70b52fcc
child 347534 521987ad1ac612c7083a11b2f765dbc8cb615d11
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 9 - Implement Clone for ServoDeclarationBlock. r=heycam MozReview-Commit-ID: 5y2h26j87Sz
dom/html/nsGenericHTMLElement.cpp
layout/style/DeclarationBlock.h
layout/style/DeclarationBlockInlines.h
layout/style/ServoBindingList.h
layout/style/ServoDeclarationBlock.h
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -185,26 +185,20 @@ nsGenericHTMLElement::CopyInnerTo(Elemen
     const nsAttrValue *value = mAttrsAndChildren.AttrAt(i);
 
     nsAutoString valStr;
     value->ToString(valStr);
 
     if (name->Equals(nsGkAtoms::style, kNameSpaceID_None) &&
         value->Type() == nsAttrValue::eCSSDeclaration) {
       DeclarationBlock* decl = value->GetCSSDeclarationValue();
-      if (decl->IsServo()) {
-        MOZ_CRASH("stylo: clone not implemented");
-        continue;
-      }
-
       // We can't just set this as a string, because that will fail
       // to reparse the string into style data until the node is
       // inserted into the document.  Clone the Rule instead.
-      RefPtr<css::Declaration>
-        declClone = new css::Declaration(*decl->AsGecko());
+      RefPtr<DeclarationBlock> declClone = decl->Clone();
 
       rv = aDst->SetInlineStyleDeclaration(declClone, &valStr, false);
       NS_ENSURE_SUCCESS(rv, rv);
 
       continue;
     }
 
     rv = aDst->SetAttr(name->NamespaceID(), name->LocalName(),
--- a/layout/style/DeclarationBlock.h
+++ b/layout/style/DeclarationBlock.h
@@ -36,16 +36,18 @@ protected:
     : DeclarationBlock(aCopy.mType) {}
 
 public:
   MOZ_DECL_STYLO_METHODS(css::Declaration, ServoDeclarationBlock)
 
   inline MozExternalRefCountType AddRef();
   inline MozExternalRefCountType Release();
 
+  inline already_AddRefed<DeclarationBlock> Clone() const;
+
   /**
    * Return whether |this| may be modified.
    */
   bool IsMutable() const {
     return !mImmutable;
   }
 
   /**
--- a/layout/style/DeclarationBlockInlines.h
+++ b/layout/style/DeclarationBlockInlines.h
@@ -21,16 +21,28 @@ DeclarationBlock::AddRef()
 }
 
 MozExternalRefCountType
 DeclarationBlock::Release()
 {
   MOZ_STYLO_FORWARD(Release, ())
 }
 
+already_AddRefed<DeclarationBlock>
+DeclarationBlock::Clone() const
+{
+  RefPtr<DeclarationBlock> result;
+  if (IsGecko()) {
+    result = new css::Declaration(*AsGecko());
+  } else {
+    result = new ServoDeclarationBlock(*AsServo());
+  }
+  return result.forget();
+}
+
 void
 DeclarationBlock::ToString(nsAString& aString) const
 {
   MOZ_STYLO_FORWARD(ToString, (aString))
 }
 
 uint32_t
 DeclarationBlock::Count() const
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -59,16 +59,18 @@ SERVO_BINDING_FUNC(Servo_RestyleWithAdde
                    RawServoDeclarationBlockBorrowed declarations,
                    ServoComputedValuesBorrowed previous_style)
 
 // Style attribute
 SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, RawServoDeclarationBlockStrong,
                    const nsACString* data)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_CreateEmpty,
                    RawServoDeclarationBlockStrong)
+SERVO_BINDING_FUNC(Servo_DeclarationBlock_Clone, RawServoDeclarationBlockStrong,
+                   RawServoDeclarationBlockBorrowed declarations)
 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,
--- a/layout/style/ServoDeclarationBlock.h
+++ b/layout/style/ServoDeclarationBlock.h
@@ -12,16 +12,20 @@
 namespace mozilla {
 
 class ServoDeclarationBlock final : public DeclarationBlock
 {
 public:
   ServoDeclarationBlock()
     : ServoDeclarationBlock(Servo_DeclarationBlock_CreateEmpty().Consume()) {}
 
+  ServoDeclarationBlock(const ServoDeclarationBlock& aCopy)
+    : DeclarationBlock(aCopy)
+    , mRaw(Servo_DeclarationBlock_Clone(aCopy.mRaw).Consume()) {}
+
   NS_INLINE_DECL_REFCOUNTING(ServoDeclarationBlock)
 
   static already_AddRefed<ServoDeclarationBlock>
   FromCssText(const nsAString& aCssText);
 
   RawServoDeclarationBlock* const* RefRaw() const {
     static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
                   sizeof(RawServoDeclarationBlock*),