 Chromium Code Reviews
 Chromium Code Reviews Issue 11369042:
  Caches the display names in MultiDisplayManager.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11369042:
  Caches the display names in MultiDisplayManager.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow( | 122 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow( | 
| 123 const aura::Window* window, | 123 const aura::Window* window, | 
| 124 const gfx::Insets& insets) { | 124 const gfx::Insets& insets) { | 
| 125 const RootWindow* root = window->GetRootWindow(); | 125 const RootWindow* root = window->GetRootWindow(); | 
| 126 gfx::Display& display = FindDisplayForRootWindow(root); | 126 gfx::Display& display = FindDisplayForRootWindow(root); | 
| 127 gfx::Rect old_work_area = display.work_area(); | 127 gfx::Rect old_work_area = display.work_area(); | 
| 128 display.UpdateWorkAreaFromInsets(insets); | 128 display.UpdateWorkAreaFromInsets(insets); | 
| 129 return old_work_area != display.work_area(); | 129 return old_work_area != display.work_area(); | 
| 130 } | 130 } | 
| 131 | 131 | 
| 132 std::vector<std::string> MultiDisplayManager::GetExternalDisplayNames() const { | |
| 
Daniel Erat
2012/11/02 16:46:17
this method seems a bit tricky; it returns an orde
 
Jun Mukai
2012/11/02 18:04:35
Thanks for the comment.  Removed this method and c
 | |
| 133 std::vector<std::string> result; | |
| 134 for (std::map<int64, std::string>::const_iterator iter = | |
| 135 display_names_.begin(); iter != display_names_.end(); ++iter) { | |
| 136 if (!IsInternalDisplayId(iter->first)) | |
| 137 result.push_back(iter->second); | |
| 138 } | |
| 139 | |
| 140 return result; | |
| 141 } | |
| 142 | |
| 132 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const { | 143 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const { | 
| 133 return const_cast<MultiDisplayManager*>(this)->FindDisplayForId(id); | 144 return const_cast<MultiDisplayManager*>(this)->FindDisplayForId(id); | 
| 134 } | 145 } | 
| 135 | 146 | 
| 136 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( | 147 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( | 
| 137 const gfx::Point& point_in_screen) const { | 148 const gfx::Point& point_in_screen) const { | 
| 138 for (DisplayList::const_iterator iter = displays_.begin(); | 149 for (DisplayList::const_iterator iter = displays_.begin(); | 
| 139 iter != displays_.end(); ++iter) { | 150 iter != displays_.end(); ++iter) { | 
| 140 const gfx::Display& display = *iter; | 151 const gfx::Display& display = *iter; | 
| 141 if (display.bounds().Contains(point_in_screen)) | 152 if (display.bounds().Contains(point_in_screen)) | 
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 | 287 | 
| 277 // Do not update |displays_| if there's nothing to be updated. Without this, | 288 // Do not update |displays_| if there's nothing to be updated. Without this, | 
| 278 // it will not update the display layout, which causes the bug | 289 // it will not update the display layout, which causes the bug | 
| 279 // http://crbug.com/155948. | 290 // http://crbug.com/155948. | 
| 280 if (changed_display_indices.empty() && added_display_indices.empty() && | 291 if (changed_display_indices.empty() && added_display_indices.empty() && | 
| 281 removed_displays.empty()) { | 292 removed_displays.empty()) { | 
| 282 return; | 293 return; | 
| 283 } | 294 } | 
| 284 | 295 | 
| 285 displays_ = new_displays; | 296 displays_ = new_displays; | 
| 297 RefreshDisplayNames(); | |
| 298 | |
| 286 // Temporarily add displays to be removed because display object | 299 // Temporarily add displays to be removed because display object | 
| 287 // being removed are accessed during shutting down the root. | 300 // being removed are accessed during shutting down the root. | 
| 288 displays_.insert(displays_.end(), removed_displays.begin(), | 301 displays_.insert(displays_.end(), removed_displays.begin(), | 
| 289 removed_displays.end()); | 302 removed_displays.end()); | 
| 290 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); | 303 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); | 
| 291 iter != changed_display_indices.end(); ++iter) { | 304 iter != changed_display_indices.end(); ++iter) { | 
| 292 NotifyBoundsChanged(displays_[*iter]); | 305 NotifyBoundsChanged(displays_[*iter]); | 
| 293 } | 306 } | 
| 294 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); | 307 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); | 
| 295 iter != added_display_indices.end(); ++iter) { | 308 iter != added_display_indices.end(); ++iter) { | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 int area = intersect.width() * intersect.height(); | 377 int area = intersect.width() * intersect.height(); | 
| 365 if (area > max) { | 378 if (area > max) { | 
| 366 max = area; | 379 max = area; | 
| 367 matching = &(*iter); | 380 matching = &(*iter); | 
| 368 } | 381 } | 
| 369 } | 382 } | 
| 370 // Fallback to the primary display if there is no matching display. | 383 // Fallback to the primary display if there is no matching display. | 
| 371 return matching ? *matching : DisplayController::GetPrimaryDisplay(); | 384 return matching ? *matching : DisplayController::GetPrimaryDisplay(); | 
| 372 } | 385 } | 
| 373 | 386 | 
| 374 std::string MultiDisplayManager::GetDisplayNameFor( | 387 std::string MultiDisplayManager::GetDisplayNameFor( | 
| 
Daniel Erat
2012/11/02 16:46:17
nit (doesn't need to be addressed here): putting "
 
Jun Mukai
2012/11/02 18:04:35
Can we do that in another CL?  This is used in man
 
Daniel Erat
2012/11/02 18:59:04
Sure, sounds fine.
 | |
| 375 const gfx::Display& display) { | 388 const gfx::Display& display) { | 
| 376 if (HasInternalDisplay() && IsInternalDisplayId(display.id())) { | 389 std::map<int64, std::string>::const_iterator iter = | 
| 377 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 390 display_names_.find(display.id()); | 
| 378 return UTF16ToUTF8( | 391 if (iter != display_names_.end()) | 
| 379 bundle.GetLocalizedString(IDS_ASH_INTERNAL_DISPLAY_NAME)); | 392 return iter->second; | 
| 380 } | |
| 381 | 393 | 
| 382 #if defined(USE_X11) | |
| 383 std::vector<XID> outputs; | |
| 384 if (display.id() != gfx::Display::kInvalidDisplayID && | |
| 385 ui::GetOutputDeviceHandles(&outputs)) { | |
| 386 for (size_t i = 0; i < outputs.size(); ++i) { | |
| 387 uint16 manufacturer_id = 0; | |
| 388 uint32 serial_number = 0; | |
| 389 std::string name; | |
| 390 if (ui::GetOutputDeviceData( | |
| 391 outputs[i], &manufacturer_id, &serial_number, &name) && | |
| 392 display.id() == | |
| 393 gfx::Display::GetID(manufacturer_id, serial_number)) { | |
| 394 return name; | |
| 395 } | |
| 396 } | |
| 397 } | |
| 398 #endif | |
| 399 return base::StringPrintf("Display %d", static_cast<int>(display.id())); | 394 return base::StringPrintf("Display %d", static_cast<int>(display.id())); | 
| 400 } | 395 } | 
| 401 | 396 | 
| 402 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, | 397 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, | 
| 403 const gfx::Size& old_size) { | 398 const gfx::Size& old_size) { | 
| 404 if (!use_fullscreen_host_window()) { | 399 if (!use_fullscreen_host_window()) { | 
| 405 gfx::Display& display = FindDisplayForRootWindow(root); | 400 gfx::Display& display = FindDisplayForRootWindow(root); | 
| 406 if (display.size() != root->GetHostSize()) { | 401 if (display.size() != root->GetHostSize()) { | 
| 407 display.SetSize(root->GetHostSize()); | 402 display.SetSize(root->GetHostSize()); | 
| 408 NotifyBoundsChanged(display); | 403 NotifyBoundsChanged(display); | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 419 for (size_t i = 0; i < output_names.size(); ++i) { | 414 for (size_t i = 0; i < output_names.size(); ++i) { | 
| 420 if (chromeos::OutputConfigurator::IsInternalOutputName( | 415 if (chromeos::OutputConfigurator::IsInternalOutputName( | 
| 421 output_names[i])) { | 416 output_names[i])) { | 
| 422 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); | 417 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); | 
| 423 break; | 418 break; | 
| 424 } | 419 } | 
| 425 } | 420 } | 
| 426 } | 421 } | 
| 427 #endif | 422 #endif | 
| 428 | 423 | 
| 424 RefreshDisplayNames(); | |
| 425 | |
| 429 #if defined(OS_WIN) | 426 #if defined(OS_WIN) | 
| 430 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 427 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 
| 431 set_use_fullscreen_host_window(true); | 428 set_use_fullscreen_host_window(true); | 
| 432 #endif | 429 #endif | 
| 433 // TODO(oshima): Move this logic to DisplayChangeObserver. | 430 // TODO(oshima): Move this logic to DisplayChangeObserver. | 
| 434 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 431 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 
| 435 switches::kAuraHostWindowSize); | 432 switches::kAuraHostWindowSize); | 
| 436 vector<string> parts; | 433 vector<string> parts; | 
| 437 base::SplitString(size_str, ',', &parts); | 434 base::SplitString(size_str, ',', &parts); | 
| 438 for (vector<string>::const_iterator iter = parts.begin(); | 435 for (vector<string>::const_iterator iter = parts.begin(); | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 } | 533 } | 
| 537 | 534 | 
| 538 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 535 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 
| 539 aura::client::ScreenPositionClient* client = | 536 aura::client::ScreenPositionClient* client = | 
| 540 aura::client::GetScreenPositionClient(root_window); | 537 aura::client::GetScreenPositionClient(root_window); | 
| 541 client->ConvertPointFromScreen(root_window, &target_location); | 538 client->ConvertPointFromScreen(root_window, &target_location); | 
| 542 | 539 | 
| 543 root_window->MoveCursorTo(target_location); | 540 root_window->MoveCursorTo(target_location); | 
| 544 } | 541 } | 
| 545 | 542 | 
| 543 void MultiDisplayManager::RefreshDisplayNames() { | |
| 544 display_names_.clear(); | |
| 545 | |
| 546 if (!base::chromeos::IsRunningOnChromeOS()) | |
| 547 return; | |
| 548 | |
| 549 #if defined(USE_X11) | |
| 550 std::vector<XID> outputs; | |
| 551 if (!ui::GetOutputDeviceHandles(&outputs)) | |
| 552 return; | |
| 553 | |
| 554 for (size_t i = 0; i < outputs.size(); ++i) { | |
| 555 uint16 manufacturer_id = 0; | |
| 556 uint32 serial_number = 0; | |
| 557 std::string name; | |
| 558 if (ui::GetOutputDeviceData( | |
| 559 outputs[i], &manufacturer_id, &serial_number, &name)) { | |
| 560 int64 id = gfx::Display::GetID(manufacturer_id, serial_number); | |
| 561 if (IsInternalDisplayId(id)) { | |
| 562 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 563 display_names_[id] = UTF16ToUTF8( | |
| 564 bundle.GetLocalizedString(IDS_ASH_INTERNAL_DISPLAY_NAME)); | |
| 565 } else { | |
| 566 display_names_[id] = name; | |
| 567 } | |
| 568 } | |
| 569 } | |
| 570 #endif | |
| 571 } | |
| 572 | |
| 546 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { | 573 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { | 
| 547 DisplayList::iterator iter_to_update = to_update->begin(); | 574 DisplayList::iterator iter_to_update = to_update->begin(); | 
| 548 DisplayList::const_iterator iter = displays_.begin(); | 575 DisplayList::const_iterator iter = displays_.begin(); | 
| 549 for (; iter != displays_.end() && iter_to_update != to_update->end(); | 576 for (; iter != displays_.end() && iter_to_update != to_update->end(); | 
| 550 ++iter, ++iter_to_update) { | 577 ++iter, ++iter_to_update) { | 
| 551 (*iter_to_update).set_id((*iter).id()); | 578 (*iter_to_update).set_id((*iter).id()); | 
| 552 } | 579 } | 
| 553 } | 580 } | 
| 554 | 581 | 
| 555 } // namespace internal | 582 } // namespace internal | 
| 556 } // namespace ash | 583 } // namespace ash | 
| OLD | NEW |