OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm/lock_layout_manager.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/shell_delegate.h" | |
9 #include "ash/wm/lock_window_state.h" | |
10 #include "ash/wm/window_state.h" | |
11 #include "ash/wm/wm_event.h" | |
12 #include "ui/aura/window.h" | |
13 #include "ui/aura/window_observer.h" | |
14 #include "ui/events/event.h" | |
15 | |
16 using aura::Window; | |
17 | |
18 namespace ash { | |
19 | |
20 LockLayoutManager::LockLayoutManager(aura::Window* window) | |
21 : window_(window), | |
22 root_window_(window->GetRootWindow()), | |
23 is_observing_keyboard_(false) { | |
24 Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this); | |
25 root_window_->AddObserver(this); | |
26 if (keyboard::KeyboardController::GetInstance()) { | |
27 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
28 is_observing_keyboard_ = true; | |
29 } | |
30 } | |
31 | |
32 LockLayoutManager::~LockLayoutManager() { | |
33 if (root_window_) | |
34 root_window_->RemoveObserver(this); | |
35 | |
36 for (WindowSet::const_iterator i = windows_.begin(); i != windows_.end(); ++i) | |
37 (*i)->RemoveObserver(this); | |
38 | |
39 Shell::GetInstance()->delegate()->RemoveVirtualKeyboardStateObserver(this); | |
40 | |
41 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) { | |
42 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
43 is_observing_keyboard_ = false; | |
44 } | |
45 } | |
46 | |
47 void LockLayoutManager::WindowStateDestroyed(aura::Window* window) { | |
48 // At this time ForgetWindow() should already have been called. If not, | |
49 // someone else must have replaced the "window manager's state object". | |
50 DCHECK(!window->HasObserver(this)); | |
51 | |
52 WindowToState::iterator it = window_state_map_.find(window); | |
53 DCHECK(it != window_state_map_.end()); | |
54 window_state_map_.erase(it); | |
55 } | |
56 | |
57 void LockLayoutManager::OnWindowResized() { | |
58 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
59 AdjustWindowsForWorkAreaChange(&event); | |
60 } | |
61 | |
62 void LockLayoutManager::OnWindowAddedToLayout(Window* child) { | |
63 windows_.insert(child); | |
oshima
2014/06/04 19:20:14
do you need windows_? Isn't this same as window_->
| |
64 child->AddObserver(this); | |
65 | |
oshima
2014/06/03 22:36:44
you should be able to just
wm::GetWindowState(chi
Nikita (slow)
2014/06/04 04:17:00
Ok, I'll do that.
Nikita (slow)
2014/06/04 17:40:39
Done.
| |
66 window_state_map_[child] = new LockWindowState(child, this); | |
oshima
2014/06/04 19:20:14
the following should work (no need to pass child t
Nikita (slow)
2014/06/04 19:37:56
SetStateobject is private. Ok to add LockLayoutMan
| |
67 wm::WindowState* window_state = wm::GetWindowState(child); | |
68 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | |
69 window_state->OnWMEvent(&event); | |
70 } | |
71 | |
72 void LockLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { | |
73 windows_.erase(child); | |
74 child->RemoveObserver(this); | |
75 } | |
76 | |
77 void LockLayoutManager::OnWindowRemovedFromLayout(Window* child) { | |
78 } | |
79 | |
80 void LockLayoutManager::OnChildWindowVisibilityChanged(Window* child, | |
81 bool visible) { | |
82 } | |
83 | |
84 void LockLayoutManager::SetChildBounds( | |
85 Window* child, | |
86 const gfx::Rect& requested_bounds) { | |
87 wm::WindowState* window_state = wm::GetWindowState(child); | |
88 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | |
89 window_state->OnWMEvent(&event); | |
90 } | |
91 | |
92 void LockLayoutManager::OnWindowHierarchyChanged( | |
93 const WindowObserver::HierarchyChangeParams& params) { | |
94 } | |
95 | |
96 void LockLayoutManager::OnWindowPropertyChanged(Window* window, | |
97 const void* key, | |
98 intptr_t old) { | |
99 } | |
100 | |
101 void LockLayoutManager::OnWindowStackingChanged(aura::Window* window) { | |
102 } | |
103 | |
104 void LockLayoutManager::OnWindowDestroying(aura::Window* window) { | |
105 if (root_window_ == window) { | |
106 root_window_->RemoveObserver(this); | |
107 root_window_ = NULL; | |
108 } else { | |
109 ForgetWindow(window); | |
110 } | |
111 } | |
112 | |
113 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window, | |
114 const gfx::Rect& old_bounds, | |
115 const gfx::Rect& new_bounds) { | |
116 if (root_window_ == window) { | |
117 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); | |
118 AdjustWindowsForWorkAreaChange(&wm_event); | |
119 } | |
120 } | |
121 | |
122 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated) { | |
123 if (keyboard::KeyboardController::GetInstance()) { | |
124 if (activated) { | |
125 if (!is_observing_keyboard_) { | |
126 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
127 is_observing_keyboard_ = true; | |
128 } | |
129 } else { | |
130 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
131 is_observing_keyboard_ = false; | |
132 } | |
133 } | |
134 } | |
135 | |
136 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | |
137 keyboard_bounds_ = new_bounds; | |
138 OnWindowResized(); | |
139 } | |
140 | |
141 void LockLayoutManager::AdjustWindowsForWorkAreaChange( | |
142 const wm::WMEvent* event) { | |
143 for (WindowToState::iterator it = window_state_map_.begin(); | |
144 it != window_state_map_.end(); | |
145 ++it) { | |
146 wm::GetWindowState(it->first)->OnWMEvent(event); | |
147 } | |
oshima
2014/06/04 19:20:14
this should be equivalent to
for (child in windo
Nikita (slow)
2014/06/05 10:51:37
Done.
| |
148 | |
149 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || | |
150 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
151 | |
152 // If a user plugs an external display into a laptop running Aura the | |
153 // display size will change. Maximized windows need to resize to match. | |
154 // We also do this when developers running Aura on a desktop manually resize | |
155 // the host window. | |
156 // We also need to do this when the work area insets changes. | |
157 for (WindowSet::const_iterator it = windows_.begin(); | |
158 it != windows_.end(); | |
159 ++it) { | |
160 wm::GetWindowState(*it)->OnWMEvent(event); | |
161 } | |
162 } | |
163 | |
164 void LockLayoutManager::ForgetWindow(aura::Window* window) { | |
165 WindowToState::iterator it = window_state_map_.find(window); | |
166 | |
167 // The following DCHECK could fail if our window state object was destroyed | |
168 // earlier by someone else. However - at this point there is no other client | |
169 // which replaces the state object and therefore this should not happen. | |
170 DCHECK(it != window_state_map_.end()); | |
171 window->RemoveObserver(this); | |
172 | |
173 // By telling the state object to revert, it will switch back the old | |
174 // State object and destroy itself, calling WindowStateDerstroyed(). | |
175 it->second->RestoreWindowState(wm::GetWindowState(it->first)); | |
176 DCHECK(window_state_map_.find(window) == window_state_map_.end()); | |
177 } | |
178 | |
179 } // namespace ash | |
OLD | NEW |