OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 #include "ui/keyboard/keyboard_controller.h" | |
16 #include "ui/keyboard/keyboard_util.h" | |
17 | |
18 using aura::Window; | |
19 | |
20 namespace ash { | |
21 | |
22 LockLayoutManager::LockLayoutManager(aura::Window* window) | |
23 : window_(window), | |
24 root_window_(window->GetRootWindow()), | |
25 is_observing_keyboard_(false) { | |
26 Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this); | |
27 root_window_->AddObserver(this); | |
28 if (keyboard::KeyboardController::GetInstance()) { | |
29 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
30 is_observing_keyboard_ = true; | |
31 } | |
32 } | |
33 | |
34 LockLayoutManager::~LockLayoutManager() { | |
35 if (root_window_) | |
36 root_window_->RemoveObserver(this); | |
37 | |
38 for (WindowSet::const_iterator i = windows_.begin(); i != windows_.end(); ++i) | |
39 (*i)->RemoveObserver(this); | |
40 | |
41 Shell::GetInstance()->delegate()->RemoveVirtualKeyboardStateObserver(this); | |
42 | |
43 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) { | |
44 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
45 is_observing_keyboard_ = false; | |
46 } | |
47 } | |
48 | |
49 void LockLayoutManager::OnWindowResized() { | |
50 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
51 AdjustWindowsForWorkAreaChange(&event); | |
52 } | |
53 | |
54 void LockLayoutManager::OnWindowAddedToLayout(Window* child) { | |
55 windows_.insert(child); | |
56 child->AddObserver(this); | |
57 | |
58 window_state_map_[child] = new LockWindowState(child); | |
59 wm::WindowState* window_state = wm::GetWindowState(child); | |
60 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | |
61 window_state->OnWMEvent(&event); | |
62 } | |
63 | |
64 void LockLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { | |
65 windows_.erase(child); | |
66 child->RemoveObserver(this); | |
67 } | |
68 | |
69 void LockLayoutManager::OnWindowRemovedFromLayout(Window* child) { | |
70 } | |
71 | |
72 void LockLayoutManager::OnChildWindowVisibilityChanged(Window* child, | |
73 bool visible) { | |
74 } | |
75 | |
76 void LockLayoutManager::SetChildBounds( | |
77 Window* child, | |
78 const gfx::Rect& requested_bounds) { | |
79 wm::WindowState* window_state = wm::GetWindowState(child); | |
80 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | |
81 window_state->OnWMEvent(&event); | |
82 } | |
83 | |
84 void LockLayoutManager::OnWindowHierarchyChanged( | |
85 const WindowObserver::HierarchyChangeParams& params) { | |
86 } | |
87 | |
88 void LockLayoutManager::OnWindowPropertyChanged(Window* window, | |
89 const void* key, | |
90 intptr_t old) { | |
91 } | |
92 | |
93 void LockLayoutManager::OnWindowStackingChanged(aura::Window* window) { | |
94 } | |
95 | |
96 void LockLayoutManager::OnWindowDestroying(aura::Window* window) { | |
97 if (root_window_ == window) { | |
98 root_window_->RemoveObserver(this); | |
99 root_window_ = NULL; | |
100 } else { | |
101 ForgetWindow(window); | |
102 } | |
103 } | |
104 | |
105 void LockLayoutManager::OnWindowBoundsChanged(aura::Window* window, | |
106 const gfx::Rect& old_bounds, | |
107 const gfx::Rect& new_bounds) { | |
108 if (root_window_ == window) { | |
109 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); | |
110 AdjustWindowsForWorkAreaChange(&wm_event); | |
111 } | |
112 } | |
113 | |
114 void LockLayoutManager::OnVirtualKeyboardStateChanged(bool activated) { | |
115 if (keyboard::KeyboardController::GetInstance()) { | |
116 if (activated) { | |
117 if (!is_observing_keyboard_) { | |
118 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
119 is_observing_keyboard_ = true; | |
120 } | |
121 } else { | |
122 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
123 is_observing_keyboard_ = false; | |
124 } | |
125 } | |
126 } | |
127 | |
128 void LockLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | |
129 keyboard_bounds_ = new_bounds; | |
130 OnWindowResized(); | |
131 } | |
132 | |
133 void LockLayoutManager::AdjustWindowsForWorkAreaChange( | |
134 const wm::WMEvent* event) { | |
135 for (WindowToState::iterator it = window_state_map_.begin(); | |
136 it != window_state_map_.end(); | |
137 ++it) { | |
138 wm::GetWindowState(it->first)->OnWMEvent(event); | |
139 } | |
140 | |
141 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || | |
142 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
143 | |
144 // If a user plugs an external display into a laptop running Aura the | |
145 // display size will change. Maximized windows need to resize to match. | |
146 // We also do this when developers running Aura on a desktop manually resize | |
147 // the host window. | |
148 // We also need to do this when the work area insets changes. | |
149 for (WindowSet::const_iterator it = windows_.begin(); | |
150 it != windows_.end(); | |
151 ++it) { | |
152 wm::GetWindowState(*it)->OnWMEvent(event); | |
153 } | |
oshima
2014/06/04 19:20:14
looks to me that you're sending the same event twi
| |
154 } | |
155 | |
156 void LockLayoutManager::ForgetWindow(aura::Window* window) { | |
157 WindowToState::iterator it = window_state_map_.find(window); | |
158 | |
159 // The following DCHECK could fail if our window state object was destroyed | |
160 // earlier by someone else. However - at this point there is no other client | |
161 // which replaces the state object and therefore this should not happen. | |
162 DCHECK(it != window_state_map_.end()); | |
163 window->RemoveObserver(this); | |
164 window_state_map_.erase(it); | |
165 } | |
166 | |
167 } // namespace ash | |
OLD | NEW |