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 "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
| 23 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/color_palette.h" | |
| 26 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 27 #include "ui/gfx/paint_vector_icon.h" | 28 #include "ui/gfx/paint_vector_icon.h" |
| 29 #include "ui/gfx/vector_icons/vector_icons.h" | |
|
tdanderson
2016/09/29 18:54:39
is this #include needed?
fukino
2016/09/30 02:43:49
Removed. Thanks!
| |
| 28 #include "ui/views/controls/button/toggle_button.h" | 30 #include "ui/views/controls/button/toggle_button.h" |
| 29 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
| 31 #include "ui/views/layout/box_layout.h" | 33 #include "ui/views/layout/box_layout.h" |
| 32 | 34 |
| 33 namespace ash { | 35 namespace ash { |
| 34 namespace tray { | 36 namespace tray { |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 // Updates bluetooth device |device| in the |list|. If it is new, append to the | 39 // Updates bluetooth device |device| in the |list|. If it is new, append to the |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 new_connecting_devices); | 225 new_connecting_devices); |
| 224 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, | 226 RemoveObsoleteBluetoothDevicesFromList(&connected_devices_, |
| 225 new_connected_devices); | 227 new_connected_devices); |
| 226 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, | 228 RemoveObsoleteBluetoothDevicesFromList(&paired_not_connected_devices_, |
| 227 new_paired_not_connected_devices); | 229 new_paired_not_connected_devices); |
| 228 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, | 230 RemoveObsoleteBluetoothDevicesFromList(&discovered_not_paired_devices_, |
| 229 new_discovered_not_paired_devices); | 231 new_discovered_not_paired_devices); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void UpdateHeaderEntry() { | 234 void UpdateHeaderEntry() { |
| 233 if (toggle_bluetooth_) { | 235 bool isBluetoothEnabled = |
| 234 toggle_bluetooth_->SetToggled( | 236 WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled(); |
| 235 !WmShell::Get()->system_tray_delegate()->GetBluetoothEnabled()); | 237 if (toggle_) |
| 236 } | 238 toggle_->SetIsOn(isBluetoothEnabled, false); |
| 239 if (toggle_bluetooth_) | |
|
tdanderson
2016/09/29 18:54:39
nit: else if (since you'll never have both visible
fukino
2016/09/30 02:43:49
Done.
| |
| 240 toggle_bluetooth_->SetToggled(!isBluetoothEnabled); | |
| 237 } | 241 } |
| 238 | 242 |
| 239 void UpdateDeviceScrollList() { | 243 void UpdateDeviceScrollList() { |
| 240 device_map_.clear(); | 244 device_map_.clear(); |
| 241 scroll_content()->RemoveAllChildViews(true); | 245 scroll_content()->RemoveAllChildViews(true); |
| 242 enable_bluetooth_ = nullptr; | 246 enable_bluetooth_ = nullptr; |
| 243 | 247 |
| 244 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 248 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 245 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 249 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| 246 bool blueooth_available = delegate->GetBluetoothAvailable(); | 250 bool blueooth_available = delegate->GetBluetoothAvailable(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 272 } | 276 } |
| 273 | 277 |
| 274 scroll_content()->SizeToPreferredSize(); | 278 scroll_content()->SizeToPreferredSize(); |
| 275 } | 279 } |
| 276 | 280 |
| 277 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, | 281 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, |
| 278 bool highlight, | 282 bool highlight, |
| 279 bool checked, | 283 bool checked, |
| 280 bool enabled) { | 284 bool enabled) { |
| 281 for (size_t i = 0; i < list.size(); ++i) { | 285 for (size_t i = 0; i < list.size(); ++i) { |
| 282 HoverHighlightView* container = | 286 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 283 AddScrollListItem(list[i].display_name, highlight, checked, enabled); | 287 HoverHighlightView* container = |
| 284 device_map_[container] = list[i].address; | 288 AddScrollListItemWithIcon(list[i].display_name, highlight, checked, |
| 289 enabled, list[i].icon_image); | |
| 290 device_map_[container] = list[i].address; | |
|
tdanderson
2016/09/29 18:54:39
nit: factor out lines 290 and 294 to after the if-
fukino
2016/09/30 02:43:49
Done. I used "md ? ... : ...";
| |
| 291 } else { | |
| 292 HoverHighlightView* container = AddScrollListItem( | |
| 293 list[i].display_name, highlight, checked, enabled); | |
| 294 device_map_[container] = list[i].address; | |
| 295 } | |
| 285 } | 296 } |
| 286 } | 297 } |
| 287 | 298 |
| 288 HoverHighlightView* AddScrollListItem(const base::string16& text, | 299 HoverHighlightView* AddScrollListItem(const base::string16& text, |
|
tdanderson
2016/09/29 18:54:39
As a side note, wherever it makes sense to do so,
fukino
2016/09/30 02:43:49
Done.
| |
| 289 bool highlight, | 300 bool highlight, |
| 290 bool checked, | 301 bool checked, |
| 291 bool enabled) { | 302 bool enabled) { |
| 292 HoverHighlightView* container = new HoverHighlightView(this); | 303 HoverHighlightView* container = new HoverHighlightView(this); |
| 293 views::Label* label = | 304 views::Label* label = |
| 294 container->AddCheckableLabel(text, highlight, checked); | 305 container->AddCheckableLabel(text, highlight, checked); |
| 295 label->SetEnabled(enabled); | 306 label->SetEnabled(enabled); |
| 296 scroll_content()->AddChildView(container); | 307 scroll_content()->AddChildView(container); |
| 297 return container; | 308 return container; |
| 298 } | 309 } |
| 299 | 310 |
| 311 HoverHighlightView* AddScrollListItemWithIcon(const base::string16& text, | |
| 312 bool highlight, | |
| 313 bool checked, | |
| 314 bool enabled, | |
| 315 const gfx::ImageSkia& image) { | |
| 316 HoverHighlightView* container = new HoverHighlightView(this); | |
|
fukino
2016/09/29 16:27:36
This implementation to place icons/labels/etc... i
tdanderson
2016/09/29 18:54:39
Acknowledged. Whatever you do here is probably wha
fukino
2016/09/30 02:43:49
Thanks. I'll update this design next, and I'll mak
| |
| 317 const int padding = (kMenuButtonSize - image.width()) / 2; | |
| 318 container->AddIconAndLabelCustomSize( | |
| 319 image, text, highlight, | |
| 320 image.width() + kMenuSeparatorVerticalPadding * 2, padding, padding); | |
| 321 gfx::ImageSkia check_mark = | |
| 322 CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700); | |
| 323 container->AddRightIcon(check_mark, check_mark.width()); | |
| 324 container->SetRightIconVisible(checked); | |
| 325 container->text_label()->SetEnabled(enabled); | |
| 326 scroll_content()->AddChildView(container); | |
| 327 return container; | |
| 328 } | |
| 329 | |
| 300 // Add settings entries. | 330 // Add settings entries. |
| 301 void AppendSettingsEntries() { | 331 void AppendSettingsEntries() { |
| 302 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) | 332 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) |
| 303 return; | 333 return; |
| 304 | 334 |
| 305 // Add bluetooth device requires a browser window, hide it for non logged in | 335 // Add bluetooth device requires a browser window, hide it for non logged in |
| 306 // user. | 336 // user. |
| 307 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || | 337 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || |
| 308 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) { | 338 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) { |
| 309 return; | 339 return; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 if (FoundDevice(device_id, connecting_devices_, nullptr)) | 412 if (FoundDevice(device_id, connecting_devices_, nullptr)) |
| 383 return; | 413 return; |
| 384 | 414 |
| 385 UpdateClickedDevice(device_id, view); | 415 UpdateClickedDevice(device_id, view); |
| 386 delegate->ConnectToBluetoothDevice(device_id); | 416 delegate->ConnectToBluetoothDevice(device_id); |
| 387 } | 417 } |
| 388 | 418 |
| 389 void HandleButtonPressed(views::Button* sender, | 419 void HandleButtonPressed(views::Button* sender, |
| 390 const ui::Event& event) override { | 420 const ui::Event& event) override { |
| 391 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 421 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 392 // TODO(fukino): Make the toggle button functional. | |
| 393 if (sender == toggle_) | 422 if (sender == toggle_) |
| 394 toggle_->SetIsOn(toggle_->is_on(), true); | 423 WmShell::Get()->system_tray_delegate()->ToggleBluetooth(); |
| 424 else | |
| 425 NOTREACHED(); | |
| 395 return; | 426 return; |
| 396 } | 427 } |
| 397 | 428 |
| 398 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 429 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 399 if (sender == toggle_bluetooth_) | 430 if (sender == toggle_bluetooth_) |
| 400 delegate->ToggleBluetooth(); | 431 delegate->ToggleBluetooth(); |
| 401 else | 432 else |
| 402 NOTREACHED(); | 433 NOTREACHED(); |
| 403 } | 434 } |
| 404 | 435 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 detailed_->Update(); | 542 detailed_->Update(); |
| 512 } | 543 } |
| 513 | 544 |
| 514 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 545 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
| 515 if (!detailed_) | 546 if (!detailed_) |
| 516 return; | 547 return; |
| 517 detailed_->Update(); | 548 detailed_->Update(); |
| 518 } | 549 } |
| 519 | 550 |
| 520 } // namespace ash | 551 } // namespace ash |
| OLD | NEW |