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

Side by Side Diff: ui/aura/client/default_activation_client.cc

Issue 250113002: Move DefaultActivationClient to wm/core (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 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/client/default_activation_client.h ('k') | ui/aura/test/aura_test_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura/client/default_activation_client.h"
6
7 #include "ui/aura/window.h"
8 #include "ui/wm/public/activation_change_observer.h"
9 #include "ui/wm/public/activation_delegate.h"
10
11 namespace aura {
12 namespace client {
13
14 ////////////////////////////////////////////////////////////////////////////////
15 // DefaultActivationClient, public:
16
17 DefaultActivationClient::DefaultActivationClient(Window* root_window)
18 : last_active_(NULL) {
19 client::SetActivationClient(root_window, this);
20 }
21
22 DefaultActivationClient::~DefaultActivationClient() {
23 for (unsigned int i = 0; i < active_windows_.size(); ++i) {
24 active_windows_[i]->RemoveObserver(this);
25 }
26 }
27
28 ////////////////////////////////////////////////////////////////////////////////
29 // DefaultActivationClient, client::ActivationClient implementation:
30
31 void DefaultActivationClient::AddObserver(
32 client::ActivationChangeObserver* observer) {
33 observers_.AddObserver(observer);
34 }
35
36 void DefaultActivationClient::RemoveObserver(
37 client::ActivationChangeObserver* observer) {
38 observers_.RemoveObserver(observer);
39 }
40
41 void DefaultActivationClient::ActivateWindow(Window* window) {
42 Window* last_active = GetActiveWindow();
43 if (last_active == window)
44 return;
45
46 last_active_ = last_active;
47 RemoveActiveWindow(window);
48 active_windows_.push_back(window);
49 window->parent()->StackChildAtTop(window);
50 window->AddObserver(this);
51
52 FOR_EACH_OBSERVER(client::ActivationChangeObserver,
53 observers_,
54 OnWindowActivated(window, last_active));
55
56 aura::client::ActivationChangeObserver* observer =
57 aura::client::GetActivationChangeObserver(last_active);
58 if (observer)
59 observer->OnWindowActivated(window, last_active);
60 observer = aura::client::GetActivationChangeObserver(window);
61 if (observer)
62 observer->OnWindowActivated(window, last_active);
63 }
64
65 void DefaultActivationClient::DeactivateWindow(Window* window) {
66 aura::client::ActivationChangeObserver* observer =
67 aura::client::GetActivationChangeObserver(window);
68 if (observer)
69 observer->OnWindowActivated(NULL, window);
70 if (last_active_)
71 ActivateWindow(last_active_);
72 }
73
74 Window* DefaultActivationClient::GetActiveWindow() {
75 if (active_windows_.empty())
76 return NULL;
77 return active_windows_.back();
78 }
79
80 Window* DefaultActivationClient::GetActivatableWindow(Window* window) {
81 return NULL;
82 }
83
84 Window* DefaultActivationClient::GetToplevelWindow(Window* window) {
85 return NULL;
86 }
87
88 bool DefaultActivationClient::OnWillFocusWindow(Window* window,
89 const ui::Event* event) {
90 return true;
91 }
92
93 bool DefaultActivationClient::CanActivateWindow(Window* window) const {
94 return true;
95 }
96
97 ////////////////////////////////////////////////////////////////////////////////
98 // DefaultActivationClient, WindowObserver implementation:
99
100 void DefaultActivationClient::OnWindowDestroyed(Window* window) {
101 if (window == last_active_)
102 last_active_ = NULL;
103
104 if (window == GetActiveWindow()) {
105 active_windows_.pop_back();
106 Window* next_active = GetActiveWindow();
107 if (next_active && aura::client::GetActivationChangeObserver(next_active)) {
108 aura::client::GetActivationChangeObserver(next_active)->OnWindowActivated(
109 next_active, NULL);
110 }
111 return;
112 }
113
114 RemoveActiveWindow(window);
115 }
116
117 void DefaultActivationClient::RemoveActiveWindow(Window* window) {
118 for (unsigned int i = 0; i < active_windows_.size(); ++i) {
119 if (active_windows_[i] == window) {
120 active_windows_.erase(active_windows_.begin() + i);
121 window->RemoveObserver(this);
122 return;
123 }
124 }
125 }
126
127 } // namespace client
128 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/client/default_activation_client.h ('k') | ui/aura/test/aura_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698