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

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

Issue 2680113002: [ash-md] Remove non-md code from the Shelf background 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 (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"
8 #include "ash/common/shelf/shelf_background_animator.h" 7 #include "ash/common/shelf/shelf_background_animator.h"
9 #include "ash/common/shelf/shelf_background_animator_observer.h" 8 #include "ash/common/shelf/shelf_background_animator_observer.h"
10 #include "ash/common/shelf/shelf_constants.h" 9 #include "ash/common/shelf/shelf_constants.h"
11 #include "ash/common/shelf/wm_shelf.h" 10 #include "ash/common/shelf/wm_shelf.h"
12 #include "ash/common/shelf/wm_shelf_observer.h" 11 #include "ash/common/shelf/wm_shelf_observer.h"
13 #include "ash/common/wm/overview/window_selector_controller.h" 12 #include "ash/common/wm/overview/window_selector_controller.h"
14 #include "ash/common/wm/window_animation_types.h" 13 #include "ash/common/wm/window_animation_types.h"
15 #include "ash/common/wm/window_parenting_utils.h" 14 #include "ash/common/wm/window_parenting_utils.h"
16 #include "ash/common/wm/window_resizer.h" 15 #include "ash/common/wm/window_resizer.h"
17 #include "ash/common/wm/window_state.h" 16 #include "ash/common/wm/window_state.h"
18 #include "ash/common/wm_lookup.h" 17 #include "ash/common/wm_lookup.h"
19 #include "ash/common/wm_shell.h" 18 #include "ash/common/wm_shell.h"
20 #include "ash/common/wm_window.h" 19 #include "ash/common/wm_window.h"
21 #include "ash/public/cpp/shell_window_ids.h" 20 #include "ash/public/cpp/shell_window_ids.h"
22 #include "ash/root_window_controller.h" 21 #include "ash/root_window_controller.h"
23 #include "base/auto_reset.h" 22 #include "base/auto_reset.h"
24 #include "base/metrics/histogram_macros.h" 23 #include "base/metrics/histogram_macros.h"
25 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
26 #include "third_party/skia/include/core/SkColor.h" 25 #include "third_party/skia/include/core/SkColor.h"
27 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/compositor/paint_recorder.h"
29 #include "ui/compositor/scoped_layer_animation_settings.h" 27 #include "ui/compositor/scoped_layer_animation_settings.h"
30 #include "ui/display/display.h" 28 #include "ui/display/display.h"
31 #include "ui/display/screen.h" 29 #include "ui/display/screen.h"
32 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/image/image_skia_operations.h" 30 #include "ui/gfx/image/image_skia_operations.h"
James Cook 2017/02/07 23:50:16 Can this be removed?
bruthig 2017/02/08 21:05:29 Done.
34 #include "ui/views/background.h" 31 #include "ui/views/background.h"
35 32
36 namespace ash { 33 namespace ash {
37 34
38 // Minimum, maximum width of the dock area and a width of the gap 35 // Minimum, maximum width of the dock area and a width of the gap
39 // static 36 // static
40 const int DockedWindowLayoutManager::kMaxDockWidth = 360; 37 const int DockedWindowLayoutManager::kMaxDockWidth = 360;
41 // static 38 // static
42 const int DockedWindowLayoutManager::kMinDockWidth = 200; 39 const int DockedWindowLayoutManager::kMinDockWidth = 200;
43 // static 40 // static
44 const int DockedWindowLayoutManager::kMinDockGap = 2; 41 const int DockedWindowLayoutManager::kMinDockGap = 2;
45 // static 42 // static
46 const int DockedWindowLayoutManager::kIdealWidth = 250; 43 const int DockedWindowLayoutManager::kIdealWidth = 250;
47 const int kMinimumHeight = 250; 44 const int kMinimumHeight = 250;
48 const int kSlideDurationMs = 120; 45 const int kSlideDurationMs = 120;
49 const int kFadeDurationMs = 60; 46 const int kFadeDurationMs = 60;
50 const int kMinimizeDurationMs = 720; 47 const int kMinimizeDurationMs = 720;
51 48
52 class DockedBackgroundWidget : public views::Widget, 49 class DockedBackgroundWidget : public views::Widget,
53 public WmShelfObserver, 50 public WmShelfObserver,
54 public ShelfBackgroundAnimatorObserver { 51 public ShelfBackgroundAnimatorObserver {
55 public: 52 public:
56 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) 53 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager)
57 : manager_(manager), 54 : manager_(manager),
58 alignment_(DOCKED_ALIGNMENT_NONE), 55 alignment_(DOCKED_ALIGNMENT_NONE),
59 background_animator_(SHELF_BACKGROUND_DEFAULT, nullptr), 56 background_animator_(SHELF_BACKGROUND_DEFAULT, nullptr),
60 asset_background_alpha_(0),
61 opaque_background_(ui::LAYER_SOLID_COLOR), 57 opaque_background_(ui::LAYER_SOLID_COLOR),
62 visible_background_type_(manager_->shelf()->GetBackgroundType()), 58 visible_background_type_(manager_->shelf()->GetBackgroundType()),
63 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { 59 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) {
64 manager_->shelf()->AddObserver(this); 60 manager_->shelf()->AddObserver(this);
65 InitWidget(manager_->dock_container()); 61 InitWidget(manager_->dock_container());
66 62
67 background_animator_.AddObserver(this); 63 background_animator_.AddObserver(this);
68 } 64 }
69 65
70 ~DockedBackgroundWidget() override { 66 ~DockedBackgroundWidget() override {
71 background_animator_.RemoveObserver(this); 67 background_animator_.RemoveObserver(this);
72 manager_->shelf()->RemoveObserver(this); 68 manager_->shelf()->RemoveObserver(this);
73 } 69 }
74 70
75 // Sets widget bounds and sizes opaque background layer to fill the widget. 71 // Sets widget bounds and sizes opaque background layer to fill the widget.
76 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) { 72 void SetBackgroundBounds(const gfx::Rect& bounds, DockedAlignment alignment) {
77 SetBounds(bounds); 73 SetBounds(bounds);
78 opaque_background_.SetBounds(gfx::Rect(bounds.size())); 74 opaque_background_.SetBounds(gfx::Rect(bounds.size()));
79 alignment_ = alignment; 75 alignment_ = alignment;
80 } 76 }
81 77
82 private: 78 private:
83 // views::Widget: 79 // views::Widget:
84 void OnNativeWidgetVisibilityChanged(bool visible) override { 80 void OnNativeWidgetVisibilityChanged(bool visible) override {
85 views::Widget::OnNativeWidgetVisibilityChanged(visible); 81 views::Widget::OnNativeWidgetVisibilityChanged(visible);
86 UpdateBackground(); 82 UpdateBackground();
87 } 83 }
88 84
89 void OnNativeWidgetPaint(const ui::PaintContext& context) override {
90 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size());
91 ui::PaintRecorder recorder(context, local_window_bounds.size());
92
93 if (!MaterialDesignController::IsShelfMaterial()) {
94 const gfx::ImageSkia& shelf_background(alignment_ == DOCKED_ALIGNMENT_LEFT
95 ? shelf_background_left_
96 : shelf_background_right_);
97 cc::PaintFlags paint;
98 paint.setAlpha(asset_background_alpha_);
99 recorder.canvas()->DrawImageInt(
100 shelf_background, 0, 0, shelf_background.width(),
101 shelf_background.height(),
102 alignment_ == DOCKED_ALIGNMENT_LEFT
103 ? local_window_bounds.width() - shelf_background.width()
104 : 0,
105 0, shelf_background.width(), local_window_bounds.height(), false,
106 paint);
107 recorder.canvas()->DrawImageInt(
108 shelf_background,
109 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0
110 : shelf_background.width() - 1,
111 0, 1, shelf_background.height(),
112 alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width(), 0,
113 local_window_bounds.width() - shelf_background.width(),
114 local_window_bounds.height(), false, paint);
115 }
116 }
117
118 // ShelfBackgroundAnimatorObserver: 85 // ShelfBackgroundAnimatorObserver:
119 void UpdateShelfOpaqueBackground(int alpha) override { 86 void UpdateShelfOpaqueBackground(int alpha) override {
120 const float kMaxAlpha = 255.0f; 87 const float kMaxAlpha = 255.0f;
121 opaque_background_.SetOpacity(alpha / kMaxAlpha); 88 opaque_background_.SetOpacity(alpha / kMaxAlpha);
122 } 89 }
123 90
124 void UpdateShelfAssetBackground(int alpha) override {
125 asset_background_alpha_ = alpha;
126 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
127 }
128
129 // WmShelfObserver: 91 // WmShelfObserver:
130 void OnBackgroundTypeChanged( 92 void OnBackgroundTypeChanged(
131 ShelfBackgroundType background_type, 93 ShelfBackgroundType background_type,
132 BackgroundAnimatorChangeType change_type) override { 94 BackgroundAnimatorChangeType change_type) override {
133 // Sets the background type. Starts an animation to transition to 95 // Sets the background type. Starts an animation to transition to
134 // |background_type| if the widget is visible. If the widget is not visible, 96 // |background_type| if the widget is visible. If the widget is not visible,
135 // the animation is postponed till the widget becomes visible. 97 // the animation is postponed till the widget becomes visible.
136 visible_background_type_ = background_type; 98 visible_background_type_ = background_type;
137 visible_background_change_type_ = change_type; 99 visible_background_change_type_ = change_type;
138 if (IsVisible()) 100 if (IsVisible())
(...skipping 12 matching lines...) Expand all
151 this, parent->GetShellWindowId(), &params); 113 this, parent->GetShellWindowId(), &params);
152 Init(params); 114 Init(params);
153 SetVisibilityChangedAnimationsEnabled(false); 115 SetVisibilityChangedAnimationsEnabled(false);
154 WmWindow* wm_window = WmLookup::Get()->GetWindowForWidget(this); 116 WmWindow* wm_window = WmLookup::Get()->GetWindowForWidget(this);
155 wm_window->SetLockedToRoot(true); 117 wm_window->SetLockedToRoot(true);
156 opaque_background_.SetColor(SK_ColorBLACK); 118 opaque_background_.SetColor(SK_ColorBLACK);
157 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); 119 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size()));
158 opaque_background_.SetOpacity(0.0f); 120 opaque_background_.SetOpacity(0.0f);
159 wm_window->GetLayer()->Add(&opaque_background_); 121 wm_window->GetLayer()->Add(&opaque_background_);
160 122
161 if (!MaterialDesignController::IsShelfMaterial()) {
162 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
163 gfx::ImageSkia shelf_background =
164 *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
165 shelf_background_left_ = gfx::ImageSkiaOperations::CreateRotatedImage(
166 shelf_background, SkBitmapOperations::ROTATION_90_CW);
167 shelf_background_right_ = gfx::ImageSkiaOperations::CreateRotatedImage(
168 shelf_background, SkBitmapOperations::ROTATION_270_CW);
169 }
170
171 // This background should be explicitly stacked below any windows already in 123 // This background should be explicitly stacked below any windows already in
172 // the dock, otherwise the z-order is set by the order in which windows were 124 // the dock, otherwise the z-order is set by the order in which windows were
173 // added to the container, and UpdateStacking only manages user windows, not 125 // added to the container, and UpdateStacking only manages user windows, not
174 // the background widget. 126 // the background widget.
175 parent->StackChildAtBottom(wm_window); 127 parent->StackChildAtBottom(wm_window);
176 } 128 }
177 129
178 // Transitions to |visible_background_type_| if the widget is visible and to 130 // Transitions to |visible_background_type_| if the widget is visible and to
179 // SHELF_BACKGROUND_DEFAULT if it is not. 131 // SHELF_BACKGROUND_DEFAULT if it is not.
180 void UpdateBackground() { 132 void UpdateBackground() {
181 ShelfBackgroundType background_type = 133 ShelfBackgroundType background_type =
182 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; 134 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT;
183 BackgroundAnimatorChangeType change_type = 135 BackgroundAnimatorChangeType change_type =
184 IsVisible() ? visible_background_change_type_ 136 IsVisible() ? visible_background_change_type_
185 : BACKGROUND_CHANGE_IMMEDIATE; 137 : BACKGROUND_CHANGE_IMMEDIATE;
186 background_animator_.PaintBackground(background_type, change_type); 138 background_animator_.PaintBackground(background_type, change_type);
187 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); 139 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
188 } 140 }
189 141
190 DockedWindowLayoutManager* manager_; 142 DockedWindowLayoutManager* manager_;
191 143
192 DockedAlignment alignment_; 144 DockedAlignment alignment_;
193 145
194 // The animator for the background transitions. 146 // The animator for the background transitions.
195 ShelfBackgroundAnimator background_animator_; 147 ShelfBackgroundAnimator background_animator_;
196 148
197 // The alpha to use for drawing image assets covering the docked background.
198 int asset_background_alpha_;
199
200 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551).
James Cook 2017/02/07 23:50:16 ditto. It seems like the bug needs an update and t
bruthig 2017/02/08 21:05:29 Originally I was planning to update issue 621551 a
201 // Solid black background that can be made fully opaque. 149 // Solid black background that can be made fully opaque.
202 ui::Layer opaque_background_; 150 ui::Layer opaque_background_;
203 151
204 // Backgrounds created from shelf background by 90 or 270 degree rotation.
205 // TODO(tdanderson): These members can be removed once the material design
206 // shelf is enabled by default. See crbug.com/614453.
207 gfx::ImageSkia shelf_background_left_;
208 gfx::ImageSkia shelf_background_right_;
209
210 // The background type to use when the widget is visible. When not visible, 152 // The background type to use when the widget is visible. When not visible,
211 // the widget uses SHELF_BACKGROUND_DEFAULT. 153 // the widget uses SHELF_BACKGROUND_DEFAULT.
212 ShelfBackgroundType visible_background_type_; 154 ShelfBackgroundType visible_background_type_;
213 155
214 // Whether the widget should animate to |visible_background_type_|. 156 // Whether the widget should animate to |visible_background_type_|.
215 BackgroundAnimatorChangeType visible_background_change_type_; 157 BackgroundAnimatorChangeType visible_background_change_type_;
216 158
217 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget); 159 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget);
218 }; 160 };
219 161
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 const gfx::Rect& keyboard_bounds) { 1319 const gfx::Rect& keyboard_bounds) {
1378 // This bounds change will have caused a change to the Shelf which does not 1320 // This bounds change will have caused a change to the Shelf which does not
1379 // propagate automatically to this class, so manually recalculate bounds. 1321 // propagate automatically to this class, so manually recalculate bounds.
1380 Relayout(); 1322 Relayout();
1381 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); 1323 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING);
1382 } 1324 }
1383 1325
1384 void DockedWindowLayoutManager::OnKeyboardClosed() {} 1326 void DockedWindowLayoutManager::OnKeyboardClosed() {}
1385 1327
1386 } // namespace ash 1328 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698