| OLD | NEW |
| 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/monitor/monitor_controller.h" | 5 #include "ash/monitor/monitor_controller.h" |
| 6 | 6 |
| 7 #include "ash/monitor/multi_monitor_manager.h" | 7 #include "ash/monitor/multi_monitor_manager.h" |
| 8 #include "ash/monitor/secondary_monitor_view.h" | 8 #include "ash/monitor/secondary_monitor_view.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/base_layout_manager.h" | 10 #include "ash/wm/base_layout_manager.h" |
| 11 #include "ash/wm/root_window_layout_manager.h" | 11 #include "ash/wm/root_window_layout_manager.h" |
| 12 #include "base/bind.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/time.h" |
| 13 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 14 #include "ui/aura/monitor.h" | 16 #include "ui/aura/monitor.h" |
| 15 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 17 | 19 |
| 18 namespace ash { | 20 namespace ash { |
| 19 namespace internal { | 21 namespace internal { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 void SetupAsSecondaryMonitor(aura::RootWindow* root) { | 25 void SetupAsSecondaryMonitor(aura::RootWindow* root) { |
| 26 root->SetFocusWhenShown(false); |
| 24 root->SetLayoutManager(new internal::RootWindowLayoutManager(root)); | 27 root->SetLayoutManager(new internal::RootWindowLayoutManager(root)); |
| 25 aura::Window* container = new aura::Window(NULL); | 28 aura::Window* container = new aura::Window(NULL); |
| 26 container->SetName("SecondaryMonitorContainer"); | 29 container->SetName("SecondaryMonitorContainer"); |
| 27 container->Init(ui::LAYER_NOT_DRAWN); | 30 container->Init(ui::LAYER_NOT_DRAWN); |
| 28 root->AddChild(container); | 31 root->AddChild(container); |
| 29 container->Show(); | |
| 30 container->SetLayoutManager(new internal::BaseLayoutManager(root)); | 32 container->SetLayoutManager(new internal::BaseLayoutManager(root)); |
| 31 CreateSecondaryMonitorWidget(container); | 33 CreateSecondaryMonitorWidget(container); |
| 34 container->Show(); |
| 35 root->layout_manager()->OnWindowResized(); |
| 32 root->ShowRootWindow(); | 36 root->ShowRootWindow(); |
| 33 } | 37 } |
| 34 | 38 |
| 35 } // namespace | 39 } // namespace |
| 36 | 40 |
| 37 MonitorController::MonitorController() { | 41 MonitorController::MonitorController() { |
| 38 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); | 42 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); |
| 39 Init(); | 43 Init(); |
| 40 } | 44 } |
| 41 | 45 |
| 42 MonitorController::~MonitorController() { | 46 MonitorController::~MonitorController() { |
| 43 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); | 47 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); |
| 44 // Remove the root first. | 48 // Remove the root first. |
| 45 aura::Monitor* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey); | 49 aura::Monitor* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey); |
| 50 DCHECK(monitor); |
| 46 root_windows_.erase(monitor); | 51 root_windows_.erase(monitor); |
| 47 STLDeleteContainerPairSecondPointers( | 52 STLDeleteContainerPairSecondPointers( |
| 48 root_windows_.begin(), root_windows_.end()); | 53 root_windows_.begin(), root_windows_.end()); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void MonitorController::OnMonitorBoundsChanged(const aura::Monitor* monitor) { | 56 void MonitorController::OnMonitorBoundsChanged(const aura::Monitor* monitor) { |
| 52 if (aura::MonitorManager::use_fullscreen_host_window()) | 57 root_windows_[monitor]->SetHostBounds(monitor->bounds()); |
| 53 root_windows_[monitor]->SetHostBounds(monitor->bounds()); | 58 } |
| 59 |
| 60 void MonitorController::OnMonitorAdded(aura::Monitor* monitor) { |
| 61 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> |
| 62 CreateRootWindowForMonitor(monitor); |
| 63 root_windows_[monitor] = root; |
| 64 SetupAsSecondaryMonitor(root); |
| 65 } |
| 66 |
| 67 void MonitorController::OnMonitorRemoved(const aura::Monitor* monitor) { |
| 68 aura::RootWindow* root = root_windows_[monitor]; |
| 69 root_windows_.erase(monitor); |
| 70 delete root; |
| 54 } | 71 } |
| 55 | 72 |
| 56 void MonitorController::Init() { | 73 void MonitorController::Init() { |
| 57 aura::MonitorManager* monitor_manager = | 74 aura::MonitorManager* monitor_manager = |
| 58 aura::Env::GetInstance()->monitor_manager(); | 75 aura::Env::GetInstance()->monitor_manager(); |
| 59 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { | 76 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { |
| 60 aura::Monitor* monitor = monitor_manager->GetMonitorAt(i); | 77 aura::Monitor* monitor = monitor_manager->GetMonitorAt(i); |
| 61 const aura::Monitor* key = monitor; | 78 const aura::Monitor* key = monitor; |
| 62 if (i == 0) { | 79 if (i == 0) { |
| 63 // Primary monitor | 80 // Primary monitor |
| 64 root_windows_[key] = Shell::GetRootWindow(); | 81 root_windows_[key] = Shell::GetRootWindow(); |
| 82 Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); |
| 65 } else { | 83 } else { |
| 66 aura::RootWindow* root = | 84 aura::RootWindow* root = |
| 67 monitor_manager->CreateRootWindowForMonitor(monitor); | 85 monitor_manager->CreateRootWindowForMonitor(monitor); |
| 68 root_windows_[key] = root; | 86 root_windows_[key] = root; |
| 69 SetupAsSecondaryMonitor(root); | 87 SetupAsSecondaryMonitor(root); |
| 70 } | 88 } |
| 71 } | 89 } |
| 72 } | 90 } |
| 73 | 91 |
| 74 } // namespace internal | 92 } // namespace internal |
| 75 } // namespace ash | 93 } // namespace ash |
| OLD | NEW |