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

Side by Side Diff: ash/system/bluetooth/tray_bluetooth.cc

Issue 11415014: Stop using shell::GetInstance()->system_tray() in system tray items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified CL to provide TrayItems and Tray*Views with parent pointers instead. 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/bluetooth/tray_bluetooth.h" 5 #include "ash/system/bluetooth/tray_bluetooth.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray.h" 8 #include "ash/system/tray/system_tray.h"
9 #include "ash/system/tray/system_tray_delegate.h" 9 #include "ash/system/tray/system_tray_delegate.h"
10 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
(...skipping 13 matching lines...) Expand all
24 const int kDeviceListHeight = 276; 24 const int kDeviceListHeight = 276;
25 } 25 }
26 26
27 namespace ash { 27 namespace ash {
28 namespace internal { 28 namespace internal {
29 29
30 namespace tray { 30 namespace tray {
31 31
32 class BluetoothDefaultView : public TrayItemMore { 32 class BluetoothDefaultView : public TrayItemMore {
33 public: 33 public:
34 explicit BluetoothDefaultView(SystemTrayItem* owner) 34 explicit BluetoothDefaultView(SystemTrayItem* tray)
bartfab (slow) 2012/11/16 15:01:35 I renamed |owner| to |tray| here and elsewhere for
stevenjb 2012/11/16 17:41:43 Actually, sorry to push back on this, but "tray" i
bartfab (slow) 2012/11/16 18:45:34 I picked |tray| over |owner| because it seems to h
35 : TrayItemMore(owner, true) { 35 : TrayItemMore(tray, true) {
36 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 36 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
37 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); 37 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia());
38 UpdateLabel(); 38 UpdateLabel();
39 } 39 }
40 40
41 virtual ~BluetoothDefaultView() {} 41 virtual ~BluetoothDefaultView() {}
42 42
43 void UpdateLabel() { 43 void UpdateLabel() {
44 ash::SystemTrayDelegate* delegate = 44 ash::SystemTrayDelegate* delegate =
45 ash::Shell::GetInstance()->tray_delegate(); 45 ash::Shell::GetInstance()->tray_delegate();
46 if (delegate->GetBluetoothAvailable()) { 46 if (delegate->GetBluetoothAvailable()) {
47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
48 SetLabel(rb.GetLocalizedString(delegate->GetBluetoothEnabled() ? 48 SetLabel(rb.GetLocalizedString(delegate->GetBluetoothEnabled() ?
49 IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED : 49 IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED :
50 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED)); 50 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED));
51 SetVisible(true); 51 SetVisible(true);
52 } else { 52 } else {
53 SetVisible(false); 53 SetVisible(false);
54 } 54 }
55 } 55 }
56 56
57 private: 57 private:
58 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); 58 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView);
59 }; 59 };
60 60
61 class BluetoothDetailedView : public TrayDetailsView, 61 class BluetoothDetailedView : public TrayDetailsView,
62 public ViewClickListener, 62 public ViewClickListener,
63 public views::ButtonListener { 63 public views::ButtonListener {
64 public: 64 public:
65 explicit BluetoothDetailedView(user::LoginStatus login) 65 BluetoothDetailedView(SystemTrayItem* tray, user::LoginStatus login)
66 : login_(login), 66 : TrayDetailsView(tray),
67 login_(login),
67 add_device_(NULL), 68 add_device_(NULL),
68 toggle_bluetooth_(NULL) { 69 toggle_bluetooth_(NULL) {
69 BluetoothDeviceList list; 70 BluetoothDeviceList list;
70 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); 71 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list);
71 Update(list); 72 Update(list);
72 } 73 }
73 74
74 virtual ~BluetoothDetailedView() {} 75 virtual ~BluetoothDetailedView() {}
75 76
76 void Update(const BluetoothDeviceList& list) { 77 void Update(const BluetoothDeviceList& list) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 container->SetEnabled(delegate->GetBluetoothAvailable()); 169 container->SetEnabled(delegate->GetBluetoothAvailable());
169 AddChildView(container); 170 AddChildView(container);
170 add_device_ = container; 171 add_device_ = container;
171 } 172 }
172 173
173 // Overridden from ViewClickListener. 174 // Overridden from ViewClickListener.
174 virtual void ClickedOn(views::View* sender) OVERRIDE { 175 virtual void ClickedOn(views::View* sender) OVERRIDE {
175 ash::SystemTrayDelegate* delegate = 176 ash::SystemTrayDelegate* delegate =
176 ash::Shell::GetInstance()->tray_delegate(); 177 ash::Shell::GetInstance()->tray_delegate();
177 if (sender == footer()->content()) { 178 if (sender == footer()->content()) {
178 Shell::GetInstance()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); 179 tray()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
179 } else if (sender == add_device_) { 180 } else if (sender == add_device_) {
180 if (!delegate->GetBluetoothEnabled()) 181 if (!delegate->GetBluetoothEnabled())
181 delegate->ToggleBluetooth(); 182 delegate->ToggleBluetooth();
182 delegate->AddBluetoothDevice(); 183 delegate->AddBluetoothDevice();
183 } else { 184 } else {
184 std::map<views::View*, std::string>::iterator find; 185 std::map<views::View*, std::string>::iterator find;
185 find = device_map_.find(sender); 186 find = device_map_.find(sender);
186 if (find != device_map_.end()) { 187 if (find != device_map_.end()) {
187 std::string device_id = find->second; 188 std::string device_id = find->second;
188 delegate->ToggleBluetoothConnection(device_id); 189 delegate->ToggleBluetoothConnection(device_id);
(...skipping 17 matching lines...) Expand all
206 std::map<views::View*, std::string> device_map_; 207 std::map<views::View*, std::string> device_map_;
207 views::View* add_device_; 208 views::View* add_device_;
208 TrayPopupHeaderButton* toggle_bluetooth_; 209 TrayPopupHeaderButton* toggle_bluetooth_;
209 views::View* settings_; 210 views::View* settings_;
210 211
211 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); 212 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
212 }; 213 };
213 214
214 } // namespace tray 215 } // namespace tray
215 216
216 TrayBluetooth::TrayBluetooth() 217 TrayBluetooth::TrayBluetooth(SystemTray* system_tray)
217 : default_(NULL), 218 : SystemTrayItem(system_tray),
219 default_(NULL),
218 detailed_(NULL) { 220 detailed_(NULL) {
219 } 221 }
220 222
221 TrayBluetooth::~TrayBluetooth() { 223 TrayBluetooth::~TrayBluetooth() {
222 } 224 }
223 225
224 views::View* TrayBluetooth::CreateTrayView(user::LoginStatus status) { 226 views::View* TrayBluetooth::CreateTrayView(user::LoginStatus status) {
225 return NULL; 227 return NULL;
226 } 228 }
227 229
228 views::View* TrayBluetooth::CreateDefaultView(user::LoginStatus status) { 230 views::View* TrayBluetooth::CreateDefaultView(user::LoginStatus status) {
229 CHECK(default_ == NULL); 231 CHECK(default_ == NULL);
230 default_ = new tray::BluetoothDefaultView(this); 232 default_ = new tray::BluetoothDefaultView(this);
231 return default_; 233 return default_;
232 } 234 }
233 235
234 views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) { 236 views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) {
235 if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable()) 237 if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable())
236 return NULL; 238 return NULL;
237 CHECK(detailed_ == NULL); 239 CHECK(detailed_ == NULL);
238 detailed_ = new tray::BluetoothDetailedView(status); 240 detailed_ = new tray::BluetoothDetailedView(this, status);
239 return detailed_; 241 return detailed_;
240 } 242 }
241 243
242 void TrayBluetooth::DestroyTrayView() { 244 void TrayBluetooth::DestroyTrayView() {
243 } 245 }
244 246
245 void TrayBluetooth::DestroyDefaultView() { 247 void TrayBluetooth::DestroyDefaultView() {
246 default_ = NULL; 248 default_ = NULL;
247 } 249 }
248 250
(...skipping 16 matching lines...) Expand all
265 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 267 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
266 if (!detailed_) 268 if (!detailed_)
267 return; 269 return;
268 BluetoothDeviceList list; 270 BluetoothDeviceList list;
269 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); 271 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list);
270 detailed_->Update(list); 272 detailed_->Update(list);
271 } 273 }
272 274
273 } // namespace internal 275 } // namespace internal
274 } // namespace ash 276 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698