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_layout_manager.h" | 5 #include "ash/shelf/shelf_layout_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <cstring> | 9 #include <cstring> |
10 #include <string> | 10 #include <string> |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 644 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
645 OnAutoHideStateChanged(state_.auto_hide_state)); | 645 OnAutoHideStateChanged(state_.auto_hide_state)); |
646 } | 646 } |
647 } | 647 } |
648 | 648 |
649 void ShelfLayoutManager::UpdateBoundsAndOpacity( | 649 void ShelfLayoutManager::UpdateBoundsAndOpacity( |
650 const TargetBounds& target_bounds, | 650 const TargetBounds& target_bounds, |
651 bool animate, | 651 bool animate, |
652 ui::ImplicitAnimationObserver* observer) { | 652 ui::ImplicitAnimationObserver* observer) { |
653 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); | 653 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); |
| 654 { |
| 655 ui::ScopedLayerAnimationSettings shelf_animation_setter( |
| 656 GetLayer(shelf_)->GetAnimator()); |
| 657 ui::ScopedLayerAnimationSettings status_animation_setter( |
| 658 GetLayer(shelf_->status_area_widget())->GetAnimator()); |
| 659 if (animate) { |
| 660 int duration = duration_override_in_ms_ ? duration_override_in_ms_ : |
| 661 kCrossFadeDurationMS; |
| 662 shelf_animation_setter.SetTransitionDuration( |
| 663 base::TimeDelta::FromMilliseconds(duration)); |
| 664 shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); |
| 665 shelf_animation_setter.SetPreemptionStrategy( |
| 666 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 667 status_animation_setter.SetTransitionDuration( |
| 668 base::TimeDelta::FromMilliseconds(duration)); |
| 669 status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); |
| 670 status_animation_setter.SetPreemptionStrategy( |
| 671 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 672 } else { |
| 673 StopAnimating(); |
| 674 shelf_animation_setter.SetTransitionDuration(base::TimeDelta()); |
| 675 status_animation_setter.SetTransitionDuration(base::TimeDelta()); |
| 676 } |
| 677 if (observer) |
| 678 status_animation_setter.AddObserver(observer); |
654 | 679 |
655 ui::ScopedLayerAnimationSettings shelf_animation_setter( | 680 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); |
656 GetLayer(shelf_)->GetAnimator()); | 681 shelf_->SetBounds(ScreenUtil::ConvertRectToScreen( |
657 ui::ScopedLayerAnimationSettings status_animation_setter( | 682 shelf_->GetNativeView()->parent(), |
658 GetLayer(shelf_->status_area_widget())->GetAnimator()); | 683 target_bounds.shelf_bounds_in_root)); |
659 if (animate) { | 684 |
660 int duration = duration_override_in_ms_ ? duration_override_in_ms_ : | 685 GetLayer(shelf_->status_area_widget())->SetOpacity( |
661 kCrossFadeDurationMS; | 686 target_bounds.status_opacity); |
662 shelf_animation_setter.SetTransitionDuration( | 687 |
663 base::TimeDelta::FromMilliseconds(duration)); | 688 // Having a window which is visible but does not have an opacity is an |
664 shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); | 689 // illegal state. We therefore hide the shelf here if required. |
665 shelf_animation_setter.SetPreemptionStrategy( | 690 if (!target_bounds.status_opacity) |
666 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 691 shelf_->status_area_widget()->Hide(); |
667 status_animation_setter.SetTransitionDuration( | 692 // Setting visibility during an animation causes the visibility property to |
668 base::TimeDelta::FromMilliseconds(duration)); | 693 // animate. Override the animation settings to immediately set the |
669 status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); | 694 // visibility property. Opacity will still animate. |
670 status_animation_setter.SetPreemptionStrategy( | 695 |
671 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 696 // TODO(harrym): Once status area widget is a child view of shelf |
672 } else { | 697 // this can be simplified. |
673 StopAnimating(); | 698 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; |
674 shelf_animation_setter.SetTransitionDuration(base::TimeDelta()); | 699 status_bounds.set_x(status_bounds.x() + |
675 status_animation_setter.SetTransitionDuration(base::TimeDelta()); | 700 target_bounds.shelf_bounds_in_root.x()); |
| 701 status_bounds.set_y(status_bounds.y() + |
| 702 target_bounds.shelf_bounds_in_root.y()); |
| 703 shelf_->status_area_widget()->SetBounds( |
| 704 ScreenUtil::ConvertRectToScreen( |
| 705 shelf_->status_area_widget()->GetNativeView()->parent(), |
| 706 status_bounds)); |
| 707 SessionStateDelegate* session_state_delegate = |
| 708 Shell::GetInstance()->session_state_delegate(); |
| 709 if (!state_.is_screen_locked) { |
| 710 gfx::Insets insets; |
| 711 // If user session is blocked (login to new user session or add user to |
| 712 // the existing session - multi-profile) then give 100% of work area only |
| 713 // if keyboard is not shown. |
| 714 if (!session_state_delegate->IsUserSessionBlocked() || |
| 715 !keyboard_bounds_.IsEmpty()) { |
| 716 insets = target_bounds.work_area_insets; |
| 717 } |
| 718 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, insets); |
| 719 } |
676 } | 720 } |
677 if (observer) | |
678 status_animation_setter.AddObserver(observer); | |
679 | 721 |
680 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); | 722 // Setting visibility during an animation causes the visibility property to |
681 shelf_->SetBounds(ScreenUtil::ConvertRectToScreen( | 723 // animate. Set the visibility property without an animation. |
682 shelf_->GetNativeView()->parent(), | 724 if (target_bounds.status_opacity) |
683 target_bounds.shelf_bounds_in_root)); | |
684 | |
685 GetLayer(shelf_->status_area_widget())->SetOpacity( | |
686 target_bounds.status_opacity); | |
687 | |
688 // Having a window which is visible but does not have an opacity is an illegal | |
689 // state. We therefore show / hide the shelf here if required. | |
690 if (!target_bounds.status_opacity) | |
691 shelf_->status_area_widget()->Hide(); | |
692 else if (target_bounds.status_opacity) | |
693 shelf_->status_area_widget()->Show(); | 725 shelf_->status_area_widget()->Show(); |
694 | |
695 // TODO(harrym): Once status area widget is a child view of shelf | |
696 // this can be simplified. | |
697 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | |
698 status_bounds.set_x(status_bounds.x() + | |
699 target_bounds.shelf_bounds_in_root.x()); | |
700 status_bounds.set_y(status_bounds.y() + | |
701 target_bounds.shelf_bounds_in_root.y()); | |
702 shelf_->status_area_widget()->SetBounds( | |
703 ScreenUtil::ConvertRectToScreen( | |
704 shelf_->status_area_widget()->GetNativeView()->parent(), | |
705 status_bounds)); | |
706 SessionStateDelegate* session_state_delegate = | |
707 Shell::GetInstance()->session_state_delegate(); | |
708 if (!state_.is_screen_locked) { | |
709 gfx::Insets insets; | |
710 // If user session is blocked (login to new user session or add user to | |
711 // the existing session - multi-profile) then give 100% of work area only if | |
712 // keyboard is not shown. | |
713 if (!session_state_delegate->IsUserSessionBlocked() || | |
714 !keyboard_bounds_.IsEmpty()) { | |
715 insets = target_bounds.work_area_insets; | |
716 } | |
717 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, insets); | |
718 } | |
719 } | 726 } |
720 | 727 |
721 void ShelfLayoutManager::StopAnimating() { | 728 void ShelfLayoutManager::StopAnimating() { |
722 GetLayer(shelf_)->GetAnimator()->StopAnimating(); | 729 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
723 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); | 730 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
724 } | 731 } |
725 | 732 |
726 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 733 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
727 *width = *height = 0; | 734 *width = *height = 0; |
728 gfx::Size status_size( | 735 gfx::Size status_size( |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 | 1147 |
1141 void ShelfLayoutManager::SessionStateChanged( | 1148 void ShelfLayoutManager::SessionStateChanged( |
1142 SessionStateDelegate::SessionState state) { | 1149 SessionStateDelegate::SessionState state) { |
1143 TargetBounds target_bounds; | 1150 TargetBounds target_bounds; |
1144 CalculateTargetBounds(state_, &target_bounds); | 1151 CalculateTargetBounds(state_, &target_bounds); |
1145 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1152 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1146 UpdateVisibilityState(); | 1153 UpdateVisibilityState(); |
1147 } | 1154 } |
1148 | 1155 |
1149 } // namespace ash | 1156 } // namespace ash |
OLD | NEW |