| 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/display/multi_display_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 "ash/display/display_controller.h" | 10 #include "ash/display/display_controller.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 14 #include "base/stringprintf.h" |
| 14 #include "ui/aura/aura_switches.h" | 15 #include "ui/aura/aura_switches.h" |
| 15 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 16 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 17 #include "ui/aura/root_window_host.h" | 18 #include "ui/aura/root_window_host.h" |
| 18 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
| 19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| 21 | 22 |
| 23 #if defined(USE_X11) |
| 24 #include "ui/base/x/x11_util.h" |
| 25 #endif |
| 26 |
| 22 DECLARE_WINDOW_PROPERTY_TYPE(int); | 27 DECLARE_WINDOW_PROPERTY_TYPE(int); |
| 23 | 28 |
| 24 namespace ash { | 29 namespace ash { |
| 25 namespace internal { | 30 namespace internal { |
| 26 namespace { | 31 namespace { |
| 27 | 32 |
| 28 gfx::Display& GetInvalidDisplay() { | 33 gfx::Display& GetInvalidDisplay() { |
| 29 static gfx::Display* invalid_display = new gfx::Display(); | 34 static gfx::Display* invalid_display = new gfx::Display(); |
| 30 return *invalid_display; | 35 return *invalid_display; |
| 31 } | 36 } |
| 32 | 37 |
| 33 } // namespace | 38 } // namespace |
| 34 | 39 |
| 35 using aura::RootWindow; | 40 using aura::RootWindow; |
| 36 using aura::Window; | 41 using aura::Window; |
| 37 using std::string; | 42 using std::string; |
| 38 using std::vector; | 43 using std::vector; |
| 39 | 44 |
| 40 DEFINE_WINDOW_PROPERTY_KEY(int, kDisplayIdKey, -1); | 45 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey, -1); |
| 41 | 46 |
| 42 MultiDisplayManager::MultiDisplayManager() { | 47 MultiDisplayManager::MultiDisplayManager() { |
| 43 Init(); | 48 Init(); |
| 44 } | 49 } |
| 45 | 50 |
| 46 MultiDisplayManager::~MultiDisplayManager() { | 51 MultiDisplayManager::~MultiDisplayManager() { |
| 47 } | 52 } |
| 48 | 53 |
| 49 // static | 54 // static |
| 50 void MultiDisplayManager::AddRemoveDisplay() { | 55 void MultiDisplayManager::AddRemoveDisplay() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 NotifyBoundsChanged(current_display); | 103 NotifyBoundsChanged(current_display); |
| 99 } | 104 } |
| 100 } | 105 } |
| 101 | 106 |
| 102 if (displays_.size() < new_displays.size()) { | 107 if (displays_.size() < new_displays.size()) { |
| 103 // New displays added | 108 // New displays added |
| 104 for (size_t i = min; i < new_displays.size(); ++i) { | 109 for (size_t i = min; i < new_displays.size(); ++i) { |
| 105 const gfx::Display& new_display = new_displays[i]; | 110 const gfx::Display& new_display = new_displays[i]; |
| 106 displays_.push_back(gfx::Display(new_display.id())); | 111 displays_.push_back(gfx::Display(new_display.id())); |
| 107 gfx::Display& display = displays_.back(); | 112 gfx::Display& display = displays_.back(); |
| 108 // Force the primary display's ID to be 0. | |
| 109 if (i == 0) | |
| 110 display.set_id(0); | |
| 111 display.SetScaleAndBounds(new_display.device_scale_factor(), | 113 display.SetScaleAndBounds(new_display.device_scale_factor(), |
| 112 new_display.bounds_in_pixel()); | 114 new_display.bounds_in_pixel()); |
| 113 NotifyDisplayAdded(display); | 115 NotifyDisplayAdded(display); |
| 114 } | 116 } |
| 115 } else { | 117 } else { |
| 116 // Displays are removed. We keep the display for the primary | 118 // Displays are removed. We keep the display for the primary |
| 117 // display (at index 0) because it needs the display information | 119 // display (at index 0) because it needs the display information |
| 118 // even if it doesn't exit. | 120 // even if it doesn't exit. |
| 119 while (displays_.size() > new_displays.size() && displays_.size() > 1) { | 121 while (displays_.size() > new_displays.size() && displays_.size() > 1) { |
| 120 Displays::reverse_iterator iter = displays_.rbegin(); | 122 Displays::reverse_iterator iter = displays_.rbegin(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 int area = intersect.width() * intersect.height(); | 185 int area = intersect.width() * intersect.height(); |
| 184 if (area > max) { | 186 if (area > max) { |
| 185 max = area; | 187 max = area; |
| 186 matching = &(*iter); | 188 matching = &(*iter); |
| 187 } | 189 } |
| 188 } | 190 } |
| 189 // Fallback to the primary display if there is no matching display. | 191 // Fallback to the primary display if there is no matching display. |
| 190 return matching ? *matching : displays_[0]; | 192 return matching ? *matching : displays_[0]; |
| 191 } | 193 } |
| 192 | 194 |
| 195 std::string MultiDisplayManager::GetDisplayNameAt(size_t index) { |
| 196 #if defined(USE_X11) |
| 197 gfx::Display* display = GetDisplayAt(index); |
| 198 std::vector<XID> outputs; |
| 199 if (display && display->id() != -1 && |
| 200 ui::GetOutputDeviceHandles(&outputs)) { |
| 201 for (size_t i = 0; i < outputs.size(); ++i) { |
| 202 uint16 manufacturer_id = 0; |
| 203 uint32 serial_number = 0; |
| 204 std::string name; |
| 205 if (ui::GetOutputDeviceData( |
| 206 outputs[i], &manufacturer_id, &serial_number, &name) && |
| 207 display->id() == |
| 208 gfx::Display::GetID(manufacturer_id, serial_number)) { |
| 209 return name; |
| 210 } |
| 211 } |
| 212 } |
| 213 #endif |
| 214 |
| 215 return base::StringPrintf("Display %d", static_cast<int>(index + 1)); |
| 216 } |
| 217 |
| 193 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, | 218 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, |
| 194 const gfx::Size& old_size) { | 219 const gfx::Size& old_size) { |
| 195 if (!use_fullscreen_host_window()) { | 220 if (!use_fullscreen_host_window()) { |
| 196 gfx::Display& display = FindDisplayForRootWindow(root); | 221 gfx::Display& display = FindDisplayForRootWindow(root); |
| 197 display.SetSize(root->GetHostSize()); | 222 display.SetSize(root->GetHostSize()); |
| 198 NotifyBoundsChanged(display); | 223 NotifyBoundsChanged(display); |
| 199 } | 224 } |
| 200 } | 225 } |
| 201 | 226 |
| 202 void MultiDisplayManager::Init() { | 227 void MultiDisplayManager::Init() { |
| 203 // TODO(oshima): Move this logic to DisplayChangeObserver. | 228 // TODO(oshima): Move this logic to DisplayChangeObserver. |
| 204 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 229 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 205 switches::kAuraHostWindowSize); | 230 switches::kAuraHostWindowSize); |
| 206 vector<string> parts; | 231 vector<string> parts; |
| 207 base::SplitString(size_str, ',', &parts); | 232 base::SplitString(size_str, ',', &parts); |
| 208 for (vector<string>::const_iterator iter = parts.begin(); | 233 for (vector<string>::const_iterator iter = parts.begin(); |
| 209 iter != parts.end(); ++iter) { | 234 iter != parts.end(); ++iter) { |
| 210 AddDisplayFromSpec(*iter); | 235 AddDisplayFromSpec(*iter); |
| 211 } | 236 } |
| 212 if (displays_.empty()) | 237 if (displays_.empty()) |
| 213 AddDisplayFromSpec(std::string() /* default */); | 238 AddDisplayFromSpec(std::string() /* default */); |
| 214 // Force the 1st display to be the primary display (id == 0). | |
| 215 displays_[0].set_id(0); | |
| 216 } | 239 } |
| 217 | 240 |
| 218 void MultiDisplayManager::AddRemoveDisplayImpl() { | 241 void MultiDisplayManager::AddRemoveDisplayImpl() { |
| 219 std::vector<gfx::Display> new_displays; | 242 std::vector<gfx::Display> new_displays; |
| 220 if (displays_.size() > 1) { | 243 if (displays_.size() > 1) { |
| 221 // Remove if there is more than one display. | 244 // Remove if there is more than one display. |
| 222 int count = displays_.size() - 1; | 245 int count = displays_.size() - 1; |
| 223 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) | 246 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) |
| 224 new_displays.push_back(*iter); | 247 new_displays.push_back(*iter); |
| 225 } else { | 248 } else { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 const gfx::Insets insets = display.GetWorkAreaInsets(); | 302 const gfx::Insets insets = display.GetWorkAreaInsets(); |
| 280 const gfx::Rect& native_bounds = display.bounds_in_pixel(); | 303 const gfx::Rect& native_bounds = display.bounds_in_pixel(); |
| 281 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); | 304 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); |
| 282 display.UpdateWorkAreaFromInsets(insets); | 305 display.UpdateWorkAreaFromInsets(insets); |
| 283 } | 306 } |
| 284 displays_.push_back(display); | 307 displays_.push_back(display); |
| 285 } | 308 } |
| 286 | 309 |
| 287 } // namespace internal | 310 } // namespace internal |
| 288 } // namespace ash | 311 } // namespace ash |
| OLD | NEW |