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/tray/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell/panel_window.h" | 9 #include "ash/shell/panel_window.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ash/system/audio/tray_volume.h" | 11 #include "ash/system/audio/tray_volume.h" |
12 #include "ash/system/bluetooth/tray_bluetooth.h" | 12 #include "ash/system/bluetooth/tray_bluetooth.h" |
13 #include "ash/system/brightness/tray_brightness.h" | 13 #include "ash/system/brightness/tray_brightness.h" |
14 #include "ash/system/chromeos/tray_display.h" | 14 #include "ash/system/chromeos/tray_display.h" |
15 #include "ash/system/date/tray_date.h" | 15 #include "ash/system/date/tray_date.h" |
16 #include "ash/system/drive/tray_drive.h" | 16 #include "ash/system/drive/tray_drive.h" |
17 #include "ash/system/ime/tray_ime.h" | 17 #include "ash/system/ime/tray_ime.h" |
18 #include "ash/system/locale/tray_locale.h" | 18 #include "ash/system/locale/tray_locale.h" |
19 #include "ash/system/logout_button/tray_logout_button.h" | 19 #include "ash/system/logout_button/tray_logout_button.h" |
20 #include "ash/system/monitor/tray_monitor.h" | 20 #include "ash/system/monitor/tray_monitor.h" |
21 #include "ash/system/power/power_status_observer.h" | |
22 #include "ash/system/power/power_supply_status.h" | 21 #include "ash/system/power/power_supply_status.h" |
23 #include "ash/system/power/tray_power.h" | 22 #include "ash/system/power/tray_power.h" |
24 #include "ash/system/settings/tray_settings.h" | 23 #include "ash/system/settings/tray_settings.h" |
25 #include "ash/system/status_area_widget.h" | 24 #include "ash/system/status_area_widget.h" |
26 #include "ash/system/tray/system_tray_delegate.h" | 25 #include "ash/system/tray/system_tray_delegate.h" |
| 26 #include "ash/system/tray/system_tray_notifier.h" |
27 #include "ash/system/tray/system_tray_item.h" | 27 #include "ash/system/tray/system_tray_item.h" |
28 #include "ash/system/tray/tray_bubble_wrapper.h" | 28 #include "ash/system/tray/tray_bubble_wrapper.h" |
29 #include "ash/system/tray/tray_constants.h" | 29 #include "ash/system/tray/tray_constants.h" |
30 #include "ash/system/tray_accessibility.h" | 30 #include "ash/system/tray_accessibility.h" |
31 #include "ash/system/tray_caps_lock.h" | 31 #include "ash/system/tray_caps_lock.h" |
32 #include "ash/system/tray_update.h" | 32 #include "ash/system/tray_update.h" |
33 #include "ash/system/user/login_status.h" | 33 #include "ash/system/user/login_status.h" |
34 #include "ash/system/user/tray_user.h" | 34 #include "ash/system/user/tray_user.h" |
35 #include "ash/wm/shelf_layout_manager.h" | 35 #include "ash/wm/shelf_layout_manager.h" |
36 #include "base/command_line.h" | 36 #include "base/command_line.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 } // namespace internal | 101 } // namespace internal |
102 | 102 |
103 // SystemTray | 103 // SystemTray |
104 | 104 |
105 using internal::SystemTrayBubble; | 105 using internal::SystemTrayBubble; |
106 | 106 |
107 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) | 107 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) |
108 : internal::TrayBackgroundView(status_area_widget), | 108 : internal::TrayBackgroundView(status_area_widget), |
109 items_(), | 109 items_(), |
110 accessibility_observer_(NULL), | |
111 audio_observer_(NULL), | |
112 bluetooth_observer_(NULL), | |
113 brightness_observer_(NULL), | |
114 caps_lock_observer_(NULL), | |
115 clock_observer_(NULL), | |
116 drive_observer_(NULL), | |
117 ime_observer_(NULL), | |
118 locale_observer_(NULL), | |
119 logout_button_observer_(NULL), | |
120 #if defined(OS_CHROMEOS) | |
121 network_observer_(NULL), | |
122 vpn_observer_(NULL), | |
123 sms_observer_(NULL), | |
124 #endif | |
125 update_observer_(NULL), | |
126 user_observer_(NULL), | |
127 default_bubble_height_(0), | 110 default_bubble_height_(0), |
128 hide_notifications_(false) { | 111 hide_notifications_(false) { |
129 SetContentsBackground(); | 112 SetContentsBackground(); |
130 } | 113 } |
131 | 114 |
132 SystemTray::~SystemTray() { | 115 SystemTray::~SystemTray() { |
133 // Destroy any child views that might have back pointers before ~View(). | 116 // Destroy any child views that might have back pointers before ~View(). |
134 system_bubble_.reset(); | 117 system_bubble_.reset(); |
135 notification_bubble_.reset(); | 118 notification_bubble_.reset(); |
136 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 119 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
137 it != items_.end(); | 120 it != items_.end(); |
138 ++it) { | 121 ++it) { |
139 (*it)->DestroyTrayView(); | 122 (*it)->DestroyTrayView(); |
140 } | 123 } |
141 } | 124 } |
142 | 125 |
143 void SystemTray::CreateItems() { | 126 void SystemTray::InitializeTrayItems(SystemTrayDelegate* delegate) { |
| 127 internal::TrayBackgroundView::Initialize(); |
| 128 CreateItems(delegate); |
| 129 } |
| 130 |
| 131 void SystemTray::CreateItems(SystemTrayDelegate* delegate) { |
144 internal::TrayVolume* tray_volume = new internal::TrayVolume(); | 132 internal::TrayVolume* tray_volume = new internal::TrayVolume(); |
145 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); | 133 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); |
146 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); | 134 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); |
147 internal::TrayDate* tray_date = new internal::TrayDate(); | 135 internal::TrayDate* tray_date = new internal::TrayDate(); |
148 internal::TrayPower* tray_power = new internal::TrayPower(); | 136 internal::TrayPower* tray_power = new internal::TrayPower(); |
149 internal::TrayIME* tray_ime = new internal::TrayIME; | 137 internal::TrayIME* tray_ime = new internal::TrayIME(); |
150 internal::TrayUser* tray_user = new internal::TrayUser; | 138 internal::TrayUser* tray_user = new internal::TrayUser(); |
151 internal::TrayAccessibility* tray_accessibility = | 139 internal::TrayAccessibility* tray_accessibility = |
152 new internal::TrayAccessibility; | 140 new internal::TrayAccessibility(); |
153 internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock; | 141 internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock(); |
154 internal::TrayDrive* tray_drive = new internal::TrayDrive; | 142 internal::TrayDrive* tray_drive = new internal::TrayDrive(); |
155 internal::TrayLocale* tray_locale = new internal::TrayLocale; | 143 internal::TrayLocale* tray_locale = new internal::TrayLocale(); |
156 internal::TrayLogoutButton* tray_logout_button = | 144 internal::TrayLogoutButton* tray_logout_button = |
157 new internal::TrayLogoutButton(); | 145 new internal::TrayLogoutButton(); |
158 internal::TrayUpdate* tray_update = new internal::TrayUpdate; | 146 internal::TrayUpdate* tray_update = new internal::TrayUpdate(); |
159 internal::TraySettings* tray_settings = new internal::TraySettings(); | 147 internal::TraySettings* tray_settings = new internal::TraySettings(); |
| 148 #if defined(OS_CHROMEOS) |
| 149 internal::TrayDisplay* tray_display = new internal::TrayDisplay(); |
| 150 internal::TrayNetwork* tray_network = new internal::TrayNetwork(); |
| 151 internal::TrayVPN* tray_vpn = new internal::TrayVPN(); |
| 152 internal::TraySms* tray_sms = new internal::TraySms(); |
| 153 #endif |
160 | 154 |
161 accessibility_observer_ = tray_accessibility; | 155 SystemTrayNotifier* notifier = Shell::GetInstance()->system_tray_notifier(); |
162 audio_observer_ = tray_volume; | 156 notifier->AddAccessibilityObserver(tray_accessibility); |
163 bluetooth_observer_ = tray_bluetooth; | 157 notifier->AddAudioObserver(tray_volume); |
164 brightness_observer_ = tray_brightness; | 158 notifier->AddBluetoothObserver(tray_bluetooth); |
165 caps_lock_observer_ = tray_caps_lock; | 159 notifier->AddBrightnessObserver(tray_brightness); |
166 clock_observer_ = tray_date; | 160 notifier->AddCapsLockObserver(tray_caps_lock); |
167 drive_observer_ = tray_drive; | 161 notifier->AddClockObserver(tray_date); |
168 ime_observer_ = tray_ime; | 162 notifier->AddDriveObserver(tray_drive); |
169 locale_observer_ = tray_locale; | 163 notifier->AddIMEObserver(tray_ime); |
170 logout_button_observer_ = tray_logout_button; | 164 notifier->AddLocaleObserver(tray_locale); |
171 power_status_observers_.AddObserver(tray_power); | 165 notifier->AddLogoutButtonObserver(tray_logout_button); |
172 power_status_observers_.AddObserver(tray_settings); | 166 notifier->AddPowerStatusObserver(tray_power); |
173 update_observer_ = tray_update; | 167 notifier->AddPowerStatusObserver(tray_settings); |
174 user_observer_ = tray_user; | 168 notifier->AddUpdateObserver(tray_update); |
175 | 169 notifier->AddUserObserver(tray_user); |
176 #if defined(OS_CHROMEOS) | 170 #if defined(OS_CHROMEOS) |
177 internal::TrayDisplay* tray_display = new internal::TrayDisplay; | 171 notifier->AddNetworkObserver(tray_network); |
178 internal::TrayNetwork* tray_network = new internal::TrayNetwork; | 172 notifier->AddVpnObserver(tray_vpn); |
179 internal::TrayVPN* tray_vpn = new internal::TrayVPN; | 173 notifier->AddSmsObserver(tray_sms); |
180 internal::TraySms* tray_sms = new internal::TraySms(); | |
181 network_observer_ = tray_network; | |
182 vpn_observer_ = tray_vpn; | |
183 sms_observer_ = tray_sms; | |
184 #endif | 174 #endif |
185 | 175 |
186 AddTrayItem(tray_logout_button); | 176 AddTrayItem(tray_logout_button); |
187 AddTrayItem(tray_user); | 177 AddTrayItem(tray_user); |
188 AddTrayItem(tray_ime); | 178 AddTrayItem(tray_ime); |
189 AddTrayItem(tray_power); | 179 AddTrayItem(tray_power); |
190 #if defined(OS_CHROMEOS) | 180 #if defined(OS_CHROMEOS) |
191 AddTrayItem(tray_network); | 181 AddTrayItem(tray_network); |
192 AddTrayItem(tray_vpn); | 182 AddTrayItem(tray_vpn); |
193 AddTrayItem(tray_sms); | 183 AddTrayItem(tray_sms); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // It is possible that none of the items generated actual notifications. | 481 // It is possible that none of the items generated actual notifications. |
492 DestroyNotificationBubble(); | 482 DestroyNotificationBubble(); |
493 return; | 483 return; |
494 } | 484 } |
495 if (hide_notifications_) | 485 if (hide_notifications_) |
496 notification_bubble->SetVisible(false); | 486 notification_bubble->SetVisible(false); |
497 else | 487 else |
498 status_area_widget()->SetHideWebNotifications(true); | 488 status_area_widget()->SetHideWebNotifications(true); |
499 } | 489 } |
500 | 490 |
501 void SystemTray::Initialize() { | |
502 internal::TrayBackgroundView::Initialize(); | |
503 CreateItems(); | |
504 } | |
505 | |
506 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { | 491 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
507 if (alignment == shelf_alignment()) | 492 if (alignment == shelf_alignment()) |
508 return; | 493 return; |
509 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 494 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
510 UpdateAfterShelfAlignmentChange(alignment); | 495 UpdateAfterShelfAlignmentChange(alignment); |
511 // Destroy any existing bubble so that it is rebuilt correctly. | 496 // Destroy any existing bubble so that it is rebuilt correctly. |
512 system_bubble_.reset(); | 497 system_bubble_.reset(); |
513 // Rebuild any notification bubble. | 498 // Rebuild any notification bubble. |
514 if (notification_bubble_.get()) { | 499 if (notification_bubble_.get()) { |
515 notification_bubble_.reset(); | 500 notification_bubble_.reset(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 ConvertPointToWidget(this, &point); | 584 ConvertPointToWidget(this, &point); |
600 arrow_offset = point.x(); | 585 arrow_offset = point.x(); |
601 } | 586 } |
602 } | 587 } |
603 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 588 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
604 } | 589 } |
605 return true; | 590 return true; |
606 } | 591 } |
607 | 592 |
608 } // namespace ash | 593 } // namespace ash |
OLD | NEW |