Bug 1277456 part 6 - Use the composed document of the target effect (if any) when computing keyframe values; r=hiro
authorBrian Birtles <birtles@gmail.com>
Wed, 13 Jul 2016 13:22:25 +0900
changeset 305210 8cac50304a9a26559ac1a4fc86517b62a615354c
parent 305209 b6dd3c6ec969170a0151b7369a2528c8f4363b1d
child 305211 baf146b5a87613573ac3957ee56e1a4f23095f18
push id79518
push usercbook@mozilla.com
push dateSun, 17 Jul 2016 08:09:59 +0000
treeherdermozilla-inbound@711963e8daa3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro
bugs1277456
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1277456 part 6 - Use the composed document of the target effect (if any) when computing keyframe values; r=hiro Previously, when fetching an nsPresShell, we would look up the current realm document and get the pres shell for it. This patch makes us call GetPresShell() which uses GetRenderedDocument() which corresponds to the composed document of the target effect which seems more consistent since it is the target effect we will use as context for computing CSS values (as required by [1]). [1] https://w3c.github.io/web-animations/#calculating-computed-keyframes MozReview-Commit-ID: 9S55041rfTp
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -451,29 +451,23 @@ KeyframesEqualIgnoringComputedOffsets(co
 }
 
 // https://w3c.github.io/web-animations/#dom-keyframeeffect-setkeyframes
 void
 KeyframeEffectReadOnly::SetKeyframes(JSContext* aContext,
                                      JS::Handle<JSObject*> aKeyframes,
                                      ErrorResult& aRv)
 {
-  nsIDocument* doc = AnimationUtils::GetCurrentRealmDocument(aContext);
-  if (!doc) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return;
-  }
-
   nsTArray<Keyframe> keyframes =
     KeyframeUtils::GetKeyframesFromObject(aContext, mDocument, aKeyframes, aRv);
   if (aRv.Failed()) {
     return;
   }
 
-  RefPtr<nsStyleContext> styleContext = GetTargetStyleContext(doc);
+  RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
   SetKeyframes(Move(keyframes), styleContext);
 }
 
 void
 KeyframeEffectReadOnly::SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
                                   nsStyleContext* aStyleContext)
 {
   if (KeyframesEqualIgnoringComputedOffsets(aKeyframes, mKeyframes)) {
@@ -939,35 +933,31 @@ KeyframeEffectReadOnly::RequestRestyle(
   if (presContext && mTarget && mAnimation) {
     presContext->EffectCompositor()->
       RequestRestyle(mTarget->mElement, mTarget->mPseudoType,
                      aRestyleType, mAnimation->CascadeLevel());
   }
 }
 
 already_AddRefed<nsStyleContext>
-KeyframeEffectReadOnly::GetTargetStyleContext(nsIDocument* aDoc)
+KeyframeEffectReadOnly::GetTargetStyleContext()
 {
-  if (!mTarget) {
+  nsIPresShell* shell = GetPresShell();
+  if (!shell) {
     return nullptr;
   }
 
-  if (!aDoc) {
-    aDoc = mTarget->mElement->OwnerDoc();
-    if (!aDoc) {
-      return nullptr;
-    }
-  }
+  MOZ_ASSERT(mTarget,
+             "Should only have a presshell when we have a target element");
 
   nsIAtom* pseudo = mTarget->mPseudoType < CSSPseudoElementType::Count
                     ? nsCSSPseudoElements::GetPseudoAtom(mTarget->mPseudoType)
                     : nullptr;
   return nsComputedDOMStyle::GetStyleContextForElement(mTarget->mElement,
-                                                       pseudo,
-                                                       aDoc->GetShell());
+                                                       pseudo, shell);
 }
 
 #ifdef DEBUG
 void
 DumpAnimationProperties(nsTArray<AnimationProperty>& aAnimationProperties)
 {
   for (auto& p : aAnimationProperties) {
     printf("%s\n", nsCSSProps::GetStringValue(p.mProperty).get());
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -395,19 +395,18 @@ protected:
   // have changed, or when the target frame might have changed.
   void MaybeUpdateFrameForCompositor();
 
   // Looks up the style context associated with the target element, if any.
   // We need to be careful to *not* call this when we are updating the style
   // context. That's because calling GetStyleContextForElement when we are in
   // the process of building a style context may trigger various forms of
   // infinite recursion.
-  // If aDoc is nullptr, we will use the owner doc of the target element.
   already_AddRefed<nsStyleContext>
-  GetTargetStyleContext(nsIDocument* aDoc = nullptr);
+  GetTargetStyleContext();
 
   Maybe<OwningAnimationTarget> mTarget;
   RefPtr<Animation> mAnimation;
 
   RefPtr<AnimationEffectTimingReadOnly> mTiming;
   KeyframeEffectParams mEffectOptions;
 
   // The specified keyframes.