OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/focus_cycler.h" | 7 #include "ash/focus_cycler.h" |
8 #include "ash/launcher/launcher_delegate.h" | 8 #include "ash/launcher/launcher_delegate.h" |
9 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
10 #include "ash/launcher/launcher_navigator.h" | 10 #include "ash/launcher/launcher_navigator.h" |
11 #include "ash/launcher/launcher_view.h" | 11 #include "ash/launcher/launcher_view.h" |
12 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
13 #include "ash/session_state_delegate.h" | 13 #include "ash/session_state_delegate.h" |
14 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" |
15 #include "ash/shelf/shelf_widget.h" | 15 #include "ash/shelf/shelf_widget.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
17 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
18 #include "ash/wm/property_util.h" | 18 #include "ash/wm/property_util.h" |
19 #include "ash/wm/status_area_layout_manager.h" | 19 #include "ash/wm/status_area_layout_manager.h" |
20 #include "ash/wm/window_properties.h" | 20 #include "ash/wm/window_properties.h" |
21 #include "ash/wm/workspace_controller.h" | 21 #include "ash/wm/workspace_controller.h" |
22 #include "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
23 #include "ui/aura/client/activation_client.h" | 23 #include "ui/aura/client/activation_client.h" |
24 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
26 #include "ui/aura/window_observer.h" | 26 #include "ui/aura/window_observer.h" |
27 #include "ui/base/events/event_constants.h" | 27 #include "ui/base/events/event_constants.h" |
28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
29 #include "ui/compositor/layer.h" | 29 #include "ui/compositor/layer.h" |
| 30 #include "ui/compositor/scoped_layer_animation_settings.h" |
30 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
31 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
32 #include "ui/gfx/image/image_skia_operations.h" | 33 #include "ui/gfx/image/image_skia_operations.h" |
33 #include "ui/gfx/skbitmap_operations.h" | 34 #include "ui/gfx/skbitmap_operations.h" |
34 #include "ui/views/accessible_pane_view.h" | 35 #include "ui/views/accessible_pane_view.h" |
35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
36 #include "ui/views/widget/widget_delegate.h" | 37 #include "ui/views/widget/widget_delegate.h" |
37 | 38 |
38 namespace { | 39 namespace { |
39 // Size of black border at bottom (or side) of launcher. | 40 // Size of black border at bottom (or side) of launcher. |
40 const int kNumBlackPixels = 3; | 41 const int kNumBlackPixels = 3; |
41 // Alpha to paint dimming image with. | 42 // Alpha to paint dimming image with. |
42 const int kDimAlpha = 128; | 43 const int kDimAlpha = 128; |
43 | 44 |
44 // The time to dim and un-dim. | 45 // The time to dim and un-dim. |
45 const int kTimeToDimMs = 3000; // Slow in dimming. | 46 const int kTimeToDimMs = 3000; // Slow in dimming. |
46 const int kTimeToUnDimMs = 200; // Fast in activating. | 47 const int kTimeToUnDimMs = 200; // Fast in activating. |
| 48 const int kTimeToSwitchBackgroundMs = 1000; |
47 | 49 |
48 // Class used to slightly dim shelf items when maximized and visible. | 50 // Class used to slightly dim shelf items when maximized and visible. |
49 class DimmerView : public views::View, | 51 class DimmerView : public views::View, |
50 public views::WidgetDelegate, | 52 public views::WidgetDelegate, |
51 ash::internal::BackgroundAnimatorDelegate { | 53 ash::internal::BackgroundAnimatorDelegate { |
52 public: | 54 public: |
53 // If |disable_dimming_animations_for_test| is set, all alpha animations will | 55 // If |disable_dimming_animations_for_test| is set, all alpha animations will |
54 // be performed instantly. | 56 // be performed instantly. |
55 DimmerView(ash::ShelfWidget* shelf_widget, | 57 DimmerView(ash::ShelfWidget* shelf_widget, |
56 bool disable_dimming_animations_for_test); | 58 bool disable_dimming_animations_for_test); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 explicit DelegateView(ShelfWidget* shelf); | 241 explicit DelegateView(ShelfWidget* shelf); |
240 virtual ~DelegateView(); | 242 virtual ~DelegateView(); |
241 | 243 |
242 void set_focus_cycler(internal::FocusCycler* focus_cycler) { | 244 void set_focus_cycler(internal::FocusCycler* focus_cycler) { |
243 focus_cycler_ = focus_cycler; | 245 focus_cycler_ = focus_cycler; |
244 } | 246 } |
245 internal::FocusCycler* focus_cycler() { | 247 internal::FocusCycler* focus_cycler() { |
246 return focus_cycler_; | 248 return focus_cycler_; |
247 } | 249 } |
248 | 250 |
| 251 ui::Layer* opaque_background() { return &opaque_background_; } |
| 252 |
249 // Set if the shelf area is dimmed (eg when a window is maximized). | 253 // Set if the shelf area is dimmed (eg when a window is maximized). |
250 void SetDimmed(bool dimmed); | 254 void SetDimmed(bool dimmed); |
251 bool GetDimmed() const; | 255 bool GetDimmed() const; |
252 | 256 |
253 // Set the bounds of the widget. | 257 // Set the bounds of the widget. |
254 void SetWidgetBounds(const gfx::Rect bounds); | 258 void SetWidgetBounds(const gfx::Rect bounds); |
255 | 259 |
| 260 void SetParentLayer(ui::Layer* layer); |
| 261 |
256 // views::View overrides: | 262 // views::View overrides: |
257 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; | 263 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; |
258 | 264 |
259 // views::WidgetDelegateView overrides: | 265 // views::WidgetDelegateView overrides: |
260 virtual views::Widget* GetWidget() OVERRIDE { | 266 virtual views::Widget* GetWidget() OVERRIDE { |
261 return View::GetWidget(); | 267 return View::GetWidget(); |
262 } | 268 } |
263 virtual const views::Widget* GetWidget() const OVERRIDE { | 269 virtual const views::Widget* GetWidget() const OVERRIDE { |
264 return View::GetWidget(); | 270 return View::GetWidget(); |
265 } | 271 } |
266 | 272 |
267 virtual bool CanActivate() const OVERRIDE; | 273 virtual bool CanActivate() const OVERRIDE; |
268 virtual void Layout() OVERRIDE; | 274 virtual void Layout() OVERRIDE; |
| 275 virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE; |
| 276 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE; |
269 | 277 |
270 // BackgroundAnimatorDelegate overrides: | 278 // BackgroundAnimatorDelegate overrides: |
271 virtual void UpdateBackground(int alpha) OVERRIDE; | 279 virtual void UpdateBackground(int alpha) OVERRIDE; |
272 | 280 |
273 // Force the shelf to be presented in an undimmed state. | 281 // Force the shelf to be presented in an undimmed state. |
274 void ForceUndimming(bool force); | 282 void ForceUndimming(bool force); |
275 | 283 |
276 // A function to test the current alpha used by the dimming bar. If there is | 284 // A function to test the current alpha used by the dimming bar. If there is |
277 // no dimmer active, the function will return -1. | 285 // no dimmer active, the function will return -1. |
278 int GetDimmingAlphaForTest(); | 286 int GetDimmingAlphaForTest(); |
279 | 287 |
280 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if | 288 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if |
281 // the dimmer is inactive. | 289 // the dimmer is inactive. |
282 gfx::Rect GetDimmerBoundsForTest(); | 290 gfx::Rect GetDimmerBoundsForTest(); |
283 | 291 |
284 // Disable dimming animations for running tests. This needs to be called | 292 // Disable dimming animations for running tests. This needs to be called |
285 // prior to the creation of of the |dimmer_|. | 293 // prior to the creation of of the |dimmer_|. |
286 void disable_dimming_animations_for_test() { | 294 void disable_dimming_animations_for_test() { |
287 disable_dimming_animations_for_test_ = true; | 295 disable_dimming_animations_for_test_ = true; |
288 } | 296 } |
289 | 297 |
290 private: | 298 private: |
291 ShelfWidget* shelf_; | 299 ShelfWidget* shelf_; |
292 scoped_ptr<views::Widget> dimmer_; | 300 scoped_ptr<views::Widget> dimmer_; |
293 internal::FocusCycler* focus_cycler_; | 301 internal::FocusCycler* focus_cycler_; |
294 int alpha_; | 302 int alpha_; |
| 303 ui::Layer opaque_background_; |
295 | 304 |
296 // The view which does the dimming. | 305 // The view which does the dimming. |
297 DimmerView* dimmer_view_; | 306 DimmerView* dimmer_view_; |
298 | 307 |
299 // True if dimming animations should be turned off. | 308 // True if dimming animations should be turned off. |
300 bool disable_dimming_animations_for_test_; | 309 bool disable_dimming_animations_for_test_; |
301 | 310 |
302 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 311 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
303 }; | 312 }; |
304 | 313 |
305 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) | 314 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) |
306 : shelf_(shelf), | 315 : shelf_(shelf), |
307 focus_cycler_(NULL), | 316 focus_cycler_(NULL), |
308 alpha_(0), | 317 alpha_(0), |
| 318 opaque_background_(ui::LAYER_SOLID_COLOR), |
309 dimmer_view_(NULL), | 319 dimmer_view_(NULL), |
310 disable_dimming_animations_for_test_(false) { | 320 disable_dimming_animations_for_test_(false) { |
311 set_allow_deactivate_on_esc(true); | 321 set_allow_deactivate_on_esc(true); |
| 322 opaque_background_.SetColor(SK_ColorBLACK); |
| 323 opaque_background_.SetBounds(GetLocalBounds()); |
| 324 opaque_background_.SetOpacity(0.0f); |
312 } | 325 } |
313 | 326 |
314 ShelfWidget::DelegateView::~DelegateView() { | 327 ShelfWidget::DelegateView::~DelegateView() { |
315 } | 328 } |
316 | 329 |
317 void ShelfWidget::DelegateView::SetDimmed(bool value) { | 330 void ShelfWidget::DelegateView::SetDimmed(bool value) { |
318 if (value == (dimmer_.get() != NULL)) | 331 if (value == (dimmer_.get() != NULL)) |
319 return; | 332 return; |
320 | 333 |
321 if (value) { | 334 if (value) { |
(...skipping 22 matching lines...) Expand all Loading... |
344 | 357 |
345 bool ShelfWidget::DelegateView::GetDimmed() const { | 358 bool ShelfWidget::DelegateView::GetDimmed() const { |
346 return dimmer_.get() && dimmer_->IsVisible(); | 359 return dimmer_.get() && dimmer_->IsVisible(); |
347 } | 360 } |
348 | 361 |
349 void ShelfWidget::DelegateView::SetWidgetBounds(const gfx::Rect bounds) { | 362 void ShelfWidget::DelegateView::SetWidgetBounds(const gfx::Rect bounds) { |
350 if (dimmer_) | 363 if (dimmer_) |
351 dimmer_->SetBounds(bounds); | 364 dimmer_->SetBounds(bounds); |
352 } | 365 } |
353 | 366 |
| 367 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
| 368 layer->Add(&opaque_background_); |
| 369 ReorderLayers(); |
| 370 } |
| 371 |
354 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 372 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
355 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 373 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
356 gfx::ImageSkia launcher_background = | 374 gfx::ImageSkia launcher_background = |
357 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); | 375 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); |
358 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) | 376 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) |
359 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 377 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
360 launcher_background, | 378 launcher_background, |
361 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | 379 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( |
362 SkBitmapOperations::ROTATION_90_CW, | 380 SkBitmapOperations::ROTATION_90_CW, |
363 SkBitmapOperations::ROTATION_90_CW, | 381 SkBitmapOperations::ROTATION_90_CW, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 if (shelf_->shelf_layout_manager()->IsHorizontalAlignment()) { | 416 if (shelf_->shelf_layout_manager()->IsHorizontalAlignment()) { |
399 child_at(i)->SetBounds(child_at(i)->x(), child_at(i)->y(), | 417 child_at(i)->SetBounds(child_at(i)->x(), child_at(i)->y(), |
400 child_at(i)->width(), height()); | 418 child_at(i)->width(), height()); |
401 } else { | 419 } else { |
402 child_at(i)->SetBounds(child_at(i)->x(), child_at(i)->y(), | 420 child_at(i)->SetBounds(child_at(i)->x(), child_at(i)->y(), |
403 width(), child_at(i)->height()); | 421 width(), child_at(i)->height()); |
404 } | 422 } |
405 } | 423 } |
406 } | 424 } |
407 | 425 |
| 426 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { |
| 427 views::View::ReorderChildLayers(parent_layer); |
| 428 parent_layer->StackAtBottom(&opaque_background_); |
| 429 } |
| 430 |
| 431 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { |
| 432 opaque_background_.SetBounds(GetLocalBounds()); |
| 433 } |
| 434 |
408 void ShelfWidget::DelegateView::ForceUndimming(bool force) { | 435 void ShelfWidget::DelegateView::ForceUndimming(bool force) { |
409 if (GetDimmed()) | 436 if (GetDimmed()) |
410 dimmer_view_->ForceUndimming(force); | 437 dimmer_view_->ForceUndimming(force); |
411 } | 438 } |
412 | 439 |
413 int ShelfWidget::DelegateView::GetDimmingAlphaForTest() { | 440 int ShelfWidget::DelegateView::GetDimmingAlphaForTest() { |
414 if (GetDimmed()) | 441 if (GetDimmed()) |
415 return dimmer_view_->get_dimming_alpha_for_test(); | 442 return dimmer_view_->get_dimming_alpha_for_test(); |
416 return -1; | 443 return -1; |
417 } | 444 } |
(...skipping 20 matching lines...) Expand all Loading... |
438 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 465 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
439 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 466 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
440 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 467 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
441 params.parent = shelf_container; | 468 params.parent = shelf_container; |
442 params.delegate = delegate_view_; | 469 params.delegate = delegate_view_; |
443 Init(params); | 470 Init(params); |
444 | 471 |
445 // The shelf should not take focus when initially shown. | 472 // The shelf should not take focus when initially shown. |
446 set_focus_on_creation(false); | 473 set_focus_on_creation(false); |
447 SetContentsView(delegate_view_); | 474 SetContentsView(delegate_view_); |
| 475 delegate_view_->SetParentLayer(GetLayer()); |
448 | 476 |
449 status_area_widget_ = new internal::StatusAreaWidget(status_container); | 477 status_area_widget_ = new internal::StatusAreaWidget(status_container); |
450 status_area_widget_->CreateTrayViews(); | 478 status_area_widget_->CreateTrayViews(); |
451 if (Shell::GetInstance()->session_state_delegate()-> | 479 if (Shell::GetInstance()->session_state_delegate()-> |
452 IsActiveUserSessionStarted()) { | 480 IsActiveUserSessionStarted()) { |
453 status_area_widget_->Show(); | 481 status_area_widget_->Show(); |
454 } | 482 } |
455 Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); | 483 Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); |
456 | 484 |
457 shelf_layout_manager_ = new internal::ShelfLayoutManager(this); | 485 shelf_layout_manager_ = new internal::ShelfLayoutManager(this); |
458 shelf_container->SetLayoutManager(shelf_layout_manager_); | 486 shelf_container->SetLayoutManager(shelf_layout_manager_); |
459 shelf_layout_manager_->set_workspace_controller(workspace_controller); | 487 shelf_layout_manager_->set_workspace_controller(workspace_controller); |
460 workspace_controller->SetShelf(shelf_layout_manager_); | 488 workspace_controller->SetShelf(shelf_layout_manager_); |
461 | 489 |
462 status_container->SetLayoutManager( | 490 status_container->SetLayoutManager( |
463 new internal::StatusAreaLayoutManager(this)); | 491 new internal::StatusAreaLayoutManager(this)); |
464 | 492 |
465 views::Widget::AddObserver(this); | 493 views::Widget::AddObserver(this); |
466 GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); | 494 GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); |
467 } | 495 } |
468 | 496 |
469 ShelfWidget::~ShelfWidget() { | 497 ShelfWidget::~ShelfWidget() { |
470 RemoveObserver(this); | 498 RemoveObserver(this); |
471 } | 499 } |
472 | 500 |
473 void ShelfWidget::SetPaintsBackground( | 501 void ShelfWidget::SetPaintsBackground( |
474 bool value, | 502 ShelfBackgroundType background_type, |
475 internal::BackgroundAnimator::ChangeType change_type) { | 503 internal::BackgroundAnimator::ChangeType change_type) { |
476 background_animator_.SetPaintsBackground(value, change_type); | 504 ui::Layer* opaque_background = delegate_view_->opaque_background(); |
| 505 float target_opacity = |
| 506 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
| 507 scoped_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; |
| 508 if (change_type != internal::BackgroundAnimator::CHANGE_IMMEDIATE) { |
| 509 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( |
| 510 opaque_background->GetAnimator())); |
| 511 opaque_background_animation->SetTransitionDuration( |
| 512 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); |
| 513 } |
| 514 opaque_background->SetOpacity(target_opacity); |
| 515 |
| 516 // TODO(mukai): use ui::Layer on both opaque_background and normal background |
| 517 // retire background_animator_ at all. It would be simpler. |
| 518 background_animator_.SetPaintsBackground( |
| 519 background_type != SHELF_BACKGROUND_DEFAULT, |
| 520 change_type); |
| 521 } |
| 522 |
| 523 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
| 524 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) |
| 525 return SHELF_BACKGROUND_MAXIMIZED; |
| 526 if (background_animator_.paints_background()) |
| 527 return SHELF_BACKGROUND_OVERLAP; |
| 528 |
| 529 return SHELF_BACKGROUND_DEFAULT; |
477 } | 530 } |
478 | 531 |
479 ShelfAlignment ShelfWidget::GetAlignment() const { | 532 ShelfAlignment ShelfWidget::GetAlignment() const { |
480 return shelf_layout_manager_->GetAlignment(); | 533 return shelf_layout_manager_->GetAlignment(); |
481 } | 534 } |
482 | 535 |
483 void ShelfWidget::SetAlignment(ShelfAlignment alignment) { | 536 void ShelfWidget::SetAlignment(ShelfAlignment alignment) { |
484 if (launcher_) | 537 if (launcher_) |
485 launcher_->SetAlignment(alignment); | 538 launcher_->SetAlignment(alignment); |
486 status_area_widget_->SetShelfAlignment(alignment); | 539 status_area_widget_->SetShelfAlignment(alignment); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 return delegate_view_->GetDimmerBoundsForTest(); | 630 return delegate_view_->GetDimmerBoundsForTest(); |
578 return gfx::Rect(); | 631 return gfx::Rect(); |
579 } | 632 } |
580 | 633 |
581 void ShelfWidget::DisableDimmingAnimationsForTest() { | 634 void ShelfWidget::DisableDimmingAnimationsForTest() { |
582 DCHECK(delegate_view_); | 635 DCHECK(delegate_view_); |
583 return delegate_view_->disable_dimming_animations_for_test(); | 636 return delegate_view_->disable_dimming_animations_for_test(); |
584 } | 637 } |
585 | 638 |
586 } // namespace ash | 639 } // namespace ash |
OLD | NEW |