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

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

Issue 2429923002: Implement all system menu title row buttons for Ash MD (Closed)
Patch Set: OS_WIN define in tests Created 4 years, 2 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/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/system/tray/tray_utils.h"
20 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
21 #include "ash/resources/vector_icons/vector_icons.h" 22 #include "ash/resources/vector_icons/vector_icons.h"
22 #include "device/bluetooth/bluetooth_common.h" 23 #include "device/bluetooth/bluetooth_common.h"
23 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
24 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/gfx/color_palette.h" 28 #include "ui/gfx/color_palette.h"
28 #include "ui/gfx/image/image.h" 29 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/paint_vector_icon.h" 30 #include "ui/gfx/paint_vector_icon.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 171
171 class BluetoothDetailedView : public TrayDetailsView { 172 class BluetoothDetailedView : public TrayDetailsView {
172 public: 173 public:
173 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) 174 BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login)
174 : TrayDetailsView(owner), 175 : TrayDetailsView(owner),
175 login_(login), 176 login_(login),
176 manage_devices_(nullptr), 177 manage_devices_(nullptr),
177 throbber_(nullptr), 178 throbber_(nullptr),
178 toggle_bluetooth_(nullptr), 179 toggle_bluetooth_(nullptr),
179 enable_bluetooth_(nullptr), 180 enable_bluetooth_(nullptr),
180 toggle_(nullptr) { 181 toggle_(nullptr),
182 settings_(nullptr) {
181 CreateItems(); 183 CreateItems();
182 } 184 }
183 185
184 ~BluetoothDetailedView() override { 186 ~BluetoothDetailedView() override {
185 // Stop discovering bluetooth devices when exiting BT detailed view. 187 // Stop discovering bluetooth devices when exiting BT detailed view.
186 BluetoothStopDiscovering(); 188 BluetoothStopDiscovering();
187 } 189 }
188 190
189 void Update() { 191 void Update() {
190 BluetoothStartDiscovering(); 192 BluetoothStartDiscovering();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700); 363 CreateVectorIcon(gfx::VectorIconId::CHECK_CIRCLE, gfx::kGoogleGreen700);
362 container->AddRightIcon(check_mark, check_mark.width()); 364 container->AddRightIcon(check_mark, check_mark.width());
363 container->SetRightIconVisible(checked); 365 container->SetRightIconVisible(checked);
364 container->text_label()->SetEnabled(enabled); 366 container->text_label()->SetEnabled(enabled);
365 scroll_content()->AddChildView(container); 367 scroll_content()->AddChildView(container);
366 return container; 368 return container;
367 } 369 }
368 370
369 // Add settings entries. 371 // Add settings entries.
370 void AppendSettingsEntries() { 372 void AppendSettingsEntries() {
373 // Do not append the bottom button row in material design; this is replaced
374 // by the settings button in the header row.
375 if (MaterialDesignController::IsSystemTrayMenuMaterial())
376 return;
377
371 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings()) 378 if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings())
372 return; 379 return;
373 380
374 // Add bluetooth device requires a browser window, hide it for non logged in 381 // Add bluetooth device requires a browser window, hide it for non logged in
375 // user. 382 // user.
376 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || 383 if (!CanOpenWebUISettings(login_))
377 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) {
378 return; 384 return;
379 }
380 385
381 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 386 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
382 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 387 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
383 HoverHighlightView* container = new HoverHighlightView(this); 388 HoverHighlightView* container = new HoverHighlightView(this);
384 container->AddLabel( 389 container->AddLabel(
385 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES), 390 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_MANAGE_DEVICES),
386 gfx::ALIGN_LEFT, false /* highlight */); 391 gfx::ALIGN_LEFT, false /* highlight */);
387 container->SetEnabled(delegate->GetBluetoothAvailable()); 392 container->SetEnabled(delegate->GetBluetoothAvailable());
388 AddChildView(container); 393 AddChildView(container);
389 manage_devices_ = container; 394 manage_devices_ = container;
(...skipping 27 matching lines...) Expand all
417 item_container->RemoveAllChildViews(true); 422 item_container->RemoveAllChildViews(true);
418 static_cast<HoverHighlightView*>(item_container) 423 static_cast<HoverHighlightView*>(item_container)
419 ->AddCheckableLabel(display_name, true /* highlight */, false); 424 ->AddCheckableLabel(display_name, true /* highlight */, false);
420 scroll_content()->SizeToPreferredSize(); 425 scroll_content()->SizeToPreferredSize();
421 static_cast<views::View*>(scroller())->Layout(); 426 static_cast<views::View*>(scroller())->Layout();
422 } 427 }
423 } 428 }
424 429
425 // TrayDetailsView: 430 // TrayDetailsView:
426 void HandleViewClicked(views::View* view) override { 431 void HandleViewClicked(views::View* view) override {
427 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
428 if (view == manage_devices_) { 432 if (view == manage_devices_) {
429 delegate->ManageBluetoothDevices(); 433 ShowSettings();
430 owner()->system_tray()->CloseSystemBubble();
431 return; 434 return;
432 } 435 }
433 436
437 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
434 if (view == enable_bluetooth_) { 438 if (view == enable_bluetooth_) {
435 WmShell::Get()->RecordUserMetricsAction( 439 WmShell::Get()->RecordUserMetricsAction(
436 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED 440 delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED
437 : UMA_STATUS_AREA_BLUETOOTH_ENABLED); 441 : UMA_STATUS_AREA_BLUETOOTH_ENABLED);
438 delegate->ToggleBluetooth(); 442 delegate->ToggleBluetooth();
439 return; 443 return;
440 } 444 }
441 445
442 if (!delegate->GetBluetoothEnabled()) 446 if (!delegate->GetBluetoothEnabled())
443 return; 447 return;
444 448
445 std::map<views::View*, std::string>::iterator find; 449 std::map<views::View*, std::string>::iterator find;
446 find = device_map_.find(view); 450 find = device_map_.find(view);
447 if (find == device_map_.end()) 451 if (find == device_map_.end())
448 return; 452 return;
449 453
450 const std::string device_id = find->second; 454 const std::string device_id = find->second;
451 if (FoundDevice(device_id, connecting_devices_, nullptr)) 455 if (FoundDevice(device_id, connecting_devices_, nullptr))
452 return; 456 return;
453 457
454 UpdateClickedDevice(device_id, view); 458 UpdateClickedDevice(device_id, view);
455 delegate->ConnectToBluetoothDevice(device_id); 459 delegate->ConnectToBluetoothDevice(device_id);
456 } 460 }
457 461
458 void HandleButtonPressed(views::Button* sender, 462 void HandleButtonPressed(views::Button* sender,
459 const ui::Event& event) override { 463 const ui::Event& event) override {
460 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 464 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
461 if (sender == toggle_) 465 if (sender == toggle_)
462 WmShell::Get()->system_tray_delegate()->ToggleBluetooth(); 466 WmShell::Get()->system_tray_delegate()->ToggleBluetooth();
467 else if (sender == settings_)
468 ShowSettings();
463 else 469 else
464 NOTREACHED(); 470 NOTREACHED();
465 return; 471 return;
466 } 472 }
467 473
468 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 474 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
469 if (sender == toggle_bluetooth_) 475 if (sender == toggle_bluetooth_)
470 delegate->ToggleBluetooth(); 476 delegate->ToggleBluetooth();
471 else 477 else
472 NOTREACHED(); 478 NOTREACHED();
473 } 479 }
474 480
475 void CreateExtraTitleRowButtons() override { 481 void CreateExtraTitleRowButtons() override {
476 if (login_ == LoginStatus::LOCKED) 482 if (login_ == LoginStatus::LOCKED)
477 return; 483 return;
478 484
479 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 485 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
480 toggle_ = title_row()->AddToggleButton(this); 486 toggle_ = title_row()->AddToggleButton(this);
487 settings_ = title_row()->AddSettingsButton(this, login_);
481 return; 488 return;
482 } 489 }
483 490
484 throbber_ = new ThrobberView; 491 throbber_ = new ThrobberView;
485 throbber_->SetTooltipText( 492 throbber_->SetTooltipText(
486 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); 493 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING));
487 title_row()->AddViewToRowNonMd(throbber_, false); 494 title_row()->AddViewToRowNonMd(throbber_, false);
488 495
489 // Do not allow toggling bluetooth in the lock screen. 496 // Do not allow toggling bluetooth in the lock screen.
490 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 497 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
491 toggle_bluetooth_ = 498 toggle_bluetooth_ =
492 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, 499 new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
493 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, 500 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
494 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, 501 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
495 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, 502 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER,
496 IDS_ASH_STATUS_TRAY_BLUETOOTH); 503 IDS_ASH_STATUS_TRAY_BLUETOOTH);
497 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); 504 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled());
498 toggle_bluetooth_->SetTooltipText( 505 toggle_bluetooth_->SetTooltipText(
499 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); 506 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH));
500 toggle_bluetooth_->SetToggledTooltipText( 507 toggle_bluetooth_->SetToggledTooltipText(
501 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); 508 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH));
502 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); 509 toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false);
503 title_row()->AddViewToRowNonMd(toggle_bluetooth_, true); 510 title_row()->AddViewToRowNonMd(toggle_bluetooth_, true);
504 } 511 }
505 512
513 void ShowSettings() {
514 if (CanOpenWebUISettings(login_)) {
515 WmShell::Get()->system_tray_delegate()->ManageBluetoothDevices();
516 owner()->system_tray()->CloseSystemBubble();
517 }
518 }
519
506 LoginStatus login_; 520 LoginStatus login_;
507 521
508 std::map<views::View*, std::string> device_map_; 522 std::map<views::View*, std::string> device_map_;
523
524 // Not used in material design.
509 views::View* manage_devices_; 525 views::View* manage_devices_;
510 526
511 // Not used in material design. 527 // Not used in material design.
512 ThrobberView* throbber_; 528 ThrobberView* throbber_;
513 529
514 // Not used in material design. 530 // Not used in material design.
515 TrayPopupHeaderButton* toggle_bluetooth_; 531 TrayPopupHeaderButton* toggle_bluetooth_;
516 532
517 HoverHighlightView* enable_bluetooth_; 533 HoverHighlightView* enable_bluetooth_;
518 BluetoothDeviceList connected_devices_; 534 BluetoothDeviceList connected_devices_;
519 BluetoothDeviceList connecting_devices_; 535 BluetoothDeviceList connecting_devices_;
520 BluetoothDeviceList paired_not_connected_devices_; 536 BluetoothDeviceList paired_not_connected_devices_;
521 BluetoothDeviceList discovered_not_paired_devices_; 537 BluetoothDeviceList discovered_not_paired_devices_;
522 538
523 // The on/off toggle button used in material design. 539 // The on/off toggle button used in material design.
524 views::ToggleButton* toggle_; 540 views::ToggleButton* toggle_;
525 541
542 // Only used in material design.
543 views::Button* settings_;
544
526 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); 545 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
527 }; 546 };
528 547
529 } // namespace tray 548 } // namespace tray
530 549
531 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) 550 TrayBluetooth::TrayBluetooth(SystemTray* system_tray)
532 : SystemTrayItem(system_tray, UMA_BLUETOOTH), 551 : SystemTrayItem(system_tray, UMA_BLUETOOTH),
533 default_(nullptr), 552 default_(nullptr),
534 detailed_(nullptr) { 553 detailed_(nullptr) {
535 WmShell::Get()->system_tray_notifier()->AddBluetoothObserver(this); 554 WmShell::Get()->system_tray_notifier()->AddBluetoothObserver(this);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 detailed_->Update(); 600 detailed_->Update();
582 } 601 }
583 602
584 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 603 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
585 if (!detailed_) 604 if (!detailed_)
586 return; 605 return;
587 detailed_->Update(); 606 detailed_->Update();
588 } 607 }
589 608
590 } // namespace ash 609 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/cast/tray_cast.cc ('k') | ash/common/system/chromeos/network/network_state_list_detailed_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698