OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura_shell/activation_controller.h" | 5 #include "ui/aura_shell/activation_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "ui/aura/client/activation_delegate.h" | 8 #include "ui/aura/client/activation_delegate.h" |
9 #include "ui/aura/client/aura_constants.h" | |
10 #include "ui/aura/root_window.h" | 9 #include "ui/aura/root_window.h" |
11 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
12 #include "ui/aura/window_delegate.h" | 11 #include "ui/aura/window_delegate.h" |
13 #include "ui/aura_shell/shell.h" | 12 #include "ui/aura_shell/shell.h" |
14 #include "ui/aura_shell/shell_window_ids.h" | 13 #include "ui/aura_shell/shell_window_ids.h" |
15 #include "ui/aura_shell/window_util.h" | 14 #include "ui/aura_shell/window_util.h" |
16 | 15 |
17 namespace aura_shell { | 16 namespace aura_shell { |
18 namespace internal { | 17 namespace internal { |
19 namespace { | 18 namespace { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 aura::Window* old_active = GetActiveWindow(); | 89 aura::Window* old_active = GetActiveWindow(); |
91 if (old_active == window) | 90 if (old_active == window) |
92 return; | 91 return; |
93 // The stacking client may impose rules on what window configurations can be | 92 // The stacking client may impose rules on what window configurations can be |
94 // activated or deactivated. | 93 // activated or deactivated. |
95 if (!CanActivateWindow(window)) | 94 if (!CanActivateWindow(window)) |
96 return; | 95 return; |
97 | 96 |
98 if (!window->Contains(window->GetFocusManager()->GetFocusedWindow())) | 97 if (!window->Contains(window->GetFocusManager()->GetFocusedWindow())) |
99 window->GetFocusManager()->SetFocusedWindow(window); | 98 window->GetFocusManager()->SetFocusedWindow(window); |
100 aura::RootWindow::GetInstance()->SetProperty(aura::kRootWindowActiveWindow, | 99 aura::RootWindow::GetInstance()->SetProperty( |
101 window); | 100 aura::client::kRootWindowActiveWindow, |
| 101 window); |
102 // Invoke OnLostActive after we've changed the active window. That way if the | 102 // Invoke OnLostActive after we've changed the active window. That way if the |
103 // delegate queries for active state it doesn't think the window is still | 103 // delegate queries for active state it doesn't think the window is still |
104 // active. | 104 // active. |
105 if (old_active && aura::client::GetActivationDelegate(old_active)) | 105 if (old_active && aura::client::GetActivationDelegate(old_active)) |
106 aura::client::GetActivationDelegate(old_active)->OnLostActive(); | 106 aura::client::GetActivationDelegate(old_active)->OnLostActive(); |
107 if (window) { | 107 if (window) { |
108 window->parent()->StackChildAtTop(window); | 108 window->parent()->StackChildAtTop(window); |
109 if (aura::client::GetActivationDelegate(window)) | 109 if (aura::client::GetActivationDelegate(window)) |
110 aura::client::GetActivationDelegate(window)->OnActivated(); | 110 aura::client::GetActivationDelegate(window)->OnActivated(); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 void ActivationController::DeactivateWindow(aura::Window* window) { | 114 void ActivationController::DeactivateWindow(aura::Window* window) { |
115 if (window) | 115 if (window) |
116 ActivateNextWindow(window); | 116 ActivateNextWindow(window); |
117 } | 117 } |
118 | 118 |
119 aura::Window* ActivationController::GetActiveWindow() { | 119 aura::Window* ActivationController::GetActiveWindow() { |
120 return reinterpret_cast<aura::Window*>( | 120 return reinterpret_cast<aura::Window*>( |
121 aura::RootWindow::GetInstance()->GetProperty( | 121 aura::RootWindow::GetInstance()->GetProperty( |
122 aura::kRootWindowActiveWindow)); | 122 aura::client::kRootWindowActiveWindow)); |
123 } | 123 } |
124 | 124 |
125 bool ActivationController::CanFocusWindow(aura::Window* window) const { | 125 bool ActivationController::CanFocusWindow(aura::Window* window) const { |
126 return CanActivateWindow(GetActivatableWindow(window)); | 126 return CanActivateWindow(GetActivatableWindow(window)); |
127 } | 127 } |
128 | 128 |
129 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
130 // ActivationController, aura::WindowObserver implementation: | 130 // ActivationController, aura::WindowObserver implementation: |
131 | 131 |
132 void ActivationController::OnWindowVisibilityChanged(aura::Window* window, | 132 void ActivationController::OnWindowVisibilityChanged(aura::Window* window, |
133 bool visible) { | 133 bool visible) { |
134 if (!visible) | 134 if (!visible) |
135 ActivateNextWindow(window); | 135 ActivateNextWindow(window); |
136 } | 136 } |
137 | 137 |
138 void ActivationController::OnWindowDestroyed(aura::Window* window) { | 138 void ActivationController::OnWindowDestroyed(aura::Window* window) { |
139 if (IsActiveWindow(window)) { | 139 if (IsActiveWindow(window)) { |
140 // Clear the property before activating something else, since | 140 // Clear the property before activating something else, since |
141 // ActivateWindow() will attempt to notify the window stored in this value | 141 // ActivateWindow() will attempt to notify the window stored in this value |
142 // otherwise. | 142 // otherwise. |
143 aura::RootWindow::GetInstance()->SetProperty(aura::kRootWindowActiveWindow, | 143 aura::RootWindow::GetInstance()->SetProperty( |
144 NULL); | 144 aura::client::kRootWindowActiveWindow, |
| 145 NULL); |
145 ActivateWindow(GetTopmostWindowToActivate(window)); | 146 ActivateWindow(GetTopmostWindowToActivate(window)); |
146 } | 147 } |
147 window->RemoveObserver(this); | 148 window->RemoveObserver(this); |
148 } | 149 } |
149 | 150 |
150 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
151 // ActivationController, aura::RootWindowObserver implementation: | 152 // ActivationController, aura::RootWindowObserver implementation: |
152 | 153 |
153 void ActivationController::OnWindowInitialized(aura::Window* window) { | 154 void ActivationController::OnWindowInitialized(aura::Window* window) { |
154 window->AddObserver(this); | 155 window->AddObserver(this); |
(...skipping 21 matching lines...) Expand all Loading... |
176 i != container->children().rend(); | 177 i != container->children().rend(); |
177 ++i) { | 178 ++i) { |
178 if (*i != ignore && CanActivateWindow(*i)) | 179 if (*i != ignore && CanActivateWindow(*i)) |
179 return *i; | 180 return *i; |
180 } | 181 } |
181 return NULL; | 182 return NULL; |
182 } | 183 } |
183 | 184 |
184 } // namespace internal | 185 } // namespace internal |
185 } // namespace aura_shell | 186 } // namespace aura_shell |
OLD | NEW |