Bug 1474247 - Introduce nsDOMWindowUtils.isAnimationPending(). r?birtles
It might be possible that we can check whether an animation is being tracked
by the pending animation tracker without this function to count layout flush
since we force to flush layout if there is any pending animations [1]. But
it will probably result complicated test cases. So to make test cases simple,
we introduce a new function which just checking whether a given animation is
being tracked by the pending animation tracker.
[1] https://hg.mozilla.org/mozilla-central/file/3d20b0701781/layout/base/nsRefreshDriver.cpp#l1957
MozReview-Commit-ID: 4lWuOYCucaD
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -11,16 +11,17 @@
#include "nsPresContext.h"
#include "nsError.h"
#include "nsQueryContentEventResult.h"
#include "nsGlobalWindow.h"
#include "nsIDocument.h"
#include "nsFocusManager.h"
#include "nsFrameManager.h"
#include "nsRefreshDriver.h"
+#include "mozilla/dom/Animation.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/Touch.h"
#include "mozilla/PendingAnimationTracker.h"
#include "nsIObjectLoadingContent.h"
#include "nsFrame.h"
#include "mozilla/layers/ShadowLayers.h"
@@ -3801,16 +3802,43 @@ nsDOMWindowUtils::GetOMTCTransform(Eleme
nsAutoString text;
ErrorResult rv;
cssValue->GetCssText(text, rv);
aResult.Assign(text);
return rv.StealNSResult();
}
+NS_IMETHODIMP
+nsDOMWindowUtils::IsAnimationInPendingTracker(dom::Animation* aAnimation,
+ bool* aRetVal)
+{
+ MOZ_ASSERT(aRetVal);
+
+ if (!aAnimation) {
+ return NS_ERROR_INVALID_ARG;
+ }
+
+ nsIDocument* doc = GetDocument();
+ if (!doc) {
+ *aRetVal = false;
+ return NS_OK;
+ }
+
+ PendingAnimationTracker* tracker = doc->GetPendingAnimationTracker();
+ if (!tracker) {
+ *aRetVal = false;
+ return NS_OK;
+ }
+
+ *aRetVal = tracker->IsWaitingToPlay(*aAnimation) ||
+ tracker->IsWaitingToPause(*aAnimation);
+ return NS_OK;
+}
+
namespace {
class HandlingUserInputHelper final : public nsIJSRAIIHelper
{
public:
explicit HandlingUserInputHelper(bool aHandlingUserInput);
NS_DECL_ISUPPORTS
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -39,16 +39,17 @@ interface nsIFile;
interface nsIURI;
interface nsIRunnable;
interface nsITranslationNodeList;
interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest;
interface nsIObserver;
interface nsIDOMStorage;
+webidl Animation;
webidl DOMRect;
webidl Element;
webidl EventTarget;
webidl Event;
webidl Node;
webidl NodeList;
[scriptable, uuid(4d6732ca-9da7-4176-b8a1-8dde15cd0bf9)]
@@ -1702,16 +1703,22 @@ interface nsIDOMWindowUtils : nsISupport
* Unlike the above getOMTAStyle, the transform value returned by this
* includes both of animating and APZ values.
* Note: This function doesn't work on WebRender at all. Also this function
* does work only for transform layer and opacity layer with animations.
*/
AString getOMTCTransform(in Element aElement,
[optional] in AString aPseudoElement);
+ /*
+ * Returns true if the given animation is being tracked by the pending
+ * animation tracker for the current document.
+ */
+ bool isAnimationInPendingTracker(in Animation aAnimation);
+
/**
* If aHandlingInput is true, this informs the event state manager that
* we're handling user input. Otherwise, this is a no-op (as by default
* we're not handling user input).
* Remember to call destruct() on the return value!
* See also nsIDOMWindowUtils::isHandlingUserInput.
*/
nsIJSRAIIHelper setHandlingUserInput(in boolean aHandlingInput);