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

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

Issue 2966343002: Port NotificationViewMD unit tests from NotificationViewTest. (Closed)
Patch Set: Added Slide tests. 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_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/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "ui/base/cursor/cursor.h" 10 #include "ui/base/cursor/cursor.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 // ItemView //////////////////////////////////////////////////////////////////// 110 // ItemView ////////////////////////////////////////////////////////////////////
111 111
112 // ItemViews are responsible for drawing each list notification item's title and 112 // ItemViews are responsible for drawing each list notification item's title and
113 // message next to each other within a single column. 113 // message next to each other within a single column.
114 class ItemView : public views::View { 114 class ItemView : public views::View {
115 public: 115 public:
116 explicit ItemView(const message_center::NotificationItem& item); 116 explicit ItemView(const message_center::NotificationItem& item);
117 ~ItemView() override; 117 ~ItemView() override;
118 118
119 const char* GetClassName() const override;
120
119 private: 121 private:
120 DISALLOW_COPY_AND_ASSIGN(ItemView); 122 DISALLOW_COPY_AND_ASSIGN(ItemView);
121 }; 123 };
122 124
123 ItemView::ItemView(const message_center::NotificationItem& item) { 125 ItemView::ItemView(const message_center::NotificationItem& item) {
124 SetLayoutManager( 126 SetLayoutManager(
125 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), 0)); 127 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), 0));
126 128
127 views::Label* title = new views::Label(item.title); 129 views::Label* title = new views::Label(item.title);
128 title->set_collapse_when_hidden(true); 130 title->set_collapse_when_hidden(true);
129 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); 131 title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
130 title->SetEnabledColor(message_center::kRegularTextColor); 132 title->SetEnabledColor(message_center::kRegularTextColor);
131 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); 133 title->SetBackgroundColor(message_center::kDimTextBackgroundColor);
132 AddChildView(title); 134 AddChildView(title);
133 135
134 views::Label* message = new views::Label(l10n_util::GetStringFUTF16( 136 views::Label* message = new views::Label(l10n_util::GetStringFUTF16(
135 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_MESSAGE_WITH_DIVIDER, item.message)); 137 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_MESSAGE_WITH_DIVIDER, item.message));
136 message->set_collapse_when_hidden(true); 138 message->set_collapse_when_hidden(true);
137 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); 139 message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
138 message->SetEnabledColor(message_center::kDimTextColor); 140 message->SetEnabledColor(message_center::kDimTextColor);
139 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); 141 message->SetBackgroundColor(message_center::kDimTextBackgroundColor);
140 AddChildView(message); 142 AddChildView(message);
141 } 143 }
142 144
143 ItemView::~ItemView() = default; 145 ItemView::~ItemView() = default;
144 146
147 const char* ItemView::GetClassName() const {
148 return "ItemView";
149 }
150
145 // CompactTitleMessageView ///////////////////////////////////////////////////// 151 // CompactTitleMessageView /////////////////////////////////////////////////////
146 152
147 // CompactTitleMessageView shows notification title and message in a single 153 // CompactTitleMessageView shows notification title and message in a single
148 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. 154 // line. This view is used for NOTIFICATION_TYPE_PROGRESS.
149 class CompactTitleMessageView : public views::View { 155 class CompactTitleMessageView : public views::View {
150 public: 156 public:
151 explicit CompactTitleMessageView(); 157 explicit CompactTitleMessageView();
152 ~CompactTitleMessageView() override; 158 ~CompactTitleMessageView() override;
153 159
160 const char* GetClassName() const override;
161
154 void OnPaint(gfx::Canvas* canvas) override; 162 void OnPaint(gfx::Canvas* canvas) override;
155 163
156 void set_title(const base::string16& title) { title_ = title; } 164 void set_title(const base::string16& title) { title_ = title; }
157 void set_message(const base::string16& message) { message_ = message; } 165 void set_message(const base::string16& message) { message_ = message; }
158 166
159 private: 167 private:
160 DISALLOW_COPY_AND_ASSIGN(CompactTitleMessageView); 168 DISALLOW_COPY_AND_ASSIGN(CompactTitleMessageView);
161 169
162 base::string16 title_; 170 base::string16 title_;
163 base::string16 message_; 171 base::string16 message_;
164 172
165 views::Label* title_view_ = nullptr; 173 views::Label* title_view_ = nullptr;
166 views::Label* message_view_ = nullptr; 174 views::Label* message_view_ = nullptr;
167 }; 175 };
168 176
169 CompactTitleMessageView::~CompactTitleMessageView() {} 177 CompactTitleMessageView::~CompactTitleMessageView() = default;
178
179 const char* CompactTitleMessageView::GetClassName() const {
180 return "CompactTitleMessageView";
181 }
170 182
171 CompactTitleMessageView::CompactTitleMessageView() { 183 CompactTitleMessageView::CompactTitleMessageView() {
172 SetLayoutManager(new views::FillLayout()); 184 SetLayoutManager(new views::FillLayout());
173 185
174 const gfx::FontList& font_list = views::Label().font_list().Derive( 186 const gfx::FontList& font_list = views::Label().font_list().Derive(
175 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); 187 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL);
176 188
177 title_view_ = new views::Label(); 189 title_view_ = new views::Label();
178 title_view_->SetFontList(font_list); 190 title_view_->SetFontList(font_list);
179 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 191 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // NotificationButtonMD //////////////////////////////////////////////////////// 232 // NotificationButtonMD ////////////////////////////////////////////////////////
221 233
222 // This class is needed in addition to LabelButton mainly becuase we want to set 234 // This class is needed in addition to LabelButton mainly becuase we want to set
223 // visible_opacity of InkDropHighlight. 235 // visible_opacity of InkDropHighlight.
224 class NotificationButtonMD : public views::LabelButton { 236 class NotificationButtonMD : public views::LabelButton {
225 public: 237 public:
226 NotificationButtonMD(views::ButtonListener* listener, 238 NotificationButtonMD(views::ButtonListener* listener,
227 const base::string16& text); 239 const base::string16& text);
228 ~NotificationButtonMD() override; 240 ~NotificationButtonMD() override;
229 241
242 const char* GetClassName() const override;
243
230 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() 244 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
231 const override; 245 const override;
232 246
233 private: 247 private:
234 DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD); 248 DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD);
235 }; 249 };
236 250
237 NotificationButtonMD::NotificationButtonMD(views::ButtonListener* listener, 251 NotificationButtonMD::NotificationButtonMD(views::ButtonListener* listener,
238 const base::string16& text) 252 const base::string16& text)
239 : views::LabelButton(listener, text, views::style::CONTEXT_BUTTON_MD) { 253 : views::LabelButton(listener, text, views::style::CONTEXT_BUTTON_MD) {
240 SetInkDropMode(views::LabelButton::InkDropMode::ON); 254 SetInkDropMode(views::LabelButton::InkDropMode::ON);
241 set_has_ink_drop_action_on_click(true); 255 set_has_ink_drop_action_on_click(true);
242 set_ink_drop_base_color(kActionButtonInkDropBaseColor); 256 set_ink_drop_base_color(kActionButtonInkDropBaseColor);
243 set_ink_drop_visible_opacity(kActionButtonInkDropRippleVisibleOpacity); 257 set_ink_drop_visible_opacity(kActionButtonInkDropRippleVisibleOpacity);
244 SetEnabledTextColors(kActionButtonTextColor); 258 SetEnabledTextColors(kActionButtonTextColor);
245 SetBorder(views::CreateEmptyBorder(kActionButtonPadding)); 259 SetBorder(views::CreateEmptyBorder(kActionButtonPadding));
246 SetMinSize(kActionButtonMinSize); 260 SetMinSize(kActionButtonMinSize);
247 SetFocusForPlatform(); 261 SetFocusForPlatform();
248 } 262 }
249 263
250 NotificationButtonMD::~NotificationButtonMD() = default; 264 NotificationButtonMD::~NotificationButtonMD() = default;
251 265
266 const char* NotificationButtonMD::GetClassName() const {
267 return "NotificationButtonMD";
268 }
269
252 std::unique_ptr<views::InkDropHighlight> 270 std::unique_ptr<views::InkDropHighlight>
253 NotificationButtonMD::CreateInkDropHighlight() const { 271 NotificationButtonMD::CreateInkDropHighlight() const {
254 std::unique_ptr<views::InkDropHighlight> highlight = 272 std::unique_ptr<views::InkDropHighlight> highlight =
255 views::LabelButton::CreateInkDropHighlight(); 273 views::LabelButton::CreateInkDropHighlight();
256 highlight->set_visible_opacity(kActionButtonInkDropHighlightVisibleOpacity); 274 highlight->set_visible_opacity(kActionButtonInkDropHighlightVisibleOpacity);
257 return highlight; 275 return highlight;
258 } 276 }
259 277
260 } // anonymous namespace 278 } // anonymous namespace
261 279
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 void NotificationViewMD::CreateOrUpdateViews(const Notification& notification) { 315 void NotificationViewMD::CreateOrUpdateViews(const Notification& notification) {
298 CreateOrUpdateContextTitleView(notification); 316 CreateOrUpdateContextTitleView(notification);
299 CreateOrUpdateTitleView(notification); 317 CreateOrUpdateTitleView(notification);
300 CreateOrUpdateMessageView(notification); 318 CreateOrUpdateMessageView(notification);
301 CreateOrUpdateCompactTitleMessageView(notification); 319 CreateOrUpdateCompactTitleMessageView(notification);
302 CreateOrUpdateProgressBarView(notification); 320 CreateOrUpdateProgressBarView(notification);
303 CreateOrUpdateListItemViews(notification); 321 CreateOrUpdateListItemViews(notification);
304 CreateOrUpdateIconView(notification); 322 CreateOrUpdateIconView(notification);
305 CreateOrUpdateSmallIconView(notification); 323 CreateOrUpdateSmallIconView(notification);
306 CreateOrUpdateImageView(notification); 324 CreateOrUpdateImageView(notification);
307 CreateOrUpdateActionButtonViews(notification);
308 CreateOrUpdateCloseButtonView(notification); 325 CreateOrUpdateCloseButtonView(notification);
309 CreateOrUpdateSettingsButtonView(notification); 326 CreateOrUpdateSettingsButtonView(notification);
310 UpdateViewForExpandedState(expanded_); 327 UpdateViewForExpandedState(expanded_);
328 // Should be called at the last because SynthesizeMouseMoveEvent() requires
329 // everything is in the right location when called.
330 CreateOrUpdateActionButtonViews(notification);
311 } 331 }
312 332
313 NotificationViewMD::NotificationViewMD(MessageCenterController* controller, 333 NotificationViewMD::NotificationViewMD(MessageCenterController* controller,
314 const Notification& notification) 334 const Notification& notification)
315 : MessageView(controller, notification), 335 : MessageView(controller, notification),
316 clickable_(notification.clickable()) { 336 clickable_(notification.clickable()) {
317 SetLayoutManager( 337 SetLayoutManager(
318 new views::BoxLayout(views::BoxLayout::kVertical, gfx::Insets(), 0)); 338 new views::BoxLayout(views::BoxLayout::kVertical, gfx::Insets(), 0));
319 339
320 // |header_row_| contains app_icon, app_name, control buttons, etc... 340 // |header_row_| contains app_icon, app_name, control buttons, etc...
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 485 }
466 486
467 void NotificationViewMD::CreateOrUpdateContextTitleView( 487 void NotificationViewMD::CreateOrUpdateContextTitleView(
468 const Notification& notification) { 488 const Notification& notification) {
469 header_row_->SetAppName(notification.display_source()); 489 header_row_->SetAppName(notification.display_source());
470 header_row_->SetTimestamp(notification.timestamp()); 490 header_row_->SetTimestamp(notification.timestamp());
471 } 491 }
472 492
473 void NotificationViewMD::CreateOrUpdateTitleView( 493 void NotificationViewMD::CreateOrUpdateTitleView(
474 const Notification& notification) { 494 const Notification& notification) {
475 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { 495 if (notification.title().empty() ||
476 left_content_->RemoveChildView(title_view_); 496 notification.type() == NOTIFICATION_TYPE_PROGRESS) {
497 if (title_view_ != nullptr)
fukino 2017/07/06 12:44:10 nit: "if (title_view_)" is sufficient and consiste
tetsui 2017/07/07 01:52:41 Done.
498 left_content_->RemoveChildView(title_view_);
477 title_view_ = nullptr; 499 title_view_ = nullptr;
478 return; 500 return;
479 } 501 }
480 const gfx::FontList& font_list = views::Label().font_list().Derive( 502 const gfx::FontList& font_list = views::Label().font_list().Derive(
481 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); 503 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL);
482 504
483 int title_character_limit = 505 int title_character_limit =
484 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; 506 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter;
485 507
486 base::string16 title = gfx::TruncateString( 508 base::string16 title = gfx::TruncateString(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } else { 543 } else {
522 message_view_->SetText(text); 544 message_view_->SetText(text);
523 } 545 }
524 546
525 message_view_->SetVisible(notification.items().empty()); 547 message_view_->SetVisible(notification.items().empty());
526 } 548 }
527 549
528 void NotificationViewMD::CreateOrUpdateCompactTitleMessageView( 550 void NotificationViewMD::CreateOrUpdateCompactTitleMessageView(
529 const Notification& notification) { 551 const Notification& notification) {
530 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { 552 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) {
531 left_content_->RemoveChildView(compact_title_message_view_); 553 if (compact_title_message_view_ != nullptr)
fukino 2017/07/06 12:44:11 ditto
tetsui 2017/07/07 01:52:41 Done.
554 left_content_->RemoveChildView(compact_title_message_view_);
532 compact_title_message_view_ = nullptr; 555 compact_title_message_view_ = nullptr;
533 return; 556 return;
534 } 557 }
535 if (!compact_title_message_view_) { 558 if (!compact_title_message_view_) {
536 compact_title_message_view_ = new CompactTitleMessageView(); 559 compact_title_message_view_ = new CompactTitleMessageView();
537 left_content_->AddChildView(compact_title_message_view_); 560 left_content_->AddChildView(compact_title_message_view_);
538 } 561 }
539 562
540 compact_title_message_view_->set_title(notification.title()); 563 compact_title_message_view_->set_title(notification.title());
541 compact_title_message_view_->set_message(notification.message()); 564 compact_title_message_view_->set_message(notification.message());
542 left_content_->InvalidateLayout(); 565 left_content_->InvalidateLayout();
543 } 566 }
544 567
545 void NotificationViewMD::CreateOrUpdateProgressBarView( 568 void NotificationViewMD::CreateOrUpdateProgressBarView(
546 const Notification& notification) { 569 const Notification& notification) {
547 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { 570 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) {
548 left_content_->RemoveChildView(progress_bar_view_); 571 if (progress_bar_view_ != nullptr)
fukino 2017/07/06 12:44:10 ditto
tetsui 2017/07/07 01:52:41 Done.
572 left_content_->RemoveChildView(progress_bar_view_);
549 progress_bar_view_ = nullptr; 573 progress_bar_view_ = nullptr;
550 header_row_->ClearProgress(); 574 header_row_->ClearProgress();
551 return; 575 return;
552 } 576 }
553 577
554 DCHECK(left_content_); 578 DCHECK(left_content_);
555 579
556 if (!progress_bar_view_) { 580 if (!progress_bar_view_) {
557 progress_bar_view_ = new views::ProgressBar(kProgressBarHeight, 581 progress_bar_view_ = new views::ProgressBar(kProgressBarHeight,
558 /* allow_round_corner */ false); 582 /* allow_round_corner */ false);
(...skipping 27 matching lines...) Expand all
586 610
587 // Needed when CreateOrUpdateViews is called for update. 611 // Needed when CreateOrUpdateViews is called for update.
588 if (!item_views_.empty()) 612 if (!item_views_.empty())
589 left_content_->InvalidateLayout(); 613 left_content_->InvalidateLayout();
590 } 614 }
591 615
592 void NotificationViewMD::CreateOrUpdateIconView( 616 void NotificationViewMD::CreateOrUpdateIconView(
593 const Notification& notification) { 617 const Notification& notification) {
594 if (notification.type() == NOTIFICATION_TYPE_PROGRESS || 618 if (notification.type() == NOTIFICATION_TYPE_PROGRESS ||
595 notification.type() == NOTIFICATION_TYPE_MULTIPLE) { 619 notification.type() == NOTIFICATION_TYPE_MULTIPLE) {
596 right_content_->RemoveChildView(icon_view_); 620 if (icon_view_ != nullptr)
fukino 2017/07/06 12:44:11 ditto
tetsui 2017/07/07 01:52:41 Done.
621 right_content_->RemoveChildView(icon_view_);
597 icon_view_ = nullptr; 622 icon_view_ = nullptr;
598 return; 623 return;
599 } 624 }
600 625
601 gfx::Size image_view_size(30, 30); 626 gfx::Size image_view_size(30, 30);
602 if (!icon_view_) { 627 if (!icon_view_) {
603 icon_view_ = new ProportionalImageView(image_view_size); 628 icon_view_ = new ProportionalImageView(image_view_size);
604 right_content_->AddChildView(icon_view_); 629 right_content_->AddChildView(icon_view_);
605 } 630 }
606 631
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 new NotificationButtonMD(this, button_info.title); 703 new NotificationButtonMD(this, button_info.title);
679 action_buttons_.push_back(button); 704 action_buttons_.push_back(button);
680 actions_row_->AddChildView(button); 705 actions_row_->AddChildView(button);
681 } else { 706 } else {
682 action_buttons_[i]->SetText(button_info.title); 707 action_buttons_[i]->SetText(button_info.title);
683 action_buttons_[i]->SchedulePaint(); 708 action_buttons_[i]->SchedulePaint();
684 action_buttons_[i]->Layout(); 709 action_buttons_[i]->Layout();
685 } 710 }
686 } 711 }
687 712
688 if (new_buttons) { 713 // Inherit mouse hover state when action button views reset.
689 // TODO(fukino): Investigate if this Layout() is necessary. 714 // If the view is not expanded, there should be no hover state.
690 Layout(); 715 if (new_buttons && expanded_) {
691 views::Widget* widget = GetWidget(); 716 views::Widget* widget = GetWidget();
692 if (widget != NULL) { 717 if (widget != nullptr) {
fukino 2017/07/06 12:44:11 ditto
tetsui 2017/07/07 01:52:41 Done.
718 // This Layout() is needed because button should be in the right location
719 // in the view hierarchy when SynthesizeMouseMoveEvent() is called.
720 Layout();
693 widget->SetSize(widget->GetContentsView()->GetPreferredSize()); 721 widget->SetSize(widget->GetContentsView()->GetPreferredSize());
694 GetWidget()->SynthesizeMouseMoveEvent(); 722 GetWidget()->SynthesizeMouseMoveEvent();
695 } 723 }
696 } 724 }
697 } 725 }
698 726
699 void NotificationViewMD::CreateOrUpdateCloseButtonView( 727 void NotificationViewMD::CreateOrUpdateCloseButtonView(
700 const Notification& notification) { 728 const Notification& notification) {
701 if (!notification.pinned()) { 729 if (!notification.pinned()) {
702 header_row_->SetCloseButtonEnabled(true); 730 header_row_->SetCloseButtonEnabled(true);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 header_row_->expand_button()->HasFocus()) || 796 header_row_->expand_button()->HasFocus()) ||
769 (header_row_->IsCloseButtonEnabled() && 797 (header_row_->IsCloseButtonEnabled() &&
770 header_row_->close_button()->HasFocus()) || 798 header_row_->close_button()->HasFocus()) ||
771 (header_row_->IsSettingsButtonEnabled() && 799 (header_row_->IsSettingsButtonEnabled() &&
772 header_row_->settings_button()->HasFocus()); 800 header_row_->settings_button()->HasFocus());
773 801
774 header_row_->SetControlButtonsVisible(target_visibility); 802 header_row_->SetControlButtonsVisible(target_visibility);
775 } 803 }
776 804
777 } // namespace message_center 805 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view_md.h ('k') | ui/message_center/views/notification_view_md_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698