Bug 1171817 part 14 - Add AnimationPtrComparator class; r=dbaron

Having created composite ordering methods for the different kinds of animations
this patch adds a Comparator class so that they can be used to sort an
array of such animations.

This patch uses this Comparator object to sort the results returned by
Element.getAnimations. For this case, the order in which we create animations
and transitions happens to almost perfectly correspond with the composite
ordering defined so that no sorting is necessary.

One exception is that some -moz-* transitions may be created after transitions
that they should sort before when sorting by transition property. In this
case the sorting added in this patch should ensure they are returned in the
correct sequence.

Unfortunately, we can't easily test this since the test files we have are
intended to be cross-browser (where -moz-* properties won't be supported).

Once we implement AnimationTimeline.getAnimations (bug 1150810) we'll have
a better opportunity to test this sorting. For now, the added tests in this
patch just serve as a regression test that the sorting hasn't upset the
already correct order (and an interop test in future once we move them to
web-platform-tests).

--HG--
extra : commitid : KkfoSE69B0F
extra : rebase_source : ee4e47f44281504eb4d35e0f6cc3392ee0cffb94
This commit is contained in:
Brian Birtles 2015-06-09 11:13:54 +09:00
Родитель 3c01d47be1
Коммит 6fbabd8dad
5 изменённых файлов: 81 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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_AnimationComparator_h
#define mozilla_AnimationComparator_h
namespace mozilla {
// Although this file is called AnimationComparator, we don't actually
// implement AnimationComparator (to compare const Animation& parameters)
// since it's not actually needed (yet).
template<typename AnimationPtrType>
class AnimationPtrComparator {
public:
bool Equals(const AnimationPtrType& a, const AnimationPtrType& b) const
{
return a == b;
}
bool LessThan(const AnimationPtrType& a, const AnimationPtrType& b) const
{
return a->HasLowerCompositeOrderThan(*b);
}
};
} // namespace mozilla
#endif // mozilla_AnimationComparator_h

Просмотреть файл

@ -16,6 +16,7 @@ EXPORTS.mozilla.dom += [
]
EXPORTS.mozilla += [
'AnimationComparator.h',
'AnimationUtils.h',
'PendingAnimationTracker.h',
]

Просмотреть файл

@ -37,7 +37,7 @@ async_test(function(t) {
'getAnimations returns Animations for all running CSS Transitions');
return waitForAllAnimations(animations);
})).then(t.step_func(function() {
assert_true(animations[1].startTime < animations[2].startTime,
assert_less_than(animations[1].startTime, animations[2].startTime,
'Animation for additional CSS transition starts after the original'
+ ' transitions and appears later in the list');
t.done();
@ -101,6 +101,47 @@ test(function(t) {
+ ' of an unsupported property');
}, 'getAnimations for transition on unsupported property');
test(function(t) {
var div = addDiv(t, { style: 'transform: translate(0px); ' +
'opacity: 0; ' +
'border-width: 0px; ' + // Shorthand
'border-style: solid' });
getComputedStyle(div).transform;
div.style.transition = 'all 100s';
div.style.transform = 'translate(100px)';
div.style.opacity = '1';
div.style.borderWidth = '1px';
var animations = div.getAnimations();
assert_equals(animations.length, 6,
'Generated expected number of transitions');
assert_equals(animations[0].transitionProperty, 'border-bottom-width');
assert_equals(animations[1].transitionProperty, 'border-left-width');
assert_equals(animations[2].transitionProperty, 'border-right-width');
assert_equals(animations[3].transitionProperty, 'border-top-width');
assert_equals(animations[4].transitionProperty, 'opacity');
assert_equals(animations[5].transitionProperty, 'transform');
}, 'getAnimations sorts simultaneous transitions by name');
test(function(t) {
var div = addDiv(t, { style: 'transform: translate(0px); ' +
'opacity: 0' });
getComputedStyle(div).transform;
div.style.transition = 'all 100s';
div.style.transform = 'translate(100px)';
assert_equals(div.getAnimations().length, 1,
'Initially there is only one (transform) transition');
div.style.opacity = '1';
assert_equals(div.getAnimations().length, 2,
'Then a second (opacity) transition is added');
var animations = div.getAnimations();
assert_equals(animations[0].transitionProperty, 'transform');
assert_equals(animations[1].transitionProperty, 'opacity');
}, 'getAnimations sorts transitions by when they were generated');
done();
</script>
</body>

Просмотреть файл

@ -78,8 +78,9 @@ function flushComputedStyle(elem) {
}
for (var funcName of ["async_test", "assert_not_equals", "assert_equals",
"assert_approx_equals", "assert_less_than_equal",
"assert_between_inclusive", "assert_true", "assert_false",
"assert_approx_equals", "assert_less_than",
"assert_less_than_equal", "assert_between_inclusive",
"assert_true", "assert_false",
"assert_class_string", "assert_throws", "test"]) {
window[funcName] = opener[funcName].bind(opener);
}

Просмотреть файл

@ -51,6 +51,7 @@
#include "nsDOMString.h"
#include "nsIScriptSecurityManager.h"
#include "nsIDOMMutationEvent.h"
#include "mozilla/AnimationComparator.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/EventDispatcher.h"
@ -3201,6 +3202,8 @@ Element::GetAnimations(nsTArray<nsRefPtr<Animation>>& aAnimations)
}
}
}
aAnimations.Sort(AnimationPtrComparator<nsRefPtr<Animation>>());
}
NS_IMETHODIMP