Possibilities for XUL Transitions and Animation
September 25th, 2008Aaron’s recent comments about problems a particular user was having with the sliding effect that the Firefox notification bar uses made me think again about how incorporating a easy means of doing transition and animtion-type effects in XUL and in the browser UI is needed. Naturally, if there’s an accessibility problem, a global preference to disable these types of effects is probably the most obvious option here. But whatever solution is used for that, it’s easy compared to finding a general solution to doing the transition effects in the first place. There’s been a strong desire from many that being able to incorporate these types of effects into the UI can open up a number of interesting possibilities to enhance the UI or direct the user’s attention to something of interest.
SVG incorporates an animation mechanism (mostly just by using parts of SMIL) that uses tags to declare animations that can be applied to other elements. In this way, one can specify that certain CSS properties or DOM attributes of an SVG element can be modified over time. The whole SMIL specification is quite complicated though. I could imagine that using a declarative form of animation using tags and attributes to specify what and how to animate to be useful in some cases.
A while ago, Webkit added support for a transition feature by adding some custom CSS properties. It works by smoothly adjusting the value of particular CSS properties whenever they change. This feature appears to have been designed intentionally such that one would be able to use it entirely from with a style sheet, without having to modify the document or use any script (and therefore browsers that don’t support the feature don’t suffer any ill effects). However, without script to accompany it, this transition feature is of somewhat limited value, mainly centered around the use of hover effects and the like, and, indeed, the scarce descriptions of this feature present hovering over an element as the main use case. The author also has little control over the transition, in fact, only the CSS properties that participate in transitions and characteristics about their speed can be controlled. The author has no ability to customize, for example, different behaviours for fading in versus fading out or to make an element glow or pulsate.
There’s also another related specification from Apple that defines a different form of animation, also defined in CSS. This allows one to define specific animations to apply to elements. Personally, I find the syntax for this animation feature rather ugly, and more importantly, it’s mostly only of use when used in conjuction with script that modifies the custom CSS properties the spec defines. It seems though that once script is required, it doesn’t make sense any more to define the behaviour in CSS and instead just provide some script APIs to accomplish what you need to.
Of course, all of this moot for XUL and UI as both SVG animation and the two Webkit animation proposals are intended for animating the value of CSS properties, and for many purposes in XUL, one doesn’t want to animate any CSS properties. Indeed, many slide-in effects like the notification bar actually want to have a transition occur when an element is made visible in some way (whatever way that may be), and smoothly grow to its intrinsic size. Note that this is distinctly different from changing the width or height of the element; in this case, both the width and height always remain set to ‘auto’ during the transition. (Note that the notification bar implementation currently does something quite different and overly complicated that I don’t really like — all the more reason for a better way to do this.) To give a more specific example, the smooth animation that occurs when scrolling through tabs when there are too many to display at once, adjusts the scroll position, a property which isn’t exposed to CSS or in the XML document at all.
I imagine there may be some value in allowing a declarative form of animation as SVG does, although I’d think here someone might complain if we invented a different syntax that SMIL or SVG animation (both W3C recommendations) use. There is also some value in the Webkit idea that transitions can be applied automatically, for example, allowing an element to smoothly change when some value is modified. There’s certainly a use of this to make for easier development in the case where an element might change in a variety of different ways. On the other hand, it’s quite often the case that the time when a animation effect should occur is known already, and should just be triggered by a script. For that, it may be easier just to add a simple API for all XUL elements:
element.transition(arguments)
Ideally, here, arguments would be just some opaque JavaScript object that the method can read properties of for different sorts of transitions. At the moment, I’m preferring an approach more akin to this, but am open to suggestions.
An issue here is performance. Various tests I’ve done show that performance isn’t spectacular for many cases, mainly due to the need to do a layout at each step. The notification bar that asks to save a password in Firefox, for example, pushes the entire content down, requiring it to be relaid out at each interval. My testing also shows that performance is quite slower when rendering native widgets on Mac at least. But some of these are problems that could be solved with a bit of work.
Another potential performance issue is whether to allow all elements to have animations, or just, say, create a special element that only animates itself and its children. This could easily extend one of the other elements (for XUL, presumably the generic box), but would have the disadvantage that it wouldn’t be as general purpose and could limit its use for certain effects. Allowing transitons on all elements, of course, means we need extra code and time to check for transitions on every element, most of which won’t be animating. (If most elements are animating, that UI you’re designing is more properly referred to as a cartoon).
Some interesting possibilities, but no clear solution here.


