| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 MonitorController::MonitorController() { | 41 MonitorController::MonitorController() { |
| 42 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); | 42 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); |
| 43 Init(); | 43 Init(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 MonitorController::~MonitorController() { | 46 MonitorController::~MonitorController() { |
| 47 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); | 47 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); |
| 48 // Remove the root first. | 48 // Remove the root first. |
| 49 int monitor_id = Shell::GetRootWindow()->GetProperty(kMonitorIdKey); | 49 int monitor_id = Shell::GetPrimaryRootWindow()->GetProperty(kMonitorIdKey); |
| 50 DCHECK(monitor_id >= 0); | 50 DCHECK(monitor_id >= 0); |
| 51 root_windows_.erase(monitor_id); | 51 root_windows_.erase(monitor_id); |
| 52 STLDeleteContainerPairSecondPointers( | 52 STLDeleteContainerPairSecondPointers( |
| 53 root_windows_.begin(), root_windows_.end()); | 53 root_windows_.begin(), root_windows_.end()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void MonitorController::OnMonitorBoundsChanged(const gfx::Monitor& monitor) { | 56 void MonitorController::OnMonitorBoundsChanged(const gfx::Monitor& monitor) { |
| 57 root_windows_[monitor.id()]->SetHostBounds(monitor.bounds_in_pixel()); | 57 root_windows_[monitor.id()]->SetHostBounds(monitor.bounds_in_pixel()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void MonitorController::OnMonitorAdded(const gfx::Monitor& monitor) { | 60 void MonitorController::OnMonitorAdded(const gfx::Monitor& monitor) { |
| 61 if (root_windows_.empty()) { | 61 if (root_windows_.empty()) { |
| 62 root_windows_[monitor.id()] = Shell::GetRootWindow(); | 62 root_windows_[monitor.id()] = Shell::GetPrimaryRootWindow(); |
| 63 Shell::GetRootWindow()->SetHostBounds(monitor.bounds_in_pixel()); | 63 Shell::GetPrimaryRootWindow()->SetHostBounds(monitor.bounds_in_pixel()); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> | 66 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> |
| 67 CreateRootWindowForMonitor(monitor); | 67 CreateRootWindowForMonitor(monitor); |
| 68 root_windows_[monitor.id()] = root; | 68 root_windows_[monitor.id()] = root; |
| 69 SetupAsSecondaryMonitor(root); | 69 SetupAsSecondaryMonitor(root); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void MonitorController::OnMonitorRemoved(const gfx::Monitor& monitor) { | 72 void MonitorController::OnMonitorRemoved(const gfx::Monitor& monitor) { |
| 73 aura::RootWindow* root = root_windows_[monitor.id()]; | 73 aura::RootWindow* root = root_windows_[monitor.id()]; |
| 74 DCHECK(root); | 74 DCHECK(root); |
| 75 // Primary monitor should never be removed by MonitorManager. | 75 // Primary monitor should never be removed by MonitorManager. |
| 76 DCHECK(root != Shell::GetRootWindow()); | 76 DCHECK(root != Shell::GetPrimaryRootWindow()); |
| 77 // Monitor for root window will be deleted when the Primary RootWindow | 77 // Monitor for root window will be deleted when the Primary RootWindow |
| 78 // is deleted by the Shell. | 78 // is deleted by the Shell. |
| 79 if (root != Shell::GetRootWindow()) { | 79 if (root != Shell::GetPrimaryRootWindow()) { |
| 80 root_windows_.erase(monitor.id()); | 80 root_windows_.erase(monitor.id()); |
| 81 delete root; | 81 delete root; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 void MonitorController::Init() { | 85 void MonitorController::Init() { |
| 86 aura::MonitorManager* monitor_manager = | 86 aura::MonitorManager* monitor_manager = |
| 87 aura::Env::GetInstance()->monitor_manager(); | 87 aura::Env::GetInstance()->monitor_manager(); |
| 88 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { | 88 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { |
| 89 const gfx::Monitor& monitor = monitor_manager->GetMonitorAt(i); | 89 const gfx::Monitor& monitor = monitor_manager->GetMonitorAt(i); |
| 90 if (i == 0) { | 90 if (i == 0) { |
| 91 // Primary monitor | 91 // Primary monitor |
| 92 root_windows_[monitor.id()] = Shell::GetRootWindow(); | 92 root_windows_[monitor.id()] = Shell::GetPrimaryRootWindow(); |
| 93 Shell::GetRootWindow()->SetHostBounds(monitor.bounds_in_pixel()); | 93 Shell::GetPrimaryRootWindow()->SetHostBounds(monitor.bounds_in_pixel()); |
| 94 } else { | 94 } else { |
| 95 aura::RootWindow* root = | 95 aura::RootWindow* root = |
| 96 monitor_manager->CreateRootWindowForMonitor(monitor); | 96 monitor_manager->CreateRootWindowForMonitor(monitor); |
| 97 root_windows_[monitor.id()] = root; | 97 root_windows_[monitor.id()] = root; |
| 98 SetupAsSecondaryMonitor(root); | 98 SetupAsSecondaryMonitor(root); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace internal | 103 } // namespace internal |
| 104 } // namespace ash | 104 } // namespace ash |
| OLD | NEW |