| 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/multi_monitor_manager.h" | 5 #include "ash/display/multi_display_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "ui/aura/aura_switches.h" | 13 #include "ui/aura/aura_switches.h" |
| 14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
| 15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 29 return *invalid_display; | 29 return *invalid_display; |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 using aura::RootWindow; | 34 using aura::RootWindow; |
| 35 using aura::Window; | 35 using aura::Window; |
| 36 using std::string; | 36 using std::string; |
| 37 using std::vector; | 37 using std::vector; |
| 38 | 38 |
| 39 DEFINE_WINDOW_PROPERTY_KEY(int, kMonitorIdKey, -1); | 39 DEFINE_WINDOW_PROPERTY_KEY(int, kDisplayIdKey, -1); |
| 40 | 40 |
| 41 MultiMonitorManager::MultiMonitorManager() { | 41 MultiDisplayManager::MultiDisplayManager() { |
| 42 Init(); | 42 Init(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 MultiMonitorManager::~MultiMonitorManager() { | 45 MultiDisplayManager::~MultiDisplayManager() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 void MultiMonitorManager::AddRemoveMonitor() { | 49 void MultiDisplayManager::AddRemoveDisplay() { |
| 50 MultiMonitorManager* manager = static_cast<MultiMonitorManager*>( | 50 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( |
| 51 aura::Env::GetInstance()->monitor_manager()); | 51 aura::Env::GetInstance()->display_manager()); |
| 52 manager->AddRemoveMonitorImpl(); | 52 manager->AddRemoveDisplayImpl(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void MultiMonitorManager::CycleMonitor() { | 55 void MultiDisplayManager::CycleDisplay() { |
| 56 MultiMonitorManager* manager = static_cast<MultiMonitorManager*>( | 56 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( |
| 57 aura::Env::GetInstance()->monitor_manager()); | 57 aura::Env::GetInstance()->display_manager()); |
| 58 manager->CycleMonitorImpl(); | 58 manager->CycleDisplayImpl(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void MultiMonitorManager::ToggleMonitorScale() { | 61 void MultiDisplayManager::ToggleDisplayScale() { |
| 62 MultiMonitorManager* manager = static_cast<MultiMonitorManager*>( | 62 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( |
| 63 aura::Env::GetInstance()->monitor_manager()); | 63 aura::Env::GetInstance()->display_manager()); |
| 64 manager->ScaleMonitorImpl(); | 64 manager->ScaleDisplayImpl(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void MultiMonitorManager::OnNativeMonitorsChanged( | 67 void MultiDisplayManager::OnNativeDisplaysChanged( |
| 68 const std::vector<gfx::Display>& new_displays) { | 68 const std::vector<gfx::Display>& new_displays) { |
| 69 size_t min = std::min(displays_.size(), new_displays.size()); | 69 size_t min = std::min(displays_.size(), new_displays.size()); |
| 70 | 70 |
| 71 // For m19, we only care about 1st monitor as primary, and | 71 // For m19, we only care about 1st display as primary, and |
| 72 // don't differentiate the rest of monitors as all secondary | 72 // don't differentiate the rest of displays as all secondary |
| 73 // monitors have the same content. ID for primary monitor stays the same | 73 // displays have the same content. ID for primary display stays the same |
| 74 // because we never remove it, we don't update IDs for other monitors | 74 // because we never remove it, we don't update IDs for other displays |
| 75 // , for now, because they're the same. | 75 // , for now, because they're the same. |
| 76 // TODO(oshima): Fix this so that we can differentiate outputs | 76 // TODO(oshima): Fix this so that we can differentiate outputs |
| 77 // and keep a content on one monitor stays on the same monitor | 77 // and keep a content on one display stays on the same display |
| 78 // when a monitor is added or removed. | 78 // when a display is added or removed. |
| 79 for (size_t i = 0; i < min; ++i) { | 79 for (size_t i = 0; i < min; ++i) { |
| 80 gfx::Display& current_display = displays_[i]; | 80 gfx::Display& current_display = displays_[i]; |
| 81 const gfx::Display& new_display = new_displays[i]; | 81 const gfx::Display& new_display = new_displays[i]; |
| 82 if (current_display.bounds_in_pixel() != new_display.bounds_in_pixel() || | 82 if (current_display.bounds_in_pixel() != new_display.bounds_in_pixel() || |
| 83 current_display.device_scale_factor() != | 83 current_display.device_scale_factor() != |
| 84 new_display.device_scale_factor()) { | 84 new_display.device_scale_factor()) { |
| 85 current_display.SetScaleAndBounds(new_display.device_scale_factor(), | 85 current_display.SetScaleAndBounds(new_display.device_scale_factor(), |
| 86 new_display.bounds_in_pixel()); | 86 new_display.bounds_in_pixel()); |
| 87 NotifyBoundsChanged(current_display); | 87 NotifyBoundsChanged(current_display); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 if (displays_.size() < new_displays.size()) { | 91 if (displays_.size() < new_displays.size()) { |
| 92 // New monitors added | 92 // New displays added |
| 93 for (size_t i = min; i < new_displays.size(); ++i) { | 93 for (size_t i = min; i < new_displays.size(); ++i) { |
| 94 const gfx::Display& new_display = new_displays[i]; | 94 const gfx::Display& new_display = new_displays[i]; |
| 95 displays_.push_back(gfx::Display(new_display.id())); | 95 displays_.push_back(gfx::Display(new_display.id())); |
| 96 gfx::Display& display = displays_.back(); | 96 gfx::Display& display = displays_.back(); |
| 97 // Force the primary display's ID to be 0. | 97 // Force the primary display's ID to be 0. |
| 98 if (i == 0) | 98 if (i == 0) |
| 99 display.set_id(0); | 99 display.set_id(0); |
| 100 display.SetScaleAndBounds(new_display.device_scale_factor(), | 100 display.SetScaleAndBounds(new_display.device_scale_factor(), |
| 101 new_display.bounds_in_pixel()); | 101 new_display.bounds_in_pixel()); |
| 102 NotifyDisplayAdded(display); | 102 NotifyDisplayAdded(display); |
| 103 } | 103 } |
| 104 } else { | 104 } else { |
| 105 // Monitors are removed. We keep the monitor for the primary | 105 // Displays are removed. We keep the display for the primary |
| 106 // monitor (at index 0) because it needs the monitor information | 106 // display (at index 0) because it needs the display information |
| 107 // even if it doesn't exit. | 107 // even if it doesn't exit. |
| 108 while (displays_.size() > new_displays.size() && displays_.size() > 1) { | 108 while (displays_.size() > new_displays.size() && displays_.size() > 1) { |
| 109 Displays::reverse_iterator iter = displays_.rbegin(); | 109 Displays::reverse_iterator iter = displays_.rbegin(); |
| 110 NotifyDisplayRemoved(*iter); | 110 NotifyDisplayRemoved(*iter); |
| 111 displays_.erase(iter.base() - 1); | 111 displays_.erase(iter.base() - 1); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 RootWindow* MultiMonitorManager::CreateRootWindowForMonitor( | 116 RootWindow* MultiDisplayManager::CreateRootWindowForDisplay( |
| 117 const gfx::Display& display) { | 117 const gfx::Display& display) { |
| 118 RootWindow* root_window = new RootWindow(display.bounds_in_pixel()); | 118 RootWindow* root_window = new RootWindow(display.bounds_in_pixel()); |
| 119 // No need to remove RootWindowObserver because | 119 // No need to remove RootWindowObserver because |
| 120 // the MonitorManager object outlives RootWindow objects. | 120 // the DisplayManager object outlives RootWindow objects. |
| 121 root_window->AddRootWindowObserver(this); | 121 root_window->AddRootWindowObserver(this); |
| 122 root_window->SetProperty(kMonitorIdKey, display.id()); | 122 root_window->SetProperty(kDisplayIdKey, display.id()); |
| 123 root_window->Init(); | 123 root_window->Init(); |
| 124 return root_window; | 124 return root_window; |
| 125 } | 125 } |
| 126 | 126 |
| 127 const gfx::Display& MultiMonitorManager::GetDisplayAt(size_t index) { | 127 const gfx::Display& MultiDisplayManager::GetDisplayAt(size_t index) { |
| 128 return index < displays_.size() ? displays_[index] : GetInvalidDisplay(); | 128 return index < displays_.size() ? displays_[index] : GetInvalidDisplay(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 size_t MultiMonitorManager::GetNumDisplays() const { | 131 size_t MultiDisplayManager::GetNumDisplays() const { |
| 132 return displays_.size(); | 132 return displays_.size(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 const gfx::Display& MultiMonitorManager::GetDisplayNearestWindow( | 135 const gfx::Display& MultiDisplayManager::GetDisplayNearestWindow( |
| 136 const Window* window) const { | 136 const Window* window) const { |
| 137 if (!window) { | 137 if (!window) { |
| 138 MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this); | 138 MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this); |
| 139 return manager->GetDisplayAt(0); | 139 return manager->GetDisplayAt(0); |
| 140 } | 140 } |
| 141 const RootWindow* root = window->GetRootWindow(); | 141 const RootWindow* root = window->GetRootWindow(); |
| 142 MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this); | 142 MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this); |
| 143 return root ? manager->FindDisplayForRootWindow(root) : GetInvalidDisplay(); | 143 return root ? manager->FindDisplayForRootWindow(root) : GetInvalidDisplay(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 const gfx::Display& MultiMonitorManager::GetDisplayNearestPoint( | 146 const gfx::Display& MultiDisplayManager::GetDisplayNearestPoint( |
| 147 const gfx::Point& point) const { | 147 const gfx::Point& point) const { |
| 148 // TODO(oshima): For m19, mouse is constrained within | 148 // TODO(oshima): For m19, mouse is constrained within |
| 149 // the primary window. | 149 // the primary window. |
| 150 MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this); | 150 MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this); |
| 151 return manager->GetDisplayAt(0); | 151 return manager->GetDisplayAt(0); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void MultiMonitorManager::OnRootWindowResized(const aura::RootWindow* root, | 154 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, |
| 155 const gfx::Size& old_size) { | 155 const gfx::Size& old_size) { |
| 156 if (!use_fullscreen_host_window()) { | 156 if (!use_fullscreen_host_window()) { |
| 157 gfx::Display& display = FindDisplayForRootWindow(root); | 157 gfx::Display& display = FindDisplayForRootWindow(root); |
| 158 display.SetSize(root->GetHostSize()); | 158 display.SetSize(root->GetHostSize()); |
| 159 NotifyBoundsChanged(display); | 159 NotifyBoundsChanged(display); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool MultiMonitorManager::UpdateWorkAreaOfMonitorNearestWindow( | 163 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow( |
| 164 const aura::Window* window, | 164 const aura::Window* window, |
| 165 const gfx::Insets& insets) { | 165 const gfx::Insets& insets) { |
| 166 const RootWindow* root = window->GetRootWindow(); | 166 const RootWindow* root = window->GetRootWindow(); |
| 167 gfx::Display& display = FindDisplayForRootWindow(root); | 167 gfx::Display& display = FindDisplayForRootWindow(root); |
| 168 gfx::Rect old_work_area = display.work_area(); | 168 gfx::Rect old_work_area = display.work_area(); |
| 169 display.UpdateWorkAreaFromInsets(insets); | 169 display.UpdateWorkAreaFromInsets(insets); |
| 170 return old_work_area != display.work_area(); | 170 return old_work_area != display.work_area(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void MultiMonitorManager::Init() { | 173 void MultiDisplayManager::Init() { |
| 174 // TODO(oshima): Move this logic to MonitorChangeObserver. | 174 // TODO(oshima): Move this logic to DisplayChangeObserver. |
| 175 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 175 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 176 switches::kAuraHostWindowSize); | 176 switches::kAuraHostWindowSize); |
| 177 vector<string> parts; | 177 vector<string> parts; |
| 178 base::SplitString(size_str, ',', &parts); | 178 base::SplitString(size_str, ',', &parts); |
| 179 for (vector<string>::const_iterator iter = parts.begin(); | 179 for (vector<string>::const_iterator iter = parts.begin(); |
| 180 iter != parts.end(); ++iter) { | 180 iter != parts.end(); ++iter) { |
| 181 displays_.push_back(CreateMonitorFromSpec(*iter)); | 181 displays_.push_back(CreateDisplayFromSpec(*iter)); |
| 182 } | 182 } |
| 183 if (displays_.empty()) | 183 if (displays_.empty()) |
| 184 displays_.push_back(CreateMonitorFromSpec("" /* default */)); | 184 displays_.push_back(CreateDisplayFromSpec("" /* default */)); |
| 185 // Force the 1st display to be the primary display (id == 0). | 185 // Force the 1st display to be the primary display (id == 0). |
| 186 displays_[0].set_id(0); | 186 displays_[0].set_id(0); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void MultiMonitorManager::AddRemoveMonitorImpl() { | 189 void MultiDisplayManager::AddRemoveDisplayImpl() { |
| 190 std::vector<gfx::Display> new_displays; | 190 std::vector<gfx::Display> new_displays; |
| 191 if (displays_.size() > 1) { | 191 if (displays_.size() > 1) { |
| 192 // Remove if there is more than one display. | 192 // Remove if there is more than one display. |
| 193 int count = displays_.size() - 1; | 193 int count = displays_.size() - 1; |
| 194 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) | 194 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) |
| 195 new_displays.push_back(*iter); | 195 new_displays.push_back(*iter); |
| 196 } else { | 196 } else { |
| 197 // Add if there is only one display. | 197 // Add if there is only one display. |
| 198 new_displays.push_back(displays_[0]); | 198 new_displays.push_back(displays_[0]); |
| 199 new_displays.push_back(CreateMonitorFromSpec("50+50-1280x768")); | 199 new_displays.push_back(CreateDisplayFromSpec("50+50-1280x768")); |
| 200 } | 200 } |
| 201 if (new_displays.size()) | 201 if (new_displays.size()) |
| 202 OnNativeMonitorsChanged(new_displays); | 202 OnNativeDisplaysChanged(new_displays); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void MultiMonitorManager::CycleMonitorImpl() { | 205 void MultiDisplayManager::CycleDisplayImpl() { |
| 206 if (displays_.size() > 1) { | 206 if (displays_.size() > 1) { |
| 207 std::vector<gfx::Display> new_displays; | 207 std::vector<gfx::Display> new_displays; |
| 208 for (Displays::const_iterator iter = displays_.begin() + 1; | 208 for (Displays::const_iterator iter = displays_.begin() + 1; |
| 209 iter != displays_.end(); ++iter) { | 209 iter != displays_.end(); ++iter) { |
| 210 gfx::Display display = *iter; | 210 gfx::Display display = *iter; |
| 211 new_displays.push_back(display); | 211 new_displays.push_back(display); |
| 212 } | 212 } |
| 213 new_displays.push_back(displays_.front()); | 213 new_displays.push_back(displays_.front()); |
| 214 OnNativeMonitorsChanged(new_displays); | 214 OnNativeDisplaysChanged(new_displays); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 void MultiMonitorManager::ScaleMonitorImpl() { | 218 void MultiDisplayManager::ScaleDisplayImpl() { |
| 219 if (displays_.size() > 0) { | 219 if (displays_.size() > 0) { |
| 220 std::vector<gfx::Display> new_displays; | 220 std::vector<gfx::Display> new_displays; |
| 221 for (Displays::const_iterator iter = displays_.begin(); | 221 for (Displays::const_iterator iter = displays_.begin(); |
| 222 iter != displays_.end(); ++iter) { | 222 iter != displays_.end(); ++iter) { |
| 223 gfx::Display display = *iter; | 223 gfx::Display display = *iter; |
| 224 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; | 224 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; |
| 225 display.SetScaleAndBounds( | 225 display.SetScaleAndBounds( |
| 226 factor, gfx::Rect(display.bounds_in_pixel().origin(), | 226 factor, gfx::Rect(display.bounds_in_pixel().origin(), |
| 227 display.size().Scale(factor))); | 227 display.size().Scale(factor))); |
| 228 new_displays.push_back(display); | 228 new_displays.push_back(display); |
| 229 } | 229 } |
| 230 OnNativeMonitorsChanged(new_displays); | 230 OnNativeDisplaysChanged(new_displays); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 gfx::Display& MultiMonitorManager::FindDisplayForRootWindow( | 234 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( |
| 235 const aura::RootWindow* root_window) { | 235 const aura::RootWindow* root_window) { |
| 236 int id = root_window->GetProperty(kMonitorIdKey); | 236 int id = root_window->GetProperty(kDisplayIdKey); |
| 237 for (Displays::iterator iter = displays_.begin(); | 237 for (Displays::iterator iter = displays_.begin(); |
| 238 iter != displays_.end(); ++iter) { | 238 iter != displays_.end(); ++iter) { |
| 239 if ((*iter).id() == id) | 239 if ((*iter).id() == id) |
| 240 return *iter; | 240 return *iter; |
| 241 } | 241 } |
| 242 DLOG(FATAL) << "Could not find display by id:" << id; | 242 DLOG(FATAL) << "Could not find display by id:" << id; |
| 243 return GetInvalidDisplay(); | 243 return GetInvalidDisplay(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace internal | 246 } // namespace internal |
| 247 } // namespace ash | 247 } // namespace ash |
| OLD | NEW |