| 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" | 9 #include "ui/aura/client/aura_constants.h" |
| 10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 window->id() == kShellWindowId_LockScreenContainer || | 30 window->id() == kShellWindowId_LockScreenContainer || |
| 31 window->id() == kShellWindowId_LockModalContainer; | 31 window->id() == kShellWindowId_LockModalContainer; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Returns true if |window| can be activated or deactivated. | 34 // Returns true if |window| can be activated or deactivated. |
| 35 // A window manager typically defines some notion of "top level window" that | 35 // A window manager typically defines some notion of "top level window" that |
| 36 // supports activation/deactivation. | 36 // supports activation/deactivation. |
| 37 bool CanActivateWindow(aura::Window* window) { | 37 bool CanActivateWindow(aura::Window* window) { |
| 38 return window && | 38 return window && |
| 39 window->IsVisible() && | 39 window->IsVisible() && |
| 40 (!aura::ActivationDelegate::GetActivationDelegate(window) || | 40 (!aura::client::GetActivationDelegate(window) || |
| 41 aura::ActivationDelegate::GetActivationDelegate(window)-> | 41 aura::client::GetActivationDelegate(window)->ShouldActivate(NULL)) && |
| 42 ShouldActivate(NULL)) && | |
| 43 SupportsChildActivation(window->parent()); | 42 SupportsChildActivation(window->parent()); |
| 44 } | 43 } |
| 45 | 44 |
| 46 } // namespace | 45 } // namespace |
| 47 | 46 |
| 48 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 49 // ActivationController, public: | 48 // ActivationController, public: |
| 50 | 49 |
| 51 ActivationController::ActivationController() | 50 ActivationController::ActivationController() |
| 52 : updating_activation_(false), | 51 : updating_activation_(false), |
| 53 default_container_for_test_(NULL) { | 52 default_container_for_test_(NULL) { |
| 54 aura::ActivationClient::SetActivationClient(this); | 53 aura::client::SetActivationClient(this); |
| 55 aura::RootWindow::GetInstance()->AddRootWindowObserver(this); | 54 aura::RootWindow::GetInstance()->AddRootWindowObserver(this); |
| 56 } | 55 } |
| 57 | 56 |
| 58 ActivationController::~ActivationController() { | 57 ActivationController::~ActivationController() { |
| 59 aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); | 58 aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); |
| 60 } | 59 } |
| 61 | 60 |
| 62 // static | 61 // static |
| 63 aura::Window* ActivationController::GetActivatableWindow(aura::Window* window) { | 62 aura::Window* ActivationController::GetActivatableWindow(aura::Window* window) { |
| 64 aura::Window* parent = window->parent(); | 63 aura::Window* parent = window->parent(); |
| 65 aura::Window* child = window; | 64 aura::Window* child = window; |
| 66 while (parent) { | 65 while (parent) { |
| 67 if (SupportsChildActivation(parent)) | 66 if (SupportsChildActivation(parent)) |
| 68 return child; | 67 return child; |
| 69 // If |child| isn't activatable, but has transient parent, trace | 68 // If |child| isn't activatable, but has transient parent, trace |
| 70 // that path instead. | 69 // that path instead. |
| 71 if (child->transient_parent()) | 70 if (child->transient_parent()) |
| 72 return GetActivatableWindow(child->transient_parent()); | 71 return GetActivatableWindow(child->transient_parent()); |
| 73 parent = parent->parent(); | 72 parent = parent->parent(); |
| 74 child = child->parent(); | 73 child = child->parent(); |
| 75 } | 74 } |
| 76 return NULL; | 75 return NULL; |
| 77 } | 76 } |
| 78 | 77 |
| 79 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
| 80 // StackingController, aura::ActivationClient implementation: | 79 // ActivationController, aura::client::ActivationClient implementation: |
| 81 | 80 |
| 82 void ActivationController::ActivateWindow(aura::Window* window) { | 81 void ActivationController::ActivateWindow(aura::Window* window) { |
| 83 // Prevent recursion when called from focus. | 82 // Prevent recursion when called from focus. |
| 84 if (updating_activation_) | 83 if (updating_activation_) |
| 85 return; | 84 return; |
| 86 | 85 |
| 87 AutoReset<bool> in_activate_window(&updating_activation_, true); | 86 AutoReset<bool> in_activate_window(&updating_activation_, true); |
| 88 if (!window) | 87 if (!window) |
| 89 return; | 88 return; |
| 90 // Nothing may actually have changed. | 89 // Nothing may actually have changed. |
| 91 aura::Window* old_active = GetActiveWindow(); | 90 aura::Window* old_active = GetActiveWindow(); |
| 92 if (old_active == window) | 91 if (old_active == window) |
| 93 return; | 92 return; |
| 94 // The stacking client may impose rules on what window configurations can be | 93 // The stacking client may impose rules on what window configurations can be |
| 95 // activated or deactivated. | 94 // activated or deactivated. |
| 96 if (!CanActivateWindow(window)) | 95 if (!CanActivateWindow(window)) |
| 97 return; | 96 return; |
| 98 | 97 |
| 99 if (!window->Contains(window->GetFocusManager()->GetFocusedWindow())) | 98 if (!window->Contains(window->GetFocusManager()->GetFocusedWindow())) |
| 100 window->GetFocusManager()->SetFocusedWindow(window); | 99 window->GetFocusManager()->SetFocusedWindow(window); |
| 101 aura::RootWindow::GetInstance()->SetProperty(aura::kRootWindowActiveWindow, | 100 aura::RootWindow::GetInstance()->SetProperty(aura::kRootWindowActiveWindow, |
| 102 window); | 101 window); |
| 103 // 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 |
| 104 // 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 |
| 105 // active. | 104 // active. |
| 106 if (old_active && aura::ActivationDelegate::GetActivationDelegate(old_active)) | 105 if (old_active && aura::client::GetActivationDelegate(old_active)) |
| 107 aura::ActivationDelegate::GetActivationDelegate(old_active)->OnLostActive(); | 106 aura::client::GetActivationDelegate(old_active)->OnLostActive(); |
| 108 if (window) { | 107 if (window) { |
| 109 window->parent()->StackChildAtTop(window); | 108 window->parent()->StackChildAtTop(window); |
| 110 if (aura::ActivationDelegate::GetActivationDelegate(window)) | 109 if (aura::client::GetActivationDelegate(window)) |
| 111 aura::ActivationDelegate::GetActivationDelegate(window)->OnActivated(); | 110 aura::client::GetActivationDelegate(window)->OnActivated(); |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| 115 void ActivationController::DeactivateWindow(aura::Window* window) { | 114 void ActivationController::DeactivateWindow(aura::Window* window) { |
| 116 if (window) | 115 if (window) |
| 117 ActivateNextWindow(window); | 116 ActivateNextWindow(window); |
| 118 } | 117 } |
| 119 | 118 |
| 120 aura::Window* ActivationController::GetActiveWindow() { | 119 aura::Window* ActivationController::GetActiveWindow() { |
| 121 return reinterpret_cast<aura::Window*>( | 120 return reinterpret_cast<aura::Window*>( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 i != container->children().rend(); | 176 i != container->children().rend(); |
| 178 ++i) { | 177 ++i) { |
| 179 if (*i != ignore && CanActivateWindow(*i)) | 178 if (*i != ignore && CanActivateWindow(*i)) |
| 180 return *i; | 179 return *i; |
| 181 } | 180 } |
| 182 return NULL; | 181 return NULL; |
| 183 } | 182 } |
| 184 | 183 |
| 185 } // namespace internal | 184 } // namespace internal |
| 186 } // namespace aura_shell | 185 } // namespace aura_shell |
| OLD | NEW |