Commit 0fdf9911 authored by Jazz Xu's avatar Jazz Xu Committed by Commit Bot

CrOS GMC: Add empty state to gmc dialog.

This CL modifies media tray bubble behavior such that when the dialog
is opened and all media stops playing, we will show an empty state
indicating there's no media playing instead of close the dialog
immediately.

Bug: 1134414
Change-Id: I3f0f2489da2189e6a71f74f6a00855d8b4a535f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444529Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Commit-Queue: Jazz Xu <jazzhsu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813279}
parent a911ce26
...@@ -31,11 +31,13 @@ ...@@ -31,11 +31,13 @@
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
namespace ash { namespace ash {
namespace { namespace {
constexpr int kNoMediaTextFontSizeIncrease = 2;
constexpr int kTitleFontSizeIncrease = 4; constexpr int kTitleFontSizeIncrease = 4;
constexpr int kTitleViewHeight = 56; constexpr int kTitleViewHeight = 56;
...@@ -257,7 +259,7 @@ void MediaTray::ShowBubble(bool show_by_click) { ...@@ -257,7 +259,7 @@ void MediaTray::ShowBubble(bool show_by_click) {
title_view->layer()->SetFillsBoundsOpaquely(false); title_view->layer()->SetFillsBoundsOpaquely(false);
pin_button_ = title_view->pin_button(); pin_button_ = title_view->pin_button();
bubble_view->AddChildView( content_view_ = bubble_view->AddChildView(
MediaNotificationProvider::Get()->GetMediaNotificationListView( MediaNotificationProvider::Get()->GetMediaNotificationListView(
AshColorProvider::Get()->GetContentLayerColor( AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparatorColor), AshColorProvider::ContentLayerType::kSeparatorColor),
...@@ -272,6 +274,7 @@ void MediaTray::CloseBubble() { ...@@ -272,6 +274,7 @@ void MediaTray::CloseBubble() {
if (MediaNotificationProvider::Get()) if (MediaNotificationProvider::Get())
MediaNotificationProvider::Get()->OnBubbleClosing(); MediaNotificationProvider::Get()->OnBubbleClosing();
SetIsActive(false); SetIsActive(false);
empty_state_view_ = nullptr;
bubble_.reset(); bubble_.reset();
shelf()->UpdateAutoHideState(); shelf()->UpdateAutoHideState();
} }
...@@ -303,19 +306,57 @@ void MediaTray::UpdateDisplayState() { ...@@ -303,19 +306,57 @@ void MediaTray::UpdateDisplayState() {
if (!MediaNotificationProvider::Get()) if (!MediaNotificationProvider::Get())
return; return;
bool should_show = if (bubble_ && Shell::Get()->session_controller()->IsScreenLocked())
(MediaNotificationProvider::Get()->HasActiveNotifications() ||
MediaNotificationProvider::Get()->HasFrozenNotifications()) &&
!Shell::Get()->session_controller()->IsScreenLocked();
if (!should_show && bubble_)
CloseBubble(); CloseBubble();
SetVisiblePreferred(should_show && IsPinnedToShelf()); bool has_session =
MediaNotificationProvider::Get()->HasActiveNotifications() ||
MediaNotificationProvider::Get()->HasFrozenNotifications();
if (bubble_ && !has_session)
ShowEmptyState();
bool should_show = has_session &&
!Shell::Get()->session_controller()->IsScreenLocked() &&
IsPinnedToShelf();
SetVisiblePreferred(should_show);
} }
void MediaTray::OnGlobalMediaControlsPinPrefChanged() { void MediaTray::OnGlobalMediaControlsPinPrefChanged() {
UpdateDisplayState(); UpdateDisplayState();
} }
void MediaTray::ShowEmptyState() {
DCHECK(content_view_);
if (empty_state_view_)
return;
// Create and add empty state view containing a label indicating there's no
// active session
auto empty_state_view = std::make_unique<views::View>();
auto* layout =
empty_state_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
layout->set_minimum_cross_axis_size(content_view_->bounds().height());
layout->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kCenter);
auto no_media_label = std::make_unique<views::Label>();
no_media_label->SetAutoColorReadabilityEnabled(false);
no_media_label->SetSubpixelRenderingEnabled(false);
no_media_label->SetEnabledColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorSecondary));
no_media_label->SetText(
l10n_util::GetStringUTF16(IDS_ASH_GLOBAL_MEDIA_CONTROLS_NO_MEDIA_TEXT));
no_media_label->SetFontList(
views::Label::GetDefaultFontList().DeriveWithSizeDelta(
kNoMediaTextFontSizeIncrease));
empty_state_view->AddChildView(std::move(no_media_label));
empty_state_view->SetPaintToLayer();
empty_state_view->layer()->SetFillsBoundsOpaquely(false);
empty_state_view_ =
bubble_->GetBubbleView()->AddChildView(std::move(empty_state_view));
}
} // namespace ash } // namespace ash
...@@ -82,6 +82,8 @@ class ASH_EXPORT MediaTray : public MediaNotificationProviderObserver, ...@@ -82,6 +82,8 @@ class ASH_EXPORT MediaTray : public MediaNotificationProviderObserver,
// Called when global media controls pin pref is changed. // Called when global media controls pin pref is changed.
void OnGlobalMediaControlsPinPrefChanged(); void OnGlobalMediaControlsPinPrefChanged();
void ShowEmptyState();
// Ptr to pin button in the dialog, owned by the view hierarchy. // Ptr to pin button in the dialog, owned by the view hierarchy.
views::Button* pin_button_ = nullptr; views::Button* pin_button_ = nullptr;
...@@ -90,6 +92,9 @@ class ASH_EXPORT MediaTray : public MediaNotificationProviderObserver, ...@@ -90,6 +92,9 @@ class ASH_EXPORT MediaTray : public MediaNotificationProviderObserver,
// Weak pointer, will be parented by TrayContainer for its lifetime. // Weak pointer, will be parented by TrayContainer for its lifetime.
views::ImageView* icon_; views::ImageView* icon_;
views::View* content_view_ = nullptr;
views::View* empty_state_view_ = nullptr;
}; };
} // namespace ash } // namespace ash
......
...@@ -99,6 +99,8 @@ class MediaTrayTest : public AshTestBase { ...@@ -99,6 +99,8 @@ class MediaTrayTest : public AshTestBase {
MediaTray* media_tray() { return media_tray_; } MediaTray* media_tray() { return media_tray_; }
views::View* empty_state_view() { return media_tray_->empty_state_view_; }
private: private:
std::unique_ptr<MockMediaNotificationProvider> provider_; std::unique_ptr<MockMediaNotificationProvider> provider_;
MediaTray* media_tray_; MediaTray* media_tray_;
...@@ -168,7 +170,7 @@ TEST_F(MediaTrayTest, ShowAndHideBubbleTest) { ...@@ -168,7 +170,7 @@ TEST_F(MediaTrayTest, ShowAndHideBubbleTest) {
EXPECT_FALSE(media_tray()->is_active()); EXPECT_FALSE(media_tray()->is_active());
} }
TEST_F(MediaTrayTest, DialogCloseWhenNoActiveNotificationTest) { TEST_F(MediaTrayTest, ShowEmptyStateWhenNoActiveNotification) {
// Media tray should be visible when there is active notification. // Media tray should be visible when there is active notification.
provider()->SetHasActiveNotifications(true); provider()->SetHasActiveNotifications(true);
SimulateNotificationListChanged(); SimulateNotificationListChanged();
...@@ -185,11 +187,11 @@ TEST_F(MediaTrayTest, DialogCloseWhenNoActiveNotificationTest) { ...@@ -185,11 +187,11 @@ TEST_F(MediaTrayTest, DialogCloseWhenNoActiveNotificationTest) {
EXPECT_TRUE(media_tray()->is_active()); EXPECT_TRUE(media_tray()->is_active());
// Bubble should close if there's no active sessions. // Bubble should close if there's no active sessions.
EXPECT_CALL(*provider(), OnBubbleClosing());
provider()->SetHasActiveNotifications(false); provider()->SetHasActiveNotifications(false);
SimulateNotificationListChanged(); SimulateNotificationListChanged();
EXPECT_EQ(GetBubbleWrapper(), nullptr); EXPECT_NE(GetBubbleWrapper(), nullptr);
EXPECT_FALSE(media_tray()->GetVisible()); EXPECT_FALSE(media_tray()->GetVisible());
EXPECT_NE(empty_state_view(), nullptr);
} }
TEST_F(MediaTrayTest, PinButtonTest) { TEST_F(MediaTrayTest, PinButtonTest) {
......
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