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/test/test_activation_client.h" | 5 #include "ui/aura/test/test_activation_client.h" |
6 | 6 |
7 #include "ui/aura/client/activation_delegate.h" | |
8 #include "ui/aura/root_window.h" | 7 #include "ui/aura/root_window.h" |
9 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
10 | 9 |
11 namespace aura { | 10 namespace aura { |
12 namespace test { | 11 namespace test { |
13 | 12 |
14 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
15 // TestActivationClient, public: | 14 // TestActivationClient, public: |
16 | 15 |
17 TestActivationClient::TestActivationClient(RootWindow* root_window) { | 16 TestActivationClient::TestActivationClient(RootWindow* root_window) |
| 17 : active_window_(NULL) { |
18 client::SetActivationClient(root_window, this); | 18 client::SetActivationClient(root_window, this); |
19 } | 19 } |
20 | 20 |
21 TestActivationClient::~TestActivationClient() { | 21 TestActivationClient::~TestActivationClient() { |
22 for (unsigned int i = 0; i < active_windows_.size(); ++i) { | |
23 active_windows_[i]->RemoveObserver(this); | |
24 } | |
25 } | 22 } |
26 | 23 |
27 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
28 // TestActivationClient, client::ActivationClient implementation: | 25 // TestActivationClient, client::ActivationClient implementation: |
29 | 26 |
30 void TestActivationClient::ActivateWindow(Window* window) { | 27 void TestActivationClient::ActivateWindow(Window* window) { |
31 Window *last_active = GetActiveWindow(); | 28 if (active_window_) |
32 if (last_active == window) | 29 active_window_->RemoveObserver(this); |
33 return; | 30 active_window_ = window; |
34 | 31 active_window_->AddObserver(this); |
35 RemoveActiveWindow(window); | |
36 active_windows_.push_back(window); | |
37 window->AddObserver(this); | |
38 if (aura::client::GetActivationDelegate(window)) | |
39 aura::client::GetActivationDelegate(window)->OnActivated(); | |
40 | |
41 if (last_active && aura::client::GetActivationDelegate(last_active)) | |
42 aura::client::GetActivationDelegate(last_active)->OnLostActive(); | |
43 | |
44 } | 32 } |
45 | 33 |
46 void TestActivationClient::DeactivateWindow(Window* window) { | 34 void TestActivationClient::DeactivateWindow(Window* window) { |
47 if (aura::client::GetActivationDelegate(window)) | 35 if (window == active_window_) { |
48 aura::client::GetActivationDelegate(window)->OnLostActive(); | 36 if (active_window_) |
| 37 active_window_->RemoveObserver(this); |
| 38 active_window_ = NULL; |
| 39 } |
49 } | 40 } |
50 | 41 |
51 Window* TestActivationClient::GetActiveWindow() { | 42 Window* TestActivationClient::GetActiveWindow() { |
52 if (active_windows_.empty()) | 43 return active_window_; |
53 return NULL; | |
54 return active_windows_.back(); | |
55 } | 44 } |
56 | 45 |
57 bool TestActivationClient::CanFocusWindow(Window* window) const { | 46 bool TestActivationClient::CanFocusWindow(Window* window) const { |
58 return true; | 47 return true; |
59 } | 48 } |
60 | 49 |
61 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
62 // TestActivationClient, WindowObserver implementation: | 51 // TestActivationClient, WindowObserver implementation: |
63 | 52 |
64 void TestActivationClient::OnWindowDestroyed(Window* window) { | 53 void TestActivationClient::OnWindowDestroyed(Window* window) { |
65 if (window == GetActiveWindow()) { | 54 if (window == active_window_) { |
66 window->RemoveObserver(this); | 55 window->RemoveObserver(this); |
67 active_windows_.pop_back(); | 56 active_window_ = NULL; |
68 Window* next_active = GetActiveWindow(); | |
69 if (next_active && aura::client::GetActivationDelegate(next_active)) | |
70 aura::client::GetActivationDelegate(next_active)->OnActivated(); | |
71 return; | |
72 } | |
73 | |
74 RemoveActiveWindow(window); | |
75 } | |
76 | |
77 void TestActivationClient::RemoveActiveWindow(Window* window) { | |
78 for (unsigned int i = 0; i < active_windows_.size(); ++i) { | |
79 if (active_windows_[i] == window) { | |
80 active_windows_.erase(active_windows_.begin() + i); | |
81 window->RemoveObserver(this); | |
82 return; | |
83 } | |
84 } | 57 } |
85 } | 58 } |
86 | 59 |
87 } // namespace test | 60 } // namespace test |
88 } // namespace aura | 61 } // namespace aura |
OLD | NEW |