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

Side by Side Diff: ash/common/wm/dock/docked_window_layout_manager.cc

Issue 2053113002: Replaced BackgroundAnimator with ShelfBackgroundAnimator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into animate_shelf_chip_backgrounds Created 4 years, 4 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
« no previous file with comments | « ash/common/wm/background_animator.cc ('k') | ash/root_window_controller.cc » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/wm/dock/docked_window_layout_manager.h" 5 #include "ash/common/wm/dock/docked_window_layout_manager.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/shelf_background_animator.h"
9 #include "ash/common/shelf/shelf_background_animator_observer.h"
8 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
9 #include "ash/common/shelf/wm_shelf.h" 11 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/shelf/wm_shelf_observer.h" 12 #include "ash/common/shelf/wm_shelf_observer.h"
11 #include "ash/common/shell_window_ids.h" 13 #include "ash/common/shell_window_ids.h"
12 #include "ash/common/wm/overview/window_selector_controller.h" 14 #include "ash/common/wm/overview/window_selector_controller.h"
13 #include "ash/common/wm/window_animation_types.h" 15 #include "ash/common/wm/window_animation_types.h"
14 #include "ash/common/wm/window_parenting_utils.h" 16 #include "ash/common/wm/window_parenting_utils.h"
15 #include "ash/common/wm/window_resizer.h" 17 #include "ash/common/wm/window_resizer.h"
16 #include "ash/common/wm/window_state.h" 18 #include "ash/common/wm/window_state.h"
17 #include "ash/common/wm_lookup.h" 19 #include "ash/common/wm_lookup.h"
(...skipping 23 matching lines...) Expand all
41 // static 43 // static
42 const int DockedWindowLayoutManager::kMinDockGap = 2; 44 const int DockedWindowLayoutManager::kMinDockGap = 2;
43 // static 45 // static
44 const int DockedWindowLayoutManager::kIdealWidth = 250; 46 const int DockedWindowLayoutManager::kIdealWidth = 250;
45 const int kMinimumHeight = 250; 47 const int kMinimumHeight = 250;
46 const int kSlideDurationMs = 120; 48 const int kSlideDurationMs = 120;
47 const int kFadeDurationMs = 60; 49 const int kFadeDurationMs = 60;
48 const int kMinimizeDurationMs = 720; 50 const int kMinimizeDurationMs = 720;
49 51
50 class DockedBackgroundWidget : public views::Widget, 52 class DockedBackgroundWidget : public views::Widget,
51 public BackgroundAnimatorDelegate, 53 public WmShelfObserver,
52 public WmShelfObserver { 54 public ShelfBackgroundAnimatorObserver {
53 public: 55 public:
54 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) 56 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager)
55 : manager_(manager), 57 : manager_(manager),
56 alignment_(DOCKED_ALIGNMENT_NONE), 58 alignment_(DOCKED_ALIGNMENT_NONE),
57 background_animator_(this, 0, GetShelfConstant(SHELF_BACKGROUND_ALPHA)), 59 background_animator_(SHELF_BACKGROUND_DEFAULT, nullptr),
58 alpha_(0), 60 asset_background_alpha_(0),
59 opaque_background_(ui::LAYER_SOLID_COLOR), 61 opaque_background_(ui::LAYER_SOLID_COLOR),
60 visible_background_type_(manager_->shelf()->GetBackgroundType()), 62 visible_background_type_(manager_->shelf()->GetBackgroundType()),
61 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { 63 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) {
62 manager_->shelf()->AddObserver(this); 64 manager_->shelf()->AddObserver(this);
63 InitWidget(manager_->dock_container()); 65 InitWidget(manager_->dock_container());
66
67 background_animator_.AddObserver(this);
64 } 68 }
65 69
66 ~DockedBackgroundWidget() override { 70 ~DockedBackgroundWidget() override {
71 background_animator_.RemoveObserver(this);
67 manager_->shelf()->RemoveObserver(this); 72 manager_->shelf()->RemoveObserver(this);
68 } 73 }
69 74
70 // Sets widget bounds and sizes opaque background layer to fill the widget. 75 // Sets widget bounds and sizes opaque background layer to fill the widget.
71 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) { 76 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) {
72 SetBounds(bounds); 77 SetBounds(bounds);
73 opaque_background_.SetBounds(gfx::Rect(bounds.size())); 78 opaque_background_.SetBounds(gfx::Rect(bounds.size()));
74 alignment_ = alignment; 79 alignment_ = alignment;
75 } 80 }
76 81
77 private: 82 private:
78 // views::Widget: 83 // views::Widget:
79 void OnNativeWidgetVisibilityChanged(bool visible) override { 84 void OnNativeWidgetVisibilityChanged(bool visible) override {
80 views::Widget::OnNativeWidgetVisibilityChanged(visible); 85 views::Widget::OnNativeWidgetVisibilityChanged(visible);
81 UpdateBackground(); 86 UpdateBackground();
82 } 87 }
83 88
84 void OnNativeWidgetPaint(const ui::PaintContext& context) override { 89 void OnNativeWidgetPaint(const ui::PaintContext& context) override {
85 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size()); 90 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size());
86 ui::PaintRecorder recorder(context, local_window_bounds.size()); 91 ui::PaintRecorder recorder(context, local_window_bounds.size());
87 92
88 if (MaterialDesignController::IsShelfMaterial()) { 93 if (!MaterialDesignController::IsShelfMaterial()) {
89 recorder.canvas()->FillRect(local_window_bounds,
90 SkColorSetA(kShelfBaseColor, alpha_));
91 } else {
92 const gfx::ImageSkia& shelf_background(alignment_ == DOCKED_ALIGNMENT_LEFT 94 const gfx::ImageSkia& shelf_background(alignment_ == DOCKED_ALIGNMENT_LEFT
93 ? shelf_background_left_ 95 ? shelf_background_left_
94 : shelf_background_right_); 96 : shelf_background_right_);
95 SkPaint paint; 97 SkPaint paint;
96 paint.setAlpha(alpha_); 98 paint.setAlpha(asset_background_alpha_);
97 recorder.canvas()->DrawImageInt( 99 recorder.canvas()->DrawImageInt(
98 shelf_background, 0, 0, shelf_background.width(), 100 shelf_background, 0, 0, shelf_background.width(),
99 shelf_background.height(), 101 shelf_background.height(),
100 alignment_ == DOCKED_ALIGNMENT_LEFT 102 alignment_ == DOCKED_ALIGNMENT_LEFT
101 ? local_window_bounds.width() - shelf_background.width() 103 ? local_window_bounds.width() - shelf_background.width()
102 : 0, 104 : 0,
103 0, shelf_background.width(), local_window_bounds.height(), false, 105 0, shelf_background.width(), local_window_bounds.height(), false,
104 paint); 106 paint);
105 recorder.canvas()->DrawImageInt( 107 recorder.canvas()->DrawImageInt(
106 shelf_background, 108 shelf_background,
107 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 109 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0
108 : shelf_background.width() - 1, 110 : shelf_background.width() - 1,
109 0, 1, shelf_background.height(), 111 0, 1, shelf_background.height(),
110 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width(), 0, 112 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width(), 0,
111 local_window_bounds.width() - shelf_background.width(), 113 local_window_bounds.width() - shelf_background.width(),
112 local_window_bounds.height(), false, paint); 114 local_window_bounds.height(), false, paint);
113 } 115 }
114 } 116 }
115 117
116 // BackgroundAnimatorDelegate: 118 // ShelfBackgroundAnimatorObserver:
117 void UpdateBackground(int alpha) override { 119 void UpdateShelfOpaqueBackground(int alpha) override {
118 alpha_ = alpha; 120 const float kMaxAlpha = 255.0f;
121 opaque_background_.SetOpacity(alpha / kMaxAlpha);
122 }
123
124 void UpdateShelfAssetBackground(int alpha) override {
125 asset_background_alpha_ = alpha;
119 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); 126 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
120 } 127 }
121 128
122 // ShelfLayoutManagerObserver: 129 // WmShelfObserver:
123 void OnBackgroundUpdated(ShelfBackgroundType background_type, 130 void OnBackgroundTypeChanged(
124 BackgroundAnimatorChangeType change_type) override { 131 ShelfBackgroundType background_type,
132 BackgroundAnimatorChangeType change_type) override {
125 // Sets the background type. Starts an animation to transition to 133 // Sets the background type. Starts an animation to transition to
126 // |background_type| if the widget is visible. If the widget is not visible, 134 // |background_type| if the widget is visible. If the widget is not visible,
127 // the animation is postponed till the widget becomes visible. 135 // the animation is postponed till the widget becomes visible.
128 visible_background_type_ = background_type; 136 visible_background_type_ = background_type;
129 visible_background_change_type_ = change_type; 137 visible_background_change_type_ = change_type;
130 if (IsVisible()) 138 if (IsVisible())
131 UpdateBackground(); 139 UpdateBackground();
132 } 140 }
133 141
134 void InitWidget(WmWindow* parent) { 142 void InitWidget(WmWindow* parent) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 176 }
169 177
170 // Transitions to |visible_background_type_| if the widget is visible and to 178 // Transitions to |visible_background_type_| if the widget is visible and to
171 // SHELF_BACKGROUND_DEFAULT if it is not. 179 // SHELF_BACKGROUND_DEFAULT if it is not.
172 void UpdateBackground() { 180 void UpdateBackground() {
173 ShelfBackgroundType background_type = 181 ShelfBackgroundType background_type =
174 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; 182 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT;
175 BackgroundAnimatorChangeType change_type = 183 BackgroundAnimatorChangeType change_type =
176 IsVisible() ? visible_background_change_type_ 184 IsVisible() ? visible_background_change_type_
177 : BACKGROUND_CHANGE_IMMEDIATE; 185 : BACKGROUND_CHANGE_IMMEDIATE;
178 186 background_animator_.PaintBackground(background_type, change_type);
179 float target_opacity =
180 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f;
181 std::unique_ptr<ui::ScopedLayerAnimationSettings>
182 opaque_background_animation;
183 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) {
184 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings(
185 opaque_background_.GetAnimator()));
186 opaque_background_animation->SetTransitionDuration(
187 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs));
188 }
189 opaque_background_.SetOpacity(target_opacity);
190
191 // TODO(varkha): use ui::Layer on both opaque_background and normal
192 // background retire background_animator_ at all. It would be simpler.
193 // See also ShelfWidget::SetPaintsBackground.
194 background_animator_.SetPaintsBackground(
195 background_type != SHELF_BACKGROUND_DEFAULT, change_type);
196 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); 187 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
197 } 188 }
198 189
199 DockedWindowLayoutManager* manager_; 190 DockedWindowLayoutManager* manager_;
200 191
201 DockedAlignment alignment_; 192 DockedAlignment alignment_;
202 193
203 // The animator for the background transitions. 194 // The animator for the background transitions.
204 BackgroundAnimator background_animator_; 195 ShelfBackgroundAnimator background_animator_;
205 196
206 // The alpha to use for drawing image assets covering the docked background. 197 // The alpha to use for drawing image assets covering the docked background.
207 int alpha_; 198 int asset_background_alpha_;
208 199
200 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551).
209 // Solid black background that can be made fully opaque. 201 // Solid black background that can be made fully opaque.
210 ui::Layer opaque_background_; 202 ui::Layer opaque_background_;
211 203
212 // Backgrounds created from shelf background by 90 or 270 degree rotation. 204 // Backgrounds created from shelf background by 90 or 270 degree rotation.
213 // TODO(tdanderson): These members can be removed once the material design 205 // TODO(tdanderson): These members can be removed once the material design
214 // shelf is enabled by default. See crbug.com/614453. 206 // shelf is enabled by default. See crbug.com/614453.
215 gfx::ImageSkia shelf_background_left_; 207 gfx::ImageSkia shelf_background_left_;
216 gfx::ImageSkia shelf_background_right_; 208 gfx::ImageSkia shelf_background_right_;
217 209
218 // The background type to use when the widget is visible. When not visible, 210 // The background type to use when the widget is visible. When not visible,
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 1364
1373 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( 1365 void DockedWindowLayoutManager::OnKeyboardBoundsChanging(
1374 const gfx::Rect& keyboard_bounds) { 1366 const gfx::Rect& keyboard_bounds) {
1375 // This bounds change will have caused a change to the Shelf which does not 1367 // This bounds change will have caused a change to the Shelf which does not
1376 // propagate automatically to this class, so manually recalculate bounds. 1368 // propagate automatically to this class, so manually recalculate bounds.
1377 Relayout(); 1369 Relayout();
1378 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); 1370 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING);
1379 } 1371 }
1380 1372
1381 } // namespace ash 1373 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/background_animator.cc ('k') | ash/root_window_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698