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/system/chromeos/tray_display.h" | 5 #include "ash/system/chromeos/tray_display.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/display/multi_display_manager.h" | |
9 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
11 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
12 #include "ash/system/tray/system_tray_delegate.h" | 11 #include "ash/system/tray/system_tray_delegate.h" |
13 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
14 #include "ash/system/tray/tray_views.h" | 13 #include "ash/system/tray/tray_views.h" |
15 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
16 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
17 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
18 #include "ui/aura/display_manager.h" | 17 #include "ui/aura/display_manager.h" |
19 #include "ui/aura/env.h" | 18 #include "ui/aura/env.h" |
20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
23 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
24 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
25 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
26 | 25 |
| 26 #if defined(USE_X11) |
| 27 #include "ui/base/x/x11_util.h" |
| 28 #endif |
| 29 |
27 namespace ash { | 30 namespace ash { |
28 namespace internal { | 31 namespace internal { |
29 | 32 |
30 class DisplayView : public ash::internal::ActionableView { | 33 class DisplayView : public ash::internal::ActionableView { |
31 public: | 34 public: |
32 explicit DisplayView(user::LoginStatus login_status) | 35 explicit DisplayView(user::LoginStatus login_status) |
33 : login_status_(login_status) { | 36 : login_status_(login_status) { |
34 SetLayoutManager(new | 37 SetLayoutManager(new |
35 views::BoxLayout(views::BoxLayout::kHorizontal, | 38 views::BoxLayout(views::BoxLayout::kHorizontal, |
36 ash::kTrayPopupPaddingHorizontal, 0, | 39 ash::kTrayPopupPaddingHorizontal, 0, |
(...skipping 13 matching lines...) Expand all Loading... |
50 virtual ~DisplayView() {} | 53 virtual ~DisplayView() {} |
51 | 54 |
52 void Update() { | 55 void Update() { |
53 switch (Shell::GetInstance()->output_configurator()->output_state()) { | 56 switch (Shell::GetInstance()->output_configurator()->output_state()) { |
54 case chromeos::STATE_INVALID: | 57 case chromeos::STATE_INVALID: |
55 case chromeos::STATE_HEADLESS: | 58 case chromeos::STATE_HEADLESS: |
56 case chromeos::STATE_SINGLE: | 59 case chromeos::STATE_SINGLE: |
57 SetVisible(false); | 60 SetVisible(false); |
58 return; | 61 return; |
59 case chromeos::STATE_DUAL_MIRROR: { | 62 case chromeos::STATE_DUAL_MIRROR: { |
60 label_->SetText(l10n_util::GetStringFUTF16( | 63 // Simply assumes that the primary display appears first and the |
61 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetExternalDisplayName())); | 64 // secondary display appears next in the list. |
62 SetVisible(true); | 65 std::vector<std::string> display_names; |
| 66 #if defined(USE_X11) |
| 67 std::vector<XID> output_ids; |
| 68 ui::GetOutputDeviceHandles(&output_ids); |
| 69 display_names = ui::GetDisplayNames(output_ids); |
| 70 #endif |
| 71 if (display_names.size() > 1) { |
| 72 label_->SetText(l10n_util::GetStringFUTF16( |
| 73 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, |
| 74 UTF8ToUTF16(display_names[1]))); |
| 75 SetVisible(true); |
| 76 } else { |
| 77 SetVisible(false); |
| 78 } |
63 return; | 79 return; |
64 } | 80 } |
65 case chromeos::STATE_DUAL_PRIMARY_ONLY: | 81 case chromeos::STATE_DUAL_PRIMARY_ONLY: |
66 case chromeos::STATE_DUAL_SECONDARY_ONLY: { | 82 case chromeos::STATE_DUAL_SECONDARY_ONLY: { |
67 label_->SetText(l10n_util::GetStringFUTF16( | 83 aura::DisplayManager* display_manager = |
68 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName())); | 84 aura::Env::GetInstance()->display_manager(); |
69 SetVisible(true); | 85 if (display_manager->GetNumDisplays() > 1) { |
| 86 label_->SetText(l10n_util::GetStringFUTF16( |
| 87 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, |
| 88 UTF8ToUTF16(display_manager->GetDisplayNameFor( |
| 89 ScreenAsh::GetSecondaryDisplay())))); |
| 90 SetVisible(true); |
| 91 } else { |
| 92 SetVisible(false); |
| 93 } |
70 return; | 94 return; |
71 } | 95 } |
72 default: | 96 default: |
73 NOTREACHED(); | 97 NOTREACHED(); |
74 } | 98 } |
75 } | 99 } |
76 | 100 |
77 private: | 101 private: |
78 // Returns the name of the currently connected external display. | |
79 string16 GetExternalDisplayName() { | |
80 MultiDisplayManager* display_manager = static_cast<MultiDisplayManager*>( | |
81 aura::Env::GetInstance()->display_manager()); | |
82 | |
83 gfx::Display external_display(gfx::Display::kInvalidDisplayID); | |
84 if (display_manager->HasInternalDisplay()) { | |
85 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | |
86 gfx::Display* display = display_manager->GetDisplayAt(i); | |
87 if (!display_manager->IsInternalDisplayId(display->id())) { | |
88 external_display = *display; | |
89 break; | |
90 } | |
91 } | |
92 } else { | |
93 // Falls back to the secondary display since the system doesn't | |
94 // distinguish the displays. | |
95 external_display = ScreenAsh::GetSecondaryDisplay(); | |
96 } | |
97 | |
98 return UTF8ToUTF16(display_manager->GetDisplayNameFor(external_display)); | |
99 } | |
100 | |
101 // Overridden from ActionableView. | 102 // Overridden from ActionableView. |
102 virtual bool PerformAction(const ui::Event& event) OVERRIDE { | 103 virtual bool PerformAction(const ui::Event& event) OVERRIDE { |
103 if (login_status_ == ash::user::LOGGED_IN_USER || | 104 if (login_status_ == ash::user::LOGGED_IN_USER || |
104 login_status_ == ash::user::LOGGED_IN_OWNER || | 105 login_status_ == ash::user::LOGGED_IN_OWNER || |
105 login_status_ == ash::user::LOGGED_IN_GUEST) { | 106 login_status_ == ash::user::LOGGED_IN_GUEST) { |
106 ash::Shell::GetInstance()->tray_delegate()->ShowDisplaySettings(); | 107 ash::Shell::GetInstance()->tray_delegate()->ShowDisplaySettings(); |
107 } | 108 } |
108 | 109 |
109 return true; | 110 return true; |
110 } | 111 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 default_->Update(); | 151 default_->Update(); |
151 } | 152 } |
152 | 153 |
153 void TrayDisplay::OnDisplayModeChanged() { | 154 void TrayDisplay::OnDisplayModeChanged() { |
154 if (default_) | 155 if (default_) |
155 default_->Update(); | 156 default_->Update(); |
156 } | 157 } |
157 | 158 |
158 } // namespace internal | 159 } // namespace internal |
159 } // namespace ash | 160 } // namespace ash |
OLD | NEW |