OLD | NEW |
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/aura/wm_shelf_aura.h" | 7 #include "ash/aura/wm_shelf_aura.h" |
8 #include "ash/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
10 #include "ash/common/focus_cycler.h" | 10 #include "ash/common/focus_cycler.h" |
11 #include "ash/common/material_design/material_design_controller.h" | 11 #include "ash/common/material_design/material_design_controller.h" |
12 #include "ash/common/session/session_state_delegate.h" | 12 #include "ash/common/session/session_state_delegate.h" |
| 13 #include "ash/common/shelf/shelf_background_animator_observer.h" |
13 #include "ash/common/shelf/shelf_constants.h" | 14 #include "ash/common/shelf/shelf_constants.h" |
14 #include "ash/common/shelf/shelf_delegate.h" | 15 #include "ash/common/shelf/shelf_delegate.h" |
15 #include "ash/common/shelf/shelf_model.h" | 16 #include "ash/common/shelf/shelf_model.h" |
| 17 #include "ash/common/shelf/wm_shelf.h" |
16 #include "ash/common/shelf/wm_shelf_util.h" | 18 #include "ash/common/shelf/wm_shelf_util.h" |
17 #include "ash/common/shell_window_ids.h" | 19 #include "ash/common/shell_window_ids.h" |
18 #include "ash/common/system/status_area_widget.h" | 20 #include "ash/common/system/status_area_widget.h" |
19 #include "ash/common/system/tray/system_tray_delegate.h" | 21 #include "ash/common/system/tray/system_tray_delegate.h" |
20 #include "ash/common/wm_root_window_controller.h" | 22 #include "ash/common/wm_root_window_controller.h" |
21 #include "ash/common/wm_shell.h" | 23 #include "ash/common/wm_shell.h" |
22 #include "ash/shelf/shelf.h" | 24 #include "ash/shelf/shelf.h" |
23 #include "ash/shelf/shelf_layout_manager.h" | 25 #include "ash/shelf/shelf_layout_manager.h" |
24 #include "ash/shelf/shelf_util.h" | 26 #include "ash/shelf/shelf_util.h" |
25 #include "ash/shelf/shelf_view.h" | 27 #include "ash/shelf/shelf_view.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 void SetHovered(bool hovered); | 76 void SetHovered(bool hovered); |
75 | 77 |
76 // Force the dimmer to be undimmed. | 78 // Force the dimmer to be undimmed. |
77 void ForceUndimming(bool force); | 79 void ForceUndimming(bool force); |
78 | 80 |
79 // views::WidgetDelegate overrides: | 81 // views::WidgetDelegate overrides: |
80 views::Widget* GetWidget() override { return View::GetWidget(); } | 82 views::Widget* GetWidget() override { return View::GetWidget(); } |
81 const views::Widget* GetWidget() const override { return View::GetWidget(); } | 83 const views::Widget* GetWidget() const override { return View::GetWidget(); } |
82 | 84 |
83 // BackgroundAnimatorDelegate overrides: | 85 // BackgroundAnimatorDelegate overrides: |
84 void UpdateBackground(int alpha) override { | 86 void UpdateBackground(BackgroundAnimator* animator, int alpha) override { |
85 alpha_ = alpha; | 87 alpha_ = alpha; |
86 SchedulePaint(); | 88 SchedulePaint(); |
87 } | 89 } |
88 | 90 |
| 91 void BackgroundAnimationEnded(BackgroundAnimator* animator) override {} |
| 92 |
89 // views::View overrides: | 93 // views::View overrides: |
90 void OnPaintBackground(gfx::Canvas* canvas) override; | 94 void OnPaintBackground(gfx::Canvas* canvas) override; |
91 | 95 |
92 // A function to test the current alpha used. | 96 // A function to test the current alpha used. |
93 int get_dimming_alpha_for_test() { return alpha_; } | 97 int get_dimming_alpha_for_test() { return alpha_; } |
94 | 98 |
95 private: | 99 private: |
96 // This class monitors mouse events to see if it is on top of the shelf. | 100 // This class monitors mouse events to see if it is on top of the shelf. |
97 class DimmerEventFilter : public ui::EventHandler { | 101 class DimmerEventFilter : public ui::EventHandler { |
98 public: | 102 public: |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 295 |
292 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); | 296 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); |
293 }; | 297 }; |
294 | 298 |
295 } // namespace | 299 } // namespace |
296 | 300 |
297 // The contents view of the Shelf. This view contains ShelfView and | 301 // The contents view of the Shelf. This view contains ShelfView and |
298 // sizes it to the width of the shelf minus the size of the status area. | 302 // sizes it to the width of the shelf minus the size of the status area. |
299 class ShelfWidget::DelegateView : public views::WidgetDelegate, | 303 class ShelfWidget::DelegateView : public views::WidgetDelegate, |
300 public views::AccessiblePaneView, | 304 public views::AccessiblePaneView, |
301 public BackgroundAnimatorDelegate, | 305 public aura::WindowObserver, |
302 public aura::WindowObserver { | 306 public ShelfBackgroundAnimatorObserver { |
303 public: | 307 public: |
304 explicit DelegateView(ShelfWidget* shelf); | 308 explicit DelegateView(ShelfWidget* shelf); |
305 ~DelegateView() override; | 309 ~DelegateView() override; |
306 | 310 |
307 void set_focus_cycler(FocusCycler* focus_cycler) { | 311 void set_focus_cycler(FocusCycler* focus_cycler) { |
308 focus_cycler_ = focus_cycler; | 312 focus_cycler_ = focus_cycler; |
309 } | 313 } |
310 FocusCycler* focus_cycler() { return focus_cycler_; } | 314 FocusCycler* focus_cycler() { return focus_cycler_; } |
311 | 315 |
312 ui::Layer* opaque_background() { return &opaque_background_; } | 316 ui::Layer* opaque_background() { return &opaque_background_; } |
(...skipping 19 matching lines...) Expand all Loading... |
332 | 336 |
333 // aura::WindowObserver overrides: | 337 // aura::WindowObserver overrides: |
334 // This will be called when the shelf itself changes its absolute position. | 338 // This will be called when the shelf itself changes its absolute position. |
335 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs | 339 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs |
336 // to be repositioned. The difference to the OnBoundsChanged call above is | 340 // to be repositioned. The difference to the OnBoundsChanged call above is |
337 // that this gets also triggered when the shelf only moves. | 341 // that this gets also triggered when the shelf only moves. |
338 void OnWindowBoundsChanged(aura::Window* window, | 342 void OnWindowBoundsChanged(aura::Window* window, |
339 const gfx::Rect& old_bounds, | 343 const gfx::Rect& old_bounds, |
340 const gfx::Rect& new_bounds) override; | 344 const gfx::Rect& new_bounds) override; |
341 | 345 |
342 // BackgroundAnimatorDelegate overrides: | 346 // ShelfBackgroundAnimatorObserver: |
343 void UpdateBackground(int alpha) override; | 347 void UpdateShelfOpaqueBackground(int alpha) override; |
| 348 void UpdateShelfAssetBackground(int alpha) override; |
344 | 349 |
345 // Force the shelf to be presented in an undimmed state. | 350 // Force the shelf to be presented in an undimmed state. |
346 void ForceUndimming(bool force); | 351 void ForceUndimming(bool force); |
347 | 352 |
348 // A function to test the current alpha used by the dimming bar. If there is | 353 // A function to test the current alpha used by the dimming bar. If there is |
349 // no dimmer active, the function will return -1. | 354 // no dimmer active, the function will return -1. |
350 int GetDimmingAlphaForTest(); | 355 int GetDimmingAlphaForTest(); |
351 | 356 |
352 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if | 357 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if |
353 // the dimmer is inactive. | 358 // the dimmer is inactive. |
354 gfx::Rect GetDimmerBoundsForTest(); | 359 gfx::Rect GetDimmerBoundsForTest(); |
355 | 360 |
356 // Disable dimming animations for running tests. This needs to be called | 361 // Disable dimming animations for running tests. This needs to be called |
357 // prior to the creation of of the |dimmer_|. | 362 // prior to the creation of of the |dimmer_|. |
358 void disable_dimming_animations_for_test() { | 363 void disable_dimming_animations_for_test() { |
359 disable_dimming_animations_for_test_ = true; | 364 disable_dimming_animations_for_test_ = true; |
360 } | 365 } |
361 | 366 |
362 private: | 367 private: |
363 ShelfWidget* shelf_; | 368 ShelfWidget* shelf_; |
364 std::unique_ptr<views::Widget> dimmer_; | 369 std::unique_ptr<views::Widget> dimmer_; |
365 FocusCycler* focus_cycler_; | 370 FocusCycler* focus_cycler_; |
366 int alpha_; | 371 int asset_background_alpha_; |
| 372 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). |
367 // A black background layer which is shown when a maximized window is visible. | 373 // A black background layer which is shown when a maximized window is visible. |
368 ui::Layer opaque_background_; | 374 ui::Layer opaque_background_; |
369 // A black foreground layer which is shown while transitioning between users. | 375 // A black foreground layer which is shown while transitioning between users. |
370 // Note: Since the back- and foreground layers have different functions they | 376 // Note: Since the back- and foreground layers have different functions they |
371 // can be used simultaneously - so no repurposing possible. | 377 // can be used simultaneously - so no repurposing possible. |
372 ui::Layer opaque_foreground_; | 378 ui::Layer opaque_foreground_; |
373 | 379 |
374 // The view which does the dimming. | 380 // The view which does the dimming. |
375 DimmerView* dimmer_view_; | 381 DimmerView* dimmer_view_; |
376 | 382 |
377 // True if dimming animations should be turned off. | 383 // True if dimming animations should be turned off. |
378 bool disable_dimming_animations_for_test_; | 384 bool disable_dimming_animations_for_test_; |
379 | 385 |
380 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 386 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
381 }; | 387 }; |
382 | 388 |
383 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) | 389 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) |
384 : shelf_(shelf), | 390 : shelf_(shelf), |
385 focus_cycler_(NULL), | 391 focus_cycler_(NULL), |
386 alpha_(0), | 392 asset_background_alpha_(0), |
387 opaque_background_(ui::LAYER_SOLID_COLOR), | 393 opaque_background_(ui::LAYER_SOLID_COLOR), |
388 opaque_foreground_(ui::LAYER_SOLID_COLOR), | 394 opaque_foreground_(ui::LAYER_SOLID_COLOR), |
389 dimmer_view_(NULL), | 395 dimmer_view_(NULL), |
390 disable_dimming_animations_for_test_(false) { | 396 disable_dimming_animations_for_test_(false) { |
391 SetLayoutManager(new views::FillLayout()); | 397 SetLayoutManager(new views::FillLayout()); |
392 set_allow_deactivate_on_esc(true); | 398 set_allow_deactivate_on_esc(true); |
393 opaque_background_.SetColor(SK_ColorBLACK); | 399 opaque_background_.SetColor(SK_ColorBLACK); |
394 opaque_background_.SetBounds(GetLocalBounds()); | 400 opaque_background_.SetBounds(GetLocalBounds()); |
395 opaque_background_.SetOpacity(0.0f); | 401 opaque_background_.SetOpacity(0.0f); |
396 opaque_foreground_.SetColor(SK_ColorBLACK); | 402 opaque_foreground_.SetColor(SK_ColorBLACK); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 return dimmer_.get() && dimmer_->IsVisible(); | 445 return dimmer_.get() && dimmer_->IsVisible(); |
440 } | 446 } |
441 | 447 |
442 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { | 448 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
443 layer->Add(&opaque_background_); | 449 layer->Add(&opaque_background_); |
444 layer->Add(&opaque_foreground_); | 450 layer->Add(&opaque_foreground_); |
445 ReorderLayers(); | 451 ReorderLayers(); |
446 } | 452 } |
447 | 453 |
448 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 454 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
449 if (MaterialDesignController::IsShelfMaterial()) { | 455 if (MaterialDesignController::IsShelfMaterial()) |
450 canvas->FillRect(bounds(), SkColorSetA(kShelfBaseColor, alpha_)); | 456 return; |
451 } else { | 457 |
452 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 458 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
453 gfx::ImageSkia shelf_background = | 459 gfx::ImageSkia shelf_background = |
454 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); | 460 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
455 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); | 461 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); |
456 if (!horizontal) { | 462 if (!horizontal) { |
457 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 463 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
458 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | 464 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT |
459 ? SkBitmapOperations::ROTATION_90_CW | 465 ? SkBitmapOperations::ROTATION_90_CW |
460 : SkBitmapOperations::ROTATION_270_CW); | 466 : SkBitmapOperations::ROTATION_270_CW); |
| 467 } |
| 468 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
| 469 SkPaint paint; |
| 470 paint.setAlpha(asset_background_alpha_); |
| 471 canvas->DrawImageInt( |
| 472 shelf_background, 0, 0, shelf_background.width(), |
| 473 shelf_background.height(), |
| 474 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) |
| 475 ? dock_bounds.width() |
| 476 : 0, |
| 477 0, horizontal ? width() - dock_bounds.width() : width(), height(), false, |
| 478 paint); |
| 479 if (horizontal && dock_bounds.width() > 0) { |
| 480 // The part of the shelf background that is in the corner below the docked |
| 481 // windows close to the work area is an arched gradient that blends |
| 482 // vertically oriented docked background and horizontal shelf. |
| 483 gfx::ImageSkia shelf_corner = *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER); |
| 484 if (dock_bounds.x() == 0) { |
| 485 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 486 shelf_corner, SkBitmapOperations::ROTATION_90_CW); |
461 } | 487 } |
462 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); | |
463 SkPaint paint; | |
464 paint.setAlpha(alpha_); | |
465 canvas->DrawImageInt( | 488 canvas->DrawImageInt( |
466 shelf_background, 0, 0, shelf_background.width(), | 489 shelf_corner, 0, 0, shelf_corner.width(), shelf_corner.height(), |
467 shelf_background.height(), | 490 dock_bounds.x() > 0 ? dock_bounds.x() : dock_bounds.width() - height(), |
468 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) | 491 0, height(), height(), false, paint); |
469 ? dock_bounds.width() | 492 // The part of the shelf background that is just below the docked windows |
470 : 0, | 493 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. |
471 0, horizontal ? width() - dock_bounds.width() : width(), height(), | 494 // This avoids showing the border 3D shadow between the shelf and the |
472 false, paint); | 495 // dock. |
473 if (horizontal && dock_bounds.width() > 0) { | 496 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, |
474 // The part of the shelf background that is in the corner below the docked | 497 shelf_background.width(), 1, |
475 // windows close to the work area is an arched gradient that blends | 498 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, |
476 // vertically oriented docked background and horizontal shelf. | 499 0, dock_bounds.width() - height(), height(), false, |
477 gfx::ImageSkia shelf_corner = | 500 paint); |
478 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER); | |
479 if (dock_bounds.x() == 0) { | |
480 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage( | |
481 shelf_corner, SkBitmapOperations::ROTATION_90_CW); | |
482 } | |
483 canvas->DrawImageInt(shelf_corner, 0, 0, shelf_corner.width(), | |
484 shelf_corner.height(), | |
485 dock_bounds.x() > 0 ? dock_bounds.x() | |
486 : dock_bounds.width() - height(), | |
487 0, height(), height(), false, paint); | |
488 // The part of the shelf background that is just below the docked windows | |
489 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. | |
490 // This avoids showing the border 3D shadow between the shelf and the | |
491 // dock. | |
492 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, | |
493 shelf_background.width(), 1, | |
494 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, | |
495 0, dock_bounds.width() - height(), height(), false, | |
496 paint); | |
497 } | |
498 gfx::Rect black_rect = | |
499 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | |
500 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), | |
501 gfx::Rect(0, 0, kNumBlackPixels, height()), | |
502 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height())); | |
503 canvas->FillRect(black_rect, SK_ColorBLACK); | |
504 } | 501 } |
| 502 gfx::Rect black_rect = |
| 503 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( |
| 504 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), |
| 505 gfx::Rect(0, 0, kNumBlackPixels, height()), |
| 506 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height())); |
| 507 canvas->FillRect(black_rect, SK_ColorBLACK); |
505 } | 508 } |
506 | 509 |
507 bool ShelfWidget::DelegateView::CanActivate() const { | 510 bool ShelfWidget::DelegateView::CanActivate() const { |
508 // Allow to activate as fallback. | 511 // Allow to activate as fallback. |
509 if (shelf_->activating_as_fallback_) | 512 if (shelf_->activating_as_fallback_) |
510 return true; | 513 return true; |
511 // Allow to activate from the focus cycler. | 514 // Allow to activate from the focus cycler. |
512 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) | 515 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) |
513 return true; | 516 return true; |
514 // Disallow activating in other cases, especially when using mouse. | 517 // Disallow activating in other cases, especially when using mouse. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 return dimmer_view_->get_dimming_alpha_for_test(); | 551 return dimmer_view_->get_dimming_alpha_for_test(); |
549 return -1; | 552 return -1; |
550 } | 553 } |
551 | 554 |
552 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { | 555 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { |
553 if (GetDimmed()) | 556 if (GetDimmed()) |
554 return dimmer_view_->GetBoundsInScreen(); | 557 return dimmer_view_->GetBoundsInScreen(); |
555 return gfx::Rect(); | 558 return gfx::Rect(); |
556 } | 559 } |
557 | 560 |
558 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { | 561 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { |
559 alpha_ = alpha; | 562 const float kMaxAlpha = 255.0f; |
| 563 opaque_background_.SetOpacity(alpha / kMaxAlpha); |
| 564 } |
| 565 |
| 566 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { |
| 567 asset_background_alpha_ = alpha; |
560 SchedulePaint(); | 568 SchedulePaint(); |
561 } | 569 } |
562 | 570 |
563 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, | 571 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
564 WmWindow* wm_status_container, | 572 WmWindow* wm_status_container, |
565 WmShelfAura* wm_shelf_aura, | 573 WmShelfAura* wm_shelf_aura, |
566 WorkspaceController* workspace_controller) | 574 WorkspaceController* workspace_controller) |
567 : delegate_view_(new DelegateView(this)), | 575 : wm_shelf_aura_(wm_shelf_aura), |
568 background_animator_(delegate_view_, | 576 delegate_view_(new DelegateView(this)), |
569 0, | 577 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_), |
570 GetShelfConstant(SHELF_BACKGROUND_ALPHA)), | |
571 activating_as_fallback_(false) { | 578 activating_as_fallback_(false) { |
| 579 background_animator_.AddObserver(delegate_view_); |
| 580 |
572 views::Widget::InitParams params( | 581 views::Widget::InitParams params( |
573 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 582 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
574 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 583 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
575 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 584 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
576 params.delegate = delegate_view_; | 585 params.delegate = delegate_view_; |
577 wm_shelf_container->GetRootWindowController() | 586 wm_shelf_container->GetRootWindowController() |
578 ->ConfigureWidgetInitParamsForContainer( | 587 ->ConfigureWidgetInitParamsForContainer( |
579 this, wm_shelf_container->GetShellWindowId(), ¶ms); | 588 this, wm_shelf_container->GetShellWindowId(), ¶ms); |
580 Init(params); | 589 Init(params); |
581 | 590 |
582 // The shelf should not take focus when initially shown. | 591 // The shelf should not take focus when initially shown. |
583 set_focus_on_creation(false); | 592 set_focus_on_creation(false); |
584 SetContentsView(delegate_view_); | 593 SetContentsView(delegate_view_); |
585 delegate_view_->SetParentLayer(GetLayer()); | 594 delegate_view_->SetParentLayer(GetLayer()); |
586 | 595 |
587 shelf_layout_manager_ = new ShelfLayoutManager(this); | 596 shelf_layout_manager_ = new ShelfLayoutManager(this); |
588 shelf_layout_manager_->AddObserver(this); | 597 shelf_layout_manager_->AddObserver(this); |
589 aura::Window* shelf_container = | 598 aura::Window* shelf_container = |
590 WmWindowAura::GetAuraWindow(wm_shelf_container); | 599 WmWindowAura::GetAuraWindow(wm_shelf_container); |
591 shelf_container->SetLayoutManager(shelf_layout_manager_); | 600 shelf_container->SetLayoutManager(shelf_layout_manager_); |
592 shelf_layout_manager_->set_workspace_controller(workspace_controller); | 601 shelf_layout_manager_->set_workspace_controller(workspace_controller); |
593 workspace_controller->SetShelf(shelf_layout_manager_); | 602 workspace_controller->SetShelf(shelf_layout_manager_); |
594 wm_shelf_aura->SetShelfLayoutManager(shelf_layout_manager_); | 603 background_animator_.PaintBackground( |
| 604 shelf_layout_manager_->GetShelfBackgroundType(), |
| 605 BACKGROUND_CHANGE_IMMEDIATE); |
| 606 wm_shelf_aura_->SetShelfLayoutManager(shelf_layout_manager_); |
595 | 607 |
596 // TODO(jamescook): Move ownership to RootWindowController. | 608 // TODO(jamescook): Move ownership to RootWindowController. |
597 status_area_widget_ = | 609 status_area_widget_ = |
598 new StatusAreaWidget(wm_status_container, wm_shelf_aura); | 610 new StatusAreaWidget(wm_status_container, wm_shelf_aura_); |
599 status_area_widget_->CreateTrayViews(); | 611 status_area_widget_->CreateTrayViews(); |
600 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) | 612 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) |
601 status_area_widget_->Show(); | 613 status_area_widget_->Show(); |
602 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); | 614 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); |
| 615 background_animator_.AddObserver(status_area_widget_); |
603 | 616 |
604 aura::Window* status_container = | 617 aura::Window* status_container = |
605 WmWindowAura::GetAuraWindow(wm_status_container); | 618 WmWindowAura::GetAuraWindow(wm_status_container); |
606 status_container->SetLayoutManager( | 619 status_container->SetLayoutManager( |
607 new StatusAreaLayoutManager(status_container, this)); | 620 new StatusAreaLayoutManager(status_container, this)); |
608 | 621 |
609 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 622 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
610 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_))); | 623 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_))); |
611 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 624 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
612 new ShelfWindowTargeter(status_container, shelf_layout_manager_))); | 625 new ShelfWindowTargeter(status_container, shelf_layout_manager_))); |
613 | 626 |
614 views::Widget::AddObserver(this); | 627 views::Widget::AddObserver(this); |
615 } | 628 } |
616 | 629 |
617 ShelfWidget::~ShelfWidget() { | 630 ShelfWidget::~ShelfWidget() { |
618 // Must call Shutdown() before destruction. | 631 // Must call Shutdown() before destruction. |
619 DCHECK(!status_area_widget_); | 632 DCHECK(!status_area_widget_); |
620 WmShell::Get()->focus_cycler()->RemoveWidget(this); | 633 WmShell::Get()->focus_cycler()->RemoveWidget(this); |
621 SetFocusCycler(nullptr); | 634 SetFocusCycler(nullptr); |
622 RemoveObserver(this); | 635 RemoveObserver(this); |
| 636 background_animator_.RemoveObserver(delegate_view_); |
623 } | 637 } |
624 | 638 |
625 void ShelfWidget::SetPaintsBackground( | 639 void ShelfWidget::SetPaintsBackground( |
626 ShelfBackgroundType background_type, | 640 ShelfBackgroundType background_type, |
627 BackgroundAnimatorChangeType change_type) { | 641 BackgroundAnimatorChangeType change_type) { |
628 ui::Layer* opaque_background = delegate_view_->opaque_background(); | 642 background_animator_.PaintBackground(background_type, change_type); |
629 float target_opacity = | |
630 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | |
631 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; | |
632 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | |
633 opaque_background_animation.reset( | |
634 new ui::ScopedLayerAnimationSettings(opaque_background->GetAnimator())); | |
635 opaque_background_animation->SetTransitionDuration( | |
636 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); | |
637 } | |
638 opaque_background->SetOpacity(target_opacity); | |
639 | |
640 // TODO(mukai): use ui::Layer on both opaque_background and normal background | |
641 // retire background_animator_ at all. It would be simpler. | |
642 // See also DockedBackgroundWidget::SetPaintsBackground. | |
643 background_animator_.SetPaintsBackground( | |
644 background_type != SHELF_BACKGROUND_DEFAULT, change_type); | |
645 } | 643 } |
646 | 644 |
647 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 645 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
648 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) | 646 return background_animator_.target_background_type(); |
649 return SHELF_BACKGROUND_MAXIMIZED; | |
650 if (background_animator_.paints_background()) | |
651 return SHELF_BACKGROUND_OVERLAP; | |
652 | |
653 return SHELF_BACKGROUND_DEFAULT; | |
654 } | 647 } |
655 | 648 |
656 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { | 649 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { |
657 if (IsShelfHiddenBehindBlackBar() == hide) | 650 if (IsShelfHiddenBehindBlackBar() == hide) |
658 return; | 651 return; |
659 | 652 |
660 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); | 653 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); |
661 float target_opacity = hide ? 1.0f : 0.0f; | 654 float target_opacity = hide ? 1.0f : 0.0f; |
662 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; | 655 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; |
663 opaque_foreground_animation.reset( | 656 opaque_foreground_animation.reset( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 // status area background, app list button and overflow button. | 710 // status area background, app list button and overflow button. |
718 if (shelf_) | 711 if (shelf_) |
719 shelf_->SchedulePaint(); | 712 shelf_->SchedulePaint(); |
720 status_area_widget_->SchedulePaint(); | 713 status_area_widget_->SchedulePaint(); |
721 } | 714 } |
722 | 715 |
723 bool ShelfWidget::GetDimsShelf() const { | 716 bool ShelfWidget::GetDimsShelf() const { |
724 return delegate_view_->GetDimmed(); | 717 return delegate_view_->GetDimmed(); |
725 } | 718 } |
726 | 719 |
727 void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) { | 720 void ShelfWidget::CreateShelf() { |
728 DCHECK(!shelf_); | 721 DCHECK(!shelf_); |
729 | 722 |
730 shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura, this)); | 723 shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura_, this, |
| 724 &background_animator_)); |
731 // Must be initialized before the delegate is notified because the delegate | 725 // Must be initialized before the delegate is notified because the delegate |
732 // may try to access the WmShelf. | 726 // may try to access the WmShelf. |
733 wm_shelf_aura->SetShelf(shelf_.get()); | 727 wm_shelf_aura_->SetShelf(shelf_.get()); |
734 WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get()); | 728 WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get()); |
735 | 729 |
736 SetFocusCycler(WmShell::Get()->focus_cycler()); | 730 SetFocusCycler(WmShell::Get()->focus_cycler()); |
737 } | 731 } |
738 | 732 |
739 void ShelfWidget::PostCreateShelf() { | 733 void ShelfWidget::PostCreateShelf() { |
740 shelf_->SetVisible( | 734 shelf_->SetVisible( |
741 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); | 735 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); |
742 shelf_layout_manager_->LayoutShelf(); | 736 shelf_layout_manager_->LayoutShelf(); |
743 shelf_layout_manager_->UpdateAutoHideState(); | 737 shelf_layout_manager_->UpdateAutoHideState(); |
(...skipping 21 matching lines...) Expand all Loading... |
765 | 759 |
766 void ShelfWidget::Shutdown() { | 760 void ShelfWidget::Shutdown() { |
767 // Shutting down the status area widget may cause some widgets (e.g. bubbles) | 761 // Shutting down the status area widget may cause some widgets (e.g. bubbles) |
768 // to close, so uninstall the ShelfLayoutManager event filters first. Don't | 762 // to close, so uninstall the ShelfLayoutManager event filters first. Don't |
769 // reset the pointer until later because other widgets (e.g. app list) may | 763 // reset the pointer until later because other widgets (e.g. app list) may |
770 // access it later in shutdown. | 764 // access it later in shutdown. |
771 if (shelf_layout_manager_) | 765 if (shelf_layout_manager_) |
772 shelf_layout_manager_->PrepareForShutdown(); | 766 shelf_layout_manager_->PrepareForShutdown(); |
773 | 767 |
774 if (status_area_widget_) { | 768 if (status_area_widget_) { |
| 769 background_animator_.RemoveObserver(status_area_widget_); |
775 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); | 770 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); |
776 status_area_widget_->Shutdown(); | 771 status_area_widget_->Shutdown(); |
777 status_area_widget_ = nullptr; | 772 status_area_widget_ = nullptr; |
778 } | 773 } |
779 } | 774 } |
780 | 775 |
781 void ShelfWidget::ForceUndimming(bool force) { | 776 void ShelfWidget::ForceUndimming(bool force) { |
782 delegate_view_->ForceUndimming(force); | 777 delegate_view_->ForceUndimming(force); |
783 } | 778 } |
784 | 779 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); | 814 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); |
820 } | 815 } |
821 | 816 |
822 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { | 817 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { |
823 Widget::OnGestureEvent(event); | 818 Widget::OnGestureEvent(event); |
824 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | 819 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) |
825 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); | 820 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); |
826 } | 821 } |
827 | 822 |
828 } // namespace ash | 823 } // namespace ash |
OLD | NEW |