Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: ui/message_center/views/notification_header_view.cc

Issue 2972493002: Implement time stamp in new-style notification. (Closed)
Patch Set: Modify comment. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 17 matching lines...) Expand all
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 base::char16 kNotificationHeaderDividerSymbol = 0x2022;
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 = 60L * 1000L;
fukino 2017/07/05 06:42:59 Use the LL or ULL to create 64-bit constants. http
tetsui 2017/07/05 06:57:19 Done.
49 constexpr int64_t kHourInMillis = 60L * kMinuteInMillis;
50 constexpr int64_t kDayInMillis = 24L * kHourInMillis;
51 constexpr int64_t kYearInMillis = 365L * kDayInMillis;
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
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 20 matching lines...) Expand all
116 app_info_container->AddChildView(app_icon_view_); 152 app_info_container->AddChildView(app_icon_view_);
117 153
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
162 base::string16 divider_text =
fukino 2017/07/05 06:42:59 Instead of constructing the string here, how about
tetsui 2017/07/05 06:57:19 Done.
163 base::ASCIIToUTF16(" ") +
164 base::string16(1, kNotificationHeaderDividerSymbol) +
165 base::ASCIIToUTF16(" ");
166
126 // Summary text divider 167 // Summary text divider
127 summary_text_divider_ = 168 summary_text_divider_ = new views::Label(divider_text);
128 new views::Label(base::ASCIIToUTF16(" ") +
129 base::string16(1, kNotificationHeaderDividerSymbol) +
130 base::ASCIIToUTF16(" "));
131 summary_text_divider_->SetFontList(font_list); 169 summary_text_divider_->SetFontList(font_list);
132 summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 170 summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
133 summary_text_divider_->SetVisible(false); 171 summary_text_divider_->SetVisible(false);
134 app_info_container->AddChildView(summary_text_divider_); 172 app_info_container->AddChildView(summary_text_divider_);
135 173
136 // Summary text view 174 // Summary text view
137 summary_text_view_ = new views::Label(base::string16()); 175 summary_text_view_ = new views::Label(base::string16());
138 summary_text_view_->SetFontList(font_list); 176 summary_text_view_->SetFontList(font_list);
139 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 177 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
140 summary_text_view_->SetVisible(false); 178 summary_text_view_->SetVisible(false);
141 app_info_container->AddChildView(summary_text_view_); 179 app_info_container->AddChildView(summary_text_view_);
142 180
181 // Timestamp divider
182 timestamp_divider_ = new views::Label(divider_text);
183 timestamp_divider_->SetFontList(font_list);
184 timestamp_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
185 timestamp_divider_->SetVisible(false);
186 app_info_container->AddChildView(timestamp_divider_);
187
188 // Timestamp view
189 timestamp_view_ = new views::Label(base::string16());
190 timestamp_view_->SetFontList(font_list);
191 timestamp_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
192 timestamp_view_->SetVisible(false);
193 app_info_container->AddChildView(timestamp_view_);
194
143 // Expand button view 195 // Expand button view
144 expand_button_ = new ExpandButton(); 196 expand_button_ = new ExpandButton();
145 app_info_container->AddChildView(expand_button_); 197 app_info_container->AddChildView(expand_button_);
146 198
147 // Spacer between left-aligned views and right-aligned views 199 // Spacer between left-aligned views and right-aligned views
148 views::View* spacer = new views::View; 200 views::View* spacer = new views::View;
149 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight)); 201 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight));
150 AddChildView(spacer); 202 AddChildView(spacer);
151 layout->SetFlexForView(spacer, 1); 203 layout->SetFlexForView(spacer, 1);
152 204
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 has_overflow_indicator_ = false; 250 has_overflow_indicator_ = false;
199 } 251 }
200 UpdateSummaryTextVisibility(); 252 UpdateSummaryTextVisibility();
201 } 253 }
202 254
203 void NotificationHeaderView::ClearOverflowIndicator() { 255 void NotificationHeaderView::ClearOverflowIndicator() {
204 has_overflow_indicator_ = false; 256 has_overflow_indicator_ = false;
205 UpdateSummaryTextVisibility(); 257 UpdateSummaryTextVisibility();
206 } 258 }
207 259
260 void NotificationHeaderView::SetTimestamp(base::Time past) {
261 timestamp_view_->SetText(FormatToRelativeTime(past));
262 has_timestamp_ = true;
263 UpdateSummaryTextVisibility();
264 }
265
266 void NotificationHeaderView::ClearTimestamp() {
267 has_timestamp_ = false;
268 UpdateSummaryTextVisibility();
269 }
270
208 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { 271 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) {
209 // SetInkDropMode iff. the visibility changed. 272 // SetInkDropMode iff. the visibility changed.
210 // Otherwise, the ink drop animation cannot finish. 273 // Otherwise, the ink drop animation cannot finish.
211 if (expand_button_->visible() != enabled) 274 if (expand_button_->visible() != enabled)
212 SetInkDropMode(enabled ? InkDropMode::ON : InkDropMode::OFF); 275 SetInkDropMode(enabled ? InkDropMode::ON : InkDropMode::OFF);
213 276
214 expand_button_->SetVisible(enabled); 277 expand_button_->SetVisible(enabled);
215 } 278 }
216 279
217 void NotificationHeaderView::SetExpanded(bool expanded) { 280 void NotificationHeaderView::SetExpanded(bool expanded) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 is_control_buttons_visible_); 346 is_control_buttons_visible_);
284 close_button_->SetVisible(close_button_enabled_ && 347 close_button_->SetVisible(close_button_enabled_ &&
285 is_control_buttons_visible_); 348 is_control_buttons_visible_);
286 Layout(); 349 Layout();
287 } 350 }
288 351
289 void NotificationHeaderView::UpdateSummaryTextVisibility() { 352 void NotificationHeaderView::UpdateSummaryTextVisibility() {
290 const bool visible = has_progress_ || has_overflow_indicator_; 353 const bool visible = has_progress_ || has_overflow_indicator_;
291 summary_text_divider_->SetVisible(visible); 354 summary_text_divider_->SetVisible(visible);
292 summary_text_view_->SetVisible(visible); 355 summary_text_view_->SetVisible(visible);
356 timestamp_divider_->SetVisible(!has_progress_ && has_timestamp_);
357 timestamp_view_->SetVisible(!has_progress_ && has_timestamp_);
293 Layout(); 358 Layout();
294 } 359 }
295 360
296 } // namespace message_center 361 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_header_view.h ('k') | ui/message_center/views/notification_view_md.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698