0

gd: Add Toolbar Sub-Label

Adds the sub-label to the toolbar compact FeatureTile. This sub-label
changes dynamically depending on whether the toolbar tile is enabled or
disabled.

Bug: b:300928711
Demo: b/300928711#comment2
Test: Added unit test.
Change-Id: I3fb04e7e78ed22c7f601334b50414c4521081cd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4874496
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Commit-Queue: Gina Domergue <gdomergue@google.com>
Cr-Commit-Position: refs/heads/main@{#1197943}
This commit is contained in:
Gina Domergue
2023-09-18 19:07:20 +00:00
committed by Chromium LUCI CQ
parent e4f502cabf
commit 5ada3d148a
5 changed files with 56 additions and 14 deletions

@ -7095,6 +7095,9 @@ To shut down the device, press and hold the power button on the device again.
<message name="IDS_ASH_GAME_DASHBOARD_GAME_DASHBOARD_BUTTON_TITLE" desc="The title of the main Game Dashboard button.">
Game Dashboard
</message>
<message name="IDS_ASH_GAME_DASHBOARD_HIDDEN_STATUS" translateable="false" desc="The hidden state for compact Game Dashboard tile sub-labels.">
Hidden
</message>
<message name="IDS_ASH_GAME_DASHBOARD_RECORD_GAME_TILE_BUTTON_TITLE" translateable="false" desc="The display name for the Game Dashboard record game tile.">
Record game
</message>
@ -7113,6 +7116,9 @@ To shut down the device, press and hold the power button on the device again.
<message name="IDS_ASH_GAME_DASHBOARD_TOOLBAR_TILE_BUTTON_TITLE" translateable="false" desc="The display name for the Game Dashboard toolbar tile.">
Toolbar
</message>
<message name="IDS_ASH_GAME_DASHBOARD_VISIBLE_STATUS" translateable="false" desc="The visible state for compact Game Dashboard tile sub-labels.">
Visible
</message>
<!-- Game Dashboard / Game Controls strings -->
<message name="IDS_ASH_GAME_DASHBOARD_GC_SET_UP_SUB_TITLE" desc="The subtitle on the menu details row of Game Controls when no action is set up and Setup button shows up.">

@ -0,0 +1 @@
887ef16bbb6581df7a68e867170fa01fb8ad7ad3

@ -0,0 +1 @@
84066391d42dc383abd16918bc347daeb4df41b7

@ -53,6 +53,10 @@ using ToolbarSnapLocation = GameDashboardContext::ToolbarSnapLocation;
static const int kToolbarEdgePadding = 10;
static constexpr gfx::Rect kAppBounds = gfx::Rect(50, 50, 800, 400);
// Sub-label strings.
const std::u16string& hidden_label = u"Hidden";
const std::u16string& visible_label = u"Visible";
enum class Movement { kTouch, kMouse };
class GameDashboardContextTest : public GameDashboardTestBase {
@ -796,13 +800,16 @@ TEST_P(GameTypeGameDashboardContextTest, OpenAndCloseToolbarWidget) {
test_api_->OpenTheMainMenu();
// Retrieve the toolbar button and verify the toolbar widget is not available.
// Retrieve the toolbar button and verify the toolbar widget is not enabled.
auto* toolbar_tile = test_api_->GetMainMenuToolbarTile();
ASSERT_TRUE(toolbar_tile);
EXPECT_FALSE(toolbar_tile->IsToggled());
EXPECT_EQ(toolbar_tile->sub_label()->GetText(), hidden_label);
// Open the toolbar and verify available feature buttons.
// Open the toolbar, verify the main menu toolbar tile's sub-label is updated,
// and verify available feature buttons.
test_api_->OpenTheToolbar();
EXPECT_EQ(toolbar_tile->sub_label()->GetText(), visible_label);
EXPECT_TRUE(test_api_->GetToolbarGamepadButton());
EXPECT_TRUE(test_api_->GetToolbarRecordGameButton());
EXPECT_TRUE(test_api_->GetToolbarScreenshotButton());
@ -812,11 +819,20 @@ TEST_P(GameTypeGameDashboardContextTest, OpenAndCloseToolbarWidget) {
EXPECT_FALSE(test_api_->GetToolbarGameControlsButton());
}
// Verify toggling the main menu visibility doesn't affect the toolbar.
test_api_->CloseTheMainMenu();
EXPECT_TRUE(test_api_->GetToolbarWidget());
test_api_->OpenTheMainMenu();
toolbar_tile = test_api_->GetMainMenuToolbarTile();
EXPECT_EQ(toolbar_tile->sub_label()->GetText(), visible_label);
EXPECT_TRUE(test_api_->GetToolbarWidget());
test_api_->CloseTheToolbar();
// Verify that the toolbar widget is no longer available and is toggled off.
EXPECT_FALSE(test_api_->GetToolbarWidget());
EXPECT_FALSE(toolbar_tile->IsToggled());
EXPECT_EQ(toolbar_tile->sub_label()->GetText(), hidden_label);
}
// Verifies the toolbar screenshot button will take a screenshot of the game

@ -52,18 +52,24 @@ constexpr int kCenterPadding = 8;
constexpr int kMainMenuFixedWidth = 416;
// Creates an individual Game Dashboard Tile.
std::unique_ptr<FeatureTile> CreateTile(base::RepeatingClosure callback,
bool is_togglable,
FeatureTile::TileType type,
int id,
const gfx::VectorIcon& icon,
const std::u16string& text) {
std::unique_ptr<FeatureTile> CreateTile(
base::RepeatingClosure callback,
bool is_togglable,
FeatureTile::TileType type,
int id,
const gfx::VectorIcon& icon,
const std::u16string& text,
const absl::optional<std::u16string>& sub_label) {
auto tile =
std::make_unique<FeatureTile>(std::move(callback), is_togglable, type);
tile->SetID(id);
tile->SetVectorIcon(icon);
tile->SetLabel(text);
tile->SetTooltipText(text);
if (sub_label.has_value()) {
tile->SetSubLabel(sub_label.value());
tile->SetSubLabelVisibility(true);
}
return tile;
}
@ -257,7 +263,12 @@ void GameDashboardMainMenuView::UpdateRecordingDuration(
}
void GameDashboardMainMenuView::OnToolbarTilePressed() {
toolbar_tile_->SetToggled(context_->ToggleToolbar());
bool toolbar_visible = context_->ToggleToolbar();
toolbar_tile_->SetSubLabel(
toolbar_visible
? l10n_util::GetStringUTF16(IDS_ASH_GAME_DASHBOARD_VISIBLE_STATUS)
: l10n_util::GetStringUTF16(IDS_ASH_GAME_DASHBOARD_HIDDEN_STATUS));
toolbar_tile_->SetToggled(toolbar_visible);
}
void GameDashboardMainMenuView::OnRecordGameTilePressed() {
@ -340,14 +351,18 @@ void GameDashboardMainMenuView::AddShortcutTilesRow() {
container->SetOrientation(views::BoxLayout::Orientation::kHorizontal);
container->SetBetweenChildSpacing(kCenterPadding);
const bool toolbar_visible = context_->IsToolbarVisible();
toolbar_tile_ = container->AddChildView(CreateTile(
base::BindRepeating(&GameDashboardMainMenuView::OnToolbarTilePressed,
base::Unretained(this)),
/*is_togglable=*/true, FeatureTile::TileType::kCompact,
VIEW_ID_GD_TOOLBAR_TILE, kGdToolbarIcon,
l10n_util::GetStringUTF16(
IDS_ASH_GAME_DASHBOARD_TOOLBAR_TILE_BUTTON_TITLE)));
toolbar_tile_->SetToggled(context_->IsToolbarVisible());
IDS_ASH_GAME_DASHBOARD_TOOLBAR_TILE_BUTTON_TITLE),
toolbar_visible
? l10n_util::GetStringUTF16(IDS_ASH_GAME_DASHBOARD_VISIBLE_STATUS)
: l10n_util::GetStringUTF16(IDS_ASH_GAME_DASHBOARD_HIDDEN_STATUS)));
toolbar_tile_->SetToggled(toolbar_visible);
MaybeAddGameControlsTile(container);
@ -359,7 +374,8 @@ void GameDashboardMainMenuView::AddShortcutTilesRow() {
/*is_togglable=*/true, FeatureTile::TileType::kCompact,
VIEW_ID_GD_RECORD_GAME_TILE, kGdRecordGameIcon,
l10n_util::GetStringUTF16(
IDS_ASH_GAME_DASHBOARD_RECORD_GAME_TILE_BUTTON_TITLE)));
IDS_ASH_GAME_DASHBOARD_RECORD_GAME_TILE_BUTTON_TITLE),
/*sub_label=*/absl::nullopt));
UpdateRecordGameTile(
GameDashboardController::Get()->active_recording_context() == context_);
}
@ -370,7 +386,8 @@ void GameDashboardMainMenuView::AddShortcutTilesRow() {
/*is_togglable=*/true, FeatureTile::TileType::kCompact,
VIEW_ID_GD_SCREENSHOT_TILE, kGdScreenshotIcon,
l10n_util::GetStringUTF16(
IDS_ASH_GAME_DASHBOARD_SCREENSHOT_TILE_BUTTON_TITLE)));
IDS_ASH_GAME_DASHBOARD_SCREENSHOT_TILE_BUTTON_TITLE),
/*sub_label=*/absl::nullopt));
}
void GameDashboardMainMenuView::AddFeatureDetailsRows() {
@ -401,7 +418,8 @@ void GameDashboardMainMenuView::MaybeAddGameControlsTile(
/*is_togglable=*/true, FeatureTile::TileType::kCompact,
VIEW_ID_GD_CONTROLS_TILE, kGdGameControlsIcon,
l10n_util::GetStringUTF16(
IDS_ASH_GAME_DASHBOARD_CONTROLS_TILE_BUTTON_TITLE)));
IDS_ASH_GAME_DASHBOARD_CONTROLS_TILE_BUTTON_TITLE),
/*sub_label=*/absl::nullopt));
game_controls_tile_->SetEnabled(
game_dashboard_utils::IsFlagSet(*flags, ArcGameControlsFlag::kEnabled) &&