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 "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/resource/resource_bundle.h" | 24 #include "ui/base/l10n/l10n_util.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 Loading... |
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 |
286 // Temporarily add displays to be removed because display object | 288 // Temporarily add displays to be removed because display object |
287 // being removed are accessed during shutting down the root. | 289 // being removed are accessed during shutting down the root. |
288 displays_.insert(displays_.end(), removed_displays.begin(), | 290 displays_.insert(displays_.end(), removed_displays.begin(), |
289 removed_displays.end()); | 291 removed_displays.end()); |
290 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); | 292 for (std::vector<size_t>::iterator iter = changed_display_indices.begin(); |
291 iter != changed_display_indices.end(); ++iter) { | 293 iter != changed_display_indices.end(); ++iter) { |
292 NotifyBoundsChanged(displays_[*iter]); | 294 NotifyBoundsChanged(displays_[*iter]); |
293 } | 295 } |
294 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); | 296 for (std::vector<size_t>::iterator iter = added_display_indices.begin(); |
295 iter != added_display_indices.end(); ++iter) { | 297 iter != added_display_indices.end(); ++iter) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 max = area; | 368 max = area; |
367 matching = &(*iter); | 369 matching = &(*iter); |
368 } | 370 } |
369 } | 371 } |
370 // Fallback to the primary display if there is no matching display. | 372 // Fallback to the primary display if there is no matching display. |
371 return matching ? *matching : DisplayController::GetPrimaryDisplay(); | 373 return matching ? *matching : DisplayController::GetPrimaryDisplay(); |
372 } | 374 } |
373 | 375 |
374 std::string MultiDisplayManager::GetDisplayNameFor( | 376 std::string MultiDisplayManager::GetDisplayNameFor( |
375 const gfx::Display& display) { | 377 const gfx::Display& display) { |
376 if (HasInternalDisplay() && IsInternalDisplayId(display.id())) { | 378 if (!display.is_valid()) |
377 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 379 return l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
378 return UTF16ToUTF8( | |
379 bundle.GetLocalizedString(IDS_ASH_INTERNAL_DISPLAY_NAME)); | |
380 } | |
381 | 380 |
382 #if defined(USE_X11) | 381 std::map<int64, std::string>::const_iterator iter = |
383 std::vector<XID> outputs; | 382 display_names_.find(display.id()); |
384 if (display.id() != gfx::Display::kInvalidDisplayID && | 383 if (iter != display_names_.end()) |
385 ui::GetOutputDeviceHandles(&outputs)) { | 384 return iter->second; |
386 for (size_t i = 0; i < outputs.size(); ++i) { | 385 |
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())); | 386 return base::StringPrintf("Display %d", static_cast<int>(display.id())); |
400 } | 387 } |
401 | 388 |
402 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, | 389 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, |
403 const gfx::Size& old_size) { | 390 const gfx::Size& old_size) { |
404 if (!use_fullscreen_host_window()) { | 391 if (!use_fullscreen_host_window()) { |
405 gfx::Display& display = FindDisplayForRootWindow(root); | 392 gfx::Display& display = FindDisplayForRootWindow(root); |
406 if (display.size() != root->GetHostSize()) { | 393 if (display.size() != root->GetHostSize()) { |
407 display.SetSize(root->GetHostSize()); | 394 display.SetSize(root->GetHostSize()); |
408 NotifyBoundsChanged(display); | 395 NotifyBoundsChanged(display); |
(...skipping 10 matching lines...) Expand all Loading... |
419 for (size_t i = 0; i < output_names.size(); ++i) { | 406 for (size_t i = 0; i < output_names.size(); ++i) { |
420 if (chromeos::OutputConfigurator::IsInternalOutputName( | 407 if (chromeos::OutputConfigurator::IsInternalOutputName( |
421 output_names[i])) { | 408 output_names[i])) { |
422 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); | 409 internal_display_id_ = GetDisplayIdForOutput(outputs[i]); |
423 break; | 410 break; |
424 } | 411 } |
425 } | 412 } |
426 } | 413 } |
427 #endif | 414 #endif |
428 | 415 |
| 416 RefreshDisplayNames(); |
| 417 |
429 #if defined(OS_WIN) | 418 #if defined(OS_WIN) |
430 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 419 if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
431 set_use_fullscreen_host_window(true); | 420 set_use_fullscreen_host_window(true); |
432 #endif | 421 #endif |
433 // TODO(oshima): Move this logic to DisplayChangeObserver. | 422 // TODO(oshima): Move this logic to DisplayChangeObserver. |
434 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 423 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
435 switches::kAuraHostWindowSize); | 424 switches::kAuraHostWindowSize); |
436 vector<string> parts; | 425 vector<string> parts; |
437 base::SplitString(size_str, ',', &parts); | 426 base::SplitString(size_str, ',', &parts); |
438 for (vector<string>::const_iterator iter = parts.begin(); | 427 for (vector<string>::const_iterator iter = parts.begin(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 525 } |
537 | 526 |
538 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 527 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
539 aura::client::ScreenPositionClient* client = | 528 aura::client::ScreenPositionClient* client = |
540 aura::client::GetScreenPositionClient(root_window); | 529 aura::client::GetScreenPositionClient(root_window); |
541 client->ConvertPointFromScreen(root_window, &target_location); | 530 client->ConvertPointFromScreen(root_window, &target_location); |
542 | 531 |
543 root_window->MoveCursorTo(target_location); | 532 root_window->MoveCursorTo(target_location); |
544 } | 533 } |
545 | 534 |
| 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 |
546 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { | 564 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { |
547 DisplayList::iterator iter_to_update = to_update->begin(); | 565 DisplayList::iterator iter_to_update = to_update->begin(); |
548 DisplayList::const_iterator iter = displays_.begin(); | 566 DisplayList::const_iterator iter = displays_.begin(); |
549 for (; iter != displays_.end() && iter_to_update != to_update->end(); | 567 for (; iter != displays_.end() && iter_to_update != to_update->end(); |
550 ++iter, ++iter_to_update) { | 568 ++iter, ++iter_to_update) { |
551 (*iter_to_update).set_id((*iter).id()); | 569 (*iter_to_update).set_id((*iter).id()); |
552 } | 570 } |
553 } | 571 } |
554 | 572 |
555 } // namespace internal | 573 } // namespace internal |
556 } // namespace ash | 574 } // namespace ash |
OLD | NEW |