| 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" | |
| 8 #include "ash/common/session/session_state_delegate.h" | 7 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/system/tray/hover_highlight_view.h" | 8 #include "ash/common/system/tray/hover_highlight_view.h" |
| 10 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
| 11 #include "ash/common/system/tray/system_tray_delegate.h" | 10 #include "ash/common/system/tray/system_tray_delegate.h" |
| 12 #include "ash/common/system/tray/system_tray_notifier.h" | 11 #include "ash/common/system/tray/system_tray_notifier.h" |
| 13 #include "ash/common/system/tray/throbber_view.h" | 12 #include "ash/common/system/tray/throbber_view.h" |
| 14 #include "ash/common/system/tray/tray_constants.h" | 13 #include "ash/common/system/tray/tray_constants.h" |
| 15 #include "ash/common/system/tray/tray_details_view.h" | 14 #include "ash/common/system/tray/tray_details_view.h" |
| 16 #include "ash/common/system/tray/tray_item_more.h" | 15 #include "ash/common/system/tray/tray_item_more.h" |
| 17 #include "ash/common/system/tray/tray_popup_header_button.h" | |
| 18 #include "ash/common/system/tray/tray_popup_item_style.h" | 16 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 19 #include "ash/common/system/tray/tray_popup_utils.h" | 17 #include "ash/common/system/tray/tray_popup_utils.h" |
| 20 #include "ash/common/system/tray/tri_view.h" | 18 #include "ash/common/system/tray/tri_view.h" |
| 21 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 22 #include "ash/resources/vector_icons/vector_icons.h" | 20 #include "ash/resources/vector_icons/vector_icons.h" |
| 23 #include "device/bluetooth/bluetooth_common.h" | 21 #include "device/bluetooth/bluetooth_common.h" |
| 24 #include "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
| 25 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/color_palette.h" | 26 #include "ui/gfx/color_palette.h" |
| 29 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 30 #include "ui/gfx/paint_vector_icon.h" | 28 #include "ui/gfx/paint_vector_icon.h" |
| 31 #include "ui/gfx/vector_icons_public.h" | 29 #include "ui/gfx/vector_icons_public.h" |
| 32 #include "ui/views/controls/button/toggle_button.h" | 30 #include "ui/views/controls/button/toggle_button.h" |
| 33 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
| 34 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
| 35 #include "ui/views/controls/progress_bar.h" | 33 #include "ui/views/controls/progress_bar.h" |
| 36 #include "ui/views/controls/scroll_view.h" | 34 #include "ui/views/controls/scroll_view.h" |
| 37 #include "ui/views/controls/separator.h" | 35 #include "ui/views/controls/separator.h" |
| 38 #include "ui/views/layout/box_layout.h" | 36 #include "ui/views/layout/box_layout.h" |
| 39 | 37 |
| 40 namespace ash { | 38 namespace ash { |
| 41 namespace tray { | 39 namespace tray { |
| 42 namespace { | 40 namespace { |
| 43 | 41 |
| 44 bool UseMd() { | |
| 45 return MaterialDesignController::IsSystemTrayMenuMaterial(); | |
| 46 } | |
| 47 | |
| 48 // Updates bluetooth device |device| in the |list|. If it is new, append to the | 42 // Updates bluetooth device |device| in the |list|. If it is new, append to the |
| 49 // end of the |list|; otherwise, keep it at the same place, but update the data | 43 // end of the |list|; otherwise, keep it at the same place, but update the data |
| 50 // with new device info provided by |device|. | 44 // with new device info provided by |device|. |
| 51 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, | 45 void UpdateBluetoothDeviceListHelper(BluetoothDeviceList* list, |
| 52 const BluetoothDeviceInfo& device) { | 46 const BluetoothDeviceInfo& device) { |
| 53 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); | 47 for (BluetoothDeviceList::iterator it = list->begin(); it != list->end(); |
| 54 ++it) { | 48 ++it) { |
| 55 if ((*it).address == device.address) { | 49 if ((*it).address == device.address) { |
| 56 *it = device; | 50 *it = device; |
| 57 return; | 51 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 : ash::kSystemMenuBluetoothIcon; | 106 : ash::kSystemMenuBluetoothIcon; |
| 113 } | 107 } |
| 114 | 108 |
| 115 const int kDisabledPanelLabelBaselineY = 20; | 109 const int kDisabledPanelLabelBaselineY = 20; |
| 116 | 110 |
| 117 } // namespace | 111 } // namespace |
| 118 | 112 |
| 119 class BluetoothDefaultView : public TrayItemMore { | 113 class BluetoothDefaultView : public TrayItemMore { |
| 120 public: | 114 public: |
| 121 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) | 115 BluetoothDefaultView(SystemTrayItem* owner, bool show_more) |
| 122 : TrayItemMore(owner, show_more) { | 116 : TrayItemMore(owner, show_more) {} |
| 123 if (!UseMd()) { | |
| 124 // The icon doesn't change in non-md. | |
| 125 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 126 SetImage( | |
| 127 *bundle.GetImageNamed(IDR_AURA_UBER_TRAY_BLUETOOTH).ToImageSkia()); | |
| 128 } | |
| 129 } | |
| 130 | 117 |
| 131 ~BluetoothDefaultView() override {} | 118 ~BluetoothDefaultView() override {} |
| 132 | 119 |
| 133 void Update() { | 120 void Update() { |
| 134 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 121 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 135 const bool enabled = delegate->GetBluetoothEnabled(); | 122 const bool enabled = delegate->GetBluetoothEnabled(); |
| 136 if (delegate->GetBluetoothAvailable()) { | 123 if (delegate->GetBluetoothAvailable()) { |
| 137 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 138 const base::string16 label = rb.GetLocalizedString( | 125 const base::string16 label = rb.GetLocalizedString( |
| 139 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED | 126 enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED |
| (...skipping 17 matching lines...) Expand all Loading... |
| 157 ? TrayPopupItemStyle::ColorStyle::ACTIVE | 144 ? TrayPopupItemStyle::ColorStyle::ACTIVE |
| 158 : delegate->GetBluetoothAvailable() | 145 : delegate->GetBluetoothAvailable() |
| 159 ? TrayPopupItemStyle::ColorStyle::INACTIVE | 146 ? TrayPopupItemStyle::ColorStyle::INACTIVE |
| 160 : TrayPopupItemStyle::ColorStyle::DISABLED); | 147 : TrayPopupItemStyle::ColorStyle::DISABLED); |
| 161 | 148 |
| 162 return style; | 149 return style; |
| 163 } | 150 } |
| 164 | 151 |
| 165 void UpdateStyle() override { | 152 void UpdateStyle() override { |
| 166 TrayItemMore::UpdateStyle(); | 153 TrayItemMore::UpdateStyle(); |
| 167 | |
| 168 if (!UseMd()) | |
| 169 return; | |
| 170 | |
| 171 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); | 154 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); |
| 172 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor())); | 155 SetImage(gfx::CreateVectorIcon(GetCurrentIcon(), style->GetIconColor())); |
| 173 } | 156 } |
| 174 | 157 |
| 175 private: | 158 private: |
| 176 const gfx::VectorIcon& GetCurrentIcon() { | 159 const gfx::VectorIcon& GetCurrentIcon() { |
| 177 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 160 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 178 if (!delegate->GetBluetoothEnabled()) | 161 if (!delegate->GetBluetoothEnabled()) |
| 179 return kSystemMenuBluetoothDisabledIcon; | 162 return kSystemMenuBluetoothDisabledIcon; |
| 180 | 163 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 192 } | 175 } |
| 193 | 176 |
| 194 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); | 177 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); |
| 195 }; | 178 }; |
| 196 | 179 |
| 197 class BluetoothDetailedView : public TrayDetailsView { | 180 class BluetoothDetailedView : public TrayDetailsView { |
| 198 public: | 181 public: |
| 199 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) | 182 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) |
| 200 : TrayDetailsView(owner), | 183 : TrayDetailsView(owner), |
| 201 login_(login), | 184 login_(login), |
| 202 manage_devices_(nullptr), | |
| 203 throbber_(nullptr), | |
| 204 toggle_bluetooth_(nullptr), | |
| 205 enable_bluetooth_(nullptr), | |
| 206 toggle_(nullptr), | 185 toggle_(nullptr), |
| 207 settings_(nullptr), | 186 settings_(nullptr), |
| 208 disabled_panel_(nullptr) { | 187 disabled_panel_(nullptr) { |
| 209 CreateItems(); | 188 CreateItems(); |
| 210 } | 189 } |
| 211 | 190 |
| 212 ~BluetoothDetailedView() override { | 191 ~BluetoothDetailedView() override { |
| 213 // Stop discovering bluetooth devices when exiting BT detailed view. | 192 // Stop discovering bluetooth devices when exiting BT detailed view. |
| 214 BluetoothStopDiscovering(); | 193 BluetoothStopDiscovering(); |
| 215 } | 194 } |
| 216 | 195 |
| 217 void Update() { | 196 void Update() { |
| 218 BluetoothStartDiscovering(); | 197 BluetoothStartDiscovering(); |
| 219 UpdateBluetoothDeviceList(); | 198 UpdateBluetoothDeviceList(); |
| 220 | 199 |
| 221 // Update UI. | 200 // Update UI. |
| 222 UpdateDeviceScrollList(); | 201 UpdateDeviceScrollList(); |
| 223 UpdateHeaderEntry(); | 202 UpdateHeaderEntry(); |
| 224 Layout(); | 203 Layout(); |
| 225 } | 204 } |
| 226 | 205 |
| 227 private: | 206 private: |
| 228 void CreateItems() { | 207 void CreateItems() { |
| 229 CreateScrollableList(); | 208 CreateScrollableList(); |
| 230 AppendSettingsEntries(); | |
| 231 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); | 209 CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH); |
| 232 } | 210 } |
| 233 | 211 |
| 234 void BluetoothStartDiscovering() { | 212 void BluetoothStartDiscovering() { |
| 235 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 213 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 236 if (delegate->GetBluetoothDiscovering()) { | 214 if (delegate->GetBluetoothDiscovering()) { |
| 237 ShowLoadingIndicator(); | 215 ShowLoadingIndicator(); |
| 238 return; | 216 return; |
| 239 } | 217 } |
| 240 HideLoadingIndicator(); | 218 HideLoadingIndicator(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 253 void UpdateBluetoothDeviceList() { | 231 void UpdateBluetoothDeviceList() { |
| 254 std::set<std::string> new_connecting_devices; | 232 std::set<std::string> new_connecting_devices; |
| 255 std::set<std::string> new_connected_devices; | 233 std::set<std::string> new_connected_devices; |
| 256 std::set<std::string> new_paired_not_connected_devices; | 234 std::set<std::string> new_paired_not_connected_devices; |
| 257 std::set<std::string> new_discovered_not_paired_devices; | 235 std::set<std::string> new_discovered_not_paired_devices; |
| 258 | 236 |
| 259 BluetoothDeviceList list; | 237 BluetoothDeviceList list; |
| 260 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list); | 238 WmShell::Get()->system_tray_delegate()->GetAvailableBluetoothDevices(&list); |
| 261 for (size_t i = 0; i < list.size(); ++i) { | 239 for (size_t i = 0; i < list.size(); ++i) { |
| 262 if (list[i].connecting) { | 240 if (list[i].connecting) { |
| 263 if (!UseMd()) { | |
| 264 list[i].display_name = l10n_util::GetStringFUTF16( | |
| 265 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name); | |
| 266 } | |
| 267 new_connecting_devices.insert(list[i].address); | 241 new_connecting_devices.insert(list[i].address); |
| 268 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); | 242 UpdateBluetoothDeviceListHelper(&connecting_devices_, list[i]); |
| 269 } else if (list[i].connected && list[i].paired) { | 243 } else if (list[i].connected && list[i].paired) { |
| 270 new_connected_devices.insert(list[i].address); | 244 new_connected_devices.insert(list[i].address); |
| 271 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); | 245 UpdateBluetoothDeviceListHelper(&connected_devices_, list[i]); |
| 272 } else if (list[i].paired) { | 246 } else if (list[i].paired) { |
| 273 new_paired_not_connected_devices.insert(list[i].address); | 247 new_paired_not_connected_devices.insert(list[i].address); |
| 274 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, | 248 UpdateBluetoothDeviceListHelper(&paired_not_connected_devices_, |
| 275 list[i]); | 249 list[i]); |
| 276 } else { | 250 } else { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 287 new_paired_not_connected_devices); | 261 new_paired_not_connected_devices); |
| 288 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, | 262 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, |
| 289 new_discovered_not_paired_devices); | 263 new_discovered_not_paired_devices); |
| 290 } | 264 } |
| 291 | 265 |
| 292 void UpdateHeaderEntry() { | 266 void UpdateHeaderEntry() { |
| 293 bool is_bluetooth_enabled = | 267 bool is_bluetooth_enabled = |
| 294 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); | 268 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); |
| 295 if (toggle_) | 269 if (toggle_) |
| 296 toggle_->SetIsOn(is_bluetooth_enabled, false); | 270 toggle_->SetIsOn(is_bluetooth_enabled, false); |
| 297 else if (toggle_bluetooth_) | |
| 298 toggle_bluetooth_->SetToggled(!is_bluetooth_enabled); | |
| 299 } | 271 } |
| 300 | 272 |
| 301 void UpdateDeviceScrollList() { | 273 void UpdateDeviceScrollList() { |
| 302 device_map_.clear(); | 274 device_map_.clear(); |
| 303 scroll_content()->RemoveAllChildViews(true); | 275 scroll_content()->RemoveAllChildViews(true); |
| 304 enable_bluetooth_ = nullptr; | |
| 305 | 276 |
| 306 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 277 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 307 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 278 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| 308 bool bluetooth_available = delegate->GetBluetoothAvailable(); | 279 bool bluetooth_available = delegate->GetBluetoothAvailable(); |
| 309 if (bluetooth_available && !bluetooth_enabled && toggle_bluetooth_) { | |
| 310 enable_bluetooth_ = AddScrollListItem( | |
| 311 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), | |
| 312 false /* highlight */, false /* checked */, true /* enabled */); | |
| 313 } | |
| 314 | 280 |
| 315 // If Bluetooth is disabled, show a panel which only indicates that it is | 281 // If Bluetooth is disabled, show a panel which only indicates that it is |
| 316 // disabled, instead of the scroller with Bluetooth devices. | 282 // disabled, instead of the scroller with Bluetooth devices. |
| 317 if (UseMd()) { | 283 if (bluetooth_enabled) { |
| 318 if (bluetooth_enabled) { | 284 HideDisabledPanel(); |
| 319 HideDisabledPanel(); | 285 } else { |
| 320 } else { | 286 ShowDisabledPanel(); |
| 321 ShowDisabledPanel(); | 287 return; |
| 322 return; | |
| 323 } | |
| 324 } | 288 } |
| 325 | 289 |
| 326 // Add paired devices (and their section header in MD) in the list. | 290 // Add paired devices (and their section header in MD) in the list. |
| 327 size_t num_paired_devices = connected_devices_.size() + | 291 size_t num_paired_devices = connected_devices_.size() + |
| 328 connecting_devices_.size() + | 292 connecting_devices_.size() + |
| 329 paired_not_connected_devices_.size(); | 293 paired_not_connected_devices_.size(); |
| 330 if (num_paired_devices > 0) { | 294 if (num_paired_devices > 0) { |
| 331 if (UseMd()) | 295 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_PAIRED_DEVICES); |
| 332 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_PAIRED_DEVICES); | |
| 333 AppendSameTypeDevicesToScrollList(connected_devices_, true, true, | 296 AppendSameTypeDevicesToScrollList(connected_devices_, true, true, |
| 334 bluetooth_enabled); | 297 bluetooth_enabled); |
| 335 AppendSameTypeDevicesToScrollList(connecting_devices_, true, false, | 298 AppendSameTypeDevicesToScrollList(connecting_devices_, true, false, |
| 336 bluetooth_enabled); | 299 bluetooth_enabled); |
| 337 AppendSameTypeDevicesToScrollList(paired_not_connected_devices_, false, | 300 AppendSameTypeDevicesToScrollList(paired_not_connected_devices_, false, |
| 338 false, bluetooth_enabled); | 301 false, bluetooth_enabled); |
| 339 } | 302 } |
| 340 | 303 |
| 341 // Add paired devices (and their section header in MD) in the list. | 304 // Add paired devices (and their section header in MD) in the list. |
| 342 if (discovered_not_paired_devices_.size() > 0) { | 305 if (discovered_not_paired_devices_.size() > 0) { |
| 343 if (UseMd()) { | 306 if (num_paired_devices > 0) |
| 344 if (num_paired_devices > 0) | 307 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_UNPAIRED_DEVICES); |
| 345 AddSubHeader(IDS_ASH_STATUS_TRAY_BLUETOOTH_UNPAIRED_DEVICES); | |
| 346 } else { | |
| 347 AddScrollSeparator(); | |
| 348 } | |
| 349 AppendSameTypeDevicesToScrollList(discovered_not_paired_devices_, false, | 308 AppendSameTypeDevicesToScrollList(discovered_not_paired_devices_, false, |
| 350 false, bluetooth_enabled); | 309 false, bluetooth_enabled); |
| 351 } | 310 } |
| 352 | 311 |
| 353 // Show user Bluetooth state if there is no bluetooth devices in list. | 312 // Show user Bluetooth state if there is no bluetooth devices in list. |
| 354 if (device_map_.size() == 0) { | 313 if (device_map_.size() == 0) { |
| 355 if (bluetooth_available && bluetooth_enabled) { | 314 if (bluetooth_available && bluetooth_enabled) { |
| 356 AddScrollListItem(l10n_util::GetStringUTF16( | 315 HoverHighlightView* container = new HoverHighlightView(this); |
| 357 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), | 316 container->AddLabel(l10n_util::GetStringUTF16( |
| 358 false /* highlight */, false /* checked */, | 317 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), |
| 359 true /* enabled */); | 318 gfx::ALIGN_LEFT, false); |
| 319 scroll_content()->AddChildView(container); |
| 360 } | 320 } |
| 361 } | 321 } |
| 362 | 322 |
| 363 scroll_content()->InvalidateLayout(); | 323 scroll_content()->InvalidateLayout(); |
| 364 } | 324 } |
| 365 | 325 |
| 366 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, | 326 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, |
| 367 bool highlight, | 327 bool highlight, |
| 368 bool checked, | 328 bool checked, |
| 369 bool enabled) { | 329 bool enabled) { |
| 370 for (size_t i = 0; i < list.size(); ++i) { | 330 for (size_t i = 0; i < list.size(); ++i) { |
| 371 HoverHighlightView* container = nullptr; | 331 HoverHighlightView* container = nullptr; |
| 372 if (UseMd()) { | 332 gfx::ImageSkia icon_image = CreateVectorIcon( |
| 373 gfx::ImageSkia icon_image = CreateVectorIcon( | 333 GetBluetoothDeviceIcon(list[i].device_type, list[i].connected), |
| 374 GetBluetoothDeviceIcon(list[i].device_type, list[i].connected), | 334 kMenuIconColor); |
| 375 kMenuIconColor); | 335 container = AddScrollListItem(list[i].display_name, icon_image, |
| 376 container = AddScrollListItemMd(list[i].display_name, icon_image, | 336 list[i].connected, list[i].connecting); |
| 377 list[i].connected, list[i].connecting); | |
| 378 } else { | |
| 379 container = AddScrollListItem(list[i].display_name, highlight, checked, | |
| 380 enabled); | |
| 381 } | |
| 382 device_map_[container] = list[i].address; | 337 device_map_[container] = list[i].address; |
| 383 } | 338 } |
| 384 } | 339 } |
| 385 | 340 |
| 386 // TODO(fukino): Remove this code when material design is enabled by default, | |
| 387 // since AddScrollListItem should be used only in the old design. | |
| 388 // See crbug.com/614453". | |
| 389 HoverHighlightView* AddScrollListItem(const base::string16& text, | 341 HoverHighlightView* AddScrollListItem(const base::string16& text, |
| 390 bool highlight, | 342 const gfx::ImageSkia& image, |
| 391 bool checked, | 343 bool connected, |
| 392 bool enabled) { | 344 bool connecting) { |
| 393 HoverHighlightView* container = new HoverHighlightView(this); | |
| 394 views::Label* label = | |
| 395 container->AddCheckableLabel(text, highlight, checked); | |
| 396 label->SetEnabled(enabled); | |
| 397 scroll_content()->AddChildView(container); | |
| 398 return container; | |
| 399 } | |
| 400 | |
| 401 HoverHighlightView* AddScrollListItemMd(const base::string16& text, | |
| 402 const gfx::ImageSkia& image, | |
| 403 bool connected, | |
| 404 bool connecting) { | |
| 405 DCHECK(UseMd()); | |
| 406 HoverHighlightView* container = new HoverHighlightView(this); | 345 HoverHighlightView* container = new HoverHighlightView(this); |
| 407 if (connected) { | 346 if (connected) { |
| 408 SetupConnectedItemMd(container, text, image); | 347 SetupConnectedItem(container, text, image); |
| 409 } else if (connecting) { | 348 } else if (connecting) { |
| 410 SetupConnectingItemMd(container, text, image); | 349 SetupConnectingItem(container, text, image); |
| 411 } else { | 350 } else { |
| 412 container->AddIconAndLabel(image, text, false); | 351 container->AddIconAndLabel(image, text, false); |
| 413 } | 352 } |
| 414 scroll_content()->AddChildView(container); | 353 scroll_content()->AddChildView(container); |
| 415 return container; | 354 return container; |
| 416 } | 355 } |
| 417 | 356 |
| 418 void AddSubHeader(int message_id) { | 357 void AddSubHeader(int message_id) { |
| 419 TriView* header = TrayPopupUtils::CreateSubHeaderRowView(); | 358 TriView* header = TrayPopupUtils::CreateSubHeaderRowView(); |
| 420 TrayPopupUtils::ConfigureAsStickyHeader(header); | 359 TrayPopupUtils::ConfigureAsStickyHeader(header); |
| 421 | 360 |
| 422 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | 361 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
| 423 label->SetText(l10n_util::GetStringUTF16(message_id)); | 362 label->SetText(l10n_util::GetStringUTF16(message_id)); |
| 424 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | 363 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); |
| 425 style.SetupLabel(label); | 364 style.SetupLabel(label); |
| 426 header->AddView(TriView::Container::CENTER, label); | 365 header->AddView(TriView::Container::CENTER, label); |
| 427 | 366 |
| 428 scroll_content()->AddChildView(header); | 367 scroll_content()->AddChildView(header); |
| 429 } | 368 } |
| 430 | 369 |
| 431 void SetupConnectedItemMd(HoverHighlightView* container, | 370 void SetupConnectedItem(HoverHighlightView* container, |
| 432 const base::string16& text, | 371 const base::string16& text, |
| 433 const gfx::ImageSkia& image) { | 372 const gfx::ImageSkia& image) { |
| 434 container->AddIconAndLabels( | 373 container->AddIconAndLabels( |
| 435 image, text, l10n_util::GetStringUTF16( | 374 image, text, l10n_util::GetStringUTF16( |
| 436 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); | 375 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); |
| 437 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); | 376 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); |
| 438 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); | 377 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); |
| 439 style.SetupLabel(container->sub_text_label()); | 378 style.SetupLabel(container->sub_text_label()); |
| 440 } | 379 } |
| 441 | 380 |
| 442 void SetupConnectingItemMd(HoverHighlightView* container, | 381 void SetupConnectingItem(HoverHighlightView* container, |
| 443 const base::string16& text, | 382 const base::string16& text, |
| 444 const gfx::ImageSkia& image) { | 383 const gfx::ImageSkia& image) { |
| 445 container->AddIconAndLabels( | 384 container->AddIconAndLabels( |
| 446 image, text, l10n_util::GetStringUTF16( | 385 image, text, l10n_util::GetStringUTF16( |
| 447 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); | 386 IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); |
| 448 ThrobberView* throbber = new ThrobberView; | 387 ThrobberView* throbber = new ThrobberView; |
| 449 throbber->Start(); | 388 throbber->Start(); |
| 450 container->AddRightView(throbber); | 389 container->AddRightView(throbber); |
| 451 } | 390 } |
| 452 | 391 |
| 453 // Add settings entries. | |
| 454 void AppendSettingsEntries() { | |
| 455 // Do not append the bottom button row in material design; this is replaced | |
| 456 // by the settings button in the header row. | |
| 457 if (UseMd()) | |
| 458 return; | |
| 459 | |
| 460 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) | |
| 461 return; | |
| 462 | |
| 463 // Add bluetooth device requires a browser window, hide it for non logged in | |
| 464 // user. | |
| 465 if (!TrayPopupUtils::CanOpenWebUISettings(login_)) | |
| 466 return; | |
| 467 | |
| 468 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
| 469 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 470 HoverHighlightView* container = new HoverHighlightView(this); | |
| 471 container->AddLabel( | |
| 472 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES), | |
| 473 gfx::ALIGN_LEFT, false /* highlight */); | |
| 474 container->SetEnabled(delegate->GetBluetoothAvailable()); | |
| 475 AddChildView(container); | |
| 476 manage_devices_ = container; | |
| 477 } | |
| 478 | |
| 479 // Returns true if the device with |device_id| is found in |device_list|, | 392 // Returns true if the device with |device_id| is found in |device_list|, |
| 480 // and the display_name of the device will be returned in |display_name| if | 393 // and the display_name of the device will be returned in |display_name| if |
| 481 // it's not NULL. | 394 // it's not NULL. |
| 482 bool FoundDevice(const std::string& device_id, | 395 bool FoundDevice(const std::string& device_id, |
| 483 const BluetoothDeviceList& device_list, | 396 const BluetoothDeviceList& device_list, |
| 484 base::string16* display_name, | 397 base::string16* display_name, |
| 485 device::BluetoothDeviceType* device_type) { | 398 device::BluetoothDeviceType* device_type) { |
| 486 for (size_t i = 0; i < device_list.size(); ++i) { | 399 for (size_t i = 0; i < device_list.size(); ++i) { |
| 487 if (device_list[i].address == device_id) { | 400 if (device_list[i].address == device_id) { |
| 488 if (display_name) | 401 if (display_name) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 499 // or disconnected if such an operation is going to be performed underway. | 412 // or disconnected if such an operation is going to be performed underway. |
| 500 void UpdateClickedDevice(const std::string& device_id, | 413 void UpdateClickedDevice(const std::string& device_id, |
| 501 views::View* item_container) { | 414 views::View* item_container) { |
| 502 base::string16 display_name; | 415 base::string16 display_name; |
| 503 device::BluetoothDeviceType device_type; | 416 device::BluetoothDeviceType device_type; |
| 504 if (FoundDevice(device_id, paired_not_connected_devices_, &display_name, | 417 if (FoundDevice(device_id, paired_not_connected_devices_, &display_name, |
| 505 &device_type)) { | 418 &device_type)) { |
| 506 item_container->RemoveAllChildViews(true); | 419 item_container->RemoveAllChildViews(true); |
| 507 HoverHighlightView* container = | 420 HoverHighlightView* container = |
| 508 static_cast<HoverHighlightView*>(item_container); | 421 static_cast<HoverHighlightView*>(item_container); |
| 509 if (UseMd()) { | 422 TrayPopupItemStyle style( |
| 510 TrayPopupItemStyle style( | 423 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 511 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | 424 gfx::ImageSkia icon_image = CreateVectorIcon( |
| 512 gfx::ImageSkia icon_image = CreateVectorIcon( | 425 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor()); |
| 513 GetBluetoothDeviceIcon(device_type, false), style.GetIconColor()); | 426 SetupConnectingItem(container, display_name, icon_image); |
| 514 SetupConnectingItemMd(container, display_name, icon_image); | |
| 515 } else { | |
| 516 display_name = l10n_util::GetStringFUTF16( | |
| 517 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, display_name); | |
| 518 container->AddCheckableLabel(display_name, true /* highlight */, false); | |
| 519 } | |
| 520 scroll_content()->SizeToPreferredSize(); | 427 scroll_content()->SizeToPreferredSize(); |
| 521 scroller()->Layout(); | 428 scroller()->Layout(); |
| 522 } | 429 } |
| 523 } | 430 } |
| 524 | 431 |
| 525 // TrayDetailsView: | 432 // TrayDetailsView: |
| 526 void HandleViewClicked(views::View* view) override { | 433 void HandleViewClicked(views::View* view) override { |
| 527 if (view == manage_devices_) { | |
| 528 ShowSettings(); | |
| 529 return; | |
| 530 } | |
| 531 | |
| 532 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 434 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 533 if (view == enable_bluetooth_) { | |
| 534 WmShell::Get()->RecordUserMetricsAction( | |
| 535 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED | |
| 536 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); | |
| 537 delegate->ToggleBluetooth(); | |
| 538 return; | |
| 539 } | |
| 540 | |
| 541 if (!delegate->GetBluetoothEnabled()) | 435 if (!delegate->GetBluetoothEnabled()) |
| 542 return; | 436 return; |
| 543 | 437 |
| 544 std::map<views::View*, std::string>::iterator find; | 438 std::map<views::View*, std::string>::iterator find; |
| 545 find = device_map_.find(view); | 439 find = device_map_.find(view); |
| 546 if (find == device_map_.end()) | 440 if (find == device_map_.end()) |
| 547 return; | 441 return; |
| 548 | 442 |
| 549 const std::string device_id = find->second; | 443 const std::string device_id = find->second; |
| 550 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr)) | 444 if (FoundDevice(device_id, connecting_devices_, nullptr, nullptr)) |
| 551 return; | 445 return; |
| 552 | 446 |
| 553 UpdateClickedDevice(device_id, view); | 447 UpdateClickedDevice(device_id, view); |
| 554 delegate->ConnectToBluetoothDevice(device_id); | 448 delegate->ConnectToBluetoothDevice(device_id); |
| 555 } | 449 } |
| 556 | 450 |
| 557 void HandleButtonPressed(views::Button* sender, | 451 void HandleButtonPressed(views::Button* sender, |
| 558 const ui::Event& event) override { | 452 const ui::Event& event) override { |
| 559 if (UseMd()) { | 453 if (sender == toggle_) |
| 560 if (sender == toggle_) | 454 WmShell::Get()->system_tray_delegate()->ToggleBluetooth(); |
| 561 WmShell::Get()->system_tray_delegate()->ToggleBluetooth(); | 455 else if (sender == settings_) |
| 562 else if (sender == settings_) | 456 ShowSettings(); |
| 563 ShowSettings(); | |
| 564 else | |
| 565 NOTREACHED(); | |
| 566 return; | |
| 567 } | |
| 568 | 457 |
| 569 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 458 NOTREACHED(); |
| 570 if (sender == toggle_bluetooth_) | |
| 571 delegate->ToggleBluetooth(); | |
| 572 else | |
| 573 NOTREACHED(); | |
| 574 } | 459 } |
| 575 | 460 |
| 576 void CreateExtraTitleRowButtons() override { | 461 void CreateExtraTitleRowButtons() override { |
| 577 if (login_ == LoginStatus::LOCKED) | 462 if (login_ == LoginStatus::LOCKED) |
| 578 return; | 463 return; |
| 579 | 464 |
| 580 if (UseMd()) { | 465 DCHECK(!toggle_); |
| 581 DCHECK(!toggle_); | 466 DCHECK(!settings_); |
| 582 DCHECK(!settings_); | |
| 583 | 467 |
| 584 tri_view()->SetContainerVisible(TriView::Container::END, true); | 468 tri_view()->SetContainerVisible(TriView::Container::END, true); |
| 585 | 469 |
| 586 toggle_ = TrayPopupUtils::CreateToggleButton( | 470 toggle_ = |
| 587 this, IDS_ASH_STATUS_TRAY_BLUETOOTH); | 471 TrayPopupUtils::CreateToggleButton(this, IDS_ASH_STATUS_TRAY_BLUETOOTH); |
| 588 tri_view()->AddView(TriView::Container::END, toggle_); | 472 tri_view()->AddView(TriView::Container::END, toggle_); |
| 589 | 473 |
| 590 settings_ = CreateSettingsButton(login_); | 474 settings_ = CreateSettingsButton(login_); |
| 591 tri_view()->AddView(TriView::Container::END, settings_); | 475 tri_view()->AddView(TriView::Container::END, settings_); |
| 592 return; | |
| 593 } | |
| 594 | |
| 595 throbber_ = new ThrobberView; | |
| 596 throbber_->SetTooltipText( | |
| 597 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); | |
| 598 title_row()->AddViewToRowNonMd(throbber_, false); | |
| 599 | |
| 600 // Do not allow toggling bluetooth in the lock screen. | |
| 601 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
| 602 toggle_bluetooth_ = | |
| 603 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, | |
| 604 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, | |
| 605 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, | |
| 606 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, | |
| 607 IDS_ASH_STATUS_TRAY_BLUETOOTH); | |
| 608 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); | |
| 609 toggle_bluetooth_->SetTooltipText( | |
| 610 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); | |
| 611 toggle_bluetooth_->SetToggledTooltipText( | |
| 612 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); | |
| 613 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); | |
| 614 title_row()->AddViewToRowNonMd(toggle_bluetooth_, true); | |
| 615 } | 476 } |
| 616 | 477 |
| 617 void ShowSettings() { | 478 void ShowSettings() { |
| 618 if (TrayPopupUtils::CanOpenWebUISettings(login_)) { | 479 if (TrayPopupUtils::CanOpenWebUISettings(login_)) { |
| 619 WmShell::Get()->system_tray_delegate()->ManageBluetoothDevices(); | 480 WmShell::Get()->system_tray_delegate()->ManageBluetoothDevices(); |
| 620 owner()->system_tray()->CloseSystemBubble(); | 481 owner()->system_tray()->CloseSystemBubble(); |
| 621 } | 482 } |
| 622 } | 483 } |
| 623 | 484 |
| 624 void ShowLoadingIndicator() { | 485 void ShowLoadingIndicator() { |
| 625 if (throbber_) { | 486 // Setting a value of -1 gives progress_bar an infinite-loading behavior. |
| 626 throbber_->Start(); | 487 ShowProgress(-1, true); |
| 627 } else if (UseMd()) { | |
| 628 // Setting a value of -1 gives progress_bar an infinite-loading behavior. | |
| 629 ShowProgress(-1, true); | |
| 630 } | |
| 631 } | 488 } |
| 632 | 489 |
| 633 void HideLoadingIndicator() { | 490 void HideLoadingIndicator() { ShowProgress(0, false); } |
| 634 if (throbber_) | |
| 635 throbber_->Stop(); | |
| 636 else if (UseMd()) | |
| 637 ShowProgress(0, false); | |
| 638 } | |
| 639 | 491 |
| 640 void ShowDisabledPanel() { | 492 void ShowDisabledPanel() { |
| 641 DCHECK(UseMd()); | |
| 642 DCHECK(scroller()); | 493 DCHECK(scroller()); |
| 643 if (!disabled_panel_) { | 494 if (!disabled_panel_) { |
| 644 disabled_panel_ = CreateDisabledPanel(); | 495 disabled_panel_ = CreateDisabledPanel(); |
| 645 // Insert |disabled_panel_| before the scroller, since the scroller will | 496 // Insert |disabled_panel_| before the scroller, since the scroller will |
| 646 // have unnecessary bottom border when it is not the last child. | 497 // have unnecessary bottom border when it is not the last child. |
| 647 AddChildViewAt(disabled_panel_, GetIndexOf(scroller())); | 498 AddChildViewAt(disabled_panel_, GetIndexOf(scroller())); |
| 648 // |disabled_panel_| need to fill the remaining space below the title row | 499 // |disabled_panel_| need to fill the remaining space below the title row |
| 649 // so that the inner contents of |disabled_panel_| are placed properly. | 500 // so that the inner contents of |disabled_panel_| are placed properly. |
| 650 box_layout()->SetFlexForView(disabled_panel_, 1); | 501 box_layout()->SetFlexForView(disabled_panel_, 1); |
| 651 } | 502 } |
| 652 disabled_panel_->SetVisible(true); | 503 disabled_panel_->SetVisible(true); |
| 653 scroller()->SetVisible(false); | 504 scroller()->SetVisible(false); |
| 654 } | 505 } |
| 655 | 506 |
| 656 void HideDisabledPanel() { | 507 void HideDisabledPanel() { |
| 657 DCHECK(UseMd()); | |
| 658 DCHECK(scroller()); | 508 DCHECK(scroller()); |
| 659 if (disabled_panel_) | 509 if (disabled_panel_) |
| 660 disabled_panel_->SetVisible(false); | 510 disabled_panel_->SetVisible(false); |
| 661 scroller()->SetVisible(true); | 511 scroller()->SetVisible(true); |
| 662 } | 512 } |
| 663 | 513 |
| 664 views::View* CreateDisabledPanel() { | 514 views::View* CreateDisabledPanel() { |
| 665 views::View* container = new views::View; | 515 views::View* container = new views::View; |
| 666 views::BoxLayout* box_layout = | 516 views::BoxLayout* box_layout = |
| 667 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 517 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 691 // icon is vertically aligned to center of the container. | 541 // icon is vertically aligned to center of the container. |
| 692 image_view->SetBorder( | 542 image_view->SetBorder( |
| 693 views::CreateEmptyBorder(label->GetPreferredSize().height(), 0, 0, 0)); | 543 views::CreateEmptyBorder(label->GetPreferredSize().height(), 0, 0, 0)); |
| 694 return container; | 544 return container; |
| 695 } | 545 } |
| 696 | 546 |
| 697 LoginStatus login_; | 547 LoginStatus login_; |
| 698 | 548 |
| 699 std::map<views::View*, std::string> device_map_; | 549 std::map<views::View*, std::string> device_map_; |
| 700 | 550 |
| 701 // Not used in material design. | |
| 702 views::View* manage_devices_; | |
| 703 | |
| 704 // Not used in material design. | |
| 705 ThrobberView* throbber_; | |
| 706 | |
| 707 // Not used in material design. | |
| 708 TrayPopupHeaderButton* toggle_bluetooth_; | |
| 709 | |
| 710 HoverHighlightView* enable_bluetooth_; | |
| 711 BluetoothDeviceList connected_devices_; | 551 BluetoothDeviceList connected_devices_; |
| 712 BluetoothDeviceList connecting_devices_; | 552 BluetoothDeviceList connecting_devices_; |
| 713 BluetoothDeviceList paired_not_connected_devices_; | 553 BluetoothDeviceList paired_not_connected_devices_; |
| 714 BluetoothDeviceList discovered_not_paired_devices_; | 554 BluetoothDeviceList discovered_not_paired_devices_; |
| 715 | 555 |
| 716 // The on/off toggle button used in material design. | |
| 717 views::ToggleButton* toggle_; | 556 views::ToggleButton* toggle_; |
| 718 | |
| 719 // Only used in material design. | |
| 720 views::Button* settings_; | 557 views::Button* settings_; |
| 721 | 558 |
| 722 // Only used in material design. | |
| 723 // The container of the message "Bluetooth is disabled" and an icon. It should | 559 // The container of the message "Bluetooth is disabled" and an icon. It should |
| 724 // be shown instead of Bluetooth device list when Bluetooth is disabled. | 560 // be shown instead of Bluetooth device list when Bluetooth is disabled. |
| 725 views::View* disabled_panel_; | 561 views::View* disabled_panel_; |
| 726 | 562 |
| 727 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 563 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
| 728 }; | 564 }; |
| 729 | 565 |
| 730 } // namespace tray | 566 } // namespace tray |
| 731 | 567 |
| 732 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) | 568 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 detailed_->Update(); | 618 detailed_->Update(); |
| 783 } | 619 } |
| 784 | 620 |
| 785 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 621 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
| 786 if (!detailed_) | 622 if (!detailed_) |
| 787 return; | 623 return; |
| 788 detailed_->Update(); | 624 detailed_->Update(); |
| 789 } | 625 } |
| 790 | 626 |
| 791 } // namespace ash | 627 } // namespace ash |
| OLD | NEW |