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

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

Issue 2761063002: Move more from WmShell to Shell (Closed)
Patch Set: cleanup Created 3 years, 9 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
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/common/system/chromeos/bluetooth/tray_bluetooth.h" 5 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h"
6 6
7 #include "ash/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/system/tray/hover_highlight_view.h" 8 #include "ash/common/system/tray/hover_highlight_view.h"
9 #include "ash/common/system/tray/system_tray.h" 9 #include "ash/common/system/tray/system_tray.h"
10 #include "ash/common/system/tray/system_tray_delegate.h" 10 #include "ash/common/system/tray/system_tray_delegate.h"
11 #include "ash/common/system/tray/system_tray_notifier.h" 11 #include "ash/common/system/tray/system_tray_notifier.h"
12 #include "ash/common/system/tray/throbber_view.h" 12 #include "ash/common/system/tray/throbber_view.h"
13 #include "ash/common/system/tray/tray_constants.h" 13 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_details_view.h" 14 #include "ash/common/system/tray/tray_details_view.h"
15 #include "ash/common/system/tray/tray_item_more.h" 15 #include "ash/common/system/tray/tray_item_more.h"
16 #include "ash/common/system/tray/tray_popup_item_style.h" 16 #include "ash/common/system/tray/tray_popup_item_style.h"
17 #include "ash/common/system/tray/tray_popup_utils.h" 17 #include "ash/common/system/tray/tray_popup_utils.h"
18 #include "ash/common/system/tray/tri_view.h" 18 #include "ash/common/system/tray/tri_view.h"
19 #include "ash/common/wm_shell.h" 19 #include "ash/common/wm_shell.h"
20 #include "ash/resources/grit/ash_resources.h" 20 #include "ash/resources/grit/ash_resources.h"
21 #include "ash/resources/vector_icons/vector_icons.h" 21 #include "ash/resources/vector_icons/vector_icons.h"
22 #include "ash/shell.h"
22 #include "ash/strings/grit/ash_strings.h" 23 #include "ash/strings/grit/ash_strings.h"
23 #include "device/bluetooth/bluetooth_common.h" 24 #include "device/bluetooth/bluetooth_common.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/color_palette.h" 27 #include "ui/gfx/color_palette.h"
27 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
28 #include "ui/gfx/paint_vector_icon.h" 29 #include "ui/gfx/paint_vector_icon.h"
29 #include "ui/views/controls/button/toggle_button.h" 30 #include "ui/views/controls/button/toggle_button.h"
30 #include "ui/views/controls/image_view.h" 31 #include "ui/views/controls/image_view.h"
31 #include "ui/views/controls/label.h" 32 #include "ui/views/controls/label.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const int kDisabledPanelLabelBaselineY = 20; 109 const int kDisabledPanelLabelBaselineY = 20;
109 110
110 } // namespace 111 } // namespace
111 112
112 class BluetoothDefaultView : public TrayItemMore { 113 class BluetoothDefaultView : public TrayItemMore {
113 public: 114 public:
114 explicit BluetoothDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {} 115 explicit BluetoothDefaultView(SystemTrayItem* owner) : TrayItemMore(owner) {}
115 ~BluetoothDefaultView() override {} 116 ~BluetoothDefaultView() override {}
116 117
117 void Update() { 118 void Update() {
118 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 119 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
119 const bool enabled = delegate->GetBluetoothEnabled(); 120 const bool enabled = delegate->GetBluetoothEnabled();
120 if (delegate->GetBluetoothAvailable()) { 121 if (delegate->GetBluetoothAvailable()) {
121 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
122 const base::string16 label = rb.GetLocalizedString( 123 const base::string16 label = rb.GetLocalizedString(
123 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED 124 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED
124 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED); 125 : IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED);
125 SetLabel(label); 126 SetLabel(label);
126 SetAccessibleName(label); 127 SetAccessibleName(label);
127 SetVisible(true); 128 SetVisible(true);
128 } else { 129 } else {
129 SetVisible(false); 130 SetVisible(false);
130 } 131 }
131 UpdateStyle(); 132 UpdateStyle();
132 } 133 }
133 134
134 protected: 135 protected:
135 // TrayItemMore: 136 // TrayItemMore:
136 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override { 137 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override {
137 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 138 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
138 std::unique_ptr<TrayPopupItemStyle> style = 139 std::unique_ptr<TrayPopupItemStyle> style =
139 TrayItemMore::HandleCreateStyle(); 140 TrayItemMore::HandleCreateStyle();
140 style->set_color_style( 141 style->set_color_style(
141 delegate->GetBluetoothEnabled() 142 delegate->GetBluetoothEnabled()
142 ? TrayPopupItemStyle::ColorStyle::ACTIVE 143 ? TrayPopupItemStyle::ColorStyle::ACTIVE
143 : delegate->GetBluetoothAvailable() 144 : delegate->GetBluetoothAvailable()
144 ? TrayPopupItemStyle::ColorStyle::INACTIVE 145 ? TrayPopupItemStyle::ColorStyle::INACTIVE
145 : TrayPopupItemStyle::ColorStyle::DISABLED); 146 : TrayPopupItemStyle::ColorStyle::DISABLED);
146 147
147 return style; 148 return style;
148 } 149 }
149 150
150 void UpdateStyle() override { 151 void UpdateStyle() override {
151 TrayItemMore::UpdateStyle(); 152 TrayItemMore::UpdateStyle();
152 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); 153 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle();
153 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor())); 154 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor()));
154 } 155 }
155 156
156 private: 157 private:
157 const gfx::VectorIcon& GetCurrentIcon() { 158 const gfx::VectorIcon& GetCurrentIcon() {
158 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 159 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
159 if (!delegate->GetBluetoothEnabled()) 160 if (!delegate->GetBluetoothEnabled())
160 return kSystemMenuBluetoothDisabledIcon; 161 return kSystemMenuBluetoothDisabledIcon;
161 162
162 bool has_connected_device = false; 163 bool has_connected_device = false;
163 BluetoothDeviceList list; 164 BluetoothDeviceList list;
164 delegate->GetAvailableBluetoothDevices(&list); 165 delegate->GetAvailableBluetoothDevices(&list);
165 for (size_t i = 0; i < list.size(); ++i) { 166 for (size_t i = 0; i < list.size(); ++i) {
166 if (list[i].connected) { 167 if (list[i].connected) {
167 has_connected_device = true; 168 has_connected_device = true;
168 break; 169 break;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 Layout(); 202 Layout();
202 } 203 }
203 204
204 private: 205 private:
205 void CreateItems() { 206 void CreateItems() {
206 CreateScrollableList(); 207 CreateScrollableList();
207 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); 208 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH);
208 } 209 }
209 210
210 void BluetoothStartDiscovering() { 211 void BluetoothStartDiscovering() {
211 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 212 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
212 if (delegate->GetBluetoothDiscovering()) { 213 if (delegate->GetBluetoothDiscovering()) {
213 ShowLoadingIndicator(); 214 ShowLoadingIndicator();
214 return; 215 return;
215 } 216 }
216 HideLoadingIndicator(); 217 HideLoadingIndicator();
217 if (delegate->GetBluetoothEnabled()) 218 if (delegate->GetBluetoothEnabled())
218 delegate->BluetoothStartDiscovering(); 219 delegate->BluetoothStartDiscovering();
219 } 220 }
220 221
221 void BluetoothStopDiscovering() { 222 void BluetoothStopDiscovering() {
222 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 223 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
223 if (delegate && delegate->GetBluetoothDiscovering()) { 224 if (delegate && delegate->GetBluetoothDiscovering()) {
224 delegate->BluetoothStopDiscovering(); 225 delegate->BluetoothStopDiscovering();
225 HideLoadingIndicator(); 226 HideLoadingIndicator();
226 } 227 }
227 } 228 }
228 229
229 void UpdateBluetoothDeviceList() { 230 void UpdateBluetoothDeviceList() {
230 std::set<std::string> new_connecting_devices; 231 std::set<std::string> new_connecting_devices;
231 std::set<std::string> new_connected_devices; 232 std::set<std::string> new_connected_devices;
232 std::set<std::string> new_paired_not_connected_devices; 233 std::set<std::string> new_paired_not_connected_devices;
233 std::set<std::string> new_discovered_not_paired_devices; 234 std::set<std::string> new_discovered_not_paired_devices;
234 235
235 BluetoothDeviceList list; 236 BluetoothDeviceList list;
236 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list); 237 Shell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list);
237 for (size_t i = 0; i < list.size(); ++i) { 238 for (size_t i = 0; i < list.size(); ++i) {
238 if (list[i].connecting) { 239 if (list[i].connecting) {
239 new_connecting_devices.insert(list[i].address); 240 new_connecting_devices.insert(list[i].address);
240 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); 241 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]);
241 } else if (list[i].connected && list[i].paired) { 242 } else if (list[i].connected && list[i].paired) {
242 new_connected_devices.insert(list[i].address); 243 new_connected_devices.insert(list[i].address);
243 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); 244 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]);
244 } else if (list[i].paired) { 245 } else if (list[i].paired) {
245 new_paired_not_connected_devices.insert(list[i].address); 246 new_paired_not_connected_devices.insert(list[i].address);
246 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, 247 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_,
247 list[i]); 248 list[i]);
248 } else { 249 } else {
249 new_discovered_not_paired_devices.insert(list[i].address); 250 new_discovered_not_paired_devices.insert(list[i].address);
250 UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_, 251 UpdateBluetoothDeviceListHelper(&discovered_not_paired_devices_,
251 list[i]); 252 list[i]);
252 } 253 }
253 } 254 }
254 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_, 255 RemoveObsoleteBluetoothDevicesFromList(&connecting_devices_,
255 new_connecting_devices); 256 new_connecting_devices);
256 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, 257 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_,
257 new_connected_devices); 258 new_connected_devices);
258 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, 259 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_,
259 new_paired_not_connected_devices); 260 new_paired_not_connected_devices);
260 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, 261 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_,
261 new_discovered_not_paired_devices); 262 new_discovered_not_paired_devices);
262 } 263 }
263 264
264 void UpdateHeaderEntry() { 265 void UpdateHeaderEntry() {
265 bool is_bluetooth_enabled = 266 bool is_bluetooth_enabled =
266 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); 267 Shell::Get()->system_tray_delegate()->GetBluetoothEnabled();
267 if (toggle_) 268 if (toggle_)
268 toggle_->SetIsOn(is_bluetooth_enabled, true); 269 toggle_->SetIsOn(is_bluetooth_enabled, true);
269 } 270 }
270 271
271 void UpdateDeviceScrollList() { 272 void UpdateDeviceScrollList() {
272 std::string focused_device_address = GetFocusedDeviceAddress(); 273 std::string focused_device_address = GetFocusedDeviceAddress();
273 274
274 device_map_.clear(); 275 device_map_.clear();
275 scroll_content()->RemoveAllChildViews(true); 276 scroll_content()->RemoveAllChildViews(true);
276 277
277 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 278 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
278 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); 279 bool bluetooth_enabled = delegate->GetBluetoothEnabled();
279 bool bluetooth_available = delegate->GetBluetoothAvailable(); 280 bool bluetooth_available = delegate->GetBluetoothAvailable();
280 281
281 // If Bluetooth is disabled, show a panel which only indicates that it is 282 // If Bluetooth is disabled, show a panel which only indicates that it is
282 // disabled, instead of the scroller with Bluetooth devices. 283 // disabled, instead of the scroller with Bluetooth devices.
283 if (bluetooth_enabled) { 284 if (bluetooth_enabled) {
284 HideDisabledPanel(); 285 HideDisabledPanel();
285 } else { 286 } else {
286 ShowDisabledPanel(); 287 ShowDisabledPanel();
287 return; 288 return;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 gfx::ImageSkia icon_image = CreateVectorIcon( 429 gfx::ImageSkia icon_image = CreateVectorIcon(
429 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor()); 430 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor());
430 SetupConnectingItem(container, display_name, icon_image); 431 SetupConnectingItem(container, display_name, icon_image);
431 scroll_content()->SizeToPreferredSize(); 432 scroll_content()->SizeToPreferredSize();
432 scroller()->Layout(); 433 scroller()->Layout();
433 } 434 }
434 } 435 }
435 436
436 // TrayDetailsView: 437 // TrayDetailsView:
437 void HandleViewClicked(views::View* view) override { 438 void HandleViewClicked(views::View* view) override {
438 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 439 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
439 if (!delegate->GetBluetoothEnabled()) 440 if (!delegate->GetBluetoothEnabled())
440 return; 441 return;
441 442
442 std::map<views::View*, std::string>::iterator find; 443 std::map<views::View*, std::string>::iterator find;
443 find = device_map_.find(view); 444 find = device_map_.find(view);
444 if (find == device_map_.end()) 445 if (find == device_map_.end())
445 return; 446 return;
446 447
447 const std::string device_id = find->second; 448 const std::string device_id = find->second;
448 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr)) 449 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr))
449 return; 450 return;
450 451
451 UpdateClickedDevice(device_id, view); 452 UpdateClickedDevice(device_id, view);
452 delegate->ConnectToBluetoothDevice(device_id); 453 delegate->ConnectToBluetoothDevice(device_id);
453 } 454 }
454 455
455 void HandleButtonPressed(views::Button* sender, 456 void HandleButtonPressed(views::Button* sender,
456 const ui::Event& event) override { 457 const ui::Event& event) override {
457 if (sender == toggle_) { 458 if (sender == toggle_) {
458 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 459 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
459 WmShell::Get()->RecordUserMetricsAction( 460 WmShell::Get()->RecordUserMetricsAction(
460 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED 461 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED
461 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); 462 : UMA_STATUS_AREA_BLUETOOTH_ENABLED);
462 delegate->ToggleBluetooth(); 463 delegate->ToggleBluetooth();
463 } else if (sender == settings_) { 464 } else if (sender == settings_) {
464 ShowSettings(); 465 ShowSettings();
465 } else { 466 } else {
466 NOTREACHED(); 467 NOTREACHED();
467 } 468 }
468 } 469 }
(...skipping 11 matching lines...) Expand all
480 TrayPopupUtils::CreateToggleButton(this, IDS_ASH_STATUS_TRAY_BLUETOOTH); 481 TrayPopupUtils::CreateToggleButton(this, IDS_ASH_STATUS_TRAY_BLUETOOTH);
481 tri_view()->AddView(TriView::Container::END, toggle_); 482 tri_view()->AddView(TriView::Container::END, toggle_);
482 483
483 settings_ = 484 settings_ =
484 CreateSettingsButton(login_, IDS_ASH_STATUS_TRAY_BLUETOOTH_SETTINGS); 485 CreateSettingsButton(login_, IDS_ASH_STATUS_TRAY_BLUETOOTH_SETTINGS);
485 tri_view()->AddView(TriView::Container::END, settings_); 486 tri_view()->AddView(TriView::Container::END, settings_);
486 } 487 }
487 488
488 void ShowSettings() { 489 void ShowSettings() {
489 if (TrayPopupUtils::CanOpenWebUISettings(login_)) { 490 if (TrayPopupUtils::CanOpenWebUISettings(login_)) {
490 WmShell::Get()->system_tray_delegate()->ManageBluetoothDevices(); 491 Shell::Get()->system_tray_delegate()->ManageBluetoothDevices();
491 owner()->system_tray()->CloseSystemBubble(); 492 owner()->system_tray()->CloseSystemBubble();
492 } 493 }
493 } 494 }
494 495
495 void ShowLoadingIndicator() { 496 void ShowLoadingIndicator() {
496 // Setting a value of -1 gives progress_bar an infinite-loading behavior. 497 // Setting a value of -1 gives progress_bar an infinite-loading behavior.
497 ShowProgress(-1, true); 498 ShowProgress(-1, true);
498 } 499 }
499 500
500 void HideLoadingIndicator() { ShowProgress(0, false); } 501 void HideLoadingIndicator() { ShowProgress(0, false); }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 610
610 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) { 611 views::View* TrayBluetooth::CreateDefaultView(LoginStatus status) {
611 CHECK(default_ == NULL); 612 CHECK(default_ == NULL);
612 default_ = new tray::BluetoothDefaultView(this); 613 default_ = new tray::BluetoothDefaultView(this);
613 default_->SetEnabled(status != LoginStatus::LOCKED); 614 default_->SetEnabled(status != LoginStatus::LOCKED);
614 default_->Update(); 615 default_->Update();
615 return default_; 616 return default_;
616 } 617 }
617 618
618 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) { 619 views::View* TrayBluetooth::CreateDetailedView(LoginStatus status) {
619 if (!WmShell::Get()->system_tray_delegate()->GetBluetoothAvailable()) 620 if (!Shell::Get()->system_tray_delegate()->GetBluetoothAvailable())
620 return NULL; 621 return NULL;
621 WmShell::Get()->RecordUserMetricsAction( 622 WmShell::Get()->RecordUserMetricsAction(
622 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW); 623 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW);
623 CHECK(detailed_ == NULL); 624 CHECK(detailed_ == NULL);
624 detailed_ = new tray::BluetoothDetailedView(this, status); 625 detailed_ = new tray::BluetoothDetailedView(this, status);
625 detailed_->Update(); 626 detailed_->Update();
626 return detailed_; 627 return detailed_;
627 } 628 }
628 629
629 void TrayBluetooth::DestroyTrayView() {} 630 void TrayBluetooth::DestroyTrayView() {}
(...skipping 15 matching lines...) Expand all
645 detailed_->Update(); 646 detailed_->Update();
646 } 647 }
647 648
648 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 649 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
649 if (!detailed_) 650 if (!detailed_)
650 return; 651 return;
651 detailed_->Update(); 652 detailed_->Update();
652 } 653 }
653 654
654 } // namespace ash 655 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698