Commit ace1a40c authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Media Notification] Remove right padding if no artwork

If we do not have any artwork we should not shift the
media notification contents to the right.

BUG=897836

Change-Id: Ia1b333e5c80e2065fda9ad2c1eea90dfdd86742d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1545728
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646414}
parent 089c7cc7
......@@ -44,13 +44,6 @@ constexpr double kMediaImageMaxWidthExpandedPct = 0.4;
constexpr gfx::Size kMediaButtonSize = gfx::Size(36, 36);
constexpr int kMediaButtonRowSeparator = 8;
constexpr gfx::Insets kMediaTitleArtistInsets = gfx::Insets(8, 8, 0, 8);
constexpr gfx::Insets kMediaNotificationMainRowInsets =
gfx::Insets(0, kDefaultMarginSize, 14, kRightMarginSize);
constexpr gfx::Insets kMediaNotificationExpandedMainRowInsets =
gfx::Insets(kDefaultMarginSize,
kDefaultMarginSize,
kDefaultMarginSize,
kRightMarginExpandedSize);
constexpr int kMediaNotificationHeaderTopInset = 6;
constexpr int kMediaNotificationHeaderRightInset = 6;
constexpr int kMediaNotificationHeaderInset = 0;
......@@ -285,6 +278,13 @@ void MediaNotificationView::UpdateWithMediaActions(
void MediaNotificationView::UpdateWithMediaArtwork(
const gfx::ImageSkia& image) {
GetMediaNotificationBackground()->UpdateArtwork(image);
has_artwork_ = !image.isNull();
UpdateViewForExpandedState();
PreferredSizeChanged();
Layout();
SchedulePaint();
}
void MediaNotificationView::UpdateWithMediaIcon(const gfx::ImageSkia& image) {
......@@ -337,16 +337,23 @@ void MediaNotificationView::UpdateViewForExpandedState() {
main_row_
->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kVertical,
kMediaNotificationExpandedMainRowInsets, kDefaultMarginSize))
gfx::Insets(
kDefaultMarginSize, kDefaultMarginSize, kDefaultMarginSize,
has_artwork_ ? kRightMarginExpandedSize : kDefaultMarginSize),
kDefaultMarginSize))
->SetDefaultFlex(1);
} else {
main_row_
->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, kMediaNotificationMainRowInsets,
views::BoxLayout::kHorizontal,
gfx::Insets(0, kDefaultMarginSize, 14,
has_artwork_ ? kRightMarginSize : kDefaultMarginSize),
kDefaultMarginSize, true))
->SetDefaultFlex(1);
}
main_row_->Layout();
GetMediaNotificationBackground()->UpdateArtworkMaxWidthPct(
expanded_ ? kMediaImageMaxWidthExpandedPct : kMediaImageMaxWidthPct);
......
......@@ -94,6 +94,8 @@ class ASH_EXPORT MediaNotificationView : public message_center::MessageView,
std::unique_ptr<message_center::NotificationControlButtonsView>
control_buttons_view_;
bool has_artwork_ = false;
// Whether this notification is expanded or not.
bool expanded_ = false;
......
......@@ -621,6 +621,7 @@ TEST_F(MediaNotificationViewTest, ActionButtonsToggleVisbility) {
}
TEST_F(MediaNotificationViewTest, UpdateArtworkFromItem) {
int title_artist_width = title_artist_row()->width();
gfx::Size size = view()->size();
SkBitmap image;
......@@ -632,6 +633,10 @@ TEST_F(MediaNotificationViewTest, UpdateArtworkFromItem) {
GetItem()->MediaControllerImageChanged(
media_session::mojom::MediaSessionImageType::kArtwork, image);
// Ensure the title artist row has a small width than before now that we
// have artwork.
EXPECT_GT(title_artist_width, title_artist_row()->width());
// Ensure that the image is displayed in the background artwork and that the
// size of the notification was not affected.
EXPECT_FALSE(GetArtworkImage().isNull());
......@@ -641,6 +646,10 @@ TEST_F(MediaNotificationViewTest, UpdateArtworkFromItem) {
GetItem()->MediaControllerImageChanged(
media_session::mojom::MediaSessionImageType::kArtwork, SkBitmap());
// Ensure the title artist row goes back to the original width now that we
// do not have any artwork.
EXPECT_EQ(title_artist_width, title_artist_row()->width());
// Ensure that the background artwork was reset and the size was still not
// affected.
EXPECT_TRUE(GetArtworkImage().isNull());
......
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