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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/aura/wm_shelf_aura.h" | 8 #include "ash/aura/wm_shelf_aura.h" |
9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
11 #include "ash/common/session/session_state_delegate.h" | 11 #include "ash/common/session/session_state_delegate.h" |
12 #include "ash/common/shelf/shelf_background_animator_observer.h" | |
12 #include "ash/common/shelf/shelf_constants.h" | 13 #include "ash/common/shelf/shelf_constants.h" |
13 #include "ash/common/shelf/shelf_model.h" | 14 #include "ash/common/shelf/shelf_model.h" |
14 #include "ash/common/shelf/wm_shelf_util.h" | 15 #include "ash/common/shelf/wm_shelf_util.h" |
15 #include "ash/common/shell_window_ids.h" | 16 #include "ash/common/shell_window_ids.h" |
16 #include "ash/common/system/tray/system_tray_delegate.h" | 17 #include "ash/common/system/tray/system_tray_delegate.h" |
17 #include "ash/common/wm_root_window_controller.h" | 18 #include "ash/common/wm_root_window_controller.h" |
18 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
19 #include "ash/focus_cycler.h" | 20 #include "ash/focus_cycler.h" |
20 #include "ash/shelf/shelf_delegate.h" | 21 #include "ash/shelf/shelf_delegate.h" |
21 #include "ash/shelf/shelf_layout_manager.h" | 22 #include "ash/shelf/shelf_layout_manager.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 void SetHovered(bool hovered); | 74 void SetHovered(bool hovered); |
74 | 75 |
75 // Force the dimmer to be undimmed. | 76 // Force the dimmer to be undimmed. |
76 void ForceUndimming(bool force); | 77 void ForceUndimming(bool force); |
77 | 78 |
78 // views::WidgetDelegate overrides: | 79 // views::WidgetDelegate overrides: |
79 views::Widget* GetWidget() override { return View::GetWidget(); } | 80 views::Widget* GetWidget() override { return View::GetWidget(); } |
80 const views::Widget* GetWidget() const override { return View::GetWidget(); } | 81 const views::Widget* GetWidget() const override { return View::GetWidget(); } |
81 | 82 |
82 // BackgroundAnimatorDelegate overrides: | 83 // BackgroundAnimatorDelegate overrides: |
83 void UpdateBackground(int alpha) override { | 84 void UpdateBackground(BackgroundAnimator* animator, int alpha) override { |
84 alpha_ = alpha; | 85 alpha_ = alpha; |
85 SchedulePaint(); | 86 SchedulePaint(); |
86 } | 87 } |
87 | 88 |
89 void BackgroundAnimationEnded(BackgroundAnimator* animator, | |
90 bool successful) override {} | |
91 | |
88 // views::View overrides: | 92 // views::View overrides: |
89 void OnPaintBackground(gfx::Canvas* canvas) override; | 93 void OnPaintBackground(gfx::Canvas* canvas) override; |
90 | 94 |
91 // A function to test the current alpha used. | 95 // A function to test the current alpha used. |
92 int get_dimming_alpha_for_test() { return alpha_; } | 96 int get_dimming_alpha_for_test() { return alpha_; } |
93 | 97 |
94 private: | 98 private: |
95 // This class monitors mouse events to see if it is on top of the shelf. | 99 // This class monitors mouse events to see if it is on top of the shelf. |
96 class DimmerEventFilter : public ui::EventHandler { | 100 class DimmerEventFilter : public ui::EventHandler { |
97 public: | 101 public: |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 | 299 |
296 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); | 300 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); |
297 }; | 301 }; |
298 | 302 |
299 } // namespace | 303 } // namespace |
300 | 304 |
301 // The contents view of the Shelf. This view contains ShelfView and | 305 // The contents view of the Shelf. This view contains ShelfView and |
302 // sizes it to the width of the shelf minus the size of the status area. | 306 // sizes it to the width of the shelf minus the size of the status area. |
303 class ShelfWidget::DelegateView : public views::WidgetDelegate, | 307 class ShelfWidget::DelegateView : public views::WidgetDelegate, |
304 public views::AccessiblePaneView, | 308 public views::AccessiblePaneView, |
305 public BackgroundAnimatorDelegate, | 309 public aura::WindowObserver, |
306 public aura::WindowObserver { | 310 public ShelfBackgroundAnimatorObserver { |
307 public: | 311 public: |
308 explicit DelegateView(ShelfWidget* shelf); | 312 explicit DelegateView(ShelfWidget* shelf); |
309 ~DelegateView() override; | 313 ~DelegateView() override; |
310 | 314 |
311 void set_focus_cycler(FocusCycler* focus_cycler) { | 315 void set_focus_cycler(FocusCycler* focus_cycler) { |
312 focus_cycler_ = focus_cycler; | 316 focus_cycler_ = focus_cycler; |
313 } | 317 } |
314 FocusCycler* focus_cycler() { return focus_cycler_; } | 318 FocusCycler* focus_cycler() { return focus_cycler_; } |
315 | 319 |
316 ui::Layer* opaque_background() { return &opaque_background_; } | 320 ui::Layer* opaque_background() { return &opaque_background_; } |
(...skipping 19 matching lines...) Expand all Loading... | |
336 | 340 |
337 // aura::WindowObserver overrides: | 341 // aura::WindowObserver overrides: |
338 // This will be called when the shelf itself changes its absolute position. | 342 // This will be called when the shelf itself changes its absolute position. |
339 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs | 343 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs |
340 // to be repositioned. The difference to the OnBoundsChanged call above is | 344 // to be repositioned. The difference to the OnBoundsChanged call above is |
341 // that this gets also triggered when the shelf only moves. | 345 // that this gets also triggered when the shelf only moves. |
342 void OnWindowBoundsChanged(aura::Window* window, | 346 void OnWindowBoundsChanged(aura::Window* window, |
343 const gfx::Rect& old_bounds, | 347 const gfx::Rect& old_bounds, |
344 const gfx::Rect& new_bounds) override; | 348 const gfx::Rect& new_bounds) override; |
345 | 349 |
346 // BackgroundAnimatorDelegate overrides: | 350 // ShelfBackgroundAnimatorObserver: |
347 void UpdateBackground(int alpha) override; | 351 void UpdateShelfOpaqueBackground(int alpha) override; |
352 void UpdateShelfAssetBackground(int alpha) override; | |
348 | 353 |
349 // Force the shelf to be presented in an undimmed state. | 354 // Force the shelf to be presented in an undimmed state. |
350 void ForceUndimming(bool force); | 355 void ForceUndimming(bool force); |
351 | 356 |
352 // A function to test the current alpha used by the dimming bar. If there is | 357 // A function to test the current alpha used by the dimming bar. If there is |
353 // no dimmer active, the function will return -1. | 358 // no dimmer active, the function will return -1. |
354 int GetDimmingAlphaForTest(); | 359 int GetDimmingAlphaForTest(); |
355 | 360 |
356 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if | 361 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if |
357 // the dimmer is inactive. | 362 // the dimmer is inactive. |
358 gfx::Rect GetDimmerBoundsForTest(); | 363 gfx::Rect GetDimmerBoundsForTest(); |
359 | 364 |
360 // Disable dimming animations for running tests. This needs to be called | 365 // Disable dimming animations for running tests. This needs to be called |
361 // prior to the creation of of the |dimmer_|. | 366 // prior to the creation of of the |dimmer_|. |
362 void disable_dimming_animations_for_test() { | 367 void disable_dimming_animations_for_test() { |
363 disable_dimming_animations_for_test_ = true; | 368 disable_dimming_animations_for_test_ = true; |
364 } | 369 } |
365 | 370 |
366 private: | 371 private: |
367 ShelfWidget* shelf_; | 372 ShelfWidget* shelf_; |
368 std::unique_ptr<views::Widget> dimmer_; | 373 std::unique_ptr<views::Widget> dimmer_; |
369 FocusCycler* focus_cycler_; | 374 FocusCycler* focus_cycler_; |
370 int alpha_; | 375 int asset_background_alpha_; |
James Cook
2016/06/14 17:50:02
Hooray for more explicit variable names!
| |
376 // TODO(bruthig): Remove opaque_background_. | |
James Cook
2016/06/14 17:50:02
Please file a bug for this and reference it here.
bruthig
2016/07/26 19:50:03
Done.
| |
371 // A black background layer which is shown when a maximized window is visible. | 377 // A black background layer which is shown when a maximized window is visible. |
372 ui::Layer opaque_background_; | 378 ui::Layer opaque_background_; |
373 // A black foreground layer which is shown while transitioning between users. | 379 // A black foreground layer which is shown while transitioning between users. |
374 // Note: Since the back- and foreground layers have different functions they | 380 // Note: Since the back- and foreground layers have different functions they |
375 // can be used simultaneously - so no repurposing possible. | 381 // can be used simultaneously - so no repurposing possible. |
376 ui::Layer opaque_foreground_; | 382 ui::Layer opaque_foreground_; |
377 | 383 |
378 // The view which does the dimming. | 384 // The view which does the dimming. |
379 DimmerView* dimmer_view_; | 385 DimmerView* dimmer_view_; |
380 | 386 |
381 // True if dimming animations should be turned off. | 387 // True if dimming animations should be turned off. |
382 bool disable_dimming_animations_for_test_; | 388 bool disable_dimming_animations_for_test_; |
383 | 389 |
384 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 390 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
385 }; | 391 }; |
386 | 392 |
387 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) | 393 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) |
388 : shelf_(shelf), | 394 : shelf_(shelf), |
389 focus_cycler_(NULL), | 395 focus_cycler_(NULL), |
390 alpha_(0), | 396 asset_background_alpha_(0), |
391 opaque_background_(ui::LAYER_SOLID_COLOR), | 397 opaque_background_(ui::LAYER_SOLID_COLOR), |
392 opaque_foreground_(ui::LAYER_SOLID_COLOR), | 398 opaque_foreground_(ui::LAYER_SOLID_COLOR), |
393 dimmer_view_(NULL), | 399 dimmer_view_(NULL), |
394 disable_dimming_animations_for_test_(false) { | 400 disable_dimming_animations_for_test_(false) { |
395 SetLayoutManager(new views::FillLayout()); | 401 SetLayoutManager(new views::FillLayout()); |
396 set_allow_deactivate_on_esc(true); | 402 set_allow_deactivate_on_esc(true); |
397 opaque_background_.SetColor(SK_ColorBLACK); | 403 opaque_background_.SetColor(SK_ColorBLACK); |
398 opaque_background_.SetBounds(GetLocalBounds()); | 404 opaque_background_.SetBounds(GetLocalBounds()); |
399 opaque_background_.SetOpacity(0.0f); | 405 opaque_background_.SetOpacity(0.0f); |
400 opaque_foreground_.SetColor(SK_ColorBLACK); | 406 opaque_foreground_.SetColor(SK_ColorBLACK); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 return dimmer_.get() && dimmer_->IsVisible(); | 449 return dimmer_.get() && dimmer_->IsVisible(); |
444 } | 450 } |
445 | 451 |
446 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { | 452 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
447 layer->Add(&opaque_background_); | 453 layer->Add(&opaque_background_); |
448 layer->Add(&opaque_foreground_); | 454 layer->Add(&opaque_foreground_); |
449 ReorderLayers(); | 455 ReorderLayers(); |
450 } | 456 } |
451 | 457 |
452 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 458 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
453 if (MaterialDesignController::IsShelfMaterial()) { | 459 if (!MaterialDesignController::IsShelfMaterial()) { |
454 canvas->FillRect(bounds(), SkColorSetA(kShelfBaseColor, alpha_)); | |
455 } else { | |
456 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 460 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
457 gfx::ImageSkia shelf_background = | 461 gfx::ImageSkia shelf_background = |
458 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); | 462 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
459 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); | 463 const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment()); |
460 if (!horizontal) { | 464 if (!horizontal) { |
461 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 465 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
462 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | 466 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT |
463 ? SkBitmapOperations::ROTATION_90_CW | 467 ? SkBitmapOperations::ROTATION_90_CW |
464 : SkBitmapOperations::ROTATION_270_CW); | 468 : SkBitmapOperations::ROTATION_270_CW); |
465 } | 469 } |
466 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); | 470 const gfx::Rect dock_bounds(shelf_->shelf_layout_manager()->dock_bounds()); |
467 SkPaint paint; | 471 SkPaint paint; |
468 paint.setAlpha(alpha_); | 472 paint.setAlpha(asset_background_alpha_); |
469 canvas->DrawImageInt( | 473 canvas->DrawImageInt( |
470 shelf_background, 0, 0, shelf_background.width(), | 474 shelf_background, 0, 0, shelf_background.width(), |
471 shelf_background.height(), | 475 shelf_background.height(), |
472 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) | 476 (horizontal && dock_bounds.x() == 0 && dock_bounds.width() > 0) |
473 ? dock_bounds.width() | 477 ? dock_bounds.width() |
474 : 0, | 478 : 0, |
475 0, horizontal ? width() - dock_bounds.width() : width(), height(), | 479 0, horizontal ? width() - dock_bounds.width() : width(), height(), |
476 false, paint); | 480 false, paint); |
477 if (horizontal && dock_bounds.width() > 0) { | 481 if (horizontal && dock_bounds.width() > 0) { |
478 // The part of the shelf background that is in the corner below the docked | 482 // The part of the shelf background that is in the corner below the docked |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 return dimmer_view_->get_dimming_alpha_for_test(); | 557 return dimmer_view_->get_dimming_alpha_for_test(); |
554 return -1; | 558 return -1; |
555 } | 559 } |
556 | 560 |
557 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { | 561 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { |
558 if (GetDimmed()) | 562 if (GetDimmed()) |
559 return dimmer_view_->GetBoundsInScreen(); | 563 return dimmer_view_->GetBoundsInScreen(); |
560 return gfx::Rect(); | 564 return gfx::Rect(); |
561 } | 565 } |
562 | 566 |
563 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { | 567 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { |
564 alpha_ = alpha; | 568 const double kMaxAlpha = 255.0; |
James Cook
2016/06/14 17:50:02
could be a float
bruthig
2016/07/26 19:50:03
Done.
| |
569 opaque_background_.SetOpacity(alpha / kMaxAlpha); | |
570 } | |
571 | |
572 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { | |
573 asset_background_alpha_ = alpha; | |
565 SchedulePaint(); | 574 SchedulePaint(); |
566 } | 575 } |
567 | 576 |
568 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, | 577 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
569 WmWindow* wm_status_container, | 578 WmWindow* wm_status_container, |
570 WorkspaceController* workspace_controller) | 579 WorkspaceController* workspace_controller) |
571 : delegate_view_(new DelegateView(this)), | 580 : delegate_view_(new DelegateView(this)), |
572 background_animator_( | |
573 delegate_view_, 0, GetShelfConstant(SHELF_BACKGROUND_ALPHA)), | |
574 activating_as_fallback_(false) { | 581 activating_as_fallback_(false) { |
575 views::Widget::InitParams params( | 582 views::Widget::InitParams params( |
576 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 583 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
577 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 584 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
578 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 585 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
579 params.delegate = delegate_view_; | 586 params.delegate = delegate_view_; |
580 wm_shelf_container->GetRootWindowController() | 587 wm_shelf_container->GetRootWindowController() |
581 ->ConfigureWidgetInitParamsForContainer( | 588 ->ConfigureWidgetInitParamsForContainer( |
582 this, wm_shelf_container->GetShellWindowId(), ¶ms); | 589 this, wm_shelf_container->GetShellWindowId(), ¶ms); |
583 Init(params); | 590 Init(params); |
584 | 591 |
585 // The shelf should not take focus when initially shown. | 592 // The shelf should not take focus when initially shown. |
586 set_focus_on_creation(false); | 593 set_focus_on_creation(false); |
587 SetContentsView(delegate_view_); | 594 SetContentsView(delegate_view_); |
588 delegate_view_->SetParentLayer(GetLayer()); | 595 delegate_view_->SetParentLayer(GetLayer()); |
589 | 596 |
590 shelf_layout_manager_ = new ShelfLayoutManager(this); | 597 shelf_layout_manager_ = new ShelfLayoutManager(this); |
591 shelf_layout_manager_->AddObserver(this); | 598 shelf_layout_manager_->AddObserver(this); |
592 aura::Window* shelf_container = | 599 aura::Window* shelf_container = |
593 WmWindowAura::GetAuraWindow(wm_shelf_container); | 600 WmWindowAura::GetAuraWindow(wm_shelf_container); |
594 shelf_container->SetLayoutManager(shelf_layout_manager_); | 601 shelf_container->SetLayoutManager(shelf_layout_manager_); |
595 shelf_layout_manager_->set_workspace_controller(workspace_controller); | 602 shelf_layout_manager_->set_workspace_controller(workspace_controller); |
596 workspace_controller->SetShelf(shelf_layout_manager_); | 603 workspace_controller->SetShelf(shelf_layout_manager_); |
597 | 604 |
605 background_animator_.AddObserver(delegate_view_); | |
James Cook
2016/06/14 17:50:02
Does this need to be done here, or could it happen
bruthig
2016/07/26 19:50:03
Done.
| |
606 | |
598 status_area_widget_ = new StatusAreaWidget(wm_status_container, this); | 607 status_area_widget_ = new StatusAreaWidget(wm_status_container, this); |
599 status_area_widget_->CreateTrayViews(); | 608 status_area_widget_->CreateTrayViews(); |
600 if (Shell::GetInstance()->session_state_delegate()-> | 609 if (Shell::GetInstance()->session_state_delegate()-> |
601 IsActiveUserSessionStarted()) { | 610 IsActiveUserSessionStarted()) { |
602 status_area_widget_->Show(); | 611 status_area_widget_->Show(); |
603 } | 612 } |
604 Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); | 613 Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); |
614 background_animator_.AddObserver(status_area_widget_); | |
605 | 615 |
606 aura::Window* status_container = | 616 aura::Window* status_container = |
607 WmWindowAura::GetAuraWindow(wm_status_container); | 617 WmWindowAura::GetAuraWindow(wm_status_container); |
608 status_container->SetLayoutManager( | 618 status_container->SetLayoutManager( |
609 new StatusAreaLayoutManager(status_container, this)); | 619 new StatusAreaLayoutManager(status_container, this)); |
610 | 620 |
611 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 621 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
612 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_))); | 622 new ShelfWindowTargeter(shelf_container, shelf_layout_manager_))); |
613 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 623 status_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
614 new ShelfWindowTargeter(status_container, shelf_layout_manager_))); | 624 new ShelfWindowTargeter(status_container, shelf_layout_manager_))); |
615 | 625 |
626 // Forcefully paint the background after all observers have been added so they | |
627 // paint properly the first time. | |
628 background_animator_.PaintBackground(SHELF_BACKGROUND_DEFAULT, | |
629 BACKGROUND_CHANGE_IMMEDIATE); | |
630 | |
616 views::Widget::AddObserver(this); | 631 views::Widget::AddObserver(this); |
617 } | 632 } |
618 | 633 |
619 ShelfWidget::~ShelfWidget() { | 634 ShelfWidget::~ShelfWidget() { |
620 // Must call Shutdown() before destruction. | 635 // Must call Shutdown() before destruction. |
621 DCHECK(!status_area_widget_); | 636 DCHECK(!status_area_widget_); |
622 Shell::GetInstance()->focus_cycler()->RemoveWidget(this); | 637 Shell::GetInstance()->focus_cycler()->RemoveWidget(this); |
623 SetFocusCycler(nullptr); | 638 SetFocusCycler(nullptr); |
624 RemoveObserver(this); | 639 RemoveObserver(this); |
625 } | 640 } |
626 | 641 |
627 void ShelfWidget::SetPaintsBackground( | 642 void ShelfWidget::SetPaintsBackground( |
628 ShelfBackgroundType background_type, | 643 ShelfBackgroundType background_type, |
629 BackgroundAnimatorChangeType change_type) { | 644 BackgroundAnimatorChangeType change_type) { |
630 ui::Layer* opaque_background = delegate_view_->opaque_background(); | 645 background_animator_.PaintBackground(background_type, change_type); |
631 float target_opacity = | |
632 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | |
633 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; | |
634 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | |
635 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | |
636 opaque_background->GetAnimator())); | |
637 opaque_background_animation->SetTransitionDuration( | |
638 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); | |
639 } | |
640 opaque_background->SetOpacity(target_opacity); | |
641 | |
642 // TODO(mukai): use ui::Layer on both opaque_background and normal background | |
643 // retire background_animator_ at all. It would be simpler. | |
644 // See also DockedBackgroundWidget::SetPaintsBackground. | |
645 background_animator_.SetPaintsBackground( | |
646 background_type != SHELF_BACKGROUND_DEFAULT, change_type); | |
647 } | 646 } |
648 | 647 |
649 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 648 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
650 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) | 649 return background_animator_.target_background_type(); |
651 return SHELF_BACKGROUND_MAXIMIZED; | |
652 if (background_animator_.paints_background()) | |
653 return SHELF_BACKGROUND_OVERLAP; | |
654 | |
655 return SHELF_BACKGROUND_DEFAULT; | |
656 } | 650 } |
657 | 651 |
658 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { | 652 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { |
659 if (IsShelfHiddenBehindBlackBar() == hide) | 653 if (IsShelfHiddenBehindBlackBar() == hide) |
660 return; | 654 return; |
661 | 655 |
662 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); | 656 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); |
663 float target_opacity = hide ? 1.0f : 0.0f; | 657 float target_opacity = hide ? 1.0f : 0.0f; |
664 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; | 658 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; |
665 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings( | 659 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 | 722 |
729 void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) { | 723 void ShelfWidget::CreateShelf(WmShelfAura* wm_shelf_aura) { |
730 DCHECK(!shelf_); | 724 DCHECK(!shelf_); |
731 | 725 |
732 Shell* shell = Shell::GetInstance(); | 726 Shell* shell = Shell::GetInstance(); |
733 ShelfDelegate* delegate = shell->GetShelfDelegate(); | 727 ShelfDelegate* delegate = shell->GetShelfDelegate(); |
734 shelf_.reset(new Shelf(shell->shelf_model(), delegate, wm_shelf_aura, this)); | 728 shelf_.reset(new Shelf(shell->shelf_model(), delegate, wm_shelf_aura, this)); |
735 // Must be initialized before the delegate is notified because the delegate | 729 // Must be initialized before the delegate is notified because the delegate |
736 // may try to access the WmShelf. | 730 // may try to access the WmShelf. |
737 wm_shelf_aura->SetShelf(shelf_.get()); | 731 wm_shelf_aura->SetShelf(shelf_.get()); |
732 // TODO(bruthig): Is this the best/right place to attach the | |
733 // |background_animator_|? Does |background_animator_| need to be removed as | |
734 // an observer? | |
735 wm_shelf_aura->AddObserver(&background_animator_); | |
James Cook
2016/06/14 17:50:02
Given that the items being animated are built in t
bruthig
2016/07/26 19:50:03
Done.
| |
738 delegate->OnShelfCreated(shelf_.get()); | 736 delegate->OnShelfCreated(shelf_.get()); |
739 | 737 |
740 SetFocusCycler(shell->focus_cycler()); | 738 SetFocusCycler(shell->focus_cycler()); |
741 } | 739 } |
742 | 740 |
743 void ShelfWidget::PostCreateShelf() { | 741 void ShelfWidget::PostCreateShelf() { |
744 shelf_->SetVisible(Shell::GetInstance() | 742 shelf_->SetVisible(Shell::GetInstance() |
745 ->session_state_delegate() | 743 ->session_state_delegate() |
746 ->IsActiveUserSessionStarted()); | 744 ->IsActiveUserSessionStarted()); |
747 shelf_layout_manager_->LayoutShelf(); | 745 shelf_layout_manager_->LayoutShelf(); |
(...skipping 23 matching lines...) Expand all Loading... | |
771 void ShelfWidget::Shutdown() { | 769 void ShelfWidget::Shutdown() { |
772 // Shutting down the status area widget may cause some widgets (e.g. bubbles) | 770 // Shutting down the status area widget may cause some widgets (e.g. bubbles) |
773 // to close, so uninstall the ShelfLayoutManager event filters first. Don't | 771 // to close, so uninstall the ShelfLayoutManager event filters first. Don't |
774 // reset the pointer until later because other widgets (e.g. app list) may | 772 // reset the pointer until later because other widgets (e.g. app list) may |
775 // access it later in shutdown. | 773 // access it later in shutdown. |
776 if (shelf_layout_manager_) | 774 if (shelf_layout_manager_) |
777 shelf_layout_manager_->PrepareForShutdown(); | 775 shelf_layout_manager_->PrepareForShutdown(); |
778 | 776 |
779 if (status_area_widget_) { | 777 if (status_area_widget_) { |
780 Shell::GetInstance()->focus_cycler()->RemoveWidget(status_area_widget_); | 778 Shell::GetInstance()->focus_cycler()->RemoveWidget(status_area_widget_); |
779 background_animator_.RemoveObserver(status_area_widget_); | |
781 status_area_widget_->Shutdown(); | 780 status_area_widget_->Shutdown(); |
782 status_area_widget_ = nullptr; | 781 status_area_widget_ = nullptr; |
783 } | 782 } |
784 } | 783 } |
785 | 784 |
786 void ShelfWidget::ForceUndimming(bool force) { | 785 void ShelfWidget::ForceUndimming(bool force) { |
787 delegate_view_->ForceUndimming(force); | 786 delegate_view_->ForceUndimming(force); |
788 } | 787 } |
789 | 788 |
790 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget, | 789 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); | 823 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); |
825 } | 824 } |
826 | 825 |
827 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { | 826 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { |
828 Widget::OnGestureEvent(event); | 827 Widget::OnGestureEvent(event); |
829 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | 828 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) |
830 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); | 829 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); |
831 } | 830 } |
832 | 831 |
833 } // namespace ash | 832 } // namespace ash |
OLD | NEW |