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