Commit 12689961 authored by Mia Bergeron's avatar Mia Bergeron Committed by Commit Bot

Add seek forward and backward to Chrome OS lock screen media controls

Seek forward and seek backward actions and icons are now included in
the Chrome OS lock screen media controls view.

Bug: 965572
Change-Id: Ie528f5be7121c487415161cd3f8685d5bda80327
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1709690
Commit-Queue: Mia Bergeron <miaber@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679596}
parent d9e72e69
......@@ -1972,12 +1972,18 @@ This file contains the strings for ash.
<message name="IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_PREVIOUS_TRACK" desc="The button to trigger media playback to go to the previous track.">
Previous Track
</message>
<message name="IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_SEEK_BACKWARD" desc="The button to trigger media playback to seek backward a few seconds.">
Seek Backward
</message>
<message name="IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_PLAY" desc="The button to trigger media playback to start.">
Play
</message>
<message name="IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_PAUSE" desc="The button to trigger media playback to pause.">
Pause
</message>
<message name="IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_SEEK_FORWARD" desc="The button to trigger media playback to seek forward a few seconds.">
Seek Forward
</message>
<message name="IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_NEXT_TRACK" desc="The button to trigger media playback to go to the next track.">
Next Track
</message>
......
099755082e3dffae340d4830f9409499cd841679
\ No newline at end of file
099755082e3dffae340d4830f9409499cd841679
\ No newline at end of file
......@@ -52,10 +52,11 @@ constexpr int kArtworkViewWidth = 270;
constexpr int kArtworkViewHeight = 200;
constexpr gfx::Size kMediaButtonSize = gfx::Size(45, 45);
constexpr int kPlayPauseIconSize = 32;
constexpr int kMediaButtonIconSize = 18;
constexpr int kChangeTrackIconSize = 16;
constexpr int kSeekingIconsSize = 28;
constexpr gfx::Size kMediaControlsButtonRowSize =
gfx::Size(270, kMediaButtonSize.height());
constexpr int kMediaButtonRowSeparator = 20;
constexpr int kMediaButtonRowSeparator = 10;
// How long to wait (in milliseconds) for a new media session to begin.
constexpr base::TimeDelta kNextMediaDelay =
......@@ -92,10 +93,12 @@ const gfx::VectorIcon& GetVectorIconForMediaAction(MediaSessionAction action) {
return kLockScreenNextTrackIcon;
case MediaSessionAction::kPlay:
return kLockScreenPlayIcon;
// The following actions are not yet supported on the controls.
case MediaSessionAction::kSeekBackward:
return kLockScreenSeekBackwardIcon;
case MediaSessionAction::kSeekForward:
return kLockScreenSeekForwardIcon;
// The following actions are not yet supported on the controls.
case MediaSessionAction::kStop:
case MediaSessionAction::kSkipAd:
case MediaSessionAction::kSeekTo:
......@@ -159,10 +162,15 @@ LockScreenMediaControlsView::LockScreenMediaControlsView(
button_row_ = AddChildView(std::move(button_row));
CreateMediaButton(
MediaSessionAction::kPreviousTrack,
kChangeTrackIconSize, MediaSessionAction::kPreviousTrack,
l10n_util::GetStringUTF16(
IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_PREVIOUS_TRACK));
CreateMediaButton(
kSeekingIconsSize, MediaSessionAction::kSeekBackward,
l10n_util::GetStringUTF16(
IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_SEEK_BACKWARD));
// |play_pause_button_| toggles playback. If the current media is playing, the
// tag will be |MediaSessionAction::kPause|. If the current media is paused,
// the tag will be |MediaSessionAction::kPlay|.
......@@ -186,7 +194,12 @@ LockScreenMediaControlsView::LockScreenMediaControlsView(
GetVectorIconForMediaAction(MediaSessionAction::kPlay),
kPlayPauseIconSize, kMediaButtonColor);
CreateMediaButton(MediaSessionAction::kNextTrack,
CreateMediaButton(
kSeekingIconsSize, MediaSessionAction::kSeekForward,
l10n_util::GetStringUTF16(
IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_SEEK_FORWARD));
CreateMediaButton(kChangeTrackIconSize, MediaSessionAction::kNextTrack,
l10n_util::GetStringUTF16(
IDS_ASH_LOCK_SCREEN_MEDIA_CONTROLS_ACTION_NEXT_TRACK));
......@@ -363,6 +376,7 @@ void LockScreenMediaControlsView::FlushForTesting() {
}
void LockScreenMediaControlsView::CreateMediaButton(
int size,
MediaSessionAction action,
const base::string16& accessible_name) {
auto button = views::CreateVectorImageButton(this);
......@@ -372,8 +386,8 @@ void LockScreenMediaControlsView::CreateMediaButton(
button->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
views::SetImageFromVectorIcon(button.get(),
GetVectorIconForMediaAction(action),
kMediaButtonIconSize, kMediaButtonColor);
GetVectorIconForMediaAction(action), size,
kMediaButtonColor);
button_row_->AddChildView(std::move(button));
}
......
......@@ -103,7 +103,8 @@ class ASH_EXPORT LockScreenMediaControlsView
// Creates and adds a new media button to |button_row_|. This should not be
// used to create toggle buttons such as play/pause.
void CreateMediaButton(media_session::mojom::MediaSessionAction action,
void CreateMediaButton(int size,
media_session::mojom::MediaSessionAction action,
const base::string16& accessible_name);
// Updates the visibility of buttons on |button_row_| depending on what is
......
......@@ -32,6 +32,11 @@ constexpr int kArtworkViewHeight = 200;
const base::string16 kTestAppName = base::ASCIIToUTF16("Test app");
MediaSessionAction kActionButtonOrder[] = {
MediaSessionAction::kPreviousTrack, MediaSessionAction::kSeekBackward,
MediaSessionAction::kPause, MediaSessionAction::kSeekForward,
MediaSessionAction::kNextTrack};
// Checks if the view class name is used by a media button.
bool IsMediaButtonType(const char* class_name) {
return class_name == views::ImageButton::kViewClassName ||
......@@ -230,11 +235,17 @@ TEST_F(LockScreenMediaControlsViewTest, ButtonsSanityCheck) {
EnableAllActions();
EXPECT_TRUE(button_row()->GetVisible());
EXPECT_EQ(3u, button_row()->children().size());
EXPECT_EQ(5u, button_row()->children().size());
for (int i = 0; i < 5; /* size of |button_row| */ i++) {
auto* child = button_row()->children()[i];
for (auto* child : button_row()->children()) {
ASSERT_TRUE(IsMediaButtonType(child->GetClassName()));
ASSERT_EQ(
static_cast<MediaSessionAction>(views::Button::AsButton(child)->tag()),
kActionButtonOrder[i]);
EXPECT_TRUE(child->GetVisible());
EXPECT_FALSE(views::Button::AsButton(child)->GetAccessibleName().empty());
}
......@@ -242,6 +253,8 @@ TEST_F(LockScreenMediaControlsViewTest, ButtonsSanityCheck) {
EXPECT_TRUE(GetButtonForAction(MediaSessionAction::kPause));
EXPECT_TRUE(GetButtonForAction(MediaSessionAction::kPreviousTrack));
EXPECT_TRUE(GetButtonForAction(MediaSessionAction::kNextTrack));
EXPECT_TRUE(GetButtonForAction(MediaSessionAction::kSeekBackward));
EXPECT_TRUE(GetButtonForAction(MediaSessionAction::kSeekForward));
// |kPlay| cannot be present if |kPause| is.
EXPECT_FALSE(GetButtonForAction(MediaSessionAction::kPlay));
......@@ -259,10 +272,18 @@ TEST_F(LockScreenMediaControlsViewTest, ButtonsFocusCheck) {
EXPECT_EQ(button, focus_manager->GetFocusedView());
}
SimulateTab();
EXPECT_EQ(GetButtonForAction(MediaSessionAction::kSeekBackward),
focus_manager->GetFocusedView());
SimulateTab();
EXPECT_EQ(GetButtonForAction(MediaSessionAction::kPause),
focus_manager->GetFocusedView());
SimulateTab();
EXPECT_EQ(GetButtonForAction(MediaSessionAction::kSeekForward),
focus_manager->GetFocusedView());
SimulateTab();
EXPECT_EQ(GetButtonForAction(MediaSessionAction::kNextTrack),
focus_manager->GetFocusedView());
......@@ -337,6 +358,28 @@ TEST_F(LockScreenMediaControlsViewTest, NextTrackButtonClick) {
EXPECT_EQ(1, media_controller()->next_track_count());
}
TEST_F(LockScreenMediaControlsViewTest, SeekBackwardButtonClick) {
EnableAction(MediaSessionAction::kSeekBackward);
EXPECT_EQ(0, media_controller()->seek_backward_count());
SimulateButtonClick(MediaSessionAction::kSeekBackward);
media_controls_view_->FlushForTesting();
EXPECT_EQ(1, media_controller()->seek_backward_count());
}
TEST_F(LockScreenMediaControlsViewTest, SeekForwardButtonClick) {
EnableAction(MediaSessionAction::kSeekForward);
EXPECT_EQ(0, media_controller()->seek_forward_count());
SimulateButtonClick(MediaSessionAction::kSeekForward);
media_controls_view_->FlushForTesting();
EXPECT_EQ(1, media_controller()->seek_forward_count());
}
TEST_F(LockScreenMediaControlsViewTest, UpdateAppIcon) {
gfx::ImageSkia default_icon = gfx::CreateVectorIcon(
message_center::kProductIcon, kAppIconSize, gfx::kChromeIconGrey);
......
......@@ -124,6 +124,8 @@ aggregate_vector_icons("ash_vector_icons") {
"lock_screen_play.icon",
"lock_screen_previous_track.icon",
"lock_screen_next_track.icon",
"lock_screen_seek_forward.icon",
"lock_screen_seek_backward.icon",
"send.icon",
"settings.icon",
"shelf_add_person_button.icon",
......
// Copyright 2019 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 9.44f, 18.88f,
ARC_TO, 0.89f, 0.89f, 0, 0, 1, 9, 18.72f,
R_LINE_TO, -8.58f, -6,
R_ARC_TO, 0.87f, 0.87f, 0, 0, 1, -0.22f, -1.2f,
R_ARC_TO, 0.88f, 0.88f, 0, 0, 1, 0.22f, -0.21f,
LINE_TO, 9, 5.3f,
R_ARC_TO, 0.86f, 0.86f, 0, 0, 1, 0.86f, -0.06f,
R_ARC_TO, 0.84f, 0.84f, 0, 0, 1, 0.45f, 0.76f,
V_LINE_TO, 18,
R_ARC_TO, 0.84f, 0.84f, 0, 0, 1, -0.45f, 0.76f,
ARC_TO, 1, 1, 0, 0, 1, 9.44f, 18.88f,
CLOSE,
MOVE_TO, 2.36f, 12,
R_LINE_TO, 6.22f, 4.36f,
V_LINE_TO, 7.65f,
CLOSE,
MOVE_TO, 23.18f, 18.88f,
R_ARC_TO, 0.84f, 0.84f, 0, 0, 1, -0.49f, -0.16f,
R_LINE_TO, -8.59f, -6,
R_ARC_TO, 0.86f, 0.86f, 0, 0, 1, -0.21f, -1.2f,
R_ARC_TO, 1, 1, 0, 0, 1, 0.21f, -0.21f,
R_LINE_TO, 8.59f, -6,
ARC_TO, 0.83f, 0.83f, 0, 0, 1, 24, 6,
V_LINE_TO, 18,
R_ARC_TO, 0.86f, 0.86f, 0, 0, 1, -0.45f, 0.76f,
ARC_TO, 1, 1, 0, 0, 1, 23.18f, 18.88f,
CLOSE,
MOVE_TO, 16.09f, 12,
R_LINE_TO, 6.23f, 4.36f,
V_LINE_TO, 7.65f,
CLOSE
// Copyright 2019 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 0.86f, 18.87f,
R_ARC_TO, 0.93f, 0.93f, 0, 0, 1, -0.4f, -0.09f,
ARC_TO, 0.86f, 0.86f, 0, 0, 1, 0, 18,
V_LINE_TO, 6,
R_ARC_TO, 0.86f, 0.86f, 0, 0, 1, 0.46f, -0.76f,
R_ARC_TO, 0.85f, 0.85f, 0, 0, 1, 0.93f, 0.06f,
R_LINE_TO, 8.58f, 6,
R_ARC_TO, 0.86f, 0.86f, 0, 0, 1, 0.21f, 1.2f,
R_ARC_TO, 0.84f, 0.84f, 0, 0, 1, -0.21f, 0.21f,
R_LINE_TO, -8.58f, 6,
ARC_TO, 0.84f, 0.84f, 0, 0, 1, 0.86f, 18.87f,
CLOSE,
MOVE_TO, 1.72f, 7.65f,
R_V_LINE_TO, 8.72f,
LINE_TO, 8, 12,
CLOSE,
MOVE_TO, 14.59f, 18.87f,
R_ARC_TO, 0.93f, 0.93f, 0, 0, 1, -0.4f, -0.09f,
R_ARC_TO, 0.86f, 0.86f, 0, 0, 1, -0.46f, -0.76f,
V_LINE_TO, 6,
R_ARC_TO, 0.86f, 0.86f, 0, 0, 1, 0.46f, -0.76f,
R_ARC_TO, 0.85f, 0.85f, 0, 0, 1, 0.86f, 0.06f,
R_LINE_TO, 8.58f, 6,
R_ARC_TO, 0.87f, 0.87f, 0, 0, 1, 0.22f, 1.2f,
R_ARC_TO, 0.88f, 0.88f, 0, 0, 1, -0.22f, 0.21f,
R_LINE_TO, -8.58f, 6,
ARC_TO, 0.84f, 0.84f, 0, 0, 1, 14.59f, 18.87f,
CLOSE,
R_MOVE_TO, 0.86f, -11.22f,
R_V_LINE_TO, 8.72f,
LINE_TO, 21.68f, 12,
CLOSE
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