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

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

Issue 2922903002: Add List notification support to new-style notification. (Closed)
Patch Set: Fix layout bug. Created 3 years, 6 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 "base/strings/utf_string_conversions.h"
10 #include "ui/base/cursor/cursor.h" 11 #include "ui/base/cursor/cursor.h"
11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
13 #include "ui/gfx/image/image_skia_operations.h" 14 #include "ui/gfx/image/image_skia_operations.h"
14 #include "ui/gfx/paint_vector_icon.h" 15 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/gfx/skia_util.h" 16 #include "ui/gfx/skia_util.h"
16 #include "ui/gfx/text_elider.h" 17 #include "ui/gfx/text_elider.h"
17 #include "ui/message_center/message_center.h" 18 #include "ui/message_center/message_center.h"
18 #include "ui/message_center/message_center_style.h" 19 #include "ui/message_center/message_center_style.h"
19 #include "ui/message_center/notification.h" 20 #include "ui/message_center/notification.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const gfx::ImageSkia masked_small_image = 84 const gfx::ImageSkia masked_small_image =
84 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon); 85 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon);
85 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, 86 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background,
86 masked_small_image); 87 masked_small_image);
87 } 88 }
88 89
89 const gfx::ImageSkia GetProductIcon() { 90 const gfx::ImageSkia GetProductIcon() {
90 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); 91 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor);
91 } 92 }
92 93
94 // ItemView ////////////////////////////////////////////////////////////////////
95
96 // ItemViews are responsible for drawing each list notification item's title and
97 // message next to each other within a single column.
98 class ItemView : public views::View {
99 public:
100 explicit ItemView(const message_center::NotificationItem& item);
101 ~ItemView() override;
102
103 private:
104 DISALLOW_COPY_AND_ASSIGN(ItemView);
105 };
106
107 ItemView::ItemView(const message_center::NotificationItem& item) {
108 SetLayoutManager(
109 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), 0));
110
111 views::Label* message =
112 new views::Label(item.title + base::ASCIIToUTF16(" - ") + item.message);
fukino 2017/06/13 04:27:09 We should have separate between title and message
fukino 2017/06/13 04:27:09 Can we have darker color for item.title than item.
tetsui 2017/06/13 04:55:03 In my understanding, list notification and bundle
tetsui 2017/06/13 04:55:03 Done.
113 message->set_collapse_when_hidden(true);
114 message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
115 message->SetEnabledColor(message_center::kDimTextColor);
116 message->SetBackgroundColor(message_center::kDimTextBackgroundColor);
117 AddChildView(message);
118 }
119
120 ItemView::~ItemView() {}
121
93 } // anonymous namespace 122 } // anonymous namespace
94 123
95 // //////////////////////////////////////////////////////////// 124 // ////////////////////////////////////////////////////////////
96 // NotificationViewMD 125 // NotificationViewMD
97 // //////////////////////////////////////////////////////////// 126 // ////////////////////////////////////////////////////////////
98 127
99 views::View* NotificationViewMD::TargetForRect(views::View* root, 128 views::View* NotificationViewMD::TargetForRect(views::View* root,
100 const gfx::Rect& rect) { 129 const gfx::Rect& rect) {
101 CHECK_EQ(root, this); 130 CHECK_EQ(root, this);
102 131
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 369
341 if (!message_view_) { 370 if (!message_view_) {
342 message_view_ = new BoundedLabel(text, font_list); 371 message_view_ = new BoundedLabel(text, font_list);
343 message_view_->SetLineLimit(kMaxLinesForMessageView); 372 message_view_->SetLineLimit(kMaxLinesForMessageView);
344 message_view_->SetColors(message_center::kDimTextColor, 373 message_view_->SetColors(message_center::kDimTextColor,
345 kContextTextBackgroundColor); 374 kContextTextBackgroundColor);
346 left_content_->AddChildView(message_view_); 375 left_content_->AddChildView(message_view_);
347 } else { 376 } else {
348 message_view_->SetText(text); 377 message_view_->SetText(text);
349 } 378 }
379
380 message_view_->SetVisible(notification.items().empty());
350 } 381 }
351 382
352 void NotificationViewMD::CreateOrUpdateProgressBarView( 383 void NotificationViewMD::CreateOrUpdateProgressBarView(
353 const Notification& notification) { 384 const Notification& notification) {
354 // TODO(yoshiki): Implement this. 385 // TODO(yoshiki): Implement this.
355 } 386 }
356 387
357 void NotificationViewMD::CreateOrUpdateListItemViews( 388 void NotificationViewMD::CreateOrUpdateListItemViews(
358 const Notification& notification) { 389 const Notification& notification) {
359 // TODO(yoshiki): Implement this. 390 for (auto* item_view : item_views_)
391 delete item_view;
392 item_views_.clear();
393
394 const std::vector<NotificationItem>& items = notification.items();
395
396 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
397 ItemView* item_view = new ItemView(items[i]);
398 item_views_.push_back(item_view);
399 left_content_->AddChildView(item_view);
400 }
401
402 // Needed when CreateOrUpdateViews is called for update.
403 left_content_->Layout();
404 left_content_->SchedulePaint();
360 } 405 }
361 406
362 void NotificationViewMD::CreateOrUpdateIconView( 407 void NotificationViewMD::CreateOrUpdateIconView(
363 const Notification& notification) { 408 const Notification& notification) {
364 gfx::Size image_view_size(30, 30); 409 gfx::Size image_view_size(30, 30);
365 if (!icon_view_) { 410 if (!icon_view_) {
366 icon_view_ = new ProportionalImageView(image_view_size); 411 icon_view_ = new ProportionalImageView(image_view_size);
367 right_content_->AddChildView(icon_view_); 412 right_content_->AddChildView(icon_view_);
368 } 413 }
369 414
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 return true; 523 return true;
479 } 524 }
480 // Expandable if there is at least one inline action. 525 // Expandable if there is at least one inline action.
481 if (actions_row_->has_children()) 526 if (actions_row_->has_children())
482 return true; 527 return true;
483 528
484 // Expandable if the notification has image. 529 // Expandable if the notification has image.
485 if (image_view_) 530 if (image_view_)
486 return true; 531 return true;
487 532
533 // Expandable if there are multiple list items.
534 if (item_views_.size() > 1) {
fukino 2017/06/13 04:27:09 nit: We usually omit curly braces for 1-line if st
tetsui 2017/06/13 04:55:03 Done.
535 return true;
536 }
537
488 // TODO(fukino): Expandable if both progress bar and message exist. 538 // TODO(fukino): Expandable if both progress bar and message exist.
489 539
490 return false; 540 return false;
491 } 541 }
492 542
493 void NotificationViewMD::ToggleExpanded() { 543 void NotificationViewMD::ToggleExpanded() {
494 expanded_ = !expanded_; 544 expanded_ = !expanded_;
495 UpdateViewForExpandedState(expanded_); 545 UpdateViewForExpandedState(expanded_);
496 content_row_->InvalidateLayout(); 546 content_row_->InvalidateLayout();
497 if (controller()) 547 if (controller())
498 controller()->UpdateNotificationSize(notification_id()); 548 controller()->UpdateNotificationSize(notification_id());
499 } 549 }
500 550
501 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { 551 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) {
502 header_row_->SetExpanded(expanded); 552 header_row_->SetExpanded(expanded);
503 if (message_view_) { 553 if (message_view_) {
504 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView 554 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView
505 : kMaxLinesForMessageView); 555 : kMaxLinesForMessageView);
506 } 556 }
507 if (image_container_) 557 if (image_container_)
508 image_container_->SetVisible(expanded); 558 image_container_->SetVisible(expanded);
509 actions_row_->SetVisible(expanded && actions_row_->has_children()); 559 actions_row_->SetVisible(expanded && actions_row_->has_children());
560 for (size_t i = 1; i < item_views_.size(); ++i) {
561 item_views_[i]->SetVisible(expanded);
562 }
510 } 563 }
511 564
512 void NotificationViewMD::UpdateControlButtonsVisibility() { 565 void NotificationViewMD::UpdateControlButtonsVisibility() {
513 const bool target_visibility = IsMouseHovered() || HasFocus() || 566 const bool target_visibility = IsMouseHovered() || HasFocus() ||
514 (header_row_->IsExpandButtonEnabled() && 567 (header_row_->IsExpandButtonEnabled() &&
515 header_row_->expand_button()->HasFocus()) || 568 header_row_->expand_button()->HasFocus()) ||
516 (header_row_->IsCloseButtonEnabled() && 569 (header_row_->IsCloseButtonEnabled() &&
517 header_row_->close_button()->HasFocus()) || 570 header_row_->close_button()->HasFocus()) ||
518 (header_row_->IsSettingsButtonEnabled() && 571 (header_row_->IsSettingsButtonEnabled() &&
519 header_row_->settings_button()->HasFocus()); 572 header_row_->settings_button()->HasFocus());
520 573
521 header_row_->SetControlButtonsVisible(target_visibility); 574 header_row_->SetControlButtonsVisible(target_visibility);
522 } 575 }
523 576
524 } // namespace message_center 577 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698