Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: ash/display/multi_display_manager.cc

Issue 11369042: Caches the display names in MultiDisplayManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 {
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 result.push_back(iter->second);
137 }
138
139 return result;
140 }
141
132 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const { 142 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const {
133 return const_cast<MultiDisplayManager*>(this)->FindDisplayForId(id); 143 return const_cast<MultiDisplayManager*>(this)->FindDisplayForId(id);
134 } 144 }
135 145
136 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( 146 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint(
137 const gfx::Point& point_in_screen) const { 147 const gfx::Point& point_in_screen) const {
138 for (DisplayList::const_iterator iter = displays_.begin(); 148 for (DisplayList::const_iterator iter = displays_.begin();
139 iter != displays_.end(); ++iter) { 149 iter != displays_.end(); ++iter) {
140 const gfx::Display& display = *iter; 150 const gfx::Display& display = *iter;
141 if (display.bounds().Contains(point_in_screen)) 151 if (display.bounds().Contains(point_in_screen))
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 286
277 // Do not update |displays_| if there's nothing to be updated. Without this, 287 // 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 288 // it will not update the display layout, which causes the bug
279 // http://crbug.com/155948. 289 // http://crbug.com/155948.
280 if (changed_display_indices.empty() && added_display_indices.empty() && 290 if (changed_display_indices.empty() && added_display_indices.empty() &&
281 removed_displays.empty()) { 291 removed_displays.empty()) {
282 return; 292 return;
283 } 293 }
284 294
285 displays_ = new_displays; 295 displays_ = new_displays;
296 RefreshDisplayNames();
297
286 // Temporarily add displays to be removed because display object 298 // Temporarily add displays to be removed because display object
287 // being removed are accessed during shutting down the root. 299 // being removed are accessed during shutting down the root.
288 displays_.insert(displays_.end(), removed_displays.begin(), 300 displays_.insert(displays_.end(), removed_displays.begin(),
289 removed_displays.end()); 301 removed_displays.end());
290 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); 302 for (std::vector<size_t>::iterator iter = changed_display_indices.begin();
291 iter != changed_display_indices.end(); ++iter) { 303 iter != changed_display_indices.end(); ++iter) {
292 NotifyBoundsChanged(displays_[*iter]); 304 NotifyBoundsChanged(displays_[*iter]);
293 } 305 }
294 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); 306 for (std::vector<size_t>::iterator iter = added_display_indices.begin();
295 iter != added_display_indices.end(); ++iter) { 307 iter != added_display_indices.end(); ++iter) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 384 }
373 385
374 std::string MultiDisplayManager::GetDisplayNameFor( 386 std::string MultiDisplayManager::GetDisplayNameFor(
375 const gfx::Display& display) { 387 const gfx::Display& display) {
376 if (HasInternalDisplay() && IsInternalDisplayId(display.id())) { 388 if (HasInternalDisplay() && IsInternalDisplayId(display.id())) {
377 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 389 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
378 return UTF16ToUTF8( 390 return UTF16ToUTF8(
379 bundle.GetLocalizedString(IDS_ASH_INTERNAL_DISPLAY_NAME)); 391 bundle.GetLocalizedString(IDS_ASH_INTERNAL_DISPLAY_NAME));
380 } 392 }
381 393
382 #if defined(USE_X11) 394 std::map<int64, std::string>::const_iterator iter =
383 std::vector<XID> outputs; 395 display_names_.find(display.id());
384 if (display.id() != gfx::Display::kInvalidDisplayID && 396 if (iter != display_names_.end())
385 ui::GetOutputDeviceHandles(&outputs)) { 397 return iter->second;
386 for (size_t i = 0; i < outputs.size(); ++i) { 398
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())); 399 return base::StringPrintf("Display %d", static_cast<int>(display.id()));
400 } 400 }
401 401
402 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, 402 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root,
403 const gfx::Size& old_size) { 403 const gfx::Size& old_size) {
404 if (!use_fullscreen_host_window()) { 404 if (!use_fullscreen_host_window()) {
405 gfx::Display& display = FindDisplayForRootWindow(root); 405 gfx::Display& display = FindDisplayForRootWindow(root);
406 if (display.size() != root->GetHostSize()) { 406 if (display.size() != root->GetHostSize()) {
407 display.SetSize(root->GetHostSize()); 407 display.SetSize(root->GetHostSize());
408 NotifyBoundsChanged(display); 408 NotifyBoundsChanged(display);
(...skipping 10 matching lines...) Expand all
419 for (size_t i = 0; i < output_names.size(); ++i) { 419 for (size_t i = 0; i < output_names.size(); ++i) {
420 if (chromeos::OutputConfigurator::IsInternalOutputName( 420 if (chromeos::OutputConfigurator::IsInternalOutputName(
421 output_names[i])) { 421 output_names[i])) {
422 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); 422 internal_display_id_ = GetDisplayIdForOutput(outputs[i]);
423 break; 423 break;
424 } 424 }
425 } 425 }
426 } 426 }
427 #endif 427 #endif
428 428
429 RefreshDisplayNames();
430
429 #if defined(OS_WIN) 431 #if defined(OS_WIN)
430 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 432 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
431 set_use_fullscreen_host_window(true); 433 set_use_fullscreen_host_window(true);
432 #endif 434 #endif
433 // TODO(oshima): Move this logic to DisplayChangeObserver. 435 // TODO(oshima): Move this logic to DisplayChangeObserver.
434 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 436 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
435 switches::kAuraHostWindowSize); 437 switches::kAuraHostWindowSize);
436 vector<string> parts; 438 vector<string> parts;
437 base::SplitString(size_str, ',', &parts); 439 base::SplitString(size_str, ',', &parts);
438 for (vector<string>::const_iterator iter = parts.begin(); 440 for (vector<string>::const_iterator iter = parts.begin();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 538 }
537 539
538 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 540 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
539 aura::client::ScreenPositionClient* client = 541 aura::client::ScreenPositionClient* client =
540 aura::client::GetScreenPositionClient(root_window); 542 aura::client::GetScreenPositionClient(root_window);
541 client->ConvertPointFromScreen(root_window, &target_location); 543 client->ConvertPointFromScreen(root_window, &target_location);
542 544
543 root_window->MoveCursorTo(target_location); 545 root_window->MoveCursorTo(target_location);
544 } 546 }
545 547
548 void MultiDisplayManager::RefreshDisplayNames() {
549 display_names_.clear();
550
551 if (!base::chromeos::IsRunningOnChromeOS())
552 return;
553
554 #if defined(USE_X11)
555 std::vector<XID> outputs;
556 std::string result;
oshima 2012/11/02 06:33:56 this isn't used?
Jun Mukai 2012/11/02 16:09:07 Done.
557 if (!ui::GetOutputDeviceHandles(&outputs))
558 return;
559
560 for (size_t i = 0; i < outputs.size(); ++i) {
561 uint16 manufacturer_id = 0;
562 uint32 serial_number = 0;
563 std::string name;
564 if (ui::GetOutputDeviceData(
565 outputs[i], &manufacturer_id, &serial_number, &name)) {
566 int64 id = gfx::Display::GetID(manufacturer_id, serial_number);
567 if (!HasInternalDisplay() || !IsInternalDisplayId(id))
oshima 2012/11/02 06:33:56 is it simpler to set inernal display's name here r
Jun Mukai 2012/11/02 16:09:07 Done.
568 display_names_[id] = name;
569 }
570 }
571 #endif
572 }
573
546 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { 574 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const {
547 DisplayList::iterator iter_to_update = to_update->begin(); 575 DisplayList::iterator iter_to_update = to_update->begin();
548 DisplayList::const_iterator iter = displays_.begin(); 576 DisplayList::const_iterator iter = displays_.begin();
549 for (; iter != displays_.end() && iter_to_update != to_update->end(); 577 for (; iter != displays_.end() && iter_to_update != to_update->end();
550 ++iter, ++iter_to_update) { 578 ++iter, ++iter_to_update) {
551 (*iter_to_update).set_id((*iter).id()); 579 (*iter_to_update).set_id((*iter).id());
552 } 580 }
553 } 581 }
554 582
555 } // namespace internal 583 } // namespace internal
556 } // namespace ash 584 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698