Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: ui/aura/test/test_activation_client.cc

Issue 9702072: Second try for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/test_activation_client.h ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
7 #include "ui/aura/root_window.h" 8 #include "ui/aura/root_window.h"
8 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
9 10
10 namespace aura { 11 namespace aura {
11 namespace test { 12 namespace test {
12 13
13 //////////////////////////////////////////////////////////////////////////////// 14 ////////////////////////////////////////////////////////////////////////////////
14 // TestActivationClient, public: 15 // TestActivationClient, public:
15 16
16 TestActivationClient::TestActivationClient(RootWindow* root_window) 17 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 }
22 } 25 }
23 26
24 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
25 // TestActivationClient, client::ActivationClient implementation: 28 // TestActivationClient, client::ActivationClient implementation:
26 29
27 void TestActivationClient::ActivateWindow(Window* window) { 30 void TestActivationClient::ActivateWindow(Window* window) {
28 if (active_window_) 31 Window *last_active = GetActiveWindow();
29 active_window_->RemoveObserver(this); 32 if (last_active == window)
30 active_window_ = window; 33 return;
31 active_window_->AddObserver(this); 34
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
32 } 44 }
33 45
34 void TestActivationClient::DeactivateWindow(Window* window) { 46 void TestActivationClient::DeactivateWindow(Window* window) {
35 if (window == active_window_) { 47 if (aura::client::GetActivationDelegate(window))
36 if (active_window_) 48 aura::client::GetActivationDelegate(window)->OnLostActive();
37 active_window_->RemoveObserver(this);
38 active_window_ = NULL;
39 }
40 } 49 }
41 50
42 Window* TestActivationClient::GetActiveWindow() { 51 Window* TestActivationClient::GetActiveWindow() {
43 return active_window_; 52 if (active_windows_.empty())
53 return NULL;
54 return active_windows_.back();
44 } 55 }
45 56
46 bool TestActivationClient::CanFocusWindow(Window* window) const { 57 bool TestActivationClient::CanFocusWindow(Window* window) const {
47 return true; 58 return true;
48 } 59 }
49 60
50 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
51 // TestActivationClient, WindowObserver implementation: 62 // TestActivationClient, WindowObserver implementation:
52 63
53 void TestActivationClient::OnWindowDestroyed(Window* window) { 64 void TestActivationClient::OnWindowDestroyed(Window* window) {
54 if (window == active_window_) { 65 if (window == GetActiveWindow()) {
55 window->RemoveObserver(this); 66 window->RemoveObserver(this);
56 active_window_ = NULL; 67 active_windows_.pop_back();
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 }
57 } 84 }
58 } 85 }
59 86
60 } // namespace test 87 } // namespace test
61 } // namespace aura 88 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/test_activation_client.h ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698