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/wm/core/base_focus_rules.h" | 5 #include "ui/wm/core/base_focus_rules.h" |
6 | 6 |
7 #include "ui/aura/client/focus_client.h" | 7 #include "ui/aura/client/focus_client.h" |
8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
9 #include "ui/wm/core/window_modality_controller.h" | 9 #include "ui/wm/core/window_modality_controller.h" |
10 #include "ui/wm/core/window_util.h" | 10 #include "ui/wm/core/window_util.h" |
11 #include "ui/wm/public/activation_delegate.h" | 11 #include "ui/wm/public/activation_delegate.h" |
12 | 12 |
13 namespace wm { | 13 namespace wm { |
14 namespace { | 14 namespace { |
15 | 15 |
16 aura::Window* GetFocusedWindow(aura::Window* context) { | 16 aura::Window* GetFocusedWindow(aura::Window* context) { |
17 aura::client::FocusClient* focus_client = | 17 aura::client::FocusClient* focus_client = |
18 aura::client::GetFocusClient(context); | 18 aura::client::GetFocusClient(context); |
19 return focus_client ? focus_client->GetFocusedWindow() : NULL; | 19 return focus_client ? focus_client->GetFocusedWindow() : nullptr; |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
25 // BaseFocusRules, protected: | 25 // BaseFocusRules, protected: |
26 | 26 |
27 BaseFocusRules::BaseFocusRules() { | 27 BaseFocusRules::BaseFocusRules() = default; |
28 } | |
29 | 28 |
30 BaseFocusRules::~BaseFocusRules() { | 29 BaseFocusRules::~BaseFocusRules() = default; |
31 } | |
32 | 30 |
33 bool BaseFocusRules::IsWindowConsideredVisibleForActivation( | 31 bool BaseFocusRules::IsWindowConsideredVisibleForActivation( |
34 aura::Window* window) const { | 32 aura::Window* window) const { |
35 return window->IsVisible(); | 33 return window->IsVisible(); |
36 } | 34 } |
37 | 35 |
38 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
39 // BaseFocusRules, FocusRules implementation: | 37 // BaseFocusRules, FocusRules implementation: |
40 | 38 |
41 bool BaseFocusRules::IsToplevelWindow(aura::Window* window) const { | 39 bool BaseFocusRules::IsToplevelWindow(aura::Window* window) const { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 return true; | 82 return true; |
85 | 83 |
86 // The focused window is always inside the active window, so windows that | 84 // The focused window is always inside the active window, so windows that |
87 // aren't activatable can't contain the focused window. | 85 // aren't activatable can't contain the focused window. |
88 aura::Window* activatable = GetActivatableWindow(window); | 86 aura::Window* activatable = GetActivatableWindow(window); |
89 if (!activatable || !activatable->Contains(window)) | 87 if (!activatable || !activatable->Contains(window)) |
90 return false; | 88 return false; |
91 return window->CanFocus(); | 89 return window->CanFocus(); |
92 } | 90 } |
93 | 91 |
| 92 bool BaseFocusRules::IsWindowConsideredActivatableForEvent( |
| 93 aura::Window* window, |
| 94 ui::Event* event) const { |
| 95 return true; |
| 96 } |
| 97 |
94 aura::Window* BaseFocusRules::GetToplevelWindow(aura::Window* window) const { | 98 aura::Window* BaseFocusRules::GetToplevelWindow(aura::Window* window) const { |
95 aura::Window* parent = window->parent(); | 99 aura::Window* parent = window->parent(); |
96 aura::Window* child = window; | 100 aura::Window* child = window; |
97 while (parent) { | 101 while (parent) { |
98 if (IsToplevelWindow(child)) | 102 if (IsToplevelWindow(child)) |
99 return child; | 103 return child; |
100 | 104 |
101 parent = parent->parent(); | 105 parent = parent->parent(); |
102 child = child->parent(); | 106 child = child->parent(); |
103 } | 107 } |
104 return NULL; | 108 return nullptr; |
105 } | 109 } |
106 | 110 |
107 aura::Window* BaseFocusRules::GetActivatableWindow(aura::Window* window) const { | 111 aura::Window* BaseFocusRules::GetActivatableWindow(aura::Window* window) const { |
108 aura::Window* parent = window->parent(); | 112 aura::Window* parent = window->parent(); |
109 aura::Window* child = window; | 113 aura::Window* child = window; |
110 while (parent) { | 114 while (parent) { |
111 if (CanActivateWindow(child)) | 115 if (CanActivateWindow(child)) |
112 return child; | 116 return child; |
113 | 117 |
114 // CanActivateWindow() above will return false if |child| is blocked by a | 118 // CanActivateWindow() above will return false if |child| is blocked by a |
(...skipping 11 matching lines...) Expand all Loading... |
126 GetModalTransient(wm::GetTransientParent(child)); | 130 GetModalTransient(wm::GetTransientParent(child)); |
127 if (parent_modal_transient == child) | 131 if (parent_modal_transient == child) |
128 return child; | 132 return child; |
129 | 133 |
130 return GetActivatableWindow(wm::GetTransientParent(child)); | 134 return GetActivatableWindow(wm::GetTransientParent(child)); |
131 } | 135 } |
132 | 136 |
133 parent = parent->parent(); | 137 parent = parent->parent(); |
134 child = child->parent(); | 138 child = child->parent(); |
135 } | 139 } |
136 return NULL; | 140 return nullptr; |
137 } | 141 } |
138 | 142 |
139 aura::Window* BaseFocusRules::GetFocusableWindow(aura::Window* window) const { | 143 aura::Window* BaseFocusRules::GetFocusableWindow(aura::Window* window) const { |
140 if (CanFocusWindow(window)) | 144 if (CanFocusWindow(window)) |
141 return window; | 145 return window; |
142 | 146 |
143 // |window| may be in a hierarchy that is non-activatable, in which case we | 147 // |window| may be in a hierarchy that is non-activatable, in which case we |
144 // need to cut over to the activatable hierarchy. | 148 // need to cut over to the activatable hierarchy. |
145 aura::Window* activatable = GetActivatableWindow(window); | 149 aura::Window* activatable = GetActivatableWindow(window); |
146 if (!activatable) { | 150 if (!activatable) { |
147 // There may not be a related activatable hierarchy to cut over to, in which | 151 // There may not be a related activatable hierarchy to cut over to, in which |
148 // case we try an unrelated one. | 152 // case we try an unrelated one. |
149 aura::Window* toplevel = GetToplevelWindow(window); | 153 aura::Window* toplevel = GetToplevelWindow(window); |
150 if (toplevel) | 154 if (toplevel) |
151 activatable = GetNextActivatableWindow(toplevel); | 155 activatable = GetNextActivatableWindow(toplevel); |
152 if (!activatable) | 156 if (!activatable) |
153 return NULL; | 157 return nullptr; |
154 } | 158 } |
155 | 159 |
156 if (!activatable->Contains(window)) { | 160 if (!activatable->Contains(window)) { |
157 // If there's already a child window focused in the activatable hierarchy, | 161 // If there's already a child window focused in the activatable hierarchy, |
158 // just use that (i.e. don't shift focus), otherwise we need to at least cut | 162 // just use that (i.e. don't shift focus), otherwise we need to at least cut |
159 // over to the activatable hierarchy. | 163 // over to the activatable hierarchy. |
160 aura::Window* focused = GetFocusedWindow(activatable); | 164 aura::Window* focused = GetFocusedWindow(activatable); |
161 return activatable->Contains(focused) ? focused : activatable; | 165 return activatable->Contains(focused) ? focused : activatable; |
162 } | 166 } |
163 | 167 |
164 while (window && !CanFocusWindow(window)) | 168 while (window && !CanFocusWindow(window)) |
165 window = window->parent(); | 169 window = window->parent(); |
166 return window; | 170 return window; |
167 } | 171 } |
168 | 172 |
169 aura::Window* BaseFocusRules::GetNextActivatableWindow( | 173 aura::Window* BaseFocusRules::GetNextActivatableWindow( |
170 aura::Window* ignore) const { | 174 aura::Window* ignore) const { |
171 DCHECK(ignore); | 175 DCHECK(ignore); |
172 | 176 |
173 // Can be called from the RootWindow's destruction, which has a NULL parent. | 177 // Can be called from the RootWindow's destruction, which has a NULL parent. |
174 if (!ignore->parent()) | 178 if (!ignore->parent()) |
175 return NULL; | 179 return nullptr; |
176 | 180 |
177 // In the basic scenarios handled by BasicFocusRules, the pool of activatable | 181 // In the basic scenarios handled by BasicFocusRules, the pool of activatable |
178 // windows is limited to the |ignore|'s siblings. | 182 // windows is limited to the |ignore|'s siblings. |
179 const aura::Window::Windows& siblings = ignore->parent()->children(); | 183 const aura::Window::Windows& siblings = ignore->parent()->children(); |
180 DCHECK(!siblings.empty()); | 184 DCHECK(!siblings.empty()); |
181 | 185 |
182 for (aura::Window::Windows::const_reverse_iterator rit = siblings.rbegin(); | 186 for (aura::Window::Windows::const_reverse_iterator rit = siblings.rbegin(); |
183 rit != siblings.rend(); | 187 rit != siblings.rend(); |
184 ++rit) { | 188 ++rit) { |
185 aura::Window* cur = *rit; | 189 aura::Window* cur = *rit; |
186 if (cur == ignore) | 190 if (cur == ignore) |
187 continue; | 191 continue; |
188 if (CanActivateWindow(cur)) | 192 if (CanActivateWindow(cur)) |
189 return cur; | 193 return cur; |
190 } | 194 } |
191 return NULL; | 195 return nullptr; |
192 } | 196 } |
193 | 197 |
194 } // namespace wm | 198 } // namespace wm |
OLD | NEW |