Chromium Code Reviews| Index: mojo/services/window_manager/basic_focus_rules.cc |
| diff --git a/mojo/services/window_manager/basic_focus_rules.cc b/mojo/services/window_manager/basic_focus_rules.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e3d063de519f7216b6d331d977d445d0061e172 |
| --- /dev/null |
| +++ b/mojo/services/window_manager/basic_focus_rules.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "mojo/services/window_manager/basic_focus_rules.h" |
| + |
| +#include "base/macros.h" |
| +#include "mojo/services/public/cpp/view_manager/view.h" |
| +#include "mojo/services/window_manager/window_manager_app.h" |
| + |
| +namespace mojo { |
| + |
| +BasicFocusRules::BasicFocusRules(mojo::WindowManagerApp* window_manager_app, |
| + mojo::View* window_container) |
| + : window_container_(window_container), |
| + window_manager_app_(window_manager_app) {} |
| + |
| +BasicFocusRules::~BasicFocusRules() {} |
| + |
| +bool BasicFocusRules::IsToplevelView(mojo::View* view) const { |
| + return view->parent() == window_container_; |
| +} |
| + |
| +bool BasicFocusRules::CanActivateView(mojo::View* view) const { |
| + return view->parent() == window_container_; |
|
sky
2014/11/10 20:45:30
Don't you want to check visibility/drawn in any of
Elliot Glaysher
2014/11/10 22:18:49
You do, but right now this is a straight port of t
|
| +} |
| + |
| +bool BasicFocusRules::CanFocusView(mojo::View* view) const { |
| + return true; |
| +} |
| + |
| +mojo::View* BasicFocusRules::GetToplevelView(mojo::View* view) const { |
| + while (view->parent() != window_container_) { |
| + view = view->parent(); |
| + // Unparented hierarchy, there is no "top level" window. |
| + if (!view) |
| + return NULL; |
|
sky
2014/11/10 20:45:30
nullptr every where.
|
| + } |
| + |
| + return view; |
| +} |
| + |
| +mojo::View* BasicFocusRules::GetActivatableView(mojo::View* view) const { |
| + return GetToplevelView(view); |
| +} |
| + |
| +mojo::View* BasicFocusRules::GetFocusableView(mojo::View* view) const { |
| + return view; |
| +} |
| + |
| +mojo::View* BasicFocusRules::GetNextActivatableView( |
| + mojo::View* activatable) const { |
| + const mojo::View::Children& children = activatable->parent()->children(); |
| + for (mojo::View::Children::const_reverse_iterator it = children.rbegin(); |
| + it != children.rend(); ++it) { |
| + if (*it != activatable) |
| + return *it; |
| + } |
| + return NULL; |
| +} |
| + |
| +} // namespace mojo |