OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/wm/lock_action_handler_layout_manager.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "ash/public/cpp/shell_window_ids.h" | |
10 #include "ash/public/interfaces/tray_action.mojom.h" | |
11 #include "ash/shelf/wm_shelf.h" | |
12 #include "ash/shell.h" | |
13 #include "ash/tray_action/tray_action.h" | |
14 #include "ash/wm/lock_window_state.h" | |
15 #include "ash/wm/window_state.h" | |
16 #include "ash/wm/window_util.h" | |
17 #include "ash/wm/wm_event.h" | |
18 #include "ash/wm_window.h" | |
19 | |
20 namespace ash { | |
21 namespace {} // namespace | |
oshima
2017/05/17 18:15:59
?
tbarzic
2017/05/18 19:54:58
oops, had a constant that I remove here.
| |
22 | |
23 LockActionHandlerLayoutManager::LockActionHandlerLayoutManager( | |
24 aura::Window* window, | |
25 WmShelf* wm_shelf) | |
26 : LockLayoutManager(window), | |
27 shelf_observer_(this), | |
28 tray_action_observer_(this) { | |
29 TrayAction* tray_action = Shell::Get()->tray_action(); | |
30 tray_action_observer_.Add(tray_action); | |
31 shelf_observer_.Add(wm_shelf); | |
32 } | |
33 | |
34 LockActionHandlerLayoutManager::~LockActionHandlerLayoutManager() = default; | |
35 | |
36 void LockActionHandlerLayoutManager::OnWindowAddedToLayout( | |
37 aura::Window* child) { | |
38 wm::WindowState* window_state = | |
39 LockWindowState::SetLockWindowStateWithVisibleShelf(WmWindow::Get(child)); | |
40 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | |
41 window_state->OnWMEvent(&event); | |
42 | |
43 // If a child is added while tray action state is active, make sure it gets | |
44 // focused - focusing the window only on child visibility changed might not | |
45 // be enough, as the window might have already been visible (in case it got | |
46 // reparented from the background window container). | |
47 mojom::TrayActionState action_state = | |
48 Shell::Get()->tray_action()->GetLockScreenNoteState(); | |
49 if (child->IsVisible()) { | |
50 if (window() == GetActiveActionHandlerContainer(action_state) && | |
51 action_state == mojom::TrayActionState::kActive) { | |
52 wm::ActivateWindow(child); | |
53 } else if (wm::IsActiveWindow(child)) { | |
54 wm::DeactivateWindow(child); | |
55 } | |
56 } | |
57 } | |
58 | |
59 void LockActionHandlerLayoutManager::OnChildWindowVisibilityChanged( | |
60 aura::Window* child, | |
61 bool visible) { | |
62 mojom::TrayActionState action_state = | |
63 Shell::Get()->tray_action()->GetLockScreenNoteState(); | |
64 | |
65 if (visible && window() != GetActiveActionHandlerContainer(action_state)) { | |
66 // Make sure windows are shown in the container only if the container is the | |
67 // active lock action handler container. | |
68 child->Hide(); | |
69 } else if (visible && action_state == mojom::TrayActionState::kActive) { | |
70 // Activate the window if it just became visible in active container (with | |
71 // tray action in active state). | |
72 wm::ActivateWindow(child); | |
73 } else if (visible && wm::IsActiveWindow(child)) { | |
74 // Deactivate the window if it's active and tray action is in inactive | |
75 // state. | |
76 wm::DeactivateWindow(child); | |
77 } | |
78 } | |
79 | |
80 void LockActionHandlerLayoutManager::WillChangeVisibilityState( | |
81 ShelfVisibilityState visibility) { | |
82 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
83 AdjustWindowsForWorkAreaChange(&event); | |
84 } | |
85 | |
86 void LockActionHandlerLayoutManager::OnLockScreenNoteStateChanged( | |
87 mojom::TrayActionState state) { | |
88 aura::Window* active_container = GetActiveActionHandlerContainer(state); | |
89 std::vector<aura::Window*> children = window()->children(); | |
90 for (aura::Window* child : children) { | |
91 if (active_container && active_container == window()) { | |
92 child->Show(); | |
93 } else if (active_container) { | |
94 active_container->AddChild(child); | |
95 } else { | |
96 child->Hide(); | |
97 } | |
98 } | |
99 } | |
100 | |
101 aura::Window* LockActionHandlerLayoutManager::GetActiveActionHandlerContainer( | |
102 mojom::TrayActionState state) { | |
103 if (state == mojom::TrayActionState::kActive) | |
104 return root_window()->GetChildById( | |
105 kShellWindowId_LockActionHandlerContainer); | |
106 if (state == mojom::TrayActionState::kBackground) { | |
107 return root_window()->GetChildById( | |
108 kShellWindowId_LockActionHandlerContainer_Background); | |
109 } | |
110 return nullptr; | |
111 } | |
112 | |
113 } // namespace ash | |
OLD | NEW |