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

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

Issue 11363071: Revert "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
« no previous file with comments | « ash/display/multi_display_manager.h ('k') | ash/system/chromeos/tray_display.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/string_split.h" 14 #include "base/string_split.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
18 #include "ui/aura/aura_switches.h" 18 #include "ui/aura/aura_switches.h"
19 #include "ui/aura/client/screen_position_client.h" 19 #include "ui/aura/client/screen_position_client.h"
20 #include "ui/aura/env.h" 20 #include "ui/aura/env.h"
21 #include "ui/aura/root_window.h" 21 #include "ui/aura/root_window.h"
22 #include "ui/aura/root_window_host.h" 22 #include "ui/aura/root_window_host.h"
23 #include "ui/aura/window_property.h" 23 #include "ui/aura/window_property.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/display.h" 25 #include "ui/gfx/display.h"
26 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
27 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
28 #include "ui/gfx/size_conversions.h" 28 #include "ui/gfx/size_conversions.h"
29 29
30 #if defined(USE_X11) 30 #if defined(USE_X11)
31 #include "ui/base/x/x11_util.h" 31 #include "ui/base/x/x11_util.h"
32 #endif 32 #endif
33 33
34 #if defined(OS_CHROMEOS) 34 #if defined(OS_CHROMEOS)
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 // Do not update |displays_| if there's nothing to be updated. Without this, 277 // 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 278 // it will not update the display layout, which causes the bug
279 // http://crbug.com/155948. 279 // http://crbug.com/155948.
280 if (changed_display_indices.empty() && added_display_indices.empty() && 280 if (changed_display_indices.empty() && added_display_indices.empty() &&
281 removed_displays.empty()) { 281 removed_displays.empty()) {
282 return; 282 return;
283 } 283 }
284 284
285 displays_ = new_displays; 285 displays_ = new_displays;
286 RefreshDisplayNames();
287
288 // Temporarily add displays to be removed because display object 286 // Temporarily add displays to be removed because display object
289 // being removed are accessed during shutting down the root. 287 // being removed are accessed during shutting down the root.
290 displays_.insert(displays_.end(), removed_displays.begin(), 288 displays_.insert(displays_.end(), removed_displays.begin(),
291 removed_displays.end()); 289 removed_displays.end());
292 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); 290 for (std::vector<size_t>::iterator iter = changed_display_indices.begin();
293 iter != changed_display_indices.end(); ++iter) { 291 iter != changed_display_indices.end(); ++iter) {
294 NotifyBoundsChanged(displays_[*iter]); 292 NotifyBoundsChanged(displays_[*iter]);
295 } 293 }
296 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); 294 for (std::vector<size_t>::iterator iter = added_display_indices.begin();
297 iter != added_display_indices.end(); ++iter) { 295 iter != added_display_indices.end(); ++iter) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 max = area; 366 max = area;
369 matching = &(*iter); 367 matching = &(*iter);
370 } 368 }
371 } 369 }
372 // Fallback to the primary display if there is no matching display. 370 // Fallback to the primary display if there is no matching display.
373 return matching ? *matching : DisplayController::GetPrimaryDisplay(); 371 return matching ? *matching : DisplayController::GetPrimaryDisplay();
374 } 372 }
375 373
376 std::string MultiDisplayManager::GetDisplayNameFor( 374 std::string MultiDisplayManager::GetDisplayNameFor(
377 const gfx::Display& display) { 375 const gfx::Display& display) {
378 if (!display.is_valid()) 376 if (HasInternalDisplay() && IsInternalDisplayId(display.id())) {
379 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 377 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
378 return UTF16ToUTF8(
379 bundle.GetLocalizedString(IDS_ASH_INTERNAL_DISPLAY_NAME));
380 }
380 381
381 std::map<int64, std::string>::const_iterator iter = 382 #if defined(USE_X11)
382 display_names_.find(display.id()); 383 std::vector<XID> outputs;
383 if (iter != display_names_.end()) 384 if (display.id() != gfx::Display::kInvalidDisplayID &&
384 return iter->second; 385 ui::GetOutputDeviceHandles(&outputs)) {
385 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
386 return base::StringPrintf("Display %d", static_cast<int>(display.id())); 399 return base::StringPrintf("Display %d", static_cast<int>(display.id()));
387 } 400 }
388 401
389 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, 402 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root,
390 const gfx::Size& old_size) { 403 const gfx::Size& old_size) {
391 if (!use_fullscreen_host_window()) { 404 if (!use_fullscreen_host_window()) {
392 gfx::Display& display = FindDisplayForRootWindow(root); 405 gfx::Display& display = FindDisplayForRootWindow(root);
393 if (display.size() != root->GetHostSize()) { 406 if (display.size() != root->GetHostSize()) {
394 display.SetSize(root->GetHostSize()); 407 display.SetSize(root->GetHostSize());
395 NotifyBoundsChanged(display); 408 NotifyBoundsChanged(display);
(...skipping 10 matching lines...) Expand all
406 for (size_t i = 0; i < output_names.size(); ++i) { 419 for (size_t i = 0; i < output_names.size(); ++i) {
407 if (chromeos::OutputConfigurator::IsInternalOutputName( 420 if (chromeos::OutputConfigurator::IsInternalOutputName(
408 output_names[i])) { 421 output_names[i])) {
409 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); 422 internal_display_id_ = GetDisplayIdForOutput(outputs[i]);
410 break; 423 break;
411 } 424 }
412 } 425 }
413 } 426 }
414 #endif 427 #endif
415 428
416 RefreshDisplayNames();
417
418 #if defined(OS_WIN) 429 #if defined(OS_WIN)
419 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 430 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
420 set_use_fullscreen_host_window(true); 431 set_use_fullscreen_host_window(true);
421 #endif 432 #endif
422 // TODO(oshima): Move this logic to DisplayChangeObserver. 433 // TODO(oshima): Move this logic to DisplayChangeObserver.
423 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 434 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
424 switches::kAuraHostWindowSize); 435 switches::kAuraHostWindowSize);
425 vector<string> parts; 436 vector<string> parts;
426 base::SplitString(size_str, ',', &parts); 437 base::SplitString(size_str, ',', &parts);
427 for (vector<string>::const_iterator iter = parts.begin(); 438 for (vector<string>::const_iterator iter = parts.begin();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 536 }
526 537
527 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 538 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
528 aura::client::ScreenPositionClient* client = 539 aura::client::ScreenPositionClient* client =
529 aura::client::GetScreenPositionClient(root_window); 540 aura::client::GetScreenPositionClient(root_window);
530 client->ConvertPointFromScreen(root_window, &target_location); 541 client->ConvertPointFromScreen(root_window, &target_location);
531 542
532 root_window->MoveCursorTo(target_location); 543 root_window->MoveCursorTo(target_location);
533 } 544 }
534 545
535 void MultiDisplayManager::RefreshDisplayNames() {
536 display_names_.clear();
537
538 if (!base::chromeos::IsRunningOnChromeOS())
539 return;
540
541 #if defined(USE_X11)
542 std::vector<XID> outputs;
543 if (!ui::GetOutputDeviceHandles(&outputs))
544 return;
545
546 for (size_t i = 0; i < outputs.size(); ++i) {
547 uint16 manufacturer_id = 0;
548 uint32 serial_number = 0;
549 std::string name;
550 if (ui::GetOutputDeviceData(
551 outputs[i], &manufacturer_id, &serial_number, &name)) {
552 int64 id = gfx::Display::GetID(manufacturer_id, serial_number);
553 if (IsInternalDisplayId(id)) {
554 display_names_[id] =
555 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME);
556 } else {
557 display_names_[id] = name;
558 }
559 }
560 }
561 #endif
562 }
563
564 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { 546 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const {
565 DisplayList::iterator iter_to_update = to_update->begin(); 547 DisplayList::iterator iter_to_update = to_update->begin();
566 DisplayList::const_iterator iter = displays_.begin(); 548 DisplayList::const_iterator iter = displays_.begin();
567 for (; iter != displays_.end() && iter_to_update != to_update->end(); 549 for (; iter != displays_.end() && iter_to_update != to_update->end();
568 ++iter, ++iter_to_update) { 550 ++iter, ++iter_to_update) {
569 (*iter_to_update).set_id((*iter).id()); 551 (*iter_to_update).set_id((*iter).id());
570 } 552 }
571 } 553 }
572 554
573 } // namespace internal 555 } // namespace internal
574 } // namespace ash 556 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/multi_display_manager.h ('k') | ash/system/chromeos/tray_display.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698