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

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

Issue 9689047: Added notion of currently active app / browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review issues 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
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() {
sky 2012/03/14 04:05:44 The destructor should remove all the observers.
DaveMoore 2012/03/14 19:54:58 Done.
22 } 22 }
23 23
24 //////////////////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////////////////
25 // TestActivationClient, client::ActivationClient implementation: 25 // TestActivationClient, client::ActivationClient implementation:
26 26
27 void TestActivationClient::ActivateWindow(Window* window) { 27 void TestActivationClient::ActivateWindow(Window* window) {
28 if (active_window_) 28 Window *last_active = GetActiveWindow();
29 active_window_->RemoveObserver(this); 29 if (last_active == window)
30 active_window_ = window; 30 return;
31 active_window_->AddObserver(this); 31
32 RemoveActiveWindow(window);
33 active_windows_.push_back(window);
34 window->AddObserver(this);
35 if (aura::client::GetActivationDelegate(window))
36 aura::client::GetActivationDelegate(window)->OnActivated();
37
38 if (last_active) {
sky 2012/03/14 04:05:44 nit: combine into a single if.
DaveMoore 2012/03/14 19:54:58 Done.
39 if (aura::client::GetActivationDelegate(last_active))
40 aura::client::GetActivationDelegate(last_active)->OnLostActive();
41 }
42
32 } 43 }
33 44
34 void TestActivationClient::DeactivateWindow(Window* window) { 45 void TestActivationClient::DeactivateWindow(Window* window) {
35 if (window == active_window_) { 46 if (window && window == GetActiveWindow()) {
36 if (active_window_) 47 RemoveActiveWindow(window);
sky 2012/03/14 04:05:44 How come deactivate removes from the vector?
DaveMoore 2012/03/14 19:54:58 You're right...it shouldn't. On 2012/03/14 04:05:4
37 active_window_->RemoveObserver(this); 48 if (aura::client::GetActivationDelegate(window))
38 active_window_ = NULL; 49 aura::client::GetActivationDelegate(window)->OnLostActive();
39 } 50 }
40 } 51 }
41
42 Window* TestActivationClient::GetActiveWindow() { 52 Window* TestActivationClient::GetActiveWindow() {
43 return active_window_; 53 if (active_windows_.size() == 0)
sky 2012/03/14 04:05:44 empty
DaveMoore 2012/03/14 19:54:58 Done.
54 return NULL;
55 return active_windows_.back();
44 } 56 }
45 57
46 bool TestActivationClient::CanFocusWindow(Window* window) const { 58 bool TestActivationClient::CanFocusWindow(Window* window) const {
47 return true; 59 return true;
48 } 60 }
49 61
50 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
51 // TestActivationClient, WindowObserver implementation: 63 // TestActivationClient, WindowObserver implementation:
52 64
53 void TestActivationClient::OnWindowDestroyed(Window* window) { 65 void TestActivationClient::OnWindowDestroyed(Window* window) {
54 if (window == active_window_) { 66 if (window == GetActiveWindow()) {
55 window->RemoveObserver(this); 67 active_windows_.pop_back();
sky 2012/03/14 04:05:44 This should remove the observer too.
DaveMoore 2012/03/14 19:54:58 Done.
56 active_window_ = NULL; 68 Window *next_active = GetActiveWindow();
sky 2012/03/14 04:05:44 'window *' -> 'window* '
DaveMoore 2012/03/14 19:54:58 Done.
69 if (next_active) {
sky 2012/03/14 04:05:44 nit: combine into a single if.
DaveMoore 2012/03/14 19:54:58 Done.
70 if (aura::client::GetActivationDelegate(next_active))
71 aura::client::GetActivationDelegate(next_active)->OnActivated();
72 }
73 return;
74 }
75
76 RemoveActiveWindow(window);
77 }
78
79 void TestActivationClient::RemoveActiveWindow(Window* window) {
80 for (unsigned int i = 0; i < active_windows_.size(); ++i) {
sky 2012/03/14 04:05:44 unsigned int -> size_t
DaveMoore 2012/03/14 19:54:58 Done.
81 if (active_windows_[i] == window) {
82 active_windows_.erase(active_windows_.begin() + i);
83 window->RemoveObserver(this);
84 return;
85 }
57 } 86 }
58 } 87 }
59 88
60 } // namespace test 89 } // namespace test
61 } // namespace aura 90 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698