OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/tray_display.h" | |
6 | |
7 #include "ash/display/display_controller.h" | |
8 #include "ash/screen_ash.h" | |
9 #include "ash/shell.h" | |
10 #include "ash/system/tray/system_tray.h" | |
11 #include "ash/system/tray/system_tray_delegate.h" | |
12 #include "ash/system/tray/tray_constants.h" | |
13 #include "ash/system/tray/tray_views.h" | |
14 #include "base/utf_string_conversions.h" | |
15 #include "grit/ash_resources.h" | |
16 #include "grit/ash_strings.h" | |
17 #include "ui/aura/display_manager.h" | |
18 #include "ui/aura/env.h" | |
19 #include "ui/base/l10n/l10n_util.h" | |
20 #include "ui/base/resource/resource_bundle.h" | |
21 #include "ui/gfx/image/image.h" | |
22 #include "ui/views/controls/image_view.h" | |
23 #include "ui/views/controls/label.h" | |
24 #include "ui/views/layout/box_layout.h" | |
25 | |
26 #if defined(USE_X11) | |
27 #include "ui/base/x/x11_util.h" | |
28 #endif | |
29 | |
30 namespace ash { | |
31 namespace internal { | |
32 | |
33 class DisplayView : public ash::internal::ActionableView { | |
34 public: | |
35 explicit DisplayView(user::LoginStatus login_status) | |
36 : login_status_(login_status) { | |
37 SetLayoutManager(new | |
38 views::BoxLayout(views::BoxLayout::kHorizontal, | |
39 ash::kTrayPopupPaddingHorizontal, 0, | |
40 ash::kTrayPopupPaddingBetweenItems)); | |
41 | |
42 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
43 views::ImageView* image = | |
44 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); | |
45 image->SetImage( | |
46 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); | |
47 AddChildView(image); | |
48 label_ = new views::Label(); | |
49 AddChildView(label_); | |
50 Update(); | |
51 } | |
52 | |
53 virtual ~DisplayView() {} | |
54 | |
55 void Update() { | |
56 #if defined(OS_CHROMEOS) | |
57 switch (Shell::GetInstance()->output_configurator()->output_state()) { | |
58 case chromeos::STATE_INVALID: | |
59 case chromeos::STATE_HEADLESS: | |
60 case chromeos::STATE_SINGLE: | |
61 SetVisible(false); | |
62 return; | |
63 case chromeos::STATE_DUAL_MIRROR: { | |
64 // Simply assumes that the primary display appears first and the | |
65 // secondary display appears next in the list. | |
66 std::vector<std::string> display_names; | |
67 #if defined(USE_X11) | |
68 std::vector<XID> output_ids; | |
69 ui::GetOutputDeviceHandles(&output_ids); | |
70 display_names = ui::GetDisplayNames(output_ids); | |
71 #endif | |
72 if (display_names.size() > 1) { | |
73 label_->SetText(l10n_util::GetStringFUTF16( | |
74 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
75 UTF8ToUTF16(display_names[1]))); | |
76 SetVisible(true); | |
77 } else { | |
78 SetVisible(false); | |
79 } | |
80 return; | |
81 } | |
82 case chromeos::STATE_DUAL_PRIMARY_ONLY: | |
83 case chromeos::STATE_DUAL_SECONDARY_ONLY: { | |
84 aura::DisplayManager* display_manager = | |
85 aura::Env::GetInstance()->display_manager(); | |
86 if (display_manager->GetNumDisplays() > 1) { | |
87 label_->SetText(l10n_util::GetStringFUTF16( | |
88 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
89 UTF8ToUTF16(display_manager->GetDisplayNameFor( | |
90 ScreenAsh::GetSecondaryDisplay())))); | |
91 SetVisible(true); | |
92 } else { | |
93 SetVisible(false); | |
94 } | |
95 return; | |
96 } | |
97 default: | |
98 NOTREACHED(); | |
99 } | |
100 #endif // OS_CHROMEOS | |
101 } | |
102 | |
103 private: | |
104 // Overridden from ActionableView. | |
105 virtual bool PerformAction(const ui::Event& event) OVERRIDE { | |
106 if (login_status_ == ash::user::LOGGED_IN_USER || | |
107 login_status_ == ash::user::LOGGED_IN_OWNER || | |
108 login_status_ == ash::user::LOGGED_IN_GUEST) { | |
109 ash::Shell::GetInstance()->tray_delegate()->ShowDisplaySettings(); | |
110 } | |
111 | |
112 return true; | |
113 } | |
114 | |
115 user::LoginStatus login_status_; | |
116 views::Label* label_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(DisplayView); | |
119 }; | |
120 | |
121 TrayDisplay::TrayDisplay() | |
122 : default_(NULL) { | |
123 aura::Env::GetInstance()->display_manager()->AddObserver(this); | |
124 #if defined(OS_CHROMEOS) | |
125 ash::Shell::GetInstance()->output_configurator()->AddObserver(this); | |
126 #endif | |
127 } | |
128 | |
129 TrayDisplay::~TrayDisplay() { | |
130 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); | |
131 #if defined(OS_CHROMEOS) | |
132 ash::Shell::GetInstance()->output_configurator()->RemoveObserver(this); | |
133 #endif | |
134 } | |
135 | |
136 views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { | |
137 #if defined(OS_CHROMEOS) | |
138 default_ = new DisplayView(status); | |
139 #endif | |
140 return default_; | |
141 } | |
142 | |
143 void TrayDisplay::DestroyDefaultView() { | |
144 default_ = NULL; | |
145 } | |
146 | |
147 void TrayDisplay::OnDisplayBoundsChanged(const gfx::Display& display) { | |
148 if (default_) | |
149 default_->Update(); | |
150 } | |
151 | |
152 void TrayDisplay::OnDisplayAdded(const gfx::Display& new_display) { | |
153 if (default_) | |
154 default_->Update(); | |
155 } | |
156 | |
157 void TrayDisplay::OnDisplayRemoved(const gfx::Display& old_display) { | |
158 if (default_) | |
159 default_->Update(); | |
160 } | |
161 | |
162 #if defined(OS_CHROMEOS) | |
163 void TrayDisplay::OnDisplayModeChanged() { | |
164 if (default_) | |
165 default_->Update(); | |
166 } | |
167 #endif | |
168 | |
169 | |
170 } // namespace internal | |
171 } // namespace ash | |
OLD | NEW |