OLD | NEW |
| (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 "mojo/services/window_manager/basic_focus_rules.h" | |
6 | |
7 #include "base/macros.h" | |
8 #include "mojo/services/public/cpp/view_manager/view.h" | |
9 #include "mojo/services/window_manager/window_manager_app.h" | |
10 | |
11 namespace mojo { | |
12 | |
13 BasicFocusRules::BasicFocusRules(mojo::WindowManagerApp* window_manager_app, | |
14 mojo::View* window_container) | |
15 : window_container_(window_container), | |
16 window_manager_app_(window_manager_app) {} | |
17 | |
18 BasicFocusRules::~BasicFocusRules() {} | |
19 | |
20 bool BasicFocusRules::IsToplevelView(mojo::View* view) const { | |
21 return view->parent() == window_container_; | |
22 } | |
23 | |
24 bool BasicFocusRules::CanActivateView(mojo::View* view) const { | |
25 // TODO(erg): This needs to check visibility, along with focus, and several | |
26 // other things (see wm::BaseFocusRules). | |
27 return view->parent() == window_container_; | |
28 } | |
29 | |
30 bool BasicFocusRules::CanFocusView(mojo::View* view) const { | |
31 return true; | |
32 } | |
33 | |
34 mojo::View* BasicFocusRules::GetToplevelView(mojo::View* view) const { | |
35 while (view->parent() != window_container_) { | |
36 view = view->parent(); | |
37 // Unparented hierarchy, there is no "top level" window. | |
38 if (!view) | |
39 return nullptr; | |
40 } | |
41 | |
42 return view; | |
43 } | |
44 | |
45 mojo::View* BasicFocusRules::GetActivatableView(mojo::View* view) const { | |
46 return GetToplevelView(view); | |
47 } | |
48 | |
49 mojo::View* BasicFocusRules::GetFocusableView(mojo::View* view) const { | |
50 return view; | |
51 } | |
52 | |
53 mojo::View* BasicFocusRules::GetNextActivatableView( | |
54 mojo::View* activatable) const { | |
55 const mojo::View::Children& children = activatable->parent()->children(); | |
56 for (mojo::View::Children::const_reverse_iterator it = children.rbegin(); | |
57 it != children.rend(); ++it) { | |
58 if (*it != activatable) | |
59 return *it; | |
60 } | |
61 return nullptr; | |
62 } | |
63 | |
64 } // namespace mojo | |
OLD | NEW |