Implement AnimationEffect and AnimationEffect.name

RESOLVED FIXED in mozilla34

Status

()

defect
RESOLVED FIXED
5 years ago
2 months ago

People

(Reporter: birtles, Assigned: birtles)

Tracking

({dev-doc-needed})

Trunk
mozilla34
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(4 attachments, 3 obsolete attachments)

Assignee

Description

5 years ago
It would be useful to be able to trace back from an Animation to the @keyframes rule used to generate it. This would be particularly useful for the DevTools team.

In Web Animations, the Animation interface has an 'effect' member of type AnimationEffect. One subclass of this is KeyframeEffect.

In discussion with Google, we've agreed to add a 'name' DOMString attribute to AnimationEffect for this. I've yet to add this to the spec, however.

(Google also want a 'name' attribute on Animation which the author can set to whatever they like. The point of standardizing it would be that then developer tools can use this as an informational aid. I'm not totally convinced about this, but anyway.)

For now I think it would be enough to add a [Cached] 'effect' property to Animation that generates a KeyframeEffect with a single readonly attribute 'name' of type DOMString. This KeyframeEffect object, when generated could have a pointer back to its Animation and read its mName.

Currently the mName lives on AnimationPlayer, however. It is used when we regenerate animations to match old players with new players. It probably should stay on the AnimationPlayer for this purpose so perhaps we need to copy it to the Animation? (Since Animations don't have a pointer to their AnimationPlayer by design.)
Assignee

Comment 1

5 years ago
Posted patch part 1 - Add Animation.effect (obsolete) — Splinter Review
Attachment #8474984 - Flags: review?(dbaron)
Assignee

Updated

5 years ago
Assignee: nobody → birtles
Status: NEW → ASSIGNED
Assignee

Comment 2

5 years ago
This patch stores the animation name on the Animation object rather than its
AnimationPlayer. This is because Animation objects don't have a reference to
their AnimationPlayer but their AnimationEffect needs access to the animation
name.

This patch also adds an accessor for AnimationPlayer to get the name from its
Animation (since players *do* have a reference to their source animation
content).
Attachment #8474986 - Flags: review?(dbaron)
Assignee

Comment 3

5 years ago
Attachment #8474987 - Flags: review?(dbaron)
Assignee

Comment 5

5 years ago
These patches build on top of the patch from bug 1045994.
Depends on: 1045994
Assignee

Comment 6

5 years ago
https://tbpl.mozilla.org/?tree=Try&rev=fdc34544b9b9
Summary: Implement KeyframeEffect and KeyframeEffect.name → Implement AnimationEffect and AnimationEffect.name
Assignee

Comment 7

5 years ago
Notes for review:

Purpose: Expose the animation-name value used to generate animations specified by CSS animations.

It is expected this will be:
* used by DevTools as an informational aid so authors can match up the Animation(Player) objects with their source
* used by Web content and DevTools as they iterate over the values returned by getAnimationPlayers() to find a particular animation

However, I'm not entirely confident this is the "right" place to expose the animation-name.

Web Animations has the following hierarchy:

  AnimationPlayer(0..1)-->(0..1)Animation(0..1)-->(0..1)AnimationEffect

  AnimationEffect is an abstract interface with sub-interfaces KeyframeEffect and MotionPathEffect.

  (There has been some talk about making AnimationEffects shareable through some global effect repository but I don't know where that proposal is up to.)

So where should the animation name be exposed?

(a) AnimationPlayer -- when we update animations internally we match old and new AnimationPlayer objects based on their name so the name needs to be accessible from the AnimationPlayer. Furthermore, if it becomes possible to change the name associated with an Animation or AnimationEffect (either by making the name attribute writeable or by allowing these objects to be replaced) then we'll probably need a copy of the original name on the AnimationPlayer for matching purposes. Putting the name on the AnimationPlayer also probably simplifies the use-cases above.

(b) Animation -- animation-name is a key to a @keyframes rule so the key could possibly be stored in the Animation? (I'm a little concerned that doing so would create the expectation that changing it makes us replace the AnimationEffect by doing a lookup of @keyframes rules based on the new name).

(c) AnimationEffect -- the 'name' labels the @keyframes rule and @keyframes rules map most closely to KeyframeEffect objects (with the slight exception that there may be several unique KeyframeEffect objects corresponding to a single @keyframes rule due to the way animation-timing-function is inherited).

I've gone with (c) since I think it is the most natural place for this property to live. This was the agreement reached with Google.[1] However, I realise it makes using the property more awkward. Specifically you have to write player.source.effect.name.

I haven't added this property to the spec yet because:
(a) Google still have some outstanding actions around this such as determining how it gets specified by the AnimationEffect / Animation constructor and how it gets used for SVG.[1]
(b) Google also want to add a |name| property to the Animation interface that is purely for authors to have a consistent property for labelling their content so that it can be displayed by their DevTools. I'm not entirely sure this is a good idea yet (also because there's no obvious place to specify this in the constructor to an Animation).

All that is to say, "feel free to question whether these patches are doing the right thing at all."

[1] http://lists.w3.org/Archives/Public/public-fx/2014JulSep/0006.html
Comment on attachment 8474984 [details] [diff] [review]
part 1 - Add Animation.effect

AnimationEffect may as well have a private destructor given that
release is the only correct way to destroy it.

Also, I don't think AnimationEffect needs a virtual destructor -- though
you should then make the class MOZ_FINAL.

I don't feel particularly qualified to comment on what the API should
be, but r=dbaron anyway.

A DOM peer needs to review this as well, though.
Attachment #8474984 - Flags: review?(dbaron) → review+
Comment on attachment 8474986 [details] [diff] [review]
part 2 - Move the animation name from AnimationPlayer to Animation

Please prefer the name "nsSubstring" over "nsAString".  
(nsAnimationManager.h, Animation.h, AnimationPlayer.h)

AnimationPlayer::Name() should just return const nsString&, though,
since it is.

Should dom::Animation really have a constructor that doesn't take
a name?  Is that still needed?  It seems preferable not to increase
the number of constructors to maintain, and also not to leave some 
callers missing an argument they should be passing.

Shouldn't you be removing mName from dom::AnimationPlayer?

r=dbaron with that
Attachment #8474986 - Flags: review?(dbaron) → review+
Comment on attachment 8474987 [details] [diff] [review]
part 3 - Add AnimationEffect.name

It would be good to get this in a spec sooner rather than later if you've agreed on it.

r=dbaron, assuming it gets into a spec sooish
Attachment #8474987 - Flags: review?(dbaron) → review+
Attachment #8474988 - Flags: review?(dbaron) → review+
Assignee

Comment 11

5 years ago
Address review feedback.

Boris, can you please check the WebIDL parts of this? Thanks.
Attachment #8476557 - Flags: review?(bzbarsky)
Assignee

Updated

5 years ago
Attachment #8474984 - Attachment is obsolete: true
Assignee

Comment 12

5 years ago
(In reply to David Baron [:dbaron] (UTC-7) (needinfo? for questions) (away/busy Aug 27-Sep 11) from comment #9)
> Comment on attachment 8474986 [details] [diff] [review]
> part 2 - Move the animation name from AnimationPlayer to Animation
> 
> Please prefer the name "nsSubstring" over "nsAString".  
> (nsAnimationManager.h, Animation.h, AnimationPlayer.h)

Fixed. I wasn't sure about that so thanks for pointing it out.

> AnimationPlayer::Name() should just return const nsString&, though,
> since it is.

Fixed.

> Should dom::Animation really have a constructor that doesn't take
> a name?  Is that still needed?  It seems preferable not to increase
> the number of constructors to maintain, and also not to leave some 
> callers missing an argument they should be passing.

Fixed.

> Shouldn't you be removing mName from dom::AnimationPlayer?

Yes, sorry, that's sloppy work on my part. I've been trying to get too many things done this month.
Assignee

Updated

5 years ago
Attachment #8474986 - Attachment is obsolete: true
Assignee

Updated

5 years ago
Attachment #8474987 - Attachment is obsolete: true
Assignee

Comment 14

5 years ago
(In reply to David Baron [:dbaron] (UTC-7) (needinfo? for questions) (away/busy Aug 27-Sep 11) from comment #10)
> Comment on attachment 8474987 [details] [diff] [review]
> part 3 - Add AnimationEffect.name
> 
> It would be good to get this in a spec sooner rather than later if you've
> agreed on it.

Added:
https://github.com/web-animations/web-animations-spec/commit/3c57d6e81e2b59315a1609a2cdd82ce3a6ab37ca

(This is the bikeshed/github version of the spec which we're switching to as soon as the Google guys get around to doing it.)
Assignee

Comment 16

5 years ago
Comment on attachment 8476560 [details] [diff] [review]
part 3 - Add AnimationEffect.name

Hi Boris, can I ask you to review the WebIDL parts of this too.

(I seem to be asking you for a lot of these kind of reviews. Is there someone else you prefer I send them too?)
Attachment #8476560 - Flags: review?(bzbarsky)
Comment on attachment 8476557 [details] [diff] [review]
part 1 - Add AnimationEffect interface and Animation.effect member

Why not just make the method non-const instead of doing the weird casting?

Will anyone use this API from C++?  The behavior difference wrt JS (always returning the same thing in JS, vs a new object each time in C++) might be worth a comment in the header at least.

r=me
Attachment #8476557 - Flags: review?(bzbarsky) → review+
Comment on attachment 8476560 [details] [diff] [review]
part 3 - Add AnimationEffect.name

> Is there someone else you prefer I send them too?

I'm ok doing them; they're pretty quick.  Other options if you want quick turnaround are basically "smaug".  If you're ok with slower turnaround, bholley or khuey or peterv or jst or mrbkap are viable options.  The full list of whitelisted IDL reviewers as of today is at http://hg.mozilla.org/hgcustom/hghooks/file/1da6c5dff8e2/mozhghooks/prevent_webidl_changes.py#l36

r=me
Attachment #8476560 - Flags: review?(bzbarsky) → review+
Assignee

Comment 19

5 years ago
(In reply to Boris Zbarsky [:bz] from comment #17)
> Comment on attachment 8476557 [details] [diff] [review]
> part 1 - Add AnimationEffect interface and Animation.effect member
> 
> Why not just make the method non-const instead of doing the weird casting?

I didn't realise the bindings let you do that. I thought the method signature generated by 'mach webidl-example' was final.
 
> Will anyone use this API from C++?  The behavior difference wrt JS (always
> returning the same thing in JS, vs a new object each time in C++) might be
> worth a comment in the header at least.

No-one will use it from C++ yet. Later on they will (when we move keyframes into that object) but at that point we'll also generate the object at the outset and manage it on the Animation, not via [Cached]. I'll add a comment.
> I thought the method signature generated by 'mach webidl-example' was final.

Ah.  One of the major points of the bindings was that the callee can choose stuff about their function signature like constness, ABI, etc.  The caller is just C++ calling into the callee, so as long as the name matches and the arguments end up compatible and the return value ends up compatible everything is fine.
Component: DOM → DOM: Core & HTML
Product: Core → Core
You need to log in before you can comment on or make changes to this bug.