summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 00:37:15 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 00:37:15 +0000
commit553aabb40b432ecdc2c289c935ba77874928dfcc (patch)
tree7ecabde66cc28677bc092a715c2a1228cac80ba5 /app
parent2ca83cd871de1a2c322a48b80d06f4d3c8bb6923 (diff)
downloadchromium_src-553aabb40b432ecdc2c289c935ba77874928dfcc.zip
chromium_src-553aabb40b432ecdc2c289c935ba77874928dfcc.tar.gz
chromium_src-553aabb40b432ecdc2c289c935ba77874928dfcc.tar.bz2
Makes the instant suggested text autocomplete after 1.3 seconds. There
are a number of parts of this patch that need work, but it should be good enough for us to decide if we want to pursue it. BUG=none TEST=none Review URL: http://codereview.chromium.org/4385001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/multi_animation.cc13
-rw-r--r--app/multi_animation.h11
-rw-r--r--app/multi_animation_unittest.cc30
3 files changed, 49 insertions, 5 deletions
diff --git a/app/multi_animation.cc b/app/multi_animation.cc
index 11ca6f8..812a668 100644
--- a/app/multi_animation.cc
+++ b/app/multi_animation.cc
@@ -21,7 +21,8 @@ MultiAnimation::MultiAnimation(const Parts& parts)
parts_(parts),
cycle_time_ms_(TotalTime(parts)),
current_value_(0),
- current_part_index_(0) {
+ current_part_index_(0),
+ continuous_(true) {
DCHECK(!parts_.empty());
}
@@ -31,8 +32,14 @@ void MultiAnimation::Step(base::TimeTicks time_now) {
double last_value = current_value_;
size_t last_index = current_part_index_;
- int delta = static_cast<int>((time_now - start_time()).InMilliseconds() %
- cycle_time_ms_);
+ int delta = static_cast<int>((time_now - start_time()).InMilliseconds());
+ if (delta >= cycle_time_ms_ && !continuous_) {
+ current_part_index_ = parts_.size() - 1;
+ current_value_ = Tween::CalculateValue(parts_[current_part_index_].type, 1);
+ Stop();
+ return;
+ }
+ delta %= cycle_time_ms_;
const Part& part = GetPart(&delta, &current_part_index_);
double percent = static_cast<double>(delta + part.start_time_ms) /
static_cast<double>(part.end_time_ms);
diff --git a/app/multi_animation.h b/app/multi_animation.h
index 5583c3f..2d4ef2c 100644
--- a/app/multi_animation.h
+++ b/app/multi_animation.h
@@ -13,8 +13,8 @@
// MultiAnimation is an animation that consists of a number of sub animations.
// To create a MultiAnimation pass in the parts, invoke Start() and the delegate
-// is notified as the animation progresses. MultiAnimation runs until Stop is
-// invoked.
+// is notified as the animation progresses. By default MultiAnimation runs until
+// Stop is invoked, see |set_continuous()| for details.
class MultiAnimation : public Animation {
public:
// Defines part of the animation. Each part consists of the following:
@@ -47,6 +47,10 @@ class MultiAnimation : public Animation {
explicit MultiAnimation(const Parts& parts);
virtual ~MultiAnimation();
+ // Sets whether the animation continues after it reaches the end. If true, the
+ // animation runs until explicitly stopped. The default is true.
+ void set_continuous(bool continuous) { continuous_ = continuous; }
+
// Returns the current value. The current value for a MultiAnimation is
// determined from the tween type of the current part.
virtual double GetCurrentValue() const { return current_value_; }
@@ -76,6 +80,9 @@ class MultiAnimation : public Animation {
// Index of the current part.
size_t current_part_index_;
+ // See description above setter.
+ bool continuous_;
+
DISALLOW_COPY_AND_ASSIGN(MultiAnimation);
};
diff --git a/app/multi_animation_unittest.cc b/app/multi_animation_unittest.cc
index fbbf1b0..e6e81f1 100644
--- a/app/multi_animation_unittest.cc
+++ b/app/multi_animation_unittest.cc
@@ -56,3 +56,33 @@ TEST_F(MultiAnimationTest, DifferingStartAndEnd) {
as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(100));
EXPECT_EQ(.5, animation.GetCurrentValue());
}
+
+// Makes sure multi-animation stops if cycles is false.
+TEST_F(MultiAnimationTest, DontCycle) {
+ MultiAnimation::Parts parts;
+ parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
+ MultiAnimation animation(parts);
+ AnimationContainer::Element* as_element =
+ static_cast<AnimationContainer::Element*>(&animation);
+ as_element->SetStartTime(base::TimeTicks());
+ animation.set_continuous(false);
+
+ // Step to 300, which is greater than the cycle time.
+ as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
+ EXPECT_EQ(1.0, animation.GetCurrentValue());
+ EXPECT_FALSE(animation.is_animating());
+}
+
+// Makes sure multi-animation cycles correctly.
+TEST_F(MultiAnimationTest, Cycle) {
+ MultiAnimation::Parts parts;
+ parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
+ MultiAnimation animation(parts);
+ AnimationContainer::Element* as_element =
+ static_cast<AnimationContainer::Element*>(&animation);
+ as_element->SetStartTime(base::TimeTicks());
+
+ // Step to 300, which is greater than the cycle time.
+ as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
+ EXPECT_EQ(.5, animation.GetCurrentValue());
+}