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

Side by Side Diff: ash/system/chromeos/tray_display.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
« no previous file with comments | « ash/display/multi_display_manager.cc ('k') | no next file » | 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/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"
8 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray.h" 11 #include "ash/system/tray/system_tray.h"
11 #include "ash/system/tray/system_tray_delegate.h" 12 #include "ash/system/tray/system_tray_delegate.h"
12 #include "ash/system/tray/tray_constants.h" 13 #include "ash/system/tray/tray_constants.h"
13 #include "ash/system/tray/tray_views.h" 14 #include "ash/system/tray/tray_views.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
16 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
17 #include "ui/aura/display_manager.h" 18 #include "ui/aura/display_manager.h"
18 #include "ui/aura/env.h" 19 #include "ui/aura/env.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
22 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
24 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
25 26
26 #if defined(USE_X11)
27 #include "ui/base/x/x11_util.h"
28 #endif
29
30 namespace ash { 27 namespace ash {
31 namespace internal { 28 namespace internal {
32 29
33 class DisplayView : public ash::internal::ActionableView { 30 class DisplayView : public ash::internal::ActionableView {
34 public: 31 public:
35 explicit DisplayView(user::LoginStatus login_status) 32 explicit DisplayView(user::LoginStatus login_status)
36 : login_status_(login_status) { 33 : login_status_(login_status) {
37 SetLayoutManager(new 34 SetLayoutManager(new
38 views::BoxLayout(views::BoxLayout::kHorizontal, 35 views::BoxLayout(views::BoxLayout::kHorizontal,
39 ash::kTrayPopupPaddingHorizontal, 0, 36 ash::kTrayPopupPaddingHorizontal, 0,
(...skipping 13 matching lines...) Expand all
53 virtual ~DisplayView() {} 50 virtual ~DisplayView() {}
54 51
55 void Update() { 52 void Update() {
56 switch (Shell::GetInstance()->output_configurator()->output_state()) { 53 switch (Shell::GetInstance()->output_configurator()->output_state()) {
57 case chromeos::STATE_INVALID: 54 case chromeos::STATE_INVALID:
58 case chromeos::STATE_HEADLESS: 55 case chromeos::STATE_HEADLESS:
59 case chromeos::STATE_SINGLE: 56 case chromeos::STATE_SINGLE:
60 SetVisible(false); 57 SetVisible(false);
61 return; 58 return;
62 case chromeos::STATE_DUAL_MIRROR: { 59 case chromeos::STATE_DUAL_MIRROR: {
63 // Simply assumes that the primary display appears first and the 60 label_->SetText(l10n_util::GetStringFUTF16(
64 // secondary display appears next in the list. 61 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetExternalDisplayName()));
65 std::vector<std::string> display_names; 62 SetVisible(true);
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 }
79 return; 63 return;
80 } 64 }
81 case chromeos::STATE_DUAL_PRIMARY_ONLY: 65 case chromeos::STATE_DUAL_PRIMARY_ONLY:
82 case chromeos::STATE_DUAL_SECONDARY_ONLY: { 66 case chromeos::STATE_DUAL_SECONDARY_ONLY: {
83 aura::DisplayManager* display_manager = 67 label_->SetText(l10n_util::GetStringFUTF16(
84 aura::Env::GetInstance()->display_manager(); 68 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName()));
85 if (display_manager->GetNumDisplays() > 1) { 69 SetVisible(true);
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 }
94 return; 70 return;
95 } 71 }
96 default: 72 default:
97 NOTREACHED(); 73 NOTREACHED();
98 } 74 }
99 } 75 }
100 76
101 private: 77 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
102 // Overridden from ActionableView. 101 // Overridden from ActionableView.
103 virtual bool PerformAction(const ui::Event& event) OVERRIDE { 102 virtual bool PerformAction(const ui::Event& event) OVERRIDE {
104 if (login_status_ == ash::user::LOGGED_IN_USER || 103 if (login_status_ == ash::user::LOGGED_IN_USER ||
105 login_status_ == ash::user::LOGGED_IN_OWNER || 104 login_status_ == ash::user::LOGGED_IN_OWNER ||
106 login_status_ == ash::user::LOGGED_IN_GUEST) { 105 login_status_ == ash::user::LOGGED_IN_GUEST) {
107 ash::Shell::GetInstance()->tray_delegate()->ShowDisplaySettings(); 106 ash::Shell::GetInstance()->tray_delegate()->ShowDisplaySettings();
108 } 107 }
109 108
110 return true; 109 return true;
111 } 110 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 default_->Update(); 150 default_->Update();
152 } 151 }
153 152
154 void TrayDisplay::OnDisplayModeChanged() { 153 void TrayDisplay::OnDisplayModeChanged() {
155 if (default_) 154 if (default_)
156 default_->Update(); 155 default_->Update();
157 } 156 }
158 157
159 } // namespace internal 158 } // namespace internal
160 } // namespace ash 159 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/multi_display_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698