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

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
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,
40 ash::kTrayPopupPaddingBetweenItems)); 37 ash::kTrayPopupPaddingBetweenItems));
41 38
42 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 39 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
43 views::ImageView* image = 40 views::ImageView* image =
44 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); 41 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight);
45 image->SetImage( 42 image->SetImage(
46 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); 43 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia());
47 AddChildView(image); 44 AddChildView(image);
48 label_ = new views::Label(); 45 label_ = new views::Label();
49 AddChildView(label_); 46 AddChildView(label_);
50 Update(); 47 Update();
51 } 48 }
52 49
53 virtual ~DisplayView() {} 50 virtual ~DisplayView() {}
54 51
55 void Update() { 52 void Update() {
53 MultiDisplayManager* display_manager = static_cast<MultiDisplayManager*>(
54 aura::Env::GetInstance()->display_manager());
55
56 switch (Shell::GetInstance()->output_configurator()->output_state()) { 56 switch (Shell::GetInstance()->output_configurator()->output_state()) {
57 case chromeos::STATE_INVALID: 57 case chromeos::STATE_INVALID:
58 case chromeos::STATE_HEADLESS: 58 case chromeos::STATE_HEADLESS:
59 case chromeos::STATE_SINGLE: 59 case chromeos::STATE_SINGLE:
60 SetVisible(false); 60 SetVisible(false);
61 return; 61 return;
62 case chromeos::STATE_DUAL_MIRROR: { 62 case chromeos::STATE_DUAL_MIRROR: {
63 // Simply assumes that the primary display appears first and the 63 std::vector<std::string> display_names =
64 // secondary display appears next in the list. 64 display_manager->GetExternalDisplayNames();
65 std::vector<std::string> display_names; 65 string16 display_name = (!display_names.empty()) ?
Daniel Erat 2012/11/02 16:46:17 nit: remove extra parentheses around !display_name
Jun Mukai 2012/11/02 18:04:35 Done.
66 #if defined(USE_X11) 66 UTF8ToUTF16(display_names[0]) :
67 std::vector<XID> output_ids; 67 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
68 ui::GetOutputDeviceHandles(&output_ids); 68 label_->SetText(l10n_util::GetStringFUTF16(
69 display_names = ui::GetDisplayNames(output_ids); 69 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, display_name));
70 #endif 70 SetVisible(true);
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; 71 return;
80 } 72 }
81 case chromeos::STATE_DUAL_PRIMARY_ONLY: 73 case chromeos::STATE_DUAL_PRIMARY_ONLY:
82 case chromeos::STATE_DUAL_SECONDARY_ONLY: { 74 case chromeos::STATE_DUAL_SECONDARY_ONLY: {
83 aura::DisplayManager* display_manager = 75 string16 display_name = (display_manager->GetNumDisplays() > 1) ?
84 aura::Env::GetInstance()->display_manager(); 76 UTF8ToUTF16(display_manager->GetDisplayNameFor(
85 if (display_manager->GetNumDisplays() > 1) { 77 ScreenAsh::GetSecondaryDisplay())) :
86 label_->SetText(l10n_util::GetStringFUTF16( 78 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
87 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, 79 label_->SetText(l10n_util::GetStringFUTF16(
88 UTF8ToUTF16(display_manager->GetDisplayNameFor( 80 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, display_name));
89 ScreenAsh::GetSecondaryDisplay())))); 81 SetVisible(true);
90 SetVisible(true);
91 } else {
92 SetVisible(false);
93 }
94 return; 82 return;
95 } 83 }
96 default: 84 default:
97 NOTREACHED(); 85 NOTREACHED();
98 } 86 }
99 } 87 }
100 88
101 private: 89 private:
102 // Overridden from ActionableView. 90 // Overridden from ActionableView.
103 virtual bool PerformAction(const ui::Event& event) OVERRIDE { 91 virtual bool PerformAction(const ui::Event& event) OVERRIDE {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 default_->Update(); 139 default_->Update();
152 } 140 }
153 141
154 void TrayDisplay::OnDisplayModeChanged() { 142 void TrayDisplay::OnDisplayModeChanged() {
155 if (default_) 143 if (default_)
156 default_->Update(); 144 default_->Update();
157 } 145 }
158 146
159 } // namespace internal 147 } // namespace internal
160 } // namespace ash 148 } // namespace ash
OLDNEW
« ash/display/multi_display_manager.cc ('K') | « ash/display/multi_display_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698