Skip to content

Commit

Permalink
Make PriorityCompare a SMILAnimationSandwich detail
Browse files Browse the repository at this point in the history
The ordering required in SMILTimeContainer::ApplyAnimationValues isn't
really the full-blown ordering used for sandwiches - using only the
"document order index" should be sufficient (although arguably still not
correct).

Bug: 998526
Change-Id: I293b9e55824c2b683b5991e7da3266958eb94e67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1840991
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#703073}
  • Loading branch information
Fredrik Söderquist authored and Commit Bot committed Oct 4, 2019
1 parent f49a863 commit ee784aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@

namespace blink {

namespace {

struct PriorityCompare {
PriorityCompare(SMILTime elapsed) : elapsed_(elapsed) {}
bool operator()(const Member<SVGSMILElement>& a,
const Member<SVGSMILElement>& b) {
// FIXME: This should also consider possible timing relations between the
// elements.
SMILTime a_begin = a->BeginTimeForPrioritization(elapsed_);
SMILTime b_begin = b->BeginTimeForPrioritization(elapsed_);
if (a_begin == b_begin)
return a->DocumentOrderIndex() < b->DocumentOrderIndex();
return a_begin < b_begin;
}
SMILTime elapsed_;
};

} // namespace

SMILAnimationSandwich::SMILAnimationSandwich() = default;

void SMILAnimationSandwich::Schedule(SVGSMILElement* animation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@

namespace blink {

struct PriorityCompare {
PriorityCompare(SMILTime elapsed) : elapsed_(elapsed) {}
bool operator()(const Member<SVGSMILElement>& a,
const Member<SVGSMILElement>& b) {
// FIXME: This should also consider possible timing relations between the
// elements.
SMILTime a_begin = a->BeginTimeForPrioritization(elapsed_);
SMILTime b_begin = b->BeginTimeForPrioritization(elapsed_);
if (a_begin == b_begin)
return a->DocumentOrderIndex() < b->DocumentOrderIndex();
return a_begin < b_begin;
}
SMILTime elapsed_;
};

// This class implements/helps with implementing the "sandwich model" from SMIL.
// https://www.w3.org/TR/SMIL3/smil-animation.html#animationNS-AnimationSandwichModel
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,13 @@ void SMILTimeContainer::ApplyAnimationValues(SMILTime elapsed) {
// Everything bellow handles "discard" elements.
UseCounter::Count(&GetDocument(), WebFeature::kSVGSMILAnimationAppliedEffect);

std::sort(animations_to_apply.begin(), animations_to_apply.end(),
PriorityCompare(elapsed));
// Sort by location in the document. (Should be based on the target rather
// than the timed element, but often enough they will order the same.)
std::sort(
animations_to_apply.begin(), animations_to_apply.end(),
[](const Member<SVGSMILElement>& a, const Member<SVGSMILElement>& b) {
return a->DocumentOrderIndex() < b->DocumentOrderIndex();
});

for (const auto& timed_element : animations_to_apply) {
if (timed_element->isConnected() && timed_element->IsSVGDiscardElement()) {
Expand Down

0 comments on commit ee784aa

Please sign in to comment.