Chromium Code Reviews| 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/common/system/chromeos/bluetooth/tray_bluetooth.h" | 5 #include "ash/common/system/chromeos/bluetooth/tray_bluetooth.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
| 10 #include "ash/common/system/tray/hover_highlight_view.h" | 10 #include "ash/common/system/tray/hover_highlight_view.h" |
| 11 #include "ash/common/system/tray/system_tray.h" | 11 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/system/tray/system_tray_delegate.h" | 12 #include "ash/common/system/tray/system_tray_delegate.h" |
| 13 #include "ash/common/system/tray/system_tray_notifier.h" | 13 #include "ash/common/system/tray/system_tray_notifier.h" |
| 14 #include "ash/common/system/tray/throbber_view.h" | 14 #include "ash/common/system/tray/throbber_view.h" |
| 15 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
| 16 #include "ash/common/system/tray/tray_details_view.h" | 16 #include "ash/common/system/tray/tray_details_view.h" |
| 17 #include "ash/common/system/tray/tray_item_more.h" | 17 #include "ash/common/system/tray/tray_item_more.h" |
| 18 #include "ash/common/system/tray/tray_popup_header_button.h" | 18 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 19 #include "ash/common/system/tray/tray_popup_item_style.h" | 19 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 20 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 21 #include "ash/resources/vector_icons/vector_icons.h" | 21 #include "ash/resources/vector_icons/vector_icons.h" |
| 22 #include "device/bluetooth/bluetooth_common.h" | |
| 22 #include "grit/ash_resources.h" | 23 #include "grit/ash_resources.h" |
| 23 #include "grit/ash_strings.h" | 24 #include "grit/ash_strings.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" |
| 27 #include "ui/gfx/color_palette.h" | |
| 26 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 27 #include "ui/gfx/paint_vector_icon.h" | 29 #include "ui/gfx/paint_vector_icon.h" |
| 30 #include "ui/gfx/vector_icons_public.h" | |
| 28 #include "ui/views/controls/button/toggle_button.h" | 31 #include "ui/views/controls/button/toggle_button.h" |
| 29 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" |
| 31 #include "ui/views/layout/box_layout.h" | 34 #include "ui/views/layout/box_layout.h" |
| 32 | 35 |
| 33 namespace ash { | 36 namespace ash { |
| 34 namespace tray { | 37 namespace tray { |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 // Updates bluetooth device |device| in the |list|. If it is new, append to the | 40 // Updates bluetooth device |device| in the |list|. If it is new, append to the |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 58 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); | 61 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); |
| 59 ++it) { | 62 ++it) { |
| 60 if (new_list.find((*it).address) == new_list.end()) { | 63 if (new_list.find((*it).address) == new_list.end()) { |
| 61 it = list->erase(it); | 64 it = list->erase(it); |
| 62 if (it == list->end()) | 65 if (it == list->end()) |
| 63 return; | 66 return; |
| 64 } | 67 } |
| 65 } | 68 } |
| 66 } | 69 } |
| 67 | 70 |
| 71 // Returns corresponding device type icons for given Bluetooth device types. | |
| 72 const gfx::VectorIcon& GetBluetoothDeviceIcon( | |
| 73 device::BluetoothDeviceType device_type) { | |
| 74 switch (device_type) { | |
| 75 case device::BluetoothDeviceType::COMPUTER: | |
| 76 return ash::kSystemMenuComputerIcon; | |
| 77 case device::BluetoothDeviceType::PHONE: | |
| 78 return ash::kSystemMenuPhoneIcon; | |
| 79 case device::BluetoothDeviceType::AUDIO: | |
| 80 case device::BluetoothDeviceType::CAR_AUDIO: | |
| 81 return ash::kSystemMenuHeadsetIcon; | |
| 82 case device::BluetoothDeviceType::VIDEO: | |
| 83 return ash::kSystemMenuVideocamIcon; | |
| 84 case device::BluetoothDeviceType::JOYSTICK: | |
| 85 case device::BluetoothDeviceType::GAMEPAD: | |
| 86 return ash::kSystemMenuGamepadIcon; | |
| 87 case device::BluetoothDeviceType::KEYBOARD: | |
| 88 case device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO: | |
| 89 return ash::kSystemMenuKeyboardIcon; | |
| 90 case device::BluetoothDeviceType::TABLET: | |
| 91 return ash::kSystemMenuTabletIcon; | |
| 92 case device::BluetoothDeviceType::MOUSE: | |
| 93 return ash::kSystemMenuMouseIcon; | |
| 94 case device::BluetoothDeviceType::MODEM: | |
| 95 case device::BluetoothDeviceType::PERIPHERAL: | |
| 96 return ash::kSystemMenuBluetoothIcon; | |
| 97 case device::BluetoothDeviceType::UNKNOWN: | |
| 98 LOG(WARNING) << "Unknown device type icon for Bluetooth was requested."; | |
|
tdanderson
2016/10/06 14:12:12
Would a NOTREACHED() be more appropriate here?
fukino
2016/10/06 14:45:30
I'm not sure if it is critical that a BT device is
tdanderson
2016/10/06 14:47:16
OK, sg
| |
| 99 break; | |
| 100 } | |
| 101 return ash::kSystemMenuBluetoothIcon; | |
| 102 } | |
| 103 | |
| 68 } // namespace | 104 } // namespace |
| 69 | 105 |
| 70 class BluetoothDefaultView : public TrayItemMore { | 106 class BluetoothDefaultView : public TrayItemMore { |
| 71 public: | 107 public: |
| 72 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) | 108 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) |
| 73 : TrayItemMore(owner, show_more) { | 109 : TrayItemMore(owner, show_more) { |
| 74 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { | 110 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 75 // The icon doesn't change in non-md. | 111 // The icon doesn't change in non-md. |
| 76 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 112 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 77 SetImage( | 113 SetImage( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 new_connecting_devices); | 259 new_connecting_devices); |
| 224 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, | 260 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, |
| 225 new_connected_devices); | 261 new_connected_devices); |
| 226 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, | 262 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, |
| 227 new_paired_not_connected_devices); | 263 new_paired_not_connected_devices); |
| 228 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, | 264 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, |
| 229 new_discovered_not_paired_devices); | 265 new_discovered_not_paired_devices); |
| 230 } | 266 } |
| 231 | 267 |
| 232 void UpdateHeaderEntry() { | 268 void UpdateHeaderEntry() { |
| 233 if (toggle_bluetooth_) { | 269 bool is_bluetooth_enabled = |
| 234 toggle_bluetooth_->SetToggled( | 270 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); |
| 235 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); | 271 if (toggle_) |
| 236 } | 272 toggle_->SetIsOn(is_bluetooth_enabled, false); |
| 273 else if (toggle_bluetooth_) | |
| 274 toggle_bluetooth_->SetToggled(!is_bluetooth_enabled); | |
| 237 } | 275 } |
| 238 | 276 |
| 239 void UpdateDeviceScrollList() { | 277 void UpdateDeviceScrollList() { |
| 240 device_map_.clear(); | 278 device_map_.clear(); |
| 241 scroll_content()->RemoveAllChildViews(true); | 279 scroll_content()->RemoveAllChildViews(true); |
| 242 enable_bluetooth_ = nullptr; | 280 enable_bluetooth_ = nullptr; |
| 243 | 281 |
| 244 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 282 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 245 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 283 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| 246 bool blueooth_available = delegate->GetBluetoothAvailable(); | 284 bool blueooth_available = delegate->GetBluetoothAvailable(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 272 } | 310 } |
| 273 | 311 |
| 274 scroll_content()->SizeToPreferredSize(); | 312 scroll_content()->SizeToPreferredSize(); |
| 275 } | 313 } |
| 276 | 314 |
| 277 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, | 315 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, |
| 278 bool highlight, | 316 bool highlight, |
| 279 bool checked, | 317 bool checked, |
| 280 bool enabled) { | 318 bool enabled) { |
| 281 for (size_t i = 0; i < list.size(); ++i) { | 319 for (size_t i = 0; i < list.size(); ++i) { |
| 282 HoverHighlightView* container = | 320 HoverHighlightView* container = nullptr; |
| 283 AddScrollListItem(list[i].display_name, highlight, checked, enabled); | 321 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 322 gfx::ImageSkia icon_image = CreateVectorIcon( | |
| 323 GetBluetoothDeviceIcon(list[i].device_type), ash::kMenuIconColor); | |
|
tdanderson
2016/10/06 14:12:12
nit: ash:: not needed
fukino
2016/10/07 00:19:16
Done.
| |
| 324 container = AddScrollListItemWithIcon(list[i].display_name, highlight, | |
| 325 checked, enabled, icon_image); | |
| 326 | |
| 327 } else { | |
| 328 container = AddScrollListItem(list[i].display_name, highlight, checked, | |
| 329 enabled); | |
| 330 } | |
| 284 device_map_[container] = list[i].address; | 331 device_map_[container] = list[i].address; |
| 285 } | 332 } |
| 286 } | 333 } |
| 287 | 334 |
| 335 // TODO(fukino): Remove this code when material design is enabled by default, | |
| 336 // since AddScrollListItem should be used only in the old design. | |
| 337 // See crbug.com/614453". | |
| 288 HoverHighlightView* AddScrollListItem(const base::string16& text, | 338 HoverHighlightView* AddScrollListItem(const base::string16& text, |
| 289 bool highlight, | 339 bool highlight, |
| 290 bool checked, | 340 bool checked, |
| 291 bool enabled) { | 341 bool enabled) { |
| 292 HoverHighlightView* container = new HoverHighlightView(this); | 342 HoverHighlightView* container = new HoverHighlightView(this); |
| 293 views::Label* label = | 343 views::Label* label = |
| 294 container->AddCheckableLabel(text, highlight, checked); | 344 container->AddCheckableLabel(text, highlight, checked); |
| 295 label->SetEnabled(enabled); | 345 label->SetEnabled(enabled); |
| 296 scroll_content()->AddChildView(container); | 346 scroll_content()->AddChildView(container); |
| 297 return container; | 347 return container; |
| 298 } | 348 } |
| 299 | 349 |
| 350 HoverHighlightView* AddScrollListItemWithIcon(const base::string16& text, | |
| 351 bool highlight, | |
| 352 bool checked, | |
| 353 bool enabled, | |
| 354 const gfx::ImageSkia& image) { | |
| 355 HoverHighlightView* container = new HoverHighlightView(this); | |
| 356 const int padding = (kMenuButtonSize - image.width()) / 2; | |
| 357 container->AddIconAndLabelCustomSize( | |
| 358 image, text, highlight, | |
| 359 image.width() + kMenuSeparatorVerticalPadding * 2, padding, padding); | |
| 360 gfx::ImageSkia check_mark = | |
| 361 CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700); | |
| 362 container->AddRightIcon(check_mark, check_mark.width()); | |
| 363 container->SetRightIconVisible(checked); | |
| 364 container->text_label()->SetEnabled(enabled); | |
| 365 scroll_content()->AddChildView(container); | |
| 366 return container; | |
| 367 } | |
| 368 | |
| 300 // Add settings entries. | 369 // Add settings entries. |
| 301 void AppendSettingsEntries() { | 370 void AppendSettingsEntries() { |
| 302 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) | 371 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) |
| 303 return; | 372 return; |
| 304 | 373 |
| 305 // Add bluetooth device requires a browser window, hide it for non logged in | 374 // Add bluetooth device requires a browser window, hide it for non logged in |
| 306 // user. | 375 // user. |
| 307 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || | 376 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || |
| 308 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) { | 377 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) { |
| 309 return; | 378 return; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 if (FoundDevice(device_id, connecting_devices_, nullptr)) | 451 if (FoundDevice(device_id, connecting_devices_, nullptr)) |
| 383 return; | 452 return; |
| 384 | 453 |
| 385 UpdateClickedDevice(device_id, view); | 454 UpdateClickedDevice(device_id, view); |
| 386 delegate->ConnectToBluetoothDevice(device_id); | 455 delegate->ConnectToBluetoothDevice(device_id); |
| 387 } | 456 } |
| 388 | 457 |
| 389 void HandleButtonPressed(views::Button* sender, | 458 void HandleButtonPressed(views::Button* sender, |
| 390 const ui::Event& event) override { | 459 const ui::Event& event) override { |
| 391 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 460 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 392 // TODO(fukino): Make the toggle button functional. | |
| 393 if (sender == toggle_) | 461 if (sender == toggle_) |
| 394 toggle_->SetIsOn(toggle_->is_on(), true); | 462 WmShell::Get()->system_tray_delegate()->ToggleBluetooth(); |
| 463 else | |
| 464 NOTREACHED(); | |
| 395 return; | 465 return; |
| 396 } | 466 } |
| 397 | 467 |
| 398 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 468 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 399 if (sender == toggle_bluetooth_) | 469 if (sender == toggle_bluetooth_) |
| 400 delegate->ToggleBluetooth(); | 470 delegate->ToggleBluetooth(); |
| 401 else | 471 else |
| 402 NOTREACHED(); | 472 NOTREACHED(); |
| 403 } | 473 } |
| 404 | 474 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 detailed_->Update(); | 581 detailed_->Update(); |
| 512 } | 582 } |
| 513 | 583 |
| 514 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 584 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
| 515 if (!detailed_) | 585 if (!detailed_) |
| 516 return; | 586 return; |
| 517 detailed_->Update(); | 587 detailed_->Update(); |
| 518 } | 588 } |
| 519 | 589 |
| 520 } // namespace ash | 590 } // namespace ash |
| OLD | NEW |