Commit 5004f1f2 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

fix: do not remove notification body if image present

If we show a notification with a long title, a context message and an
image, the line limit of the message body is set to 0 so that the image
can be flush against the icon.

This CL removes this limitation and therefore the "feature" of having
the image flush against the icon when the notification contains a lot of
text. The notification message can now contain:

0 title lines: 5 max lines message
1 title lines: 5 max lines message
2 title lines: 3 max lines message

This does not depend on whether there is an image or a context message.
We still make sure that there is at least 16px of space between the icon
and the image, if the text part is higher than the icon.

Bug: 697573
Change-Id: Ic8f2441de58e4503d93da025275b57ba5a2a92b9
Reviewed-on: https://chromium-review.googlesource.com/c/1350749Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#616024}
parent 46fc59f9
......@@ -654,36 +654,15 @@ NotificationControlButtonsView* NotificationView::GetControlButtonsView()
}
int NotificationView::GetMessageLineLimit(int title_lines, int width) const {
// Image notifications require that the image must be kept flush against
// their icons, but we can allow more text if no image.
int effective_title_lines = std::max(0, title_lines - 1);
int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines;
if (!image_view_) {
// Title lines are counted as twice as big as message lines for the purpose
// of this calculation.
// The effect from the title reduction here should be:
// * 0 title lines: 5 max lines message.
// * 1 title line: 5 max lines message.
// * 2 title lines: 3 max lines message.
return std::max(0, kMessageExpandedLineLimit - line_reduction_from_title);
}
int message_line_limit = kMessageCollapsedLineLimit;
// Subtract any lines taken by the context message.
if (context_message_view_) {
message_line_limit -= context_message_view_->GetLinesForWidthAndLimit(
width, kContextMessageLineLimit);
}
int line_reduction_from_title = 2 * effective_title_lines;
// Title lines are counted as twice as big as message lines for the purpose
// of this calculation.
// The effect from the title reduction here should be:
// * 0 title lines: 2 max lines message + context message.
// * 1 title line: 2 max lines message + context message.
// * 2 title lines: 1 max lines message + context message.
message_line_limit =
std::max(0, message_line_limit - line_reduction_from_title);
return message_line_limit;
// * 0 title lines: 5 max lines message.
// * 1 title line: 5 max lines message.
// * 2 title lines: 3 max lines message.
return std::max(0, kMessageExpandedLineLimit - line_reduction_from_title);
}
int NotificationView::GetMessageHeight(int width, int limit) const {
......
......@@ -391,18 +391,18 @@ TEST_F(NotificationViewTest, TestLineLimits) {
notification()->set_image(CreateTestImage(2, 2));
notification_view()->UpdateWithNotification(*notification());
EXPECT_EQ(2, notification_view()->GetMessageLineLimit(0, 360));
EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360));
EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360));
EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360));
EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360));
EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360));
notification()->set_context_message(base::ASCIIToUTF16("foo"));
notification_view()->UpdateWithNotification(*notification());
EXPECT_TRUE(notification_view()->context_message_view_ != NULL);
EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360));
EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360));
EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360));
EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360));
EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360));
EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360));
}
TEST_F(NotificationViewTest, TestIconSizing) {
......
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