Android: Get rid of extra dup()s on launching child processes
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / desktop_focus_rules.cc
blob1d7d40c5e3dc133ac13b6ed3628f72ea95a17d30
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
3 // found in the LICENSE file.
5 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h"
7 #include "ui/aura/window.h"
8 #include "ui/aura/window_event_dispatcher.h"
10 namespace views {
12 DesktopFocusRules::DesktopFocusRules(aura::Window* content_window)
13 : content_window_(content_window) {}
15 DesktopFocusRules::~DesktopFocusRules() {}
17 bool DesktopFocusRules::CanActivateWindow(aura::Window* window) const {
18 if (!BaseFocusRules::CanActivateWindow(window))
19 return false;
20 // Never activate a window that is not a child of the root window. Transients
21 // spanning different DesktopNativeWidgetAuras may trigger this.
22 return !window || content_window_->GetRootWindow()->Contains(window);
25 bool DesktopFocusRules::SupportsChildActivation(aura::Window* window) const {
26 // In Desktop-Aura, only the content_window or children of the RootWindow are
27 // activatable.
28 return window == content_window_->parent() ||
29 window->GetRootWindow() == window;
32 bool DesktopFocusRules::IsWindowConsideredVisibleForActivation(
33 aura::Window* window) const {
34 // |content_window_| is initially hidden and made visible from Show(). Even in
35 // this state we still want it to be active.
36 return BaseFocusRules::IsWindowConsideredVisibleForActivation(window) ||
37 (window == content_window_);
40 aura::Window* DesktopFocusRules::GetToplevelWindow(
41 aura::Window* window) const {
42 aura::Window* top_level_window =
43 wm::BaseFocusRules::GetToplevelWindow(window);
44 // In Desktop-Aura, only the content_window or children of the RootWindow are
45 // considered as top level windows.
46 if (top_level_window == content_window_->parent())
47 return content_window_;
48 return top_level_window;
51 aura::Window* DesktopFocusRules::GetNextActivatableWindow(
52 aura::Window* window) const {
53 aura::Window* next_activatable_window =
54 wm::BaseFocusRules::GetNextActivatableWindow(window);
55 // In Desktop-Aura the content_window_'s parent is a dummy window and thus
56 // should never be activated. We should return the content_window_ if it
57 // can be activated in this case.
58 if (next_activatable_window == content_window_->parent() &&
59 CanActivateWindow(content_window_))
60 return content_window_;
61 return next_activatable_window;
64 } // namespace views