Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: ui/gfx/compositor/layer_animation_sequence.cc

Issue 8247009: Explicit animation support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated views desktop demo. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/compositor/layer_animation_sequence.h"
6
7 #include <algorithm>
8 //#include <iterator>
9
10 #include "ui/gfx/compositor/layer_animation_delegate.h"
11 #include "ui/gfx/compositor/layer_animation_element.h"
12
13 namespace ui {
14
15 LayerAnimationSequence::LayerAnimationSequence()
16 : is_cyclic_(false),
17 last_element_(0) {
18 }
19
20 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element)
21 : is_cyclic_(false),
22 last_element_(0) {
23 AddElement(element);
24 }
25
26 LayerAnimationSequence::~LayerAnimationSequence() {
27 }
28
29 void LayerAnimationSequence::Progress(base::TimeDelta elapsed,
30 LayerAnimationDelegate* delegate) {
31 while (last_element_ < elements_.size() &&
32 last_start_ + elements_[last_element_]->Duration() < elapsed) {
33 // let the element we're passing finish.
34 elements_[last_element_]->Progress(1.0, delegate);
35 last_start_ += elements_[last_element_]->Duration();
36 ++last_element_;
37 }
38
39 if (last_element_ < elements_.size()) {
40 // calculate t.
41 double t = 1.0;
42 if (elements_[last_element_]->Duration() > base::TimeDelta()) {
43 t = (elapsed - last_start_).InMillisecondsF() /
44 elements_[last_element_]->Duration().InMillisecondsF();
45 }
46 elements_[last_element_]->Progress(t, delegate);
47 }
48
49 if (elapsed == duration_) {
50 last_element_ = 0;
51 last_start_ = base::TimeDelta::FromMilliseconds(0);
52 }
53 }
54
55 void LayerAnimationSequence::Abort() {
56 while (last_element_ < elements_.size()) {
57 elements_[last_element_]->Abort();
58 ++last_element_;
59 }
60 last_element_ = 0;
61 last_start_ = base::TimeDelta::FromMilliseconds(0);
62 }
63
64 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) {
65 // Update duration and properties.
66 duration_ += element->Duration();
67 LayerAnimationElement::AnimatableProperties::const_iterator iter =
68 element->Properties().begin();
69 while (iter != element->Properties().end()) {
70 properties_.insert(*iter);
71 ++iter;
72 }
73
74 elements_.push_back(make_scoped_refptr(element));
75 }
76
77 bool LayerAnimationSequence::HasCommonProperty(
78 const LayerAnimationSequence& other) const {
79 LayerAnimationElement::AnimatableProperties intersection;
80 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii(
81 intersection, intersection.begin());
82 std::set_intersection(properties_.begin(), properties_.end(),
83 other.properties().begin(), other.properties().end(),
84 ii);
85 return intersection.size() > 0;
86 }
87
88 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698