Chromium Code Reviews| Index: ui/message_center/views/notification_header_view.cc |
| diff --git a/ui/message_center/views/notification_header_view.cc b/ui/message_center/views/notification_header_view.cc |
| index 8ce5827264a9184e91a7f5021eb499e4e2a8facd..a7e11e4b3524d4b4ff7c188026f17233ce98ae15 100644 |
| --- a/ui/message_center/views/notification_header_view.cc |
| +++ b/ui/message_center/views/notification_header_view.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/time/time.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/gfx/color_palette.h" |
| #include "ui/gfx/font_list.h" |
| @@ -34,7 +35,7 @@ constexpr gfx::Insets kHeaderPadding(0, 12, 0, 2); |
| constexpr int kHeaderHorizontalSpacing = 2; |
| constexpr int kAppInfoConatainerTopPadding = 12; |
| // Bullet character. The divider symbol between different parts of the header. |
| -constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022; |
| +constexpr wchar_t kNotificationHeaderDivider[] = L" \u2022 "; |
| // Base ink drop color of action buttons. |
| const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0); |
| @@ -43,6 +44,12 @@ constexpr float kInkDropRippleVisibleOpacity = 0.08f; |
| // Highlight (hover) ink drop opacity of action buttons. |
| constexpr float kInkDropHighlightVisibleOpacity = 0.08f; |
| +// base::TimeBase has similar constants, but some of them are missing. |
| +constexpr int64_t kMinuteInMillis = 60LL * 1000LL; |
| +constexpr int64_t kHourInMillis = 60LL * kMinuteInMillis; |
| +constexpr int64_t kDayInMillis = 24LL * kHourInMillis; |
| +constexpr int64_t kYearInMillis = 365LL * kDayInMillis; |
|
fukino
2017/07/05 07:08:27
BTW, in Android, YEAR_IN_MILLIS is 364 days.
https
tetsui
2017/07/05 07:28:56
Done. It seems Android did YEAR_IN_MILLIS = WEEK_I
|
| + |
| // ExpandButtton forwards all mouse and key events to NotificationHeaderView, |
| // but takes tab focus for accessibility purpose. |
| class ExpandButton : public views::ImageView { |
| @@ -83,6 +90,35 @@ void ExpandButton::OnBlur() { |
| SchedulePaint(); |
| } |
| +// Do relative time string formatting that is similar to |
| +// com.java.android.widget.DateTimeView.updateRelativeTime. |
| +// Chromium has its own base::TimeFormat::Simple(), but none of the formats |
| +// supported by the function is similar to Android's one. |
| +base::string16 FormatToRelativeTime(base::Time past) { |
| + base::Time now = base::Time::Now(); |
| + int64_t duration = (now - past).InMilliseconds(); |
| + if (duration < kMinuteInMillis) { |
| + return l10n_util::GetStringUTF16( |
| + IDS_MESSAGE_NOTIFICATION_NOW_STRING_SHORTEST); |
| + } else if (duration < kHourInMillis) { |
| + int count = static_cast<int>(duration / kMinuteInMillis); |
| + return l10n_util::GetPluralStringFUTF16( |
| + IDS_MESSAGE_NOTIFICATION_DURATION_MINUTES_SHORTEST, count); |
| + } else if (duration < kDayInMillis) { |
| + int count = static_cast<int>(duration / kHourInMillis); |
| + return l10n_util::GetPluralStringFUTF16( |
| + IDS_MESSAGE_NOTIFICATION_DURATION_HOURS_SHORTEST, count); |
| + } else if (duration < kYearInMillis) { |
| + int count = static_cast<int>(duration / kDayInMillis); |
| + return l10n_util::GetPluralStringFUTF16( |
| + IDS_MESSAGE_NOTIFICATION_DURATION_DAYS_SHORTEST, count); |
| + } else { |
| + int count = static_cast<int>(duration / kYearInMillis); |
| + return l10n_util::GetPluralStringFUTF16( |
| + IDS_MESSAGE_NOTIFICATION_DURATION_YEARS_SHORTEST, count); |
| + } |
| +} |
| + |
| } // namespace |
| NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) |
| @@ -125,9 +161,7 @@ NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) |
| // Summary text divider |
| summary_text_divider_ = |
| - new views::Label(base::ASCIIToUTF16(" ") + |
| - base::string16(1, kNotificationHeaderDividerSymbol) + |
| - base::ASCIIToUTF16(" ")); |
| + new views::Label(base::WideToUTF16(kNotificationHeaderDivider)); |
| summary_text_divider_->SetFontList(font_list); |
| summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| summary_text_divider_->SetVisible(false); |
| @@ -140,6 +174,21 @@ NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) |
| summary_text_view_->SetVisible(false); |
| app_info_container->AddChildView(summary_text_view_); |
| + // Timestamp divider |
| + timestamp_divider_ = |
| + new views::Label(base::WideToUTF16(kNotificationHeaderDivider)); |
| + timestamp_divider_->SetFontList(font_list); |
| + timestamp_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + timestamp_divider_->SetVisible(false); |
| + app_info_container->AddChildView(timestamp_divider_); |
| + |
| + // Timestamp view |
| + timestamp_view_ = new views::Label(base::string16()); |
| + timestamp_view_->SetFontList(font_list); |
| + timestamp_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + timestamp_view_->SetVisible(false); |
| + app_info_container->AddChildView(timestamp_view_); |
| + |
| // Expand button view |
| expand_button_ = new ExpandButton(); |
| app_info_container->AddChildView(expand_button_); |
| @@ -205,6 +254,17 @@ void NotificationHeaderView::ClearOverflowIndicator() { |
| UpdateSummaryTextVisibility(); |
| } |
| +void NotificationHeaderView::SetTimestamp(base::Time past) { |
| + timestamp_view_->SetText(FormatToRelativeTime(past)); |
| + has_timestamp_ = true; |
| + UpdateSummaryTextVisibility(); |
| +} |
| + |
| +void NotificationHeaderView::ClearTimestamp() { |
| + has_timestamp_ = false; |
| + UpdateSummaryTextVisibility(); |
| +} |
| + |
| void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { |
| // SetInkDropMode iff. the visibility changed. |
| // Otherwise, the ink drop animation cannot finish. |
| @@ -290,6 +350,8 @@ void NotificationHeaderView::UpdateSummaryTextVisibility() { |
| const bool visible = has_progress_ || has_overflow_indicator_; |
| summary_text_divider_->SetVisible(visible); |
| summary_text_view_->SetVisible(visible); |
| + timestamp_divider_->SetVisible(!has_progress_ && has_timestamp_); |
| + timestamp_view_->SetVisible(!has_progress_ && has_timestamp_); |
| Layout(); |
| } |