OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/desktop/desktop_activation_client.h" | 5 #include "ui/aura/desktop/desktop_activation_client.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "ui/aura/client/activation_delegate.h" | 9 #include "ui/aura/client/activation_delegate.h" |
10 #include "ui/aura/client/activation_change_observer.h" | 10 #include "ui/aura/client/activation_change_observer.h" |
11 #include "ui/aura/env.h" | |
12 #include "ui/aura/focus_manager.h" | 11 #include "ui/aura/focus_manager.h" |
13 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
14 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
15 | 14 |
16 namespace { | 15 namespace { |
17 | 16 |
18 // Checks to make sure this window is a direct child of the Root Window. We do | 17 // Checks to make sure this window is a direct child of the Root Window. We do |
19 // this to mirror ash's more interesting behaviour: it checks to make sure the | 18 // this to mirror ash's more interesting behaviour: it checks to make sure the |
20 // window it's going to activate is a child of one a few container windows. | 19 // window it's going to activate is a child of one a few container windows. |
21 bool IsChildOfRootWindow(aura::Window* window) { | 20 bool IsChildOfRootWindow(aura::Window* window) { |
22 return window && window->parent() == window->GetRootWindow(); | 21 return window && window->parent() == window->GetRootWindow(); |
23 } | 22 } |
24 | 23 |
25 } // namespace | 24 } // namespace |
26 | 25 |
27 namespace aura { | 26 namespace aura { |
28 | 27 |
29 DesktopActivationClient::DesktopActivationClient(FocusManager* focus_manager) | 28 DesktopActivationClient::DesktopActivationClient(FocusManager* focus_manager) |
30 : focus_manager_(focus_manager), | 29 : focus_manager_(focus_manager), |
31 current_active_(NULL), | 30 current_active_(NULL), |
32 updating_activation_(false), | 31 updating_activation_(false), |
33 ALLOW_THIS_IN_INITIALIZER_LIST(observer_manager_(this)) { | 32 ALLOW_THIS_IN_INITIALIZER_LIST(observer_manager_(this)) { |
34 aura::Env::GetInstance()->AddObserver(this); | |
35 focus_manager->AddObserver(this); | 33 focus_manager->AddObserver(this); |
36 } | 34 } |
37 | 35 |
38 DesktopActivationClient::~DesktopActivationClient() { | 36 DesktopActivationClient::~DesktopActivationClient() { |
39 focus_manager_->RemoveObserver(this); | 37 focus_manager_->RemoveObserver(this); |
40 aura::Env::GetInstance()->RemoveObserver(this); | |
41 } | 38 } |
42 | 39 |
43 void DesktopActivationClient::AddObserver( | 40 void DesktopActivationClient::AddObserver( |
44 client::ActivationChangeObserver* observer) { | 41 client::ActivationChangeObserver* observer) { |
45 observers_.AddObserver(observer); | 42 observers_.AddObserver(observer); |
46 } | 43 } |
47 | 44 |
48 void DesktopActivationClient::RemoveObserver( | 45 void DesktopActivationClient::RemoveObserver( |
49 client::ActivationChangeObserver* observer) { | 46 client::ActivationChangeObserver* observer) { |
50 observers_.RemoveObserver(observer); | 47 observers_.RemoveObserver(observer); |
(...skipping 14 matching lines...) Expand all Loading... |
65 return; | 62 return; |
66 // Switch internal focus before we change the activation. Will probably cause | 63 // Switch internal focus before we change the activation. Will probably cause |
67 // recursion. | 64 // recursion. |
68 if (window && | 65 if (window && |
69 !window->Contains(window->GetFocusManager()->GetFocusedWindow())) { | 66 !window->Contains(window->GetFocusManager()->GetFocusedWindow())) { |
70 window->GetFocusManager()->SetFocusedWindow(window, NULL); | 67 window->GetFocusManager()->SetFocusedWindow(window, NULL); |
71 } | 68 } |
72 | 69 |
73 aura::Window* old_active = current_active_; | 70 aura::Window* old_active = current_active_; |
74 current_active_ = window; | 71 current_active_ = window; |
| 72 if (window && !observer_manager_.IsObserving(window)) |
| 73 observer_manager_.Add(window); |
| 74 |
75 FOR_EACH_OBSERVER(client::ActivationChangeObserver, | 75 FOR_EACH_OBSERVER(client::ActivationChangeObserver, |
76 observers_, | 76 observers_, |
77 OnWindowActivated(window, old_active)); | 77 OnWindowActivated(window, old_active)); |
78 | 78 |
79 // Invoke OnLostActive after we've changed the active window. That way if the | 79 // Invoke OnLostActive after we've changed the active window. That way if the |
80 // delegate queries for active state it doesn't think the window is still | 80 // delegate queries for active state it doesn't think the window is still |
81 // active. | 81 // active. |
82 if (old_active && client::GetActivationDelegate(old_active)) | 82 if (old_active && client::GetActivationDelegate(old_active)) |
83 client::GetActivationDelegate(old_active)->OnLostActive(); | 83 client::GetActivationDelegate(old_active)->OnLostActive(); |
84 | 84 |
(...skipping 22 matching lines...) Expand all Loading... |
107 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, | 107 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, |
108 observers_, | 108 observers_, |
109 OnWindowActivated(NULL, window)); | 109 OnWindowActivated(NULL, window)); |
110 | 110 |
111 // ash::ActivationController will also activate the next window here; we | 111 // ash::ActivationController will also activate the next window here; we |
112 // don't do this because that's the desktop environment's job. | 112 // don't do this because that's the desktop environment's job. |
113 } | 113 } |
114 observer_manager_.Remove(window); | 114 observer_manager_.Remove(window); |
115 } | 115 } |
116 | 116 |
117 void DesktopActivationClient::OnWindowInitialized(aura::Window* window) { | |
118 observer_manager_.Add(window); | |
119 } | |
120 | |
121 void DesktopActivationClient::OnWindowFocused(aura::Window* window) { | 117 void DesktopActivationClient::OnWindowFocused(aura::Window* window) { |
122 ActivateWindow(GetActivatableWindow(window)); | 118 ActivateWindow(GetActivatableWindow(window)); |
123 } | 119 } |
124 | 120 |
125 bool DesktopActivationClient::CanActivateWindow(aura::Window* window) const { | 121 bool DesktopActivationClient::CanActivateWindow(aura::Window* window) const { |
126 return window && | 122 return window && |
127 window->IsVisible() && | 123 window->IsVisible() && |
128 (!aura::client::GetActivationDelegate(window) || | 124 (!aura::client::GetActivationDelegate(window) || |
129 aura::client::GetActivationDelegate(window)->ShouldActivate(NULL)) && | 125 aura::client::GetActivationDelegate(window)->ShouldActivate(NULL)) && |
130 IsChildOfRootWindow(window); | 126 IsChildOfRootWindow(window); |
(...skipping 13 matching lines...) Expand all Loading... |
144 // that path instead. | 140 // that path instead. |
145 if (child->transient_parent()) | 141 if (child->transient_parent()) |
146 return GetActivatableWindow(child->transient_parent()); | 142 return GetActivatableWindow(child->transient_parent()); |
147 parent = parent->parent(); | 143 parent = parent->parent(); |
148 child = child->parent(); | 144 child = child->parent(); |
149 } | 145 } |
150 return NULL; | 146 return NULL; |
151 } | 147 } |
152 | 148 |
153 } // namespace aura | 149 } // namespace aura |
OLD | NEW |