Commit 3e2247dd authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add Bluetooth feature pod button.

This CL adds a feature pod button for Bluetooth. By clicking on the
button, it will show bluetooth detailed view of the existing SystemTray.
This behavior is described as Development Stage 1 in the design doc:
go/cros-qs-restyling

TEST=manual
BUG=813499

Change-Id: I130301b9a25d31a520b1a0bb8f78839aa4b91b73
Reviewed-on: https://chromium-review.googlesource.com/948164
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542067}
parent f18a39fd
......@@ -483,6 +483,8 @@ component("ash") {
"system/audio/tray_audio.h",
"system/audio/volume_view.cc",
"system/audio/volume_view.h",
"system/bluetooth/bluetooth_feature_pod_controller.cc",
"system/bluetooth/bluetooth_feature_pod_controller.h",
"system/bluetooth/bluetooth_notification_controller.cc",
"system/bluetooth/bluetooth_notification_controller.h",
"system/bluetooth/bluetooth_observer.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/bluetooth/bluetooth_feature_pod_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/bluetooth/bluetooth_power_controller.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
BluetoothFeaturePodController::BluetoothFeaturePodController(
UnifiedSystemTrayController* tray_controller)
: tray_controller_(tray_controller) {
Shell::Get()->system_tray_notifier()->AddBluetoothObserver(this);
}
BluetoothFeaturePodController::~BluetoothFeaturePodController() {
Shell::Get()->system_tray_notifier()->RemoveBluetoothObserver(this);
}
FeaturePodButton* BluetoothFeaturePodController::CreateButton() {
DCHECK(!button_);
button_ = new FeaturePodButton(this);
button_->SetVectorIcon(kSystemMenuBluetoothIcon);
UpdateButton();
return button_;
}
void BluetoothFeaturePodController::OnPressed() {
tray_controller_->ShowBluetoothDetailedView();
}
void BluetoothFeaturePodController::UpdateButton() {
bool is_available =
Shell::Get()->tray_bluetooth_helper()->GetBluetoothAvailable();
button_->SetVisible(is_available);
if (!is_available)
return;
bool is_enabled =
Shell::Get()->tray_bluetooth_helper()->GetBluetoothEnabled();
button_->SetToggled(is_enabled);
button_->SetLabel(l10n_util::GetStringUTF16(
is_enabled ? IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED
: IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED));
}
void BluetoothFeaturePodController::OnBluetoothRefresh() {
UpdateButton();
}
void BluetoothFeaturePodController::OnBluetoothDiscoveringChanged() {
UpdateButton();
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_
#define ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "base/macros.h"
#include "base/strings/string16.h"
namespace ash {
class UnifiedSystemTrayController;
// Controller of a feature pod button of bluetooth.
class BluetoothFeaturePodController : public FeaturePodControllerBase,
public BluetoothObserver {
public:
BluetoothFeaturePodController(UnifiedSystemTrayController* tray_controller);
~BluetoothFeaturePodController() override;
// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override;
void OnPressed() override;
private:
void UpdateButton();
// BluetoothObserver:
void OnBluetoothRefresh() override;
void OnBluetoothDiscoveringChanged() override;
// Unowned.
UnifiedSystemTrayController* const tray_controller_;
FeaturePodButton* button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(BluetoothFeaturePodController);
};
} // namespace ash
#endif // ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_
......@@ -270,7 +270,8 @@ void SystemTray::CreateItems() {
tray_network_ = new TrayNetwork(this);
AddTrayItem(base::WrapUnique(tray_network_));
AddTrayItem(std::make_unique<TrayVPN>(this));
AddTrayItem(std::make_unique<TrayBluetooth>(this));
tray_bluetooth_ = new TrayBluetooth(this);
AddTrayItem(base::WrapUnique(tray_bluetooth_));
tray_cast_ = new TrayCast(this);
AddTrayItem(base::WrapUnique(tray_cast_));
screen_capture_tray_item_ = new ScreenCaptureTrayItem(this);
......@@ -401,6 +402,10 @@ TrayAudio* SystemTray::GetTrayAudio() const {
return tray_audio_;
}
TrayBluetooth* SystemTray::GetTrayBluetooth() const {
return tray_bluetooth_;
}
void SystemTray::CanSwitchAwayFromActiveUser(
base::OnceCallback<void(bool)> callback) {
// If neither screen sharing nor capturing is going on we can immediately
......
......@@ -26,6 +26,7 @@ class SystemBubbleWrapper;
class SystemTrayItem;
class TrayAccessibility;
class TrayAudio;
class TrayBluetooth;
class TrayCapsLock;
class TrayCast;
class TrayEnterprise;
......@@ -119,6 +120,8 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
// Returns TrayAudio object if present or null otherwise.
TrayAudio* GetTrayAudio() const;
// Returns TrayBluetooth object if present or null otherwise.
TrayBluetooth* GetTrayBluetooth() const;
// Determines if it's ok to switch away from the currently active user. Screen
// casting may block this (or at least throw up a confirmation dialog). Calls
......@@ -214,6 +217,7 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
// These objects are not owned by this class.
TrayAccessibility* tray_accessibility_ = nullptr;
TrayAudio* tray_audio_ = nullptr;
TrayBluetooth* tray_bluetooth_ = nullptr;
TrayCapsLock* tray_caps_lock_ = nullptr;
TrayCast* tray_cast_ = nullptr;
TrayEnterprise* tray_enterprise_ = nullptr;
......
......@@ -4,6 +4,7 @@
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_controller.h"
......@@ -12,7 +13,8 @@
namespace ash {
UnifiedSystemTrayBubble::UnifiedSystemTrayBubble(UnifiedSystemTray* tray)
: controller_(std::make_unique<UnifiedSystemTrayController>()),
: controller_(std::make_unique<UnifiedSystemTrayController>(
tray->shelf()->GetStatusAreaWidget()->system_tray())),
tray_(tray) {
views::TrayBubbleView::InitParams init_params;
init_params.anchor_alignment = views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
......
......@@ -8,8 +8,11 @@
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/system/bluetooth/bluetooth_feature_pod_controller.h"
#include "ash/system/bluetooth/tray_bluetooth.h"
#include "ash/system/night_light/night_light_feature_pod_controller.h"
#include "ash/system/rotation/rotation_lock_feature_pod_controller.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_controller.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "ash/system/unified/quiet_mode_feature_pod_controller.h"
......@@ -20,7 +23,9 @@
namespace ash {
UnifiedSystemTrayController::UnifiedSystemTrayController() = default;
UnifiedSystemTrayController::UnifiedSystemTrayController(
SystemTray* system_tray)
: system_tray_(system_tray) {}
UnifiedSystemTrayController::~UnifiedSystemTrayController() = default;
......@@ -58,7 +63,18 @@ void UnifiedSystemTrayController::ToggleExpanded() {
// TODO(tetsui): Implement.
}
void UnifiedSystemTrayController::ShowBluetoothDetailedView() {
// TODO(tetsui): Implement UnifiedSystemTray's Bluetooth detailed view.
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayBluetooth(), 0,
BubbleCreationType::BUBBLE_USE_EXISTING);
}
void UnifiedSystemTrayController::InitFeaturePods() {
AddFeaturePodItem(std::make_unique<BluetoothFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<QuietModeFeaturePodController>());
AddFeaturePodItem(std::make_unique<RotationLockFeaturePodController>());
AddFeaturePodItem(std::make_unique<NightLightFeaturePodController>());
......@@ -67,7 +83,6 @@ void UnifiedSystemTrayController::InitFeaturePods() {
// TODO(tetsui): Add more feature pod items in spec:
// * NetworkFeaturePodController
// * BluetoothFeaturePodController
}
void UnifiedSystemTrayController::AddFeaturePodItem(
......
......@@ -13,12 +13,15 @@
namespace ash {
class FeaturePodControllerBase;
class SystemTray;
class UnifiedSystemTrayView;
// Controller class of UnifiedSystemTrayView. Handles events of the view.
class UnifiedSystemTrayController {
public:
UnifiedSystemTrayController();
// |system_tray| is used to show detailed views which are still not
// implemented on UnifiedSystemTray.
UnifiedSystemTrayController(SystemTray* system_tray);
~UnifiedSystemTrayController();
// Create the view. The created view is unowned.
......@@ -35,6 +38,9 @@ class UnifiedSystemTrayController {
// Toggle expanded state of UnifiedSystemTrayView. Called from the view.
void ToggleExpanded();
// Show the detailed view of bluetooth. Called from the view.
void ShowBluetoothDetailedView();
private:
// Initialize feature pod controllers and their views.
// If you want to add a new feature pod item, you have to add here.
......@@ -43,6 +49,11 @@ class UnifiedSystemTrayController {
// Add the feature pod controller and its view.
void AddFeaturePodItem(std::unique_ptr<FeaturePodControllerBase> controller);
// Only used to show detailed views which are still not implemented on
// UnifiedSystemTray. Unowned.
// TODO(tetsui): Remove reference to |system_tray|.
SystemTray* const system_tray_;
// Unowned. Owned by Views hierarchy.
UnifiedSystemTrayView* unified_view_ = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment