Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/message_center/views/notification_header_view.h" | 5 #include "ui/message_center/views/notification_header_view.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/time/time.h" | |
| 9 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
| 11 #include "ui/gfx/font_list.h" | 12 #include "ui/gfx/font_list.h" |
| 12 #include "ui/gfx/paint_vector_icon.h" | 13 #include "ui/gfx/paint_vector_icon.h" |
| 13 #include "ui/message_center/message_center_style.h" | 14 #include "ui/message_center/message_center_style.h" |
| 14 #include "ui/message_center/vector_icons.h" | 15 #include "ui/message_center/vector_icons.h" |
| 15 #include "ui/message_center/views/padded_button.h" | 16 #include "ui/message_center/views/padded_button.h" |
| 16 #include "ui/strings/grit/ui_strings.h" | 17 #include "ui/strings/grit/ui_strings.h" |
| 17 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 18 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 18 #include "ui/views/animation/ink_drop_highlight.h" | 19 #include "ui/views/animation/ink_drop_highlight.h" |
| 19 #include "ui/views/animation/ink_drop_impl.h" | 20 #include "ui/views/animation/ink_drop_impl.h" |
| 20 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
| 21 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
| 22 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
| 24 #include "ui/views/painter.h" | 25 #include "ui/views/painter.h" |
| 25 | 26 |
| 26 namespace message_center { | 27 namespace message_center { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 constexpr int kHeaderHeight = 28; | 31 constexpr int kHeaderHeight = 28; |
| 31 constexpr int kAppIconSize = 12; | 32 constexpr int kAppIconSize = 12; |
| 32 constexpr int kExpandIconSize = 12; | 33 constexpr int kExpandIconSize = 12; |
| 33 constexpr gfx::Insets kHeaderPadding(0, 12, 0, 2); | 34 constexpr gfx::Insets kHeaderPadding(0, 12, 0, 2); |
| 34 constexpr int kHeaderHorizontalSpacing = 2; | 35 constexpr int kHeaderHorizontalSpacing = 2; |
| 35 constexpr int kAppInfoConatainerTopPadding = 12; | 36 constexpr int kAppInfoConatainerTopPadding = 12; |
| 36 // Bullet character. The divider symbol between different parts of the header. | 37 // Bullet character. The divider symbol between different parts of the header. |
| 37 constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022; | 38 constexpr wchar_t kNotificationHeaderDivider[] = L" \u2022 "; |
| 38 | 39 |
| 39 // Base ink drop color of action buttons. | 40 // Base ink drop color of action buttons. |
| 40 const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0); | 41 const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0); |
| 41 // Ripple ink drop opacity of action buttons. | 42 // Ripple ink drop opacity of action buttons. |
| 42 constexpr float kInkDropRippleVisibleOpacity = 0.08f; | 43 constexpr float kInkDropRippleVisibleOpacity = 0.08f; |
| 43 // Highlight (hover) ink drop opacity of action buttons. | 44 // Highlight (hover) ink drop opacity of action buttons. |
| 44 constexpr float kInkDropHighlightVisibleOpacity = 0.08f; | 45 constexpr float kInkDropHighlightVisibleOpacity = 0.08f; |
| 45 | 46 |
| 47 // base::TimeBase has similar constants, but some of them are missing. | |
| 48 constexpr int64_t kMinuteInMillis = 60LL * 1000LL; | |
| 49 constexpr int64_t kHourInMillis = 60LL * kMinuteInMillis; | |
| 50 constexpr int64_t kDayInMillis = 24LL * kHourInMillis; | |
| 51 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
| |
| 52 | |
| 46 // ExpandButtton forwards all mouse and key events to NotificationHeaderView, | 53 // ExpandButtton forwards all mouse and key events to NotificationHeaderView, |
| 47 // but takes tab focus for accessibility purpose. | 54 // but takes tab focus for accessibility purpose. |
| 48 class ExpandButton : public views::ImageView { | 55 class ExpandButton : public views::ImageView { |
| 49 public: | 56 public: |
| 50 ExpandButton(); | 57 ExpandButton(); |
| 51 ~ExpandButton() override; | 58 ~ExpandButton() override; |
| 52 | 59 |
| 53 void OnPaint(gfx::Canvas* canvas) override; | 60 void OnPaint(gfx::Canvas* canvas) override; |
| 54 void OnFocus() override; | 61 void OnFocus() override; |
| 55 void OnBlur() override; | 62 void OnBlur() override; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 76 void ExpandButton::OnFocus() { | 83 void ExpandButton::OnFocus() { |
| 77 views::ImageView::OnFocus(); | 84 views::ImageView::OnFocus(); |
| 78 SchedulePaint(); | 85 SchedulePaint(); |
| 79 } | 86 } |
| 80 | 87 |
| 81 void ExpandButton::OnBlur() { | 88 void ExpandButton::OnBlur() { |
| 82 views::ImageView::OnBlur(); | 89 views::ImageView::OnBlur(); |
| 83 SchedulePaint(); | 90 SchedulePaint(); |
| 84 } | 91 } |
| 85 | 92 |
| 93 // Do relative time string formatting that is similar to | |
| 94 // com.java.android.widget.DateTimeView.updateRelativeTime. | |
| 95 // Chromium has its own base::TimeFormat::Simple(), but none of the formats | |
| 96 // supported by the function is similar to Android's one. | |
| 97 base::string16 FormatToRelativeTime(base::Time past) { | |
| 98 base::Time now = base::Time::Now(); | |
| 99 int64_t duration = (now - past).InMilliseconds(); | |
| 100 if (duration < kMinuteInMillis) { | |
| 101 return l10n_util::GetStringUTF16( | |
| 102 IDS_MESSAGE_NOTIFICATION_NOW_STRING_SHORTEST); | |
| 103 } else if (duration < kHourInMillis) { | |
| 104 int count = static_cast<int>(duration / kMinuteInMillis); | |
| 105 return l10n_util::GetPluralStringFUTF16( | |
| 106 IDS_MESSAGE_NOTIFICATION_DURATION_MINUTES_SHORTEST, count); | |
| 107 } else if (duration < kDayInMillis) { | |
| 108 int count = static_cast<int>(duration / kHourInMillis); | |
| 109 return l10n_util::GetPluralStringFUTF16( | |
| 110 IDS_MESSAGE_NOTIFICATION_DURATION_HOURS_SHORTEST, count); | |
| 111 } else if (duration < kYearInMillis) { | |
| 112 int count = static_cast<int>(duration / kDayInMillis); | |
| 113 return l10n_util::GetPluralStringFUTF16( | |
| 114 IDS_MESSAGE_NOTIFICATION_DURATION_DAYS_SHORTEST, count); | |
| 115 } else { | |
| 116 int count = static_cast<int>(duration / kYearInMillis); | |
| 117 return l10n_util::GetPluralStringFUTF16( | |
| 118 IDS_MESSAGE_NOTIFICATION_DURATION_YEARS_SHORTEST, count); | |
| 119 } | |
| 120 } | |
| 121 | |
| 86 } // namespace | 122 } // namespace |
| 87 | 123 |
| 88 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) | 124 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) |
| 89 : views::CustomButton(listener) { | 125 : views::CustomButton(listener) { |
| 90 SetInkDropMode(InkDropMode::ON); | 126 SetInkDropMode(InkDropMode::ON); |
| 91 set_has_ink_drop_action_on_click(true); | 127 set_has_ink_drop_action_on_click(true); |
| 92 set_animate_on_state_change(true); | 128 set_animate_on_state_change(true); |
| 93 set_notify_enter_exit_on_child(true); | 129 set_notify_enter_exit_on_child(true); |
| 94 set_ink_drop_base_color(kInkDropBaseColor); | 130 set_ink_drop_base_color(kInkDropBaseColor); |
| 95 set_ink_drop_visible_opacity(kInkDropRippleVisibleOpacity); | 131 set_ink_drop_visible_opacity(kInkDropRippleVisibleOpacity); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 118 // App name view | 154 // App name view |
| 119 const gfx::FontList& font_list = views::Label().font_list().Derive( | 155 const gfx::FontList& font_list = views::Label().font_list().Derive( |
| 120 -2, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); | 156 -2, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); |
| 121 app_name_view_ = new views::Label(base::string16()); | 157 app_name_view_ = new views::Label(base::string16()); |
| 122 app_name_view_->SetFontList(font_list); | 158 app_name_view_->SetFontList(font_list); |
| 123 app_name_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 159 app_name_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 124 app_info_container->AddChildView(app_name_view_); | 160 app_info_container->AddChildView(app_name_view_); |
| 125 | 161 |
| 126 // Summary text divider | 162 // Summary text divider |
| 127 summary_text_divider_ = | 163 summary_text_divider_ = |
| 128 new views::Label(base::ASCIIToUTF16(" ") + | 164 new views::Label(base::WideToUTF16(kNotificationHeaderDivider)); |
| 129 base::string16(1, kNotificationHeaderDividerSymbol) + | |
| 130 base::ASCIIToUTF16(" ")); | |
| 131 summary_text_divider_->SetFontList(font_list); | 165 summary_text_divider_->SetFontList(font_list); |
| 132 summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 166 summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 133 summary_text_divider_->SetVisible(false); | 167 summary_text_divider_->SetVisible(false); |
| 134 app_info_container->AddChildView(summary_text_divider_); | 168 app_info_container->AddChildView(summary_text_divider_); |
| 135 | 169 |
| 136 // Summary text view | 170 // Summary text view |
| 137 summary_text_view_ = new views::Label(base::string16()); | 171 summary_text_view_ = new views::Label(base::string16()); |
| 138 summary_text_view_->SetFontList(font_list); | 172 summary_text_view_->SetFontList(font_list); |
| 139 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 173 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 140 summary_text_view_->SetVisible(false); | 174 summary_text_view_->SetVisible(false); |
| 141 app_info_container->AddChildView(summary_text_view_); | 175 app_info_container->AddChildView(summary_text_view_); |
| 142 | 176 |
| 177 // Timestamp divider | |
| 178 timestamp_divider_ = | |
| 179 new views::Label(base::WideToUTF16(kNotificationHeaderDivider)); | |
| 180 timestamp_divider_->SetFontList(font_list); | |
| 181 timestamp_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 182 timestamp_divider_->SetVisible(false); | |
| 183 app_info_container->AddChildView(timestamp_divider_); | |
| 184 | |
| 185 // Timestamp view | |
| 186 timestamp_view_ = new views::Label(base::string16()); | |
| 187 timestamp_view_->SetFontList(font_list); | |
| 188 timestamp_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 189 timestamp_view_->SetVisible(false); | |
| 190 app_info_container->AddChildView(timestamp_view_); | |
| 191 | |
| 143 // Expand button view | 192 // Expand button view |
| 144 expand_button_ = new ExpandButton(); | 193 expand_button_ = new ExpandButton(); |
| 145 app_info_container->AddChildView(expand_button_); | 194 app_info_container->AddChildView(expand_button_); |
| 146 | 195 |
| 147 // Spacer between left-aligned views and right-aligned views | 196 // Spacer between left-aligned views and right-aligned views |
| 148 views::View* spacer = new views::View; | 197 views::View* spacer = new views::View; |
| 149 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight)); | 198 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight)); |
| 150 AddChildView(spacer); | 199 AddChildView(spacer); |
| 151 layout->SetFlexForView(spacer, 1); | 200 layout->SetFlexForView(spacer, 1); |
| 152 | 201 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 has_overflow_indicator_ = false; | 247 has_overflow_indicator_ = false; |
| 199 } | 248 } |
| 200 UpdateSummaryTextVisibility(); | 249 UpdateSummaryTextVisibility(); |
| 201 } | 250 } |
| 202 | 251 |
| 203 void NotificationHeaderView::ClearOverflowIndicator() { | 252 void NotificationHeaderView::ClearOverflowIndicator() { |
| 204 has_overflow_indicator_ = false; | 253 has_overflow_indicator_ = false; |
| 205 UpdateSummaryTextVisibility(); | 254 UpdateSummaryTextVisibility(); |
| 206 } | 255 } |
| 207 | 256 |
| 257 void NotificationHeaderView::SetTimestamp(base::Time past) { | |
| 258 timestamp_view_->SetText(FormatToRelativeTime(past)); | |
| 259 has_timestamp_ = true; | |
| 260 UpdateSummaryTextVisibility(); | |
| 261 } | |
| 262 | |
| 263 void NotificationHeaderView::ClearTimestamp() { | |
| 264 has_timestamp_ = false; | |
| 265 UpdateSummaryTextVisibility(); | |
| 266 } | |
| 267 | |
| 208 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { | 268 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { |
| 209 // SetInkDropMode iff. the visibility changed. | 269 // SetInkDropMode iff. the visibility changed. |
| 210 // Otherwise, the ink drop animation cannot finish. | 270 // Otherwise, the ink drop animation cannot finish. |
| 211 if (expand_button_->visible() != enabled) | 271 if (expand_button_->visible() != enabled) |
| 212 SetInkDropMode(enabled ? InkDropMode::ON : InkDropMode::OFF); | 272 SetInkDropMode(enabled ? InkDropMode::ON : InkDropMode::OFF); |
| 213 | 273 |
| 214 expand_button_->SetVisible(enabled); | 274 expand_button_->SetVisible(enabled); |
| 215 } | 275 } |
| 216 | 276 |
| 217 void NotificationHeaderView::SetExpanded(bool expanded) { | 277 void NotificationHeaderView::SetExpanded(bool expanded) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 is_control_buttons_visible_); | 343 is_control_buttons_visible_); |
| 284 close_button_->SetVisible(close_button_enabled_ && | 344 close_button_->SetVisible(close_button_enabled_ && |
| 285 is_control_buttons_visible_); | 345 is_control_buttons_visible_); |
| 286 Layout(); | 346 Layout(); |
| 287 } | 347 } |
| 288 | 348 |
| 289 void NotificationHeaderView::UpdateSummaryTextVisibility() { | 349 void NotificationHeaderView::UpdateSummaryTextVisibility() { |
| 290 const bool visible = has_progress_ || has_overflow_indicator_; | 350 const bool visible = has_progress_ || has_overflow_indicator_; |
| 291 summary_text_divider_->SetVisible(visible); | 351 summary_text_divider_->SetVisible(visible); |
| 292 summary_text_view_->SetVisible(visible); | 352 summary_text_view_->SetVisible(visible); |
| 353 timestamp_divider_->SetVisible(!has_progress_ && has_timestamp_); | |
| 354 timestamp_view_->SetVisible(!has_progress_ && has_timestamp_); | |
| 293 Layout(); | 355 Layout(); |
| 294 } | 356 } |
| 295 | 357 |
| 296 } // namespace message_center | 358 } // namespace message_center |
| OLD | NEW |