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

Side by Side Diff: ash/common/shelf/shelf_widget.cc

Issue 2679333002: [ash-md] Remove the number of animators used for the Shelf animations. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/common/shelf/shelf_widget.h" 5 #include "ash/common/shelf/shelf_widget.h"
6 6
7 #include "ash/common/focus_cycler.h" 7 #include "ash/common/focus_cycler.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/app_list_button.h" 9 #include "ash/common/shelf/app_list_button.h"
10 #include "ash/common/shelf/shelf_background_animator_observer.h" 10 #include "ash/common/shelf/shelf_background_animator_observer.h"
11 #include "ash/common/shelf/shelf_constants.h" 11 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shelf/shelf_delegate.h" 12 #include "ash/common/shelf/shelf_delegate.h"
13 #include "ash/common/shelf/shelf_layout_manager.h" 13 #include "ash/common/shelf/shelf_layout_manager.h"
14 #include "ash/common/shelf/shelf_view.h" 14 #include "ash/common/shelf/shelf_view.h"
15 #include "ash/common/shelf/wm_shelf.h" 15 #include "ash/common/shelf/wm_shelf.h"
16 #include "ash/common/shelf/wm_shelf_util.h" 16 #include "ash/common/shelf/wm_shelf_util.h"
17 #include "ash/common/system/status_area_layout_manager.h" 17 #include "ash/common/system/status_area_layout_manager.h"
18 #include "ash/common/system/status_area_widget.h" 18 #include "ash/common/system/status_area_widget.h"
19 #include "ash/common/wm_lookup.h" 19 #include "ash/common/wm_lookup.h"
20 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
21 #include "ash/common/wm_window.h" 21 #include "ash/common/wm_window.h"
22 #include "ash/common/wm_window_property.h" 22 #include "ash/common/wm_window_property.h"
23 #include "ash/root_window_controller.h" 23 #include "ash/root_window_controller.h"
24 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
25 #include "ui/compositor/layer.h" 25 #include "ui/compositor/layer.h"
26 #include "ui/compositor/scoped_layer_animation_settings.h" 26 #include "ui/compositor/scoped_layer_animation_settings.h"
27 #include "ui/gfx/animation/animation_change_type.h"
27 #include "ui/gfx/skbitmap_operations.h" 28 #include "ui/gfx/skbitmap_operations.h"
28 #include "ui/views/accessible_pane_view.h" 29 #include "ui/views/accessible_pane_view.h"
29 #include "ui/views/layout/fill_layout.h" 30 #include "ui/views/layout/fill_layout.h"
30 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
31 #include "ui/views/widget/widget_delegate.h" 32 #include "ui/views/widget/widget_delegate.h"
32 33
33 namespace ash { 34 namespace ash {
34 35
35 // The contents view of the Shelf. This view contains ShelfView and 36 // The contents view of the Shelf. This view contains ShelfView and
36 // sizes it to the width of the shelf minus the size of the status area. 37 // sizes it to the width of the shelf minus the size of the status area.
(...skipping 17 matching lines...) Expand all
54 // views::WidgetDelegateView overrides: 55 // views::WidgetDelegateView overrides:
55 views::Widget* GetWidget() override { return View::GetWidget(); } 56 views::Widget* GetWidget() override { return View::GetWidget(); }
56 const views::Widget* GetWidget() const override { return View::GetWidget(); } 57 const views::Widget* GetWidget() const override { return View::GetWidget(); }
57 58
58 bool CanActivate() const override; 59 bool CanActivate() const override;
59 void ReorderChildLayers(ui::Layer* parent_layer) override; 60 void ReorderChildLayers(ui::Layer* parent_layer) override;
60 // This will be called when the parent local bounds change. 61 // This will be called when the parent local bounds change.
61 void OnBoundsChanged(const gfx::Rect& old_bounds) override; 62 void OnBoundsChanged(const gfx::Rect& old_bounds) override;
62 63
63 // ShelfBackgroundAnimatorObserver: 64 // ShelfBackgroundAnimatorObserver:
64 void UpdateShelfOpaqueBackground(int alpha) override; 65 void UpdateShelfBackground(int alpha) override;
65 66
66 private: 67 private:
67 ShelfWidget* shelf_widget_; 68 ShelfWidget* shelf_widget_;
68 FocusCycler* focus_cycler_; 69 FocusCycler* focus_cycler_;
69 // A black background layer which is shown when a maximized window is visible. 70 // A black background layer that may be visible depending on a
71 // ShelfBackgroundAnimator.
70 ui::Layer opaque_background_; 72 ui::Layer opaque_background_;
71 // A black foreground layer which is shown while transitioning between users. 73 // A black foreground layer which is shown while transitioning between users.
72 // Note: Since the back- and foreground layers have different functions they 74 // Note: Since the back- and foreground layers have different functions they
73 // can be used simultaneously - so no repurposing possible. 75 // can be used simultaneously - so no repurposing possible.
74 ui::Layer opaque_foreground_; 76 ui::Layer opaque_foreground_;
75 77
76 DISALLOW_COPY_AND_ASSIGN(DelegateView); 78 DISALLOW_COPY_AND_ASSIGN(DelegateView);
77 }; 79 };
78 80
79 ShelfWidget::DelegateView::DelegateView(WmShelf* wm_shelf, 81 ShelfWidget::DelegateView::DelegateView(WmShelf* wm_shelf,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 views::View::ReorderChildLayers(parent_layer); 118 views::View::ReorderChildLayers(parent_layer);
117 parent_layer->StackAtBottom(&opaque_background_); 119 parent_layer->StackAtBottom(&opaque_background_);
118 parent_layer->StackAtTop(&opaque_foreground_); 120 parent_layer->StackAtTop(&opaque_foreground_);
119 } 121 }
120 122
121 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { 123 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) {
122 opaque_background_.SetBounds(GetLocalBounds()); 124 opaque_background_.SetBounds(GetLocalBounds());
123 opaque_foreground_.SetBounds(GetLocalBounds()); 125 opaque_foreground_.SetBounds(GetLocalBounds());
124 } 126 }
125 127
126 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { 128 void ShelfWidget::DelegateView::UpdateShelfBackground(int alpha) {
127 const float kMaxAlpha = 255.0f; 129 const float kMaxAlpha = 255.0f;
128 opaque_background_.SetOpacity(alpha / kMaxAlpha); 130 opaque_background_.SetOpacity(alpha / kMaxAlpha);
129 } 131 }
130 132
131 ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf) 133 ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf)
132 : wm_shelf_(wm_shelf), 134 : wm_shelf_(wm_shelf),
133 status_area_widget_(nullptr), 135 status_area_widget_(nullptr),
134 delegate_view_(new DelegateView(wm_shelf, this)), 136 delegate_view_(new DelegateView(wm_shelf, this)),
135 shelf_view_(nullptr), 137 shelf_view_(nullptr),
136 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_), 138 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_),
(...skipping 16 matching lines...) Expand all
153 // The shelf should not take focus when initially shown. 155 // The shelf should not take focus when initially shown.
154 set_focus_on_creation(false); 156 set_focus_on_creation(false);
155 SetContentsView(delegate_view_); 157 SetContentsView(delegate_view_);
156 delegate_view_->SetParentLayer(GetLayer()); 158 delegate_view_->SetParentLayer(GetLayer());
157 159
158 shelf_layout_manager_ = new ShelfLayoutManager(this, wm_shelf_); 160 shelf_layout_manager_ = new ShelfLayoutManager(this, wm_shelf_);
159 shelf_layout_manager_->AddObserver(this); 161 shelf_layout_manager_->AddObserver(this);
160 shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_)); 162 shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_));
161 background_animator_.PaintBackground( 163 background_animator_.PaintBackground(
162 shelf_layout_manager_->GetShelfBackgroundType(), 164 shelf_layout_manager_->GetShelfBackgroundType(),
163 BACKGROUND_CHANGE_IMMEDIATE); 165 gfx::ANIMATION_CHANGE_IMMEDIATE);
164 166
165 views::Widget::AddObserver(this); 167 views::Widget::AddObserver(this);
166 } 168 }
167 169
168 ShelfWidget::~ShelfWidget() { 170 ShelfWidget::~ShelfWidget() {
169 // Must call Shutdown() before destruction. 171 // Must call Shutdown() before destruction.
170 DCHECK(!status_area_widget_); 172 DCHECK(!status_area_widget_);
171 WmShell::Get()->focus_cycler()->RemoveWidget(this); 173 WmShell::Get()->focus_cycler()->RemoveWidget(this);
172 SetFocusCycler(nullptr); 174 SetFocusCycler(nullptr);
173 RemoveObserver(this); 175 RemoveObserver(this);
174 background_animator_.RemoveObserver(delegate_view_); 176 background_animator_.RemoveObserver(delegate_view_);
175 background_animator_.RemoveObserver(this); 177 background_animator_.RemoveObserver(this);
176 } 178 }
177 179
178 void ShelfWidget::CreateStatusAreaWidget(WmWindow* status_container) { 180 void ShelfWidget::CreateStatusAreaWidget(WmWindow* status_container) {
179 DCHECK(status_container); 181 DCHECK(status_container);
180 DCHECK(!status_area_widget_); 182 DCHECK(!status_area_widget_);
181 // TODO(jamescook): Move ownership to RootWindowController. 183 // TODO(jamescook): Move ownership to RootWindowController.
182 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_); 184 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_);
183 status_area_widget_->CreateTrayViews(); 185 status_area_widget_->CreateTrayViews();
184 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) 186 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted())
185 status_area_widget_->Show(); 187 status_area_widget_->Show();
186 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); 188 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_);
187 background_animator_.AddObserver(status_area_widget_); 189 background_animator_.AddObserver(status_area_widget_);
188 status_container->SetLayoutManager( 190 status_container->SetLayoutManager(
189 base::MakeUnique<StatusAreaLayoutManager>(this)); 191 base::MakeUnique<StatusAreaLayoutManager>(this));
190 } 192 }
191 193
192 void ShelfWidget::SetPaintsBackground( 194 void ShelfWidget::SetPaintsBackground(ShelfBackgroundType background_type,
193 ShelfBackgroundType background_type, 195 gfx::AnimationChangeType change_type) {
194 BackgroundAnimatorChangeType change_type) {
195 background_animator_.PaintBackground(background_type, change_type); 196 background_animator_.PaintBackground(background_type, change_type);
196 } 197 }
197 198
198 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { 199 ShelfBackgroundType ShelfWidget::GetBackgroundType() const {
199 return background_animator_.target_background_type(); 200 return background_animator_.target_background_type();
200 } 201 }
201 202
202 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { 203 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) {
203 if (IsShelfHiddenBehindBlackBar() == hide) 204 if (IsShelfHiddenBehindBlackBar() == hide)
204 return; 205 return;
(...skipping 30 matching lines...) Expand all
235 WmShell::Get()->shelf_delegate(), wm_shelf_, this); 236 WmShell::Get()->shelf_delegate(), wm_shelf_, this);
236 shelf_view_->Init(); 237 shelf_view_->Init();
237 GetContentsView()->AddChildView(shelf_view_); 238 GetContentsView()->AddChildView(shelf_view_);
238 return shelf_view_; 239 return shelf_view_;
239 } 240 }
240 241
241 void ShelfWidget::PostCreateShelf() { 242 void ShelfWidget::PostCreateShelf() {
242 SetFocusCycler(WmShell::Get()->focus_cycler()); 243 SetFocusCycler(WmShell::Get()->focus_cycler());
243 244
244 // Ensure the newly created |shelf_| gets current values. 245 // Ensure the newly created |shelf_| gets current values.
245 background_animator_.Initialize(this); 246 background_animator_.NotifyObserver(this);
246 247
247 // TODO(jamescook): The IsActiveUserSessionStarted() check may not be needed 248 // TODO(jamescook): The IsActiveUserSessionStarted() check may not be needed
248 // because the shelf is only created after the first user session is active. 249 // because the shelf is only created after the first user session is active.
249 // The ShelfView seems to always be visible after login. At the lock screen 250 // The ShelfView seems to always be visible after login. At the lock screen
250 // the shelf is hidden because its container is hidden. During auto-hide it is 251 // the shelf is hidden because its container is hidden. During auto-hide it is
251 // hidden because ShelfWidget is transparent. Some of the ShelfView visibility 252 // hidden because ShelfWidget is transparent. Some of the ShelfView visibility
252 // code could be simplified. http://crbug.com/674773 253 // code could be simplified. http://crbug.com/674773
253 shelf_view_->SetVisible( 254 shelf_view_->SetVisible(
254 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); 255 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted());
255 shelf_layout_manager_->LayoutShelf(); 256 shelf_layout_manager_->LayoutShelf();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (shelf_view_) 350 if (shelf_view_)
350 shelf_view_->UpdateShelfItemBackground(alpha); 351 shelf_view_->UpdateShelfItemBackground(alpha);
351 } 352 }
352 353
353 void ShelfWidget::WillDeleteShelfLayoutManager() { 354 void ShelfWidget::WillDeleteShelfLayoutManager() {
354 shelf_layout_manager_->RemoveObserver(this); 355 shelf_layout_manager_->RemoveObserver(this);
355 shelf_layout_manager_ = nullptr; 356 shelf_layout_manager_ = nullptr;
356 } 357 }
357 358
358 } // namespace ash 359 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698