Bug 1388557 - Call RequestRestyle(Layer) in the case where we attach orphaned animating element to the document. r?birtles
MozReview-Commit-ID: IIcyYFROqDx
--- a/dom/animation/test/mozilla/file_restyles.html
+++ b/dom/animation/test/mozilla/file_restyles.html
@@ -1283,31 +1283,24 @@ waitForAllPaints(() => {
markers = await observeStyling(1);
if (isServo) {
// In Servo, we explicitly set important_rules_change flag to the element
// in compute_style() during the initial normal traversal right after
// re-attaching which leads to invoking a SequentialTask for
// CascadeResults which ends up calling RequestRestyle(Standard). As a
// result, the animation is restyled during a second animation restyle in
- // the first frame. If we fix the behavior when we attach an orphaned
- // element with script animations to a document so that it requests a
- // layer restyle (bug 1388557) before fixing important_rules_change in
- // compute_style() so that it no longer dispatches a needless standard
- // restyle (bug 1388560), we should add a test case that fails if we
- // continue to unnecessarily request a standard restyle.
+ // the first frame.
+ todo_is(markers.length, 1,
+ 'Bug 1388560 We should observe one restyle in the first frame ' +
+ 'right after re-attaching to the document');
+ } else {
is(markers.length, 1,
'We should observe one restyle in the first frame right after ' +
're-attaching to the document');
- } else {
- // Bug 1388557: We should call RequestRestyle(Layer) when an element which
- // has running script animations is attached to a document.
- todo_is(markers.length, 1,
- 'Bug 1388557 We should observe one restyle in the first frame ' +
- 'right after re-attaching to the document');
}
markers = await observeStyling(5);
is(markers.length, 5,
'Animation on re-attached to the document begins to update style');
await ensureElementRemoval(div);
});
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1844,16 +1844,29 @@ Element::BindToTree(nsIDocument* aDocume
nsIContent* parent = aParent;
while (parent && !parent->IsRootOfNativeAnonymousSubtree()) {
MOZ_ASSERT(parent->IsInNativeAnonymousSubtree());
parent->SetFlags(NODE_IS_NATIVE_ANONYMOUS);
parent = parent->GetParent();
}
MOZ_ASSERT(parent);
}
+
+ if (MayHaveAnimations() &&
+ (pseudoType == CSSPseudoElementType::NotPseudo ||
+ pseudoType == CSSPseudoElementType::before ||
+ pseudoType == CSSPseudoElementType::after) &&
+ EffectSet::GetEffectSet(this, pseudoType)) {
+ if (nsPresContext* presContext = aDocument->GetPresContext()) {
+ presContext->EffectCompositor()->
+ RequestRestyle(this, pseudoType,
+ EffectCompositor::RestyleType::Standard,
+ EffectCompositor::CascadeLevel::Animations);
+ }
+ }
}
// XXXbz script execution during binding can trigger some of these
// postcondition asserts.... But we do want that, since things will
// generally be quite broken when that happens.
MOZ_ASSERT(aDocument == GetUncomposedDoc(), "Bound to wrong document");
MOZ_ASSERT(aParent == GetParent(), "Bound to wrong parent");
MOZ_ASSERT(aBindingParent == GetBindingParent(),