| 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 19 matching lines...) Expand all Loading... |
| 30 #include "base/i18n/rtl.h" | 30 #include "base/i18n/rtl.h" |
| 31 #include "ui/base/ui_base_switches.h" | 31 #include "ui/base/ui_base_switches.h" |
| 32 #include "ui/compositor/layer.h" | 32 #include "ui/compositor/layer.h" |
| 33 #include "ui/compositor/layer_animation_observer.h" | 33 #include "ui/compositor/layer_animation_observer.h" |
| 34 #include "ui/compositor/layer_animator.h" | 34 #include "ui/compositor/layer_animator.h" |
| 35 #include "ui/compositor/scoped_layer_animation_settings.h" | 35 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 36 #include "ui/display/display.h" | 36 #include "ui/display/display.h" |
| 37 #include "ui/display/screen.h" | 37 #include "ui/display/screen.h" |
| 38 #include "ui/events/event.h" | 38 #include "ui/events/event.h" |
| 39 #include "ui/events/event_handler.h" | 39 #include "ui/events/event_handler.h" |
| 40 #include "ui/gfx/animation/animation_change_type.h" |
| 40 #include "ui/keyboard/keyboard_controller.h" | 41 #include "ui/keyboard/keyboard_controller.h" |
| 41 #include "ui/keyboard/keyboard_util.h" | 42 #include "ui/keyboard/keyboard_util.h" |
| 42 #include "ui/views/border.h" | 43 #include "ui/views/border.h" |
| 43 #include "ui/views/widget/widget.h" | 44 #include "ui/views/widget/widget.h" |
| 44 | 45 |
| 45 namespace ash { | 46 namespace ash { |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 // Delay before showing the shelf. This is after the mouse stops moving. | 49 // Delay before showing the shelf. This is after the mouse stops moving. |
| 49 const int kAutoHideDelayMS = 200; | 50 const int kAutoHideDelayMS = 200; |
| (...skipping 39 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(gfx::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(gfx::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 gfx::AnimationChangeType change_type = gfx::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 = gfx::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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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( |
| 818 BackgroundAnimatorChangeType type) { | 819 gfx::AnimationChangeType type) { |
| 819 const ShelfBackgroundType new_background_type(GetShelfBackgroundType()); | 820 const ShelfBackgroundType new_background_type(GetShelfBackgroundType()); |
| 820 | 821 |
| 821 if (new_background_type == shelf_background_type_) | 822 if (new_background_type == shelf_background_type_) |
| 822 return; | 823 return; |
| 823 | 824 |
| 824 shelf_background_type_ = new_background_type; | 825 shelf_background_type_ = new_background_type; |
| 825 for (auto& observer : observers_) | 826 for (auto& observer : observers_) |
| 826 observer.OnBackgroundUpdated(shelf_background_type_, type); | 827 observer.OnBackgroundUpdated(shelf_background_type_, type); |
| 827 } | 828 } |
| 828 | 829 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 void ShelfLayoutManager::OnDockBoundsChanging( | 975 void ShelfLayoutManager::OnDockBoundsChanging( |
| 975 const gfx::Rect& dock_bounds, | 976 const gfx::Rect& dock_bounds, |
| 976 DockedWindowLayoutManagerObserver::Reason reason) { | 977 DockedWindowLayoutManagerObserver::Reason reason) { |
| 977 // Skip shelf layout in case docked notification originates from this class. | 978 // Skip shelf layout in case docked notification originates from this class. |
| 978 if (reason == DISPLAY_INSETS_CHANGED) | 979 if (reason == DISPLAY_INSETS_CHANGED) |
| 979 return; | 980 return; |
| 980 if (dock_bounds_ != dock_bounds) { | 981 if (dock_bounds_ != dock_bounds) { |
| 981 dock_bounds_ = dock_bounds; | 982 dock_bounds_ = dock_bounds; |
| 982 OnWindowResized(); | 983 OnWindowResized(); |
| 983 UpdateVisibilityState(); | 984 UpdateVisibilityState(); |
| 984 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 985 MaybeUpdateShelfBackground(gfx::AnimationChangeType::ANIMATE); |
| 985 } | 986 } |
| 986 } | 987 } |
| 987 | 988 |
| 988 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) { | 989 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) { |
| 989 if (event == EVENT_LOCK_ANIMATION_STARTED) { | 990 if (event == EVENT_LOCK_ANIMATION_STARTED) { |
| 990 // Enter the screen locked state and update the visibility to avoid an odd | 991 // Enter the screen locked state and update the visibility to avoid an odd |
| 991 // animation when transitioning the orientation from L/R to bottom. | 992 // animation when transitioning the orientation from L/R to bottom. |
| 992 state_.pre_lock_screen_animation_active = true; | 993 state_.pre_lock_screen_animation_active = true; |
| 993 UpdateShelfVisibilityAfterLoginUIChange(); | 994 UpdateShelfVisibilityAfterLoginUIChange(); |
| 994 } else { | 995 } else { |
| 995 state_.pre_lock_screen_animation_active = false; | 996 state_.pre_lock_screen_animation_active = false; |
| 996 } | 997 } |
| 997 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 998 MaybeUpdateShelfBackground(gfx::AnimationChangeType::ANIMATE); |
| 998 } | 999 } |
| 999 | 1000 |
| 1000 void ShelfLayoutManager::SessionStateChanged( | 1001 void ShelfLayoutManager::SessionStateChanged( |
| 1001 session_manager::SessionState state) { | 1002 session_manager::SessionState state) { |
| 1002 // Check transition changes to/from the add user to session and change the | 1003 // Check transition changes to/from the add user to session and change the |
| 1003 // shelf alignment accordingly | 1004 // shelf alignment accordingly |
| 1004 const bool was_adding_user = state_.IsAddingSecondaryUser(); | 1005 const bool was_adding_user = state_.IsAddingSecondaryUser(); |
| 1005 const bool was_locked = state_.IsScreenLocked(); | 1006 const bool was_locked = state_.IsScreenLocked(); |
| 1006 state_.session_state = state; | 1007 state_.session_state = state; |
| 1007 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 1008 MaybeUpdateShelfBackground(gfx::AnimationChangeType::ANIMATE); |
| 1008 if (was_adding_user != state_.IsAddingSecondaryUser()) { | 1009 if (was_adding_user != state_.IsAddingSecondaryUser()) { |
| 1009 UpdateShelfVisibilityAfterLoginUIChange(); | 1010 UpdateShelfVisibilityAfterLoginUIChange(); |
| 1010 return; | 1011 return; |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 // Force the shelf to layout for alignment (bottom if locked, restore the | 1014 // Force the shelf to layout for alignment (bottom if locked, restore the |
| 1014 // previous alignment otherwise). | 1015 // previous alignment otherwise). |
| 1015 if (was_locked != state_.IsScreenLocked()) | 1016 if (was_locked != state_.IsScreenLocked()) |
| 1016 UpdateShelfVisibilityAfterLoginUIChange(); | 1017 UpdateShelfVisibilityAfterLoginUIChange(); |
| 1017 | 1018 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 | 1054 |
| 1054 //////////////////////////////////////////////////////////////////////////////// | 1055 //////////////////////////////////////////////////////////////////////////////// |
| 1055 // ShelfLayoutManager, Gesture functions: | 1056 // ShelfLayoutManager, Gesture functions: |
| 1056 | 1057 |
| 1057 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { | 1058 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { |
| 1058 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; | 1059 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; |
| 1059 gesture_drag_amount_ = 0.f; | 1060 gesture_drag_amount_ = 0.f; |
| 1060 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE | 1061 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE |
| 1061 ? auto_hide_state() | 1062 ? auto_hide_state() |
| 1062 : SHELF_AUTO_HIDE_SHOWN; | 1063 : SHELF_AUTO_HIDE_SHOWN; |
| 1063 MaybeUpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); | 1064 MaybeUpdateShelfBackground(gfx::AnimationChangeType::ANIMATE); |
| 1064 } | 1065 } |
| 1065 | 1066 |
| 1066 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { | 1067 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { |
| 1067 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), | 1068 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), |
| 1068 gesture.details().scroll_x()); | 1069 gesture.details().scroll_x()); |
| 1069 LayoutShelf(); | 1070 LayoutShelf(); |
| 1070 } | 1071 } |
| 1071 | 1072 |
| 1072 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { | 1073 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
| 1073 bool horizontal = wm_shelf_->IsHorizontalAlignment(); | 1074 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; | 1140 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1140 } | 1141 } |
| 1141 | 1142 |
| 1142 void ShelfLayoutManager::CancelGestureDrag() { | 1143 void ShelfLayoutManager::CancelGestureDrag() { |
| 1143 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1144 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
| 1144 UpdateVisibilityState(); | 1145 UpdateVisibilityState(); |
| 1145 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1146 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1146 } | 1147 } |
| 1147 | 1148 |
| 1148 } // namespace ash | 1149 } // namespace ash |
| OLD | NEW |