From 6b5fcefb3639da5331d3ad7adf938ce4ba410bcb Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Fri, 10 Apr 2015 10:34:22 +0900 Subject: [PATCH] Bug 1152171 part 2 - Rename AnimationTimeline to DocumentTimeline; r=smaug And then re-add AnimationTimeline as an abstract super-interface of DocumentTimeline. --HG-- rename : dom/animation/AnimationTimeline.cpp => dom/animation/DocumentTimeline.cpp rename : dom/animation/AnimationTimeline.h => dom/animation/DocumentTimeline.h rename : dom/animation/test/animation-timeline/test_animation-timeline.html => dom/animation/test/document-timeline/test_document-timeline.html rename : dom/animation/test/animation-timeline/test_request_animation_frame.html => dom/animation/test/document-timeline/test_request_animation_frame.html --- dom/animation/AnimationPlayer.cpp | 2 +- dom/animation/AnimationPlayer.h | 13 +- dom/animation/AnimationTimeline.cpp | 113 +--------------- dom/animation/AnimationTimeline.h | 62 ++------- dom/animation/DocumentTimeline.cpp | 123 ++++++++++++++++++ dom/animation/DocumentTimeline.h | 76 +++++++++++ dom/animation/PendingPlayerTracker.cpp | 4 +- dom/animation/moz.build | 3 + .../test_document-timeline.html} | 2 +- .../test_request_animation_frame.html | 0 dom/animation/test/mochitest.ini | 6 +- dom/base/nsDocument.cpp | 16 +-- dom/base/nsDocument.h | 4 +- dom/base/nsIDocument.h | 4 +- dom/bindings/Bindings.conf | 4 + .../mochitest/general/test_interfaces.html | 2 + dom/webidl/AnimationTimeline.webidl | 4 +- dom/webidl/Document.webidl | 4 +- dom/webidl/DocumentTimeline.webidl | 17 +++ dom/webidl/moz.build | 1 + layout/style/nsAnimationManager.cpp | 4 +- layout/style/nsAnimationManager.h | 4 +- layout/style/nsTransitionManager.cpp | 2 +- layout/style/nsTransitionManager.h | 2 +- 24 files changed, 282 insertions(+), 190 deletions(-) create mode 100644 dom/animation/DocumentTimeline.cpp create mode 100644 dom/animation/DocumentTimeline.h rename dom/animation/test/{animation-timeline/test_animation-timeline.html => document-timeline/test_document-timeline.html} (98%) rename dom/animation/test/{animation-timeline => document-timeline}/test_request_animation_frame.html (100%) create mode 100644 dom/webidl/DocumentTimeline.webidl diff --git a/dom/animation/AnimationPlayer.cpp b/dom/animation/AnimationPlayer.cpp index 625399469a1a..c3d9f2e45cf3 100644 --- a/dom/animation/AnimationPlayer.cpp +++ b/dom/animation/AnimationPlayer.cpp @@ -180,7 +180,7 @@ AnimationPlayer::PlayState() const } static inline already_AddRefed -CreatePromise(AnimationTimeline* aTimeline, ErrorResult& aRv) +CreatePromise(DocumentTimeline* aTimeline, ErrorResult& aRv) { nsIGlobalObject* global = aTimeline->GetParentObject(); if (global) { diff --git a/dom/animation/AnimationPlayer.h b/dom/animation/AnimationPlayer.h index fb29b68d1a99..2215c4913b70 100644 --- a/dom/animation/AnimationPlayer.h +++ b/dom/animation/AnimationPlayer.h @@ -12,7 +12,7 @@ #include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration #include "mozilla/dom/Animation.h" // for Animation #include "mozilla/dom/AnimationPlayerBinding.h" // for AnimationPlayState -#include "mozilla/dom/AnimationTimeline.h" // for AnimationTimeline +#include "mozilla/dom/DocumentTimeline.h" // for DocumentTimeline #include "mozilla/dom/Promise.h" // for Promise #include "nsCSSProperty.h" // for nsCSSProperty @@ -51,7 +51,7 @@ protected: virtual ~AnimationPlayer() {} public: - explicit AnimationPlayer(AnimationTimeline* aTimeline) + explicit AnimationPlayer(DocumentTimeline* aTimeline) : mTimeline(aTimeline) , mPlaybackRate(1.0) , mPendingState(PendingState::NotPending) @@ -65,8 +65,9 @@ public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AnimationPlayer) - AnimationTimeline* GetParentObject() const { return mTimeline; } - virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + DocumentTimeline* GetParentObject() const { return mTimeline; } + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; virtual CSSAnimationPlayer* AsCSSAnimationPlayer() { return nullptr; } virtual CSSTransitionPlayer* AsCSSTransitionPlayer() { return nullptr; } @@ -80,7 +81,7 @@ public: // AnimationPlayer methods Animation* GetSource() const { return mSource; } - AnimationTimeline* Timeline() const { return mTimeline; } + DocumentTimeline* Timeline() const { return mTimeline; } Nullable GetStartTime() const { return mStartTime; } void SetStartTime(const Nullable& aNewStartTime); Nullable GetCurrentTime() const; @@ -301,7 +302,7 @@ protected: virtual css::CommonAnimationManager* GetAnimationManager() const = 0; AnimationPlayerCollection* GetCollection() const; - nsRefPtr mTimeline; + nsRefPtr mTimeline; nsRefPtr mSource; // The beginning of the delay period. Nullable mStartTime; // Timeline timescale diff --git a/dom/animation/AnimationTimeline.cpp b/dom/animation/AnimationTimeline.cpp index d83ae7389b9f..73033a5de580 100644 --- a/dom/animation/AnimationTimeline.cpp +++ b/dom/animation/AnimationTimeline.cpp @@ -4,118 +4,19 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "AnimationTimeline.h" -#include "mozilla/dom/AnimationTimelineBinding.h" -#include "AnimationUtils.h" -#include "nsContentUtils.h" -#include "nsIPresShell.h" -#include "nsPresContext.h" -#include "nsRefreshDriver.h" -#include "nsDOMNavigationTiming.h" namespace mozilla { namespace dom { -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AnimationTimeline, mDocument, mWindow) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AnimationTimeline, mWindow) -NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AnimationTimeline, AddRef) -NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AnimationTimeline, Release) +NS_IMPL_CYCLE_COLLECTING_ADDREF(AnimationTimeline) +NS_IMPL_CYCLE_COLLECTING_RELEASE(AnimationTimeline) -JSObject* -AnimationTimeline::WrapObject(JSContext* aCx, JS::Handle aGivenProto) -{ - return AnimationTimelineBinding::Wrap(aCx, this, aGivenProto); -} - -Nullable -AnimationTimeline::GetCurrentTime() const -{ - return ToTimelineTime(GetCurrentTimeStamp()); -} - -Nullable -AnimationTimeline::GetCurrentTimeAsDouble() const -{ - return AnimationUtils::TimeDurationToDouble(GetCurrentTime()); -} - -TimeStamp -AnimationTimeline::GetCurrentTimeStamp() const -{ - nsRefreshDriver* refreshDriver = GetRefreshDriver(); - TimeStamp refreshTime = refreshDriver - ? refreshDriver->MostRecentRefresh() - : TimeStamp(); - - // Always return the same object to benefit from return-value optimization. - TimeStamp result = !refreshTime.IsNull() - ? refreshTime - : mLastRefreshDriverTime; - - // If we don't have a refresh driver and we've never had one use the - // timeline's zero time. - if (result.IsNull()) { - nsRefPtr timing = mDocument->GetNavigationTiming(); - if (timing) { - result = timing->GetNavigationStartTimeStamp(); - // Also, let this time represent the current refresh time. This way - // we'll save it as the last refresh time and skip looking up - // navigation timing each time. - refreshTime = result; - } - } - - if (!refreshTime.IsNull()) { - mLastRefreshDriverTime = refreshTime; - } - - return result; -} - -Nullable -AnimationTimeline::ToTimelineTime(const TimeStamp& aTimeStamp) const -{ - Nullable result; // Initializes to null - if (aTimeStamp.IsNull()) { - return result; - } - - nsRefPtr timing = mDocument->GetNavigationTiming(); - if (MOZ_UNLIKELY(!timing)) { - return result; - } - - result.SetValue(aTimeStamp - timing->GetNavigationStartTimeStamp()); - return result; -} - -TimeStamp -AnimationTimeline::ToTimeStamp(const TimeDuration& aTimeDuration) const -{ - TimeStamp result; - nsRefPtr timing = mDocument->GetNavigationTiming(); - if (MOZ_UNLIKELY(!timing)) { - return result; - } - - result = timing->GetNavigationStartTimeStamp() + aTimeDuration; - return result; -} - -nsRefreshDriver* -AnimationTimeline::GetRefreshDriver() const -{ - nsIPresShell* presShell = mDocument->GetShell(); - if (MOZ_UNLIKELY(!presShell)) { - return nullptr; - } - - nsPresContext* presContext = presShell->GetPresContext(); - if (MOZ_UNLIKELY(!presContext)) { - return nullptr; - } - - return presContext->RefreshDriver(); -} +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AnimationTimeline) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END } // namespace dom } // namespace mozilla diff --git a/dom/animation/AnimationTimeline.h b/dom/animation/AnimationTimeline.h index 6a1f320ab0ea..8faaf54f75a1 100644 --- a/dom/animation/AnimationTimeline.h +++ b/dom/animation/AnimationTimeline.h @@ -6,26 +6,24 @@ #ifndef mozilla_dom_AnimationTimeline_h #define mozilla_dom_AnimationTimeline_h +#include "nsISupports.h" #include "nsWrapperCache.h" #include "nsCycleCollectionParticipant.h" +#include "mozilla/AnimationUtils.h" #include "mozilla/Attributes.h" -#include "mozilla/TimeStamp.h" #include "nsIGlobalObject.h" #include "js/TypeDecls.h" -#include "nsIDocument.h" -#include "nsRefreshDriver.h" - -struct JSContext; namespace mozilla { namespace dom { -class AnimationTimeline final : public nsWrapperCache +class AnimationTimeline + : public nsISupports + , public nsWrapperCache { public: - explicit AnimationTimeline(nsIDocument* aDocument) - : mDocument(aDocument) - , mWindow(aDocument->GetParentObject()) + explicit AnimationTimeline(nsIGlobalObject* aWindow) + : mWindow(aWindow) { MOZ_ASSERT(mWindow); } @@ -34,56 +32,22 @@ protected: virtual ~AnimationTimeline() { } public: - NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationTimeline) - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AnimationTimeline) + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AnimationTimeline) - nsIGlobalObject* GetParentObject() const - { - return mWindow; - } - virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + nsIGlobalObject* GetParentObject() const { return mWindow; } // AnimationTimeline methods - Nullable GetCurrentTime() const; + virtual Nullable GetCurrentTime() const = 0; // Wrapper functions for AnimationTimeline DOM methods when called from // script. - Nullable GetCurrentTimeAsDouble() const; - - // Converts a TimeStamp to the equivalent value in timeline time. - // Note that when IsUnderTestControl() is true, there is no correspondence - // between timeline time and wallclock time. In such a case, passing a - // timestamp from TimeStamp::Now() to this method will not return a - // meaningful result. - Nullable ToTimelineTime(const TimeStamp& aTimeStamp) const; - TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const; - - nsRefreshDriver* GetRefreshDriver() const; - // Returns true if this timeline is driven by a refresh driver that is - // under test control. In such a case, there is no correspondence between - // TimeStamp values returned by the refresh driver and wallclock time. - // As a result, passing a value from TimeStamp::Now() to ToTimelineTime() - // would not return a meaningful result. - bool IsUnderTestControl() const - { - nsRefreshDriver* refreshDriver = GetRefreshDriver(); - return refreshDriver && refreshDriver->IsTestControllingRefreshesEnabled(); + Nullable GetCurrentTimeAsDouble() const { + return AnimationUtils::TimeDurationToDouble(GetCurrentTime()); } protected: - TimeStamp GetCurrentTimeStamp() const; - - // Sometimes documents can be given a new window, or windows can be given a - // new document (e.g. document.open()). Since GetParentObject is required to - // _always_ return the same object it can't get the window from our - // mDocument, which is why we have pointers to both our document and window. - nsCOMPtr mDocument; nsCOMPtr mWindow; - - // The most recently used refresh driver time. This is used in cases where - // we don't have a refresh driver (e.g. because we are in a display:none - // iframe). - mutable TimeStamp mLastRefreshDriverTime; }; } // namespace dom diff --git a/dom/animation/DocumentTimeline.cpp b/dom/animation/DocumentTimeline.cpp new file mode 100644 index 000000000000..1ed91d9a8982 --- /dev/null +++ b/dom/animation/DocumentTimeline.cpp @@ -0,0 +1,123 @@ +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "DocumentTimeline.h" +#include "mozilla/dom/DocumentTimelineBinding.h" +#include "AnimationUtils.h" +#include "nsContentUtils.h" +#include "nsIPresShell.h" +#include "nsPresContext.h" +#include "nsRefreshDriver.h" +#include "nsDOMNavigationTiming.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION_INHERITED(DocumentTimeline, AnimationTimeline, + mDocument) + +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(DocumentTimeline, + AnimationTimeline) +NS_IMPL_CYCLE_COLLECTION_TRACE_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DocumentTimeline) +NS_INTERFACE_MAP_END_INHERITING(AnimationTimeline) + +NS_IMPL_ADDREF_INHERITED(DocumentTimeline, AnimationTimeline) +NS_IMPL_RELEASE_INHERITED(DocumentTimeline, AnimationTimeline) + +JSObject* +DocumentTimeline::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return DocumentTimelineBinding::Wrap(aCx, this, aGivenProto); +} + +Nullable +DocumentTimeline::GetCurrentTime() const +{ + return ToTimelineTime(GetCurrentTimeStamp()); +} + +TimeStamp +DocumentTimeline::GetCurrentTimeStamp() const +{ + nsRefreshDriver* refreshDriver = GetRefreshDriver(); + TimeStamp refreshTime = refreshDriver + ? refreshDriver->MostRecentRefresh() + : TimeStamp(); + + // Always return the same object to benefit from return-value optimization. + TimeStamp result = !refreshTime.IsNull() + ? refreshTime + : mLastRefreshDriverTime; + + // If we don't have a refresh driver and we've never had one use the + // timeline's zero time. + if (result.IsNull()) { + nsRefPtr timing = mDocument->GetNavigationTiming(); + if (timing) { + result = timing->GetNavigationStartTimeStamp(); + // Also, let this time represent the current refresh time. This way + // we'll save it as the last refresh time and skip looking up + // navigation timing each time. + refreshTime = result; + } + } + + if (!refreshTime.IsNull()) { + mLastRefreshDriverTime = refreshTime; + } + + return result; +} + +Nullable +DocumentTimeline::ToTimelineTime(const TimeStamp& aTimeStamp) const +{ + Nullable result; // Initializes to null + if (aTimeStamp.IsNull()) { + return result; + } + + nsRefPtr timing = mDocument->GetNavigationTiming(); + if (MOZ_UNLIKELY(!timing)) { + return result; + } + + result.SetValue(aTimeStamp - timing->GetNavigationStartTimeStamp()); + return result; +} + +TimeStamp +DocumentTimeline::ToTimeStamp(const TimeDuration& aTimeDuration) const +{ + TimeStamp result; + nsRefPtr timing = mDocument->GetNavigationTiming(); + if (MOZ_UNLIKELY(!timing)) { + return result; + } + + result = timing->GetNavigationStartTimeStamp() + aTimeDuration; + return result; +} + +nsRefreshDriver* +DocumentTimeline::GetRefreshDriver() const +{ + nsIPresShell* presShell = mDocument->GetShell(); + if (MOZ_UNLIKELY(!presShell)) { + return nullptr; + } + + nsPresContext* presContext = presShell->GetPresContext(); + if (MOZ_UNLIKELY(!presContext)) { + return nullptr; + } + + return presContext->RefreshDriver(); +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/animation/DocumentTimeline.h b/dom/animation/DocumentTimeline.h new file mode 100644 index 000000000000..20dedff2acfd --- /dev/null +++ b/dom/animation/DocumentTimeline.h @@ -0,0 +1,76 @@ +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_DocumentTimeline_h +#define mozilla_dom_DocumentTimeline_h + +#include "mozilla/TimeStamp.h" +#include "AnimationTimeline.h" +#include "nsIDocument.h" +#include "nsRefreshDriver.h" + +struct JSContext; + +namespace mozilla { +namespace dom { + +class DocumentTimeline final : public AnimationTimeline +{ +public: + explicit DocumentTimeline(nsIDocument* aDocument) + : AnimationTimeline(aDocument->GetParentObject()) + , mDocument(aDocument) + { + } + +protected: + virtual ~DocumentTimeline() { } + +public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DocumentTimeline, + AnimationTimeline) + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + // DocumentTimeline methods + virtual Nullable GetCurrentTime() const override; + + // Converts a TimeStamp to the equivalent value in timeline time. + // Note that when IsUnderTestControl() is true, there is no correspondence + // between timeline time and wallclock time. In such a case, passing a + // timestamp from TimeStamp::Now() to this method will not return a + // meaningful result. + Nullable ToTimelineTime(const TimeStamp& aTimeStamp) const; + TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const; + + nsRefreshDriver* GetRefreshDriver() const; + // Returns true if this timeline is driven by a refresh driver that is + // under test control. In such a case, there is no correspondence between + // TimeStamp values returned by the refresh driver and wallclock time. + // As a result, passing a value from TimeStamp::Now() to ToTimelineTime() + // would not return a meaningful result. + bool IsUnderTestControl() const + { + nsRefreshDriver* refreshDriver = GetRefreshDriver(); + return refreshDriver && refreshDriver->IsTestControllingRefreshesEnabled(); + } + +protected: + TimeStamp GetCurrentTimeStamp() const; + + nsCOMPtr mDocument; + + // The most recently used refresh driver time. This is used in cases where + // we don't have a refresh driver (e.g. because we are in a display:none + // iframe). + mutable TimeStamp mLastRefreshDriverTime; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_DocumentTimeline_h diff --git a/dom/animation/PendingPlayerTracker.cpp b/dom/animation/PendingPlayerTracker.cpp index 740cd71238ea..19aa81aa4b4b 100644 --- a/dom/animation/PendingPlayerTracker.cpp +++ b/dom/animation/PendingPlayerTracker.cpp @@ -5,7 +5,7 @@ #include "PendingPlayerTracker.h" -#include "mozilla/dom/AnimationTimeline.h" +#include "mozilla/dom/DocumentTimeline.h" #include "nsIFrame.h" #include "nsIPresShell.h" @@ -52,7 +52,7 @@ TriggerPlayerAtTime(nsRefPtrHashKey* aKey, void* aReadyTime) { dom::AnimationPlayer* player = aKey->GetKey(); - dom::AnimationTimeline* timeline = player->Timeline(); + dom::DocumentTimeline* timeline = player->Timeline(); // When the timeline's refresh driver is under test control, its values // have no correspondance to wallclock times so we shouldn't try to convert diff --git a/dom/animation/moz.build b/dom/animation/moz.build index 4be377afb272..5f564e271d5c 100644 --- a/dom/animation/moz.build +++ b/dom/animation/moz.build @@ -12,9 +12,11 @@ EXPORTS.mozilla.dom += [ 'AnimationEffect.h', 'AnimationPlayer.h', 'AnimationTimeline.h', + 'DocumentTimeline.h', ] EXPORTS.mozilla += [ + 'AnimationUtils.h', 'PendingPlayerTracker.h', ] @@ -23,6 +25,7 @@ UNIFIED_SOURCES += [ 'AnimationEffect.cpp', 'AnimationPlayer.cpp', 'AnimationTimeline.cpp', + 'DocumentTimeline.cpp', 'PendingPlayerTracker.cpp', ] diff --git a/dom/animation/test/animation-timeline/test_animation-timeline.html b/dom/animation/test/document-timeline/test_document-timeline.html similarity index 98% rename from dom/animation/test/animation-timeline/test_animation-timeline.html rename to dom/animation/test/document-timeline/test_document-timeline.html index 4740836e72d7..4d656135fd15 100644 --- a/dom/animation/test/animation-timeline/test_animation-timeline.html +++ b/dom/animation/test/document-timeline/test_document-timeline.html @@ -1,6 +1,6 @@ -Web Animations API: AnimationTimeline tests +Web Animations API: DocumentTimeline tests
diff --git a/dom/animation/test/animation-timeline/test_request_animation_frame.html b/dom/animation/test/document-timeline/test_request_animation_frame.html similarity index 100% rename from dom/animation/test/animation-timeline/test_request_animation_frame.html rename to dom/animation/test/document-timeline/test_request_animation_frame.html diff --git a/dom/animation/test/mochitest.ini b/dom/animation/test/mochitest.ini index fb1f754d856d..ca06f8b58a40 100644 --- a/dom/animation/test/mochitest.ini +++ b/dom/animation/test/mochitest.ini @@ -2,9 +2,6 @@ support-files = testcommon.js -[animation-timeline/test_animation-timeline.html] -[animation-timeline/test_request_animation_frame.html] -skip-if = buildapp == 'mulet' [css-animations/test_animations-dynamic-changes.html] [css-animations/test_animation-effect-name.html] [css-animations/test_animation-pausing.html] @@ -24,4 +21,7 @@ skip-if = buildapp == 'mulet' [css-transitions/test_animation-player-starttime.html] [css-transitions/test_element-get-animation-players.html] skip-if = buildapp == 'mulet' +[document-timeline/test_document-timeline.html] +[document-timeline/test_request_animation_frame.html] +skip-if = buildapp == 'mulet' [mozilla/test_deferred_start.html] diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 2b6c1cac4dd5..144b0fa7c28d 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -186,9 +186,9 @@ #include "nsSandboxFlags.h" #include "nsIAppsService.h" #include "mozilla/dom/AnonymousContent.h" -#include "mozilla/dom/AnimationTimeline.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/DocumentFragment.h" +#include "mozilla/dom/DocumentTimeline.h" #include "mozilla/dom/Event.h" #include "mozilla/dom/HTMLBodyElement.h" #include "mozilla/dom/HTMLInputElement.h" @@ -2017,7 +2017,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCachedEncoder) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStateObjectCached) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mUndoManager) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnimationTimeline) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentTimeline) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingPlayerTracker) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTemplateContentsOwner) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildrenCollection) @@ -2101,7 +2101,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK(mOriginalDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedEncoder) NS_IMPL_CYCLE_COLLECTION_UNLINK(mUndoManager) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnimationTimeline) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentTimeline) NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingPlayerTracker) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTemplateContentsOwner) NS_IMPL_CYCLE_COLLECTION_UNLINK(mChildrenCollection) @@ -2303,7 +2303,7 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) // Note that, since mTiming does not change during a reset, the // navigationStart time remains unchanged and therefore any future new // timeline will have the same global clock time as the old one. - mAnimationTimeline = nullptr; + mDocumentTimeline = nullptr; nsCOMPtr bag = do_QueryInterface(aChannel); if (bag) { @@ -3322,14 +3322,14 @@ nsDocument::IsWebAnimationsEnabled(JSContext* /*unused*/, JSObject* /*unused*/) Preferences::GetBool("dom.animations-api.core.enabled"); } -AnimationTimeline* +DocumentTimeline* nsDocument::Timeline() { - if (!mAnimationTimeline) { - mAnimationTimeline = new AnimationTimeline(this); + if (!mDocumentTimeline) { + mDocumentTimeline = new DocumentTimeline(this); } - return mAnimationTimeline; + return mDocumentTimeline; } /* Return true if the document is in the focused top-level window, and is an diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 1b1bf79ee6a6..3e9d50a09d4a 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -785,7 +785,7 @@ public: virtual already_AddRefed GetUndoManager() override; static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject); - virtual mozilla::dom::AnimationTimeline* Timeline() override; + virtual mozilla::dom::DocumentTimeline* Timeline() override; virtual nsresult SetSubDocumentFor(Element* aContent, nsIDocument* aSubDoc) override; @@ -1805,7 +1805,7 @@ private: nsRefPtr mUndoManager; - nsRefPtr mAnimationTimeline; + nsRefPtr mDocumentTimeline; enum ViewportType { DisplayWidthHeight, diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 474c5a40552b..1517b8aa1559 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -101,7 +101,6 @@ class VRHMDInfo; } // namespace gfx namespace dom { -class AnimationTimeline; class AnonymousContent; class Attr; class BoxObject; @@ -109,6 +108,7 @@ class CDATASection; class Comment; struct CustomElementDefinition; class DocumentFragment; +class DocumentTimeline; class DocumentType; class DOMImplementation; class DOMStringList; @@ -2087,7 +2087,7 @@ public: virtual already_AddRefed GetUndoManager() = 0; - virtual mozilla::dom::AnimationTimeline* Timeline() = 0; + virtual mozilla::dom::DocumentTimeline* Timeline() = 0; typedef mozilla::dom::CallbackObjectHolder< mozilla::dom::FrameRequestCallback, diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index ddcec77fdb82..402785966086 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -88,6 +88,10 @@ DOMInterfaces = { 'concrete': False }, +'AnimationTimeline': { + 'concrete': False +}, + 'AnonymousContent': { 'wrapperCache': False }, diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 31a3381f9627..d535964031ad 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -352,6 +352,8 @@ var interfaceNamesInGlobalScope = "Document", // IMPORTANT: Do not change this list without review from a DOM peer! "DocumentFragment", +// IMPORTANT: Do not change this list without review from a DOM peer! + {name: "DocumentTimeline", pref: "dom.animations-api.core.enabled"}, // IMPORTANT: Do not change this list without review from a DOM peer! "DocumentType", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/AnimationTimeline.webidl b/dom/webidl/AnimationTimeline.webidl index 14d67254ba31..5616ff9a9f42 100644 --- a/dom/webidl/AnimationTimeline.webidl +++ b/dom/webidl/AnimationTimeline.webidl @@ -4,9 +4,9 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. * * The origin of this IDL file is - * http://dev.w3.org/fxtf/web-animations/#the-animationtimeline-interface + * https://w3c.github.io/web-animations/#animationtimeline * - * Copyright © 2014 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C * liability, trademark and document use rules apply. */ diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index 13f2cae129e9..d385bf73c9f1 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -292,10 +292,10 @@ partial interface Document { //(Not implemented)NodeList findAll(DOMString selectors, optional (Element or sequence)? refNodes); }; -// http://dev.w3.org/fxtf/web-animations/#extensions-to-the-document-interface +// http://w3c.github.io/web-animations/#extensions-to-the-document-interface partial interface Document { [Func="nsDocument::IsWebAnimationsEnabled"] - readonly attribute AnimationTimeline timeline; + readonly attribute DocumentTimeline timeline; }; // Mozilla extensions of various sorts diff --git a/dom/webidl/DocumentTimeline.webidl b/dom/webidl/DocumentTimeline.webidl new file mode 100644 index 000000000000..bd7c793b490a --- /dev/null +++ b/dom/webidl/DocumentTimeline.webidl @@ -0,0 +1,17 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://w3c.github.io/web-animations/#documenttimeline + * + * Copyright © 2015 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C + * liability, trademark and document use rules apply. + */ + +// Not yet implemented: +// [Constructor (DOMHighResTimeStamp originTime)] +[Func="nsDocument::IsWebAnimationsEnabled"] +interface DocumentTimeline : AnimationTimeline { +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index a8d3f7578d7c..51d715d0524c 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -108,6 +108,7 @@ WEBIDL_FILES = [ 'DisplayPortInputPort.webidl', 'Document.webidl', 'DocumentFragment.webidl', + 'DocumentTimeline.webidl', 'DocumentType.webidl', 'DOMCursor.webidl', 'DOMError.webidl', diff --git a/layout/style/nsAnimationManager.cpp b/layout/style/nsAnimationManager.cpp index df7200c3734e..5f4bffacf3f1 100644 --- a/layout/style/nsAnimationManager.cpp +++ b/layout/style/nsAnimationManager.cpp @@ -290,7 +290,7 @@ nsAnimationManager::CheckAnimationRule(nsStyleContext* aStyleContext, nsAutoAnimationMutationBatch mb(aElement); // build the animations list - dom::AnimationTimeline* timeline = aElement->OwnerDoc()->Timeline(); + dom::DocumentTimeline* timeline = aElement->OwnerDoc()->Timeline(); AnimationPlayerPtrArray newPlayers; if (!aStyleContext->IsInDisplayNoneSubtree()) { BuildAnimations(aStyleContext, aElement, timeline, newPlayers); @@ -487,7 +487,7 @@ ResolvedStyleCache::Get(nsPresContext *aPresContext, void nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext, dom::Element* aTarget, - dom::AnimationTimeline* aTimeline, + dom::DocumentTimeline* aTimeline, AnimationPlayerPtrArray& aPlayers) { MOZ_ASSERT(aPlayers.IsEmpty(), "expect empty array"); diff --git a/layout/style/nsAnimationManager.h b/layout/style/nsAnimationManager.h index bd62b8e0207f..8aa814cadf02 100644 --- a/layout/style/nsAnimationManager.h +++ b/layout/style/nsAnimationManager.h @@ -55,7 +55,7 @@ typedef InfallibleTArray EventArray; class CSSAnimationPlayer final : public dom::AnimationPlayer { public: - explicit CSSAnimationPlayer(dom::AnimationTimeline* aTimeline) + explicit CSSAnimationPlayer(dom::DocumentTimeline* aTimeline) : dom::AnimationPlayer(aTimeline) , mIsStylePaused(false) , mPauseShouldStick(false) @@ -237,7 +237,7 @@ protected: private: void BuildAnimations(nsStyleContext* aStyleContext, mozilla::dom::Element* aTarget, - mozilla::dom::AnimationTimeline* aTimeline, + mozilla::dom::DocumentTimeline* aTimeline, mozilla::AnimationPlayerPtrArray& aAnimations); bool BuildSegment(InfallibleTArray& aSegments, diff --git a/layout/style/nsTransitionManager.cpp b/layout/style/nsTransitionManager.cpp index 8c9bdecda3a6..d39afc8e2738 100644 --- a/layout/style/nsTransitionManager.cpp +++ b/layout/style/nsTransitionManager.cpp @@ -398,7 +398,7 @@ nsTransitionManager::ConsiderStartingTransition( return; } - dom::AnimationTimeline* timeline = aElement->OwnerDoc()->Timeline(); + dom::DocumentTimeline* timeline = aElement->OwnerDoc()->Timeline(); StyleAnimationValue startValue, endValue, dummyValue; bool haveValues = diff --git a/layout/style/nsTransitionManager.h b/layout/style/nsTransitionManager.h index 76ad20e0046d..aa8bb9d16321 100644 --- a/layout/style/nsTransitionManager.h +++ b/layout/style/nsTransitionManager.h @@ -68,7 +68,7 @@ struct ElementPropertyTransition : public dom::Animation class CSSTransitionPlayer final : public dom::AnimationPlayer { public: - explicit CSSTransitionPlayer(dom::AnimationTimeline* aTimeline) + explicit CSSTransitionPlayer(dom::DocumentTimeline* aTimeline) : dom::AnimationPlayer(aTimeline) { }