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/common/shelf/shelf_layout_manager.h" | 5 #include "ash/common/shelf/shelf_layout_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "ash/animation/animation_change_type.h" |
11 #include "ash/common/material_design/material_design_controller.h" | 12 #include "ash/common/material_design/material_design_controller.h" |
12 #include "ash/common/session/session_controller.h" | 13 #include "ash/common/session/session_controller.h" |
13 #include "ash/common/session/session_state_delegate.h" | 14 #include "ash/common/session/session_state_delegate.h" |
14 #include "ash/common/shelf/shelf_constants.h" | 15 #include "ash/common/shelf/shelf_constants.h" |
15 #include "ash/common/shelf/shelf_layout_manager_observer.h" | 16 #include "ash/common/shelf/shelf_layout_manager_observer.h" |
16 #include "ash/common/shelf/shelf_widget.h" | 17 #include "ash/common/shelf/shelf_widget.h" |
17 #include "ash/common/shelf/wm_shelf.h" | 18 #include "ash/common/shelf/wm_shelf.h" |
18 #include "ash/common/system/status_area_widget.h" | 19 #include "ash/common/system/status_area_widget.h" |
19 #include "ash/common/wm/fullscreen_window_finder.h" | 20 #include "ash/common/wm/fullscreen_window_finder.h" |
20 #include "ash/common/wm/mru_window_tracker.h" | 21 #include "ash/common/wm/mru_window_tracker.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 : public ui::ImplicitAnimationObserver { | 90 : public ui::ImplicitAnimationObserver { |
90 public: | 91 public: |
91 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { | 92 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { |
92 shelf_->update_shelf_observer_ = this; | 93 shelf_->update_shelf_observer_ = this; |
93 } | 94 } |
94 | 95 |
95 void Detach() { shelf_ = NULL; } | 96 void Detach() { shelf_ = NULL; } |
96 | 97 |
97 void OnImplicitAnimationsCompleted() override { | 98 void OnImplicitAnimationsCompleted() override { |
98 if (shelf_) | 99 if (shelf_) |
99 shelf_->MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 100 shelf_->MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
100 delete this; | 101 delete this; |
101 } | 102 } |
102 | 103 |
103 private: | 104 private: |
104 ~UpdateShelfObserver() override { | 105 ~UpdateShelfObserver() override { |
105 if (shelf_) | 106 if (shelf_) |
106 shelf_->update_shelf_observer_ = NULL; | 107 shelf_->update_shelf_observer_ = NULL; |
107 } | 108 } |
108 | 109 |
109 // Shelf we're in. NULL if deleted before we're deleted. | 110 // Shelf we're in. NULL if deleted before we're deleted. |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 WmWindow* target) { | 319 WmWindow* target) { |
319 if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_) | 320 if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_) |
320 return; | 321 return; |
321 | 322 |
322 if (IsShelfWindow(target) && ProcessGestureEvent(*event)) | 323 if (IsShelfWindow(target) && ProcessGestureEvent(*event)) |
323 event->StopPropagation(); | 324 event->StopPropagation(); |
324 } | 325 } |
325 | 326 |
326 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { | 327 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { |
327 window_overlaps_shelf_ = value; | 328 window_overlaps_shelf_ = value; |
328 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 329 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
329 } | 330 } |
330 | 331 |
331 void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver* observer) { | 332 void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver* observer) { |
332 observers_.AddObserver(observer); | 333 observers_.AddObserver(observer); |
333 } | 334 } |
334 | 335 |
335 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { | 336 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { |
336 observers_.RemoveObserver(observer); | 337 observers_.RemoveObserver(observer); |
337 } | 338 } |
338 | 339 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 return; // Nothing changed. | 494 return; // Nothing changed. |
494 | 495 |
495 for (auto& observer : observers_) | 496 for (auto& observer : observers_) |
496 observer.WillChangeVisibilityState(visibility_state); | 497 observer.WillChangeVisibilityState(visibility_state); |
497 | 498 |
498 StopAutoHideTimer(); | 499 StopAutoHideTimer(); |
499 | 500 |
500 State old_state = state_; | 501 State old_state = state_; |
501 state_ = state; | 502 state_ = state; |
502 | 503 |
503 BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE; | 504 AnimationChangeType change_type = AnimationChangeType::ANIMATE; |
504 bool delay_background_change = false; | 505 bool delay_background_change = false; |
505 | 506 |
506 // Do not animate the background when: | 507 // Do not animate the background when: |
507 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf | 508 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf |
508 // in maximized mode. | 509 // in maximized mode. |
509 // - Going from an auto hidden shelf in maximized mode to a visible shelf in | 510 // - Going from an auto hidden shelf in maximized mode to a visible shelf in |
510 // maximized mode. | 511 // maximized mode. |
511 if (state.visibility_state == SHELF_VISIBLE && | 512 if (state.visibility_state == SHELF_VISIBLE && |
512 state.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED && | 513 state.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED && |
513 old_state.visibility_state != SHELF_VISIBLE) { | 514 old_state.visibility_state != SHELF_VISIBLE) { |
514 change_type = BACKGROUND_CHANGE_IMMEDIATE; | 515 change_type = AnimationChangeType::IMMEDIATE; |
515 } else { | 516 } else { |
516 // Delay the animation when the shelf was hidden, and has just been made | 517 // Delay the animation when the shelf was hidden, and has just been made |
517 // visible (e.g. using a gesture-drag). | 518 // visible (e.g. using a gesture-drag). |
518 if (state.visibility_state == SHELF_VISIBLE && | 519 if (state.visibility_state == SHELF_VISIBLE && |
519 old_state.visibility_state == SHELF_AUTO_HIDE && | 520 old_state.visibility_state == SHELF_AUTO_HIDE && |
520 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 521 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
521 delay_background_change = true; | 522 delay_background_change = true; |
522 } | 523 } |
523 } | 524 } |
524 | 525 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 if (right_aligned) { | 808 if (right_aligned) { |
808 target_bounds->status_bounds_in_shelf.set_x(0); | 809 target_bounds->status_bounds_in_shelf.set_x(0); |
809 } else { | 810 } else { |
810 target_bounds->status_bounds_in_shelf.set_x( | 811 target_bounds->status_bounds_in_shelf.set_x( |
811 target_bounds->shelf_bounds_in_root.width() - | 812 target_bounds->shelf_bounds_in_root.width() - |
812 GetShelfConstant(SHELF_SIZE)); | 813 GetShelfConstant(SHELF_SIZE)); |
813 } | 814 } |
814 } | 815 } |
815 } | 816 } |
816 | 817 |
817 void ShelfLayoutManager::MaybeUpdateShelfBackground( | 818 void ShelfLayoutManager::MaybeUpdateShelfBackground(AnimationChangeType type) { |
818 BackgroundAnimatorChangeType type) { | |
819 const ShelfBackgroundType new_background_type(GetShelfBackgroundType()); | 819 const ShelfBackgroundType new_background_type(GetShelfBackgroundType()); |
820 | 820 |
821 if (new_background_type == shelf_background_type_) | 821 if (new_background_type == shelf_background_type_) |
822 return; | 822 return; |
823 | 823 |
824 shelf_background_type_ = new_background_type; | 824 shelf_background_type_ = new_background_type; |
825 for (auto& observer : observers_) | 825 for (auto& observer : observers_) |
826 observer.OnBackgroundUpdated(shelf_background_type_, type); | 826 observer.OnBackgroundUpdated(shelf_background_type_, type); |
827 } | 827 } |
828 | 828 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 void ShelfLayoutManager::OnDockBoundsChanging( | 974 void ShelfLayoutManager::OnDockBoundsChanging( |
975 const gfx::Rect& dock_bounds, | 975 const gfx::Rect& dock_bounds, |
976 DockedWindowLayoutManagerObserver::Reason reason) { | 976 DockedWindowLayoutManagerObserver::Reason reason) { |
977 // Skip shelf layout in case docked notification originates from this class. | 977 // Skip shelf layout in case docked notification originates from this class. |
978 if (reason == DISPLAY_INSETS_CHANGED) | 978 if (reason == DISPLAY_INSETS_CHANGED) |
979 return; | 979 return; |
980 if (dock_bounds_ != dock_bounds) { | 980 if (dock_bounds_ != dock_bounds) { |
981 dock_bounds_ = dock_bounds; | 981 dock_bounds_ = dock_bounds; |
982 OnWindowResized(); | 982 OnWindowResized(); |
983 UpdateVisibilityState(); | 983 UpdateVisibilityState(); |
984 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 984 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
985 } | 985 } |
986 } | 986 } |
987 | 987 |
988 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) { | 988 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) { |
989 if (event == EVENT_LOCK_ANIMATION_STARTED) { | 989 if (event == EVENT_LOCK_ANIMATION_STARTED) { |
990 // Enter the screen locked state and update the visibility to avoid an odd | 990 // Enter the screen locked state and update the visibility to avoid an odd |
991 // animation when transitioning the orientation from L/R to bottom. | 991 // animation when transitioning the orientation from L/R to bottom. |
992 state_.pre_lock_screen_animation_active = true; | 992 state_.pre_lock_screen_animation_active = true; |
993 UpdateShelfVisibilityAfterLoginUIChange(); | 993 UpdateShelfVisibilityAfterLoginUIChange(); |
994 } else { | 994 } else { |
995 state_.pre_lock_screen_animation_active = false; | 995 state_.pre_lock_screen_animation_active = false; |
996 } | 996 } |
997 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 997 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
998 } | 998 } |
999 | 999 |
1000 void ShelfLayoutManager::SessionStateChanged( | 1000 void ShelfLayoutManager::SessionStateChanged( |
1001 session_manager::SessionState state) { | 1001 session_manager::SessionState state) { |
1002 // Check transition changes to/from the add user to session and change the | 1002 // Check transition changes to/from the add user to session and change the |
1003 // shelf alignment accordingly | 1003 // shelf alignment accordingly |
1004 const bool was_adding_user = state_.IsAddingSecondaryUser(); | 1004 const bool was_adding_user = state_.IsAddingSecondaryUser(); |
1005 const bool was_locked = state_.IsScreenLocked(); | 1005 const bool was_locked = state_.IsScreenLocked(); |
1006 state_.session_state = state; | 1006 state_.session_state = state; |
1007 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 1007 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
1008 if (was_adding_user != state_.IsAddingSecondaryUser()) { | 1008 if (was_adding_user != state_.IsAddingSecondaryUser()) { |
1009 UpdateShelfVisibilityAfterLoginUIChange(); | 1009 UpdateShelfVisibilityAfterLoginUIChange(); |
1010 return; | 1010 return; |
1011 } | 1011 } |
1012 | 1012 |
1013 // Force the shelf to layout for alignment (bottom if locked, restore the | 1013 // Force the shelf to layout for alignment (bottom if locked, restore the |
1014 // previous alignment otherwise). | 1014 // previous alignment otherwise). |
1015 if (was_locked != state_.IsScreenLocked()) | 1015 if (was_locked != state_.IsScreenLocked()) |
1016 UpdateShelfVisibilityAfterLoginUIChange(); | 1016 UpdateShelfVisibilityAfterLoginUIChange(); |
1017 | 1017 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 | 1053 |
1054 //////////////////////////////////////////////////////////////////////////////// | 1054 //////////////////////////////////////////////////////////////////////////////// |
1055 // ShelfLayoutManager, Gesture functions: | 1055 // ShelfLayoutManager, Gesture functions: |
1056 | 1056 |
1057 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { | 1057 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { |
1058 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; | 1058 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; |
1059 gesture_drag_amount_ = 0.f; | 1059 gesture_drag_amount_ = 0.f; |
1060 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE | 1060 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE |
1061 ? auto_hide_state() | 1061 ? auto_hide_state() |
1062 : SHELF_AUTO_HIDE_SHOWN; | 1062 : SHELF_AUTO_HIDE_SHOWN; |
1063 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 1063 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
1064 } | 1064 } |
1065 | 1065 |
1066 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { | 1066 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { |
1067 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), | 1067 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), |
1068 gesture.details().scroll_x()); | 1068 gesture.details().scroll_x()); |
1069 LayoutShelf(); | 1069 LayoutShelf(); |
1070 } | 1070 } |
1071 | 1071 |
1072 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { | 1072 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
1073 bool horizontal = wm_shelf_->IsHorizontalAlignment(); | 1073 bool horizontal = wm_shelf_->IsHorizontalAlignment(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1139 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1140 } | 1140 } |
1141 | 1141 |
1142 void ShelfLayoutManager::CancelGestureDrag() { | 1142 void ShelfLayoutManager::CancelGestureDrag() { |
1143 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1143 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
1144 UpdateVisibilityState(); | 1144 UpdateVisibilityState(); |
1145 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1145 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1146 } | 1146 } |
1147 | 1147 |
1148 } // namespace ash | 1148 } // namespace ash |
OLD | NEW |