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_view_md.h" | 5 #include "ui/message_center/views/notification_view_md.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 // ItemView //////////////////////////////////////////////////////////////////// | 111 // ItemView //////////////////////////////////////////////////////////////////// |
112 | 112 |
113 // ItemViews are responsible for drawing each list notification item's title and | 113 // ItemViews are responsible for drawing each list notification item's title and |
114 // message next to each other within a single column. | 114 // message next to each other within a single column. |
115 class ItemView : public views::View { | 115 class ItemView : public views::View { |
116 public: | 116 public: |
117 explicit ItemView(const message_center::NotificationItem& item); | 117 explicit ItemView(const message_center::NotificationItem& item); |
118 ~ItemView() override; | 118 ~ItemView() override; |
119 | 119 |
| 120 const char* GetClassName() const override; |
| 121 |
120 private: | 122 private: |
121 DISALLOW_COPY_AND_ASSIGN(ItemView); | 123 DISALLOW_COPY_AND_ASSIGN(ItemView); |
122 }; | 124 }; |
123 | 125 |
124 ItemView::ItemView(const message_center::NotificationItem& item) { | 126 ItemView::ItemView(const message_center::NotificationItem& item) { |
125 SetLayoutManager( | 127 SetLayoutManager( |
126 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), 0)); | 128 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), 0)); |
127 | 129 |
128 views::Label* title = new views::Label(item.title); | 130 views::Label* title = new views::Label(item.title); |
129 title->set_collapse_when_hidden(true); | 131 title->set_collapse_when_hidden(true); |
130 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 132 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
131 title->SetEnabledColor(message_center::kRegularTextColor); | 133 title->SetEnabledColor(message_center::kRegularTextColor); |
132 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 134 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
133 AddChildView(title); | 135 AddChildView(title); |
134 | 136 |
135 views::Label* message = new views::Label(l10n_util::GetStringFUTF16( | 137 views::Label* message = new views::Label(l10n_util::GetStringFUTF16( |
136 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_MESSAGE_WITH_DIVIDER, item.message)); | 138 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_MESSAGE_WITH_DIVIDER, item.message)); |
137 message->set_collapse_when_hidden(true); | 139 message->set_collapse_when_hidden(true); |
138 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 140 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
139 message->SetEnabledColor(message_center::kDimTextColor); | 141 message->SetEnabledColor(message_center::kDimTextColor); |
140 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 142 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
141 AddChildView(message); | 143 AddChildView(message); |
142 } | 144 } |
143 | 145 |
144 ItemView::~ItemView() = default; | 146 ItemView::~ItemView() = default; |
145 | 147 |
| 148 const char* ItemView::GetClassName() const { |
| 149 return "ItemView"; |
| 150 } |
| 151 |
146 // CompactTitleMessageView ///////////////////////////////////////////////////// | 152 // CompactTitleMessageView ///////////////////////////////////////////////////// |
147 | 153 |
148 // CompactTitleMessageView shows notification title and message in a single | 154 // CompactTitleMessageView shows notification title and message in a single |
149 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. | 155 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. |
150 class CompactTitleMessageView : public views::View { | 156 class CompactTitleMessageView : public views::View { |
151 public: | 157 public: |
152 explicit CompactTitleMessageView(); | 158 explicit CompactTitleMessageView(); |
153 ~CompactTitleMessageView() override; | 159 ~CompactTitleMessageView() override; |
154 | 160 |
| 161 const char* GetClassName() const override; |
| 162 |
155 void OnPaint(gfx::Canvas* canvas) override; | 163 void OnPaint(gfx::Canvas* canvas) override; |
156 | 164 |
157 void set_title(const base::string16& title) { title_ = title; } | 165 void set_title(const base::string16& title) { title_ = title; } |
158 void set_message(const base::string16& message) { message_ = message; } | 166 void set_message(const base::string16& message) { message_ = message; } |
159 | 167 |
160 private: | 168 private: |
161 DISALLOW_COPY_AND_ASSIGN(CompactTitleMessageView); | 169 DISALLOW_COPY_AND_ASSIGN(CompactTitleMessageView); |
162 | 170 |
163 base::string16 title_; | 171 base::string16 title_; |
164 base::string16 message_; | 172 base::string16 message_; |
165 | 173 |
166 views::Label* title_view_ = nullptr; | 174 views::Label* title_view_ = nullptr; |
167 views::Label* message_view_ = nullptr; | 175 views::Label* message_view_ = nullptr; |
168 }; | 176 }; |
169 | 177 |
170 CompactTitleMessageView::~CompactTitleMessageView() {} | 178 CompactTitleMessageView::~CompactTitleMessageView() = default; |
| 179 |
| 180 const char* CompactTitleMessageView::GetClassName() const { |
| 181 return "CompactTitleMessageView"; |
| 182 } |
171 | 183 |
172 CompactTitleMessageView::CompactTitleMessageView() { | 184 CompactTitleMessageView::CompactTitleMessageView() { |
173 SetLayoutManager(new views::FillLayout()); | 185 SetLayoutManager(new views::FillLayout()); |
174 | 186 |
175 const gfx::FontList& font_list = views::Label().font_list().Derive( | 187 const gfx::FontList& font_list = views::Label().font_list().Derive( |
176 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); | 188 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); |
177 | 189 |
178 title_view_ = new views::Label(); | 190 title_view_ = new views::Label(); |
179 title_view_->SetFontList(font_list); | 191 title_view_->SetFontList(font_list); |
180 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 192 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // This class is needed in addition to LabelButton mainly becuase we want to set | 235 // This class is needed in addition to LabelButton mainly becuase we want to set |
224 // visible_opacity of InkDropHighlight. | 236 // visible_opacity of InkDropHighlight. |
225 // This button capitalizes the given label string. | 237 // This button capitalizes the given label string. |
226 class NotificationButtonMD : public views::LabelButton { | 238 class NotificationButtonMD : public views::LabelButton { |
227 public: | 239 public: |
228 NotificationButtonMD(views::ButtonListener* listener, | 240 NotificationButtonMD(views::ButtonListener* listener, |
229 const base::string16& text); | 241 const base::string16& text); |
230 ~NotificationButtonMD() override; | 242 ~NotificationButtonMD() override; |
231 | 243 |
232 void SetText(const base::string16& text) override; | 244 void SetText(const base::string16& text) override; |
| 245 const char* GetClassName() const override; |
233 | 246 |
234 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | 247 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
235 const override; | 248 const override; |
236 | 249 |
237 private: | 250 private: |
238 DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD); | 251 DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD); |
239 }; | 252 }; |
240 | 253 |
241 NotificationButtonMD::NotificationButtonMD(views::ButtonListener* listener, | 254 NotificationButtonMD::NotificationButtonMD(views::ButtonListener* listener, |
242 const base::string16& text) | 255 const base::string16& text) |
(...skipping 10 matching lines...) Expand all Loading... |
253 SetMinSize(kActionButtonMinSize); | 266 SetMinSize(kActionButtonMinSize); |
254 SetFocusForPlatform(); | 267 SetFocusForPlatform(); |
255 } | 268 } |
256 | 269 |
257 NotificationButtonMD::~NotificationButtonMD() = default; | 270 NotificationButtonMD::~NotificationButtonMD() = default; |
258 | 271 |
259 void NotificationButtonMD::SetText(const base::string16& text) { | 272 void NotificationButtonMD::SetText(const base::string16& text) { |
260 views::LabelButton::SetText(base::i18n::ToUpper(text)); | 273 views::LabelButton::SetText(base::i18n::ToUpper(text)); |
261 } | 274 } |
262 | 275 |
| 276 const char* NotificationButtonMD::GetClassName() const { |
| 277 return "NotificationButtonMD"; |
| 278 } |
| 279 |
263 std::unique_ptr<views::InkDropHighlight> | 280 std::unique_ptr<views::InkDropHighlight> |
264 NotificationButtonMD::CreateInkDropHighlight() const { | 281 NotificationButtonMD::CreateInkDropHighlight() const { |
265 std::unique_ptr<views::InkDropHighlight> highlight = | 282 std::unique_ptr<views::InkDropHighlight> highlight = |
266 views::LabelButton::CreateInkDropHighlight(); | 283 views::LabelButton::CreateInkDropHighlight(); |
267 highlight->set_visible_opacity(kActionButtonInkDropHighlightVisibleOpacity); | 284 highlight->set_visible_opacity(kActionButtonInkDropHighlightVisibleOpacity); |
268 return highlight; | 285 return highlight; |
269 } | 286 } |
270 | 287 |
271 } // anonymous namespace | 288 } // anonymous namespace |
272 | 289 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 void NotificationViewMD::CreateOrUpdateViews(const Notification& notification) { | 325 void NotificationViewMD::CreateOrUpdateViews(const Notification& notification) { |
309 CreateOrUpdateContextTitleView(notification); | 326 CreateOrUpdateContextTitleView(notification); |
310 CreateOrUpdateTitleView(notification); | 327 CreateOrUpdateTitleView(notification); |
311 CreateOrUpdateMessageView(notification); | 328 CreateOrUpdateMessageView(notification); |
312 CreateOrUpdateCompactTitleMessageView(notification); | 329 CreateOrUpdateCompactTitleMessageView(notification); |
313 CreateOrUpdateProgressBarView(notification); | 330 CreateOrUpdateProgressBarView(notification); |
314 CreateOrUpdateListItemViews(notification); | 331 CreateOrUpdateListItemViews(notification); |
315 CreateOrUpdateIconView(notification); | 332 CreateOrUpdateIconView(notification); |
316 CreateOrUpdateSmallIconView(notification); | 333 CreateOrUpdateSmallIconView(notification); |
317 CreateOrUpdateImageView(notification); | 334 CreateOrUpdateImageView(notification); |
318 CreateOrUpdateActionButtonViews(notification); | |
319 CreateOrUpdateCloseButtonView(notification); | 335 CreateOrUpdateCloseButtonView(notification); |
320 CreateOrUpdateSettingsButtonView(notification); | 336 CreateOrUpdateSettingsButtonView(notification); |
321 UpdateViewForExpandedState(expanded_); | 337 UpdateViewForExpandedState(expanded_); |
| 338 // Should be called at the last because SynthesizeMouseMoveEvent() requires |
| 339 // everything is in the right location when called. |
| 340 CreateOrUpdateActionButtonViews(notification); |
322 } | 341 } |
323 | 342 |
324 NotificationViewMD::NotificationViewMD(MessageCenterController* controller, | 343 NotificationViewMD::NotificationViewMD(MessageCenterController* controller, |
325 const Notification& notification) | 344 const Notification& notification) |
326 : MessageView(controller, notification), | 345 : MessageView(controller, notification), |
327 clickable_(notification.clickable()) { | 346 clickable_(notification.clickable()) { |
328 SetLayoutManager( | 347 SetLayoutManager( |
329 new views::BoxLayout(views::BoxLayout::kVertical, gfx::Insets(), 0)); | 348 new views::BoxLayout(views::BoxLayout::kVertical, gfx::Insets(), 0)); |
330 | 349 |
331 // |header_row_| contains app_icon, app_name, control buttons, etc... | 350 // |header_row_| contains app_icon, app_name, control buttons, etc... |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 } | 495 } |
477 | 496 |
478 void NotificationViewMD::CreateOrUpdateContextTitleView( | 497 void NotificationViewMD::CreateOrUpdateContextTitleView( |
479 const Notification& notification) { | 498 const Notification& notification) { |
480 header_row_->SetAppName(notification.display_source()); | 499 header_row_->SetAppName(notification.display_source()); |
481 header_row_->SetTimestamp(notification.timestamp()); | 500 header_row_->SetTimestamp(notification.timestamp()); |
482 } | 501 } |
483 | 502 |
484 void NotificationViewMD::CreateOrUpdateTitleView( | 503 void NotificationViewMD::CreateOrUpdateTitleView( |
485 const Notification& notification) { | 504 const Notification& notification) { |
486 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { | 505 if (notification.title().empty() || |
487 left_content_->RemoveChildView(title_view_); | 506 notification.type() == NOTIFICATION_TYPE_PROGRESS) { |
| 507 if (title_view_) |
| 508 left_content_->RemoveChildView(title_view_); |
488 title_view_ = nullptr; | 509 title_view_ = nullptr; |
489 return; | 510 return; |
490 } | 511 } |
491 const gfx::FontList& font_list = views::Label().font_list().Derive( | 512 const gfx::FontList& font_list = views::Label().font_list().Derive( |
492 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); | 513 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); |
493 | 514 |
494 int title_character_limit = | 515 int title_character_limit = |
495 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; | 516 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; |
496 | 517 |
497 base::string16 title = gfx::TruncateString( | 518 base::string16 title = gfx::TruncateString( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 } else { | 553 } else { |
533 message_view_->SetText(text); | 554 message_view_->SetText(text); |
534 } | 555 } |
535 | 556 |
536 message_view_->SetVisible(notification.items().empty()); | 557 message_view_->SetVisible(notification.items().empty()); |
537 } | 558 } |
538 | 559 |
539 void NotificationViewMD::CreateOrUpdateCompactTitleMessageView( | 560 void NotificationViewMD::CreateOrUpdateCompactTitleMessageView( |
540 const Notification& notification) { | 561 const Notification& notification) { |
541 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 562 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
542 left_content_->RemoveChildView(compact_title_message_view_); | 563 if (compact_title_message_view_) |
| 564 left_content_->RemoveChildView(compact_title_message_view_); |
543 compact_title_message_view_ = nullptr; | 565 compact_title_message_view_ = nullptr; |
544 return; | 566 return; |
545 } | 567 } |
546 if (!compact_title_message_view_) { | 568 if (!compact_title_message_view_) { |
547 compact_title_message_view_ = new CompactTitleMessageView(); | 569 compact_title_message_view_ = new CompactTitleMessageView(); |
548 left_content_->AddChildView(compact_title_message_view_); | 570 left_content_->AddChildView(compact_title_message_view_); |
549 } | 571 } |
550 | 572 |
551 compact_title_message_view_->set_title(notification.title()); | 573 compact_title_message_view_->set_title(notification.title()); |
552 compact_title_message_view_->set_message(notification.message()); | 574 compact_title_message_view_->set_message(notification.message()); |
553 left_content_->InvalidateLayout(); | 575 left_content_->InvalidateLayout(); |
554 } | 576 } |
555 | 577 |
556 void NotificationViewMD::CreateOrUpdateProgressBarView( | 578 void NotificationViewMD::CreateOrUpdateProgressBarView( |
557 const Notification& notification) { | 579 const Notification& notification) { |
558 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 580 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
559 left_content_->RemoveChildView(progress_bar_view_); | 581 if (progress_bar_view_) |
| 582 left_content_->RemoveChildView(progress_bar_view_); |
560 progress_bar_view_ = nullptr; | 583 progress_bar_view_ = nullptr; |
561 header_row_->ClearProgress(); | 584 header_row_->ClearProgress(); |
562 return; | 585 return; |
563 } | 586 } |
564 | 587 |
565 DCHECK(left_content_); | 588 DCHECK(left_content_); |
566 | 589 |
567 if (!progress_bar_view_) { | 590 if (!progress_bar_view_) { |
568 progress_bar_view_ = new views::ProgressBar(kProgressBarHeight, | 591 progress_bar_view_ = new views::ProgressBar(kProgressBarHeight, |
569 /* allow_round_corner */ false); | 592 /* allow_round_corner */ false); |
(...skipping 27 matching lines...) Expand all Loading... |
597 | 620 |
598 // Needed when CreateOrUpdateViews is called for update. | 621 // Needed when CreateOrUpdateViews is called for update. |
599 if (!item_views_.empty()) | 622 if (!item_views_.empty()) |
600 left_content_->InvalidateLayout(); | 623 left_content_->InvalidateLayout(); |
601 } | 624 } |
602 | 625 |
603 void NotificationViewMD::CreateOrUpdateIconView( | 626 void NotificationViewMD::CreateOrUpdateIconView( |
604 const Notification& notification) { | 627 const Notification& notification) { |
605 if (notification.type() == NOTIFICATION_TYPE_PROGRESS || | 628 if (notification.type() == NOTIFICATION_TYPE_PROGRESS || |
606 notification.type() == NOTIFICATION_TYPE_MULTIPLE) { | 629 notification.type() == NOTIFICATION_TYPE_MULTIPLE) { |
607 right_content_->RemoveChildView(icon_view_); | 630 if (icon_view_) |
| 631 right_content_->RemoveChildView(icon_view_); |
608 icon_view_ = nullptr; | 632 icon_view_ = nullptr; |
609 return; | 633 return; |
610 } | 634 } |
611 | 635 |
612 gfx::Size image_view_size(30, 30); | 636 gfx::Size image_view_size(30, 30); |
613 if (!icon_view_) { | 637 if (!icon_view_) { |
614 icon_view_ = new ProportionalImageView(image_view_size); | 638 icon_view_ = new ProportionalImageView(image_view_size); |
615 right_content_->AddChildView(icon_view_); | 639 right_content_->AddChildView(icon_view_); |
616 } | 640 } |
617 | 641 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 new NotificationButtonMD(this, button_info.title); | 713 new NotificationButtonMD(this, button_info.title); |
690 action_buttons_.push_back(button); | 714 action_buttons_.push_back(button); |
691 actions_row_->AddChildView(button); | 715 actions_row_->AddChildView(button); |
692 } else { | 716 } else { |
693 action_buttons_[i]->SetText(button_info.title); | 717 action_buttons_[i]->SetText(button_info.title); |
694 action_buttons_[i]->SchedulePaint(); | 718 action_buttons_[i]->SchedulePaint(); |
695 action_buttons_[i]->Layout(); | 719 action_buttons_[i]->Layout(); |
696 } | 720 } |
697 } | 721 } |
698 | 722 |
699 if (new_buttons) { | 723 // Inherit mouse hover state when action button views reset. |
700 // TODO(fukino): Investigate if this Layout() is necessary. | 724 // If the view is not expanded, there should be no hover state. |
701 Layout(); | 725 if (new_buttons && expanded_) { |
702 views::Widget* widget = GetWidget(); | 726 views::Widget* widget = GetWidget(); |
703 if (widget != NULL) { | 727 if (widget) { |
| 728 // This Layout() is needed because button should be in the right location |
| 729 // in the view hierarchy when SynthesizeMouseMoveEvent() is called. |
| 730 Layout(); |
704 widget->SetSize(widget->GetContentsView()->GetPreferredSize()); | 731 widget->SetSize(widget->GetContentsView()->GetPreferredSize()); |
705 GetWidget()->SynthesizeMouseMoveEvent(); | 732 GetWidget()->SynthesizeMouseMoveEvent(); |
706 } | 733 } |
707 } | 734 } |
708 } | 735 } |
709 | 736 |
710 void NotificationViewMD::CreateOrUpdateCloseButtonView( | 737 void NotificationViewMD::CreateOrUpdateCloseButtonView( |
711 const Notification& notification) { | 738 const Notification& notification) { |
712 if (!notification.pinned()) { | 739 if (!notification.pinned()) { |
713 header_row_->SetCloseButtonEnabled(true); | 740 header_row_->SetCloseButtonEnabled(true); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 header_row_->expand_button()->HasFocus()) || | 806 header_row_->expand_button()->HasFocus()) || |
780 (header_row_->IsCloseButtonEnabled() && | 807 (header_row_->IsCloseButtonEnabled() && |
781 header_row_->close_button()->HasFocus()) || | 808 header_row_->close_button()->HasFocus()) || |
782 (header_row_->IsSettingsButtonEnabled() && | 809 (header_row_->IsSettingsButtonEnabled() && |
783 header_row_->settings_button()->HasFocus()); | 810 header_row_->settings_button()->HasFocus()); |
784 | 811 |
785 header_row_->SetControlButtonsVisible(target_visibility); | 812 header_row_->SetControlButtonsVisible(target_visibility); |
786 } | 813 } |
787 | 814 |
788 } // namespace message_center | 815 } // namespace message_center |
OLD | NEW |