Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: ash/shell.cc

Issue 2633293005: Converts mash to use Shell (Closed)
Patch Set: cleanup Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shell.h" 5 #include "ash/shell.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "ash/display/projecting_observer_chromeos.h" 51 #include "ash/display/projecting_observer_chromeos.h"
52 #include "ash/display/resolution_notification_controller.h" 52 #include "ash/display/resolution_notification_controller.h"
53 #include "ash/display/screen_ash.h" 53 #include "ash/display/screen_ash.h"
54 #include "ash/display/screen_orientation_controller_chromeos.h" 54 #include "ash/display/screen_orientation_controller_chromeos.h"
55 #include "ash/display/screen_position_controller.h" 55 #include "ash/display/screen_position_controller.h"
56 #include "ash/display/shutdown_observer_chromeos.h" 56 #include "ash/display/shutdown_observer_chromeos.h"
57 #include "ash/display/window_tree_host_manager.h" 57 #include "ash/display/window_tree_host_manager.h"
58 #include "ash/drag_drop/drag_drop_controller.h" 58 #include "ash/drag_drop/drag_drop_controller.h"
59 #include "ash/first_run/first_run_helper_impl.h" 59 #include "ash/first_run/first_run_helper_impl.h"
60 #include "ash/high_contrast/high_contrast_controller.h" 60 #include "ash/high_contrast/high_contrast_controller.h"
61 #include "ash/host/ash_window_tree_host_init_params.h"
62 #include "ash/ime/input_method_event_handler.h" 61 #include "ash/ime/input_method_event_handler.h"
63 #include "ash/laser/laser_pointer_controller.h" 62 #include "ash/laser/laser_pointer_controller.h"
64 #include "ash/magnifier/magnification_controller.h" 63 #include "ash/magnifier/magnification_controller.h"
65 #include "ash/magnifier/partial_magnification_controller.h" 64 #include "ash/magnifier/partial_magnification_controller.h"
66 #include "ash/public/cpp/shell_window_ids.h" 65 #include "ash/public/cpp/shell_window_ids.h"
67 #include "ash/root_window_controller.h" 66 #include "ash/root_window_controller.h"
68 #include "ash/shell_init_params.h" 67 #include "ash/shell_init_params.h"
69 #include "ash/sticky_keys/sticky_keys_controller.h" 68 #include "ash/sticky_keys/sticky_keys_controller.h"
70 #include "ash/system/chromeos/power/power_event_observer.h" 69 #include "ash/system/chromeos/power/power_event_observer.h"
71 #include "ash/system/chromeos/power/video_activity_notifier.h" 70 #include "ash/system/chromeos/power/video_activity_notifier.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 #include "ui/display/manager/chromeos/display_change_observer.h" 113 #include "ui/display/manager/chromeos/display_change_observer.h"
115 #include "ui/display/manager/chromeos/display_configurator.h" 114 #include "ui/display/manager/chromeos/display_configurator.h"
116 #include "ui/display/manager/display_manager.h" 115 #include "ui/display/manager/display_manager.h"
117 #include "ui/display/screen.h" 116 #include "ui/display/screen.h"
118 #include "ui/events/event_target_iterator.h" 117 #include "ui/events/event_target_iterator.h"
119 #include "ui/gfx/geometry/insets.h" 118 #include "ui/gfx/geometry/insets.h"
120 #include "ui/gfx/image/image_skia.h" 119 #include "ui/gfx/image/image_skia.h"
121 #include "ui/keyboard/keyboard_controller.h" 120 #include "ui/keyboard/keyboard_controller.h"
122 #include "ui/keyboard/keyboard_switches.h" 121 #include "ui/keyboard/keyboard_switches.h"
123 #include "ui/keyboard/keyboard_util.h" 122 #include "ui/keyboard/keyboard_util.h"
124 #include "ui/message_center/message_center.h"
125 #include "ui/views/corewm/tooltip_aura.h" 123 #include "ui/views/corewm/tooltip_aura.h"
126 #include "ui/views/corewm/tooltip_controller.h" 124 #include "ui/views/corewm/tooltip_controller.h"
127 #include "ui/views/widget/native_widget_aura.h" 125 #include "ui/views/widget/native_widget_aura.h"
128 #include "ui/views/widget/widget.h" 126 #include "ui/views/widget/widget.h"
129 #include "ui/wm/core/accelerator_filter.h" 127 #include "ui/wm/core/accelerator_filter.h"
130 #include "ui/wm/core/compound_event_filter.h" 128 #include "ui/wm/core/compound_event_filter.h"
131 #include "ui/wm/core/focus_controller.h" 129 #include "ui/wm/core/focus_controller.h"
132 #include "ui/wm/core/shadow_controller.h" 130 #include "ui/wm/core/shadow_controller.h"
133 #include "ui/wm/core/visibility_controller.h" 131 #include "ui/wm/core/visibility_controller.h"
134 #include "ui/wm/core/window_modality_controller.h" 132 #include "ui/wm/core/window_modality_controller.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 aura::WindowManagerClient* Shell::window_manager_client_ = nullptr; 175 aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
178 // static 176 // static
179 bool Shell::initially_hide_cursor_ = false; 177 bool Shell::initially_hide_cursor_ = false;
180 178
181 //////////////////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////////////////
182 // Shell, public: 180 // Shell, public:
183 181
184 // static 182 // static
185 Shell* Shell::CreateInstance(const ShellInitParams& init_params) { 183 Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
186 CHECK(!instance_); 184 CHECK(!instance_);
187 instance_ = new Shell(init_params.delegate); 185 WmShell* wm_shell = init_params.wm_shell;
James Cook 2017/01/18 01:00:25 This would be clearer if init_params.wm_shell was
sky 2017/01/18 04:00:08 I choose this as it requires less changes to call
186 if (!wm_shell)
187 wm_shell =
188 new WmShellAura(base::WrapUnique<ShellDelegate>(init_params.delegate));
189 instance_ = new Shell(base::WrapUnique<WmShell>(wm_shell));
188 instance_->Init(init_params); 190 instance_->Init(init_params);
189 return instance_; 191 return instance_;
190 } 192 }
191 193
192 // static 194 // static
193 Shell* Shell::GetInstance() { 195 Shell* Shell::GetInstance() {
194 CHECK(instance_); 196 CHECK(instance_);
195 return instance_; 197 return instance_;
196 } 198 }
197 199
198 // static 200 // static
199 bool Shell::HasInstance() { 201 bool Shell::HasInstance() {
200 return !!instance_; 202 return !!instance_;
201 } 203 }
202 204
203 // static 205 // static
204 void Shell::DeleteInstance() { 206 void Shell::DeleteInstance() {
205 delete instance_; 207 delete instance_;
206 } 208 }
207 209
208 // static 210 // static
209 RootWindowController* Shell::GetPrimaryRootWindowController() { 211 RootWindowController* Shell::GetPrimaryRootWindowController() {
210 CHECK(HasInstance()); 212 CHECK(HasInstance());
211 return GetRootWindowController(GetPrimaryRootWindow()); 213 return GetRootWindowController(GetPrimaryRootWindow());
212 } 214 }
213 215
214 // static 216 // static
215 Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() { 217 Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
216 CHECK(HasInstance()); 218 CHECK(HasInstance());
217 return Shell::GetInstance() 219 RootWindowControllerList root_window_controllers;
218 ->window_tree_host_manager() 220 for (WmWindow* root_window : instance_->wm_shell_->GetAllRootWindows())
219 ->GetAllRootWindowControllers(); 221 root_window_controllers.push_back(root_window->GetRootWindowController());
222 return root_window_controllers;
220 } 223 }
221 224
222 // static 225 // static
223 aura::Window* Shell::GetPrimaryRootWindow() { 226 aura::Window* Shell::GetPrimaryRootWindow() {
224 CHECK(HasInstance()); 227 CHECK(HasInstance());
225 return GetInstance()->window_tree_host_manager()->GetPrimaryRootWindow(); 228 return instance_->wm_shell_->GetPrimaryRootWindow()->aura_window();
226 } 229 }
227 230
228 // static 231 // static
229 aura::Window* Shell::GetTargetRootWindow() { 232 aura::Window* Shell::GetTargetRootWindow() {
230 CHECK(WmShell::HasInstance()); 233 CHECK(WmShell::HasInstance());
231 return WmWindow::GetAuraWindow(WmShell::Get()->GetRootWindowForNewWindows()); 234 return WmWindow::GetAuraWindow(WmShell::Get()->GetRootWindowForNewWindows());
232 } 235 }
233 236
234 // static 237 // static
235 int64_t Shell::GetTargetDisplayId() { 238 int64_t Shell::GetTargetDisplayId() {
236 return display::Screen::GetScreen() 239 return display::Screen::GetScreen()
237 ->GetDisplayNearestWindow(GetTargetRootWindow()) 240 ->GetDisplayNearestWindow(GetTargetRootWindow())
238 .id(); 241 .id();
239 } 242 }
240 243
241 // static 244 // static
242 aura::Window::Windows Shell::GetAllRootWindows() { 245 aura::Window::Windows Shell::GetAllRootWindows() {
243 CHECK(HasInstance()); 246 CHECK(HasInstance());
244 return Shell::GetInstance()->window_tree_host_manager()->GetAllRootWindows(); 247 aura::Window::Windows windows;
248 for (WmWindow* window : instance_->wm_shell_->GetAllRootWindows())
249 windows.push_back(window->aura_window());
250 return windows;
245 } 251 }
246 252
247 // static 253 // static
248 aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) { 254 aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
249 return root_window->GetChildById(container_id); 255 return root_window->GetChildById(container_id);
250 } 256 }
251 257
252 // static 258 // static
253 const aura::Window* Shell::GetContainer(const aura::Window* root_window, 259 const aura::Window* Shell::GetContainer(const aura::Window* root_window,
254 int container_id) { 260 int container_id) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 RootWindowControllerList controllers = GetAllRootWindowControllers(); 323 RootWindowControllerList controllers = GetAllRootWindowControllers();
318 for (RootWindowControllerList::iterator iter = controllers.begin(); 324 for (RootWindowControllerList::iterator iter = controllers.begin();
319 iter != controllers.end(); ++iter) { 325 iter != controllers.end(); ++iter) {
320 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance()); 326 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
321 } 327 }
322 } 328 }
323 keyboard::KeyboardController::ResetInstance(nullptr); 329 keyboard::KeyboardController::ResetInstance(nullptr);
324 } 330 }
325 331
326 bool Shell::ShouldSaveDisplaySettings() { 332 bool Shell::ShouldSaveDisplaySettings() {
333 DCHECK(!wm_shell_->IsRunningInMash());
327 return !( 334 return !(
328 screen_orientation_controller_->ignore_display_configuration_updates() || 335 screen_orientation_controller_->ignore_display_configuration_updates() ||
329 resolution_notification_controller_->DoesNotificationTimeout()); 336 resolution_notification_controller_->DoesNotificationTimeout());
330 } 337 }
331 338
332 void Shell::UpdateShelfVisibility() { 339 void Shell::UpdateShelfVisibility() {
333 for (WmWindow* root : wm_shell_->GetAllRootWindows()) 340 for (WmWindow* root : wm_shell_->GetAllRootWindows())
334 root->GetRootWindowController()->GetShelf()->UpdateVisibilityState(); 341 root->GetRootWindowController()->GetShelf()->UpdateVisibilityState();
335 } 342 }
336 343
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 376
370 void Shell::DoInitialWorkspaceAnimation() { 377 void Shell::DoInitialWorkspaceAnimation() {
371 return GetPrimaryRootWindowController() 378 return GetPrimaryRootWindowController()
372 ->workspace_controller() 379 ->workspace_controller()
373 ->DoInitialAnimation(); 380 ->DoInitialAnimation();
374 } 381 }
375 382
376 //////////////////////////////////////////////////////////////////////////////// 383 ////////////////////////////////////////////////////////////////////////////////
377 // Shell, private: 384 // Shell, private:
378 385
379 Shell::Shell(ShellDelegate* delegate) 386 Shell::Shell(std::unique_ptr<WmShell> wm_shell)
380 : wm_shell_(new WmShellAura(base::WrapUnique(delegate))), 387 : wm_shell_(std::move(wm_shell)),
381 link_handler_model_factory_(nullptr), 388 link_handler_model_factory_(nullptr),
382 activation_client_(nullptr), 389 activation_client_(nullptr),
383 display_configurator_(new display::DisplayConfigurator()), 390 display_configurator_(new display::DisplayConfigurator()),
384 native_cursor_manager_(nullptr), 391 native_cursor_manager_(nullptr),
385 simulate_modal_window_open_for_testing_(false), 392 simulate_modal_window_open_for_testing_(false),
386 is_touch_hud_projection_enabled_(false) { 393 is_touch_hud_projection_enabled_(false) {
387 DCHECK(aura::Env::GetInstanceDontCreate()); 394 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
388 gpu_support_.reset(wm_shell_->delegate()->CreateGPUSupport()); 395 // state on WmShellAura. http://crbug.com/671246.
389 display_manager_.reset(ScreenAsh::CreateDisplayManager()); 396
390 window_tree_host_manager_.reset(new WindowTreeHostManager); 397 if (!wm_shell_->IsRunningInMash()) {
391 user_metrics_recorder_.reset(new UserMetricsRecorder); 398 gpu_support_.reset(wm_shell_->delegate()->CreateGPUSupport());
399 display_manager_.reset(ScreenAsh::CreateDisplayManager());
400 window_tree_host_manager_.reset(new WindowTreeHostManager);
401 user_metrics_recorder_.reset(new UserMetricsRecorder);
402 }
392 403
393 PowerStatus::Initialize(); 404 PowerStatus::Initialize();
394 } 405 }
395 406
396 Shell::~Shell() { 407 Shell::~Shell() {
397 TRACE_EVENT0("shutdown", "ash::Shell::Destructor"); 408 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
398 409
399 user_metrics_recorder_->OnShellShuttingDown(); 410 const bool is_mash = wm_shell_->IsRunningInMash();
411
412 if (!is_mash)
413 user_metrics_recorder_->OnShellShuttingDown();
400 414
401 wm_shell_->delegate()->PreShutdown(); 415 wm_shell_->delegate()->PreShutdown();
402 416
403 // Remove the focus from any window. This will prevent overhead and side 417 // Remove the focus from any window. This will prevent overhead and side
404 // effects (e.g. crashes) from changing focus during shutdown. 418 // effects (e.g. crashes) from changing focus during shutdown.
405 // See bug crbug.com/134502. 419 // See bug crbug.com/134502.
406 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr); 420 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
407 421
408 // Please keep in same order as in Init() because it's easy to miss one. 422 // Please keep in same order as in Init() because it's easy to miss one.
409 if (window_modality_controller_) 423 if (window_modality_controller_)
410 window_modality_controller_.reset(); 424 window_modality_controller_.reset();
411 RemovePreTargetHandler( 425 if (!is_mash) {
412 window_tree_host_manager_->input_method_event_handler()); 426 RemovePreTargetHandler(
427 window_tree_host_manager_->input_method_event_handler());
428 }
413 429
414 RemovePreTargetHandler(magnifier_key_scroll_handler_.get()); 430 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
415 magnifier_key_scroll_handler_.reset(); 431 magnifier_key_scroll_handler_.reset();
416 432
417 RemovePreTargetHandler(speech_feedback_handler_.get()); 433 RemovePreTargetHandler(speech_feedback_handler_.get());
418 speech_feedback_handler_.reset(); 434 speech_feedback_handler_.reset();
419 435
420 RemovePreTargetHandler(overlay_filter_.get()); 436 RemovePreTargetHandler(overlay_filter_.get());
James Cook 2017/01/18 01:00:25 I'm guessing none of these pre-target handlers wor
sky 2017/01/18 04:00:08 Yes. I want to make Shell not implement EventHandl
421 RemovePreTargetHandler(accelerator_filter_.get()); 437 RemovePreTargetHandler(accelerator_filter_.get());
422 RemovePreTargetHandler(event_transformation_handler_.get()); 438 RemovePreTargetHandler(event_transformation_handler_.get());
423 RemovePreTargetHandler(toplevel_window_event_handler_.get()); 439 RemovePreTargetHandler(toplevel_window_event_handler_.get());
424 RemovePostTargetHandler(toplevel_window_event_handler_.get()); 440 RemovePostTargetHandler(toplevel_window_event_handler_.get());
425 RemovePreTargetHandler(system_gesture_filter_.get()); 441 if (!is_mash) {
426 RemovePreTargetHandler(mouse_cursor_filter_.get()); 442 RemovePreTargetHandler(system_gesture_filter_.get());
443 RemovePreTargetHandler(mouse_cursor_filter_.get());
444 }
427 RemovePreTargetHandler(modality_filter_.get()); 445 RemovePreTargetHandler(modality_filter_.get());
428 446
429 // TooltipController is deleted with the Shell so removing its references. 447 // TooltipController is deleted with the Shell so removing its references.
430 RemovePreTargetHandler(tooltip_controller_.get()); 448 RemovePreTargetHandler(tooltip_controller_.get());
431 449
432 screen_orientation_controller_.reset(); 450 screen_orientation_controller_.reset();
433 screen_layout_observer_.reset(); 451 screen_layout_observer_.reset();
434 452
435 // Destroy the virtual keyboard controller before the maximize mode controller 453 // Destroy the virtual keyboard controller before the maximize mode controller
436 // since the latters destructor triggers events that the former is listening 454 // since the latters destructor triggers events that the former is listening
(...skipping 30 matching lines...) Expand all
467 video_detector_.reset(); 485 video_detector_.reset();
468 high_contrast_controller_.reset(); 486 high_contrast_controller_.reset();
469 487
470 shadow_controller_.reset(); 488 shadow_controller_.reset();
471 resize_shadow_controller_.reset(); 489 resize_shadow_controller_.reset();
472 490
473 // Has to happen before ~MruWindowTracker. 491 // Has to happen before ~MruWindowTracker.
474 wm_shell_->DeleteWindowCycleController(); 492 wm_shell_->DeleteWindowCycleController();
475 wm_shell_->DeleteWindowSelectorController(); 493 wm_shell_->DeleteWindowSelectorController();
476 494
477 // Destroy all child windows including widgets. 495 CloseAllRootWindowChildWindows();
478 window_tree_host_manager_->CloseChildWindows(); 496
479 // MruWindowTracker must be destroyed after all windows have been deleted to 497 // MruWindowTracker must be destroyed after all windows have been deleted to
480 // avoid a possible crash when Shell is destroyed from a non-normal shutdown 498 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
481 // path. (crbug.com/485438). 499 // path. (crbug.com/485438).
482 wm_shell_->DeleteMruWindowTracker(); 500 wm_shell_->DeleteMruWindowTracker();
483 501
484 // These need a valid Shell instance to clean up properly, so explicitly 502 // These need a valid Shell instance to clean up properly, so explicitly
485 // delete them before invalidating the instance. 503 // delete them before invalidating the instance.
486 // Alphabetical. TODO(oshima): sort. 504 // Alphabetical. TODO(oshima): sort.
487 magnification_controller_.reset(); 505 magnification_controller_.reset();
488 tooltip_controller_.reset(); 506 tooltip_controller_.reset();
(...skipping 18 matching lines...) Expand all
507 525
508 // This also deletes all RootWindows. Note that we invoke Shutdown() on 526 // This also deletes all RootWindows. Note that we invoke Shutdown() on
509 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since 527 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
510 // destruction 528 // destruction
511 // of its owned RootWindowControllers relies on the value. 529 // of its owned RootWindowControllers relies on the value.
512 ScreenAsh::CreateScreenForShutdown(); 530 ScreenAsh::CreateScreenForShutdown();
513 display_configuration_controller_.reset(); 531 display_configuration_controller_.reset();
514 532
515 wm_shell_->Shutdown(); 533 wm_shell_->Shutdown();
516 // Depends on |focus_client_|, so must be destroyed before. 534 // Depends on |focus_client_|, so must be destroyed before.
517 window_tree_host_manager_->Shutdown();
518 window_tree_host_manager_.reset(); 535 window_tree_host_manager_.reset();
519 focus_client_.reset(); 536 focus_client_.reset();
520 screen_position_controller_.reset(); 537 screen_position_controller_.reset();
521 538
522 keyboard::KeyboardController::ResetInstance(nullptr); 539 keyboard::KeyboardController::ResetInstance(nullptr);
523 540
524 display_color_manager_.reset(); 541 display_color_manager_.reset();
525 if (display_change_observer_) 542 if (display_change_observer_)
526 display_configurator_->RemoveObserver(display_change_observer_.get()); 543 display_configurator_->RemoveObserver(display_change_observer_.get());
527 if (display_error_observer_) 544 if (display_error_observer_)
(...skipping 11 matching lines...) Expand all
539 DCHECK(chromeos::DBusThreadManager::IsInitialized()); 556 DCHECK(chromeos::DBusThreadManager::IsInitialized());
540 557
541 // Needs to happen right before |instance_| is reset. 558 // Needs to happen right before |instance_| is reset.
542 wm_shell_.reset(); 559 wm_shell_.reset();
543 560
544 DCHECK(instance_ == this); 561 DCHECK(instance_ == this);
545 instance_ = nullptr; 562 instance_ = nullptr;
546 } 563 }
547 564
548 void Shell::Init(const ShellInitParams& init_params) { 565 void Shell::Init(const ShellInitParams& init_params) {
566 const bool is_mash = wm_shell_->IsRunningInMash();
567
549 wm_shell_->Initialize(init_params.blocking_pool); 568 wm_shell_->Initialize(init_params.blocking_pool);
550 569
551 immersive_handler_factory_ = base::MakeUnique<ImmersiveHandlerFactoryAsh>(); 570 // TODO(sky): move creation to WmShell.
571 if (!is_mash)
572 immersive_handler_factory_ = base::MakeUnique<ImmersiveHandlerFactoryAsh>();
552 573
553 scoped_overview_animation_settings_factory_.reset( 574 scoped_overview_animation_settings_factory_.reset(
554 new ScopedOverviewAnimationSettingsFactoryAura); 575 new ScopedOverviewAnimationSettingsFactoryAura);
555 window_positioner_.reset(new WindowPositioner(wm_shell_.get())); 576 window_positioner_.reset(new WindowPositioner(wm_shell_.get()));
556 577
557 native_cursor_manager_ = new AshNativeCursorManager; 578 if (!is_mash) {
558 cursor_manager_.reset( 579 native_cursor_manager_ = new AshNativeCursorManager;
559 new CursorManager(base::WrapUnique(native_cursor_manager_))); 580 cursor_manager_.reset(
581 new CursorManager(base::WrapUnique(native_cursor_manager_)));
582 }
560 583
561 wm_shell_->delegate()->PreInit(); 584 wm_shell_->delegate()->PreInit();
562 bool display_initialized = display_manager_->InitFromCommandLine(); 585 bool display_initialized = true;
586 if (!is_mash) {
587 display_initialized = display_manager_->InitFromCommandLine();
563 588
564 display_configuration_controller_.reset(new DisplayConfigurationController( 589 display_configuration_controller_.reset(new DisplayConfigurationController(
565 display_manager_.get(), window_tree_host_manager_.get())); 590 display_manager_.get(), window_tree_host_manager_.get()));
566 591
567 #if defined(USE_OZONE) 592 #if defined(USE_OZONE)
568 display_configurator_->Init( 593 display_configurator_->Init(
569 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), 594 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(),
570 !gpu_support_->IsPanelFittingDisabled()); 595 !gpu_support_->IsPanelFittingDisabled());
571 #elif defined(USE_X11) 596 #elif defined(USE_X11)
572 display_configurator_->Init( 597 display_configurator_->Init(
573 base::MakeUnique<display::NativeDisplayDelegateX11>(), 598 base::MakeUnique<display::NativeDisplayDelegateX11>(),
574 !gpu_support_->IsPanelFittingDisabled()); 599 !gpu_support_->IsPanelFittingDisabled());
575 #endif 600 #endif
601 }
576 602
577 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell. 603 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
578 chromeos::DBusThreadManager* dbus_thread_manager = 604 chromeos::DBusThreadManager* dbus_thread_manager =
579 chromeos::DBusThreadManager::Get(); 605 chromeos::DBusThreadManager::Get();
580 projecting_observer_.reset( 606 projecting_observer_.reset(
581 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient())); 607 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
582 display_configurator_->AddObserver(projecting_observer_.get()); 608 display_configurator_->AddObserver(projecting_observer_.get());
583 wm_shell_->AddShellObserver(projecting_observer_.get()); 609 wm_shell_->AddShellObserver(projecting_observer_.get());
584 610
585 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) { 611 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) {
(...skipping 16 matching lines...) Expand all
602 ? kChromeOsBootColor 628 ? kChromeOsBootColor
603 : 0); 629 : 0);
604 display_initialized = true; 630 display_initialized = true;
605 } 631 }
606 display_color_manager_.reset(new DisplayColorManager( 632 display_color_manager_.reset(new DisplayColorManager(
607 display_configurator_.get(), init_params.blocking_pool)); 633 display_configurator_.get(), init_params.blocking_pool));
608 634
609 if (!display_initialized) 635 if (!display_initialized)
610 display_manager_->InitDefaultDisplay(); 636 display_manager_->InitDefaultDisplay();
611 637
612 display_manager_->RefreshFontParams(); 638 if (!is_mash) {
639 display_manager_->RefreshFontParams();
613 640
614 aura::Env::GetInstance()->set_context_factory(init_params.context_factory); 641 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
615 aura::Env::GetInstance()->set_context_factory_private( 642 aura::Env::GetInstance()->set_context_factory_private(
616 init_params.context_factory_private); 643 init_params.context_factory_private);
644 }
617 645
618 // The WindowModalityController needs to be at the front of the input event 646 // The WindowModalityController needs to be at the front of the input event
619 // pretarget handler list to ensure that it processes input events when modal 647 // pretarget handler list to ensure that it processes input events when modal
620 // windows are active. 648 // windows are active.
621 window_modality_controller_.reset(new ::wm::WindowModalityController(this)); 649 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
622 650
623 env_filter_.reset(new ::wm::CompoundEventFilter); 651 env_filter_.reset(new ::wm::CompoundEventFilter);
624 AddPreTargetHandler(env_filter_.get()); 652 AddPreTargetHandler(env_filter_.get());
625 653
626 wm::AshFocusRules* focus_rules = new wm::AshFocusRules(); 654 wm::AshFocusRules* focus_rules = new wm::AshFocusRules();
627 655
628 ::wm::FocusController* focus_controller = 656 ::wm::FocusController* focus_controller =
629 new ::wm::FocusController(focus_rules); 657 new ::wm::FocusController(focus_rules);
630 focus_client_.reset(focus_controller); 658 focus_client_.reset(focus_controller);
631 activation_client_ = focus_controller; 659 activation_client_ = focus_controller;
632 660
633 screen_position_controller_.reset(new ScreenPositionController); 661 screen_position_controller_.reset(new ScreenPositionController);
634 662
635 window_tree_host_manager_->Start(); 663 wm_shell_->CreatePrimaryHost();
636 AshWindowTreeHostInitParams ash_init_params; 664 wm_shell_->set_root_window_for_new_windows(
637 window_tree_host_manager_->CreatePrimaryHost(ash_init_params); 665 WmWindow::Get(GetPrimaryRootWindow()));
638 aura::Window* root_window = window_tree_host_manager_->GetPrimaryRootWindow();
639 wm_shell_->set_root_window_for_new_windows(WmWindow::Get(root_window));
640 666
641 resolution_notification_controller_.reset( 667 if (!is_mash) {
642 new ResolutionNotificationController); 668 resolution_notification_controller_.reset(
669 new ResolutionNotificationController);
670 }
643 671
644 if (cursor_manager_) 672 if (cursor_manager_)
645 cursor_manager_->SetDisplay( 673 cursor_manager_->SetDisplay(
646 display::Screen::GetScreen()->GetPrimaryDisplay()); 674 display::Screen::GetScreen()->GetPrimaryDisplay());
647 675
648 accelerator_controller_delegate_.reset(new AcceleratorControllerDelegateAura); 676 if (!is_mash) {
649 wm_shell_->SetAcceleratorController(base::MakeUnique<AcceleratorController>( 677 // TODO(sky): move this to WmShell. http://crbug.com/671246.
650 accelerator_controller_delegate_.get(), nullptr)); 678 accelerator_controller_delegate_.reset(
679 new AcceleratorControllerDelegateAura);
680 wm_shell_->SetAcceleratorController(base::MakeUnique<AcceleratorController>(
681 accelerator_controller_delegate_.get(), nullptr));
682 }
651 wm_shell_->CreateMaximizeModeController(); 683 wm_shell_->CreateMaximizeModeController();
652 684
653 AddPreTargetHandler(window_tree_host_manager_->input_method_event_handler()); 685 if (!is_mash) {
686 AddPreTargetHandler(
687 window_tree_host_manager_->input_method_event_handler());
688 }
654 689
655 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler(); 690 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
656 AddPreTargetHandler(magnifier_key_scroll_handler_.get()); 691 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
657 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler(); 692 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
658 AddPreTargetHandler(speech_feedback_handler_.get()); 693 AddPreTargetHandler(speech_feedback_handler_.get());
659 694
660 // The order in which event filters are added is significant. 695 // The order in which event filters are added is significant.
661 696
662 // ui::UserActivityDetector passes events to observers, so let them get 697 // ui::UserActivityDetector passes events to observers, so let them get
663 // rewritten first. 698 // rewritten first.
664 user_activity_detector_.reset(new ui::UserActivityDetector); 699 user_activity_detector_.reset(new ui::UserActivityDetector);
665 700
666 overlay_filter_.reset(new OverlayEventFilter); 701 overlay_filter_.reset(new OverlayEventFilter);
667 AddPreTargetHandler(overlay_filter_.get()); 702 AddPreTargetHandler(overlay_filter_.get());
668 wm_shell_->AddShellObserver(overlay_filter_.get()); 703 wm_shell_->AddShellObserver(overlay_filter_.get());
669 704
670 accelerator_filter_.reset(new ::wm::AcceleratorFilter( 705 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
671 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate), 706 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
672 wm_shell_->accelerator_controller()->accelerator_history())); 707 wm_shell_->accelerator_controller()->accelerator_history()));
673 AddPreTargetHandler(accelerator_filter_.get()); 708 AddPreTargetHandler(accelerator_filter_.get());
674 709
675 event_transformation_handler_.reset(new EventTransformationHandler); 710 event_transformation_handler_.reset(new EventTransformationHandler);
676 AddPreTargetHandler(event_transformation_handler_.get()); 711 AddPreTargetHandler(event_transformation_handler_.get());
677 712
678 toplevel_window_event_handler_.reset( 713 toplevel_window_event_handler_.reset(
679 new ToplevelWindowEventHandler(wm_shell_.get())); 714 new ToplevelWindowEventHandler(wm_shell_.get()));
680 715
681 system_gesture_filter_.reset(new SystemGestureEventFilter); 716 if (!is_mash) {
682 AddPreTargetHandler(system_gesture_filter_.get()); 717 system_gesture_filter_.reset(new SystemGestureEventFilter);
718 AddPreTargetHandler(system_gesture_filter_.get());
719 }
683 720
684 sticky_keys_controller_.reset(new StickyKeysController); 721 sticky_keys_controller_.reset(new StickyKeysController);
685 screen_pinning_controller_.reset( 722 if (!is_mash) {
686 new ScreenPinningController(window_tree_host_manager_.get())); 723 screen_pinning_controller_.reset(
724 new ScreenPinningController(window_tree_host_manager_.get()));
725 }
687 726
688 lock_state_controller_ = 727 lock_state_controller_ =
689 base::MakeUnique<LockStateController>(wm_shell_->shutdown_controller()); 728 base::MakeUnique<LockStateController>(wm_shell_->shutdown_controller());
690 power_button_controller_.reset( 729 power_button_controller_.reset(
691 new PowerButtonController(lock_state_controller_.get())); 730 new PowerButtonController(lock_state_controller_.get()));
692 // Pass the initial display state to PowerButtonController. 731 // Pass the initial display state to PowerButtonController.
693 power_button_controller_->OnDisplayModeChanged( 732 power_button_controller_->OnDisplayModeChanged(
694 display_configurator_->cached_displays()); 733 display_configurator_->cached_displays());
695 734
696 wm_shell_->AddShellObserver(lock_state_controller_.get()); 735 wm_shell_->AddShellObserver(lock_state_controller_.get());
697 736
698 drag_drop_controller_.reset(new DragDropController); 737 drag_drop_controller_.reset(new DragDropController);
699 // |screenshot_controller_| needs to be created (and prepended as a 738 // |screenshot_controller_| needs to be created (and prepended as a
700 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to 739 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
701 // process mouse events prior to screenshot session. 740 // process mouse events prior to screenshot session.
702 // See http://crbug.com/459214 741 // See http://crbug.com/459214
703 screenshot_controller_.reset(new ScreenshotController()); 742 screenshot_controller_.reset(new ScreenshotController());
704 mouse_cursor_filter_.reset(new MouseCursorEventFilter()); 743 if (!is_mash) {
705 PrependPreTargetHandler(mouse_cursor_filter_.get()); 744 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
745 PrependPreTargetHandler(mouse_cursor_filter_.get());
746 }
706 747
707 // Create Controllers that may need root window. 748 // Create Controllers that may need root window.
708 // TODO(oshima): Move as many controllers before creating 749 // TODO(oshima): Move as many controllers before creating
709 // RootWindowController as possible. 750 // RootWindowController as possible.
710 visibility_controller_.reset(new AshVisibilityController); 751 visibility_controller_.reset(new AshVisibilityController);
711 752
712 laser_pointer_controller_.reset(new LaserPointerController()); 753 laser_pointer_controller_.reset(new LaserPointerController());
713 partial_magnification_controller_.reset(new PartialMagnificationController()); 754 partial_magnification_controller_.reset(new PartialMagnificationController());
714 755
715 magnification_controller_.reset(MagnificationController::CreateInstance()); 756 magnification_controller_.reset(MagnificationController::CreateInstance());
716 wm_shell_->CreateMruWindowTracker(); 757 wm_shell_->CreateMruWindowTracker();
717 758
718 autoclick_controller_.reset(AutoclickController::CreateInstance()); 759 autoclick_controller_.reset(AutoclickController::CreateInstance());
719 760
720 high_contrast_controller_.reset(new HighContrastController); 761 high_contrast_controller_.reset(new HighContrastController);
721 video_detector_.reset(new VideoDetector); 762 video_detector_.reset(new VideoDetector);
722 763
723 tooltip_controller_.reset(new views::corewm::TooltipController( 764 tooltip_controller_.reset(new views::corewm::TooltipController(
724 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura))); 765 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
725 AddPreTargetHandler(tooltip_controller_.get()); 766 AddPreTargetHandler(tooltip_controller_.get());
726 767
727 modality_filter_.reset(new SystemModalContainerEventFilter(this)); 768 modality_filter_.reset(new SystemModalContainerEventFilter(this));
728 AddPreTargetHandler(modality_filter_.get()); 769 AddPreTargetHandler(modality_filter_.get());
729 770
730 event_client_.reset(new EventClientImpl); 771 event_client_.reset(new EventClientImpl);
731 772
732 session_state_delegate_.reset( 773 session_state_delegate_.reset(
733 wm_shell_->delegate()->CreateSessionStateDelegate()); 774 wm_shell_->delegate()->CreateSessionStateDelegate());
775 // Must occur after Shell has installed its early pre-target handlers (for
776 // example, WindowModalityController).
734 wm_shell_->CreatePointerWatcherAdapter(); 777 wm_shell_->CreatePointerWatcherAdapter();
735 778
736 resize_shadow_controller_.reset(new ResizeShadowController()); 779 resize_shadow_controller_.reset(new ResizeShadowController());
737 shadow_controller_.reset(new ::wm::ShadowController(activation_client_)); 780 shadow_controller_.reset(new ::wm::ShadowController(activation_client_));
738 781
739 wm_shell_->SetSystemTrayDelegate( 782 wm_shell_->SetSystemTrayDelegate(
740 base::WrapUnique(wm_shell_->delegate()->CreateSystemTrayDelegate())); 783 base::WrapUnique(wm_shell_->delegate()->CreateSystemTrayDelegate()));
741 784
742 // Create AshTouchTransformController before 785 // Create AshTouchTransformController before
743 // WindowTreeHostManager::InitDisplays() 786 // WindowTreeHostManager::InitDisplays()
744 // since AshTouchTransformController listens on 787 // since AshTouchTransformController listens on
745 // WindowTreeHostManager::Observer::OnDisplaysInitialized(). 788 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
746 touch_transformer_controller_.reset(new AshTouchTransformController( 789 if (!is_mash) {
747 display_configurator_.get(), display_manager_.get())); 790 touch_transformer_controller_.reset(new AshTouchTransformController(
791 display_configurator_.get(), display_manager_.get()));
792 }
748 793
749 wm_shell_->SetKeyboardUI(KeyboardUI::Create()); 794 if (!is_mash)
795 wm_shell_->SetKeyboardUI(KeyboardUI::Create());
750 796
751 window_tree_host_manager_->InitHosts(); 797 wm_shell_->InitHosts(init_params);
752 798
753 // Needs to be created after InitDisplays() since it may cause the virtual 799 // Needs to be created after InitDisplays() since it may cause the virtual
754 // keyboard to be deployed. 800 // keyboard to be deployed.
755 virtual_keyboard_controller_.reset(new VirtualKeyboardController); 801 if (!is_mash)
802 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
756 803
757 audio_a11y_controller_.reset(new chromeos::AudioA11yController); 804 audio_a11y_controller_.reset(new chromeos::AudioA11yController);
758 805
759 // Initialize the wallpaper after the RootWindowController has been created, 806 // Initialize the wallpaper after the RootWindowController has been created,
760 // otherwise the widget will not paint when restoring after a browser crash. 807 // otherwise the widget will not paint when restoring after a browser crash.
761 // Also, initialize after display initialization to ensure correct sizing. 808 // Also, initialize after display initialization to ensure correct sizing.
762 wm_shell_->wallpaper_delegate()->InitializeWallpaper(); 809 wm_shell_->wallpaper_delegate()->InitializeWallpaper();
763 810
764 if (cursor_manager_) { 811 if (cursor_manager_) {
765 if (initially_hide_cursor_) 812 if (initially_hide_cursor_)
766 cursor_manager_->HideCursor(); 813 cursor_manager_->HideCursor();
767 cursor_manager_->SetCursor(ui::kCursorPointer); 814 cursor_manager_->SetCursor(ui::kCursorPointer);
768 } 815 }
769 816
770 power_event_observer_.reset(new PowerEventObserver()); 817 power_event_observer_.reset(new PowerEventObserver());
771 user_activity_notifier_.reset( 818 user_activity_notifier_.reset(
772 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); 819 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
773 video_activity_notifier_.reset( 820 video_activity_notifier_.reset(
774 new VideoActivityNotifier(video_detector_.get())); 821 new VideoActivityNotifier(video_detector_.get()));
775 bluetooth_notification_controller_.reset(new BluetoothNotificationController); 822 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
776 screen_orientation_controller_.reset(new ScreenOrientationController()); 823 if (!is_mash) {
777 screen_layout_observer_.reset(new ScreenLayoutObserver()); 824 screen_orientation_controller_.reset(new ScreenOrientationController());
825 screen_layout_observer_.reset(new ScreenLayoutObserver());
826 }
778 827
779 // The compositor thread and main message loop have to be running in 828 // The compositor thread and main message loop have to be running in
780 // order to create mirror window. Run it after the main message loop 829 // order to create mirror window. Run it after the main message loop
781 // is started. 830 // is started.
782 display_manager_->CreateMirrorWindowAsyncIfAny(); 831 if (!is_mash)
832 display_manager_->CreateMirrorWindowAsyncIfAny();
783 833
784 for (auto& observer : *wm_shell_->shell_observers()) 834 for (auto& observer : *wm_shell_->shell_observers())
785 observer.OnShellInitialized(); 835 observer.OnShellInitialized();
786 836
787 user_metrics_recorder_->OnShellInitialized(); 837 if (!is_mash)
838 user_metrics_recorder_->OnShellInitialized();
788 } 839 }
789 840
790 void Shell::InitKeyboard() { 841 void Shell::InitKeyboard() {
791 if (keyboard::IsKeyboardEnabled()) { 842 if (keyboard::IsKeyboardEnabled()) {
792 if (keyboard::KeyboardController::GetInstance()) { 843 if (keyboard::KeyboardController::GetInstance()) {
793 RootWindowControllerList controllers = GetAllRootWindowControllers(); 844 RootWindowControllerList controllers = GetAllRootWindowControllers();
794 for (RootWindowControllerList::iterator iter = controllers.begin(); 845 for (RootWindowControllerList::iterator iter = controllers.begin();
795 iter != controllers.end(); ++iter) { 846 iter != controllers.end(); ++iter) {
796 (*iter)->DeactivateKeyboard( 847 (*iter)->DeactivateKeyboard(
797 keyboard::KeyboardController::GetInstance()); 848 keyboard::KeyboardController::GetInstance());
(...skipping 23 matching lines...) Expand all
821 aura::client::SetCursorClient(root_window, cursor_manager_.get()); 872 aura::client::SetCursorClient(root_window, cursor_manager_.get());
822 aura::client::SetTooltipClient(root_window, tooltip_controller_.get()); 873 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
823 aura::client::SetEventClient(root_window, event_client_.get()); 874 aura::client::SetEventClient(root_window, event_client_.get());
824 875
825 aura::client::SetWindowMoveClient(root_window, 876 aura::client::SetWindowMoveClient(root_window,
826 toplevel_window_event_handler_.get()); 877 toplevel_window_event_handler_.get());
827 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get()); 878 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
828 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get()); 879 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
829 } 880 }
830 881
882 void Shell::CloseAllRootWindowChildWindows() {
883 for (WmWindow* wm_root_window : wm_shell_->GetAllRootWindows()) {
884 aura::Window* root_window = wm_root_window->aura_window();
885 RootWindowController* controller = GetRootWindowController(root_window);
886 if (controller) {
887 controller->CloseChildWindows();
888 } else {
889 while (!root_window->children().empty()) {
890 aura::Window* child = root_window->children()[0];
891 delete child;
892 }
893 }
894 }
895 }
896
831 bool Shell::CanWindowReceiveEvents(aura::Window* window) { 897 bool Shell::CanWindowReceiveEvents(aura::Window* window) {
832 RootWindowControllerList controllers = GetAllRootWindowControllers(); 898 RootWindowControllerList controllers = GetAllRootWindowControllers();
833 for (RootWindowController* controller : controllers) { 899 for (RootWindowController* controller : controllers) {
834 if (controller->CanWindowReceiveEvents(window)) 900 if (controller->CanWindowReceiveEvents(window))
835 return true; 901 return true;
836 } 902 }
837 return false; 903 return false;
838 } 904 }
839 905
840 //////////////////////////////////////////////////////////////////////////////// 906 ////////////////////////////////////////////////////////////////////////////////
(...skipping 10 matching lines...) Expand all
851 std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const { 917 std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
852 return std::unique_ptr<ui::EventTargetIterator>(); 918 return std::unique_ptr<ui::EventTargetIterator>();
853 } 919 }
854 920
855 ui::EventTargeter* Shell::GetEventTargeter() { 921 ui::EventTargeter* Shell::GetEventTargeter() {
856 NOTREACHED(); 922 NOTREACHED();
857 return nullptr; 923 return nullptr;
858 } 924 }
859 925
860 } // namespace ash 926 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698