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/wm/core/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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 DefaultActivationClient* client_; | 33 DefaultActivationClient* client_; |
34 aura::Window* root_window_; | 34 aura::Window* root_window_; |
35 | 35 |
36 DISALLOW_COPY_AND_ASSIGN(Deleter); | 36 DISALLOW_COPY_AND_ASSIGN(Deleter); |
37 }; | 37 }; |
38 | 38 |
39 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
40 // DefaultActivationClient, public: | 40 // DefaultActivationClient, public: |
41 | 41 |
42 DefaultActivationClient::DefaultActivationClient(aura::Window* root_window) | 42 DefaultActivationClient::DefaultActivationClient(aura::Window* root_window) |
43 : last_active_(NULL) { | 43 : last_active_(nullptr) { |
44 aura::client::SetActivationClient(root_window, this); | 44 aura::client::SetActivationClient(root_window, this); |
45 new Deleter(this, root_window); | 45 new Deleter(this, root_window); |
46 } | 46 } |
47 | 47 |
48 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
49 // DefaultActivationClient, client::ActivationClient implementation: | 49 // DefaultActivationClient, client::ActivationClient implementation: |
50 | 50 |
51 void DefaultActivationClient::AddObserver( | 51 void DefaultActivationClient::AddObserver( |
52 aura::client::ActivationChangeObserver* observer) { | 52 aura::client::ActivationChangeObserver* observer) { |
53 observers_.AddObserver(observer); | 53 observers_.AddObserver(observer); |
54 } | 54 } |
55 | 55 |
56 void DefaultActivationClient::RemoveObserver( | 56 void DefaultActivationClient::RemoveObserver( |
57 aura::client::ActivationChangeObserver* observer) { | 57 aura::client::ActivationChangeObserver* observer) { |
58 observers_.RemoveObserver(observer); | 58 observers_.RemoveObserver(observer); |
59 } | 59 } |
60 | 60 |
61 void DefaultActivationClient::ActivateWindow(aura::Window* window) { | 61 void DefaultActivationClient::ActivateWindow(aura::Window* window) { |
| 62 ActivateWindowImpl(aura::client::ActivationChangeObserver::ActivationReason:: |
| 63 ACTIVATION_CLIENT, |
| 64 window); |
| 65 } |
| 66 |
| 67 void DefaultActivationClient::ActivateWindowImpl( |
| 68 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 69 aura::Window* window) { |
62 aura::Window* last_active = GetActiveWindow(); | 70 aura::Window* last_active = GetActiveWindow(); |
63 if (last_active == window) | 71 if (last_active == window) |
64 return; | 72 return; |
65 | 73 |
66 last_active_ = last_active; | 74 last_active_ = last_active; |
67 RemoveActiveWindow(window); | 75 RemoveActiveWindow(window); |
68 active_windows_.push_back(window); | 76 active_windows_.push_back(window); |
69 window->parent()->StackChildAtTop(window); | 77 window->parent()->StackChildAtTop(window); |
70 window->AddObserver(this); | 78 window->AddObserver(this); |
71 | 79 |
72 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, | 80 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, observers_, |
73 observers_, | 81 OnWindowActivated(reason, window, last_active)); |
74 OnWindowActivated(window, last_active)); | |
75 | 82 |
76 aura::client::ActivationChangeObserver* observer = | 83 aura::client::ActivationChangeObserver* observer = |
77 aura::client::GetActivationChangeObserver(last_active); | 84 aura::client::GetActivationChangeObserver(last_active); |
78 if (observer) | 85 if (observer) { |
79 observer->OnWindowActivated(window, last_active); | 86 observer->OnWindowActivated(reason, window, last_active); |
| 87 } |
80 observer = aura::client::GetActivationChangeObserver(window); | 88 observer = aura::client::GetActivationChangeObserver(window); |
81 if (observer) | 89 if (observer) { |
82 observer->OnWindowActivated(window, last_active); | 90 observer->OnWindowActivated(reason, window, last_active); |
| 91 } |
83 } | 92 } |
84 | 93 |
85 void DefaultActivationClient::DeactivateWindow(aura::Window* window) { | 94 void DefaultActivationClient::DeactivateWindow(aura::Window* window) { |
86 aura::client::ActivationChangeObserver* observer = | 95 aura::client::ActivationChangeObserver* observer = |
87 aura::client::GetActivationChangeObserver(window); | 96 aura::client::GetActivationChangeObserver(window); |
88 if (observer) | 97 if (observer) { |
89 observer->OnWindowActivated(NULL, window); | 98 observer->OnWindowActivated(aura::client::ActivationChangeObserver:: |
| 99 ActivationReason::ACTIVATION_CLIENT, |
| 100 nullptr, window); |
| 101 } |
90 if (last_active_) | 102 if (last_active_) |
91 ActivateWindow(last_active_); | 103 ActivateWindow(last_active_); |
92 } | 104 } |
93 | 105 |
94 aura::Window* DefaultActivationClient::GetActiveWindow() { | 106 aura::Window* DefaultActivationClient::GetActiveWindow() { |
95 if (active_windows_.empty()) | 107 if (active_windows_.empty()) |
96 return NULL; | 108 return nullptr; |
97 return active_windows_.back(); | 109 return active_windows_.back(); |
98 } | 110 } |
99 | 111 |
100 aura::Window* DefaultActivationClient::GetActivatableWindow( | 112 aura::Window* DefaultActivationClient::GetActivatableWindow( |
101 aura::Window* window) { | 113 aura::Window* window) { |
102 return NULL; | 114 return nullptr; |
103 } | 115 } |
104 | 116 |
105 aura::Window* DefaultActivationClient::GetToplevelWindow(aura::Window* window) { | 117 aura::Window* DefaultActivationClient::GetToplevelWindow(aura::Window* window) { |
106 return NULL; | 118 return nullptr; |
107 } | 119 } |
108 | 120 |
109 bool DefaultActivationClient::CanActivateWindow(aura::Window* window) const { | 121 bool DefaultActivationClient::CanActivateWindow(aura::Window* window) const { |
110 return true; | 122 return true; |
111 } | 123 } |
112 | 124 |
113 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
114 // DefaultActivationClient, aura::WindowObserver implementation: | 126 // DefaultActivationClient, aura::WindowObserver implementation: |
115 | 127 |
116 void DefaultActivationClient::OnWindowDestroyed(aura::Window* window) { | 128 void DefaultActivationClient::OnWindowDestroyed(aura::Window* window) { |
117 if (window == last_active_) | 129 if (window == last_active_) |
118 last_active_ = NULL; | 130 last_active_ = nullptr; |
119 | 131 |
120 if (window == GetActiveWindow()) { | 132 if (window == GetActiveWindow()) { |
121 active_windows_.pop_back(); | 133 active_windows_.pop_back(); |
122 aura::Window* next_active = GetActiveWindow(); | 134 aura::Window* next_active = GetActiveWindow(); |
123 if (next_active && aura::client::GetActivationChangeObserver(next_active)) { | 135 if (next_active && aura::client::GetActivationChangeObserver(next_active)) { |
124 aura::client::GetActivationChangeObserver(next_active)->OnWindowActivated( | 136 aura::client::GetActivationChangeObserver(next_active) |
125 next_active, NULL); | 137 ->OnWindowActivated(aura::client::ActivationChangeObserver:: |
| 138 ActivationReason::WINDOW_DISPOSITION_CHANGED, |
| 139 next_active, nullptr); |
126 } | 140 } |
127 return; | 141 return; |
128 } | 142 } |
129 | 143 |
130 RemoveActiveWindow(window); | 144 RemoveActiveWindow(window); |
131 } | 145 } |
132 | 146 |
133 //////////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////////// |
134 // DefaultActivationClient, private: | 148 // DefaultActivationClient, private: |
135 | 149 |
136 DefaultActivationClient::~DefaultActivationClient() { | 150 DefaultActivationClient::~DefaultActivationClient() { |
137 for (unsigned int i = 0; i < active_windows_.size(); ++i) { | 151 for (unsigned int i = 0; i < active_windows_.size(); ++i) { |
138 active_windows_[i]->RemoveObserver(this); | 152 active_windows_[i]->RemoveObserver(this); |
139 } | 153 } |
140 } | 154 } |
141 | 155 |
142 void DefaultActivationClient::RemoveActiveWindow(aura::Window* window) { | 156 void DefaultActivationClient::RemoveActiveWindow(aura::Window* window) { |
143 for (unsigned int i = 0; i < active_windows_.size(); ++i) { | 157 for (unsigned int i = 0; i < active_windows_.size(); ++i) { |
144 if (active_windows_[i] == window) { | 158 if (active_windows_[i] == window) { |
145 active_windows_.erase(active_windows_.begin() + i); | 159 active_windows_.erase(active_windows_.begin() + i); |
146 window->RemoveObserver(this); | 160 window->RemoveObserver(this); |
147 return; | 161 return; |
148 } | 162 } |
149 } | 163 } |
150 } | 164 } |
151 | 165 |
152 } // namespace wm | 166 } // namespace wm |
OLD | NEW |