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

Side by Side Diff: ash/shelf/shelf_widget.cc

Issue 1907363004: (Merge to M-51) Revise the shelf alignment locking mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 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/shelf/shelf_view_unittest.cc ('k') | ash/shelf/shelf_widget_unittest.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 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/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/focus_cycler.h" 8 #include "ash/focus_cycler.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/session/session_state_delegate.h" 10 #include "ash/session/session_state_delegate.h"
11 #include "ash/shelf/shelf_constants.h" 11 #include "ash/shelf/shelf_constants.h"
12 #include "ash/shelf/shelf_delegate.h" 12 #include "ash/shelf/shelf_delegate.h"
13 #include "ash/shelf/shelf_layout_manager.h" 13 #include "ash/shelf/shelf_layout_manager.h"
14 #include "ash/shelf/shelf_model.h" 14 #include "ash/shelf/shelf_model.h"
15 #include "ash/shelf/shelf_navigator.h" 15 #include "ash/shelf/shelf_navigator.h"
16 #include "ash/shelf/shelf_util.h"
16 #include "ash/shelf/shelf_view.h" 17 #include "ash/shelf/shelf_view.h"
17 #include "ash/shelf/shelf_widget.h" 18 #include "ash/shelf/shelf_widget.h"
18 #include "ash/shell.h" 19 #include "ash/shell.h"
19 #include "ash/shell_window_ids.h" 20 #include "ash/shell_window_ids.h"
20 #include "ash/system/tray/system_tray_delegate.h" 21 #include "ash/system/tray/system_tray_delegate.h"
21 #include "ash/wm/status_area_layout_manager.h" 22 #include "ash/wm/status_area_layout_manager.h"
22 #include "ash/wm/window_properties.h" 23 #include "ash/wm/window_properties.h"
23 #include "ash/wm/workspace_controller.h" 24 #include "ash/wm/workspace_controller.h"
24 #include "grit/ash_resources.h" 25 #include "grit/ash_resources.h"
25 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
26 #include "ui/aura/window_event_dispatcher.h" 27 #include "ui/aura/window_event_dispatcher.h"
27 #include "ui/aura/window_observer.h" 28 #include "ui/aura/window_observer.h"
28 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
30 #include "ui/compositor/scoped_layer_animation_settings.h" 31 #include "ui/compositor/scoped_layer_animation_settings.h"
31 #include "ui/events/event_constants.h" 32 #include "ui/events/event_constants.h"
32 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/image/image_skia_operations.h" 35 #include "ui/gfx/image/image_skia_operations.h"
35 #include "ui/gfx/skbitmap_operations.h" 36 #include "ui/gfx/skbitmap_operations.h"
36 #include "ui/views/accessible_pane_view.h" 37 #include "ui/views/accessible_pane_view.h"
37 #include "ui/views/layout/fill_layout.h" 38 #include "ui/views/layout/fill_layout.h"
38 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
39 #include "ui/views/widget/widget_delegate.h" 40 #include "ui/views/widget/widget_delegate.h"
40 #include "ui/wm/core/coordinate_conversion.h" 41 #include "ui/wm/core/coordinate_conversion.h"
41 #include "ui/wm/core/easy_resize_window_targeter.h" 42 #include "ui/wm/core/easy_resize_window_targeter.h"
42 #include "ui/wm/public/activation_client.h" 43 #include "ui/wm/public/activation_client.h"
43 44
45 namespace ash {
46
44 namespace { 47 namespace {
45 // Size of black border at bottom (or side) of shelf. 48 // Size of black border at bottom (or side) of shelf.
46 const int kNumBlackPixels = 3; 49 const int kNumBlackPixels = 3;
47 // Alpha to paint dimming image with. 50 // Alpha to paint dimming image with.
48 const int kDimAlpha = 128; 51 const int kDimAlpha = 128;
49 52
50 // The time to dim and un-dim. 53 // The time to dim and un-dim.
51 const int kTimeToDimMs = 3000; // Slow in dimming. 54 const int kTimeToDimMs = 3000; // Slow in dimming.
52 const int kTimeToUnDimMs = 200; // Fast in activating. 55 const int kTimeToUnDimMs = 200; // Fast in activating.
53 56
54 // Class used to slightly dim shelf items when maximized and visible. 57 // Class used to slightly dim shelf items when maximized and visible.
55 class DimmerView : public views::View, 58 class DimmerView : public views::View,
56 public views::WidgetDelegate, 59 public views::WidgetDelegate,
57 ash::BackgroundAnimatorDelegate { 60 BackgroundAnimatorDelegate {
58 public: 61 public:
59 // If |disable_dimming_animations_for_test| is set, all alpha animations will 62 // If |disable_dimming_animations_for_test| is set, all alpha animations will
60 // be performed instantly. 63 // be performed instantly.
61 DimmerView(ash::ShelfWidget* shelf_widget, 64 DimmerView(ShelfWidget* shelf_widget,
62 bool disable_dimming_animations_for_test); 65 bool disable_dimming_animations_for_test);
63 ~DimmerView() override; 66 ~DimmerView() override;
64 67
65 // Called by |DimmerEventFilter| when the mouse |hovered| state changes. 68 // Called by |DimmerEventFilter| when the mouse |hovered| state changes.
66 void SetHovered(bool hovered); 69 void SetHovered(bool hovered);
67 70
68 // Force the dimmer to be undimmed. 71 // Force the dimmer to be undimmed.
69 void ForceUndimming(bool force); 72 void ForceUndimming(bool force);
70 73
71 // views::WidgetDelegate overrides: 74 // views::WidgetDelegate overrides:
72 views::Widget* GetWidget() override { return View::GetWidget(); } 75 views::Widget* GetWidget() override { return View::GetWidget(); }
73 const views::Widget* GetWidget() const override { return View::GetWidget(); } 76 const views::Widget* GetWidget() const override { return View::GetWidget(); }
74 77
75 // ash::BackgroundAnimatorDelegate overrides: 78 // BackgroundAnimatorDelegate overrides:
76 void UpdateBackground(int alpha) override { 79 void UpdateBackground(int alpha) override {
77 alpha_ = alpha; 80 alpha_ = alpha;
78 SchedulePaint(); 81 SchedulePaint();
79 } 82 }
80 83
81 // views::View overrides: 84 // views::View overrides:
82 void OnPaintBackground(gfx::Canvas* canvas) override; 85 void OnPaintBackground(gfx::Canvas* canvas) override;
83 86
84 // A function to test the current alpha used. 87 // A function to test the current alpha used.
85 int get_dimming_alpha_for_test() { return alpha_; } 88 int get_dimming_alpha_for_test() { return alpha_; }
(...skipping 15 matching lines...) Expand all
101 104
102 // TRUE if the mouse is inside the shelf. 105 // TRUE if the mouse is inside the shelf.
103 bool mouse_inside_; 106 bool mouse_inside_;
104 107
105 // TRUE if a touch event is inside the shelf. 108 // TRUE if a touch event is inside the shelf.
106 bool touch_inside_; 109 bool touch_inside_;
107 110
108 DISALLOW_COPY_AND_ASSIGN(DimmerEventFilter); 111 DISALLOW_COPY_AND_ASSIGN(DimmerEventFilter);
109 }; 112 };
110 113
111 // The owning shelf. 114 // The owning shelf widget.
112 ash::ShelfWidget* shelf_; 115 ShelfWidget* shelf_;
113 116
114 // The alpha to use for covering the shelf. 117 // The alpha to use for covering the shelf.
115 int alpha_; 118 int alpha_;
116 119
117 // True if the event filter claims that we should not be dimmed. 120 // True if the event filter claims that we should not be dimmed.
118 bool is_hovered_; 121 bool is_hovered_;
119 122
120 // True if someone forces us not to be dimmed (e.g. a menu is open). 123 // True if someone forces us not to be dimmed (e.g. a menu is open).
121 bool force_hovered_; 124 bool force_hovered_;
122 125
123 // True if animations should be suppressed for a test. 126 // True if animations should be suppressed for a test.
124 bool disable_dimming_animations_for_test_; 127 bool disable_dimming_animations_for_test_;
125 128
126 // The animator for the background transitions. 129 // The animator for the background transitions.
127 ash::BackgroundAnimator background_animator_; 130 BackgroundAnimator background_animator_;
128 131
129 // Notification of entering / exiting of the shelf area by mouse. 132 // Notification of entering / exiting of the shelf area by mouse.
130 std::unique_ptr<DimmerEventFilter> event_filter_; 133 std::unique_ptr<DimmerEventFilter> event_filter_;
131 134
132 DISALLOW_COPY_AND_ASSIGN(DimmerView); 135 DISALLOW_COPY_AND_ASSIGN(DimmerView);
133 }; 136 };
134 137
135 DimmerView::DimmerView(ash::ShelfWidget* shelf_widget, 138 DimmerView::DimmerView(ShelfWidget* shelf_widget,
136 bool disable_dimming_animations_for_test) 139 bool disable_dimming_animations_for_test)
137 : shelf_(shelf_widget), 140 : shelf_(shelf_widget),
138 alpha_(kDimAlpha), 141 alpha_(kDimAlpha),
139 is_hovered_(false), 142 is_hovered_(false),
140 force_hovered_(false), 143 force_hovered_(false),
141 disable_dimming_animations_for_test_(disable_dimming_animations_for_test), 144 disable_dimming_animations_for_test_(disable_dimming_animations_for_test),
142 background_animator_(this, 0, kDimAlpha) { 145 background_animator_(this, 0, kDimAlpha) {
143 event_filter_.reset(new DimmerEventFilter(this)); 146 event_filter_.reset(new DimmerEventFilter(this));
144 // Make sure it is undimmed at the beginning and then fire off the dimming 147 // Make sure it is undimmed at the beginning and then fire off the dimming
145 // animation. 148 // animation.
146 background_animator_.SetPaintsBackground(false, 149 background_animator_.SetPaintsBackground(false, BACKGROUND_CHANGE_IMMEDIATE);
147 ash::BACKGROUND_CHANGE_IMMEDIATE);
148 SetHovered(false); 150 SetHovered(false);
149 } 151 }
150 152
151 DimmerView::~DimmerView() { 153 DimmerView::~DimmerView() {
152 } 154 }
153 155
154 void DimmerView::SetHovered(bool hovered) { 156 void DimmerView::SetHovered(bool hovered) {
155 // Remember the hovered state so that we can correct the state once a 157 // Remember the hovered state so that we can correct the state once a
156 // possible force state has disappeared. 158 // possible force state has disappeared.
157 is_hovered_ = hovered; 159 is_hovered_ = hovered;
158 // Undimm also if we were forced to by e.g. an open menu. 160 // Undimm also if we were forced to by e.g. an open menu.
159 hovered |= force_hovered_; 161 hovered |= force_hovered_;
160 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); 162 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs);
161 background_animator_.SetPaintsBackground(!hovered, 163 background_animator_.SetPaintsBackground(!hovered,
162 disable_dimming_animations_for_test_ ? 164 disable_dimming_animations_for_test_
163 ash::BACKGROUND_CHANGE_IMMEDIATE : ash::BACKGROUND_CHANGE_ANIMATE); 165 ? BACKGROUND_CHANGE_IMMEDIATE
166 : BACKGROUND_CHANGE_ANIMATE);
164 } 167 }
165 168
166 void DimmerView::ForceUndimming(bool force) { 169 void DimmerView::ForceUndimming(bool force) {
167 bool previous = force_hovered_; 170 bool previous = force_hovered_;
168 force_hovered_ = force; 171 force_hovered_ = force;
169 // If the forced change does change the result we apply the change. 172 // If the forced change does change the result we apply the change.
170 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) 173 if (is_hovered_ || force_hovered_ != is_hovered_ || previous)
171 SetHovered(is_hovered_); 174 SetHovered(is_hovered_);
172 } 175 }
173 176
174 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { 177 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) {
175 SkPaint paint; 178 SkPaint paint;
176 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 179 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
177 gfx::ImageSkia shelf_background = 180 gfx::ImageSkia shelf_background =
178 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); 181 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia();
179 182
180 if (shelf_->GetAlignment() != ash::SHELF_ALIGNMENT_BOTTOM) { 183 if (!IsHorizontalAlignment(shelf_->GetAlignment())) {
181 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( 184 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
182 shelf_background, 185 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
183 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( 186 ? SkBitmapOperations::ROTATION_90_CW
184 SkBitmapOperations::ROTATION_90_CW, 187 : SkBitmapOperations::ROTATION_270_CW);
185 SkBitmapOperations::ROTATION_90_CW,
186 SkBitmapOperations::ROTATION_270_CW));
187 } 188 }
188 paint.setAlpha(alpha_); 189 paint.setAlpha(alpha_);
189 canvas->DrawImageInt(shelf_background, 190 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(),
190 0, 191 shelf_background.height(), 0, 0, width(), height(),
191 0, 192 false, paint);
192 shelf_background.width(),
193 shelf_background.height(),
194 0,
195 0,
196 width(),
197 height(),
198 false,
199 paint);
200 } 193 }
201 194
202 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) 195 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner)
203 : owner_(owner), 196 : owner_(owner),
204 mouse_inside_(false), 197 mouse_inside_(false),
205 touch_inside_(false) { 198 touch_inside_(false) {
206 ash::Shell::GetInstance()->AddPreTargetHandler(this); 199 Shell::GetInstance()->AddPreTargetHandler(this);
207 } 200 }
208 201
209 DimmerView::DimmerEventFilter::~DimmerEventFilter() { 202 DimmerView::DimmerEventFilter::~DimmerEventFilter() {
210 ash::Shell::GetInstance()->RemovePreTargetHandler(this); 203 Shell::GetInstance()->RemovePreTargetHandler(this);
211 } 204 }
212 205
213 void DimmerView::DimmerEventFilter::OnMouseEvent(ui::MouseEvent* event) { 206 void DimmerView::DimmerEventFilter::OnMouseEvent(ui::MouseEvent* event) {
214 if (event->type() != ui::ET_MOUSE_MOVED && 207 if (event->type() != ui::ET_MOUSE_MOVED &&
215 event->type() != ui::ET_MOUSE_DRAGGED) 208 event->type() != ui::ET_MOUSE_DRAGGED)
216 return; 209 return;
217 210
218 gfx::Point screen_point(event->location()); 211 gfx::Point screen_point(event->location());
219 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()), 212 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()),
220 &screen_point); 213 &screen_point);
(...skipping 11 matching lines...) Expand all
232 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()), 225 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()),
233 &screen_point); 226 &screen_point);
234 touch_inside = owner_->GetBoundsInScreen().Contains(screen_point); 227 touch_inside = owner_->GetBoundsInScreen().Contains(screen_point);
235 } 228 }
236 229
237 if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside) 230 if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside)
238 owner_->SetHovered(mouse_inside_ || touch_inside); 231 owner_->SetHovered(mouse_inside_ || touch_inside);
239 touch_inside_ = touch_inside; 232 touch_inside_ = touch_inside;
240 } 233 }
241 234
242 using ash::ShelfLayoutManager;
243
244 // ShelfWindowTargeter makes it easier to resize windows with the mouse when the 235 // ShelfWindowTargeter makes it easier to resize windows with the mouse when the
245 // window-edge slightly overlaps with the shelf edge. The targeter also makes it 236 // window-edge slightly overlaps with the shelf edge. The targeter also makes it
246 // easier to drag the shelf out with touch while it is hidden. 237 // easier to drag the shelf out with touch while it is hidden.
247 class ShelfWindowTargeter : public wm::EasyResizeWindowTargeter, 238 class ShelfWindowTargeter : public ::wm::EasyResizeWindowTargeter,
248 public ash::ShelfLayoutManagerObserver { 239 public ShelfLayoutManagerObserver {
249 public: 240 public:
250 ShelfWindowTargeter(aura::Window* container, 241 ShelfWindowTargeter(aura::Window* container, ShelfLayoutManager* shelf)
251 ShelfLayoutManager* shelf) 242 : ::wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()),
252 : wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()),
253 shelf_(shelf) { 243 shelf_(shelf) {
254 WillChangeVisibilityState(shelf_->visibility_state()); 244 WillChangeVisibilityState(shelf_->visibility_state());
255 shelf_->AddObserver(this); 245 shelf_->AddObserver(this);
256 } 246 }
257 247
258 ~ShelfWindowTargeter() override { 248 ~ShelfWindowTargeter() override {
259 // |shelf_| may have been destroyed by this time. 249 // |shelf_| may have been destroyed by this time.
260 if (shelf_) 250 if (shelf_)
261 shelf_->RemoveObserver(this); 251 shelf_->RemoveObserver(this);
262 } 252 }
263 253
264 private: 254 private:
265 gfx::Insets GetInsetsForAlignment(int distance, 255 gfx::Insets GetInsetsForAlignment(int distance, ShelfAlignment alignment) {
266 ash::ShelfAlignment alignment) { 256 if (alignment == SHELF_ALIGNMENT_LEFT)
267 switch (alignment) { 257 return gfx::Insets(0, 0, 0, distance);
268 case ash::SHELF_ALIGNMENT_BOTTOM: 258 if (alignment == SHELF_ALIGNMENT_RIGHT)
269 return gfx::Insets(distance, 0, 0, 0); 259 return gfx::Insets(0, distance, 0, 0);
270 case ash::SHELF_ALIGNMENT_LEFT: 260 return gfx::Insets(distance, 0, 0, 0);
271 return gfx::Insets(0, 0, 0, distance);
272 case ash::SHELF_ALIGNMENT_RIGHT:
273 return gfx::Insets(0, distance, 0, 0);
274 }
275 NOTREACHED();
276 return gfx::Insets();
277 } 261 }
278 262
279 // ash::ShelfLayoutManagerObserver: 263 // ShelfLayoutManagerObserver:
280 void WillDeleteShelf() override { 264 void WillDeleteShelf() override {
281 shelf_->RemoveObserver(this); 265 shelf_->RemoveObserver(this);
282 shelf_ = NULL; 266 shelf_ = NULL;
283 } 267 }
284 268
285 void WillChangeVisibilityState(ash::ShelfVisibilityState new_state) override { 269 void WillChangeVisibilityState(ShelfVisibilityState new_state) override {
286 gfx::Insets mouse_insets; 270 gfx::Insets mouse_insets;
287 gfx::Insets touch_insets; 271 gfx::Insets touch_insets;
288 if (new_state == ash::SHELF_VISIBLE) { 272 if (new_state == SHELF_VISIBLE) {
289 // Let clicks at the very top of the shelf through so windows can be 273 // Let clicks at the very top of the shelf through so windows can be
290 // resized with the bottom-right corner and bottom edge. 274 // resized with the bottom-right corner and bottom edge.
291 mouse_insets = GetInsetsForAlignment( 275 mouse_insets = GetInsetsForAlignment(
292 ShelfLayoutManager::kWorkspaceAreaVisibleInset, 276 ShelfLayoutManager::kWorkspaceAreaVisibleInset,
293 shelf_->GetAlignment()); 277 shelf_->GetAlignment());
294 } else if (new_state == ash::SHELF_AUTO_HIDE) { 278 } else if (new_state == SHELF_AUTO_HIDE) {
295 // Extend the touch hit target out a bit to allow users to drag shelf out 279 // Extend the touch hit target out a bit to allow users to drag shelf out
296 // while hidden. 280 // while hidden.
297 touch_insets = GetInsetsForAlignment( 281 touch_insets = GetInsetsForAlignment(
298 -ShelfLayoutManager::kWorkspaceAreaAutoHideInset, 282 -ShelfLayoutManager::kWorkspaceAreaAutoHideInset,
299 shelf_->GetAlignment()); 283 shelf_->GetAlignment());
300 } 284 }
301 285
302 set_mouse_extend(mouse_insets); 286 set_mouse_extend(mouse_insets);
303 set_touch_extend(touch_insets); 287 set_touch_extend(touch_insets);
304 } 288 }
305 289
306 ShelfLayoutManager* shelf_; 290 ShelfLayoutManager* shelf_;
307 291
308 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); 292 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter);
309 }; 293 };
310 294
311 } // namespace 295 } // namespace
312 296
313 namespace ash {
314
315 // The contents view of the Shelf. This view contains ShelfView and 297 // The contents view of the Shelf. This view contains ShelfView and
316 // sizes it to the width of the shelf minus the size of the status area. 298 // sizes it to the width of the shelf minus the size of the status area.
317 class ShelfWidget::DelegateView : public views::WidgetDelegate, 299 class ShelfWidget::DelegateView : public views::WidgetDelegate,
318 public views::AccessiblePaneView, 300 public views::AccessiblePaneView,
319 public BackgroundAnimatorDelegate, 301 public BackgroundAnimatorDelegate,
320 public aura::WindowObserver { 302 public aura::WindowObserver {
321 public: 303 public:
322 explicit DelegateView(ShelfWidget* shelf); 304 explicit DelegateView(ShelfWidget* shelf);
323 ~DelegateView() override; 305 ~DelegateView() override;
324 306
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { 442 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) {
461 layer->Add(&opaque_background_); 443 layer->Add(&opaque_background_);
462 layer->Add(&opaque_foreground_); 444 layer->Add(&opaque_foreground_);
463 ReorderLayers(); 445 ReorderLayers();
464 } 446 }
465 447
466 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { 448 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
467 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 449 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
468 gfx::ImageSkia shelf_background = 450 gfx::ImageSkia shelf_background =
469 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); 451 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
470 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) 452 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment());
453 if (!horizontal) {
471 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( 454 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
472 shelf_background, 455 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
473 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( 456 ? SkBitmapOperations::ROTATION_90_CW
474 SkBitmapOperations::ROTATION_90_CW, 457 : SkBitmapOperations::ROTATION_270_CW);
475 SkBitmapOperations::ROTATION_90_CW, 458 }
476 SkBitmapOperations::ROTATION_270_CW));
477 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); 459 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds());
478 SkPaint paint; 460 SkPaint paint;
479 paint.setAlpha(alpha_); 461 paint.setAlpha(alpha_);
480 canvas->DrawImageInt(shelf_background, 462 canvas->DrawImageInt(
481 0, 463 shelf_background, 0, 0, shelf_background.width(),
482 0, 464 shelf_background.height(),
483 shelf_background.width(), 465 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0)
484 shelf_background.height(), 466 ? dock_bounds.width()
485 (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() && 467 : 0,
486 dock_bounds.x() == 0 && dock_bounds.width() > 0) 468 0, horizontal ? width() - dock_bounds.width() : width(), height(), false,
487 ? dock_bounds.width() 469 paint);
488 : 0, 470 if (horizontal && dock_bounds.width() > 0) {
489 0,
490 SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment()
491 ? width() - dock_bounds.width()
492 : width(),
493 height(),
494 false,
495 paint);
496 if (SHELF_ALIGNMENT_BOTTOM == shelf_->GetAlignment() &&
497 dock_bounds.width() > 0) {
498 // The part of the shelf background that is in the corner below the docked 471 // The part of the shelf background that is in the corner below the docked
499 // windows close to the work area is an arched gradient that blends 472 // windows close to the work area is an arched gradient that blends
500 // vertically oriented docked background and horizontal shelf. 473 // vertically oriented docked background and horizontal shelf.
501 gfx::ImageSkia shelf_corner = *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER); 474 gfx::ImageSkia shelf_corner = *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER);
502 if (dock_bounds.x() == 0) { 475 if (dock_bounds.x() == 0) {
503 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage( 476 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
504 shelf_corner, SkBitmapOperations::ROTATION_90_CW); 477 shelf_corner, SkBitmapOperations::ROTATION_90_CW);
505 } 478 }
506 canvas->DrawImageInt( 479 canvas->DrawImageInt(
507 shelf_corner, 480 shelf_corner, 0, 0, shelf_corner.width(), shelf_corner.height(),
508 0,
509 0,
510 shelf_corner.width(),
511 shelf_corner.height(),
512 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(), 481 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(),
513 0, 482 0, height(), height(), false, paint);
514 height(),
515 height(),
516 false,
517 paint);
518 // The part of the shelf background that is just below the docked windows 483 // The part of the shelf background that is just below the docked windows
519 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. 484 // is drawn using the last (lowest) 1-pixel tall strip of the image asset.
520 // This avoids showing the border 3D shadow between the shelf and the dock. 485 // This avoids showing the border 3D shadow between the shelf and the dock.
521 canvas->DrawImageInt(shelf_background, 486 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1,
522 0, 487 shelf_background.width(), 1,
523 shelf_background.height() - 1,
524 shelf_background.width(),
525 1,
526 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, 488 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0,
527 0, 489 0, dock_bounds.width() - height(), height(), false,
528 dock_bounds.width() - height(),
529 height(),
530 false,
531 paint); 490 paint);
532 } 491 }
533 gfx::Rect black_rect = 492 gfx::Rect black_rect =
534 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( 493 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment(
535 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), 494 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels),
536 gfx::Rect(0, 0, kNumBlackPixels, height()), 495 gfx::Rect(0, 0, kNumBlackPixels, height()),
537 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height())); 496 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()));
538 canvas->FillRect(black_rect, SK_ColorBLACK); 497 canvas->FillRect(black_rect, SK_ColorBLACK);
539 } 498 }
540 499
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 case user::LOGGED_IN_NONE: 680 case user::LOGGED_IN_NONE:
722 return false; 681 return false;
723 } 682 }
724 683
725 NOTREACHED(); 684 NOTREACHED();
726 return false; 685 return false;
727 } 686 }
728 687
729 ShelfAlignment ShelfWidget::GetAlignment() const { 688 ShelfAlignment ShelfWidget::GetAlignment() const {
730 // TODO(msw): This should not be called before |shelf_| is created. 689 // TODO(msw): This should not be called before |shelf_| is created.
731 return shelf_ ? shelf_->GetAlignment() : SHELF_ALIGNMENT_BOTTOM; 690 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED;
732 } 691 }
733 692
734 void ShelfWidget::OnShelfAlignmentChanged() { 693 void ShelfWidget::OnShelfAlignmentChanged() {
735 status_area_widget_->SetShelfAlignment(GetAlignment()); 694 status_area_widget_->SetShelfAlignment(GetAlignment());
736 delegate_view_->SchedulePaint(); 695 delegate_view_->SchedulePaint();
737 } 696 }
738 697
739 void ShelfWidget::SetDimsShelf(bool dimming) { 698 void ShelfWidget::SetDimsShelf(bool dimming) {
740 delegate_view_->SetDimmed(dimming); 699 delegate_view_->SetDimmed(dimming);
741 // Repaint all children, allowing updates to reflect dimmed state eg: 700 // Repaint all children, allowing updates to reflect dimmed state eg:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 DCHECK(delegate_view_); 785 DCHECK(delegate_view_);
827 return delegate_view_->disable_dimming_animations_for_test(); 786 return delegate_view_->disable_dimming_animations_for_test();
828 } 787 }
829 788
830 void ShelfWidget::WillDeleteShelf() { 789 void ShelfWidget::WillDeleteShelf() {
831 shelf_layout_manager_->RemoveObserver(this); 790 shelf_layout_manager_->RemoveObserver(this);
832 shelf_layout_manager_ = NULL; 791 shelf_layout_manager_ = NULL;
833 } 792 }
834 793
835 } // namespace ash 794 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view_unittest.cc ('k') | ash/shelf/shelf_widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698