| 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/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
| 10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/gfx/monitor.h" | 12 #include "ui/gfx/display.h" |
| 13 | 13 |
| 14 namespace ash { | 14 namespace ash { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 MonitorController::MonitorController() { | 17 MonitorController::MonitorController() { |
| 18 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); | 18 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); |
| 19 Init(); | 19 Init(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 MonitorController::~MonitorController() { | 22 MonitorController::~MonitorController() { |
| 23 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); | 23 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); |
| 24 // Remove the root first. | 24 // Remove the root first. |
| 25 int monitor_id = Shell::GetPrimaryRootWindow()->GetProperty(kMonitorIdKey); | 25 int monitor_id = Shell::GetPrimaryRootWindow()->GetProperty(kMonitorIdKey); |
| 26 DCHECK(monitor_id >= 0); | 26 DCHECK(monitor_id >= 0); |
| 27 root_windows_.erase(monitor_id); | 27 root_windows_.erase(monitor_id); |
| 28 STLDeleteContainerPairSecondPointers( | 28 STLDeleteContainerPairSecondPointers( |
| 29 root_windows_.begin(), root_windows_.end()); | 29 root_windows_.begin(), root_windows_.end()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void MonitorController::GetAllRootWindows( | 32 void MonitorController::GetAllRootWindows( |
| 33 std::vector<aura::RootWindow*>* windows) { | 33 std::vector<aura::RootWindow*>* windows) { |
| 34 DCHECK(windows); | 34 DCHECK(windows); |
| 35 windows->clear(); | 35 windows->clear(); |
| 36 | 36 |
| 37 for (std::map<int, aura::RootWindow*>::const_iterator it = | 37 for (std::map<int, aura::RootWindow*>::const_iterator it = |
| 38 root_windows_.begin(); it != root_windows_.end(); ++it) | 38 root_windows_.begin(); it != root_windows_.end(); ++it) |
| 39 windows->push_back(it->second); | 39 windows->push_back(it->second); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void MonitorController::OnMonitorBoundsChanged(const gfx::Monitor& monitor) { | 42 void MonitorController::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 43 root_windows_[monitor.id()]->SetHostBounds(monitor.bounds_in_pixel()); | 43 root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void MonitorController::OnMonitorAdded(const gfx::Monitor& monitor) { | 46 void MonitorController::OnDisplayAdded(const gfx::Display& display) { |
| 47 if (root_windows_.empty()) { | 47 if (root_windows_.empty()) { |
| 48 root_windows_[monitor.id()] = Shell::GetPrimaryRootWindow(); | 48 root_windows_[display.id()] = Shell::GetPrimaryRootWindow(); |
| 49 Shell::GetPrimaryRootWindow()->SetHostBounds(monitor.bounds_in_pixel()); | 49 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel()); |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> | 52 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> |
| 53 CreateRootWindowForMonitor(monitor); | 53 CreateRootWindowForMonitor(display); |
| 54 root_windows_[monitor.id()] = root; | 54 root_windows_[display.id()] = root; |
| 55 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); | 55 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void MonitorController::OnMonitorRemoved(const gfx::Monitor& monitor) { | 58 void MonitorController::OnDisplayRemoved(const gfx::Display& display) { |
| 59 aura::RootWindow* root = root_windows_[monitor.id()]; | 59 aura::RootWindow* root = root_windows_[display.id()]; |
| 60 DCHECK(root); | 60 DCHECK(root); |
| 61 // Primary monitor should never be removed by MonitorManager. | 61 // Primary monitor should never be removed by MonitorManager. |
| 62 DCHECK(root != Shell::GetPrimaryRootWindow()); | 62 DCHECK(root != Shell::GetPrimaryRootWindow()); |
| 63 // Monitor for root window will be deleted when the Primary RootWindow | 63 // Monitor for root window will be deleted when the Primary RootWindow |
| 64 // is deleted by the Shell. | 64 // is deleted by the Shell. |
| 65 if (root != Shell::GetPrimaryRootWindow()) { | 65 if (root != Shell::GetPrimaryRootWindow()) { |
| 66 root_windows_.erase(monitor.id()); | 66 root_windows_.erase(display.id()); |
| 67 delete root; | 67 delete root; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 void MonitorController::Init() { | 71 void MonitorController::Init() { |
| 72 aura::MonitorManager* monitor_manager = | 72 aura::MonitorManager* monitor_manager = |
| 73 aura::Env::GetInstance()->monitor_manager(); | 73 aura::Env::GetInstance()->monitor_manager(); |
| 74 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { | 74 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { |
| 75 const gfx::Monitor& monitor = monitor_manager->GetMonitorAt(i); | 75 const gfx::Display& display = monitor_manager->GetMonitorAt(i); |
| 76 if (i == 0) { | 76 if (i == 0) { |
| 77 // Primary monitor | 77 // Primary monitor |
| 78 root_windows_[monitor.id()] = Shell::GetPrimaryRootWindow(); | 78 root_windows_[display.id()] = Shell::GetPrimaryRootWindow(); |
| 79 Shell::GetPrimaryRootWindow()->SetHostBounds(monitor.bounds_in_pixel()); | 79 Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel()); |
| 80 } else { | 80 } else { |
| 81 aura::RootWindow* root = | 81 aura::RootWindow* root = |
| 82 monitor_manager->CreateRootWindowForMonitor(monitor); | 82 monitor_manager->CreateRootWindowForMonitor(display); |
| 83 root_windows_[monitor.id()] = root; | 83 root_windows_[display.id()] = root; |
| 84 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); | 84 Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace internal | 89 } // namespace internal |
| 90 } // namespace ash | 90 } // namespace ash |
| OLD | NEW |