Commit 1e4cc726 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Change eliding priority of progress bar notification.

Previously, if both the title and the message for a progress bar
notification is long enough, the implementation showed the full
text of the title and elided the message by following Android
behavior.

However, in Download notification, it elides "n mins left" text
(See screenshot in the bug), which is not preferable.

This CL changes the behavior to prioritize the message and elide the
title if there is not enough space.

TEST=manual
BUG=789924

Change-Id: I9e8da6c9c53ce1409b6d2d7aa05ae2bd62ca854b
Reviewed-on: https://chromium-review.googlesource.com/804982Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523666}
parent 227270a3
......@@ -108,6 +108,12 @@ constexpr int kMessageViewWidth =
// "Roboto-Regular, 13sp" is specified in the mock.
constexpr int kTextFontSize = 13;
// In progress notification, if both the title and the message are long, the
// message would be prioritized and the title would be elided.
// However, it is not perferable that we completely omit the title, so
// the ratio of the message width is limited to this value.
constexpr double kProgressNotificationMessageRatio = 0.7;
// FontList for the texts except for the header.
gfx::FontList GetTextFontList() {
gfx::Font default_font;
......@@ -203,22 +209,24 @@ void CompactTitleMessageView::OnPaint(gfx::Canvas* canvas) {
const gfx::FontList& font_list = GetTextFontList();
// Elides title and message. The behavior is based on Android's one.
// * If the title is too long, only the title is shown.
// * If the message is too long, the full content of the title is shown,
// Elides title and message.
// * If the message is too long, the message occupies at most
// kProgressNotificationMessageRatio of the width.
// * If the title is too long, the full content of the message is shown,
// kCompactTitleMessageViewSpacing is added between them, and the elided
// message is shown.
// title is shown.
// * If they are short enough, the title is left-aligned and the message is
// right-aligned.
const int original_title_width =
gfx::Canvas::GetStringWidthF(title, font_list);
if (original_title_width >= width())
message.clear();
title = gfx::ElideText(title, font_list, width(), gfx::ELIDE_TAIL);
const int title_width = gfx::Canvas::GetStringWidthF(title, font_list);
const int message_width =
std::max(0, width() - title_width - kCompactTitleMessageViewSpacing);
message = gfx::ElideText(message, font_list, message_width, gfx::ELIDE_TAIL);
message = gfx::ElideText(
message, font_list,
title.empty()
? width()
: static_cast<int>(kProgressNotificationMessageRatio * width()),
gfx::ELIDE_TAIL);
const int message_width = gfx::Canvas::GetStringWidthF(message, font_list);
const int title_width =
std::max(0, width() - message_width - kCompactTitleMessageViewSpacing);
title = gfx::ElideText(title, font_list, title_width, gfx::ELIDE_TAIL);
title_view_->SetText(title);
message_view_->SetText(message);
......
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