summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2015-09-01 14:54:26 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-01 21:55:05 +0000
commit71dc72ffa5d0f30b3756217f37d7ec34eb4a81ff (patch)
tree186b59753a8f3fa6f65a65e5e92d076b346ae0e6
parentb8f8f682a82bce992edb35c3030214ede236d3ba (diff)
downloadchromium_src-71dc72ffa5d0f30b3756217f37d7ec34eb4a81ff.zip
chromium_src-71dc72ffa5d0f30b3756217f37d7ec34eb4a81ff.tar.gz
chromium_src-71dc72ffa5d0f30b3756217f37d7ec34eb4a81ff.tar.bz2
Removes animation code from viewmanager
We can add back if it makes sense. BUG=none TEST=none R=ben@chromium.org Review URL: https://codereview.chromium.org/1307943009 Cr-Commit-Position: refs/heads/master@{#346743}
-rw-r--r--components/view_manager/BUILD.gn7
-rw-r--r--components/view_manager/animation_runner.cc157
-rw-r--r--components/view_manager/animation_runner.h114
-rw-r--r--components/view_manager/animation_runner_observer.h23
-rw-r--r--components/view_manager/animation_runner_unittest.cc641
-rw-r--r--components/view_manager/connection_manager.cc155
-rw-r--r--components/view_manager/connection_manager.h17
-rw-r--r--components/view_manager/ids.h5
-rw-r--r--components/view_manager/public/interfaces/BUILD.gn1
-rw-r--r--components/view_manager/public/interfaces/animations.mojom61
-rw-r--r--components/view_manager/scheduled_animation_group.cc352
-rw-r--r--components/view_manager/scheduled_animation_group.h110
-rw-r--r--components/view_manager/scheduled_animation_group_unittest.cc97
-rw-r--r--components/view_manager/server_view.cc4
-rw-r--r--components/view_manager/server_view_delegate.h24
-rw-r--r--components/view_manager/test_server_view_delegate.cc12
-rw-r--r--components/view_manager/test_server_view_delegate.h5
-rw-r--r--components/view_manager/view_tree_apptest.cc7
-rw-r--r--components/view_manager/view_tree_unittest.cc200
-rw-r--r--components/view_manager/window_manager_access_policy.cc7
20 files changed, 3 insertions, 1996 deletions
diff --git a/components/view_manager/BUILD.gn b/components/view_manager/BUILD.gn
index 26c4154..1c8e7ed 100644
--- a/components/view_manager/BUILD.gn
+++ b/components/view_manager/BUILD.gn
@@ -42,9 +42,6 @@ source_set("lib") {
sources = [
"access_policy.h",
"access_policy_delegate.h",
- "animation_runner.cc",
- "animation_runner.h",
- "animation_runner_observer.h",
"client_connection.cc",
"client_connection.h",
"connection_manager.cc",
@@ -64,8 +61,6 @@ source_set("lib") {
"gesture_manager.cc",
"gesture_manager.h",
"gesture_manager_delegate.h",
- "scheduled_animation_group.cc",
- "scheduled_animation_group.h",
"server_view.cc",
"server_view.h",
"server_view_delegate.h",
@@ -154,10 +149,8 @@ group("tests") {
test("view_manager_unittests") {
sources = [
- "animation_runner_unittest.cc",
"focus_controller_unittest.cc",
"gesture_manager_unittest.cc",
- "scheduled_animation_group_unittest.cc",
"server_view_drawn_tracker_unittest.cc",
"test_server_view_delegate.cc",
"test_server_view_delegate.h",
diff --git a/components/view_manager/animation_runner.cc b/components/view_manager/animation_runner.cc
deleted file mode 100644
index 6569ff1..0000000
--- a/components/view_manager/animation_runner.cc
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/view_manager/animation_runner.h"
-
-#include "base/memory/scoped_vector.h"
-#include "components/view_manager/animation_runner_observer.h"
-#include "components/view_manager/scheduled_animation_group.h"
-#include "components/view_manager/server_view.h"
-
-namespace view_manager {
-namespace {
-
-bool ConvertViewAndAnimationPairToScheduledAnimationGroup(
- const std::vector<AnimationRunner::ViewAndAnimationPair>& views,
- AnimationRunner::AnimationId id,
- base::TimeTicks now,
- ScopedVector<ScheduledAnimationGroup>* groups) {
- for (const auto& view_animation_pair : views) {
- DCHECK(view_animation_pair.second);
- scoped_ptr<ScheduledAnimationGroup> group(ScheduledAnimationGroup::Create(
- view_animation_pair.first, now, id, *(view_animation_pair.second)));
- if (!group.get())
- return false;
- groups->push_back(group.release());
- }
- return true;
-}
-
-} // namespace
-
-AnimationRunner::AnimationRunner(base::TimeTicks now)
- : next_id_(1), last_tick_time_(now) {
-}
-
-AnimationRunner::~AnimationRunner() {
-}
-
-void AnimationRunner::AddObserver(AnimationRunnerObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void AnimationRunner::RemoveObserver(AnimationRunnerObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-AnimationRunner::AnimationId AnimationRunner::Schedule(
- const std::vector<ViewAndAnimationPair>& views,
- base::TimeTicks now) {
- DCHECK_GE(now, last_tick_time_);
-
- const AnimationId animation_id = next_id_++;
- ScopedVector<ScheduledAnimationGroup> groups;
- if (!ConvertViewAndAnimationPairToScheduledAnimationGroup(views, animation_id,
- now, &groups)) {
- return 0;
- }
-
- // Cancel any animations for the views.
- for (auto* group : groups) {
- ScheduledAnimationGroup* current_group =
- view_to_animation_map_.get(group->view());
- if (current_group)
- current_group->SetValuesToTargetValuesForPropertiesNotIn(*group);
-
- CancelAnimationForViewImpl(group->view(), CANCEL_SOURCE_SCHEDULE);
- }
-
- for (auto* group : groups) {
- group->ObtainStartValues();
- view_to_animation_map_.set(group->view(), make_scoped_ptr(group));
- DCHECK(!id_to_views_map_[animation_id].count(group->view()));
- id_to_views_map_[animation_id].insert(group->view());
- }
- // |view_to_animation_map_| owns the groups.
- groups.weak_clear();
-
- FOR_EACH_OBSERVER(AnimationRunnerObserver, observers_,
- OnAnimationScheduled(animation_id));
- return animation_id;
-}
-
-void AnimationRunner::CancelAnimation(AnimationId id) {
- if (id_to_views_map_.count(id) == 0)
- return;
-
- std::set<ServerView*> views(id_to_views_map_[id]);
- for (ServerView* view : views)
- CancelAnimationForView(view);
-}
-
-void AnimationRunner::CancelAnimationForView(ServerView* view) {
- CancelAnimationForViewImpl(view, CANCEL_SOURCE_CANCEL);
-}
-
-void AnimationRunner::Tick(base::TimeTicks time) {
- DCHECK(time >= last_tick_time_);
- last_tick_time_ = time;
- if (view_to_animation_map_.empty())
- return;
-
- // The animation ids of any views whose animation completes are added here. We
- // notify after processing all views so that if an observer mutates us in some
- // way we're aren't left in a weird state.
- std::set<AnimationId> animations_completed;
- for (ViewToAnimationMap::iterator i = view_to_animation_map_.begin();
- i != view_to_animation_map_.end();) {
- if (i->second->Tick(time)) {
- const AnimationId animation_id = i->second->id();
- ServerView* view = i->first;
- ++i;
- if (RemoveViewFromMaps(view))
- animations_completed.insert(animation_id);
- } else {
- ++i;
- }
- }
- for (const AnimationId& id : animations_completed) {
- FOR_EACH_OBSERVER(AnimationRunnerObserver, observers_, OnAnimationDone(id));
- }
-}
-
-void AnimationRunner::CancelAnimationForViewImpl(ServerView* view,
- CancelSource source) {
- if (!view_to_animation_map_.contains(view))
- return;
-
- const AnimationId animation_id = view_to_animation_map_.get(view)->id();
- if (RemoveViewFromMaps(view)) {
- // This was the last view in the group.
- if (source == CANCEL_SOURCE_CANCEL) {
- FOR_EACH_OBSERVER(AnimationRunnerObserver, observers_,
- OnAnimationCanceled(animation_id));
- } else {
- FOR_EACH_OBSERVER(AnimationRunnerObserver, observers_,
- OnAnimationInterrupted(animation_id));
- }
- }
-}
-
-bool AnimationRunner::RemoveViewFromMaps(ServerView* view) {
- DCHECK(view_to_animation_map_.contains(view));
-
- const AnimationId animation_id = view_to_animation_map_.get(view)->id();
- view_to_animation_map_.erase(view);
-
- DCHECK(id_to_views_map_.count(animation_id));
- id_to_views_map_[animation_id].erase(view);
- if (!id_to_views_map_[animation_id].empty())
- return false;
-
- id_to_views_map_.erase(animation_id);
- return true;
-}
-
-} // namespace view_manager
diff --git a/components/view_manager/animation_runner.h b/components/view_manager/animation_runner.h
deleted file mode 100644
index 547190e..0000000
--- a/components/view_manager/animation_runner.h
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_VIEW_MANAGER_ANIMATION_RUNNER_H_
-#define COMPONENTS_VIEW_MANAGER_ANIMATION_RUNNER_H_
-
-#include <algorithm>
-#include <map>
-#include <set>
-#include <vector>
-
-#include "base/containers/scoped_ptr_hash_map.h"
-#include "base/observer_list.h"
-#include "base/time/time.h"
-
-namespace mojo {
-class AnimationGroup;
-}
-
-namespace view_manager {
-
-class AnimationRunnerObserver;
-class ScheduledAnimationGroup;
-class ServerView;
-
-// AnimationRunner is responsible for maintaing and running a set of animations.
-// The animations are represented as a set of AnimationGroups. New animations
-// are scheduled by way of Schedule(). A |view| may only have one animation
-// running at a time. Schedule()ing a new animation for a view already animating
-// implicitly cancels the current animation for the view. Animations progress
-// by way of the Tick() function.
-class AnimationRunner {
- public:
- using AnimationId = uint32_t;
- using ViewAndAnimationPair =
- std::pair<ServerView*, const mojo::AnimationGroup*>;
-
- explicit AnimationRunner(base::TimeTicks now);
- ~AnimationRunner();
-
- void AddObserver(AnimationRunnerObserver* observer);
- void RemoveObserver(AnimationRunnerObserver* observer);
-
- // Schedules animations. If any of the groups are not valid no animations are
- // scheuled and 0 is returned. If there is an existing animation in progress
- // for any of the views it is canceled and any properties that were animating
- // but are no longer animating are set to their target value.
- AnimationId Schedule(const std::vector<ViewAndAnimationPair>& views,
- base::TimeTicks now);
-
- // Cancels an animation scheduled by an id that was previously returned from
- // Schedule().
- void CancelAnimation(AnimationId id);
-
- // Cancels the animation scheduled for |view|. Does nothing if there is no
- // animation scheduled for |view|. This does not change |view|. That is, any
- // in progress animations are stopped.
- void CancelAnimationForView(ServerView* view);
-
- // Advance the animations updating values appropriately.
- void Tick(base::TimeTicks time);
-
- // Returns true if there are animations currently scheduled.
- bool HasAnimations() const { return !view_to_animation_map_.empty(); }
-
- // Returns true if the animation identified by |id| is valid and animating.
- bool IsAnimating(AnimationId id) const {
- return id_to_views_map_.count(id) > 0;
- }
-
- // Returns the views that are currently animating for |id|. Returns an empty
- // set if |id| does not identify a valid animation.
- std::set<ServerView*> GetViewsAnimating(AnimationId id) {
- return IsAnimating(id) ? id_to_views_map_.find(id)->second
- : std::set<ServerView*>();
- }
-
- private:
- enum CancelSource {
- // Cancel is the result of scheduling another animation for the view.
- CANCEL_SOURCE_SCHEDULE,
-
- // Cancel originates from an explicit call to cancel.
- CANCEL_SOURCE_CANCEL,
- };
-
- using ViewToAnimationMap =
- base::ScopedPtrHashMap<ServerView*, scoped_ptr<ScheduledAnimationGroup>>;
- using IdToViewsMap = std::map<AnimationId, std::set<ServerView*>>;
-
- void CancelAnimationForViewImpl(ServerView* view, CancelSource source);
-
- // Removes |view| from both |view_to_animation_map_| and |id_to_views_map_|.
- // Returns true if there are no more views animating with the animation id
- // the view is associated with.
- bool RemoveViewFromMaps(ServerView* view);
-
- AnimationId next_id_;
-
- base::TimeTicks last_tick_time_;
-
- base::ObserverList<AnimationRunnerObserver> observers_;
-
- ViewToAnimationMap view_to_animation_map_;
-
- IdToViewsMap id_to_views_map_;
-
- DISALLOW_COPY_AND_ASSIGN(AnimationRunner);
-};
-
-} // namespace view_manager
-
-#endif // COMPONENTS_VIEW_MANAGER_ANIMATION_RUNNER_H_
diff --git a/components/view_manager/animation_runner_observer.h b/components/view_manager/animation_runner_observer.h
deleted file mode 100644
index aa99d4c..0000000
--- a/components/view_manager/animation_runner_observer.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_VIEW_MANAGER_ANIMATION_RUNNER_OBSERVER_H_
-#define COMPONENTS_VIEW_MANAGER_ANIMATION_RUNNER_OBSERVER_H_
-
-namespace view_manager {
-
-class AnimationRunnerObserver {
- public:
- virtual void OnAnimationScheduled(uint32_t id) = 0;
- virtual void OnAnimationDone(uint32_t id) = 0;
- virtual void OnAnimationInterrupted(uint32_t id) = 0;
- virtual void OnAnimationCanceled(uint32_t id) = 0;
-
- protected:
- virtual ~AnimationRunnerObserver() {}
-};
-
-} // namespace view_manager
-
-#endif // COMPONENTS_VIEW_MANAGER_ANIMATION_RUNNER_OBSERVER_H_
diff --git a/components/view_manager/animation_runner_unittest.cc b/components/view_manager/animation_runner_unittest.cc
deleted file mode 100644
index d04ad6b..0000000
--- a/components/view_manager/animation_runner_unittest.cc
+++ /dev/null
@@ -1,641 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/view_manager/animation_runner.h"
-
-#include "base/strings/stringprintf.h"
-#include "components/view_manager/animation_runner_observer.h"
-#include "components/view_manager/public/interfaces/view_manager_constants.mojom.h"
-#include "components/view_manager/scheduled_animation_group.h"
-#include "components/view_manager/server_view.h"
-#include "components/view_manager/test_server_view_delegate.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/transform/transform_type_converters.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using base::TimeDelta;
-using mojo::ANIMATION_PROPERTY_NONE;
-using mojo::ANIMATION_PROPERTY_OPACITY;
-using mojo::ANIMATION_PROPERTY_TRANSFORM;
-using mojo::ANIMATION_TWEEN_TYPE_LINEAR;
-using mojo::AnimationElement;
-using mojo::AnimationGroup;
-using mojo::AnimationProperty;
-using mojo::AnimationSequence;
-using mojo::AnimationTweenType;
-using mojo::AnimationValue;
-using mojo::AnimationValuePtr;
-using mojo::Transform;
-
-namespace view_manager {
-namespace {
-
-class TestAnimationRunnerObserver : public AnimationRunnerObserver {
- public:
- TestAnimationRunnerObserver() {}
- ~TestAnimationRunnerObserver() override {}
-
- std::vector<std::string>* changes() { return &changes_; }
- std::vector<uint32_t>* change_ids() { return &change_ids_; }
-
- void clear_changes() {
- changes_.clear();
- change_ids_.clear();
- }
-
- // AnimationRunnerDelgate:
- void OnAnimationScheduled(uint32_t id) override {
- change_ids_.push_back(id);
- changes_.push_back("scheduled");
- }
- void OnAnimationDone(uint32_t id) override {
- change_ids_.push_back(id);
- changes_.push_back("done");
- }
- void OnAnimationInterrupted(uint32_t id) override {
- change_ids_.push_back(id);
- changes_.push_back("interrupted");
- }
- void OnAnimationCanceled(uint32_t id) override {
- change_ids_.push_back(id);
- changes_.push_back("canceled");
- }
-
- private:
- std::vector<uint32_t> change_ids_;
- std::vector<std::string> changes_;
-
- DISALLOW_COPY_AND_ASSIGN(TestAnimationRunnerObserver);
-};
-
-// Creates an AnimationValuePtr from the specified float value.
-AnimationValuePtr FloatAnimationValue(float float_value) {
- AnimationValuePtr value(AnimationValue::New());
- value->float_value = float_value;
- return value.Pass();
-}
-
-// Creates an AnimationValuePtr from the specified transform.
-AnimationValuePtr TransformAnimationValue(const gfx::Transform& transform) {
- AnimationValuePtr value(AnimationValue::New());
- value->transform = Transform::From(transform);
- return value.Pass();
-}
-
-// Adds an AnimationElement to |group|s last sequence with the specified value.
-void AddElement(AnimationGroup* group,
- TimeDelta time,
- AnimationValuePtr start_value,
- AnimationValuePtr target_value,
- AnimationProperty property,
- AnimationTweenType tween_type) {
- AnimationSequence& sequence =
- *(group->sequences[group->sequences.size() - 1]);
- sequence.elements.push_back(AnimationElement::New());
- AnimationElement& element =
- *(sequence.elements[sequence.elements.size() - 1]);
- element.property = property;
- element.duration = time.InMicroseconds();
- element.tween_type = tween_type;
- element.start_value = start_value.Pass();
- element.target_value = target_value.Pass();
-}
-
-void AddOpacityElement(AnimationGroup* group,
- TimeDelta time,
- AnimationValuePtr start_value,
- AnimationValuePtr target_value) {
- AddElement(group, time, start_value.Pass(), target_value.Pass(),
- ANIMATION_PROPERTY_OPACITY, ANIMATION_TWEEN_TYPE_LINEAR);
-}
-
-void AddTransformElement(AnimationGroup* group,
- TimeDelta time,
- AnimationValuePtr start_value,
- AnimationValuePtr target_value) {
- AddElement(group, time, start_value.Pass(), target_value.Pass(),
- ANIMATION_PROPERTY_TRANSFORM, ANIMATION_TWEEN_TYPE_LINEAR);
-}
-
-void AddPauseElement(AnimationGroup* group, TimeDelta time) {
- AddElement(group, time, AnimationValuePtr(), AnimationValuePtr(),
- ANIMATION_PROPERTY_NONE, ANIMATION_TWEEN_TYPE_LINEAR);
-}
-
-void InitGroupForView(AnimationGroup* group,
- const ViewId& id,
- int cycle_count) {
- group->view_id = ViewIdToTransportId(id);
- group->sequences.push_back(AnimationSequence::New());
- group->sequences[group->sequences.size() - 1]->cycle_count = cycle_count;
-}
-
-} // namespace
-
-class AnimationRunnerTest : public testing::Test {
- public:
- AnimationRunnerTest()
- : initial_time_(base::TimeTicks::Now()), runner_(initial_time_) {
- runner_.AddObserver(&runner_observer_);
- }
- ~AnimationRunnerTest() override { runner_.RemoveObserver(&runner_observer_); }
-
- protected:
- // Convenience to schedule an animation for a single view/group pair.
- AnimationRunner::AnimationId ScheduleForSingleView(
- ServerView* view,
- const AnimationGroup* group,
- base::TimeTicks now) {
- std::vector<AnimationRunner::ViewAndAnimationPair> pairs;
- pairs.push_back(std::make_pair(view, group));
- return runner_.Schedule(pairs, now);
- }
-
- // If |id| is valid and there is only one view schedule against the animation
- // it is returned; otherwise returns null.
- ServerView* GetSingleViewAnimating(AnimationRunner::AnimationId id) {
- std::set<ServerView*> views(runner_.GetViewsAnimating(id));
- return views.size() == 1 ? *views.begin() : nullptr;
- }
-
- const base::TimeTicks initial_time_;
- TestAnimationRunnerObserver runner_observer_;
- AnimationRunner runner_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(AnimationRunnerTest);
-};
-
-// Opacity from 1 to .5 over 1000.
-TEST_F(AnimationRunnerTest, SingleProperty) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId());
-
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 1);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(.5));
-
- const uint32_t animation_id =
- ScheduleForSingleView(&view, &group, initial_time_);
-
- ASSERT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("scheduled", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id, runner_observer_.change_ids()->at(0));
- runner_observer_.clear_changes();
-
- EXPECT_TRUE(runner_.HasAnimations());
-
- // Opacity should still be 1 (the initial value).
- EXPECT_EQ(1.f, view.opacity());
-
- // Animate half way.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(500));
-
- EXPECT_EQ(.75f, view.opacity());
- EXPECT_TRUE(runner_observer_.changes()->empty());
-
- // Run well past the end. Value should progress to end and delegate should
- // be notified.
- runner_.Tick(initial_time_ + TimeDelta::FromSeconds(10));
- EXPECT_EQ(.5f, view.opacity());
-
- ASSERT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("done", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id, runner_observer_.change_ids()->at(0));
-
- EXPECT_FALSE(runner_.HasAnimations());
-}
-
-// Opacity from 1 to .5, followed by transform from identity to 2x,3x.
-TEST_F(AnimationRunnerTest, TwoPropertiesInSequence) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId());
-
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 1);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(.5f));
-
- gfx::Transform done_transform;
- done_transform.Scale(2, 4);
- AddTransformElement(&group, TimeDelta::FromMicroseconds(2000),
- AnimationValuePtr(),
- TransformAnimationValue(done_transform));
-
- const uint32_t animation_id =
- ScheduleForSingleView(&view, &group, initial_time_);
- runner_observer_.clear_changes();
-
- // Nothing in the view should have changed yet.
- EXPECT_EQ(1.f, view.opacity());
- EXPECT_TRUE(view.transform().IsIdentity());
-
- // Animate half way from through opacity animation.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(500));
-
- EXPECT_EQ(.75f, view.opacity());
- EXPECT_TRUE(view.transform().IsIdentity());
-
- // Finish first element (opacity).
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(1000));
- EXPECT_EQ(.5f, view.opacity());
- EXPECT_TRUE(view.transform().IsIdentity());
-
- // Half way through second (transform).
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(2000));
- EXPECT_EQ(.5f, view.opacity());
- gfx::Transform half_way_transform;
- half_way_transform.Scale(1.5, 2.5);
- EXPECT_EQ(half_way_transform, view.transform());
-
- EXPECT_TRUE(runner_observer_.changes()->empty());
-
- // To end.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(3500));
- EXPECT_EQ(.5f, view.opacity());
- EXPECT_EQ(done_transform, view.transform());
-
- ASSERT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("done", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id, runner_observer_.change_ids()->at(0));
-}
-
-// Opacity from .5 to 1 over 1000, transform to 2x,4x over 500.
-TEST_F(AnimationRunnerTest, TwoPropertiesInParallel) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId(1, 1));
-
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 1);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- FloatAnimationValue(.5f), FloatAnimationValue(1));
-
- group.sequences.push_back(AnimationSequence::New());
- group.sequences[1]->cycle_count = 1;
- gfx::Transform done_transform;
- done_transform.Scale(2, 4);
- AddTransformElement(&group, TimeDelta::FromMicroseconds(500),
- AnimationValuePtr(),
- TransformAnimationValue(done_transform));
-
- const uint32_t animation_id =
- ScheduleForSingleView(&view, &group, initial_time_);
-
- runner_observer_.clear_changes();
-
- // Nothing in the view should have changed yet.
- EXPECT_EQ(1.f, view.opacity());
- EXPECT_TRUE(view.transform().IsIdentity());
-
- // Animate to 250, which is 1/4 way through opacity and half way through
- // transform.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(250));
-
- EXPECT_EQ(.625f, view.opacity());
- gfx::Transform half_way_transform;
- half_way_transform.Scale(1.5, 2.5);
- EXPECT_EQ(half_way_transform, view.transform());
-
- // Animate to 500, which is 1/2 way through opacity and transform done.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(500));
- EXPECT_EQ(.75f, view.opacity());
- EXPECT_EQ(done_transform, view.transform());
-
- // Animate to 750, which is 3/4 way through opacity and transform done.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(750));
- EXPECT_EQ(.875f, view.opacity());
- EXPECT_EQ(done_transform, view.transform());
-
- EXPECT_TRUE(runner_observer_.changes()->empty());
-
- // To end.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(3500));
- EXPECT_EQ(1.f, view.opacity());
- EXPECT_EQ(done_transform, view.transform());
-
- ASSERT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("done", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id, runner_observer_.change_ids()->at(0));
-}
-
-// Opacity from .5 to 1 over 1000, pause for 500, 1 to .5 over 500, with a cycle
-// count of 3.
-TEST_F(AnimationRunnerTest, Cycles) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId(1, 2));
-
- view.SetOpacity(.5f);
-
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 3);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(1));
- AddPauseElement(&group, TimeDelta::FromMicroseconds(500));
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(500),
- AnimationValuePtr(), FloatAnimationValue(.5));
-
- ScheduleForSingleView(&view, &group, initial_time_);
- runner_observer_.clear_changes();
-
- // Nothing in the view should have changed yet.
- EXPECT_EQ(.5f, view.opacity());
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(500));
- EXPECT_EQ(.75f, view.opacity());
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(1250));
- EXPECT_EQ(1.f, view.opacity());
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(1750));
- EXPECT_EQ(.75f, view.opacity());
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(2500));
- EXPECT_EQ(.75f, view.opacity());
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(3250));
- EXPECT_EQ(1.f, view.opacity());
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(3750));
- EXPECT_EQ(.75f, view.opacity());
-
- // Animate to the end.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(6500));
- EXPECT_EQ(.5f, view.opacity());
-
- ASSERT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("done", runner_observer_.changes()->at(0));
-}
-
-// Verifies scheduling the same view twice sends an interrupt.
-TEST_F(AnimationRunnerTest, ScheduleTwice) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId(1, 2));
-
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 1);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(.5));
-
- const uint32_t animation_id =
- ScheduleForSingleView(&view, &group, initial_time_);
- runner_observer_.clear_changes();
-
- // Animate half way.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(500));
-
- EXPECT_EQ(.75f, view.opacity());
- EXPECT_TRUE(runner_observer_.changes()->empty());
-
- // Schedule again. We should get an interrupt, but opacity shouldn't change.
- const uint32_t animation2_id = ScheduleForSingleView(
- &view, &group, initial_time_ + TimeDelta::FromMicroseconds(500));
-
- // Id should have changed.
- EXPECT_NE(animation_id, animation2_id);
-
- EXPECT_FALSE(runner_.IsAnimating(animation_id));
- EXPECT_EQ(&view, GetSingleViewAnimating(animation2_id));
-
- EXPECT_EQ(.75f, view.opacity());
- EXPECT_EQ(2u, runner_observer_.changes()->size());
- EXPECT_EQ("interrupted", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id, runner_observer_.change_ids()->at(0));
- EXPECT_EQ("scheduled", runner_observer_.changes()->at(1));
- EXPECT_EQ(animation2_id, runner_observer_.change_ids()->at(1));
- runner_observer_.clear_changes();
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(1000));
- EXPECT_EQ(.625f, view.opacity());
- EXPECT_TRUE(runner_observer_.changes()->empty());
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(2000));
- EXPECT_EQ(.5f, view.opacity());
- EXPECT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("done", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation2_id, runner_observer_.change_ids()->at(0));
-}
-
-// Verifies Remove() works.
-TEST_F(AnimationRunnerTest, CancelAnimationForView) {
- // Create an animation and advance it part way.
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId());
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 1);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(.5));
-
- const uint32_t animation_id =
- ScheduleForSingleView(&view, &group, initial_time_);
- runner_observer_.clear_changes();
- EXPECT_EQ(&view, GetSingleViewAnimating(animation_id));
-
- EXPECT_TRUE(runner_.HasAnimations());
-
- // Animate half way.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(500));
- EXPECT_EQ(.75f, view.opacity());
- EXPECT_TRUE(runner_observer_.changes()->empty());
-
- // Cancel the animation.
- runner_.CancelAnimationForView(&view);
-
- EXPECT_FALSE(runner_.HasAnimations());
- EXPECT_EQ(nullptr, GetSingleViewAnimating(animation_id));
-
- EXPECT_EQ(.75f, view.opacity());
-
- EXPECT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("canceled", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id, runner_observer_.change_ids()->at(0));
-}
-
-// Verifies a tick with a very large delta and a sequence that repeats forever
-// doesn't take a long time.
-TEST_F(AnimationRunnerTest, InfiniteRepeatWithHugeGap) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId(1, 2));
-
- view.SetOpacity(.5f);
-
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 0);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(500),
- AnimationValuePtr(), FloatAnimationValue(1));
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(500),
- AnimationValuePtr(), FloatAnimationValue(.5));
-
- ScheduleForSingleView(&view, &group, initial_time_);
- runner_observer_.clear_changes();
-
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(1000000000750));
-
- EXPECT_EQ(.75f, view.opacity());
-
- ASSERT_EQ(0u, runner_observer_.changes()->size());
-}
-
-// Verifies a second schedule sets any properties that are no longer animating
-// to their final value.
-TEST_F(AnimationRunnerTest, RescheduleSetsPropertiesToFinalValue) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId());
-
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 1);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(.5));
-
- gfx::Transform done_transform;
- done_transform.Scale(2, 4);
- AddTransformElement(&group, TimeDelta::FromMicroseconds(500),
- AnimationValuePtr(),
- TransformAnimationValue(done_transform));
-
- ScheduleForSingleView(&view, &group, initial_time_);
-
- // Schedule() again, this time without animating opacity.
- group.sequences[0]->elements[0]->property = ANIMATION_PROPERTY_NONE;
- ScheduleForSingleView(&view, &group, initial_time_);
-
- // Opacity should go to final value.
- EXPECT_EQ(.5f, view.opacity());
- // Transform shouldn't have changed since newly scheduled animation also has
- // transform in it.
- EXPECT_TRUE(view.transform().IsIdentity());
-}
-
-// Opacity from 1 to .5 over 1000 of v1 and v2 transform to 2x,4x over 500.
-TEST_F(AnimationRunnerTest, TwoViews) {
- TestServerViewDelegate view_delegate;
- ServerView view1(&view_delegate, ViewId());
- ServerView view2(&view_delegate, ViewId(1, 2));
-
- AnimationGroup group1;
- InitGroupForView(&group1, view1.id(), 1);
- AddOpacityElement(&group1, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(.5));
-
- AnimationGroup group2;
- InitGroupForView(&group2, view2.id(), 1);
- gfx::Transform done_transform;
- done_transform.Scale(2, 4);
- AddTransformElement(&group2, TimeDelta::FromMicroseconds(500),
- AnimationValuePtr(),
- TransformAnimationValue(done_transform));
-
- std::vector<AnimationRunner::ViewAndAnimationPair> pairs;
- pairs.push_back(std::make_pair(&view1, &group1));
- pairs.push_back(std::make_pair(&view2, &group2));
-
- const uint32_t animation_id = runner_.Schedule(pairs, initial_time_);
-
- ASSERT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("scheduled", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id, runner_observer_.change_ids()->at(0));
- runner_observer_.clear_changes();
-
- EXPECT_TRUE(runner_.HasAnimations());
- EXPECT_TRUE(runner_.IsAnimating(animation_id));
-
- // Properties should be at the initial value.
- EXPECT_EQ(1.f, view1.opacity());
- EXPECT_TRUE(view2.transform().IsIdentity());
-
- // Animate 250ms in, which is quarter way for opacity and half way for
- // transform.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(250));
- EXPECT_EQ(.875f, view1.opacity());
- gfx::Transform half_way_transform;
- half_way_transform.Scale(1.5, 2.5);
- EXPECT_EQ(half_way_transform, view2.transform());
- std::set<ServerView*> views_animating(
- runner_.GetViewsAnimating(animation_id));
- EXPECT_EQ(2u, views_animating.size());
- EXPECT_EQ(1u, views_animating.count(&view1));
- EXPECT_EQ(1u, views_animating.count(&view2));
-
- // Animate 750ms in, view1 should be done 3/4 done, and view2 done.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(750));
- EXPECT_EQ(.625, view1.opacity());
- EXPECT_EQ(done_transform, view2.transform());
- views_animating = runner_.GetViewsAnimating(animation_id);
- EXPECT_EQ(1u, views_animating.size());
- EXPECT_EQ(1u, views_animating.count(&view1));
- EXPECT_TRUE(runner_.HasAnimations());
- EXPECT_TRUE(runner_.IsAnimating(animation_id));
-
- // Animate to end.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(1750));
- EXPECT_EQ(.5, view1.opacity());
- EXPECT_EQ(done_transform, view2.transform());
- views_animating = runner_.GetViewsAnimating(animation_id);
- EXPECT_TRUE(views_animating.empty());
- EXPECT_FALSE(runner_.HasAnimations());
- EXPECT_FALSE(runner_.IsAnimating(animation_id));
-}
-
-TEST_F(AnimationRunnerTest, Reschedule) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId());
-
- // Animation from 1-0 over 1ms and in parallel transform to 2x,4x over 1ms.
- AnimationGroup group;
- InitGroupForView(&group, view.id(), 1);
- AddOpacityElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(0));
- group.sequences.push_back(AnimationSequence::New());
- group.sequences[1]->cycle_count = 1;
- gfx::Transform done_transform;
- done_transform.Scale(2, 4);
- AddTransformElement(&group, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(),
- TransformAnimationValue(done_transform));
- const uint32_t animation_id1 =
- ScheduleForSingleView(&view, &group, initial_time_);
-
- // Animate half way in.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(500));
- EXPECT_EQ(.5f, view.opacity());
- gfx::Transform half_way_transform;
- half_way_transform.Scale(1.5, 2.5);
- EXPECT_EQ(half_way_transform, view.transform());
-
- runner_observer_.clear_changes();
-
- // Schedule the same view animating opacity to 1.
- AnimationGroup group2;
- InitGroupForView(&group2, view.id(), 1);
- AddOpacityElement(&group2, TimeDelta::FromMicroseconds(1000),
- AnimationValuePtr(), FloatAnimationValue(1));
- const uint32_t animation_id2 = ScheduleForSingleView(
- &view, &group2, initial_time_ + TimeDelta::FromMicroseconds(500));
-
- // Opacity should remain at .5, but transform should go to end state.
- EXPECT_EQ(.5f, view.opacity());
- EXPECT_EQ(done_transform, view.transform());
-
- ASSERT_EQ(2u, runner_observer_.changes()->size());
- EXPECT_EQ("interrupted", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id1, runner_observer_.change_ids()->at(0));
- EXPECT_EQ("scheduled", runner_observer_.changes()->at(1));
- EXPECT_EQ(animation_id2, runner_observer_.change_ids()->at(1));
- runner_observer_.clear_changes();
-
- // Animate half way through new sequence. Opacity should be the only thing
- // changing.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(1000));
- EXPECT_EQ(.75f, view.opacity());
- EXPECT_EQ(done_transform, view.transform());
- ASSERT_EQ(0u, runner_observer_.changes()->size());
-
- // Animate to end.
- runner_.Tick(initial_time_ + TimeDelta::FromMicroseconds(2000));
- ASSERT_EQ(1u, runner_observer_.changes()->size());
- EXPECT_EQ("done", runner_observer_.changes()->at(0));
- EXPECT_EQ(animation_id2, runner_observer_.change_ids()->at(0));
-}
-
-} // namespace view_manager
diff --git a/components/view_manager/connection_manager.cc b/components/view_manager/connection_manager.cc
index 5076c93ff..ae5ddfe 100644
--- a/components/view_manager/connection_manager.cc
+++ b/components/view_manager/connection_manager.cc
@@ -24,81 +24,6 @@
using mojo::ConnectionSpecificId;
namespace view_manager {
-namespace {
-
-// Creates a copy of |view|. The copied view has |delegate| as its delegate.
-// This does not recurse.
-ServerView* CloneView(const ServerView* view, ServerViewDelegate* delegate) {
- ServerView* clone = new ServerView(delegate, ClonedViewId());
- clone->SetBounds(view->bounds());
- clone->SetSurfaceId(view->surface_id());
- clone->SetOpacity(view->opacity());
- return clone;
-}
-
-// Creates copies of all the visible children of |parent|. Newly cloned views
-// are added to |cloned_parent| and have |delegate| as their delegate. The
-// stacking order of the cloned views is preseved.
-void CloneViewTree(const ServerView* parent,
- ServerView* cloned_parent,
- ServerViewDelegate* delegate) {
- DCHECK(parent->visible());
- for (const ServerView* to_clone : parent->GetChildren()) {
- if (to_clone->visible()) {
- ServerView* cloned = CloneView(to_clone, delegate);
- cloned_parent->Add(cloned);
- CloneViewTree(to_clone, cloned, delegate);
- }
- }
-}
-
-// Recurses through all the children of |view| moving any cloned views to
-// |new_parent| stacked above |stack_above|. |stack_above| is updated as views
-// are moved.
-void ReparentClonedViews(ServerView* new_parent,
- ServerView** stack_above,
- ServerView* view) {
- if (view->id() == ClonedViewId()) {
- const gfx::Rect new_bounds(ConvertRectBetweenViews(
- view, new_parent, gfx::Rect(view->bounds().size())));
- new_parent->Add(view);
- new_parent->Reorder(view, *stack_above, mojo::ORDER_DIRECTION_ABOVE);
- view->SetBounds(new_bounds);
- *stack_above = view;
- return;
- }
-
- for (ServerView* child : view->GetChildren())
- ReparentClonedViews(new_parent, stack_above, child);
-}
-
-// Deletes |view| and all its descendants.
-void DeleteViewTree(ServerView* view) {
- for (ServerView* child : view->GetChildren())
- DeleteViewTree(child);
-
- delete view;
-}
-
-// TODO(sky): nuke, proof of concept.
-bool DecrementAnimatingViewsOpacity(ServerView* view) {
- if (view->id() == ClonedViewId()) {
- const float new_opacity = view->opacity() - .05f;
- if (new_opacity <= 0)
- DeleteViewTree(view);
- else
- view->SetOpacity(new_opacity);
- return true;
- }
- bool ret_value = false;
- for (ServerView* child : view->GetChildren()) {
- if (DecrementAnimatingViewsOpacity(child))
- ret_value = true;
- }
- return ret_value;
-}
-
-} // namespace
ConnectionManager::ScopedChange::ScopedChange(
ViewTreeImpl* connection,
@@ -124,7 +49,6 @@ ConnectionManager::ConnectionManager(
event_dispatcher_(this),
current_change_(nullptr),
in_destructor_(false),
- animation_runner_(base::TimeTicks::Now()),
focus_controller_(new FocusController(this)) {
}
@@ -357,21 +281,6 @@ ViewTreeImpl* ConnectionManager::GetEmbedRoot(ViewTreeImpl* service) {
return nullptr;
}
-bool ConnectionManager::CloneAndAnimate(const ViewId& view_id) {
- ServerView* view = GetView(view_id);
- if (!view || !view->IsDrawn() || (view->GetRoot() == view))
- return false;
- if (!animation_timer_.IsRunning()) {
- animation_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(100),
- this, &ConnectionManager::DoAnimation);
- }
- ServerView* clone = CloneView(view, this);
- CloneViewTree(view, clone, this);
- view->parent()->Add(clone);
- view->parent()->Reorder(clone, view, mojo::ORDER_DIRECTION_ABOVE);
- return true;
-}
-
void ConnectionManager::DispatchInputEventToView(const ServerView* view,
mojo::EventPtr event) {
// If the view is an embed root, forward to the embedded view, not the owner.
@@ -476,16 +385,6 @@ void ConnectionManager::FinishChange() {
current_change_ = NULL;
}
-void ConnectionManager::DoAnimation() {
- // TODO(fsamuel): This is probably not right. We probably want a per-root
- // animation.
- bool animating = false;
- for (auto& pair : host_connection_map_)
- animating |= DecrementAnimatingViewsOpacity(pair.first->root_view());
- if (!animating)
- animation_timer_.Stop();
-}
-
void ConnectionManager::AddConnection(ClientConnection* connection) {
DCHECK_EQ(0u, connection_map_.count(connection->service()->id()));
connection_map_[connection->service()->id()] = connection;
@@ -512,54 +411,6 @@ surfaces::SurfacesState* ConnectionManager::GetSurfacesState() {
return surfaces_state_.get();
}
-void ConnectionManager::PrepareToDestroyView(ServerView* view) {
- if (!in_destructor_ && IsViewAttachedToRoot(view) &&
- view->id() != ClonedViewId()) {
- // We're about to destroy a view. Any cloned views need to be reparented
- // else the animation would no longer be visible. By moving to a visible
- // view, view->parent(), we ensure the animation is still visible.
- ServerView* parent_above = view;
- ReparentClonedViews(view->parent(), &parent_above, view);
- }
-
- animation_runner_.CancelAnimationForView(view);
-}
-
-void ConnectionManager::PrepareToChangeViewHierarchy(ServerView* view,
- ServerView* new_parent,
- ServerView* old_parent) {
- if (view->id() == ClonedViewId() || in_destructor_)
- return;
-
- if (IsViewAttachedToRoot(view)) {
- // We're about to reparent a view. Any cloned views need to be reparented
- // else the animation may be effected in unusual ways. For example, the view
- // could move to a new location such that the animation is entirely clipped.
- // By moving to view->parent() we ensure the animation is still visible.
- ServerView* parent_above = view;
- ReparentClonedViews(view->parent(), &parent_above, view);
- }
-
- animation_runner_.CancelAnimationForView(view);
-}
-
-void ConnectionManager::PrepareToChangeViewVisibility(ServerView* view) {
- if (in_destructor_)
- return;
-
- if (IsViewAttachedToRoot(view) && view->id() != ClonedViewId() &&
- view->IsDrawn()) {
- // We're about to hide |view|, this would implicitly make any cloned views
- // hide too. Reparent so that animations are still visible.
- ServerView* parent_above = view;
- ReparentClonedViews(view->parent(), &parent_above, view);
- }
-
- const bool is_parent_drawn = view->parent() && view->parent()->IsDrawn();
- if (!is_parent_drawn || !view->visible())
- animation_runner_.CancelAnimationForView(view);
-}
-
void ConnectionManager::OnScheduleViewPaint(const ServerView* view) {
if (!in_destructor_)
SchedulePaint(view, gfx::Rect(view->bounds().size()));
@@ -578,7 +429,7 @@ void ConnectionManager::OnViewDestroyed(ServerView* view) {
void ConnectionManager::OnWillChangeViewHierarchy(ServerView* view,
ServerView* new_parent,
ServerView* old_parent) {
- if (view->id() == ClonedViewId() || in_destructor_)
+ if (in_destructor_)
return;
ProcessWillChangeViewHierarchy(view, new_parent, old_parent);
@@ -659,10 +510,6 @@ void ConnectionManager::OnViewTextInputStateChanged(
host->UpdateTextInputState(state);
}
-void ConnectionManager::CloneAndAnimate(mojo::Id transport_view_id) {
- CloneAndAnimate(ViewIdFromTransportId(transport_view_id));
-}
-
void ConnectionManager::OnFocusChanged(ServerView* old_focused_view,
ServerView* new_focused_view) {
// There are up to four connections that need to be notified:
diff --git a/components/view_manager/connection_manager.h b/components/view_manager/connection_manager.h
index eb28113..49cf0fd 100644
--- a/components/view_manager/connection_manager.h
+++ b/components/view_manager/connection_manager.h
@@ -11,7 +11,6 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h"
-#include "components/view_manager/animation_runner.h"
#include "components/view_manager/event_dispatcher.h"
#include "components/view_manager/focus_controller_delegate.h"
#include "components/view_manager/ids.h"
@@ -216,10 +215,6 @@ class ConnectionManager : public ServerViewDelegate,
return current_change_ && current_change_->connection_id() == connection_id;
}
- // Callback from animation timer.
- // TODO(sky): make this real (move to a different class).
- void DoAnimation();
-
// Adds |connection| to internal maps.
void AddConnection(ClientConnection* connection);
@@ -229,11 +224,6 @@ class ConnectionManager : public ServerViewDelegate,
scoped_ptr<cc::CompositorFrame> UpdateViewTreeFromCompositorFrame(
const mojo::CompositorFramePtr& input) override;
surfaces::SurfacesState* GetSurfacesState() override;
- void PrepareToDestroyView(ServerView* view) override;
- void PrepareToChangeViewHierarchy(ServerView* view,
- ServerView* new_parent,
- ServerView* old_parent) override;
- void PrepareToChangeViewVisibility(ServerView* view) override;
void OnScheduleViewPaint(const ServerView* view) override;
const ServerView* GetRootView(const ServerView* view) const override;
@@ -259,8 +249,6 @@ class ConnectionManager : public ServerViewDelegate,
void OnViewTextInputStateChanged(ServerView* view,
const ui::TextInputState& state) override;
- void CloneAndAnimate(mojo::Id transport_view_id);
-
// FocusControllerDelegate:
void OnFocusChanged(ServerView* old_focused_view,
ServerView* new_focused_view) override;
@@ -296,11 +284,6 @@ class ConnectionManager : public ServerViewDelegate,
bool in_destructor_;
- // TODO(sky): nuke! Just a proof of concept until get real animation api.
- base::RepeatingTimer<ConnectionManager> animation_timer_;
-
- AnimationRunner animation_runner_;
-
scoped_ptr<FocusController> focus_controller_;
DISALLOW_COPY_AND_ASSIGN(ConnectionManager);
diff --git a/components/view_manager/ids.h b/components/view_manager/ids.h
index 862a805..54fda01 100644
--- a/components/view_manager/ids.h
+++ b/components/view_manager/ids.h
@@ -48,11 +48,6 @@ inline ViewId InvalidViewId() {
return ViewId(kInvalidConnectionId, 0);
}
-// All cloned views use this id.
-inline ViewId ClonedViewId() {
- return ViewId(kInvalidConnectionId, 1);
-}
-
// Returns a root view id with a given index offset.
inline ViewId RootViewId(uint16_t index) {
return ViewId(kInvalidConnectionId, 2 + index);
diff --git a/components/view_manager/public/interfaces/BUILD.gn b/components/view_manager/public/interfaces/BUILD.gn
index a16d173..2ac5fb3 100644
--- a/components/view_manager/public/interfaces/BUILD.gn
+++ b/components/view_manager/public/interfaces/BUILD.gn
@@ -6,7 +6,6 @@ import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
- "animations.mojom",
"command_buffer.mojom",
"compositor_frame.mojom",
"gpu.mojom",
diff --git a/components/view_manager/public/interfaces/animations.mojom b/components/view_manager/public/interfaces/animations.mojom
deleted file mode 100644
index 6a4e559..0000000
--- a/components/view_manager/public/interfaces/animations.mojom
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module mojo;
-
-import "ui/mojo/geometry/geometry.mojom";
-
-enum AnimationTweenType {
- LINEAR,
- EASE_IN,
- EASE_OUT,
- EASE_IN_OUT,
-};
-
-enum AnimationProperty {
- // Used for pausing.
- NONE,
- OPACITY,
- TRANSFORM,
-};
-
-struct AnimationValue {
- float float_value;
- Transform transform;
-};
-
-// Identifies how a particular property should be animated between a start and
-// target value.
-struct AnimationElement {
- AnimationProperty property;
-
- // Duration is in microseconds.
- int64 duration;
-
- AnimationTweenType tween_type;
-
- // If not specified the start value is taken from either the current value
- // (for the first element) or the target_value of the previous element.
- AnimationValue? start_value;
-
- // target_value may be null when property is NONE.
- AnimationValue? target_value;
-};
-
-// An AnimationSequence consists of a number of AnimationElements to animate.
-// Each element is animated serially.
-struct AnimationSequence {
- // Number of times to run the sequence. Value of 0 means run until
- // explicitly stopped.
- uint32 cycle_count;
-
- array<AnimationElement> elements;
-};
-
-// AnimationGroup identifies a view and a set of AnimationSequences to apply
-// to the view. Each sequence is run in parallel.
-struct AnimationGroup {
- uint32 view_id;
- array<AnimationSequence> sequences;
-};
diff --git a/components/view_manager/scheduled_animation_group.cc b/components/view_manager/scheduled_animation_group.cc
deleted file mode 100644
index 210fa8e..0000000
--- a/components/view_manager/scheduled_animation_group.cc
+++ /dev/null
@@ -1,352 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/view_manager/scheduled_animation_group.h"
-
-#include <set>
-
-#include "components/view_manager/server_view.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/transform/transform_type_converters.h"
-
-using mojo::ANIMATION_PROPERTY_NONE;
-using mojo::ANIMATION_PROPERTY_OPACITY;
-using mojo::ANIMATION_PROPERTY_TRANSFORM;
-using mojo::AnimationProperty;
-
-namespace view_manager {
-namespace {
-
-using Sequences = std::vector<ScheduledAnimationSequence>;
-
-// Gets the value of |property| from |view| into |value|.
-void GetValueFromView(const ServerView* view,
- AnimationProperty property,
- ScheduledAnimationValue* value) {
- switch (property) {
- case ANIMATION_PROPERTY_NONE:
- NOTREACHED();
- break;
- case ANIMATION_PROPERTY_OPACITY:
- value->float_value = view->opacity();
- break;
- case ANIMATION_PROPERTY_TRANSFORM:
- value->transform = view->transform();
- break;
- }
-}
-
-// Sets the value of |property| from |value| into |view|.
-void SetViewPropertyFromValue(ServerView* view,
- AnimationProperty property,
- const ScheduledAnimationValue& value) {
- switch (property) {
- case ANIMATION_PROPERTY_NONE:
- break;
- case ANIMATION_PROPERTY_OPACITY:
- view->SetOpacity(value.float_value);
- break;
- case ANIMATION_PROPERTY_TRANSFORM:
- view->SetTransform(value.transform);
- break;
- }
-}
-
-// Sets the value of |property| into |view| between two points.
-void SetViewPropertyFromValueBetween(ServerView* view,
- AnimationProperty property,
- double value,
- gfx::Tween::Type tween_type,
- const ScheduledAnimationValue& start,
- const ScheduledAnimationValue& target) {
- const double tween_value = gfx::Tween::CalculateValue(tween_type, value);
- switch (property) {
- case ANIMATION_PROPERTY_NONE:
- break;
- case ANIMATION_PROPERTY_OPACITY:
- view->SetOpacity(gfx::Tween::FloatValueBetween(
- tween_value, start.float_value, target.float_value));
- break;
- case ANIMATION_PROPERTY_TRANSFORM:
- view->SetTransform(gfx::Tween::TransformValueBetween(
- tween_value, start.transform, target.transform));
- break;
- }
-}
-
-gfx::Tween::Type AnimationTypeToTweenType(mojo::AnimationTweenType type) {
- switch (type) {
- case mojo::ANIMATION_TWEEN_TYPE_LINEAR:
- return gfx::Tween::LINEAR;
- case mojo::ANIMATION_TWEEN_TYPE_EASE_IN:
- return gfx::Tween::EASE_IN;
- case mojo::ANIMATION_TWEEN_TYPE_EASE_OUT:
- return gfx::Tween::EASE_OUT;
- case mojo::ANIMATION_TWEEN_TYPE_EASE_IN_OUT:
- return gfx::Tween::EASE_IN_OUT;
- }
- return gfx::Tween::LINEAR;
-}
-
-void ConvertToScheduledValue(const mojo::AnimationValue& transport_value,
- ScheduledAnimationValue* value) {
- value->float_value = transport_value.float_value;
- value->transform = transport_value.transform.To<gfx::Transform>();
-}
-
-void ConvertToScheduledElement(const mojo::AnimationElement& transport_element,
- ScheduledAnimationElement* element) {
- element->property = transport_element.property;
- element->duration =
- base::TimeDelta::FromMicroseconds(transport_element.duration);
- element->tween_type = AnimationTypeToTweenType(transport_element.tween_type);
- if (transport_element.property != ANIMATION_PROPERTY_NONE) {
- if (transport_element.start_value.get()) {
- element->is_start_valid = true;
- ConvertToScheduledValue(*transport_element.start_value,
- &(element->start_value));
- } else {
- element->is_start_valid = false;
- }
- ConvertToScheduledValue(*transport_element.target_value,
- &(element->target_value));
- }
-}
-
-bool IsAnimationValueValid(AnimationProperty property,
- const mojo::AnimationValue& value) {
- switch (property) {
- case ANIMATION_PROPERTY_NONE:
- NOTREACHED();
- return false;
- case ANIMATION_PROPERTY_OPACITY:
- return value.float_value >= 0.f && value.float_value <= 1.f;
- case ANIMATION_PROPERTY_TRANSFORM:
- return value.transform.get() && value.transform->matrix.size() == 16u;
- }
- return false;
-}
-
-bool IsAnimationElementValid(const mojo::AnimationElement& element) {
- if (element.property == ANIMATION_PROPERTY_NONE)
- return true; // None is a pause and doesn't need any values.
- if (element.start_value.get() &&
- !IsAnimationValueValid(element.property, *element.start_value))
- return false;
- // For all other properties we require a target.
- return element.target_value.get() &&
- IsAnimationValueValid(element.property, *element.target_value);
-}
-
-bool IsAnimationSequenceValid(const mojo::AnimationSequence& sequence) {
- if (sequence.elements.size() == 0u)
- return false;
-
- for (size_t i = 0; i < sequence.elements.size(); ++i) {
- if (!IsAnimationElementValid(*sequence.elements[i]))
- return false;
- }
- return true;
-}
-
-bool IsAnimationGroupValid(const mojo::AnimationGroup& transport_group) {
- if (transport_group.sequences.size() == 0u)
- return false;
- for (size_t i = 0; i < transport_group.sequences.size(); ++i) {
- if (!IsAnimationSequenceValid(*transport_group.sequences[i]))
- return false;
- }
- return true;
-}
-
-// If the start value for |element| isn't valid, the value for the property
-// is obtained from |view| and placed into |element|.
-void GetStartValueFromViewIfNecessary(const ServerView* view,
- ScheduledAnimationElement* element) {
- if (element->property != ANIMATION_PROPERTY_NONE &&
- !element->is_start_valid) {
- GetValueFromView(view, element->property, &(element->start_value));
- }
-}
-
-void GetScheduledAnimationProperties(const Sequences& sequences,
- std::set<AnimationProperty>* properties) {
- for (const ScheduledAnimationSequence& sequence : sequences) {
- for (const ScheduledAnimationElement& element : sequence.elements)
- properties->insert(element.property);
- }
-}
-
-void SetPropertyToTargetProperty(ServerView* view,
- mojo::AnimationProperty property,
- const Sequences& sequences) {
- // NOTE: this doesn't deal with |cycle_count| quite right, but I'm honestly
- // not sure we really want to support the same property in multiple sequences
- // animating at once so I'm not dealing.
- base::TimeDelta max_end_duration;
- scoped_ptr<ScheduledAnimationValue> value;
- for (const ScheduledAnimationSequence& sequence : sequences) {
- base::TimeDelta duration;
- for (const ScheduledAnimationElement& element : sequence.elements) {
- if (element.property != property)
- continue;
-
- duration += element.duration;
- if (duration > max_end_duration) {
- max_end_duration = duration;
- value.reset(new ScheduledAnimationValue(element.target_value));
- }
- }
- }
- if (value.get())
- SetViewPropertyFromValue(view, property, *value);
-}
-
-void ConvertSequenceToScheduled(
- const mojo::AnimationSequence& transport_sequence,
- base::TimeTicks now,
- ScheduledAnimationSequence* sequence) {
- sequence->run_until_stopped = transport_sequence.cycle_count == 0u;
- sequence->cycle_count = transport_sequence.cycle_count;
- DCHECK_NE(0u, transport_sequence.elements.size());
- sequence->elements.resize(transport_sequence.elements.size());
-
- base::TimeTicks element_start_time = now;
- for (size_t i = 0; i < transport_sequence.elements.size(); ++i) {
- ConvertToScheduledElement(*(transport_sequence.elements[i].get()),
- &(sequence->elements[i]));
- sequence->elements[i].start_time = element_start_time;
- sequence->duration += sequence->elements[i].duration;
- element_start_time += sequence->elements[i].duration;
- }
-}
-
-bool AdvanceSequence(ServerView* view,
- ScheduledAnimationSequence* sequence,
- base::TimeTicks now) {
- ScheduledAnimationElement* element =
- &(sequence->elements[sequence->current_index]);
- while (element->start_time + element->duration < now) {
- SetViewPropertyFromValue(view, element->property, element->target_value);
- if (++sequence->current_index == sequence->elements.size()) {
- if (!sequence->run_until_stopped && --sequence->cycle_count == 0) {
- SetViewPropertyFromValue(view, element->property,
- element->target_value);
- return false;
- }
-
- sequence->current_index = 0;
- }
- sequence->elements[sequence->current_index].start_time =
- element->start_time + element->duration;
- element = &(sequence->elements[sequence->current_index]);
- GetStartValueFromViewIfNecessary(view, element);
-
- // It's possible for the delta between now and |last_tick_time_| to be very
- // big (could happen if machine sleeps and is woken up much later). Normally
- // the repeat count is smallish, so we don't bother optimizing it. OTOH if
- // a sequence repeats forever we optimize it lest we get stuck in this loop
- // for a very long time.
- if (sequence->run_until_stopped && sequence->current_index == 0) {
- element->start_time =
- now - base::TimeDelta::FromMicroseconds(
- (now - element->start_time).InMicroseconds() %
- sequence->duration.InMicroseconds());
- }
- }
- return true;
-}
-
-} // namespace
-
-ScheduledAnimationValue::ScheduledAnimationValue() {
-}
-ScheduledAnimationValue::~ScheduledAnimationValue() {
-}
-
-ScheduledAnimationElement::ScheduledAnimationElement()
- : property(ANIMATION_PROPERTY_OPACITY),
- tween_type(gfx::Tween::EASE_IN),
- is_start_valid(false) {
-}
-ScheduledAnimationElement::~ScheduledAnimationElement() {
-}
-
-ScheduledAnimationSequence::ScheduledAnimationSequence()
- : run_until_stopped(false), cycle_count(0), current_index(0u) {
-}
-ScheduledAnimationSequence::~ScheduledAnimationSequence() {
-}
-
-ScheduledAnimationGroup::~ScheduledAnimationGroup() {
-}
-
-// static
-scoped_ptr<ScheduledAnimationGroup> ScheduledAnimationGroup::Create(
- ServerView* view,
- base::TimeTicks now,
- uint32_t id,
- const mojo::AnimationGroup& transport_group) {
- if (!IsAnimationGroupValid(transport_group))
- return nullptr;
-
- scoped_ptr<ScheduledAnimationGroup> group(
- new ScheduledAnimationGroup(view, id, now));
- group->sequences_.resize(transport_group.sequences.size());
- for (size_t i = 0; i < transport_group.sequences.size(); ++i) {
- const mojo::AnimationSequence& transport_sequence(
- *(transport_group.sequences[i]));
- DCHECK_NE(0u, transport_sequence.elements.size());
- ConvertSequenceToScheduled(transport_sequence, now, &group->sequences_[i]);
- }
- return group.Pass();
-}
-
-void ScheduledAnimationGroup::ObtainStartValues() {
- for (ScheduledAnimationSequence& sequence : sequences_)
- GetStartValueFromViewIfNecessary(view_, &(sequence.elements[0]));
-}
-
-void ScheduledAnimationGroup::SetValuesToTargetValuesForPropertiesNotIn(
- const ScheduledAnimationGroup& other) {
- std::set<AnimationProperty> our_properties;
- GetScheduledAnimationProperties(sequences_, &our_properties);
-
- std::set<AnimationProperty> other_properties;
- GetScheduledAnimationProperties(other.sequences_, &other_properties);
-
- for (AnimationProperty property : our_properties) {
- if (other_properties.count(property) == 0 &&
- property != ANIMATION_PROPERTY_NONE) {
- SetPropertyToTargetProperty(view_, property, sequences_);
- }
- }
-}
-
-bool ScheduledAnimationGroup::Tick(base::TimeTicks time) {
- for (Sequences::iterator i = sequences_.begin(); i != sequences_.end();) {
- if (!AdvanceSequence(view_, &(*i), time)) {
- i = sequences_.erase(i);
- continue;
- }
- const ScheduledAnimationElement& active_element(
- i->elements[i->current_index]);
- const double percent =
- (time - active_element.start_time).InMillisecondsF() /
- active_element.duration.InMillisecondsF();
- SetViewPropertyFromValueBetween(
- view_, active_element.property, percent, active_element.tween_type,
- active_element.start_value, active_element.target_value);
- ++i;
- }
- return sequences_.empty();
-}
-
-ScheduledAnimationGroup::ScheduledAnimationGroup(ServerView* view,
- uint32_t id,
- base::TimeTicks time_scheduled)
- : view_(view), id_(id), time_scheduled_(time_scheduled) {
-}
-
-} // namespace view_manager
diff --git a/components/view_manager/scheduled_animation_group.h b/components/view_manager/scheduled_animation_group.h
deleted file mode 100644
index f46abf0..0000000
--- a/components/view_manager/scheduled_animation_group.h
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_VIEW_MANAGER_SCHEDULED_ANIMATION_GROUP_H_
-#define COMPONENTS_VIEW_MANAGER_SCHEDULED_ANIMATION_GROUP_H_
-
-#include <vector>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/time/time.h"
-#include "components/view_manager/public/interfaces/animations.mojom.h"
-#include "ui/gfx/animation/tween.h"
-#include "ui/gfx/transform.h"
-
-namespace view_manager {
-
-class ServerView;
-
-struct ScheduledAnimationValue {
- ScheduledAnimationValue();
- ~ScheduledAnimationValue();
-
- float float_value;
- gfx::Transform transform;
-};
-
-struct ScheduledAnimationElement {
- ScheduledAnimationElement();
- ~ScheduledAnimationElement();
-
- mojo::AnimationProperty property;
- base::TimeDelta duration;
- gfx::Tween::Type tween_type;
- bool is_start_valid;
- ScheduledAnimationValue start_value;
- ScheduledAnimationValue target_value;
- // Start time is based on scheduled time and relative to any other elements
- // in the sequence.
- base::TimeTicks start_time;
-};
-
-struct ScheduledAnimationSequence {
- ScheduledAnimationSequence();
- ~ScheduledAnimationSequence();
-
- bool run_until_stopped;
- std::vector<ScheduledAnimationElement> elements;
-
- // Sum of the duration of all elements. This does not take into account
- // |cycle_count|.
- base::TimeDelta duration;
-
- // The following values are updated as the animation progresses.
-
- // Number of cycles remaining. This is only used if |run_until_stopped| is
- // false.
- uint32_t cycle_count;
-
- // Index into |elements| of the element currently animating.
- size_t current_index;
-};
-
-// Corresponds to a mojo::AnimationGroup and is responsible for running the
-// actual animation.
-class ScheduledAnimationGroup {
- public:
- ~ScheduledAnimationGroup();
-
- // Returns a new ScheduledAnimationGroup from the supplied parameters, or
- // null if |transport_group| isn't valid.
- static scoped_ptr<ScheduledAnimationGroup> Create(
- ServerView* view,
- base::TimeTicks now,
- uint32_t id,
- const mojo::AnimationGroup& transport_group);
-
- uint32_t id() const { return id_; }
-
- // Gets the start value for any elements that don't have an explicit start.
- // value.
- void ObtainStartValues();
-
- // Sets the values of any properties that are not in |other| to their final
- // value.
- void SetValuesToTargetValuesForPropertiesNotIn(
- const ScheduledAnimationGroup& other);
-
- // Advances the group. |time| is the current time. Returns true if the group
- // is done (nothing left to animate).
- bool Tick(base::TimeTicks time);
-
- ServerView* view() { return view_; }
-
- private:
- ScheduledAnimationGroup(ServerView* view,
- uint32_t id,
- base::TimeTicks time_scheduled);
-
- ServerView* view_;
- const uint32_t id_;
- base::TimeTicks time_scheduled_;
- std::vector<ScheduledAnimationSequence> sequences_;
-
- DISALLOW_COPY_AND_ASSIGN(ScheduledAnimationGroup);
-};
-
-} // namespace view_manager
-
-#endif // COMPONENTS_VIEW_MANAGER_SCHEDULED_ANIMATION_GROUP_H_
diff --git a/components/view_manager/scheduled_animation_group_unittest.cc b/components/view_manager/scheduled_animation_group_unittest.cc
deleted file mode 100644
index 4c80179..0000000
--- a/components/view_manager/scheduled_animation_group_unittest.cc
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/view_manager/scheduled_animation_group.h"
-
-#include "components/view_manager/public/interfaces/animations.mojom.h"
-#include "components/view_manager/server_view.h"
-#include "components/view_manager/test_server_view_delegate.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/transform/transform_type_converters.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using mojo::ANIMATION_PROPERTY_NONE;
-using mojo::ANIMATION_PROPERTY_OPACITY;
-using mojo::ANIMATION_PROPERTY_TRANSFORM;
-using mojo::ANIMATION_TWEEN_TYPE_LINEAR;
-using mojo::AnimationGroup;
-using mojo::AnimationSequence;
-using mojo::AnimationElement;
-using mojo::AnimationValue;
-
-namespace view_manager {
-namespace {
-
-bool IsAnimationGroupValid(const AnimationGroup& transport_group) {
- TestServerViewDelegate view_delegate;
- ServerView view(&view_delegate, ViewId());
- scoped_ptr<ScheduledAnimationGroup> group(ScheduledAnimationGroup::Create(
- &view, base::TimeTicks::Now(), 1, transport_group));
- return group.get() != nullptr;
-}
-
-} // namespace
-
-TEST(ScheduledAnimationGroupTest, IsAnimationGroupValid) {
- AnimationGroup group;
-
- // AnimationGroup with no sequences is not valid.
- EXPECT_FALSE(IsAnimationGroupValid(group));
-
- group.sequences.push_back(AnimationSequence::New());
-
- // Sequence with no elements is not valid.
- EXPECT_FALSE(IsAnimationGroupValid(group));
-
- AnimationSequence& sequence = *(group.sequences[0]);
- sequence.elements.push_back(AnimationElement::New());
- AnimationElement& element = *(sequence.elements[0]);
- element.property = ANIMATION_PROPERTY_OPACITY;
- element.tween_type = ANIMATION_TWEEN_TYPE_LINEAR;
-
- // Element with no target_value is not valid.
- EXPECT_FALSE(IsAnimationGroupValid(group));
-
- // Opacity must be between 0 and 1.
- element.target_value = AnimationValue::New();
- element.target_value->float_value = 2.5f;
- EXPECT_FALSE(IsAnimationGroupValid(group));
-
- element.target_value->float_value = .5f;
- EXPECT_TRUE(IsAnimationGroupValid(group));
-
- // Bogus start value.
- element.start_value = AnimationValue::New();
- element.start_value->float_value = 2.5f;
- EXPECT_FALSE(IsAnimationGroupValid(group));
-
- element.start_value->float_value = .5f;
- EXPECT_TRUE(IsAnimationGroupValid(group));
-
- // Bogus transform.
- element.property = ANIMATION_PROPERTY_TRANSFORM;
- EXPECT_FALSE(IsAnimationGroupValid(group));
- element.start_value->transform = mojo::Transform::From(gfx::Transform());
- EXPECT_FALSE(IsAnimationGroupValid(group));
- element.target_value->transform = mojo::Transform::From(gfx::Transform());
- EXPECT_TRUE(IsAnimationGroupValid(group));
-
- // Add another empty sequence, should be invalid again.
- group.sequences.push_back(AnimationSequence::New());
- EXPECT_FALSE(IsAnimationGroupValid(group));
-
- AnimationSequence& sequence2 = *(group.sequences[1]);
- sequence2.elements.push_back(AnimationElement::New());
- AnimationElement& element2 = *(sequence2.elements[0]);
- element2.property = ANIMATION_PROPERTY_OPACITY;
- element2.tween_type = ANIMATION_TWEEN_TYPE_LINEAR;
-
- // Element with no target_value is not valid.
- EXPECT_FALSE(IsAnimationGroupValid(group));
-
- element2.property = ANIMATION_PROPERTY_NONE;
- EXPECT_TRUE(IsAnimationGroupValid(group));
-}
-
-} // namespace view_manager
diff --git a/components/view_manager/server_view.cc b/components/view_manager/server_view.cc
index 00de8f3..fe90ac9 100644
--- a/components/view_manager/server_view.cc
+++ b/components/view_manager/server_view.cc
@@ -40,7 +40,6 @@ ServerView::ServerView(ServerViewDelegate* delegate,
}
ServerView::~ServerView() {
- delegate_->PrepareToDestroyView(this);
FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnWillDestroyView(this));
while (!children_.empty())
@@ -94,7 +93,6 @@ void ServerView::Add(ServerView* child) {
}
ServerView* old_parent = child->parent();
- child->delegate_->PrepareToChangeViewHierarchy(child, this, old_parent);
FOR_EACH_OBSERVER(ServerViewObserver, child->observers_,
OnWillChangeViewHierarchy(child, this, old_parent));
@@ -113,7 +111,6 @@ void ServerView::Remove(ServerView* child) {
DCHECK(child != this);
DCHECK(child->parent() == this);
- child->delegate_->PrepareToChangeViewHierarchy(child, NULL, this);
FOR_EACH_OBSERVER(ServerViewObserver, child->observers_,
OnWillChangeViewHierarchy(child, nullptr, this));
RemoveImpl(child);
@@ -180,7 +177,6 @@ void ServerView::SetVisible(bool value) {
if (visible_ == value)
return;
- delegate_->PrepareToChangeViewVisibility(this);
FOR_EACH_OBSERVER(ServerViewObserver, observers_,
OnWillChangeViewVisibility(this));
visible_ = value;
diff --git a/components/view_manager/server_view_delegate.h b/components/view_manager/server_view_delegate.h
index 67ba9cb..aa63b88 100644
--- a/components/view_manager/server_view_delegate.h
+++ b/components/view_manager/server_view_delegate.h
@@ -13,14 +13,6 @@ namespace cc {
class CompositorFrame;
}
-namespace gfx {
-class Rect;
-}
-
-namespace mojo {
-class ViewportMetrics;
-}
-
namespace surfaces {
class SurfacesState;
}
@@ -29,12 +21,6 @@ namespace view_manager {
class ServerView;
-// ServerViewDelegate is notified at key points in the lifetime of a
-// ServerView. Some of the functions are similar to that of
-// ServerViewObserver. For example, ServerViewDelegate::PrepareToDestroyView()
-// and ServerViewObserver::OnWillDestroyView(). The key difference between
-// the two are the ServerViewDelegate ones are always notified first, and
-// ServerViewDelegate gets non-const arguments.
class ServerViewDelegate {
public:
virtual scoped_ptr<cc::CompositorFrame> UpdateViewTreeFromCompositorFrame(
@@ -42,16 +28,6 @@ class ServerViewDelegate {
virtual surfaces::SurfacesState* GetSurfacesState() = 0;
- // Invoked when a view is about to be destroyed; before any of the children
- // have been removed and before the view has been removed from its parent.
- virtual void PrepareToDestroyView(ServerView* view) = 0;
-
- virtual void PrepareToChangeViewHierarchy(ServerView* view,
- ServerView* new_parent,
- ServerView* old_parent) = 0;
-
- virtual void PrepareToChangeViewVisibility(ServerView* view) = 0;
-
virtual void OnScheduleViewPaint(const ServerView* view) = 0;
// Returns the root of the view tree to which this |view| is attached. Returns
diff --git a/components/view_manager/test_server_view_delegate.cc b/components/view_manager/test_server_view_delegate.cc
index 059d513..db056a6 100644
--- a/components/view_manager/test_server_view_delegate.cc
+++ b/components/view_manager/test_server_view_delegate.cc
@@ -23,18 +23,6 @@ surfaces::SurfacesState* TestServerViewDelegate::GetSurfacesState() {
return nullptr;
}
-void TestServerViewDelegate::PrepareToDestroyView(ServerView* view) {
-}
-
-void TestServerViewDelegate::PrepareToChangeViewHierarchy(
- ServerView* view,
- ServerView* new_parent,
- ServerView* old_parent) {
-}
-
-void TestServerViewDelegate::PrepareToChangeViewVisibility(ServerView* view) {
-}
-
void TestServerViewDelegate::OnScheduleViewPaint(const ServerView* view) {
}
diff --git a/components/view_manager/test_server_view_delegate.h b/components/view_manager/test_server_view_delegate.h
index 42e0fe5..d19e140 100644
--- a/components/view_manager/test_server_view_delegate.h
+++ b/components/view_manager/test_server_view_delegate.h
@@ -21,11 +21,6 @@ class TestServerViewDelegate : public ServerViewDelegate {
scoped_ptr<cc::CompositorFrame> UpdateViewTreeFromCompositorFrame(
const mojo::CompositorFramePtr& input) override;
surfaces::SurfacesState* GetSurfacesState() override;
- void PrepareToDestroyView(ServerView* view) override;
- void PrepareToChangeViewHierarchy(ServerView* view,
- ServerView* new_parent,
- ServerView* old_parent) override;
- void PrepareToChangeViewVisibility(ServerView* view) override;
void OnScheduleViewPaint(const ServerView* view) override;
const ServerView* GetRootView(const ServerView* view) const override;
diff --git a/components/view_manager/view_tree_apptest.cc b/components/view_manager/view_tree_apptest.cc
index 19746d9..0542c16 100644
--- a/components/view_manager/view_tree_apptest.cc
+++ b/components/view_manager/view_tree_apptest.cc
@@ -213,13 +213,6 @@ bool WaitForAllMessages(ViewTree* vm) {
return result != ERROR_CODE_NONE;
}
-bool HasClonedView(const std::vector<TestView>& views) {
- for (size_t i = 0; i < views.size(); ++i)
- if (views[i].view_id == ViewIdToTransportId(ClonedViewId()))
- return true;
- return false;
-}
-
const Id kNullParentId = 0;
std::string IdToString(Id id) {
return (id == kNullParentId)
diff --git a/components/view_manager/view_tree_unittest.cc b/components/view_manager/view_tree_unittest.cc
index 0b539d2..e467740 100644
--- a/components/view_manager/view_tree_unittest.cc
+++ b/components/view_manager/view_tree_unittest.cc
@@ -324,206 +324,6 @@ class ViewTreeTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(ViewTreeTest);
};
-namespace {
-
-const ServerView* GetFirstCloned(const ServerView* view) {
- for (const ServerView* child : view->GetChildren()) {
- if (child->id() == ClonedViewId())
- return child;
- }
- return nullptr;
-}
-
-// Provides common setup for animation tests. Creates the following views:
-// 0,1 (the root, provided by view manager)
-// 1,1 the second connection is embedded here (view owned by wm_connection()).
-// 2,1 bounds=1,2 11x22
-// 2,2 bounds=2,3 6x7
-// 2,3 bounds=3,4 6x7
-// CloneAndAnimate() is invoked for 2,2.
-void SetUpAnimate1(ViewTreeTest* test, ViewId* embed_view_id) {
- *embed_view_id = ViewId(test->wm_connection()->id(), 1);
- EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id));
- EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true));
- EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()),
- *embed_view_id));
- mojo::URLRequestPtr request(mojo::URLRequest::New());
- test->wm_connection()->Embed(*embed_view_id, request.Pass());
- ViewTreeImpl* connection1 =
- test->connection_manager()->GetConnectionWithRoot(*embed_view_id);
- ASSERT_TRUE(connection1 != nullptr);
- ASSERT_NE(connection1, test->wm_connection());
-
- const ViewId child1(connection1->id(), 1);
- EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
- const ViewId child2(connection1->id(), 2);
- EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
- const ViewId child3(connection1->id(), 3);
- EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
-
- ServerView* v1 = connection1->GetView(child1);
- v1->SetVisible(true);
- v1->SetBounds(gfx::Rect(1, 2, 11, 22));
- ServerView* v2 = connection1->GetView(child2);
- v2->SetVisible(true);
- v2->SetBounds(gfx::Rect(2, 3, 6, 7));
- ServerView* v3 = connection1->GetView(child3);
- v3->SetVisible(true);
- v3->SetBounds(gfx::Rect(3, 4, 6, 7));
-
- EXPECT_TRUE(connection1->AddView(*embed_view_id, child1));
- EXPECT_TRUE(connection1->AddView(child1, child2));
- EXPECT_TRUE(connection1->AddView(child2, child3));
-
- TestViewTreeClient* connection1_client = test->last_view_tree_client();
- connection1_client->tracker()->changes()->clear();
- test->wm_client()->tracker()->changes()->clear();
- EXPECT_TRUE(test->connection_manager()->CloneAndAnimate(child2));
- EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
- EXPECT_TRUE(test->wm_client()->tracker()->changes()->empty());
-
- // We cloned v2. The cloned view ends up as a sibling of it.
- const ServerView* cloned_view = GetFirstCloned(connection1->GetView(child1));
- ASSERT_TRUE(cloned_view);
- // |cloned_view| should have one and only one cloned child (corresponds to
- // |child3|).
- ASSERT_EQ(1u, cloned_view->GetChildren().size());
- EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
-
- // Cloned views should match the bounds of the view they were cloned from.
- EXPECT_EQ(v2->bounds(), cloned_view->bounds());
- EXPECT_EQ(v3->bounds(), cloned_view->GetChildren()[0]->bounds());
-
- // Cloned views are owned by the ConnectionManager and shouldn't be returned
- // from ViewTreeImpl::GetView.
- EXPECT_TRUE(connection1->GetView(ClonedViewId()) == nullptr);
- EXPECT_TRUE(test->wm_connection()->GetView(ClonedViewId()) == nullptr);
-}
-
-} // namespace
-
-// Verifies ViewTree::GetViewTree() doesn't return cloned views.
-TEST_F(ViewTreeTest, ConnectionsCantSeeClonedViews) {
- ViewId embed_view_id;
- EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
-
- ViewTreeImpl* connection1 =
- connection_manager()->GetConnectionWithRoot(embed_view_id);
-
- const ViewId child1(connection1->id(), 1);
- const ViewId child2(connection1->id(), 2);
- const ViewId child3(connection1->id(), 3);
-
- // Verify the root doesn't see any cloned views.
- std::vector<const ServerView*> views(
- wm_connection()->GetViewTree(*wm_connection()->root()));
- ASSERT_EQ(5u, views.size());
- ASSERT_TRUE(views[0]->id() == *wm_connection()->root());
- ASSERT_TRUE(views[1]->id() == embed_view_id);
- ASSERT_TRUE(views[2]->id() == child1);
- ASSERT_TRUE(views[3]->id() == child2);
- ASSERT_TRUE(views[4]->id() == child3);
-
- // Verify connection1 doesn't see any cloned views.
- std::vector<const ServerView*> v1_views(
- connection1->GetViewTree(embed_view_id));
- ASSERT_EQ(4u, v1_views.size());
- ASSERT_TRUE(v1_views[0]->id() == embed_view_id);
- ASSERT_TRUE(v1_views[1]->id() == child1);
- ASSERT_TRUE(v1_views[2]->id() == child2);
- ASSERT_TRUE(v1_views[3]->id() == child3);
-}
-
-TEST_F(ViewTreeTest, ClonedViewsPromotedOnConnectionClose) {
- ViewId embed_view_id;
- EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
-
- // Destroy connection1, which should force the cloned view to become a child
- // of where it was embedded (the embedded view still exists).
- connection_manager()->OnConnectionError(last_client_connection());
-
- ServerView* embed_view = wm_connection()->GetView(embed_view_id);
- ASSERT_TRUE(embed_view != nullptr);
- const ServerView* cloned_view = GetFirstCloned(embed_view);
- ASSERT_TRUE(cloned_view);
- ASSERT_EQ(1u, cloned_view->GetChildren().size());
- EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
-
- // Because the cloned view changed parents its bounds should have changed.
- EXPECT_EQ(gfx::Rect(3, 5, 6, 7), cloned_view->bounds());
- // The bounds of the cloned child should not have changed though.
- EXPECT_EQ(gfx::Rect(3, 4, 6, 7), cloned_view->GetChildren()[0]->bounds());
-}
-
-TEST_F(ViewTreeTest, ClonedViewsPromotedOnHide) {
- ViewId embed_view_id;
- EXPECT_NO_FATAL_FAILURE(SetUpAnimate1(this, &embed_view_id));
-
- ViewTreeImpl* connection1 =
- connection_manager()->GetConnectionWithRoot(embed_view_id);
-
- // Hide the parent of the cloned view, which should force the cloned view to
- // become a sibling of the parent.
- const ServerView* view_to_hide =
- connection1->GetView(ViewId(connection1->id(), 1));
- ASSERT_TRUE(connection1->SetViewVisibility(view_to_hide->id(), false));
-
- const ServerView* cloned_view = GetFirstCloned(view_to_hide->parent());
- ASSERT_TRUE(cloned_view);
- ASSERT_EQ(1u, cloned_view->GetChildren().size());
- EXPECT_TRUE(cloned_view->GetChildren()[0]->id() == ClonedViewId());
- EXPECT_EQ(2u, cloned_view->parent()->GetChildren().size());
- EXPECT_TRUE(cloned_view->parent()->GetChildren()[1] == cloned_view);
-}
-
-// Clone and animate on a tree with more depth. Basically that of
-// SetUpAnimate1() but cloning 2,1.
-TEST_F(ViewTreeTest, CloneAndAnimateLargerDepth) {
- const ViewId embed_view_id(wm_connection()->id(), 1);
- EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id));
- EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true));
- EXPECT_TRUE(
- wm_connection()->AddView(*(wm_connection()->root()), embed_view_id));
- mojo::URLRequestPtr request(mojo::URLRequest::New());
- wm_connection()->Embed(embed_view_id, request.Pass());
- ViewTreeImpl* connection1 =
- connection_manager()->GetConnectionWithRoot(embed_view_id);
- ASSERT_TRUE(connection1 != nullptr);
- ASSERT_NE(connection1, wm_connection());
-
- const ViewId child1(connection1->id(), 1);
- EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1));
- const ViewId child2(connection1->id(), 2);
- EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2));
- const ViewId child3(connection1->id(), 3);
- EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child3));
-
- ServerView* v1 = connection1->GetView(child1);
- v1->SetVisible(true);
- connection1->GetView(child2)->SetVisible(true);
- connection1->GetView(child3)->SetVisible(true);
-
- EXPECT_TRUE(connection1->AddView(embed_view_id, child1));
- EXPECT_TRUE(connection1->AddView(child1, child2));
- EXPECT_TRUE(connection1->AddView(child2, child3));
-
- TestViewTreeClient* connection1_client = last_view_tree_client();
- connection1_client->tracker()->changes()->clear();
- wm_client()->tracker()->changes()->clear();
- EXPECT_TRUE(connection_manager()->CloneAndAnimate(child1));
- EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
- EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
-
- // We cloned v1. The cloned view ends up as a sibling of it.
- const ServerView* cloned_view = GetFirstCloned(v1->parent());
- ASSERT_TRUE(cloned_view);
- // |cloned_view| should have a child and its child should have a child.
- ASSERT_EQ(1u, cloned_view->GetChildren().size());
- const ServerView* cloned_view_child = cloned_view->GetChildren()[0];
- EXPECT_EQ(1u, cloned_view_child->GetChildren().size());
- EXPECT_TRUE(cloned_view_child->id() == ClonedViewId());
-}
-
// Verifies focus correctly changes on pointer events.
TEST_F(ViewTreeTest, FocusOnPointer) {
const ViewId embed_view_id(wm_connection()->id(), 1);
diff --git a/components/view_manager/window_manager_access_policy.cc b/components/view_manager/window_manager_access_policy.cc
index d90026c..a9dd326 100644
--- a/components/view_manager/window_manager_access_policy.cc
+++ b/components/view_manager/window_manager_access_policy.cc
@@ -43,12 +43,12 @@ bool WindowManagerAccessPolicy::CanDeleteView(const ServerView* view) const {
}
bool WindowManagerAccessPolicy::CanGetViewTree(const ServerView* view) const {
- return view->id() != ClonedViewId();
+ return true;
}
bool WindowManagerAccessPolicy::CanDescendIntoViewForViewTree(
const ServerView* view) const {
- return view->id() != ClonedViewId();
+ return true;
}
bool WindowManagerAccessPolicy::CanEmbed(const ServerView* view) const {
@@ -92,9 +92,6 @@ bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
const ServerView* view,
const ServerView** new_parent,
const ServerView** old_parent) const {
- if (view->id() == ClonedViewId())
- return false;
-
// Notify if we've already told the window manager about the view, or if we've
// already told the window manager about the parent. The later handles the
// case of a view that wasn't parented to the root getting added to the root.