Bug 1294299 part 3 - Make it possible to create empty ServoDeclarationBlock. r=heycam
MozReview-Commit-ID: FSdSXDFoxM
--- 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,23 @@ 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 {
+ decl = new css::Declaration();
+ decl->AsGecko()->InitializeEmpty();
+ }
// 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
@@ -918,16 +918,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
@@ -416,16 +416,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) };
}