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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 namespace ash { | 49 namespace ash { |
50 | 50 |
51 namespace { | 51 namespace { |
52 // Size of black border at bottom (or side) of shelf. | 52 // Size of black border at bottom (or side) of shelf. |
53 const int kNumBlackPixels = 3; | 53 const int kNumBlackPixels = 3; |
54 // Alpha to paint dimming image with. | 54 // Alpha to paint dimming image with. |
55 const int kDimAlpha = 128; | 55 const int kDimAlpha = 128; |
56 | 56 |
57 // The time to dim and un-dim. | 57 // The time to dim and un-dim. |
58 const int kTimeToDimMs = 3000; // Slow in dimming. | 58 const int kTimeToDimMs = 3000; // Slow in dimming. |
59 const int kTimeToUnDimMs = 200; // Fast in activating. | 59 const int kTimeToUnDimMs = 200; // Fast in activating. |
60 | 60 |
61 // Class used to slightly dim shelf items when maximized and visible. | 61 // Class used to slightly dim shelf items when maximized and visible. |
62 class DimmerView : public views::View, | 62 class DimmerView : public views::View, |
63 public views::WidgetDelegate, | 63 public views::WidgetDelegate, |
64 BackgroundAnimatorDelegate { | 64 BackgroundAnimatorDelegate { |
65 public: | 65 public: |
66 // If |disable_dimming_animations_for_test| is set, all alpha animations will | 66 // If |disable_dimming_animations_for_test| is set, all alpha animations will |
67 // be performed instantly. | 67 // be performed instantly. |
68 DimmerView(ShelfWidget* shelf_widget, | 68 DimmerView(ShelfWidget* shelf_widget, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 force_hovered_(false), | 147 force_hovered_(false), |
148 disable_dimming_animations_for_test_(disable_dimming_animations_for_test), | 148 disable_dimming_animations_for_test_(disable_dimming_animations_for_test), |
149 background_animator_(this, 0, kDimAlpha) { | 149 background_animator_(this, 0, kDimAlpha) { |
150 event_filter_.reset(new DimmerEventFilter(this)); | 150 event_filter_.reset(new DimmerEventFilter(this)); |
151 // Make sure it is undimmed at the beginning and then fire off the dimming | 151 // Make sure it is undimmed at the beginning and then fire off the dimming |
152 // animation. | 152 // animation. |
153 background_animator_.SetPaintsBackground(false, BACKGROUND_CHANGE_IMMEDIATE); | 153 background_animator_.SetPaintsBackground(false, BACKGROUND_CHANGE_IMMEDIATE); |
154 SetHovered(false); | 154 SetHovered(false); |
155 } | 155 } |
156 | 156 |
157 DimmerView::~DimmerView() { | 157 DimmerView::~DimmerView() {} |
158 } | |
159 | 158 |
160 void DimmerView::SetHovered(bool hovered) { | 159 void DimmerView::SetHovered(bool hovered) { |
161 // Remember the hovered state so that we can correct the state once a | 160 // Remember the hovered state so that we can correct the state once a |
162 // possible force state has disappeared. | 161 // possible force state has disappeared. |
163 is_hovered_ = hovered; | 162 is_hovered_ = hovered; |
164 // Undimm also if we were forced to by e.g. an open menu. | 163 // Undimm also if we were forced to by e.g. an open menu. |
165 hovered |= force_hovered_; | 164 hovered |= force_hovered_; |
166 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); | 165 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); |
167 background_animator_.SetPaintsBackground(!hovered, | 166 background_animator_.SetPaintsBackground(!hovered, |
168 disable_dimming_animations_for_test_ | 167 disable_dimming_animations_for_test_ |
(...skipping 21 matching lines...) Expand all Loading... |
190 ? SkBitmapOperations::ROTATION_90_CW | 189 ? SkBitmapOperations::ROTATION_90_CW |
191 : SkBitmapOperations::ROTATION_270_CW); | 190 : SkBitmapOperations::ROTATION_270_CW); |
192 } | 191 } |
193 paint.setAlpha(alpha_); | 192 paint.setAlpha(alpha_); |
194 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(), | 193 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(), |
195 shelf_background.height(), 0, 0, width(), height(), | 194 shelf_background.height(), 0, 0, width(), height(), |
196 false, paint); | 195 false, paint); |
197 } | 196 } |
198 | 197 |
199 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) | 198 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) |
200 : owner_(owner), | 199 : owner_(owner), mouse_inside_(false), touch_inside_(false) { |
201 mouse_inside_(false), | |
202 touch_inside_(false) { | |
203 Shell::GetInstance()->AddPreTargetHandler(this); | 200 Shell::GetInstance()->AddPreTargetHandler(this); |
204 } | 201 } |
205 | 202 |
206 DimmerView::DimmerEventFilter::~DimmerEventFilter() { | 203 DimmerView::DimmerEventFilter::~DimmerEventFilter() { |
207 Shell::GetInstance()->RemovePreTargetHandler(this); | 204 Shell::GetInstance()->RemovePreTargetHandler(this); |
208 } | 205 } |
209 | 206 |
210 void DimmerView::DimmerEventFilter::OnMouseEvent(ui::MouseEvent* event) { | 207 void DimmerView::DimmerEventFilter::OnMouseEvent(ui::MouseEvent* event) { |
211 if (event->type() != ui::ET_MOUSE_MOVED && | 208 if (event->type() != ui::ET_MOUSE_MOVED && |
212 event->type() != ui::ET_MOUSE_DRAGGED) | 209 event->type() != ui::ET_MOUSE_DRAGGED) |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 if (horizontal && dock_bounds.width() > 0) { | 472 if (horizontal && dock_bounds.width() > 0) { |
476 // The part of the shelf background that is in the corner below the docked | 473 // The part of the shelf background that is in the corner below the docked |
477 // windows close to the work area is an arched gradient that blends | 474 // windows close to the work area is an arched gradient that blends |
478 // vertically oriented docked background and horizontal shelf. | 475 // vertically oriented docked background and horizontal shelf. |
479 gfx::ImageSkia shelf_corner = | 476 gfx::ImageSkia shelf_corner = |
480 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER); | 477 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_CORNER); |
481 if (dock_bounds.x() == 0) { | 478 if (dock_bounds.x() == 0) { |
482 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage( | 479 shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage( |
483 shelf_corner, SkBitmapOperations::ROTATION_90_CW); | 480 shelf_corner, SkBitmapOperations::ROTATION_90_CW); |
484 } | 481 } |
485 canvas->DrawImageInt( | 482 canvas->DrawImageInt(shelf_corner, 0, 0, shelf_corner.width(), |
486 shelf_corner, 0, 0, shelf_corner.width(), shelf_corner.height(), | 483 shelf_corner.height(), |
487 dock_bounds.x() > 0 | 484 dock_bounds.x() > 0 ? dock_bounds.x() |
488 ? dock_bounds.x() | 485 : dock_bounds.width() - height(), |
489 : dock_bounds.width() - height(), | 486 0, height(), height(), false, paint); |
490 0, height(), height(), false, paint); | |
491 // The part of the shelf background that is just below the docked windows | 487 // The part of the shelf background that is just below the docked windows |
492 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. | 488 // is drawn using the last (lowest) 1-pixel tall strip of the image asset. |
493 // This avoids showing the border 3D shadow between the shelf and the | 489 // This avoids showing the border 3D shadow between the shelf and the |
494 // dock. | 490 // dock. |
495 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, | 491 canvas->DrawImageInt(shelf_background, 0, shelf_background.height() - 1, |
496 shelf_background.width(), 1, | 492 shelf_background.width(), 1, |
497 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, | 493 dock_bounds.x() > 0 ? dock_bounds.x() + height() : 0, |
498 0, dock_bounds.width() - height(), height(), false, | 494 0, dock_bounds.width() - height(), height(), false, |
499 paint); | 495 paint); |
500 } | 496 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { | 557 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { |
562 alpha_ = alpha; | 558 alpha_ = alpha; |
563 SchedulePaint(); | 559 SchedulePaint(); |
564 } | 560 } |
565 | 561 |
566 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, | 562 ShelfWidget::ShelfWidget(WmWindow* wm_shelf_container, |
567 WmWindow* wm_status_container, | 563 WmWindow* wm_status_container, |
568 WmShelfAura* wm_shelf_aura, | 564 WmShelfAura* wm_shelf_aura, |
569 WorkspaceController* workspace_controller) | 565 WorkspaceController* workspace_controller) |
570 : delegate_view_(new DelegateView(this)), | 566 : delegate_view_(new DelegateView(this)), |
571 background_animator_( | 567 background_animator_(delegate_view_, |
572 delegate_view_, 0, GetShelfConstant(SHELF_BACKGROUND_ALPHA)), | 568 0, |
| 569 GetShelfConstant(SHELF_BACKGROUND_ALPHA)), |
573 activating_as_fallback_(false) { | 570 activating_as_fallback_(false) { |
574 views::Widget::InitParams params( | 571 views::Widget::InitParams params( |
575 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 572 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
576 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 573 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
577 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 574 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
578 params.delegate = delegate_view_; | 575 params.delegate = delegate_view_; |
579 wm_shelf_container->GetRootWindowController() | 576 wm_shelf_container->GetRootWindowController() |
580 ->ConfigureWidgetInitParamsForContainer( | 577 ->ConfigureWidgetInitParamsForContainer( |
581 this, wm_shelf_container->GetShellWindowId(), ¶ms); | 578 this, wm_shelf_container->GetShellWindowId(), ¶ms); |
582 Init(params); | 579 Init(params); |
583 | 580 |
584 // The shelf should not take focus when initially shown. | 581 // The shelf should not take focus when initially shown. |
585 set_focus_on_creation(false); | 582 set_focus_on_creation(false); |
586 SetContentsView(delegate_view_); | 583 SetContentsView(delegate_view_); |
587 delegate_view_->SetParentLayer(GetLayer()); | 584 delegate_view_->SetParentLayer(GetLayer()); |
588 | 585 |
589 shelf_layout_manager_ = new ShelfLayoutManager(this); | 586 shelf_layout_manager_ = new ShelfLayoutManager(this); |
590 shelf_layout_manager_->AddObserver(this); | 587 shelf_layout_manager_->AddObserver(this); |
591 aura::Window* shelf_container = | 588 aura::Window* shelf_container = |
592 WmWindowAura::GetAuraWindow(wm_shelf_container); | 589 WmWindowAura::GetAuraWindow(wm_shelf_container); |
593 shelf_container->SetLayoutManager(shelf_layout_manager_); | 590 shelf_container->SetLayoutManager(shelf_layout_manager_); |
594 shelf_layout_manager_->set_workspace_controller(workspace_controller); | 591 shelf_layout_manager_->set_workspace_controller(workspace_controller); |
595 workspace_controller->SetShelf(shelf_layout_manager_); | 592 workspace_controller->SetShelf(shelf_layout_manager_); |
596 wm_shelf_aura->SetShelfLayoutManager(shelf_layout_manager_); | 593 wm_shelf_aura->SetShelfLayoutManager(shelf_layout_manager_); |
597 | 594 |
598 // TODO(jamescook): Move ownership to RootWindowController. | 595 // TODO(jamescook): Move ownership to RootWindowController. |
599 status_area_widget_ = | 596 status_area_widget_ = |
600 new StatusAreaWidget(wm_status_container, wm_shelf_aura); | 597 new StatusAreaWidget(wm_status_container, wm_shelf_aura); |
601 status_area_widget_->CreateTrayViews(); | 598 status_area_widget_->CreateTrayViews(); |
602 if (Shell::GetInstance()->session_state_delegate()-> | 599 if (Shell::GetInstance() |
603 IsActiveUserSessionStarted()) { | 600 ->session_state_delegate() |
| 601 ->IsActiveUserSessionStarted()) { |
604 status_area_widget_->Show(); | 602 status_area_widget_->Show(); |
605 } | 603 } |
606 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); | 604 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); |
607 | 605 |
608 aura::Window* status_container = | 606 aura::Window* status_container = |
609 WmWindowAura::GetAuraWindow(wm_status_container); | 607 WmWindowAura::GetAuraWindow(wm_status_container); |
610 status_container->SetLayoutManager( | 608 status_container->SetLayoutManager( |
611 new StatusAreaLayoutManager(status_container, this)); | 609 new StatusAreaLayoutManager(status_container, this)); |
612 | 610 |
613 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 611 shelf_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
(...skipping 13 matching lines...) Expand all Loading... |
627 } | 625 } |
628 | 626 |
629 void ShelfWidget::SetPaintsBackground( | 627 void ShelfWidget::SetPaintsBackground( |
630 ShelfBackgroundType background_type, | 628 ShelfBackgroundType background_type, |
631 BackgroundAnimatorChangeType change_type) { | 629 BackgroundAnimatorChangeType change_type) { |
632 ui::Layer* opaque_background = delegate_view_->opaque_background(); | 630 ui::Layer* opaque_background = delegate_view_->opaque_background(); |
633 float target_opacity = | 631 float target_opacity = |
634 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; | 632 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; |
635 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; | 633 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_background_animation; |
636 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { | 634 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { |
637 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( | 635 opaque_background_animation.reset( |
638 opaque_background->GetAnimator())); | 636 new ui::ScopedLayerAnimationSettings(opaque_background->GetAnimator())); |
639 opaque_background_animation->SetTransitionDuration( | 637 opaque_background_animation->SetTransitionDuration( |
640 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); | 638 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs)); |
641 } | 639 } |
642 opaque_background->SetOpacity(target_opacity); | 640 opaque_background->SetOpacity(target_opacity); |
643 | 641 |
644 // TODO(mukai): use ui::Layer on both opaque_background and normal background | 642 // TODO(mukai): use ui::Layer on both opaque_background and normal background |
645 // retire background_animator_ at all. It would be simpler. | 643 // retire background_animator_ at all. It would be simpler. |
646 // See also DockedBackgroundWidget::SetPaintsBackground. | 644 // See also DockedBackgroundWidget::SetPaintsBackground. |
647 background_animator_.SetPaintsBackground( | 645 background_animator_.SetPaintsBackground( |
648 background_type != SHELF_BACKGROUND_DEFAULT, change_type); | 646 background_type != SHELF_BACKGROUND_DEFAULT, change_type); |
649 } | 647 } |
650 | 648 |
651 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 649 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
652 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) | 650 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) |
653 return SHELF_BACKGROUND_MAXIMIZED; | 651 return SHELF_BACKGROUND_MAXIMIZED; |
654 if (background_animator_.paints_background()) | 652 if (background_animator_.paints_background()) |
655 return SHELF_BACKGROUND_OVERLAP; | 653 return SHELF_BACKGROUND_OVERLAP; |
656 | 654 |
657 return SHELF_BACKGROUND_DEFAULT; | 655 return SHELF_BACKGROUND_DEFAULT; |
658 } | 656 } |
659 | 657 |
660 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { | 658 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) { |
661 if (IsShelfHiddenBehindBlackBar() == hide) | 659 if (IsShelfHiddenBehindBlackBar() == hide) |
662 return; | 660 return; |
663 | 661 |
664 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); | 662 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground(); |
665 float target_opacity = hide ? 1.0f : 0.0f; | 663 float target_opacity = hide ? 1.0f : 0.0f; |
666 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; | 664 std::unique_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation; |
667 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings( | 665 opaque_foreground_animation.reset( |
668 opaque_foreground->GetAnimator())); | 666 new ui::ScopedLayerAnimationSettings(opaque_foreground->GetAnimator())); |
669 opaque_foreground_animation->SetTransitionDuration( | 667 opaque_foreground_animation->SetTransitionDuration( |
670 base::TimeDelta::FromMilliseconds(animation_time_ms)); | 668 base::TimeDelta::FromMilliseconds(animation_time_ms)); |
671 opaque_foreground_animation->SetPreemptionStrategy( | 669 opaque_foreground_animation->SetPreemptionStrategy( |
672 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 670 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
673 | 671 |
674 opaque_foreground->SetOpacity(target_opacity); | 672 opaque_foreground->SetOpacity(target_opacity); |
675 } | 673 } |
676 | 674 |
677 bool ShelfWidget::IsShelfHiddenBehindBlackBar() const { | 675 bool ShelfWidget::IsShelfHiddenBehindBlackBar() const { |
678 return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f; | 676 return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); | 824 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); |
827 } | 825 } |
828 | 826 |
829 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { | 827 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { |
830 Widget::OnGestureEvent(event); | 828 Widget::OnGestureEvent(event); |
831 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | 829 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) |
832 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); | 830 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); |
833 } | 831 } |
834 | 832 |
835 } // namespace ash | 833 } // namespace ash |
OLD | NEW |