summaryrefslogtreecommitdiff
path: root/chromium/components/exo/wm_helper_ash.cc
blob: 23beac2a1e1ec37b86859b4d2f3eded3b1259784 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2016 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 "components/exo/wm_helper_ash.h"

#include "ash/public/cpp/config.h"
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "base/memory/singleton.h"
#include "ui/aura/client/focus_client.h"
#include "ui/display/manager/display_manager.h"
#include "ui/events/devices/input_device_manager.h"
#include "ui/wm/public/activation_client.h"

namespace exo {

////////////////////////////////////////////////////////////////////////////////
// WMHelperAsh, public:

WMHelperAsh::WMHelperAsh() {
  ash::Shell::Get()->AddShellObserver(this);
  ash::Shell::Get()->activation_client()->AddObserver(this);
  // TODO(crbug.com/631103): Mushrome doesn't have a cursor manager yet.
  if (ash::ShellPort::Get()->GetAshConfig() != ash::Config::MUS)
    ash::Shell::Get()->cursor_manager()->AddObserver(this);
  ash::ShellPort::Get()->AddDisplayObserver(this);
  aura::client::FocusClient* focus_client =
      aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow());
  focus_client->AddObserver(this);
  ui::InputDeviceManager::GetInstance()->AddObserver(this);
}

WMHelperAsh::~WMHelperAsh() {
  if (!ash::Shell::HasInstance())
    return;
  aura::client::FocusClient* focus_client =
      aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow());
  focus_client->RemoveObserver(this);
  ash::ShellPort::Get()->RemoveDisplayObserver(this);
  // TODO(crbug.com/631103): Mushrome doesn't have a cursor manager yet.
  if (ash::ShellPort::Get()->GetAshConfig() != ash::Config::MUS)
    ash::Shell::Get()->cursor_manager()->RemoveObserver(this);
  ash::Shell::Get()->activation_client()->RemoveObserver(this);
  ash::Shell::Get()->RemoveShellObserver(this);
  ui::InputDeviceManager::GetInstance()->RemoveObserver(this);
}

////////////////////////////////////////////////////////////////////////////////
// WMHelperAsh, private:

const display::ManagedDisplayInfo& WMHelperAsh::GetDisplayInfo(
    int64_t display_id) const {
  return ash::Shell::Get()->display_manager()->GetDisplayInfo(display_id);
}

aura::Window* WMHelperAsh::GetPrimaryDisplayContainer(int container_id) {
  return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
                                  container_id);
}

aura::Window* WMHelperAsh::GetActiveWindow() const {
  return ash::Shell::Get()->activation_client()->GetActiveWindow();
}

aura::Window* WMHelperAsh::GetFocusedWindow() const {
  aura::client::FocusClient* focus_client =
      aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow());
  return focus_client->GetFocusedWindow();
}

ui::CursorSetType WMHelperAsh::GetCursorSet() const {
  // TODO(crbug.com/631103): Mushrome doesn't have a cursor manager yet.
  if (ash::ShellPort::Get()->GetAshConfig() == ash::Config::MUS)
    return ui::CURSOR_SET_NORMAL;
  return ash::Shell::Get()->cursor_manager()->GetCursorSet();
}

const display::Display& WMHelperAsh::GetCursorDisplay() const {
  // TODO(crbug.com/631103): Mushrome doesn't have a cursor manager yet.
  if (ash::ShellPort::Get()->GetAshConfig() == ash::Config::MUS) {
    static const display::Display display;
    return display;
  }
  return ash::Shell::Get()->cursor_manager()->GetDisplay();
}

void WMHelperAsh::AddPreTargetHandler(ui::EventHandler* handler) {
  ash::Shell::Get()->AddPreTargetHandler(handler);
}

void WMHelperAsh::PrependPreTargetHandler(ui::EventHandler* handler) {
  ash::Shell::Get()->PrependPreTargetHandler(handler);
}

void WMHelperAsh::RemovePreTargetHandler(ui::EventHandler* handler) {
  ash::Shell::Get()->RemovePreTargetHandler(handler);
}

void WMHelperAsh::AddPostTargetHandler(ui::EventHandler* handler) {
  ash::Shell::Get()->AddPostTargetHandler(handler);
}

void WMHelperAsh::RemovePostTargetHandler(ui::EventHandler* handler) {
  ash::Shell::Get()->RemovePostTargetHandler(handler);
}

bool WMHelperAsh::IsMaximizeModeWindowManagerEnabled() const {
  return ash::Shell::Get()
      ->maximize_mode_controller()
      ->IsMaximizeModeWindowManagerEnabled();
}

void WMHelperAsh::OnWindowActivated(
    aura::client::ActivationChangeObserver::ActivationReason reason,
    aura::Window* gained_active,
    aura::Window* lost_active) {
  NotifyWindowActivated(gained_active, lost_active);
}

void WMHelperAsh::OnWindowFocused(aura::Window* gained_focus,
                                  aura::Window* lost_focus) {
  NotifyWindowFocused(gained_focus, lost_focus);
}

void WMHelperAsh::OnCursorVisibilityChanged(bool is_visible) {
  NotifyCursorVisibilityChanged(is_visible);
}

void WMHelperAsh::OnCursorSetChanged(ui::CursorSetType cursor_set) {
  NotifyCursorSetChanged(cursor_set);
}

void WMHelperAsh::OnCursorDisplayChanged(const display::Display& display) {
  NotifyCursorDisplayChanged(display);
}

void WMHelperAsh::OnMaximizeModeStarted() {
  NotifyMaximizeModeStarted();
}

void WMHelperAsh::OnMaximizeModeEnding() {
  NotifyMaximizeModeEnding();
}

void WMHelperAsh::OnMaximizeModeEnded() {
  NotifyMaximizeModeEnded();
}

void WMHelperAsh::OnDisplayConfigurationChanged() {
  NotifyDisplayConfigurationChanged();
}

void WMHelperAsh::OnKeyboardDeviceConfigurationChanged() {
  NotifyKeyboardDeviceConfigurationChanged();
}

}  // namespace exo