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

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

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