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

Side by Side Diff: ash/system/status_area_widget.cc

Issue 10535112: Prepare status area to support multiple trays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 6 months 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/system/status_area_widget.h ('k') | ash/system/status_area_widget_delegate.h » ('j') | 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/status_area_widget.h" 5 #include "ash/system/status_area_widget.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h"
8 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/system/bluetooth/bluetooth_observer.h"
11 #include "ash/system/network/network_observer.h"
9 #include "ash/system/status_area_widget_delegate.h" 12 #include "ash/system/status_area_widget_delegate.h"
13 #include "ash/system/tray/system_tray.h"
14 #include "ash/system/tray/system_tray_delegate.h"
15 #include "base/i18n/time_formatting.h"
16 #include "base/utf_string_conversions.h"
10 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
11 18
12 namespace ash { 19 namespace ash {
20
21 namespace {
22
23 class DummySystemTrayDelegate : public SystemTrayDelegate {
24 public:
25 DummySystemTrayDelegate()
26 : muted_(false),
27 wifi_enabled_(true),
28 cellular_enabled_(true),
29 bluetooth_enabled_(true),
30 volume_(0.5),
31 caps_lock_enabled_(false) {
32 }
33
34 virtual ~DummySystemTrayDelegate() {}
35
36 private:
37 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { return true; }
38
39 // Overridden from SystemTrayDelegate:
40 virtual const string16 GetUserDisplayName() const OVERRIDE {
41 return UTF8ToUTF16("Über tray Über tray Über tray Über tray");
42 }
43
44 virtual const std::string GetUserEmail() const OVERRIDE {
45 return "über@tray";
46 }
47
48 virtual const gfx::ImageSkia& GetUserImage() const OVERRIDE {
49 return null_image_;
50 }
51
52 virtual user::LoginStatus GetUserLoginStatus() const OVERRIDE {
53 return user::LOGGED_IN_USER;
54 }
55
56 virtual bool SystemShouldUpgrade() const OVERRIDE {
57 return true;
58 }
59
60 virtual base::HourClockType GetHourClockType() const OVERRIDE {
61 return base::k24HourClock;
62 }
63
64 virtual PowerSupplyStatus GetPowerSupplyStatus() const OVERRIDE {
65 return PowerSupplyStatus();
66 }
67
68 virtual void RequestStatusUpdate() const OVERRIDE {
69 }
70
71 virtual void ShowSettings() OVERRIDE {
72 }
73
74 virtual void ShowDateSettings() OVERRIDE {
75 }
76
77 virtual void ShowNetworkSettings() OVERRIDE {
78 }
79
80 virtual void ShowBluetoothSettings() OVERRIDE {
81 }
82
83 virtual void ShowDriveSettings() OVERRIDE {
84 }
85
86 virtual void ShowIMESettings() OVERRIDE {
87 }
88
89 virtual void ShowHelp() OVERRIDE {
90 }
91
92 virtual bool IsAudioMuted() const OVERRIDE {
93 return muted_;
94 }
95
96 virtual void SetAudioMuted(bool muted) OVERRIDE {
97 muted_ = muted;
98 }
99
100 virtual float GetVolumeLevel() const OVERRIDE {
101 return volume_;
102 }
103
104 virtual void SetVolumeLevel(float volume) OVERRIDE {
105 volume_ = volume;
106 }
107
108 virtual bool IsCapsLockOn() const OVERRIDE {
109 return caps_lock_enabled_;
110 }
111
112 virtual void SetCapsLockEnabled(bool enabled) OVERRIDE {
113 caps_lock_enabled_ = enabled;
114 }
115
116 virtual bool IsInAccessibilityMode() const OVERRIDE {
117 return false;
118 }
119
120 virtual void SetEnableSpokenFeedback(bool enable) OVERRIDE {}
121
122 virtual void ShutDown() OVERRIDE {}
123
124 virtual void SignOut() OVERRIDE {
125 MessageLoop::current()->Quit();
126 }
127
128 virtual void RequestLockScreen() OVERRIDE {}
129
130 virtual void RequestRestart() OVERRIDE {}
131
132 virtual void GetAvailableBluetoothDevices(
133 BluetoothDeviceList* list) OVERRIDE {
134 }
135
136 virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE {
137 }
138
139 virtual void GetCurrentIME(IMEInfo* info) OVERRIDE {
140 }
141
142 virtual void GetAvailableIMEList(IMEInfoList* list) OVERRIDE {
143 }
144
145 virtual void GetCurrentIMEProperties(IMEPropertyInfoList* list) OVERRIDE {
146 }
147
148 virtual void SwitchIME(const std::string& ime_id) OVERRIDE {
149 }
150
151 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE {
152 }
153
154 virtual void CancelDriveOperation(const FilePath&) OVERRIDE {
155 }
156
157 virtual void GetDriveOperationStatusList(
158 ash::DriveOperationStatusList*) OVERRIDE {
159 }
160
161 virtual void GetMostRelevantNetworkIcon(NetworkIconInfo* info,
162 bool large) OVERRIDE {
163 }
164
165 virtual void GetAvailableNetworks(
166 std::vector<NetworkIconInfo>* list) OVERRIDE {
167 }
168
169 virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE {
170 }
171
172 virtual void GetNetworkAddresses(std::string* ip_address,
173 std::string* ethernet_mac_address,
174 std::string* wifi_mac_address) OVERRIDE {
175 *ip_address = "127.0.0.1";
176 *ethernet_mac_address = "00:11:22:33:44:55";
177 *wifi_mac_address = "66:77:88:99:00:11";
178 }
179
180 virtual void RequestNetworkScan() OVERRIDE {
181 }
182
183 virtual void AddBluetoothDevice() OVERRIDE {
184 }
185
186 virtual void ToggleAirplaneMode() OVERRIDE {
187 }
188
189 virtual void ToggleWifi() OVERRIDE {
190 wifi_enabled_ = !wifi_enabled_;
191 ash::NetworkObserver* observer =
192 ash::Shell::GetInstance()->system_tray()->network_observer();
193 if (observer) {
194 ash::NetworkIconInfo info;
195 observer->OnNetworkRefresh(info);
196 }
197 }
198
199 virtual void ToggleMobile() OVERRIDE {
200 cellular_enabled_ = !cellular_enabled_;
201 ash::NetworkObserver* observer =
202 ash::Shell::GetInstance()->system_tray()->network_observer();
203 if (observer) {
204 ash::NetworkIconInfo info;
205 observer->OnNetworkRefresh(info);
206 }
207 }
208
209 virtual void ToggleBluetooth() OVERRIDE {
210 bluetooth_enabled_ = !bluetooth_enabled_;
211 ash::BluetoothObserver* observer =
212 ash::Shell::GetInstance()->system_tray()->bluetooth_observer();
213 if (observer)
214 observer->OnBluetoothRefresh();
215 }
216
217 virtual void ShowOtherWifi() OVERRIDE {
218 }
219
220 virtual void ShowOtherCellular() OVERRIDE {
221 }
222
223 virtual bool IsNetworkConnected() OVERRIDE {
224 return true;
225 }
226
227 virtual bool GetWifiAvailable() OVERRIDE {
228 return true;
229 }
230
231 virtual bool GetMobileAvailable() OVERRIDE {
232 return true;
233 }
234
235 virtual bool GetBluetoothAvailable() OVERRIDE {
236 return true;
237 }
238
239 virtual bool GetWifiEnabled() OVERRIDE {
240 return wifi_enabled_;
241 }
242
243 virtual bool GetMobileEnabled() OVERRIDE {
244 return cellular_enabled_;
245 }
246
247 virtual bool GetBluetoothEnabled() OVERRIDE {
248 return bluetooth_enabled_;
249 }
250
251 virtual bool GetMobileScanSupported() OVERRIDE {
252 return true;
253 }
254
255 virtual bool GetCellularCarrierInfo(std::string* carrier_id,
256 std::string* topup_url,
257 std::string* setup_url) OVERRIDE {
258 return false;
259 }
260
261 virtual void ShowCellularURL(const std::string& url) OVERRIDE {
262 }
263
264 virtual void ChangeProxySettings() OVERRIDE {
265 }
266
267 bool muted_;
268 bool wifi_enabled_;
269 bool cellular_enabled_;
270 bool bluetooth_enabled_;
271 float volume_;
272 bool caps_lock_enabled_;
273 gfx::ImageSkia null_image_;
274
275 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate);
276 };
277
278 } // namespace
279
13 namespace internal { 280 namespace internal {
14 281
15 StatusAreaWidget::StatusAreaWidget() { 282 StatusAreaWidget::StatusAreaWidget()
16 widget_delegate_ = new internal::StatusAreaWidgetDelegate; 283 : widget_delegate_(new internal::StatusAreaWidgetDelegate),
17 284 system_tray_(NULL) {
18 views::Widget::InitParams params( 285 views::Widget::InitParams params(
19 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 286 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
20 params.delegate = widget_delegate_; 287 params.delegate = widget_delegate_;
21 params.parent = Shell::GetContainer( 288 params.parent = Shell::GetContainer(
22 Shell::GetPrimaryRootWindow(), 289 Shell::GetPrimaryRootWindow(),
23 ash::internal::kShellWindowId_StatusContainer); 290 ash::internal::kShellWindowId_StatusContainer);
24 params.transparent = true; 291 params.transparent = true;
25 Init(params); 292 Init(params);
26 set_focus_on_creation(false); 293 set_focus_on_creation(false);
27 SetContentsView(widget_delegate_); 294 SetContentsView(widget_delegate_);
28 GetNativeView()->SetName("StatusAreaWidget"); 295 GetNativeView()->SetName("StatusAreaWidget");
29 } 296 }
30 297
31 StatusAreaWidget::~StatusAreaWidget() { 298 StatusAreaWidget::~StatusAreaWidget() {
32 } 299 }
33 300
34 void StatusAreaWidget::AddTray(views::View* tray) { 301 void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) {
35 widget_delegate_->AddChildView(tray); 302 AddSystemTray(new SystemTray(), shell_delegate);
36 widget_delegate_->Layout(); 303 }
304
305 void StatusAreaWidget::Shutdown() {
306 // Destroy the trays early, causing them to be removed from the view
307 // hierarchy. Do not used scoped pointers since we don't want to destroy them
308 // in the destructor if Shutdown() is not called (e.g. in tests).
309 delete system_tray_;
310 system_tray_ = NULL;
311 }
312
313 void StatusAreaWidget::AddSystemTray(SystemTray* system_tray,
314 ShellDelegate* shell_delegate) {
315 system_tray_ = system_tray;
316 widget_delegate_->AddTray(system_tray);
317 system_tray_->Initialize(); // Called after added to widget.
318
319 if (shell_delegate) {
320 system_tray_delegate_.reset(
321 shell_delegate->CreateSystemTrayDelegate(system_tray));
322 }
323 if (!system_tray_delegate_.get())
324 system_tray_delegate_.reset(new DummySystemTrayDelegate());
325
326 system_tray->CreateItems(); // Called after delegate is created.
37 } 327 }
38 328
39 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { 329 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
40 if (alignment == SHELF_ALIGNMENT_BOTTOM) 330 widget_delegate_->set_alignment(alignment);
41 widget_delegate_->SetLayout(views::BoxLayout::kHorizontal); 331 widget_delegate_->UpdateLayout();
42 else
43 widget_delegate_->SetLayout(views::BoxLayout::kVertical);
44 } 332 }
45 333
46 } // namespace internal 334 } // namespace internal
47 } // namespace ash 335 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/status_area_widget.h ('k') | ash/system/status_area_widget_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698