summaryrefslogtreecommitdiff
path: root/chromium/ash/wm/ash_activation_controller.cc
blob: 146cf4930831561e97d11e2b8b72a6369efffdd9 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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 "ash/wm/ash_activation_controller.h"

#include "ash/launcher/launcher.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/wm/activation_controller.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller.h"
#include "ui/views/corewm/window_modality_controller.h"
#include "ui/views/widget/widget.h"

namespace ash {
namespace internal {

////////////////////////////////////////////////////////////////////////////////
// AshActivationController, public:

AshActivationController::AshActivationController() {
}

AshActivationController::~AshActivationController() {
}

////////////////////////////////////////////////////////////////////////////////
// AshActivationController, ActivationControllerDelegate implementation:

aura::Window* AshActivationController::WillActivateWindow(
    aura::Window* window) {
  aura::Window* window_modal_transient =
      views::corewm::GetModalTransient(window);
  if (window_modal_transient)
    return window_modal_transient;

  // Fallback to launcher
  if (!window)
    window = PrepareToActivateLauncher();

  // Restore minimized window. This needs to be done before CanReceiveEvents()
  // is called as that function checks window visibility.
  if (window && wm::IsWindowMinimized(window))
    window->Show();

  // If the screen is locked, just bring the window to top so that
  // it will be activated when the lock window is destroyed.
  // TODO(beng): Call EventClient directly here, rather than conflating with
  //             window visibility.
  if (window && !window->CanReceiveEvents())
    return NULL;

  // TODO(beng): could probably move to being a ActivationChangeObserver on
  //             Shell.
  if (window) {
    DCHECK(window->GetRootWindow());
    Shell::GetInstance()->set_active_root_window(window->GetRootWindow());
  }
  return window;
}

aura::Window* AshActivationController::WillFocusWindow(
    aura::Window* window) {
  aura::Window* window_modal_transient =
      views::corewm::GetModalTransient(window);
  if (window_modal_transient)
    return window_modal_transient;
  return window;
}

aura::Window* AshActivationController::PrepareToActivateLauncher() {
  // If workspace controller is not available, then it means that the root
  // window is being destroyed. We can't activate any window then.
  if (!GetRootWindowController(
      Shell::GetActiveRootWindow())->workspace_controller()) {
    return NULL;
  }
  // Fallback to a launcher only when Spoken feedback is enabled.
  if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
    return NULL;
  ShelfWidget* shelf = GetRootWindowController(
      Shell::GetActiveRootWindow())->shelf();
  // Launcher's window may be already destroyed in shutting down process.
  if (!shelf)
    return NULL;
  // Notify launcher to allow activation via CanActivate().
  shelf->WillActivateAsFallback();
  return shelf->GetNativeWindow();
}

}  // namespace internal
}  // namespace ash