summaryrefslogtreecommitdiff
path: root/chromium/ui/views/widget/desktop_aura/desktop_focus_rules.cc
blob: 1d7d40c5e3dc133ac13b6ed3628f72ea95a17d30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2012 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 "ui/views/widget/desktop_aura/desktop_focus_rules.h"

#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"

namespace views {

DesktopFocusRules::DesktopFocusRules(aura::Window* content_window)
    : content_window_(content_window) {}

DesktopFocusRules::~DesktopFocusRules() {}

bool DesktopFocusRules::CanActivateWindow(aura::Window* window) const {
  if (!BaseFocusRules::CanActivateWindow(window))
    return false;
  // Never activate a window that is not a child of the root window. Transients
  // spanning different DesktopNativeWidgetAuras may trigger this.
  return !window || content_window_->GetRootWindow()->Contains(window);
}

bool DesktopFocusRules::SupportsChildActivation(aura::Window* window) const {
  // In Desktop-Aura, only the content_window or children of the RootWindow are
  // activatable.
  return window == content_window_->parent() ||
         window->GetRootWindow() == window;
}

bool DesktopFocusRules::IsWindowConsideredVisibleForActivation(
    aura::Window* window) const {
  // |content_window_| is initially hidden and made visible from Show(). Even in
  // this state we still want it to be active.
  return BaseFocusRules::IsWindowConsideredVisibleForActivation(window) ||
      (window == content_window_);
}

aura::Window* DesktopFocusRules::GetToplevelWindow(
    aura::Window* window) const {
  aura::Window* top_level_window =
      wm::BaseFocusRules::GetToplevelWindow(window);
  // In Desktop-Aura, only the content_window or children of the RootWindow are
  // considered as top level windows.
  if (top_level_window == content_window_->parent())
    return content_window_;
  return top_level_window;
}

aura::Window* DesktopFocusRules::GetNextActivatableWindow(
    aura::Window* window) const {
  aura::Window* next_activatable_window =
      wm::BaseFocusRules::GetNextActivatableWindow(window);
  // In Desktop-Aura the content_window_'s parent is a dummy window and thus
  // should never be activated. We should return the content_window_ if it
  // can be activated in this case.
  if (next_activatable_window == content_window_->parent() &&
      CanActivateWindow(content_window_))
    return content_window_;
  return next_activatable_window;
}

}  // namespace views