shelf_locking_manager.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/shelf/shelf_locking_manager.h"
  5. #include "ash/session/session_controller_impl.h"
  6. #include "ash/shelf/shelf.h"
  7. #include "ash/shell.h"
  8. #include "ash/wm/lock_state_controller.h"
  9. namespace ash {
  10. ShelfLockingManager::ShelfLockingManager(Shelf* shelf)
  11. : shelf_(shelf), scoped_session_observer_(this) {
  12. DCHECK(shelf_);
  13. Shell::Get()->lock_state_controller()->AddObserver(this);
  14. SessionControllerImpl* controller = Shell::Get()->session_controller();
  15. session_locked_ =
  16. controller->GetSessionState() != session_manager::SessionState::ACTIVE;
  17. screen_locked_ = controller->IsScreenLocked();
  18. }
  19. ShelfLockingManager::~ShelfLockingManager() {
  20. // |this| is destroyed after LockStateController for the primary display.
  21. if (Shell::Get()->lock_state_controller())
  22. Shell::Get()->lock_state_controller()->RemoveObserver(this);
  23. }
  24. void ShelfLockingManager::OnLockStateChanged(bool locked) {
  25. screen_locked_ = locked;
  26. UpdateLockedState();
  27. }
  28. void ShelfLockingManager::OnSessionStateChanged(
  29. session_manager::SessionState state) {
  30. session_locked_ = state != session_manager::SessionState::ACTIVE;
  31. UpdateLockedState();
  32. }
  33. void ShelfLockingManager::OnLockStateEvent(EventType event) {
  34. // Lock when the animation starts, ignoring pre-lock. There's no unlock event.
  35. screen_locked_ |= event == EVENT_LOCK_ANIMATION_STARTED;
  36. UpdateLockedState();
  37. }
  38. void ShelfLockingManager::UpdateLockedState() {
  39. const ShelfAlignment alignment = shelf_->alignment();
  40. if (is_locked() && alignment != ShelfAlignment::kBottomLocked) {
  41. stored_alignment_ = alignment;
  42. shelf_->SetAlignment(ShelfAlignment::kBottomLocked);
  43. } else if (!is_locked() && alignment == ShelfAlignment::kBottomLocked) {
  44. shelf_->SetAlignment(stored_alignment_);
  45. }
  46. }
  47. } // namespace ash