From 30c27e55730a238d52b1d5f8d79f86856b8d0954 Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Sun, 10 Aug 2014 17:06:46 +1000 Subject: [PATCH] Bug 1040543 part 3 - Add Animation interface; r=bz This patch adds the Animation interface and adds a 'source' attribute to AnimationPlayer that refers to this class. --- dom/animation/Animation.cpp | 24 +++++++++++ dom/animation/Animation.h | 46 ++++++++++++++++++++++ dom/animation/AnimationPlayer.h | 2 + dom/animation/moz.build | 2 + dom/tests/mochitest/general/test_interfaces.html | 2 + .../{AnimationPlayer.webidl => Animation.webidl} | 7 +--- dom/webidl/AnimationPlayer.webidl | 2 + dom/webidl/moz.build | 1 + 8 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 dom/animation/Animation.cpp create mode 100644 dom/animation/Animation.h copy dom/webidl/{AnimationPlayer.webidl => Animation.webidl} (67%) diff --git a/dom/animation/Animation.cpp b/dom/animation/Animation.cpp new file mode 100644 index 000000000000..9555793ebecf --- /dev/null +++ b/dom/animation/Animation.cpp @@ -0,0 +1,24 @@ +/* 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 "mozilla/dom/Animation.h" +#include "mozilla/dom/AnimationBinding.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Animation, mDocument) + +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Animation, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Animation, Release) + +JSObject* +Animation::WrapObject(JSContext* aCx) +{ + return AnimationBinding::Wrap(aCx, this); +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/animation/Animation.h b/dom/animation/Animation.h new file mode 100644 index 000000000000..f13728ce57c2 --- /dev/null +++ b/dom/animation/Animation.h @@ -0,0 +1,46 @@ +/* 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_Animation_h +#define mozilla_dom_Animation_h + +#include "nsAutoPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsIDocument.h" +#include "nsWrapperCache.h" +#include "mozilla/Attributes.h" + +struct JSContext; + +namespace mozilla { +namespace dom { + +class Animation MOZ_FINAL : public nsWrapperCache +{ +public: + explicit Animation(nsIDocument* aDocument) + : mDocument(aDocument) + { + SetIsDOMBinding(); + } + + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Animation) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(Animation) + + nsIDocument* GetParentObject() const { return mDocument; } + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; + +protected: + virtual ~Animation() { } + + // We use a document for a parent object since the other likely candidate, + // the target element, can be empty. + nsRefPtr mDocument; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_Animation_h diff --git a/dom/animation/AnimationPlayer.h b/dom/animation/AnimationPlayer.h index 750067dc9764..9c448d62b525 100644 --- a/dom/animation/AnimationPlayer.h +++ b/dom/animation/AnimationPlayer.h @@ -12,6 +12,7 @@ #include "mozilla/Attributes.h" #include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue #include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration +#include "mozilla/dom/Animation.h" // for Animation #include "mozilla/dom/AnimationTimeline.h" // for AnimationTimeline #include "nsCSSProperty.h" // for nsCSSProperty #include "nsSMILKeySpline.h" // for nsSMILKeySpline @@ -145,6 +146,7 @@ public: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; // AnimationPlayer methods + Animation* GetSource() const { return nullptr; } AnimationTimeline* Timeline() const { return mTimeline; } double StartTime() const; double CurrentTime() const; diff --git a/dom/animation/moz.build b/dom/animation/moz.build index 1a0b087183df..6cf1ef4c3b8f 100644 --- a/dom/animation/moz.build +++ b/dom/animation/moz.build @@ -7,11 +7,13 @@ MOCHITEST_MANIFESTS += ['test/mochitest.ini'] EXPORTS.mozilla.dom += [ + 'Animation.h', 'AnimationPlayer.h', 'AnimationTimeline.h', ] SOURCES += [ + 'Animation.cpp', 'AnimationPlayer.cpp', 'AnimationTimeline.cpp', ] diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index e3aa55e27e30..56755d1bd29f 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -119,6 +119,8 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "AnimationEvent", // IMPORTANT: Do not change this list without review from a DOM peer! + {name: "Animation", pref: "dom.animations-api.core.enabled"}, +// IMPORTANT: Do not change this list without review from a DOM peer! {name: "AnimationPlayer", pref: "dom.animations-api.core.enabled"}, // IMPORTANT: Do not change this list without review from a DOM peer! {name: "AnimationTimeline", pref: "dom.animations-api.core.enabled"}, diff --git a/dom/webidl/AnimationPlayer.webidl b/dom/webidl/Animation.webidl similarity index 67% copy from dom/webidl/AnimationPlayer.webidl copy to dom/webidl/Animation.webidl index a7c5b20f8098..a0ef7714753a 100644 --- a/dom/webidl/AnimationPlayer.webidl +++ b/dom/webidl/Animation.webidl @@ -4,15 +4,12 @@ * 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 + * http://dev.w3.org/fxtf/web-animations/#the-animation-interface * * Copyright © 2014 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C * liability, trademark and document use rules apply. */ [Pref="dom.animations-api.core.enabled"] -interface AnimationPlayer { - readonly attribute AnimationTimeline timeline; - [Pure] readonly attribute double startTime; - readonly attribute double currentTime; +interface Animation { }; diff --git a/dom/webidl/AnimationPlayer.webidl b/dom/webidl/AnimationPlayer.webidl index a7c5b20f8098..8b1099476268 100644 --- a/dom/webidl/AnimationPlayer.webidl +++ b/dom/webidl/AnimationPlayer.webidl @@ -12,6 +12,8 @@ [Pref="dom.animations-api.core.enabled"] interface AnimationPlayer { + // Bug 1049975: Per spec, this should be a writeable AnimationNode? member + [Pure] readonly attribute Animation? source; readonly attribute AnimationTimeline timeline; [Pure] readonly attribute double startTime; readonly attribute double currentTime; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 0aec679caed2..0670043ca042 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -21,6 +21,7 @@ WEBIDL_FILES = [ 'AlarmsManager.webidl', 'AnalyserNode.webidl', 'Animatable.webidl', + 'Animation.webidl', 'AnimationEvent.webidl', 'AnimationPlayer.webidl', 'AnimationTimeline.webidl', -- 2.11.4.GIT