Skip to content

Commit

Permalink
focus-mode: Add quick settings button
Browse files Browse the repository at this point in the history
Add the focus mode button to quick settings behind the flag.

Currently use placeholder text and icon, will be updated later with the
specs.

BUG=b:286931299

Change-Id: Ic7975afc782e39c30e8d7d08ba7f86cc33352a50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4617591
Reviewed-by: Jiaming Cheng <jiamingc@chromium.org>
Commit-Queue: Richard Chui <richui@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: Daniel Andersson <dandersson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1159159}
  • Loading branch information
Richard Chui authored and Chromium LUCI CQ committed Jun 16, 2023
1 parent 470d952 commit 76542f8
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,8 @@ component("ash") {
"wm/float/tablet_mode_float_window_resizer.h",
"wm/float/tablet_mode_tuck_education.cc",
"wm/float/tablet_mode_tuck_education.h",
"wm/focus_mode/focus_mode_feature_pod_controller.cc",
"wm/focus_mode/focus_mode_feature_pod_controller.h",
"wm/fullscreen_window_finder.cc",
"wm/fullscreen_window_finder.h",
"wm/gestures/back_gesture/back_gesture_affordance.cc",
Expand Down
3 changes: 2 additions & 1 deletion ash/constants/quick_settings_catalogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ enum class QsFeatureCatalogName {
kShelfParty_DEPRECATED = 15,
kAutozoom = 16,
kHotspot = 17,
kMaxValue = kHotspot
kFocusMode = 18,
kMaxValue = kFocusMode
};

// A catalog that registers all the sliders on the Quick Settings page (also
Expand Down
12 changes: 12 additions & 0 deletions ash/system/unified/unified_system_tray_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "ash/system/unified/unified_system_tray_model.h"
#include "ash/system/unified/unified_system_tray_view.h"
#include "ash/system/unified/user_chooser_detailed_view_controller.h"
#include "ash/wm/focus_mode/focus_mode_feature_pod_controller.h"
#include "ash/wm/lock_state_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/functional/bind.h"
Expand Down Expand Up @@ -503,6 +504,10 @@ void UnifiedSystemTrayController::ShowAccessibilityDetailedView() {
std::make_unique<UnifiedAccessibilityDetailedViewController>(this));
}

void UnifiedSystemTrayController::ShowFocusModeDetailedView() {
// TODO(b/286931532): Create the Focus Mode detailed view.
}

