OLD | NEW |
| (Empty) |
1 // Copyright 2016 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. | |
4 | |
5 #include "ash/aura/wm_shell_aura.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "ash/accelerators/accelerator_controller.h" | |
10 #include "ash/accelerators/accelerator_controller_delegate_aura.h" | |
11 #include "ash/aura/key_event_watcher_aura.h" | |
12 #include "ash/aura/pointer_watcher_adapter.h" | |
13 #include "ash/display/window_tree_host_manager.h" | |
14 #include "ash/host/ash_window_tree_host_init_params.h" | |
15 #include "ash/keyboard/keyboard_ui.h" | |
16 #include "ash/laser/laser_pointer_controller.h" | |
17 #include "ash/magnifier/partial_magnification_controller.h" | |
18 #include "ash/metrics/task_switch_metrics_recorder.h" | |
19 #include "ash/public/cpp/config.h" | |
20 #include "ash/session/session_state_delegate.h" | |
21 #include "ash/shared/immersive_fullscreen_controller.h" | |
22 #include "ash/shell.h" | |
23 #include "ash/shell_delegate.h" | |
24 #include "ash/shell_observer.h" | |
25 #include "ash/touch/touch_uma.h" | |
26 #include "ash/virtual_keyboard_controller.h" | |
27 #include "ash/wm/drag_window_resizer.h" | |
28 #include "ash/wm/maximize_mode/maximize_mode_event_handler_aura.h" | |
29 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" | |
30 #include "ash/wm/mru_window_tracker.h" | |
31 #include "ash/wm/overview/window_selector_controller.h" | |
32 #include "ash/wm/window_cycle_event_filter_aura.h" | |
33 #include "ash/wm/window_util.h" | |
34 #include "ash/wm/workspace/workspace_event_handler_aura.h" | |
35 #include "ash/wm_display_observer.h" | |
36 #include "ash/wm_window.h" | |
37 #include "base/memory/ptr_util.h" | |
38 #include "ui/aura/env.h" | |
39 #include "ui/display/manager/display_manager.h" | |
40 | |
41 #if defined(USE_X11) | |
42 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h" | |
43 #endif | |
44 | |
45 #if defined(USE_OZONE) | |
46 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.
h" | |
47 #endif | |
48 | |
49 namespace ash { | |
50 | |
51 WmShellAura::WmShellAura() {} | |
52 | |
53 WmShellAura::~WmShellAura() {} | |
54 | |
55 // static | |
56 WmShellAura* WmShellAura::Get() { | |
57 CHECK(!WmShell::Get()->IsRunningInMash()); | |
58 return static_cast<WmShellAura*>(WmShell::Get()); | |
59 } | |
60 | |
61 void WmShellAura::Shutdown() { | |
62 if (added_display_observer_) | |
63 Shell::Get()->window_tree_host_manager()->RemoveObserver(this); | |
64 | |
65 pointer_watcher_adapter_.reset(); | |
66 | |
67 WmShell::Shutdown(); | |
68 | |
69 Shell::Get()->window_tree_host_manager()->Shutdown(); | |
70 } | |
71 | |
72 bool WmShellAura::IsRunningInMash() const { | |
73 return false; | |
74 } | |
75 | |
76 Config WmShellAura::GetAshConfig() const { | |
77 return Config::CLASSIC; | |
78 } | |
79 | |
80 WmWindow* WmShellAura::GetPrimaryRootWindow() { | |
81 return WmWindow::Get( | |
82 Shell::Get()->window_tree_host_manager()->GetPrimaryRootWindow()); | |
83 } | |
84 | |
85 WmWindow* WmShellAura::GetRootWindowForDisplayId(int64_t display_id) { | |
86 return WmWindow::Get( | |
87 Shell::Get()->window_tree_host_manager()->GetRootWindowForDisplayId( | |
88 display_id)); | |
89 } | |
90 | |
91 const display::ManagedDisplayInfo& WmShellAura::GetDisplayInfo( | |
92 int64_t display_id) const { | |
93 return Shell::Get()->display_manager()->GetDisplayInfo(display_id); | |
94 } | |
95 | |
96 bool WmShellAura::IsActiveDisplayId(int64_t display_id) const { | |
97 return Shell::Get()->display_manager()->IsActiveDisplayId(display_id); | |
98 } | |
99 | |
100 display::Display WmShellAura::GetFirstDisplay() const { | |
101 return Shell::Get()->display_manager()->software_mirroring_display_list()[0]; | |
102 } | |
103 | |
104 bool WmShellAura::IsInUnifiedMode() const { | |
105 return Shell::Get()->display_manager()->IsInUnifiedMode(); | |
106 } | |
107 | |
108 bool WmShellAura::IsInUnifiedModeIgnoreMirroring() const { | |
109 return Shell::Get() | |
110 ->display_manager() | |
111 ->current_default_multi_display_mode() == | |
112 display::DisplayManager::UNIFIED; | |
113 } | |
114 | |
115 void WmShellAura::SetDisplayWorkAreaInsets(WmWindow* window, | |
116 const gfx::Insets& insets) { | |
117 Shell::Get() | |
118 ->window_tree_host_manager() | |
119 ->UpdateWorkAreaOfDisplayNearestWindow(window->aura_window(), insets); | |
120 } | |
121 | |
122 void WmShellAura::LockCursor() { | |
123 Shell::Get()->cursor_manager()->LockCursor(); | |
124 } | |
125 | |
126 void WmShellAura::UnlockCursor() { | |
127 Shell::Get()->cursor_manager()->UnlockCursor(); | |
128 } | |
129 | |
130 bool WmShellAura::IsMouseEventsEnabled() { | |
131 return Shell::Get()->cursor_manager()->IsMouseEventsEnabled(); | |
132 } | |
133 | |
134 std::vector<WmWindow*> WmShellAura::GetAllRootWindows() { | |
135 aura::Window::Windows root_windows = | |
136 Shell::Get()->window_tree_host_manager()->GetAllRootWindows(); | |
137 std::vector<WmWindow*> wm_windows(root_windows.size()); | |
138 for (size_t i = 0; i < root_windows.size(); ++i) | |
139 wm_windows[i] = WmWindow::Get(root_windows[i]); | |
140 return wm_windows; | |
141 } | |
142 | |
143 void WmShellAura::RecordUserMetricsAction(UserMetricsAction action) { | |
144 Shell::Get()->metrics()->RecordUserMetricsAction(action); | |
145 } | |
146 | |
147 void WmShellAura::RecordGestureAction(GestureActionType action) { | |
148 TouchUMA::GetInstance()->RecordGestureAction(action); | |
149 } | |
150 | |
151 void WmShellAura::RecordTaskSwitchMetric(TaskSwitchSource source) { | |
152 Shell::Get()->metrics()->task_switch_metrics_recorder().OnTaskSwitch(source); | |
153 } | |
154 | |
155 std::unique_ptr<WindowResizer> WmShellAura::CreateDragWindowResizer( | |
156 std::unique_ptr<WindowResizer> next_window_resizer, | |
157 wm::WindowState* window_state) { | |
158 return base::WrapUnique( | |
159 DragWindowResizer::Create(next_window_resizer.release(), window_state)); | |
160 } | |
161 | |
162 std::unique_ptr<WindowCycleEventFilter> | |
163 WmShellAura::CreateWindowCycleEventFilter() { | |
164 return base::MakeUnique<WindowCycleEventFilterAura>(); | |
165 } | |
166 | |
167 std::unique_ptr<wm::MaximizeModeEventHandler> | |
168 WmShellAura::CreateMaximizeModeEventHandler() { | |
169 return base::WrapUnique(new wm::MaximizeModeEventHandlerAura); | |
170 } | |
171 | |
172 std::unique_ptr<WorkspaceEventHandler> WmShellAura::CreateWorkspaceEventHandler( | |
173 WmWindow* workspace_window) { | |
174 return base::MakeUnique<WorkspaceEventHandlerAura>(workspace_window); | |
175 } | |
176 | |
177 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> | |
178 WmShellAura::CreateScopedDisableInternalMouseAndKeyboard() { | |
179 #if defined(USE_X11) | |
180 return base::WrapUnique(new ScopedDisableInternalMouseAndKeyboardX11); | |
181 #elif defined(USE_OZONE) | |
182 return base::WrapUnique(new ScopedDisableInternalMouseAndKeyboardOzone); | |
183 #endif | |
184 return nullptr; | |
185 } | |
186 | |
187 std::unique_ptr<ImmersiveFullscreenController> | |
188 WmShellAura::CreateImmersiveFullscreenController() { | |
189 return base::MakeUnique<ImmersiveFullscreenController>(); | |
190 } | |
191 | |
192 std::unique_ptr<KeyboardUI> WmShellAura::CreateKeyboardUI() { | |
193 return KeyboardUI::Create(); | |
194 } | |
195 | |
196 std::unique_ptr<KeyEventWatcher> WmShellAura::CreateKeyEventWatcher() { | |
197 return base::MakeUnique<KeyEventWatcherAura>(); | |
198 } | |
199 | |
200 SessionStateDelegate* WmShellAura::GetSessionStateDelegate() { | |
201 return Shell::Get()->session_state_delegate(); | |
202 } | |
203 | |
204 void WmShellAura::AddDisplayObserver(WmDisplayObserver* observer) { | |
205 if (!added_display_observer_) { | |
206 added_display_observer_ = true; | |
207 Shell::Get()->window_tree_host_manager()->AddObserver(this); | |
208 } | |
209 display_observers_.AddObserver(observer); | |
210 } | |
211 | |
212 void WmShellAura::RemoveDisplayObserver(WmDisplayObserver* observer) { | |
213 display_observers_.RemoveObserver(observer); | |
214 } | |
215 | |
216 void WmShellAura::AddPointerWatcher(views::PointerWatcher* watcher, | |
217 views::PointerWatcherEventTypes events) { | |
218 pointer_watcher_adapter_->AddPointerWatcher(watcher, events); | |
219 } | |
220 | |
221 void WmShellAura::RemovePointerWatcher(views::PointerWatcher* watcher) { | |
222 pointer_watcher_adapter_->RemovePointerWatcher(watcher); | |
223 } | |
224 | |
225 bool WmShellAura::IsTouchDown() { | |
226 return aura::Env::GetInstance()->is_touch_down(); | |
227 } | |
228 | |
229 void WmShellAura::ToggleIgnoreExternalKeyboard() { | |
230 Shell::Get()->virtual_keyboard_controller()->ToggleIgnoreExternalKeyboard(); | |
231 } | |
232 | |
233 void WmShellAura::SetLaserPointerEnabled(bool enabled) { | |
234 Shell::Get()->laser_pointer_controller()->SetEnabled(enabled); | |
235 } | |
236 | |
237 void WmShellAura::SetPartialMagnifierEnabled(bool enabled) { | |
238 Shell::Get()->partial_magnification_controller()->SetEnabled(enabled); | |
239 } | |
240 | |
241 void WmShellAura::CreatePointerWatcherAdapter() { | |
242 pointer_watcher_adapter_ = base::MakeUnique<PointerWatcherAdapter>(); | |
243 } | |
244 | |
245 void WmShellAura::CreatePrimaryHost() { | |
246 Shell::Get()->window_tree_host_manager()->Start(); | |
247 AshWindowTreeHostInitParams ash_init_params; | |
248 Shell::Get()->window_tree_host_manager()->CreatePrimaryHost(ash_init_params); | |
249 } | |
250 | |
251 void WmShellAura::InitHosts(const ShellInitParams& init_params) { | |
252 Shell::Get()->window_tree_host_manager()->InitHosts(); | |
253 } | |
254 | |
255 std::unique_ptr<AcceleratorController> | |
256 WmShellAura::CreateAcceleratorController() { | |
257 DCHECK(!accelerator_controller_delegate_); | |
258 accelerator_controller_delegate_ = | |
259 base::MakeUnique<AcceleratorControllerDelegateAura>(); | |
260 return base::MakeUnique<AcceleratorController>( | |
261 accelerator_controller_delegate_.get(), nullptr); | |
262 } | |
263 | |
264 void WmShellAura::OnDisplayConfigurationChanging() { | |
265 for (auto& observer : display_observers_) | |
266 observer.OnDisplayConfigurationChanging(); | |
267 } | |
268 | |
269 void WmShellAura::OnDisplayConfigurationChanged() { | |
270 for (auto& observer : display_observers_) | |
271 observer.OnDisplayConfigurationChanged(); | |
272 } | |
273 | |
274 } // namespace ash | |
OLD | NEW |