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

Side by Side Diff: ash/wm/shelf_layout_manager.cc

Issue 9222018: reland -- Disable animations during aura tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer comments. Created 8 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/shelf_layout_manager.h" 5 #include "ash/wm/shelf_layout_manager.h"
6 6
7 #include "ash/launcher/launcher.h" 7 #include "ash/launcher/launcher.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
11 #include "ui/aura/screen_aura.h" 11 #include "ui/aura/screen_aura.h"
12 #include "ui/gfx/compositor/layer.h" 12 #include "ui/gfx/compositor/layer.h"
13 #include "ui/gfx/compositor/layer_animation_observer.h"
13 #include "ui/gfx/compositor/layer_animator.h" 14 #include "ui/gfx/compositor/layer_animator.h"
14 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" 15 #include "ui/gfx/compositor/scoped_layer_animation_settings.h"
15 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
16 17
18 using ui::ImplicitAnimationObserver;
19
17 namespace ash { 20 namespace ash {
18 namespace internal { 21 namespace internal {
19 22
20 namespace { 23 namespace {
21 24
22 ui::Layer* GetLayer(views::Widget* widget) { 25 ui::Layer* GetLayer(views::Widget* widget) {
23 return widget->GetNativeView()->layer(); 26 return widget->GetNativeView()->layer();
24 } 27 }
25 28
29 class ShelfAnimationObserver : public ImplicitAnimationObserver {
30 public:
31 ShelfAnimationObserver(ShelfAnimationObserverClient* client)
32 : client_(client) {}
33 virtual ~ShelfAnimationObserver() {}
34
35 private:
36 // Implementation of ImplicitAnimationObserver
37 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
38 client_->OnShelfAnimationsCompleted(this);
39 }
40
41 ShelfAnimationObserverClient* client_;
42
43 DISALLOW_COPY_AND_ASSIGN(ShelfAnimationObserver);
44 };
45
26 } // namespace 46 } // namespace
27 47
28 //////////////////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////////////////
29 // ShelfLayoutManager, public: 49 // ShelfLayoutManager, public:
30 50
31 ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher, 51 ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher,
32 views::Widget* status) 52 views::Widget* status)
33 : animating_(false), 53 : in_layout_(false),
34 in_layout_(false),
35 visible_(true), 54 visible_(true),
36 max_height_(-1), 55 max_height_(-1),
37 launcher_(launcher), 56 launcher_(launcher),
38 status_(status) { 57 status_(status) {
39 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); 58 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds();
40 gfx::Rect status_bounds = status->GetWindowScreenBounds(); 59 gfx::Rect status_bounds = status->GetWindowScreenBounds();
41 max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); 60 max_height_ = std::max(launcher_bounds.height(), status_bounds.height());
42 GetLayer(launcher)->GetAnimator()->AddObserver(this);
43 } 61 }
44 62
45 ShelfLayoutManager::~ShelfLayoutManager() { 63 ShelfLayoutManager::~ShelfLayoutManager() {
46 GetLayer(launcher_)->GetAnimator()->RemoveObserver(this);
47 // Without a shelf we don't need special insets anymore. 64 // Without a shelf we don't need special insets anymore.
48 aura::RootWindow::GetInstance()-> 65 aura::RootWindow::GetInstance()->
49 screen()->set_work_area_insets(gfx::Insets()); 66 screen()->set_work_area_insets(gfx::Insets());
67
68 if (launcher_animation_observer_.get())
69 GetLayer(launcher_)->GetAnimator()->RemoveObserver(
70 launcher_animation_observer_.get());
71
72 if (status_animation_observer_.get())
73 GetLayer(status_)->GetAnimator()->RemoveObserver(
74 status_animation_observer_.get());
50 } 75 }
51 76
52 void ShelfLayoutManager::LayoutShelf() { 77 void ShelfLayoutManager::LayoutShelf() {
53 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 78 AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
54 StopAnimating(); 79 StopAnimating();
55 TargetBounds target_bounds; 80 TargetBounds target_bounds;
56 float target_opacity = visible_ ? 1.0f : 0.0f; 81 float target_opacity = visible_ ? 1.0f : 0.0f;
57 CalculateTargetBounds(visible_, &target_bounds); 82 CalculateTargetBounds(visible_, &target_bounds);
58 GetLayer(launcher_)->SetOpacity(target_opacity); 83 GetLayer(launcher_)->SetOpacity(target_opacity);
59 GetLayer(status_)->SetOpacity(target_opacity); 84 GetLayer(status_)->SetOpacity(target_opacity);
60 launcher_->SetBounds(target_bounds.launcher_bounds); 85 launcher_->SetBounds(target_bounds.launcher_bounds);
61 status_->SetBounds(target_bounds.status_bounds); 86 status_->SetBounds(target_bounds.status_bounds);
62 Shell::GetInstance()->launcher()->SetStatusWidth( 87 Shell::GetInstance()->launcher()->SetStatusWidth(
63 target_bounds.status_bounds.width()); 88 target_bounds.status_bounds.width());
64 aura::RootWindow::GetInstance()->screen()->set_work_area_insets( 89 aura::RootWindow::GetInstance()->screen()->set_work_area_insets(
65 target_bounds.work_area_insets); 90 target_bounds.work_area_insets);
66 } 91 }
67 92
68 void ShelfLayoutManager::SetVisible(bool visible) { 93 void ShelfLayoutManager::SetVisible(bool visible) {
69 bool current_visibility = animating_ ? !visible_ : visible_; 94 // TODO(vollick): once visibility is animatable, use GetTargetVisibility.
95 bool current_visibility = visible_ &&
96 GetLayer(launcher_)->GetTargetOpacity() > 0.0f &&
97 GetLayer(status_)->GetTargetOpacity() > 0.0f;
98
70 if (visible == current_visibility) 99 if (visible == current_visibility)
71 return; // Nothing changed. 100 return; // Nothing changed.
72 101
73 StopAnimating(); 102 StopAnimating();
74 103
104 visible_ = visible;
75 TargetBounds target_bounds; 105 TargetBounds target_bounds;
76 float target_opacity = visible ? 1.0f : 0.0f; 106 float target_opacity = visible ? 1.0f : 0.0f;
77 CalculateTargetBounds(visible, &target_bounds); 107 CalculateTargetBounds(visible, &target_bounds);
78 AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); 108
79 AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); 109 launcher_animation_observer_.reset(new ShelfAnimationObserver(this));
80 animating_ = true; 110 status_animation_observer_.reset(new ShelfAnimationObserver(this));
81 // |visible_| is updated once the animation completes. 111
112 AnimateWidgetTo(launcher_,
113 launcher_animation_observer_.get(),
114 target_bounds.launcher_bounds,
115 target_opacity);
116
117 AnimateWidgetTo(status_,
118 status_animation_observer_.get(),
119 target_bounds.status_bounds,
120 target_opacity);
82 } 121 }
83 122
84 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
85 // ShelfLayoutManager, aura::LayoutManager implementation: 124 // ShelfLayoutManager, aura::LayoutManager implementation:
86 125
87 void ShelfLayoutManager::OnWindowResized() { 126 void ShelfLayoutManager::OnWindowResized() {
88 LayoutShelf(); 127 LayoutShelf();
89 } 128 }
90 129
91 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { 130 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
(...skipping 10 matching lines...) Expand all
102 const gfx::Rect& requested_bounds) { 141 const gfx::Rect& requested_bounds) {
103 SetChildBoundsDirect(child, requested_bounds); 142 SetChildBoundsDirect(child, requested_bounds);
104 if (!in_layout_) 143 if (!in_layout_)
105 LayoutShelf(); 144 LayoutShelf();
106 } 145 }
107 146
108 //////////////////////////////////////////////////////////////////////////////// 147 ////////////////////////////////////////////////////////////////////////////////
109 // ShelfLayoutManager, private: 148 // ShelfLayoutManager, private:
110 149
111 void ShelfLayoutManager::StopAnimating() { 150 void ShelfLayoutManager::StopAnimating() {
112 if (animating_) {
113 animating_ = false;
114 visible_ = !visible_;
115 }
116 GetLayer(launcher_)->GetAnimator()->StopAnimating(); 151 GetLayer(launcher_)->GetAnimator()->StopAnimating();
117 GetLayer(status_)->GetAnimator()->StopAnimating(); 152 GetLayer(status_)->GetAnimator()->StopAnimating();
118 } 153 }
119 154
120 void ShelfLayoutManager::CalculateTargetBounds(bool visible, 155 void ShelfLayoutManager::CalculateTargetBounds(bool visible,
121 TargetBounds* target_bounds) { 156 TargetBounds* target_bounds) {
122 const gfx::Rect& available_bounds(aura::RootWindow::GetInstance()->bounds()); 157 const gfx::Rect& available_bounds(aura::RootWindow::GetInstance()->bounds());
123 int y = available_bounds.bottom() - (visible ? max_height_ : 0); 158 int y = available_bounds.bottom() - (visible ? max_height_ : 0);
124 gfx::Rect status_bounds(status_->GetWindowScreenBounds()); 159 gfx::Rect status_bounds(status_->GetWindowScreenBounds());
125 target_bounds->status_bounds = gfx::Rect( 160 target_bounds->status_bounds = gfx::Rect(
126 available_bounds.right() - status_bounds.width(), 161 available_bounds.right() - status_bounds.width(),
127 y + (max_height_ - status_bounds.height()) / 2, 162 y + (max_height_ - status_bounds.height()) / 2,
128 status_bounds.width(), status_bounds.height()); 163 status_bounds.width(), status_bounds.height());
129 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); 164 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds());
130 target_bounds->launcher_bounds = gfx::Rect( 165 target_bounds->launcher_bounds = gfx::Rect(
131 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, 166 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2,
132 available_bounds.width(), 167 available_bounds.width(),
133 launcher_bounds.height()); 168 launcher_bounds.height());
134 if (visible) 169 if (visible)
135 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); 170 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0);
136 } 171 }
137 172
138 void ShelfLayoutManager::AnimateWidgetTo(views::Widget* widget, 173 void ShelfLayoutManager::AnimateWidgetTo(views::Widget* widget,
174 ImplicitAnimationObserver* observer,
139 const gfx::Rect& target_bounds, 175 const gfx::Rect& target_bounds,
140 float target_opacity) { 176 float target_opacity) {
141 ui::Layer* layer = GetLayer(widget); 177 ui::Layer* layer = GetLayer(widget);
142 ui::ScopedLayerAnimationSettings animation_setter(layer->GetAnimator()); 178 ui::ScopedLayerAnimationSettings animation_setter(layer->GetAnimator());
179 animation_setter.AddObserver(observer);
143 // Don't go through the widget, otherwise we end up back in SetChildBounds and 180 // Don't go through the widget, otherwise we end up back in SetChildBounds and
144 // cancel the animation/layout. 181 // cancel the animation/layout.
145 layer->SetBounds(target_bounds); 182 layer->SetBounds(target_bounds);
146 layer->SetOpacity(target_opacity); 183 layer->SetOpacity(target_opacity);
147 } 184 }
148 185
149 void ShelfLayoutManager::OnLayerAnimationEnded( 186 void ShelfLayoutManager::OnShelfAnimationsCompleted(
150 const ui::LayerAnimationSequence* sequence) { 187 ImplicitAnimationObserver* observer) {
151 if (!animating_) 188 if (observer == launcher_animation_observer_.get())
152 return; 189 launcher_animation_observer_.reset(NULL);
153 animating_ = false; 190 else if (observer == status_animation_observer_.get())
154 visible_ = !visible_; 191 status_animation_observer_.reset(NULL);
155 TargetBounds target_bounds; 192 else
156 CalculateTargetBounds(visible_, &target_bounds); 193 NOTREACHED() << "Unknown observer in OnShelfAnimationsCompleted";
157 aura::RootWindow::GetInstance()->screen()->set_work_area_insets( 194
158 target_bounds.work_area_insets); 195 if (!launcher_animation_observer_.get() &&
196 !status_animation_observer_.get()) {
197 TargetBounds target_bounds;
198 CalculateTargetBounds(visible_, &target_bounds);
199 aura::RootWindow::GetInstance()->screen()->set_work_area_insets(
200 target_bounds.work_area_insets);
201 }
159 } 202 }
160 203
161 } // namespace internal 204 } // namespace internal
162 } // namespace ash 205 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698