OLD | NEW |
(Empty) | |
| 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 |
| 5 #include "ash/shelf/shelf_locking_manager.h" |
| 6 |
| 7 #include "ash/session/session_state_delegate.h" |
| 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shell.h" |
| 10 #include "ash/wm/lock_state_controller.h" |
| 11 |
| 12 namespace ash { |
| 13 |
| 14 ShelfLockingManager::ShelfLockingManager(Shelf* shelf) : shelf_(shelf) { |
| 15 Shell* shell = Shell::GetInstance(); |
| 16 shell->lock_state_controller()->AddObserver(this); |
| 17 SessionStateDelegate* delegate = shell->session_state_delegate(); |
| 18 session_locked_ = |
| 19 delegate->GetSessionState() != SessionStateDelegate::SESSION_STATE_ACTIVE; |
| 20 screen_locked_ = delegate->IsScreenLocked(); |
| 21 delegate->AddSessionStateObserver(this); |
| 22 shell->AddShellObserver(this); |
| 23 } |
| 24 |
| 25 ShelfLockingManager::~ShelfLockingManager() { |
| 26 Shell* shell = Shell::GetInstance(); |
| 27 shell->lock_state_controller()->RemoveObserver(this); |
| 28 shell->session_state_delegate()->RemoveSessionStateObserver(this); |
| 29 shell->RemoveShellObserver(this); |
| 30 } |
| 31 |
| 32 void ShelfLockingManager::OnLockStateChanged(bool locked) { |
| 33 screen_locked_ = locked; |
| 34 UpdateLockedState(); |
| 35 } |
| 36 |
| 37 void ShelfLockingManager::SessionStateChanged( |
| 38 SessionStateDelegate::SessionState state) { |
| 39 session_locked_ = state != SessionStateDelegate::SESSION_STATE_ACTIVE; |
| 40 UpdateLockedState(); |
| 41 } |
| 42 |
| 43 void ShelfLockingManager::OnLockStateEvent(EventType event) { |
| 44 // This is only called when locking the screen; there is no unlock event here. |
| 45 // It's also called when the screen lock animation begins and should help the |
| 46 // shelf appear locked much earlier than ShellObserver::OnLockStateChanged. |
| 47 screen_locked_ = true; |
| 48 UpdateLockedState(); |
| 49 } |
| 50 |
| 51 void ShelfLockingManager::UpdateLockedState() { |
| 52 const bool should_be_locked = screen_locked_ || session_locked_; |
| 53 const ShelfAlignment alignment = shelf_->alignment(); |
| 54 if (should_be_locked && alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
| 55 stored_alignment_ = alignment; |
| 56 shelf_->SetAlignment(SHELF_ALIGNMENT_BOTTOM_LOCKED); |
| 57 } else if (!should_be_locked && alignment == SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
| 58 shelf_->SetAlignment(stored_alignment_); |
| 59 } |
| 60 } |
| 61 |
| 62 } // namespace ash |
OLD | NEW |