diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp index 09d72d7a774f..7ac32a143d9a 100644 --- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -17,7 +17,7 @@ #include "nsIAtom.h" #include "nsUnicharUtils.h" #include "mozilla/MemoryReporting.h" -#include "mozilla/ServoBindings.h" +#include "mozilla/ServoBindingHelpers.h" #include "mozilla/css/Declaration.h" #include "nsContentUtils.h" #include "nsReadableUtils.h" @@ -463,12 +463,12 @@ nsAttrValue::SetTo(css::Declaration* aValue, const nsAString* aSerialized) } void -nsAttrValue::SetTo(ServoDeclarationBlock* aValue, +nsAttrValue::SetTo(already_AddRefed aValue, const nsAString* aSerialized) { MiscContainer* cont = EnsureEmptyMiscContainer(); MOZ_ASSERT(cont->mValue.mRefCount == 0); - cont->mValue.mServoCSSDeclaration = aValue; + cont->mValue.mServoCSSDeclaration = aValue.take(); cont->mType = eServoCSSDeclaration; NS_ADDREF(cont); SetMiscAtomOrString(aSerialized); @@ -1745,12 +1745,11 @@ nsAttrValue::ParseStyleAttribute(const nsAString& aString, if (ownerDoc->GetStyleBackendType() == StyleBackendType::Servo) { NS_ConvertUTF16toUTF8 value(aString); - ServoDeclarationBlock* decl = Servo_ParseStyleAttribute( + RefPtr decl = Servo_ParseStyleAttribute( reinterpret_cast(value.get()), - value.Length(), - sheet); + value.Length(), sheet).Consume(); MOZ_ASSERT(decl); - SetTo(decl, &aString); + SetTo(decl.forget(), &aString); } else { css::Loader* cssLoader = ownerDoc->CSSLoader(); nsCSSParser cssParser(cssLoader); @@ -1862,7 +1861,7 @@ nsAttrValue::ClearMiscContainer() if (cont->mType == eGeckoCSSDeclaration) { NS_RELEASE(cont->mValue.mGeckoCSSDeclaration); } else { - Servo_DropDeclarationBlock(cont->mValue.mServoCSSDeclaration); + Servo_DeclarationBlock_Release(cont->mValue.mServoCSSDeclaration); } break; } diff --git a/dom/base/nsAttrValue.h b/dom/base/nsAttrValue.h index 6deaff3f3264..2587fc02c8f6 100644 --- a/dom/base/nsAttrValue.h +++ b/dom/base/nsAttrValue.h @@ -148,7 +148,7 @@ public: void SetTo(int32_t aInt, const nsAString* aSerialized); void SetTo(double aValue, const nsAString* aSerialized); void SetTo(mozilla::css::Declaration* aValue, const nsAString* aSerialized); - void SetTo(ServoDeclarationBlock* aDeclarationBlock, + void SetTo(already_AddRefed aDeclarationBlock, const nsAString* aSerialized); void SetTo(mozilla::css::URLValue* aValue, const nsAString* aSerialized); void SetTo(const nsIntMargin& aValue); diff --git a/layout/style/ServoBindingHelpers.h b/layout/style/ServoBindingHelpers.h index 06e2b9f0e305..e6c638dfea01 100644 --- a/layout/style/ServoBindingHelpers.h +++ b/layout/style/ServoBindingHelpers.h @@ -45,6 +45,19 @@ public: } }; +template<> +struct RefPtrTraits +{ + static void AddRef(ServoDeclarationBlock* aPtr) + { + Servo_DeclarationBlock_AddRef(aPtr); + } + static void Release(ServoDeclarationBlock* aPtr) + { + Servo_DeclarationBlock_Release(aPtr); + } +}; + } // namespace mozilla #endif // mozilla_ServoBindingHelpers_h diff --git a/layout/style/ServoBindingList.h b/layout/style/ServoBindingList.h index 71c8d60ddc18..3d4833bde958 100644 --- a/layout/style/ServoBindingList.h +++ b/layout/style/ServoBindingList.h @@ -49,17 +49,19 @@ SERVO_BINDING_FUNC(Servo_InitStyleSet, RawServoStyleSet*) SERVO_BINDING_FUNC(Servo_DropStyleSet, void, RawServoStyleSet* set) // Style attribute -SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, ServoDeclarationBlock*, +SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, ServoDeclarationBlockStrong, const uint8_t* bytes, uint32_t length, nsHTMLCSSStyleSheet* cache) -SERVO_BINDING_FUNC(Servo_DropDeclarationBlock, void, - ServoDeclarationBlock* declarations) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_AddRef, void, + ServoDeclarationBlockBorrowed declarations) +SERVO_BINDING_FUNC(Servo_DeclarationBlock_Release, void, + ServoDeclarationBlockBorrowed declarations) SERVO_BINDING_FUNC(Servo_GetDeclarationBlockCache, nsHTMLCSSStyleSheet*, - ServoDeclarationBlock* declarations) + ServoDeclarationBlockBorrowed declarations) SERVO_BINDING_FUNC(Servo_SetDeclarationBlockImmutable, void, - ServoDeclarationBlock* declarations) + ServoDeclarationBlockBorrowed declarations) SERVO_BINDING_FUNC(Servo_ClearDeclarationBlockCachePointer, void, - ServoDeclarationBlock* declarations) + ServoDeclarationBlockBorrowed declarations) // CSS supports() SERVO_BINDING_FUNC(Servo_CSSSupports, bool, diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index 0d2957d4619f..fea0d50e1cf1 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -40,6 +40,7 @@ using namespace mozilla; IMPL_STRONG_REF_TYPE_FOR(ServoComputedValues) IMPL_STRONG_REF_TYPE_FOR(RawServoStyleSheet) +IMPL_STRONG_REF_TYPE_FOR(ServoDeclarationBlock) #undef IMPL_STRONG_REF_TYPE_FOR diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index d1f403be425b..c3ed384f8443 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -65,6 +65,7 @@ struct ServoDeclarationBlock; DECL_REF_TYPE_FOR(ServoComputedValues) DECL_REF_TYPE_FOR(RawServoStyleSheet) +DECL_REF_TYPE_FOR(ServoDeclarationBlock) #undef DECL_REF_TYPE_FOR @@ -145,7 +146,7 @@ SERVO_DECLARE_ELEMENT_ATTR_MATCHING_FUNCTIONS(Gecko_Snapshot, #undef SERVO_DECLARE_ELEMENT_ATTR_MATCHING_FUNCTIONS // Style attributes. -ServoDeclarationBlock* Gecko_GetServoDeclarationBlock(RawGeckoElement* element); +ServoDeclarationBlockBorrowed Gecko_GetServoDeclarationBlock(RawGeckoElement* element); // Node data. ServoNodeData* Gecko_GetNodeData(RawGeckoNode* node);