OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/client/default_activation_client.h" | 5 #include "ui/wm/core/default_activation_client.h" |
6 | 6 |
7 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
8 #include "ui/wm/public/activation_change_observer.h" | 8 #include "ui/wm/public/activation_change_observer.h" |
9 #include "ui/wm/public/activation_delegate.h" | 9 #include "ui/wm/public/activation_delegate.h" |
10 | 10 |
11 namespace aura { | 11 namespace wm { |
12 namespace client { | 12 |
13 namespace { | |
14 | |
15 // Takes care of observing root window destruction & destroying the client. | |
16 class Deleter : public aura::WindowObserver { | |
17 public: | |
18 Deleter(DefaultActivationClient* client, aura::Window* root_window) | |
19 : client_(client), | |
20 root_window_(root_window) { | |
21 root_window_->AddObserver(this); | |
22 } | |
23 | |
24 private: | |
25 // Overridden from WindowObserver: | |
sky
2014/04/23 20:50:11
nit: add virtual private destructor to make it cle
| |
26 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { | |
27 DCHECK_EQ(window, root_window_); | |
28 root_window_->RemoveObserver(this); | |
29 delete client_; | |
30 delete this; | |
31 } | |
32 | |
33 DefaultActivationClient* client_; | |
34 aura::Window* root_window_; | |
35 | |
36 DISALLOW_COPY_AND_ASSIGN(Deleter); | |
37 }; | |
38 | |
39 } // namespace | |
13 | 40 |
14 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
15 // DefaultActivationClient, public: | 42 // DefaultActivationClient, public: |
16 | 43 |
17 DefaultActivationClient::DefaultActivationClient(Window* root_window) | 44 DefaultActivationClient::DefaultActivationClient(aura::Window* root_window) |
18 : last_active_(NULL) { | 45 : last_active_(NULL) { |
19 client::SetActivationClient(root_window, this); | 46 aura::client::SetActivationClient(root_window, this); |
47 new Deleter(this, root_window); | |
20 } | 48 } |
21 | 49 |
22 DefaultActivationClient::~DefaultActivationClient() { | 50 DefaultActivationClient::~DefaultActivationClient() { |
23 for (unsigned int i = 0; i < active_windows_.size(); ++i) { | 51 for (unsigned int i = 0; i < active_windows_.size(); ++i) { |
24 active_windows_[i]->RemoveObserver(this); | 52 active_windows_[i]->RemoveObserver(this); |
25 } | 53 } |
26 } | 54 } |
27 | 55 |
28 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
29 // DefaultActivationClient, client::ActivationClient implementation: | 57 // DefaultActivationClient, client::ActivationClient implementation: |
30 | 58 |
31 void DefaultActivationClient::AddObserver( | 59 void DefaultActivationClient::AddObserver( |
32 client::ActivationChangeObserver* observer) { | 60 aura::client::ActivationChangeObserver* observer) { |
33 observers_.AddObserver(observer); | 61 observers_.AddObserver(observer); |
34 } | 62 } |
35 | 63 |
36 void DefaultActivationClient::RemoveObserver( | 64 void DefaultActivationClient::RemoveObserver( |
37 client::ActivationChangeObserver* observer) { | 65 aura::client::ActivationChangeObserver* observer) { |
38 observers_.RemoveObserver(observer); | 66 observers_.RemoveObserver(observer); |
39 } | 67 } |
40 | 68 |
41 void DefaultActivationClient::ActivateWindow(Window* window) { | 69 void DefaultActivationClient::ActivateWindow(aura::Window* window) { |
42 Window* last_active = GetActiveWindow(); | 70 aura::Window* last_active = GetActiveWindow(); |
43 if (last_active == window) | 71 if (last_active == window) |
44 return; | 72 return; |
45 | 73 |
46 last_active_ = last_active; | 74 last_active_ = last_active; |
47 RemoveActiveWindow(window); | 75 RemoveActiveWindow(window); |
48 active_windows_.push_back(window); | 76 active_windows_.push_back(window); |
49 window->parent()->StackChildAtTop(window); | 77 window->parent()->StackChildAtTop(window); |
50 window->AddObserver(this); | 78 window->AddObserver(this); |
51 | 79 |
52 FOR_EACH_OBSERVER(client::ActivationChangeObserver, | 80 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, |
53 observers_, | 81 observers_, |
54 OnWindowActivated(window, last_active)); | 82 OnWindowActivated(window, last_active)); |
55 | 83 |
56 aura::client::ActivationChangeObserver* observer = | 84 aura::client::ActivationChangeObserver* observer = |
57 aura::client::GetActivationChangeObserver(last_active); | 85 aura::client::GetActivationChangeObserver(last_active); |
58 if (observer) | 86 if (observer) |
59 observer->OnWindowActivated(window, last_active); | 87 observer->OnWindowActivated(window, last_active); |
60 observer = aura::client::GetActivationChangeObserver(window); | 88 observer = aura::client::GetActivationChangeObserver(window); |
61 if (observer) | 89 if (observer) |
62 observer->OnWindowActivated(window, last_active); | 90 observer->OnWindowActivated(window, last_active); |
63 } | 91 } |
64 | 92 |
65 void DefaultActivationClient::DeactivateWindow(Window* window) { | 93 void DefaultActivationClient::DeactivateWindow(aura::Window* window) { |
66 aura::client::ActivationChangeObserver* observer = | 94 aura::client::ActivationChangeObserver* observer = |
67 aura::client::GetActivationChangeObserver(window); | 95 aura::client::GetActivationChangeObserver(window); |
68 if (observer) | 96 if (observer) |
69 observer->OnWindowActivated(NULL, window); | 97 observer->OnWindowActivated(NULL, window); |
70 if (last_active_) | 98 if (last_active_) |
71 ActivateWindow(last_active_); | 99 ActivateWindow(last_active_); |
72 } | 100 } |
73 | 101 |
74 Window* DefaultActivationClient::GetActiveWindow() { | 102 aura::Window* DefaultActivationClient::GetActiveWindow() { |
75 if (active_windows_.empty()) | 103 if (active_windows_.empty()) |
76 return NULL; | 104 return NULL; |
77 return active_windows_.back(); | 105 return active_windows_.back(); |
78 } | 106 } |
79 | 107 |
80 Window* DefaultActivationClient::GetActivatableWindow(Window* window) { | 108 aura::Window* DefaultActivationClient::GetActivatableWindow( |
109 aura::Window* window) { | |
81 return NULL; | 110 return NULL; |
82 } | 111 } |
83 | 112 |
84 Window* DefaultActivationClient::GetToplevelWindow(Window* window) { | 113 aura::Window* DefaultActivationClient::GetToplevelWindow(aura::Window* window) { |
85 return NULL; | 114 return NULL; |
86 } | 115 } |
87 | 116 |
88 bool DefaultActivationClient::OnWillFocusWindow(Window* window, | 117 bool DefaultActivationClient::OnWillFocusWindow(aura::Window* window, |
89 const ui::Event* event) { | 118 const ui::Event* event) { |
90 return true; | 119 return true; |
91 } | 120 } |
92 | 121 |
93 bool DefaultActivationClient::CanActivateWindow(Window* window) const { | 122 bool DefaultActivationClient::CanActivateWindow(aura::Window* window) const { |
94 return true; | 123 return true; |
95 } | 124 } |
96 | 125 |
97 //////////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////////// |
98 // DefaultActivationClient, WindowObserver implementation: | 127 // DefaultActivationClient, aura::WindowObserver implementation: |
99 | 128 |
100 void DefaultActivationClient::OnWindowDestroyed(Window* window) { | 129 void DefaultActivationClient::OnWindowDestroyed(aura::Window* window) { |
101 if (window == last_active_) | 130 if (window == last_active_) |
102 last_active_ = NULL; | 131 last_active_ = NULL; |
103 | 132 |
104 if (window == GetActiveWindow()) { | 133 if (window == GetActiveWindow()) { |
105 active_windows_.pop_back(); | 134 active_windows_.pop_back(); |
106 Window* next_active = GetActiveWindow(); | 135 aura::Window* next_active = GetActiveWindow(); |
107 if (next_active && aura::client::GetActivationChangeObserver(next_active)) { | 136 if (next_active && aura::client::GetActivationChangeObserver(next_active)) { |
108 aura::client::GetActivationChangeObserver(next_active)->OnWindowActivated( | 137 aura::client::GetActivationChangeObserver(next_active)->OnWindowActivated( |
109 next_active, NULL); | 138 next_active, NULL); |
110 } | 139 } |
111 return; | 140 return; |
112 } | 141 } |
113 | 142 |
114 RemoveActiveWindow(window); | 143 RemoveActiveWindow(window); |
115 } | 144 } |
116 | 145 |
117 void DefaultActivationClient::RemoveActiveWindow(Window* window) { | 146 void DefaultActivationClient::RemoveActiveWindow(aura::Window* window) { |
118 for (unsigned int i = 0; i < active_windows_.size(); ++i) { | 147 for (unsigned int i = 0; i < active_windows_.size(); ++i) { |
119 if (active_windows_[i] == window) { | 148 if (active_windows_[i] == window) { |
120 active_windows_.erase(active_windows_.begin() + i); | 149 active_windows_.erase(active_windows_.begin() + i); |
121 window->RemoveObserver(this); | 150 window->RemoveObserver(this); |
122 return; | 151 return; |
123 } | 152 } |
124 } | 153 } |
125 } | 154 } |
126 | 155 |
127 } // namespace client | 156 } // namespace wm |
128 } // namespace aura | |
OLD | NEW |