OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "services/window_manager/focus_controller.h" | 5 #include "services/window_manager/focus_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "mojo/services/public/cpp/view_manager/view_property.h" | 8 #include "mojo/services/public/cpp/view_manager/view_property.h" |
9 #include "mojo/services/public/cpp/view_manager/view_tracker.h" | 9 #include "mojo/services/public/cpp/view_manager/view_tracker.h" |
10 #include "services/window_manager/focus_controller_observer.h" | 10 #include "services/window_manager/focus_controller_observer.h" |
11 #include "services/window_manager/focus_rules.h" | 11 #include "services/window_manager/focus_rules.h" |
12 #include "services/window_manager/view_target.h" | 12 #include "services/window_manager/view_target.h" |
13 #include "services/window_manager/window_manager_app.h" | 13 #include "services/window_manager/window_manager_app.h" |
14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
15 | 15 |
16 DECLARE_VIEW_PROPERTY_TYPE(mojo::FocusController*); | 16 DECLARE_VIEW_PROPERTY_TYPE(window_manager::FocusController*); |
17 | 17 |
18 namespace mojo { | 18 using mojo::View; |
| 19 |
| 20 namespace window_manager { |
19 | 21 |
20 namespace { | 22 namespace { |
21 DEFINE_VIEW_PROPERTY_KEY(FocusController*, kRootViewFocusController, nullptr); | 23 DEFINE_VIEW_PROPERTY_KEY(FocusController*, kRootViewFocusController, nullptr); |
22 } // namespace | 24 } // namespace |
23 | 25 |
24 FocusController::FocusController(scoped_ptr<FocusRules> rules) | 26 FocusController::FocusController(scoped_ptr<FocusRules> rules) |
25 : active_view_(nullptr), | 27 : active_view_(nullptr), |
26 focused_view_(nullptr), | 28 focused_view_(nullptr), |
27 updating_focus_(false), | 29 updating_focus_(false), |
28 updating_activation_(false), | 30 updating_activation_(false), |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 DCHECK_EQ(view, rules_->GetFocusableView(view)); | 193 DCHECK_EQ(view, rules_->GetFocusableView(view)); |
192 | 194 |
193 base::AutoReset<bool> updating_focus(&updating_focus_, true); | 195 base::AutoReset<bool> updating_focus(&updating_focus_, true); |
194 View* lost_focus = focused_view_; | 196 View* lost_focus = focused_view_; |
195 | 197 |
196 // TODO(erg): In the aura version, we reset the text input client here. Do | 198 // TODO(erg): In the aura version, we reset the text input client here. Do |
197 // that if we bring in something like the TextInputClient. | 199 // that if we bring in something like the TextInputClient. |
198 | 200 |
199 // Allow for the window losing focus to be deleted during dispatch. If it is | 201 // Allow for the window losing focus to be deleted during dispatch. If it is |
200 // deleted pass null to observers instead of a deleted window. | 202 // deleted pass null to observers instead of a deleted window. |
201 ViewTracker view_tracker; | 203 mojo::ViewTracker view_tracker; |
202 if (lost_focus) | 204 if (lost_focus) |
203 view_tracker.Add(lost_focus); | 205 view_tracker.Add(lost_focus); |
204 if (focused_view_ && observer_manager_.IsObserving(focused_view_) && | 206 if (focused_view_ && observer_manager_.IsObserving(focused_view_) && |
205 focused_view_ != active_view_) { | 207 focused_view_ != active_view_) { |
206 observer_manager_.Remove(focused_view_); | 208 observer_manager_.Remove(focused_view_); |
207 } | 209 } |
208 focused_view_ = view; | 210 focused_view_ = view; |
209 if (focused_view_ && !observer_manager_.IsObserving(focused_view_)) | 211 if (focused_view_ && !observer_manager_.IsObserving(focused_view_)) |
210 observer_manager_.Add(focused_view_); | 212 observer_manager_.Add(focused_view_); |
211 | 213 |
(...skipping 26 matching lines...) Expand all Loading... |
238 } | 240 } |
239 | 241 |
240 DCHECK(rules_->CanActivateView(view)); | 242 DCHECK(rules_->CanActivateView(view)); |
241 if (view) | 243 if (view) |
242 DCHECK_EQ(view, rules_->GetActivatableView(view)); | 244 DCHECK_EQ(view, rules_->GetActivatableView(view)); |
243 | 245 |
244 base::AutoReset<bool> updating_activation(&updating_activation_, true); | 246 base::AutoReset<bool> updating_activation(&updating_activation_, true); |
245 View* lost_activation = active_view_; | 247 View* lost_activation = active_view_; |
246 // Allow for the window losing activation to be deleted during dispatch. If | 248 // Allow for the window losing activation to be deleted during dispatch. If |
247 // it is deleted pass null to observers instead of a deleted window. | 249 // it is deleted pass null to observers instead of a deleted window. |
248 ViewTracker view_tracker; | 250 mojo::ViewTracker view_tracker; |
249 if (lost_activation) | 251 if (lost_activation) |
250 view_tracker.Add(lost_activation); | 252 view_tracker.Add(lost_activation); |
251 if (active_view_ && observer_manager_.IsObserving(active_view_) && | 253 if (active_view_ && observer_manager_.IsObserving(active_view_) && |
252 focused_view_ != active_view_) { | 254 focused_view_ != active_view_) { |
253 observer_manager_.Remove(active_view_); | 255 observer_manager_.Remove(active_view_); |
254 } | 256 } |
255 active_view_ = view; | 257 active_view_ = view; |
256 if (active_view_ && !observer_manager_.IsObserving(active_view_)) | 258 if (active_view_ && !observer_manager_.IsObserving(active_view_)) |
257 observer_manager_.Add(active_view_); | 259 observer_manager_.Add(active_view_); |
258 | 260 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 root_view->SetLocalProperty(kRootViewFocusController, focus_controller); | 312 root_view->SetLocalProperty(kRootViewFocusController, focus_controller); |
311 } | 313 } |
312 | 314 |
313 FocusController* GetFocusController(View* root_view) { | 315 FocusController* GetFocusController(View* root_view) { |
314 if (root_view) | 316 if (root_view) |
315 DCHECK_EQ(root_view->GetRoot(), root_view); | 317 DCHECK_EQ(root_view->GetRoot(), root_view); |
316 return root_view ? | 318 return root_view ? |
317 root_view->GetLocalProperty(kRootViewFocusController) : nullptr; | 319 root_view->GetLocalProperty(kRootViewFocusController) : nullptr; |
318 } | 320 } |
319 | 321 |
320 } // namespace mojo | 322 } // namespace window_manager |
OLD | NEW |