| 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" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 MultiDisplayManager::MultiDisplayManager() : | 53 MultiDisplayManager::MultiDisplayManager() : |
| 54 internal_display_id_(gfx::Display::kInvalidDisplayID) { | 54 internal_display_id_(gfx::Display::kInvalidDisplayID) { |
| 55 Init(); | 55 Init(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 MultiDisplayManager::~MultiDisplayManager() { | 58 MultiDisplayManager::~MultiDisplayManager() { |
| 59 } | 59 } |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 void MultiDisplayManager::AddRemoveDisplay() { | |
| 63 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( | |
| 64 aura::Env::GetInstance()->display_manager()); | |
| 65 manager->AddRemoveDisplayImpl(); | |
| 66 } | |
| 67 | |
| 68 void MultiDisplayManager::CycleDisplay() { | 62 void MultiDisplayManager::CycleDisplay() { |
| 69 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( | 63 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( |
| 70 aura::Env::GetInstance()->display_manager()); | 64 aura::Env::GetInstance()->display_manager()); |
| 71 manager->CycleDisplayImpl(); | 65 manager->CycleDisplayImpl(); |
| 72 } | 66 } |
| 73 | 67 |
| 68 // static |
| 74 void MultiDisplayManager::ToggleDisplayScale() { | 69 void MultiDisplayManager::ToggleDisplayScale() { |
| 75 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( | 70 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( |
| 76 aura::Env::GetInstance()->display_manager()); | 71 aura::Env::GetInstance()->display_manager()); |
| 77 manager->ScaleDisplayImpl(); | 72 manager->ScaleDisplayImpl(); |
| 78 } | 73 } |
| 79 | 74 |
| 80 void MultiDisplayManager::InitInternalDisplayInfo() { | 75 void MultiDisplayManager::InitInternalDisplayInfo() { |
| 81 #if defined(OS_CHROMEOS) | 76 #if defined(OS_CHROMEOS) |
| 82 if (!base::chromeos::IsRunningOnChromeOS()) | 77 if (!base::chromeos::IsRunningOnChromeOS()) |
| 83 return; | 78 return; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 270 } |
| 276 #endif | 271 #endif |
| 277 | 272 |
| 278 return base::StringPrintf("Display %d", static_cast<int>(index + 1)); | 273 return base::StringPrintf("Display %d", static_cast<int>(index + 1)); |
| 279 } | 274 } |
| 280 | 275 |
| 281 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, | 276 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, |
| 282 const gfx::Size& old_size) { | 277 const gfx::Size& old_size) { |
| 283 if (!use_fullscreen_host_window()) { | 278 if (!use_fullscreen_host_window()) { |
| 284 gfx::Display& display = FindDisplayForRootWindow(root); | 279 gfx::Display& display = FindDisplayForRootWindow(root); |
| 285 display.SetSize(root->GetHostSize()); | 280 if (display.size() != root->GetHostSize()) { |
| 286 NotifyBoundsChanged(display); | 281 display.SetSize(root->GetHostSize()); |
| 282 NotifyBoundsChanged(display); |
| 283 } |
| 287 } | 284 } |
| 288 } | 285 } |
| 289 | 286 |
| 290 void MultiDisplayManager::Init() { | 287 void MultiDisplayManager::Init() { |
| 291 // TODO(oshima): Move this logic to DisplayChangeObserver. | 288 // TODO(oshima): Move this logic to DisplayChangeObserver. |
| 292 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 289 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 293 switches::kAuraHostWindowSize); | 290 switches::kAuraHostWindowSize); |
| 294 vector<string> parts; | 291 vector<string> parts; |
| 295 base::SplitString(size_str, ',', &parts); | 292 base::SplitString(size_str, ',', &parts); |
| 296 for (vector<string>::const_iterator iter = parts.begin(); | 293 for (vector<string>::const_iterator iter = parts.begin(); |
| 297 iter != parts.end(); ++iter) { | 294 iter != parts.end(); ++iter) { |
| 298 AddDisplayFromSpec(*iter); | 295 AddDisplayFromSpec(*iter); |
| 299 } | 296 } |
| 300 if (displays_.empty()) | 297 if (displays_.empty()) |
| 301 AddDisplayFromSpec(std::string() /* default */); | 298 AddDisplayFromSpec(std::string() /* default */); |
| 302 } | 299 } |
| 303 | 300 |
| 304 void MultiDisplayManager::AddRemoveDisplayImpl() { | 301 void MultiDisplayManager::CycleDisplayImpl() { |
| 305 std::vector<gfx::Display> new_displays; | 302 std::vector<gfx::Display> new_displays; |
| 306 if (displays_.size() > 1) { | 303 if (displays_.size() > 1) { |
| 307 // Remove if there is more than one display. | 304 // Remove if there is more than one display. |
| 308 int count = displays_.size() - 1; | 305 int count = displays_.size() - 1; |
| 309 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) | 306 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) |
| 310 new_displays.push_back(*iter); | 307 new_displays.push_back(*iter); |
| 311 } else { | 308 } else { |
| 312 // Add if there is only one display. | 309 // Add if there is only one display. |
| 313 new_displays.push_back(displays_[0]); | 310 new_displays.push_back(displays_[0]); |
| 314 new_displays.push_back(CreateDisplayFromSpec("50+50-1280x768")); | 311 new_displays.push_back(CreateDisplayFromSpec("100+200-500x400")); |
| 315 } | 312 } |
| 316 if (new_displays.size()) | 313 if (new_displays.size()) |
| 317 OnNativeDisplaysChanged(new_displays); | 314 OnNativeDisplaysChanged(new_displays); |
| 318 } | 315 } |
| 319 | 316 |
| 320 void MultiDisplayManager::CycleDisplayImpl() { | |
| 321 if (displays_.size() > 1) { | |
| 322 std::vector<gfx::Display> new_displays; | |
| 323 for (Displays::const_iterator iter = displays_.begin() + 1; | |
| 324 iter != displays_.end(); ++iter) { | |
| 325 gfx::Display display = *iter; | |
| 326 new_displays.push_back(display); | |
| 327 } | |
| 328 new_displays.push_back(displays_.front()); | |
| 329 OnNativeDisplaysChanged(new_displays); | |
| 330 } | |
| 331 } | |
| 332 | |
| 333 void MultiDisplayManager::ScaleDisplayImpl() { | 317 void MultiDisplayManager::ScaleDisplayImpl() { |
| 334 if (displays_.size() > 0) { | 318 if (displays_.size() > 0) { |
| 335 std::vector<gfx::Display> new_displays; | 319 std::vector<gfx::Display> new_displays; |
| 336 for (Displays::const_iterator iter = displays_.begin(); | 320 for (Displays::const_iterator iter = displays_.begin(); |
| 337 iter != displays_.end(); ++iter) { | 321 iter != displays_.end(); ++iter) { |
| 338 gfx::Display display = *iter; | 322 gfx::Display display = *iter; |
| 339 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; | 323 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; |
| 340 display.SetScaleAndBounds( | 324 display.SetScaleAndBounds( |
| 341 factor, gfx::Rect(display.bounds_in_pixel().origin(), | 325 factor, gfx::Rect(display.bounds_in_pixel().origin(), |
| 342 display.size().Scale(factor))); | 326 display.size().Scale(factor))); |
| 343 new_displays.push_back(display); | 327 new_displays.push_back(display); |
| 344 } | 328 } |
| 345 OnNativeDisplaysChanged(new_displays); | 329 OnNativeDisplaysChanged(new_displays); |
| 346 } | 330 } |
| 347 } | 331 } |
| 348 | 332 |
| 349 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( | 333 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( |
| 350 const aura::RootWindow* root_window) { | 334 const aura::RootWindow* root_window) { |
| 351 int64 id = root_window->GetProperty(kDisplayIdKey); | 335 int64 id = root_window->GetProperty(kDisplayIdKey); |
| 336 // if id is |kInvaildDisplayID|, it's being deleted. |
| 337 DCHECK(id != gfx::Display::kInvalidDisplayID); |
| 352 for (Displays::iterator iter = displays_.begin(); | 338 for (Displays::iterator iter = displays_.begin(); |
| 353 iter != displays_.end(); ++iter) { | 339 iter != displays_.end(); ++iter) { |
| 354 if ((*iter).id() == id) | 340 if ((*iter).id() == id) |
| 355 return *iter; | 341 return *iter; |
| 356 } | 342 } |
| 357 DLOG(FATAL) << "Could not find display by id:" << id; | 343 DLOG(FATAL) << "Could not find display by id:" << id; |
| 358 return GetInvalidDisplay(); | 344 return GetInvalidDisplay(); |
| 359 } | 345 } |
| 360 | 346 |
| 361 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) { | 347 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) { |
| 362 gfx::Display display = CreateDisplayFromSpec(spec); | 348 gfx::Display display = CreateDisplayFromSpec(spec); |
| 363 | 349 |
| 364 const gfx::Insets insets = display.GetWorkAreaInsets(); | 350 const gfx::Insets insets = display.GetWorkAreaInsets(); |
| 365 const gfx::Rect& native_bounds = display.bounds_in_pixel(); | 351 const gfx::Rect& native_bounds = display.bounds_in_pixel(); |
| 366 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); | 352 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); |
| 367 display.UpdateWorkAreaFromInsets(insets); | 353 display.UpdateWorkAreaFromInsets(insets); |
| 368 displays_.push_back(display); | 354 displays_.push_back(display); |
| 369 } | 355 } |
| 370 | 356 |
| 371 void MultiDisplayManager::SetInternalDisplayIdForTest(int64 id) { | 357 void MultiDisplayManager::SetInternalDisplayIdForTest(int64 id) { |
| 372 internal_display_id_ = id; | 358 internal_display_id_ = id; |
| 373 internal_display_.reset(new gfx::Display(internal_display_id_, | 359 internal_display_.reset(new gfx::Display(internal_display_id_, |
| 374 gfx::Rect(800, 600))); | 360 gfx::Rect(800, 600))); |
| 375 } | 361 } |
| 376 | 362 |
| 377 } // namespace internal | 363 } // namespace internal |
| 378 } // namespace ash | 364 } // namespace ash |
| OLD | NEW |