Bug 1294299 part 3 - Make it able to create empty ServoDeclarationBlock. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Mon, 24 Oct 2016 17:40:25 +1100
changeset 429033 bf3209f95f75a847e1e014cfe87c228554b5361a
parent 429032 8681b94e94868fee84eead034b400526a2ca6778
child 429034 877ef7cc51c77e35c64d7c684a82cb815674cfd3
push id33477
push userxquan@mozilla.com
push dateTue, 25 Oct 2016 03:45:40 +0000
reviewersheycam
bugs1294299
milestone52.0a1
Bug 1294299 part 3 - Make it able to create empty ServoDeclarationBlock. r?heycam MozReview-Commit-ID: FSdSXDFoxM
layout/style/ServoBindingList.h
layout/style/ServoDeclarationBlock.h
layout/style/nsDOMCSSAttrDeclaration.cpp
servo/components/style/gecko_bindings/bindings.rs
servo/ports/geckolib/glue.rs
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -57,16 +57,18 @@ SERVO_BINDING_FUNC(Servo_ParseProperty,
 SERVO_BINDING_FUNC(Servo_RestyleWithAddedDeclaration,
                    ServoComputedValuesStrong,
                    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_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_SerializeOneValue, void,
--- a/layout/style/ServoDeclarationBlock.h
+++ b/layout/style/ServoDeclarationBlock.h
@@ -9,16 +9,19 @@
 #include "mozilla/ServoBindings.h"
 #include "mozilla/DeclarationBlock.h"
 
 namespace mozilla {
 
 class ServoDeclarationBlock final : public DeclarationBlock
 {
 public:
+  ServoDeclarationBlock()
+    : ServoDeclarationBlock(Servo_DeclarationBlock_CreateEmpty().Consume()) {}
+
   NS_INLINE_DECL_REFCOUNTING(ServoDeclarationBlock)
 
   static already_AddRefed<ServoDeclarationBlock>
   FromStyleAttribute(const nsAString& aString);
 
   RawServoDeclarationBlock* const* RefRaw() const {
     static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
                   sizeof(RawServoDeclarationBlock*),
--- a/layout/style/nsDOMCSSAttrDeclaration.cpp
+++ b/layout/style/nsDOMCSSAttrDeclaration.cpp
@@ -123,18 +123,24 @@ nsDOMCSSAttributeDeclaration::GetCSSDecl
     return declaration;
   }
 
   if (aOperation != eOperation_Modify) {
     return nullptr;
   }
 
   // cannot fail
-  RefPtr<css::Declaration> decl = new css::Declaration();
-  decl->InitializeEmpty();
+  RefPtr<DeclarationBlock> decl;
+  if (mElement->IsStyledByServo()) {
+    decl = new ServoDeclarationBlock();
+  } else {
+    css::Declaration* declaration = new css::Declaration();
+    declaration->InitializeEmpty();
+    decl = declaration;
+  }
 
   // this *can* fail (inside SetAttrAndNotify, at least).
   nsresult rv;
   if (mIsSMILOverride) {
     rv = mElement->SetSMILOverrideStyleDeclaration(decl, false);
   } else {
     rv = mElement->SetInlineStyleDeclaration(decl, nullptr, false);
   }
--- a/servo/components/style/gecko_bindings/bindings.rs
+++ b/servo/components/style/gecko_bindings/bindings.rs
@@ -886,16 +886,20 @@ extern "C" {
                                                  ServoComputedValuesBorrowed)
      -> ServoComputedValuesStrong;
 }
 extern "C" {
     pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
      -> RawServoDeclarationBlockStrong;
 }
 extern "C" {
+    pub fn Servo_DeclarationBlock_CreateEmpty()
+     -> RawServoDeclarationBlockStrong;
+}
+extern "C" {
     pub fn Servo_DeclarationBlock_Equals(a: RawServoDeclarationBlockBorrowed,
                                          b: RawServoDeclarationBlockBorrowed)
      -> bool;
 }
 extern "C" {
     pub fn Servo_DeclarationBlock_SerializeOneValue(declarations:
                                                         RawServoDeclarationBlockBorrowed,
                                                     buffer: *mut nsString);
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -400,16 +400,21 @@ pub extern "C" fn Servo_ParseProperty(pr
 
 #[no_mangle]
 pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString) -> RawServoDeclarationBlockStrong {
     let value = unsafe { data.as_ref().unwrap().as_str_unchecked() };
     Arc::new(RwLock::new(GeckoElement::parse_style_attribute(value))).into_strong()
 }
 
 #[no_mangle]
+pub extern "C" fn Servo_DeclarationBlock_CreateEmpty() -> RawServoDeclarationBlockStrong {
+    Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![], important_count: 0 })).into_strong()
+}
+
+#[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_AddRef(declarations: RawServoDeclarationBlockBorrowed) {
     unsafe { RwLock::<PropertyDeclarationBlock>::addref(declarations) };
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_Release(declarations: RawServoDeclarationBlockBorrowed) {
     unsafe { RwLock::<PropertyDeclarationBlock>::release(declarations) };
 }