| 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 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 : public ui::ImplicitAnimationObserver { | 89 : public ui::ImplicitAnimationObserver { |
| 90 public: | 90 public: |
| 91 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { | 91 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { |
| 92 shelf_->update_shelf_observer_ = this; | 92 shelf_->update_shelf_observer_ = this; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void Detach() { shelf_ = NULL; } | 95 void Detach() { shelf_ = NULL; } |
| 96 | 96 |
| 97 void OnImplicitAnimationsCompleted() override { | 97 void OnImplicitAnimationsCompleted() override { |
| 98 if (shelf_) | 98 if (shelf_) |
| 99 shelf_->MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 99 shelf_->MaybeUpdateShelfBackground(gfx::ANIMATION_CHANGE_ANIMATE); |
| 100 delete this; | 100 delete this; |
| 101 } | 101 } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 ~UpdateShelfObserver() override { | 104 ~UpdateShelfObserver() override { |
| 105 if (shelf_) | 105 if (shelf_) |
| 106 shelf_->update_shelf_observer_ = NULL; | 106 shelf_->update_shelf_observer_ = NULL; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Shelf we're in. NULL if deleted before we're deleted. | 109 // 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) { | 318 WmWindow* target) { |
| 319 if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_) | 319 if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_) |
| 320 return; | 320 return; |
| 321 | 321 |
| 322 if (IsShelfWindow(target) && ProcessGestureEvent(*event)) | 322 if (IsShelfWindow(target) && ProcessGestureEvent(*event)) |
| 323 event->StopPropagation(); | 323 event->StopPropagation(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { | 326 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { |
| 327 window_overlaps_shelf_ = value; | 327 window_overlaps_shelf_ = value; |
| 328 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 328 MaybeUpdateShelfBackground(gfx::ANIMATION_CHANGE_ANIMATE); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver* observer) { | 331 void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver* observer) { |
| 332 observers_.AddObserver(observer); | 332 observers_.AddObserver(observer); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { | 335 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { |
| 336 observers_.RemoveObserver(observer); | 336 observers_.RemoveObserver(observer); |
| 337 } | 337 } |
| 338 | 338 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 return; // Nothing changed. | 493 return; // Nothing changed. |
| 494 | 494 |
| 495 for (auto& observer : observers_) | 495 for (auto& observer : observers_) |
| 496 observer.WillChangeVisibilityState(visibility_state); | 496 observer.WillChangeVisibilityState(visibility_state); |
| 497 | 497 |
| 498 StopAutoHideTimer(); | 498 StopAutoHideTimer(); |
| 499 | 499 |
| 500 State old_state = state_; | 500 State old_state = state_; |
| 501 state_ = state; | 501 state_ = state; |
| 502 | 502 |
| 503 BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE; | 503 gfx::AnimationChangeType change_type = gfx::ANIMATION_CHANGE_ANIMATE; |
| 504 bool delay_background_change = false; | 504 bool delay_background_change = false; |
| 505 | 505 |
| 506 // Do not animate the background when: | 506 // Do not animate the background when: |
| 507 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf | 507 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf |
| 508 // in maximized mode. | 508 // in maximized mode. |
| 509 // - Going from an auto hidden shelf in maximized mode to a visible shelf in | 509 // - Going from an auto hidden shelf in maximized mode to a visible shelf in |
| 510 // maximized mode. | 510 // maximized mode. |
| 511 if (state.visibility_state == SHELF_VISIBLE && | 511 if (state.visibility_state == SHELF_VISIBLE && |
| 512 state.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED && | 512 state.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED && |
| 513 old_state.visibility_state != SHELF_VISIBLE) { | 513 old_state.visibility_state != SHELF_VISIBLE) { |
| 514 change_type = BACKGROUND_CHANGE_IMMEDIATE; | 514 change_type = gfx::ANIMATION_CHANGE_IMMEDIATE; |
| 515 } else { | 515 } else { |
| 516 // Delay the animation when the shelf was hidden, and has just been made | 516 // Delay the animation when the shelf was hidden, and has just been made |
| 517 // visible (e.g. using a gesture-drag). | 517 // visible (e.g. using a gesture-drag). |
| 518 if (state.visibility_state == SHELF_VISIBLE && | 518 if (state.visibility_state == SHELF_VISIBLE && |
| 519 old_state.visibility_state == SHELF_AUTO_HIDE && | 519 old_state.visibility_state == SHELF_AUTO_HIDE && |
| 520 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 520 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
| 521 delay_background_change = true; | 521 delay_background_change = true; |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 target_bounds->status_bounds_in_shelf.set_x(0); | 808 target_bounds->status_bounds_in_shelf.set_x(0); |
| 809 } else { | 809 } else { |
| 810 target_bounds->status_bounds_in_shelf.set_x( | 810 target_bounds->status_bounds_in_shelf.set_x( |
| 811 target_bounds->shelf_bounds_in_root.width() - | 811 target_bounds->shelf_bounds_in_root.width() - |
| 812 GetShelfConstant(SHELF_SIZE)); | 812 GetShelfConstant(SHELF_SIZE)); |
| 813 } | 813 } |
| 814 } | 814 } |
| 815 } | 815 } |
| 816 | 816 |
| 817 void ShelfLayoutManager::MaybeUpdateShelfBackground( | 817 void ShelfLayoutManager::MaybeUpdateShelfBackground( |
| 818 BackgroundAnimatorChangeType type) { | 818 gfx::AnimationChangeType 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(gfx::ANIMATION_CHANGE_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(gfx::ANIMATION_CHANGE_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(gfx::ANIMATION_CHANGE_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(gfx::ANIMATION_CHANGE_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 |