Index: ash/wm/lock_action_handler_layout_manager.cc |
diff --git a/ash/wm/lock_action_handler_layout_manager.cc b/ash/wm/lock_action_handler_layout_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..69c70e3b596904fd48eed90c37fc268209a688ca |
--- /dev/null |
+++ b/ash/wm/lock_action_handler_layout_manager.cc |
@@ -0,0 +1,113 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/wm/lock_action_handler_layout_manager.h" |
+ |
+#include <vector> |
+ |
+#include "ash/public/cpp/shell_window_ids.h" |
+#include "ash/public/interfaces/tray_action.mojom.h" |
+#include "ash/shelf/wm_shelf.h" |
+#include "ash/shell.h" |
+#include "ash/tray_action/tray_action.h" |
+#include "ash/wm/lock_window_state.h" |
+#include "ash/wm/window_state.h" |
+#include "ash/wm/window_util.h" |
+#include "ash/wm/wm_event.h" |
+#include "ash/wm_window.h" |
+ |
+namespace ash { |
+namespace {} // namespace |
oshima
2017/05/17 18:15:59
?
tbarzic
2017/05/18 19:54:58
oops, had a constant that I remove here.
|
+ |
+LockActionHandlerLayoutManager::LockActionHandlerLayoutManager( |
+ aura::Window* window, |
+ WmShelf* wm_shelf) |
+ : LockLayoutManager(window), |
+ shelf_observer_(this), |
+ tray_action_observer_(this) { |
+ TrayAction* tray_action = Shell::Get()->tray_action(); |
+ tray_action_observer_.Add(tray_action); |
+ shelf_observer_.Add(wm_shelf); |
+} |
+ |
+LockActionHandlerLayoutManager::~LockActionHandlerLayoutManager() = default; |
+ |
+void LockActionHandlerLayoutManager::OnWindowAddedToLayout( |
+ aura::Window* child) { |
+ wm::WindowState* window_state = |
+ LockWindowState::SetLockWindowStateWithVisibleShelf(WmWindow::Get(child)); |
+ wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
+ window_state->OnWMEvent(&event); |
+ |
+ // If a child is added while tray action state is active, make sure it gets |
+ // focused - focusing the window only on child visibility changed might not |
+ // be enough, as the window might have already been visible (in case it got |
+ // reparented from the background window container). |
+ mojom::TrayActionState action_state = |
+ Shell::Get()->tray_action()->GetLockScreenNoteState(); |
+ if (child->IsVisible()) { |
+ if (window() == GetActiveActionHandlerContainer(action_state) && |
+ action_state == mojom::TrayActionState::kActive) { |
+ wm::ActivateWindow(child); |
+ } else if (wm::IsActiveWindow(child)) { |
+ wm::DeactivateWindow(child); |
+ } |
+ } |
+} |
+ |
+void LockActionHandlerLayoutManager::OnChildWindowVisibilityChanged( |
+ aura::Window* child, |
+ bool visible) { |
+ mojom::TrayActionState action_state = |
+ Shell::Get()->tray_action()->GetLockScreenNoteState(); |
+ |
+ if (visible && window() != GetActiveActionHandlerContainer(action_state)) { |
+ // Make sure windows are shown in the container only if the container is the |
+ // active lock action handler container. |
+ child->Hide(); |
+ } else if (visible && action_state == mojom::TrayActionState::kActive) { |
+ // Activate the window if it just became visible in active container (with |
+ // tray action in active state). |
+ wm::ActivateWindow(child); |
+ } else if (visible && wm::IsActiveWindow(child)) { |
+ // Deactivate the window if it's active and tray action is in inactive |
+ // state. |
+ wm::DeactivateWindow(child); |
+ } |
+} |
+ |
+void LockActionHandlerLayoutManager::WillChangeVisibilityState( |
+ ShelfVisibilityState visibility) { |
+ const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
+ AdjustWindowsForWorkAreaChange(&event); |
+} |
+ |
+void LockActionHandlerLayoutManager::OnLockScreenNoteStateChanged( |
+ mojom::TrayActionState state) { |
+ aura::Window* active_container = GetActiveActionHandlerContainer(state); |
+ std::vector<aura::Window*> children = window()->children(); |
+ for (aura::Window* child : children) { |
+ if (active_container && active_container == window()) { |
+ child->Show(); |
+ } else if (active_container) { |
+ active_container->AddChild(child); |
+ } else { |
+ child->Hide(); |
+ } |
+ } |
+} |
+ |
+aura::Window* LockActionHandlerLayoutManager::GetActiveActionHandlerContainer( |
+ mojom::TrayActionState state) { |
+ if (state == mojom::TrayActionState::kActive) |
+ return root_window()->GetChildById( |
+ kShellWindowId_LockActionHandlerContainer); |
+ if (state == mojom::TrayActionState::kBackground) { |
+ return root_window()->GetChildById( |
+ kShellWindowId_LockActionHandlerContainer_Background); |
+ } |
+ return nullptr; |
+} |
+ |
+} // namespace ash |