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

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: . Created 8 years, 10 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
« no previous file with comments | « ash/wm/shelf_layout_manager.h ('k') | ash/wm/system_modal_container_layout_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
17 namespace ash { 18 namespace ash {
18 namespace internal { 19 namespace internal {
19 20
20 namespace { 21 namespace {
21 22
22 ui::Layer* GetLayer(views::Widget* widget) { 23 ui::Layer* GetLayer(views::Widget* widget) {
23 return widget->GetNativeView()->layer(); 24 return widget->GetNativeView()->layer();
24 } 25 }
25 26
26 } // namespace 27 } // namespace
27 28
28 //////////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////////
29 // ShelfLayoutManager, public: 30 // ShelfLayoutManager, public:
30 31
31 ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher, 32 ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher,
32 views::Widget* status) 33 views::Widget* status)
33 : animating_(false), 34 : in_layout_(false),
34 in_layout_(false),
35 visible_(true), 35 visible_(true),
36 max_height_(-1), 36 max_height_(-1),
37 launcher_(launcher), 37 launcher_(launcher),
38 status_(status) { 38 status_(status) {
39 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); 39 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds();
40 gfx::Rect status_bounds = status->GetWindowScreenBounds(); 40 gfx::Rect status_bounds = status->GetWindowScreenBounds();
41 max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); 41 max_height_ = std::max(launcher_bounds.height(), status_bounds.height());
42 GetLayer(launcher)->GetAnimator()->AddObserver(this);
43 } 42 }
44 43
45 ShelfLayoutManager::~ShelfLayoutManager() { 44 ShelfLayoutManager::~ShelfLayoutManager() {
46 GetLayer(launcher_)->GetAnimator()->RemoveObserver(this);
47 // Without a shelf we don't need special insets anymore. 45 // Without a shelf we don't need special insets anymore.
48 aura::RootWindow::GetInstance()-> 46 aura::RootWindow::GetInstance()->
49 screen()->set_work_area_insets(gfx::Insets()); 47 screen()->set_work_area_insets(gfx::Insets());
50 } 48 }
51 49
52 void ShelfLayoutManager::LayoutShelf() { 50 void ShelfLayoutManager::LayoutShelf() {
53 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 51 AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
54 StopAnimating(); 52 StopAnimating();
55 TargetBounds target_bounds; 53 TargetBounds target_bounds;
56 float target_opacity = visible_ ? 1.0f : 0.0f; 54 float target_opacity = visible_ ? 1.0f : 0.0f;
57 CalculateTargetBounds(visible_, &target_bounds); 55 CalculateTargetBounds(visible_, &target_bounds);
58 GetLayer(launcher_)->SetOpacity(target_opacity); 56 GetLayer(launcher_)->SetOpacity(target_opacity);
59 GetLayer(status_)->SetOpacity(target_opacity); 57 GetLayer(status_)->SetOpacity(target_opacity);
60 launcher_->SetBounds(target_bounds.launcher_bounds); 58 launcher_->SetBounds(target_bounds.launcher_bounds);
61 status_->SetBounds(target_bounds.status_bounds); 59 status_->SetBounds(target_bounds.status_bounds);
62 Shell::GetInstance()->launcher()->SetStatusWidth( 60 Shell::GetInstance()->launcher()->SetStatusWidth(
63 target_bounds.status_bounds.width()); 61 target_bounds.status_bounds.width());
64 aura::RootWindow::GetInstance()->screen()->set_work_area_insets( 62 aura::RootWindow::GetInstance()->screen()->set_work_area_insets(
65 target_bounds.work_area_insets); 63 target_bounds.work_area_insets);
66 } 64 }
67 65
68 void ShelfLayoutManager::SetVisible(bool visible) { 66 void ShelfLayoutManager::SetVisible(bool visible) {
69 bool current_visibility = animating_ ? !visible_ : visible_; 67 ui::Layer* launcher_layer = GetLayer(launcher_);
68 ui::Layer* status_layer = GetLayer(status_);
69
70 // TODO(vollick): once visibility is animatable, use GetTargetVisibility.
71 bool current_visibility = visible_ &&
72 launcher_layer->GetTargetOpacity() > 0.0f &&
73 status_layer->GetTargetOpacity() > 0.0f;
74
70 if (visible == current_visibility) 75 if (visible == current_visibility)
71 return; // Nothing changed. 76 return; // Nothing changed.
72 77
73 StopAnimating(); 78 StopAnimating();
74 79
80 visible_ = visible;
75 TargetBounds target_bounds; 81 TargetBounds target_bounds;
76 float target_opacity = visible ? 1.0f : 0.0f; 82 float target_opacity = visible ? 1.0f : 0.0f;
77 CalculateTargetBounds(visible, &target_bounds); 83 CalculateTargetBounds(visible, &target_bounds);
78 AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); 84
79 AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); 85 ui::ScopedLayerAnimationSettings launcher_animation_setter(
80 animating_ = true; 86 launcher_layer->GetAnimator());
81 // |visible_| is updated once the animation completes. 87 ui::ScopedLayerAnimationSettings status_animation_setter(
88 status_layer->GetAnimator());
89
90 launcher_animation_setter.AddObserver(this);
91 status_animation_setter.AddObserver(this);
92
93 launcher_layer->SetBounds(target_bounds.launcher_bounds);
94 launcher_layer->SetOpacity(target_opacity);
95 status_layer->SetBounds(target_bounds.status_bounds);
96 status_layer->SetOpacity(target_opacity);
82 } 97 }
83 98
84 //////////////////////////////////////////////////////////////////////////////// 99 ////////////////////////////////////////////////////////////////////////////////
85 // ShelfLayoutManager, aura::LayoutManager implementation: 100 // ShelfLayoutManager, aura::LayoutManager implementation:
86 101
87 void ShelfLayoutManager::OnWindowResized() { 102 void ShelfLayoutManager::OnWindowResized() {
88 LayoutShelf(); 103 LayoutShelf();
89 } 104 }
90 105
91 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { 106 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
(...skipping 10 matching lines...) Expand all
102 const gfx::Rect& requested_bounds) { 117 const gfx::Rect& requested_bounds) {
103 SetChildBoundsDirect(child, requested_bounds); 118 SetChildBoundsDirect(child, requested_bounds);
104 if (!in_layout_) 119 if (!in_layout_)
105 LayoutShelf(); 120 LayoutShelf();
106 } 121 }
107 122
108 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
109 // ShelfLayoutManager, private: 124 // ShelfLayoutManager, private:
110 125
111 void ShelfLayoutManager::StopAnimating() { 126 void ShelfLayoutManager::StopAnimating() {
112 if (animating_) { 127 StopObservingImplicitAnimations();
113 animating_ = false;
114 visible_ = !visible_;
115 }
116 GetLayer(launcher_)->GetAnimator()->StopAnimating(); 128 GetLayer(launcher_)->GetAnimator()->StopAnimating();
117 GetLayer(status_)->GetAnimator()->StopAnimating(); 129 GetLayer(status_)->GetAnimator()->StopAnimating();
118 } 130 }
119 131
120 void ShelfLayoutManager::CalculateTargetBounds(bool visible, 132 void ShelfLayoutManager::CalculateTargetBounds(bool visible,
121 TargetBounds* target_bounds) { 133 TargetBounds* target_bounds) {
122 const gfx::Rect& available_bounds(aura::RootWindow::GetInstance()->bounds()); 134 const gfx::Rect& available_bounds(aura::RootWindow::GetInstance()->bounds());
123 int y = available_bounds.bottom() - (visible ? max_height_ : 0); 135 int y = available_bounds.bottom() - (visible ? max_height_ : 0);
124 gfx::Rect status_bounds(status_->GetWindowScreenBounds()); 136 gfx::Rect status_bounds(status_->GetWindowScreenBounds());
125 target_bounds->status_bounds = gfx::Rect( 137 target_bounds->status_bounds = gfx::Rect(
126 available_bounds.right() - status_bounds.width(), 138 available_bounds.right() - status_bounds.width(),
127 y + (max_height_ - status_bounds.height()) / 2, 139 y + (max_height_ - status_bounds.height()) / 2,
128 status_bounds.width(), status_bounds.height()); 140 status_bounds.width(), status_bounds.height());
129 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); 141 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds());
130 target_bounds->launcher_bounds = gfx::Rect( 142 target_bounds->launcher_bounds = gfx::Rect(
131 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, 143 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2,
132 available_bounds.width(), 144 available_bounds.width(),
133 launcher_bounds.height()); 145 launcher_bounds.height());
134 if (visible) 146 if (visible)
135 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); 147 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0);
136 } 148 }
137 149
138 void ShelfLayoutManager::AnimateWidgetTo(views::Widget* widget, 150 void ShelfLayoutManager::OnImplicitAnimationsCompleted() {
139 const gfx::Rect& target_bounds,
140 float target_opacity) {
141 ui::Layer* layer = GetLayer(widget);
142 ui::ScopedLayerAnimationSettings animation_setter(layer->GetAnimator());
143 // Don't go through the widget, otherwise we end up back in SetChildBounds and
144 // cancel the animation/layout.
145 layer->SetBounds(target_bounds);
146 layer->SetOpacity(target_opacity);
147 }
148
149 void ShelfLayoutManager::OnLayerAnimationEnded(
150 const ui::LayerAnimationSequence* sequence) {
151 if (!animating_)
152 return;
153 animating_ = false;
154 visible_ = !visible_;
155 TargetBounds target_bounds; 151 TargetBounds target_bounds;
156 CalculateTargetBounds(visible_, &target_bounds); 152 CalculateTargetBounds(visible_, &target_bounds);
157 aura::RootWindow::GetInstance()->screen()->set_work_area_insets( 153 aura::RootWindow::GetInstance()->screen()->set_work_area_insets(
158 target_bounds.work_area_insets); 154 target_bounds.work_area_insets);
159 } 155 }
160 156
161 } // namespace internal 157 } // namespace internal
162 } // namespace ash 158 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/shelf_layout_manager.h ('k') | ash/wm/system_modal_container_layout_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698