Chromium Code Reviews| Index: ash/common/system/chromeos/bluetooth/tray_bluetooth.cc |
| diff --git a/ash/common/system/chromeos/bluetooth/tray_bluetooth.cc b/ash/common/system/chromeos/bluetooth/tray_bluetooth.cc |
| index 9480fbade168eb278392c7430358e24ff745637a..4fdf504915b4c4f66103cfc429d4df8ebbf9447e 100644 |
| --- a/ash/common/system/chromeos/bluetooth/tray_bluetooth.cc |
| +++ b/ash/common/system/chromeos/bluetooth/tray_bluetooth.cc |
| @@ -16,7 +16,6 @@ |
| #include "ash/common/system/tray/tray_details_view.h" |
| #include "ash/common/system/tray/tray_item_more.h" |
| #include "ash/common/system/tray/tray_popup_header_button.h" |
| -#include "ash/common/system/tray/view_click_listener.h" |
| #include "ash/common/wm_shell.h" |
| #include "grit/ash_resources.h" |
| #include "grit/ash_strings.h" |
| @@ -107,16 +106,14 @@ class BluetoothDefaultView : public TrayItemMore { |
| DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); |
| }; |
| -class BluetoothDetailedView : public TrayDetailsView, |
| - public ViewClickListener, |
| - public views::ButtonListener { |
| +class BluetoothDetailedView : public TrayDetailsView { |
| public: |
| BluetoothDetailedView(SystemTrayItem* owner, LoginStatus login) |
| : TrayDetailsView(owner), |
| login_(login), |
| - manage_devices_(NULL), |
| - toggle_bluetooth_(NULL), |
| - enable_bluetooth_(NULL) { |
| + manage_devices_(nullptr), |
| + toggle_bluetooth_(nullptr), |
| + enable_bluetooth_(nullptr) { |
| CreateItems(); |
| } |
| @@ -139,28 +136,32 @@ class BluetoothDetailedView : public TrayDetailsView, |
| void CreateItems() { |
| CreateScrollableList(); |
| AppendSettingsEntries(); |
| - AppendHeaderEntry(); |
| + CreateTitleRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); |
| } |
| void BluetoothStartDiscovering() { |
| + // TODO(tdanderson|fukino): The material design version of the detailed |
| + // view should use an infinite loader bar instead of a throbber. See |
| + // crbug.com/632128. |
| + const bool md = MaterialDesignController::IsSystemTrayMenuMaterial(); |
|
varkha
2016/08/31 20:28:13
nit: s/md/material for consistency and I thought w
tdanderson
2016/08/31 22:24:15
Removed.
|
| SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| - bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| - bool bluetooth_discovering = delegate->GetBluetoothDiscovering(); |
| - if (bluetooth_discovering) { |
| - throbber_->Start(); |
| + if (delegate->GetBluetoothDiscovering()) { |
| + if (!md) |
|
varkha
2016/08/31 20:28:14
What do you think about replacing this with "if (t
tdanderson
2016/08/31 22:24:15
Good idea, changed.
|
| + throbber_->Start(); |
| return; |
| } |
| - throbber_->Stop(); |
| - if (bluetooth_enabled) { |
| + if (!md) |
|
varkha
2016/08/31 20:28:14
ditto.
tdanderson
2016/08/31 22:24:15
Done.
|
| + throbber_->Stop(); |
| + if (delegate->GetBluetoothEnabled()) |
| delegate->BluetoothStartDiscovering(); |
| - } |
| } |
| void BluetoothStopDiscovering() { |
| SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| if (delegate && delegate->GetBluetoothDiscovering()) { |
| delegate->BluetoothStopDiscovering(); |
| - throbber_->Stop(); |
| + if (!MaterialDesignController::IsSystemTrayMenuMaterial()) |
|
varkha
2016/08/31 20:28:14
ditto.
tdanderson
2016/08/31 22:24:15
Done.
|
| + throbber_->Stop(); |
| } |
| } |
| @@ -201,34 +202,6 @@ class BluetoothDetailedView : public TrayDetailsView, |
| new_discovered_not_paired_devices); |
| } |
| - void AppendHeaderEntry() { |
| - CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); |
| - |
| - if (login_ == LoginStatus::LOCKED) |
| - return; |
| - |
| - throbber_ = new ThrobberView; |
| - throbber_->SetTooltipText( |
| - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); |
| - footer()->AddView(throbber_, false /* separator */); |
| - |
| - // Do not allow toggling bluetooth in the lock screen. |
| - SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| - toggle_bluetooth_ = |
| - new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, |
| - IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, |
| - IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, |
| - IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, |
| - IDS_ASH_STATUS_TRAY_BLUETOOTH); |
| - toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); |
| - toggle_bluetooth_->SetTooltipText( |
| - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); |
| - toggle_bluetooth_->SetToggledTooltipText( |
| - l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); |
| - toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); |
| - footer()->AddButton(toggle_bluetooth_); |
| - } |
| - |
| void UpdateHeaderEntry() { |
| if (toggle_bluetooth_) { |
| toggle_bluetooth_->SetToggled( |
| @@ -239,7 +212,7 @@ class BluetoothDetailedView : public TrayDetailsView, |
| void UpdateDeviceScrollList() { |
| device_map_.clear(); |
| scroll_content()->RemoveAllChildViews(true); |
| - enable_bluetooth_ = NULL; |
| + enable_bluetooth_ = nullptr; |
| SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| @@ -353,35 +326,43 @@ class BluetoothDetailedView : public TrayDetailsView, |
| } |
| } |
| - // Overridden from ViewClickListener. |
| - void OnViewClicked(views::View* sender) override { |
| + // TrayDetailsView: |
| + void HandleViewClicked(views::View* view) override { |
| SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| - if (sender == footer()->content()) { |
| - TransitionToDefaultView(); |
| - } else if (sender == manage_devices_) { |
| + if (view == manage_devices_) { |
| delegate->ManageBluetoothDevices(); |
| - } else if (sender == enable_bluetooth_) { |
| + return; |
| + } |
| + |
| + if (view == enable_bluetooth_) { |
| WmShell::Get()->RecordUserMetricsAction( |
| delegate->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED |
| : UMA_STATUS_AREA_BLUETOOTH_ENABLED); |
| delegate->ToggleBluetooth(); |
| - } else { |
| - if (!delegate->GetBluetoothEnabled()) |
| - return; |
| - std::map<views::View*, std::string>::iterator find; |
| - find = device_map_.find(sender); |
| - if (find == device_map_.end()) |
| - return; |
| - const std::string device_id = find->second; |
| - if (FoundDevice(device_id, connecting_devices_, NULL)) |
| - return; |
| - UpdateClickedDevice(device_id, sender); |
| - delegate->ConnectToBluetoothDevice(device_id); |
| + return; |
| } |
| + |
| + if (!delegate->GetBluetoothEnabled()) |
| + return; |
| + |
| + std::map<views::View*, std::string>::iterator find; |
| + find = device_map_.find(view); |
| + if (find == device_map_.end()) |
| + return; |
| + |
| + const std::string device_id = find->second; |
| + if (FoundDevice(device_id, connecting_devices_, nullptr)) |
| + return; |
| + |
| + UpdateClickedDevice(device_id, view); |
| + delegate->ConnectToBluetoothDevice(device_id); |
| } |
| - // Overridden from ButtonListener. |
| - void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| + void HandleButtonPressed(views::Button* sender, |
| + const ui::Event& event) override { |
| + if (MaterialDesignController::IsSystemTrayMenuMaterial()) |
| + return; |
| + |
| SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| if (sender == toggle_bluetooth_) |
| delegate->ToggleBluetooth(); |
| @@ -389,12 +370,48 @@ class BluetoothDetailedView : public TrayDetailsView, |
| NOTREACHED(); |
| } |
| + void CreateExtraTitleRowButtons() override { |
| + // TODO(tdanderson|fukino): The material design version of the detailed |
| + // view requires different buttons. See crbug.com/632128. |
| + if (MaterialDesignController::IsSystemTrayMenuMaterial()) |
| + return; |
| + |
| + if (login_ == LoginStatus::LOCKED) |
| + return; |
| + |
| + throbber_ = new ThrobberView; |
| + throbber_->SetTooltipText( |
| + l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING)); |
| + title_row()->AddView(throbber_, false /* separator */); |
| + |
| + // Do not allow toggling bluetooth in the lock screen. |
| + SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| + toggle_bluetooth_ = |
| + new TrayPopupHeaderButton(this, IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, |
| + IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, |
| + IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, |
| + IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, |
| + IDS_ASH_STATUS_TRAY_BLUETOOTH); |
| + toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); |
| + toggle_bluetooth_->SetTooltipText( |
| + l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); |
| + toggle_bluetooth_->SetToggledTooltipText( |
| + l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); |
| + toggle_bluetooth_->EnableCanvasFlippingForRTLUI(false); |
| + title_row()->AddButton(toggle_bluetooth_); |
| + } |
| + |
| LoginStatus login_; |
| std::map<views::View*, std::string> device_map_; |
| views::View* manage_devices_; |
| + |
| + // Not used in material design. |
| ThrobberView* throbber_; |
| + |
| + // Not used in material design. |
| TrayPopupHeaderButton* toggle_bluetooth_; |
| + |
| HoverHighlightView* enable_bluetooth_; |
| BluetoothDeviceList connected_devices_; |
| BluetoothDeviceList connecting_devices_; |