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 "mojo/services/window_manager/focus_controller.h" | 5 #include "mojo/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_tracker.h" | 9 #include "mojo/services/public/cpp/view_manager/view_tracker.h" |
9 #include "mojo/services/window_manager/focus_controller_observer.h" | 10 #include "mojo/services/window_manager/focus_controller_observer.h" |
10 #include "mojo/services/window_manager/focus_rules.h" | 11 #include "mojo/services/window_manager/focus_rules.h" |
11 #include "mojo/services/window_manager/view_target.h" | 12 #include "mojo/services/window_manager/view_target.h" |
12 #include "mojo/services/window_manager/window_manager_app.h" | 13 #include "mojo/services/window_manager/window_manager_app.h" |
13 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
14 | 15 |
| 16 DECLARE_VIEW_PROPERTY_TYPE(mojo::FocusController*); |
| 17 |
15 namespace mojo { | 18 namespace mojo { |
16 | 19 |
| 20 namespace { |
| 21 DEFINE_VIEW_PROPERTY_KEY(FocusController*, kRootViewFocusController, nullptr); |
| 22 } // namespace |
| 23 |
17 FocusController::FocusController(scoped_ptr<FocusRules> rules) | 24 FocusController::FocusController(scoped_ptr<FocusRules> rules) |
18 : active_view_(nullptr), | 25 : active_view_(nullptr), |
19 focused_view_(nullptr), | 26 focused_view_(nullptr), |
20 updating_focus_(false), | 27 updating_focus_(false), |
21 updating_activation_(false), | 28 updating_activation_(false), |
22 rules_(rules.Pass()), | 29 rules_(rules.Pass()), |
23 observer_manager_(this) { | 30 observer_manager_(this) { |
24 DCHECK(rules_); | 31 DCHECK(rules_); |
25 } | 32 } |
26 | 33 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 298 } |
292 | 299 |
293 void FocusController::ViewFocusedFromInputEvent(View* view) { | 300 void FocusController::ViewFocusedFromInputEvent(View* view) { |
294 // Only focus |window| if it or any of its parents can be focused. Otherwise | 301 // Only focus |window| if it or any of its parents can be focused. Otherwise |
295 // FocusWindow() will focus the topmost window, which may not be the | 302 // FocusWindow() will focus the topmost window, which may not be the |
296 // currently focused one. | 303 // currently focused one. |
297 if (rules_->CanFocusView(GetToplevelView(view))) | 304 if (rules_->CanFocusView(GetToplevelView(view))) |
298 FocusView(view); | 305 FocusView(view); |
299 } | 306 } |
300 | 307 |
| 308 void SetFocusController(View* root_view, FocusController* focus_controller) { |
| 309 DCHECK_EQ(root_view->GetRoot(), root_view); |
| 310 root_view->SetLocalProperty(kRootViewFocusController, focus_controller); |
| 311 } |
| 312 |
| 313 FocusController* GetFocusController(View* root_view) { |
| 314 if (root_view) |
| 315 DCHECK_EQ(root_view->GetRoot(), root_view); |
| 316 return root_view ? |
| 317 root_view->GetLocalProperty(kRootViewFocusController) : nullptr; |
| 318 } |
| 319 |
301 } // namespace mojo | 320 } // namespace mojo |
OLD | NEW |