OLD | NEW |
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" | |
34 #include "ui/views/background.h" | 30 #include "ui/views/background.h" |
35 | 31 |
36 namespace ash { | 32 namespace ash { |
37 | 33 |
38 // Minimum, maximum width of the dock area and a width of the gap | 34 // Minimum, maximum width of the dock area and a width of the gap |
39 // static | 35 // static |
40 const int DockedWindowLayoutManager::kMaxDockWidth = 360; | 36 const int DockedWindowLayoutManager::kMaxDockWidth = 360; |
41 // static | 37 // static |
42 const int DockedWindowLayoutManager::kMinDockWidth = 200; | 38 const int DockedWindowLayoutManager::kMinDockWidth = 200; |
43 // static | 39 // static |
44 const int DockedWindowLayoutManager::kMinDockGap = 2; | 40 const int DockedWindowLayoutManager::kMinDockGap = 2; |
45 // static | 41 // static |
46 const int DockedWindowLayoutManager::kIdealWidth = 250; | 42 const int DockedWindowLayoutManager::kIdealWidth = 250; |
47 const int kMinimumHeight = 250; | 43 const int kMinimumHeight = 250; |
48 const int kSlideDurationMs = 120; | 44 const int kSlideDurationMs = 120; |
49 const int kFadeDurationMs = 60; | 45 const int kFadeDurationMs = 60; |
50 const int kMinimizeDurationMs = 720; | 46 const int kMinimizeDurationMs = 720; |
51 | 47 |
52 class DockedBackgroundWidget : public views::Widget, | 48 class DockedBackgroundWidget : public views::Widget, |
53 public WmShelfObserver, | 49 public WmShelfObserver, |
54 public ShelfBackgroundAnimatorObserver { | 50 public ShelfBackgroundAnimatorObserver { |
55 public: | 51 public: |
56 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) | 52 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) |
57 : manager_(manager), | 53 : manager_(manager), |
58 alignment_(DOCKED_ALIGNMENT_NONE), | 54 alignment_(DOCKED_ALIGNMENT_NONE), |
59 background_animator_(SHELF_BACKGROUND_DEFAULT, nullptr), | 55 background_animator_(SHELF_BACKGROUND_DEFAULT, nullptr), |
60 asset_background_alpha_(0), | |
61 opaque_background_(ui::LAYER_SOLID_COLOR), | 56 opaque_background_(ui::LAYER_SOLID_COLOR), |
62 visible_background_type_(manager_->shelf()->GetBackgroundType()), | 57 visible_background_type_(manager_->shelf()->GetBackgroundType()), |
63 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { | 58 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { |
64 manager_->shelf()->AddObserver(this); | 59 manager_->shelf()->AddObserver(this); |
65 InitWidget(manager_->dock_container()); | 60 InitWidget(manager_->dock_container()); |
66 | 61 |
67 background_animator_.AddObserver(this); | 62 background_animator_.AddObserver(this); |
68 } | 63 } |
69 | 64 |
70 ~DockedBackgroundWidget() override { | 65 ~DockedBackgroundWidget() override { |
71 background_animator_.RemoveObserver(this); | 66 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 { | |
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 flags; | |
98 flags.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 flags); | |
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, flags); | |
115 } | |
116 } | |
117 | |
118 // ShelfBackgroundAnimatorObserver: | 84 // ShelfBackgroundAnimatorObserver: |
119 void UpdateShelfOpaqueBackground(int alpha) override { | 85 void UpdateShelfOpaqueBackground(int alpha) override { |
120 const float kMaxAlpha = 255.0f; | 86 const float kMaxAlpha = 255.0f; |
121 opaque_background_.SetOpacity(alpha / kMaxAlpha); | 87 opaque_background_.SetOpacity(alpha / kMaxAlpha); |
122 } | 88 } |
123 | 89 |
124 void UpdateShelfAssetBackground(int alpha) override { | |
125 asset_background_alpha_ = alpha; | |
126 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | |
127 } | |
128 | |
129 // WmShelfObserver: | 90 // WmShelfObserver: |
130 void OnBackgroundTypeChanged( | 91 void OnBackgroundTypeChanged( |
131 ShelfBackgroundType background_type, | 92 ShelfBackgroundType background_type, |
132 BackgroundAnimatorChangeType change_type) override { | 93 BackgroundAnimatorChangeType change_type) override { |
133 // Sets the background type. Starts an animation to transition to | 94 // Sets the background type. Starts an animation to transition to |
134 // |background_type| if the widget is visible. If the widget is not visible, | 95 // |background_type| if the widget is visible. If the widget is not visible, |
135 // the animation is postponed till the widget becomes visible. | 96 // the animation is postponed till the widget becomes visible. |
136 visible_background_type_ = background_type; | 97 visible_background_type_ = background_type; |
137 visible_background_change_type_ = change_type; | 98 visible_background_change_type_ = change_type; |
138 if (IsVisible()) | 99 if (IsVisible()) |
(...skipping 12 matching lines...) Expand all Loading... |
151 this, parent->GetShellWindowId(), ¶ms); | 112 this, parent->GetShellWindowId(), ¶ms); |
152 Init(params); | 113 Init(params); |
153 SetVisibilityChangedAnimationsEnabled(false); | 114 SetVisibilityChangedAnimationsEnabled(false); |
154 WmWindow* wm_window = WmLookup::Get()->GetWindowForWidget(this); | 115 WmWindow* wm_window = WmLookup::Get()->GetWindowForWidget(this); |
155 wm_window->SetLockedToRoot(true); | 116 wm_window->SetLockedToRoot(true); |
156 opaque_background_.SetColor(SK_ColorBLACK); | 117 opaque_background_.SetColor(SK_ColorBLACK); |
157 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); | 118 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); |
158 opaque_background_.SetOpacity(0.0f); | 119 opaque_background_.SetOpacity(0.0f); |
159 wm_window->GetLayer()->Add(&opaque_background_); | 120 wm_window->GetLayer()->Add(&opaque_background_); |
160 | 121 |
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 | 122 // 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 | 123 // 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 | 124 // added to the container, and UpdateStacking only manages user windows, not |
174 // the background widget. | 125 // the background widget. |
175 parent->StackChildAtBottom(wm_window); | 126 parent->StackChildAtBottom(wm_window); |
176 } | 127 } |
177 | 128 |
178 // Transitions to |visible_background_type_| if the widget is visible and to | 129 // Transitions to |visible_background_type_| if the widget is visible and to |
179 // SHELF_BACKGROUND_DEFAULT if it is not. | 130 // SHELF_BACKGROUND_DEFAULT if it is not. |
180 void UpdateBackground() { | 131 void UpdateBackground() { |
181 ShelfBackgroundType background_type = | 132 ShelfBackgroundType background_type = |
182 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; | 133 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT; |
183 BackgroundAnimatorChangeType change_type = | 134 BackgroundAnimatorChangeType change_type = |
184 IsVisible() ? visible_background_change_type_ | 135 IsVisible() ? visible_background_change_type_ |
185 : BACKGROUND_CHANGE_IMMEDIATE; | 136 : BACKGROUND_CHANGE_IMMEDIATE; |
186 background_animator_.PaintBackground(background_type, change_type); | 137 background_animator_.PaintBackground(background_type, change_type); |
187 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | 138 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); |
188 } | 139 } |
189 | 140 |
190 DockedWindowLayoutManager* manager_; | 141 DockedWindowLayoutManager* manager_; |
191 | 142 |
192 DockedAlignment alignment_; | 143 DockedAlignment alignment_; |
193 | 144 |
194 // The animator for the background transitions. | 145 // The animator for the background transitions. |
195 ShelfBackgroundAnimator background_animator_; | 146 ShelfBackgroundAnimator background_animator_; |
196 | 147 |
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). | 148 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). |
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 Loading... |
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 |
OLD | NEW |