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/system/bluetooth/tray_bluetooth.h" | 5 #include "ash/system/bluetooth/tray_bluetooth.h" |
| 6 | 6 |
| 7 #include "ash/session/session_state_delegate.h" | 7 #include "ash/session/session_state_delegate.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/system/tray/fixed_sized_image_view.h" | |
| 9 #include "ash/system/tray/fixed_sized_scroll_view.h" | 10 #include "ash/system/tray/fixed_sized_scroll_view.h" |
| 10 #include "ash/system/tray/hover_highlight_view.h" | 11 #include "ash/system/tray/hover_highlight_view.h" |
| 11 #include "ash/system/tray/system_tray.h" | 12 #include "ash/system/tray/system_tray.h" |
| 12 #include "ash/system/tray/system_tray_delegate.h" | 13 #include "ash/system/tray/system_tray_delegate.h" |
| 13 #include "ash/system/tray/system_tray_notifier.h" | 14 #include "ash/system/tray/system_tray_notifier.h" |
| 14 #include "ash/system/tray/throbber_view.h" | 15 #include "ash/system/tray/throbber_view.h" |
| 15 #include "ash/system/tray/tray_constants.h" | 16 #include "ash/system/tray/tray_constants.h" |
| 16 #include "ash/system/tray/tray_details_view.h" | 17 #include "ash/system/tray/tray_details_view.h" |
| 17 #include "ash/system/tray/tray_item_more.h" | 18 #include "ash/system/tray/tray_item_more.h" |
| 18 #include "ash/system/tray/tray_popup_header_button.h" | 19 #include "ash/system/tray/tray_popup_header_button.h" |
| 19 #include "grit/ash_resources.h" | 20 #include "grit/ash_resources.h" |
| 20 #include "grit/ash_strings.h" | 21 #include "grit/ash_strings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 24 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
| 25 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
| 26 #include "ui/views/layout/box_layout.h" | 27 #include "ui/views/layout/box_layout.h" |
| 28 #include "ui/views/layout/fill_layout.h" | |
| 27 | 29 |
| 28 namespace ash { | 30 namespace ash { |
| 29 namespace tray { | 31 namespace tray { |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 34 // Constants of special layout for bluetooth device entries. | |
| 35 const int kDeviceLabelLeftMargin = 7; | |
| 36 const int kDeviceTypeIconAreaWidth = 60; | |
| 37 const int kConnectedIconSize = 10; | |
| 38 const int kConnectedIconOffsetTop = 26; | |
| 39 const int kConnectedIconOffsetLeft = 33; | |
| 40 | |
| 32 // Updates bluetooth device |device| in the |list|. If it is new, append to the | 41 // Updates bluetooth device |device| in the |list|. If it is new, append to the |
| 33 // end of the |list|; otherwise, keep it at the same place, but update the data | 42 // end of the |list|; otherwise, keep it at the same place, but update the data |
| 34 // with new device info provided by |device|. | 43 // with new device info provided by |device|. |
| 35 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, | 44 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, |
| 36 const BluetoothDeviceInfo& device) { | 45 const BluetoothDeviceInfo& device) { |
| 37 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); | 46 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); |
| 38 ++it) { | 47 ++it) { |
| 39 if ((*it).address == device.address) { | 48 if ((*it).address == device.address) { |
| 40 *it = device; | 49 *it = device; |
| 41 return; | 50 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 53 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); | 62 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); |
| 54 ++it) { | 63 ++it) { |
| 55 if (new_list.find((*it).address) == new_list.end()) { | 64 if (new_list.find((*it).address) == new_list.end()) { |
| 56 it = list->erase(it); | 65 it = list->erase(it); |
| 57 if (it == list->end()) | 66 if (it == list->end()) |
| 58 return; | 67 return; |
| 59 } | 68 } |
| 60 } | 69 } |
| 61 } | 70 } |
| 62 | 71 |
| 72 // Returns a resource id of an icon which corresponds to the given device type. | |
| 73 int GetDeviceIconResourceId(ash::BluetoothDeviceInfo::DeviceType device_type) { | |
| 74 switch (device_type) { | |
| 75 case ash::BluetoothDeviceInfo::DEVICE_COMPUTER: | |
| 76 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_COMPUTER; | |
| 77 case ash::BluetoothDeviceInfo::DEVICE_PHONE: | |
| 78 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_SMARTPHONE; | |
| 79 case ash::BluetoothDeviceInfo::DEVICE_AUDIO: | |
| 80 case ash::BluetoothDeviceInfo::DEVICE_CAR_AUDIO: | |
| 81 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_HEADSET; | |
| 82 case ash::BluetoothDeviceInfo::DEVICE_VIDEO: | |
| 83 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_VIDEOCAM; | |
| 84 case ash::BluetoothDeviceInfo::DEVICE_JOYSTICK: | |
| 85 case ash::BluetoothDeviceInfo::DEVICE_GAMEPAD: | |
| 86 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_GAMEPAD; | |
| 87 case ash::BluetoothDeviceInfo::DEVICE_KEYBOARD: | |
| 88 case ash::BluetoothDeviceInfo::DEVICE_KEYBOARD_MOUSE_COMBO: | |
| 89 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_KEYBOARD; | |
| 90 case ash::BluetoothDeviceInfo::DEVICE_TABLET: | |
| 91 case ash::BluetoothDeviceInfo::DEVICE_MOUSE: | |
| 92 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_MOUSE; | |
| 93 default: | |
| 94 return IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_BLUETOOTH; | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 // Special layout for bluetooth device entries. | |
| 99 class BluetoothDeviceListEntry : public HoverHighlightView { | |
| 100 public: | |
| 101 BluetoothDeviceListEntry(ViewClickListener* listener, | |
| 102 const gfx::ImageSkia& image, | |
| 103 const base::string16& text, | |
| 104 bool highlight, | |
| 105 bool checked, | |
| 106 bool enabled) | |
| 107 : HoverHighlightView(listener), device_icon_(nullptr) { | |
| 108 SetEnabled(enabled); | |
| 109 | |
| 110 AddDeviceTypeIcon(image); | |
| 111 AddDeviceLabel(text, highlight); | |
| 112 if (checked) | |
| 113 AddCheckmarkOnDeviceIcon(); | |
| 114 | |
| 115 // Overwrites the layout mode which was set as FillLayout by AddLabel(). | |
| 116 SetLayoutManager( | |
| 117 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 118 } | |
| 119 | |
| 120 private: | |
| 121 views::ImageView* device_icon_; | |
| 122 | |
| 123 void AddDeviceTypeIcon(const gfx::ImageSkia& image) { | |
| 124 device_icon_ = new FixedSizedImageView(kDeviceTypeIconAreaWidth, 0); | |
| 125 device_icon_->SetImage(image); | |
| 126 device_icon_->SetEnabled(enabled()); | |
| 127 AddChildView(device_icon_); | |
| 128 } | |
| 129 | |
| 130 void AddDeviceLabel(const base::string16& text, bool highlight) { | |
| 131 AddLabel(text, gfx::ALIGN_LEFT, highlight); | |
| 132 int left_margin = kDeviceLabelLeftMargin; | |
| 133 int right_margin = kTrayPopupPaddingHorizontal; | |
| 134 if (base::i18n::IsRTL()) | |
| 135 std::swap(left_margin, right_margin); | |
| 136 text_label()->SetBorder( | |
| 137 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin)); | |
| 138 } | |
| 139 | |
| 140 void AddCheckmarkOnDeviceIcon() { | |
| 141 device_icon_->SetLayoutManager(new views::FillLayout()); | |
| 142 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 143 const gfx::ImageSkia* checkmark = | |
| 144 rb.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH_DEVICE_CONNECTED) | |
| 145 .ToImageSkia(); | |
| 146 views::ImageView* checkmark_view = | |
| 147 new FixedSizedImageView(kConnectedIconSize, kConnectedIconSize); | |
| 148 checkmark_view->SetImage(checkmark); | |
| 149 checkmark_view->SetEnabled(enabled()); | |
| 150 checkmark_view->SetHorizontalAlignment(views::ImageView::LEADING); | |
| 151 checkmark_view->SetVerticalAlignment(views::ImageView::LEADING); | |
| 152 checkmark_view->SetBorder(views::Border::CreateEmptyBorder( | |
| 153 kConnectedIconOffsetTop, kConnectedIconOffsetLeft, 0, | |
| 154 kDeviceTypeIconAreaWidth - kConnectedIconOffsetLeft - | |
| 155 kConnectedIconSize)); | |
| 156 device_icon_->AddChildView(checkmark_view); | |
| 157 ; | |
|
jennyz
2016/04/27 23:27:38
nit: Remove empty ";" line.
| |
| 158 } | |
| 159 }; | |
| 160 | |
| 63 } // namespace | 161 } // namespace |
| 64 | 162 |
| 65 class BluetoothDefaultView : public TrayItemMore { | 163 class BluetoothDefaultView : public TrayItemMore { |
| 66 public: | 164 public: |
| 67 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) | 165 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) |
| 68 : TrayItemMore(owner, show_more) { | 166 : TrayItemMore(owner, show_more) { |
| 69 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 167 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 70 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); | 168 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); |
| 71 UpdateLabel(); | 169 UpdateLabel(); |
| 72 } | 170 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 } | 363 } |
| 266 } | 364 } |
| 267 | 365 |
| 268 scroll_content()->SizeToPreferredSize(); | 366 scroll_content()->SizeToPreferredSize(); |
| 269 } | 367 } |
| 270 | 368 |
| 271 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, | 369 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, |
| 272 bool highlight, | 370 bool highlight, |
| 273 bool checked, | 371 bool checked, |
| 274 bool enabled) { | 372 bool enabled) { |
| 373 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 275 for (size_t i = 0; i < list.size(); ++i) { | 374 for (size_t i = 0; i < list.size(); ++i) { |
| 276 HoverHighlightView* container = | 375 const gfx::ImageSkia* icon = |
| 277 AddScrollListItem(list[i].display_name, highlight, checked, enabled); | 376 rb.GetImageSkiaNamed(GetDeviceIconResourceId(list[i].device_type)); |
| 377 HoverHighlightView* container = AddBluetoothDeviceListEntry( | |
| 378 list[i].display_name, icon, highlight, checked, enabled); | |
| 278 device_map_[container] = list[i].address; | 379 device_map_[container] = list[i].address; |
| 279 } | 380 } |
| 280 } | 381 } |
| 281 | 382 |
| 282 HoverHighlightView* AddScrollListItem(const base::string16& text, | 383 HoverHighlightView* AddScrollListItem(const base::string16& text, |
| 283 bool highlight, | 384 bool highlight, |
| 284 bool checked, | 385 bool checked, |
| 285 bool enabled) { | 386 bool enabled) { |
| 286 HoverHighlightView* container = new HoverHighlightView(this); | 387 HoverHighlightView* container = new HoverHighlightView(this); |
| 287 views::Label* label = | 388 views::Label* label = |
| 288 container->AddCheckableLabel(text, highlight, checked); | 389 container->AddCheckableLabel(text, highlight, checked); |
| 289 label->SetEnabled(enabled); | 390 label->SetEnabled(enabled); |
| 290 scroll_content()->AddChildView(container); | 391 scroll_content()->AddChildView(container); |
| 291 return container; | 392 return container; |
| 292 } | 393 } |
| 293 | 394 |
| 395 // Add an bluetooth device entry to the scrollable device list. | |
| 396 HoverHighlightView* AddBluetoothDeviceListEntry(const base::string16& text, | |
| 397 const gfx::ImageSkia* icon, | |
| 398 bool highlight, | |
| 399 bool checked, | |
| 400 bool enabled) { | |
| 401 BluetoothDeviceListEntry* container = new BluetoothDeviceListEntry( | |
| 402 this, *icon, text, highlight, checked, enabled); | |
| 403 scroll_content()->AddChildView(container); | |
| 404 return container; | |
| 405 } | |
| 406 | |
| 294 // Add settings entries. | 407 // Add settings entries. |
| 295 void AppendSettingsEntries() { | 408 void AppendSettingsEntries() { |
| 296 if (!ash::Shell::GetInstance()-> | 409 if (!ash::Shell::GetInstance()-> |
| 297 system_tray_delegate()->ShouldShowSettings()) { | 410 system_tray_delegate()->ShouldShowSettings()) { |
| 298 return; | 411 return; |
| 299 } | 412 } |
| 300 | 413 |
| 301 // Add bluetooth device requires a browser window, hide it for non logged in | 414 // Add bluetooth device requires a browser window, hide it for non logged in |
| 302 // user. | 415 // user. |
| 303 bool userAddingRunning = ash::Shell::GetInstance() | 416 bool userAddingRunning = ash::Shell::GetInstance() |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 detailed_->Update(); | 577 detailed_->Update(); |
| 465 } | 578 } |
| 466 | 579 |
| 467 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 580 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
| 468 if (!detailed_) | 581 if (!detailed_) |
| 469 return; | 582 return; |
| 470 detailed_->Update(); | 583 detailed_->Update(); |
| 471 } | 584 } |
| 472 | 585 |
| 473 } // namespace ash | 586 } // namespace ash |
| OLD | NEW |