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

Side by Side Diff: ash/common/shelf/shelf_widget.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 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/material_design/material_design_controller.h"
9 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shelf/app_list_button.h" 9 #include "ash/common/shelf/app_list_button.h"
11 #include "ash/common/shelf/shelf_background_animator_observer.h" 10 #include "ash/common/shelf/shelf_background_animator_observer.h"
12 #include "ash/common/shelf/shelf_constants.h" 11 #include "ash/common/shelf/shelf_constants.h"
13 #include "ash/common/shelf/shelf_delegate.h" 12 #include "ash/common/shelf/shelf_delegate.h"
14 #include "ash/common/shelf/shelf_layout_manager.h" 13 #include "ash/common/shelf/shelf_layout_manager.h"
15 #include "ash/common/shelf/shelf_view.h" 14 #include "ash/common/shelf/shelf_view.h"
16 #include "ash/common/shelf/wm_shelf.h" 15 #include "ash/common/shelf/wm_shelf.h"
17 #include "ash/common/shelf/wm_shelf_util.h" 16 #include "ash/common/shelf/wm_shelf_util.h"
18 #include "ash/common/system/status_area_layout_manager.h" 17 #include "ash/common/system/status_area_layout_manager.h"
19 #include "ash/common/system/status_area_widget.h" 18 #include "ash/common/system/status_area_widget.h"
20 #include "ash/common/wm_lookup.h" 19 #include "ash/common/wm_lookup.h"
21 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
22 #include "ash/common/wm_window.h" 21 #include "ash/common/wm_window.h"
23 #include "ash/common/wm_window_property.h" 22 #include "ash/common/wm_window_property.h"
24 #include "ash/root_window_controller.h" 23 #include "ash/root_window_controller.h"
25 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
26 #include "grit/ash_resources.h"
27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/compositor/layer.h" 25 #include "ui/compositor/layer.h"
29 #include "ui/compositor/scoped_layer_animation_settings.h" 26 #include "ui/compositor/scoped_layer_animation_settings.h"
30 #include "ui/gfx/canvas.h"
31 #include "ui/gfx/image/image.h"
32 #include "ui/gfx/image/image_skia_operations.h"
33 #include "ui/gfx/skbitmap_operations.h" 27 #include "ui/gfx/skbitmap_operations.h"
34 #include "ui/views/accessible_pane_view.h" 28 #include "ui/views/accessible_pane_view.h"
35 #include "ui/views/layout/fill_layout.h" 29 #include "ui/views/layout/fill_layout.h"
36 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
37 #include "ui/views/widget/widget_delegate.h" 31 #include "ui/views/widget/widget_delegate.h"
38 32
39 namespace ash { 33 namespace ash {
40 34
41 namespace {
42
43 // Size of black border at bottom (or side) of shelf.
44 const int kNumBlackPixels = 3;
45
46 } // namespace
47
48 // The contents view of the Shelf. This view contains ShelfView and 35 // The contents view of the Shelf. This view contains ShelfView and
49 // sizes it to the width of the shelf minus the size of the status area. 36 // sizes it to the width of the shelf minus the size of the status area.
50 class ShelfWidget::DelegateView : public views::WidgetDelegate, 37 class ShelfWidget::DelegateView : public views::WidgetDelegate,
51 public views::AccessiblePaneView, 38 public views::AccessiblePaneView,
52 public ShelfBackgroundAnimatorObserver { 39 public ShelfBackgroundAnimatorObserver {
53 public: 40 public:
54 DelegateView(WmShelf* wm_shelf, ShelfWidget* shelf); 41 DelegateView(WmShelf* wm_shelf, ShelfWidget* shelf);
55 ~DelegateView() override; 42 ~DelegateView() override;
56 43
57 void set_focus_cycler(FocusCycler* focus_cycler) { 44 void set_focus_cycler(FocusCycler* focus_cycler) {
58 focus_cycler_ = focus_cycler; 45 focus_cycler_ = focus_cycler;
59 } 46 }
60 FocusCycler* focus_cycler() { return focus_cycler_; } 47 FocusCycler* focus_cycler() { return focus_cycler_; }
61 48
62 ui::Layer* opaque_background() { return &opaque_background_; } 49 ui::Layer* opaque_background() { return &opaque_background_; }
63 ui::Layer* opaque_foreground() { return &opaque_foreground_; } 50 ui::Layer* opaque_foreground() { return &opaque_foreground_; }
64 51
65 void SetParentLayer(ui::Layer* layer); 52 void SetParentLayer(ui::Layer* layer);
66 53
67 // views::View overrides:
68 void OnPaintBackground(gfx::Canvas* canvas) override;
69
70 // views::WidgetDelegateView overrides: 54 // views::WidgetDelegateView overrides:
71 views::Widget* GetWidget() override { return View::GetWidget(); } 55 views::Widget* GetWidget() override { return View::GetWidget(); }
72 const views::Widget* GetWidget() const override { return View::GetWidget(); } 56 const views::Widget* GetWidget() const override { return View::GetWidget(); }
73 57
74 bool CanActivate() const override; 58 bool CanActivate() const override;
75 void ReorderChildLayers(ui::Layer* parent_layer) override; 59 void ReorderChildLayers(ui::Layer* parent_layer) override;
76 // This will be called when the parent local bounds change. 60 // This will be called when the parent local bounds change.
77 void OnBoundsChanged(const gfx::Rect& old_bounds) override; 61 void OnBoundsChanged(const gfx::Rect& old_bounds) override;
78 62
79 // ShelfBackgroundAnimatorObserver: 63 // ShelfBackgroundAnimatorObserver:
80 void UpdateShelfOpaqueBackground(int alpha) override; 64 void UpdateShelfOpaqueBackground(int alpha) override;
81 void UpdateShelfAssetBackground(int alpha) override;
82 65
83 private: 66 private:
84 WmShelf* wm_shelf_;
85 ShelfWidget* shelf_widget_; 67 ShelfWidget* shelf_widget_;
86 FocusCycler* focus_cycler_; 68 FocusCycler* focus_cycler_;
87 int asset_background_alpha_;
88 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551).
James Cook 2017/02/07 23:50:16 This TODO doesn't seem done. What's going on with
bruthig 2017/02/08 21:05:29 Originally I was planning to update issue 621551 a
89 // A black background layer which is shown when a maximized window is visible. 69 // A black background layer which is shown when a maximized window is visible.
90 ui::Layer opaque_background_; 70 ui::Layer opaque_background_;
91 // A black foreground layer which is shown while transitioning between users. 71 // A black foreground layer which is shown while transitioning between users.
92 // Note: Since the back- and foreground layers have different functions they 72 // Note: Since the back- and foreground layers have different functions they
93 // can be used simultaneously - so no repurposing possible. 73 // can be used simultaneously - so no repurposing possible.
94 ui::Layer opaque_foreground_; 74 ui::Layer opaque_foreground_;
95 75
96 DISALLOW_COPY_AND_ASSIGN(DelegateView); 76 DISALLOW_COPY_AND_ASSIGN(DelegateView);
97 }; 77 };
98 78
99 ShelfWidget::DelegateView::DelegateView(WmShelf* wm_shelf, 79 ShelfWidget::DelegateView::DelegateView(WmShelf* wm_shelf,
James Cook 2017/02/07 23:50:16 wm_shelf is unused? remove it?
bruthig 2017/02/08 21:05:29 Done.
100 ShelfWidget* shelf_widget) 80 ShelfWidget* shelf_widget)
101 : wm_shelf_(wm_shelf), 81 : shelf_widget_(shelf_widget),
102 shelf_widget_(shelf_widget),
103 focus_cycler_(nullptr), 82 focus_cycler_(nullptr),
104 asset_background_alpha_(0),
105 opaque_background_(ui::LAYER_SOLID_COLOR), 83 opaque_background_(ui::LAYER_SOLID_COLOR),
106 opaque_foreground_(ui::LAYER_SOLID_COLOR) { 84 opaque_foreground_(ui::LAYER_SOLID_COLOR) {
107 DCHECK(wm_shelf_);
108 DCHECK(shelf_widget_); 85 DCHECK(shelf_widget_);
109 SetLayoutManager(new views::FillLayout()); 86 SetLayoutManager(new views::FillLayout());
110 set_allow_deactivate_on_esc(true); 87 set_allow_deactivate_on_esc(true);
111 opaque_background_.SetColor(SK_ColorBLACK); 88 opaque_background_.SetColor(SK_ColorBLACK);
112 opaque_background_.SetBounds(GetLocalBounds()); 89 opaque_background_.SetBounds(GetLocalBounds());
113 opaque_background_.SetOpacity(0.0f); 90 opaque_background_.SetOpacity(0.0f);
114 opaque_foreground_.SetColor(SK_ColorBLACK); 91 opaque_foreground_.SetColor(SK_ColorBLACK);
115 opaque_foreground_.SetBounds(GetLocalBounds()); 92 opaque_foreground_.SetBounds(GetLocalBounds());
116 opaque_foreground_.SetOpacity(0.0f); 93 opaque_foreground_.SetOpacity(0.0f);
117 } 94 }
118 95
119 ShelfWidget::DelegateView::~DelegateView() {} 96 ShelfWidget::DelegateView::~DelegateView() {}
120 97
121 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { 98 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) {
122 layer->Add(&opaque_background_); 99 layer->Add(&opaque_background_);
123 layer->Add(&opaque_foreground_); 100 layer->Add(&opaque_foreground_);
124 ReorderLayers(); 101 ReorderLayers();
125 } 102 }
126 103
127 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
128 if (MaterialDesignController::IsShelfMaterial())
129 return;
130
131 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
132 gfx::ImageSkia shelf_background =
133 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
James Cook 2017/02/07 23:50:16 Thanks for remembering to remove the asset files t
134 const bool horizontal = wm_shelf_->IsHorizontalAlignment();
135 if (!horizontal) {
136 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
137 shelf_background, wm_shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
138 ? SkBitmapOperations::ROTATION_90_CW
139 : SkBitmapOperations::ROTATION_270_CW);
140 }
141 const gfx::Rect dock_bounds(
142 shelf_widget_->shelf_layout_manager()->dock_bounds());
143 cc::PaintFlags paint;
144 paint.setAlpha(asset_background_alpha_);
145 canvas->DrawImageInt(
146 shelf_background, 0, 0, shelf_background.width(),
147 shelf_background.height(),
148 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0)
149 ? dock_bounds.width()
150 : 0,
151 0, horizontal ? width() - dock_bounds.width() : width(), height(), false,
152 paint);
153 if (horizontal && dock_bounds.width() > 0) {
154 // The part of the shelf background that is in the corner below the docked
155 // windows close to the work area is an arched gradient that blends
156 // vertically oriented docked background and horizontal shelf.
157 gfx::ImageSkia shelf_corner = *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER);
158 if (dock_bounds.x() == 0) {
159 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
160 shelf_corner, SkBitmapOperations::ROTATION_90_CW);
161 }
162 canvas->DrawImageInt(
163 shelf_corner, 0, 0, shelf_corner.width(), shelf_corner.height(),
164 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(),
165 0, height(), height(), false, paint);
166 // The part of the shelf background that is just below the docked windows
167 // is drawn using the last (lowest) 1-pixel tall strip of the image asset.
168 // This avoids showing the border 3D shadow between the shelf and the
169 // dock.
170 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1,
171 shelf_background.width(), 1,
172 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0,
173 0, dock_bounds.width() - height(), height(), false,
174 paint);
175 }
176 gfx::Rect black_rect =
177 shelf_widget_->shelf_layout_manager()->SelectValueForShelfAlignment(
178 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
179 gfx::Rect(0, 0, kNumBlackPixels, height()),
180 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()));
181 canvas->FillRect(black_rect, SK_ColorBLACK);
182 }
183
184 bool ShelfWidget::DelegateView::CanActivate() const { 104 bool ShelfWidget::DelegateView::CanActivate() const {
185 // Allow to activate as fallback. 105 // Allow to activate as fallback.
186 if (shelf_widget_->activating_as_fallback_) 106 if (shelf_widget_->activating_as_fallback_)
187 return true; 107 return true;
188 // Allow to activate from the focus cycler. 108 // Allow to activate from the focus cycler.
189 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) 109 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget())
190 return true; 110 return true;
191 // Disallow activating in other cases, especially when using mouse. 111 // Disallow activating in other cases, especially when using mouse.
192 return false; 112 return false;
193 } 113 }
194 114
195 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { 115 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) {
196 views::View::ReorderChildLayers(parent_layer); 116 views::View::ReorderChildLayers(parent_layer);
197 parent_layer->StackAtBottom(&opaque_background_); 117 parent_layer->StackAtBottom(&opaque_background_);
198 parent_layer->StackAtTop(&opaque_foreground_); 118 parent_layer->StackAtTop(&opaque_foreground_);
199 } 119 }
200 120
201 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { 121 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) {
202 opaque_background_.SetBounds(GetLocalBounds()); 122 opaque_background_.SetBounds(GetLocalBounds());
203 opaque_foreground_.SetBounds(GetLocalBounds()); 123 opaque_foreground_.SetBounds(GetLocalBounds());
204 } 124 }
205 125
206 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { 126 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) {
207 const float kMaxAlpha = 255.0f; 127 const float kMaxAlpha = 255.0f;
208 opaque_background_.SetOpacity(alpha / kMaxAlpha); 128 opaque_background_.SetOpacity(alpha / kMaxAlpha);
209 } 129 }
210 130
211 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) {
212 asset_background_alpha_ = alpha;
213 SchedulePaint();
214 }
215
216 ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf) 131 ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf)
217 : wm_shelf_(wm_shelf), 132 : wm_shelf_(wm_shelf),
218 status_area_widget_(nullptr), 133 status_area_widget_(nullptr),
219 delegate_view_(new DelegateView(wm_shelf, this)), 134 delegate_view_(new DelegateView(wm_shelf, this)),
220 shelf_view_(nullptr), 135 shelf_view_(nullptr),
221 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_), 136 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_),
222 activating_as_fallback_(false) { 137 activating_as_fallback_(false) {
223 DCHECK(wm_shelf_); 138 DCHECK(wm_shelf_);
224 background_animator_.AddObserver(this); 139 background_animator_.AddObserver(this);
225 background_animator_.AddObserver(delegate_view_); 140 background_animator_.AddObserver(delegate_view_);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 if (shelf_view_) 349 if (shelf_view_)
435 shelf_view_->UpdateShelfItemBackground(alpha); 350 shelf_view_->UpdateShelfItemBackground(alpha);
436 } 351 }
437 352
438 void ShelfWidget::WillDeleteShelfLayoutManager() { 353 void ShelfWidget::WillDeleteShelfLayoutManager() {
439 shelf_layout_manager_->RemoveObserver(this); 354 shelf_layout_manager_->RemoveObserver(this);
440 shelf_layout_manager_ = nullptr; 355 shelf_layout_manager_ = nullptr;
441 } 356 }
442 357
443 } // namespace ash 358 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698