| 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/bind.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 16 #include "ui/aura/monitor.h" | 16 #include "ui/aura/monitor_aura.h" |
| 17 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 void SetupAsSecondaryMonitor(aura::RootWindow* root) { | 25 void SetupAsSecondaryMonitor(aura::RootWindow* root) { |
| 26 root->SetFocusWhenShown(false); | 26 root->SetFocusWhenShown(false); |
| (...skipping 12 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 aura::Monitor* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey); | 49 aura::MonitorAura* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey); |
| 50 DCHECK(monitor); | 50 DCHECK(monitor); |
| 51 root_windows_.erase(monitor); | 51 root_windows_.erase(monitor); |
| 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 aura::Monitor* monitor) { | 56 void MonitorController::OnMonitorBoundsChanged(const gfx::Monitor* monitor) { |
| 57 root_windows_[monitor]->SetHostBounds(monitor->bounds()); | 57 const aura::MonitorAura* monitor_aura = |
| 58 static_cast<const aura::MonitorAura*>(monitor); |
| 59 root_windows_[monitor]->SetHostBounds(monitor_aura->bounds()); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void MonitorController::OnMonitorAdded(aura::Monitor* monitor) { | 62 void MonitorController::OnMonitorAdded(gfx::Monitor* monitor) { |
| 63 aura::MonitorAura* monitor_aura = static_cast<aura::MonitorAura*>(monitor); |
| 61 if (root_windows_.empty()) { | 64 if (root_windows_.empty()) { |
| 62 root_windows_[monitor] = Shell::GetRootWindow(); | 65 root_windows_[monitor] = Shell::GetRootWindow(); |
| 63 Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); | 66 Shell::GetRootWindow()->SetHostBounds(monitor_aura->bounds()); |
| 64 return; | 67 return; |
| 65 } | 68 } |
| 66 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> | 69 aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> |
| 67 CreateRootWindowForMonitor(monitor); | 70 CreateRootWindowForMonitor(monitor_aura); |
| 68 root_windows_[monitor] = root; | 71 root_windows_[monitor] = root; |
| 69 SetupAsSecondaryMonitor(root); | 72 SetupAsSecondaryMonitor(root); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void MonitorController::OnMonitorRemoved(const aura::Monitor* monitor) { | 75 void MonitorController::OnMonitorRemoved(const gfx::Monitor* monitor) { |
| 73 aura::RootWindow* root = root_windows_[monitor]; | 76 aura::RootWindow* root = root_windows_[monitor]; |
| 74 DCHECK(root); | 77 DCHECK(root); |
| 75 // Primary monitor should never be removed by MonitorManager. | 78 // Primary monitor should never be removed by MonitorManager. |
| 76 DCHECK(root != Shell::GetRootWindow()); | 79 DCHECK(root != Shell::GetRootWindow()); |
| 77 // Monitor for root window will be deleted when the Primary RootWindow | 80 // Monitor for root window will be deleted when the Primary RootWindow |
| 78 // is deleted by the Shell. | 81 // is deleted by the Shell. |
| 79 if (root != Shell::GetRootWindow()) { | 82 if (root != Shell::GetRootWindow()) { |
| 80 root_windows_.erase(monitor); | 83 root_windows_.erase(monitor); |
| 81 delete root; | 84 delete root; |
| 82 } | 85 } |
| 83 } | 86 } |
| 84 | 87 |
| 85 void MonitorController::Init() { | 88 void MonitorController::Init() { |
| 86 aura::MonitorManager* monitor_manager = | 89 aura::MonitorManager* monitor_manager = |
| 87 aura::Env::GetInstance()->monitor_manager(); | 90 aura::Env::GetInstance()->monitor_manager(); |
| 88 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { | 91 for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) { |
| 89 aura::Monitor* monitor = monitor_manager->GetMonitorAt(i); | 92 aura::MonitorAura* monitor = monitor_manager->GetMonitorAt(i); |
| 90 const aura::Monitor* key = monitor; | 93 const gfx::Monitor* key = monitor; |
| 91 if (i == 0) { | 94 if (i == 0) { |
| 92 // Primary monitor | 95 // Primary monitor |
| 93 root_windows_[key] = Shell::GetRootWindow(); | 96 root_windows_[key] = Shell::GetRootWindow(); |
| 94 Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); | 97 Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); |
| 95 } else { | 98 } else { |
| 96 aura::RootWindow* root = | 99 aura::RootWindow* root = |
| 97 monitor_manager->CreateRootWindowForMonitor(monitor); | 100 monitor_manager->CreateRootWindowForMonitor(monitor); |
| 98 root_windows_[key] = root; | 101 root_windows_[key] = root; |
| 99 SetupAsSecondaryMonitor(root); | 102 SetupAsSecondaryMonitor(root); |
| 100 } | 103 } |
| 101 } | 104 } |
| 102 } | 105 } |
| 103 | 106 |
| 104 } // namespace internal | 107 } // namespace internal |
| 105 } // namespace ash | 108 } // namespace ash |
| OLD | NEW |