void UnifiedSystemTrayController::ShowVPNDetailedView() {
base::RecordAction(base::UserMetricsAction("StatusArea_VPN_Detailed"));
ShowDetailedView(std::make_unique<UnifiedVPNDetailedViewController>(this));
Expand Down Expand Up @@ -694,6 +699,9 @@ void UnifiedSystemTrayController::InitFeaturePods() {
AddFeaturePodItem(std::make_unique<NetworkFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<BluetoothFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<AccessibilityFeaturePodController>(this));
if (base::FeatureList::IsEnabled(features::kFocusMode)) {
AddFeaturePodItem(std::make_unique<FocusModeFeaturePodController>(this));
}
AddFeaturePodItem(std::make_unique<QuietModeFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<RotationLockFeaturePodController>());
AddFeaturePodItem(std::make_unique<PrivacyScreenFeaturePodController>());
Expand Down Expand Up @@ -760,6 +768,10 @@ void UnifiedSystemTrayController::InitFeatureTiles() {
cast_and_rotation_tiles_are_compact);
create_tile(std::make_unique<AccessibilityFeaturePodController>(this),
feature_pod_controllers_, tiles);
if (base::FeatureList::IsEnabled(features::kFocusMode)) {
create_tile(std::make_unique<FocusModeFeaturePodController>(this),
feature_pod_controllers_, tiles);
}
create_tile(std::make_unique<NearbyShareFeaturePodController>(this),
feature_pod_controllers_, tiles);
create_tile(std::make_unique<LocaleFeaturePodController>(this),
Expand Down
2 changes: 2 additions & 0 deletions ash/system/unified/unified_system_tray_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class ASH_EXPORT UnifiedSystemTrayController
void ShowCastDetailedView();
// Show the detailed view of accessibility. Called from the view.
void ShowAccessibilityDetailedView();
// Show the detailed view of focus mode. Called from the view.
void ShowFocusModeDetailedView();
// Show the detailed view of VPN. Called from the view.
void ShowVPNDetailedView();
// Show the detailed view of IME. Called from the view.
Expand Down
83 changes: 83 additions & 0 deletions ash/wm/focus_mode/focus_mode_feature_pod_controller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/wm/focus_mode/focus_mode_feature_pod_controller.h"

#include "ash/constants/ash_features.h"
#include "ash/constants/quick_settings_catalogs.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/feature_tile.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "base/check.h"
#include "base/functional/bind.h"

namespace ash {

namespace {

// TODO: replace these placeholders with string ids later.
constexpr const char16_t kLabelText[] = u"Focus Mode";
constexpr const char16_t kSubLabelText[] = u"30 mins";

} // namespace

FocusModeFeaturePodController::FocusModeFeaturePodController(
UnifiedSystemTrayController* tray_controller)
: tray_controller_(tray_controller) {}

FocusModeFeaturePodController::~FocusModeFeaturePodController() = default;

FeaturePodButton* FocusModeFeaturePodController::CreateButton() {
CHECK(!button_);
CHECK(!features::IsQsRevampEnabled());
std::unique_ptr<FeaturePodButton> button =
std::make_unique<FeaturePodButton>(/*controller=*/this);
button_ = button.get();
button_->ShowDetailedViewArrow();
button_->SetVectorIcon(kCaptureModeIcon);
button_->SetLabel(kLabelText);
button_->SetSubLabel(kSubLabelText);
button_->icon_button()->SetTooltipText(kLabelText);
button_->SetLabelTooltip(kSubLabelText);
button_->SetToggled(false);
return button.release();
}

std::unique_ptr<FeatureTile> FocusModeFeaturePodController::CreateTile(
bool compact) {
CHECK(features::IsQsRevampEnabled());
auto tile = std::make_unique<FeatureTile>(
base::BindRepeating(&FocusModeFeaturePodController::OnLabelPressed,
weak_factory_.GetWeakPtr()));
tile_ = tile.get();
tile_->SetIconClickable(true);
tile_->SetIconClickCallback(
base::BindRepeating(&FocusModeFeaturePodController::OnIconPressed,
weak_factory_.GetWeakPtr()));
tile_->CreateDecorativeDrillInArrow();
tile_->SetVectorIcon(kCaptureModeIcon);
tile_->SetLabel(kLabelText);
tile_->SetSubLabel(kSubLabelText);
tile_->SetIconButtonTooltipText(kLabelText);
tile_->SetTooltipText(kLabelText);
tile_->SetToggled(false);
return tile;
}

QsFeatureCatalogName FocusModeFeaturePodController::GetCatalogName() {
return QsFeatureCatalogName::kFocusMode;
}

void FocusModeFeaturePodController::OnIconPressed() {
// TODO(b/286931230): Toggle Focus Mode.
TrackToggleUMA(/*target_toggle_state=*/false);
}

void FocusModeFeaturePodController::OnLabelPressed() {
TrackDiveInUMA();
tray_controller_->ShowFocusModeDetailedView();
}

} // namespace ash
50 changes: 50 additions & 0 deletions ash/wm/focus_mode/focus_mode_feature_pod_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WM_FOCUS_MODE_FOCUS_MODE_FEATURE_POD_CONTROLLER_H_
#define ASH_WM_FOCUS_MODE_FOCUS_MODE_FEATURE_POD_CONTROLLER_H_

#include "ash/constants/quick_settings_catalogs.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"

namespace ash {

class FeaturePodButton;
class UnifiedSystemTrayController;

// Controller of the feature pod button that allows users to toggle whether
// Focus Mode is enabled or disabled, and that allows users to navigate to a
// more detailed page with the Focus Mode settings.
class ASH_EXPORT FocusModeFeaturePodController
: public FeaturePodControllerBase {
public:
explicit FocusModeFeaturePodController(
UnifiedSystemTrayController* tray_controller);
FocusModeFeaturePodController(const FocusModeFeaturePodController&) = delete;
FocusModeFeaturePodController& operator=(
const FocusModeFeaturePodController&) = delete;
~FocusModeFeaturePodController() override;

// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override;
std::unique_ptr<FeatureTile> CreateTile(bool compact = false) override;
QsFeatureCatalogName GetCatalogName() override;
void OnIconPressed() override;
void OnLabelPressed() override;

private:
const raw_ptr<UnifiedSystemTrayController, ExperimentalAsh> tray_controller_;
raw_ptr<FeaturePodButton, ExperimentalAsh> button_ =
nullptr; // Owned by views hierarchy.
raw_ptr<FeatureTile, ExperimentalAsh> tile_ =
nullptr; // Owned by views hierarchy.

base::WeakPtrFactory<FocusModeFeaturePodController> weak_factory_{this};
};

} // namespace ash

#endif // ASH_WM_FOCUS_MODE_FOCUS_MODE_FEATURE_POD_CONTROLLER_H_

0 comments on commit 76542f8

Please sign in to comment.