Bug 1294299 part 9 - Implement Clone for ServoDeclarationBlock. r=heycam

MozReview-Commit-ID: 5y2h26j87Sz

--HG--
extra : source : 2e09860b35c9ab89fe959f9c6895a793858c4fee
This commit is contained in:
Xidorn Quan 2016-11-03 14:41:02 +11:00
parent 5e29805363
commit 3196565e73
5 changed files with 21 additions and 7 deletions

View File

@ -190,16 +190,10 @@ nsGenericHTMLElement::CopyInnerTo(Element* aDst)
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);

View File

@ -41,6 +41,8 @@ public:
inline MozExternalRefCountType AddRef();
inline MozExternalRefCountType Release();
inline already_AddRefed<DeclarationBlock> Clone() const;
/**
* Return whether |this| may be modified.
*/

View File

@ -26,6 +26,18 @@ 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
{

View File

@ -64,6 +64,8 @@ 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,

View File

@ -17,6 +17,10 @@ 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>