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/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 constexpr SkColor kSmallImageBackgroundColor = SK_ColorWHITE; | 54 constexpr SkColor kSmallImageBackgroundColor = SK_ColorWHITE; |
55 // Background of small icon image. | 55 // Background of small icon image. |
56 const SkColor kSmallImageColor = SkColorSetRGB(0x43, 0x43, 0x43); | 56 const SkColor kSmallImageColor = SkColorSetRGB(0x43, 0x43, 0x43); |
57 // Background of inline actions area. | 57 // Background of inline actions area. |
58 const SkColor kActionsRowBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); | 58 const SkColor kActionsRowBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
59 | 59 |
60 // Max number of lines for message_view_. | 60 // Max number of lines for message_view_. |
61 constexpr int kMaxLinesForMessageView = 1; | 61 constexpr int kMaxLinesForMessageView = 1; |
62 constexpr int kMaxLinesForExpandedMessageView = 4; | 62 constexpr int kMaxLinesForExpandedMessageView = 4; |
63 | 63 |
| 64 constexpr int kListNotificationOverflowIndicatorSpacing = 4; |
64 constexpr int kCompactTitleMessageViewSpacing = 12; | 65 constexpr int kCompactTitleMessageViewSpacing = 12; |
65 | 66 |
66 constexpr int kProgressBarHeight = 4; | 67 constexpr int kProgressBarHeight = 4; |
67 | 68 |
68 const gfx::ImageSkia CreateSolidColorImage(int width, | 69 const gfx::ImageSkia CreateSolidColorImage(int width, |
69 int height, | 70 int height, |
70 SkColor color) { | 71 SkColor color) { |
71 SkBitmap bitmap; | 72 SkBitmap bitmap; |
72 bitmap.allocN32Pixels(width, height); | 73 bitmap.allocN32Pixels(width, height); |
73 bitmap.eraseColor(color); | 74 bitmap.eraseColor(color); |
(...skipping 24 matching lines...) Expand all Loading... |
98 | 99 |
99 // ItemView //////////////////////////////////////////////////////////////////// | 100 // ItemView //////////////////////////////////////////////////////////////////// |
100 | 101 |
101 // ItemViews are responsible for drawing each list notification item's title and | 102 // ItemViews are responsible for drawing each list notification item's title and |
102 // message next to each other within a single column. | 103 // message next to each other within a single column. |
103 class ItemView : public views::View { | 104 class ItemView : public views::View { |
104 public: | 105 public: |
105 explicit ItemView(const message_center::NotificationItem& item); | 106 explicit ItemView(const message_center::NotificationItem& item); |
106 ~ItemView() override; | 107 ~ItemView() override; |
107 | 108 |
| 109 void SetRemainingCount(int num_remaining); |
| 110 void SetRemainingCountVisible(bool visible); |
| 111 |
108 private: | 112 private: |
| 113 class LayoutManager : public views::FillLayout { |
| 114 public: |
| 115 LayoutManager(ItemView* item_view) |
| 116 : views::FillLayout(), item_view_(item_view) {} |
| 117 |
| 118 void Layout(View* host) override { |
| 119 gfx::Rect container_bounds = host->GetContentsBounds(); |
| 120 if (item_view_->remaining_count_->visible()) { |
| 121 // Show the full content of the overflow indicator and collapse the |
| 122 // message container. |
| 123 container_bounds.set_width( |
| 124 container_bounds.width() - |
| 125 item_view_->remaining_count_->GetPreferredSize().width() - |
| 126 kListNotificationOverflowIndicatorSpacing); |
| 127 } |
| 128 item_view_->container_->SetBoundsRect(container_bounds); |
| 129 item_view_->remaining_count_->SetBoundsRect(host->GetContentsBounds()); |
| 130 } |
| 131 |
| 132 private: |
| 133 ItemView* item_view_; |
| 134 }; |
| 135 |
| 136 // Container of the title and the message. |
| 137 views::View* container_; |
| 138 // Overflow indicator e.g. "+3" shown on the right bottom. |
| 139 views::Label* remaining_count_; |
| 140 |
109 DISALLOW_COPY_AND_ASSIGN(ItemView); | 141 DISALLOW_COPY_AND_ASSIGN(ItemView); |
110 }; | 142 }; |
111 | 143 |
112 ItemView::ItemView(const message_center::NotificationItem& item) { | 144 ItemView::ItemView(const message_center::NotificationItem& item) { |
113 SetLayoutManager( | 145 SetLayoutManager(new ItemView::LayoutManager(this)); |
| 146 |
| 147 container_ = new views::View; |
| 148 AddChildView(container_); |
| 149 container_->SetLayoutManager( |
114 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), | 150 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), |
115 message_center::kItemTitleToMessagePadding)); | 151 message_center::kItemTitleToMessagePadding)); |
116 | 152 |
117 views::Label* title = new views::Label(item.title); | 153 views::Label* title = new views::Label(item.title); |
118 title->set_collapse_when_hidden(true); | 154 title->set_collapse_when_hidden(true); |
119 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 155 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
120 title->SetEnabledColor(message_center::kRegularTextColor); | 156 title->SetEnabledColor(message_center::kRegularTextColor); |
121 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 157 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
122 AddChildView(title); | 158 container_->AddChildView(title); |
123 | 159 |
124 views::Label* message = new views::Label(item.message); | 160 views::Label* message = new views::Label(item.message); |
125 message->set_collapse_when_hidden(true); | 161 message->set_collapse_when_hidden(true); |
126 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 162 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
127 message->SetEnabledColor(message_center::kDimTextColor); | 163 message->SetEnabledColor(message_center::kDimTextColor); |
128 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 164 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
129 AddChildView(message); | 165 container_->AddChildView(message); |
| 166 |
| 167 remaining_count_ = new views::Label(); |
| 168 remaining_count_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 169 remaining_count_->SetEnabledColor(message_center::kDimTextColor); |
| 170 remaining_count_->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| 171 remaining_count_->SetVisible(false); |
| 172 AddChildView(remaining_count_); |
130 } | 173 } |
131 | 174 |
132 ItemView::~ItemView() {} | 175 ItemView::~ItemView() {} |
133 | 176 |
| 177 void ItemView::SetRemainingCount(int num_remaining) { |
| 178 if (num_remaining > 0) { |
| 179 remaining_count_->SetText(l10n_util::GetStringFUTF16Int( |
| 180 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_OVERFLOW_INDICATOR, |
| 181 num_remaining)); |
| 182 } |
| 183 } |
| 184 |
| 185 void ItemView::SetRemainingCountVisible(bool visible) { |
| 186 remaining_count_->SetVisible(visible); |
| 187 } |
| 188 |
134 // CompactTitleMessageView ///////////////////////////////////////////////////// | 189 // CompactTitleMessageView ///////////////////////////////////////////////////// |
135 | 190 |
136 // CompactTitleMessageView shows notification title and message in a single | 191 // CompactTitleMessageView shows notification title and message in a single |
137 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. | 192 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. |
138 class CompactTitleMessageView : public views::View { | 193 class CompactTitleMessageView : public views::View { |
139 public: | 194 public: |
140 explicit CompactTitleMessageView(); | 195 explicit CompactTitleMessageView(); |
141 ~CompactTitleMessageView() override; | 196 ~CompactTitleMessageView() override; |
142 | 197 |
143 void OnPaint(gfx::Canvas* canvas) override; | 198 void OnPaint(gfx::Canvas* canvas) override; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 } | 569 } |
515 | 570 |
516 void NotificationViewMD::CreateOrUpdateListItemViews( | 571 void NotificationViewMD::CreateOrUpdateListItemViews( |
517 const Notification& notification) { | 572 const Notification& notification) { |
518 for (auto* item_view : item_views_) | 573 for (auto* item_view : item_views_) |
519 delete item_view; | 574 delete item_view; |
520 item_views_.clear(); | 575 item_views_.clear(); |
521 | 576 |
522 const std::vector<NotificationItem>& items = notification.items(); | 577 const std::vector<NotificationItem>& items = notification.items(); |
523 | 578 |
524 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 579 for (size_t i = 0; i < items.size() && i < kMaxLinesForExpandedMessageView; |
| 580 ++i) { |
525 ItemView* item_view = new ItemView(items[i]); | 581 ItemView* item_view = new ItemView(items[i]); |
526 item_views_.push_back(item_view); | 582 item_views_.push_back(item_view); |
527 left_content_->AddChildView(item_view); | 583 left_content_->AddChildView(item_view); |
528 } | 584 } |
529 | 585 |
530 // Needed when CreateOrUpdateViews is called for update. | 586 if (!item_views_.empty()) { |
531 if (!item_views_.empty()) | 587 item_views_.front()->SetRemainingCount(items.size() - 1); |
| 588 item_views_.back()->SetRemainingCount(items.size() - item_views_.size()); |
| 589 |
| 590 // Needed when CreateOrUpdateViews is called for update. |
532 left_content_->InvalidateLayout(); | 591 left_content_->InvalidateLayout(); |
| 592 } |
533 } | 593 } |
534 | 594 |
535 void NotificationViewMD::CreateOrUpdateIconView( | 595 void NotificationViewMD::CreateOrUpdateIconView( |
536 const Notification& notification) { | 596 const Notification& notification) { |
537 if (notification.type() == NOTIFICATION_TYPE_PROGRESS || | 597 if (notification.type() == NOTIFICATION_TYPE_PROGRESS || |
538 notification.type() == NOTIFICATION_TYPE_MULTIPLE) { | 598 notification.type() == NOTIFICATION_TYPE_MULTIPLE) { |
539 right_content_->RemoveChildView(icon_view_); | 599 right_content_->RemoveChildView(icon_view_); |
540 icon_view_ = nullptr; | 600 icon_view_ = nullptr; |
541 return; | 601 return; |
542 } | 602 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 if (message_view_) { | 754 if (message_view_) { |
695 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView | 755 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView |
696 : kMaxLinesForMessageView); | 756 : kMaxLinesForMessageView); |
697 } | 757 } |
698 if (image_container_) | 758 if (image_container_) |
699 image_container_->SetVisible(expanded); | 759 image_container_->SetVisible(expanded); |
700 actions_row_->SetVisible(expanded && actions_row_->has_children()); | 760 actions_row_->SetVisible(expanded && actions_row_->has_children()); |
701 for (size_t i = 1; i < item_views_.size(); ++i) { | 761 for (size_t i = 1; i < item_views_.size(); ++i) { |
702 item_views_[i]->SetVisible(expanded); | 762 item_views_[i]->SetVisible(expanded); |
703 } | 763 } |
| 764 if (!item_views_.empty()) { |
| 765 item_views_.front()->SetRemainingCountVisible(!expanded); |
| 766 item_views_.back()->SetRemainingCountVisible(expanded); |
| 767 } |
704 } | 768 } |
705 | 769 |
706 void NotificationViewMD::UpdateControlButtonsVisibility() { | 770 void NotificationViewMD::UpdateControlButtonsVisibility() { |
707 const bool target_visibility = IsMouseHovered() || HasFocus() || | 771 const bool target_visibility = IsMouseHovered() || HasFocus() || |
708 (header_row_->IsExpandButtonEnabled() && | 772 (header_row_->IsExpandButtonEnabled() && |
709 header_row_->expand_button()->HasFocus()) || | 773 header_row_->expand_button()->HasFocus()) || |
710 (header_row_->IsCloseButtonEnabled() && | 774 (header_row_->IsCloseButtonEnabled() && |
711 header_row_->close_button()->HasFocus()) || | 775 header_row_->close_button()->HasFocus()) || |
712 (header_row_->IsSettingsButtonEnabled() && | 776 (header_row_->IsSettingsButtonEnabled() && |
713 header_row_->settings_button()->HasFocus()); | 777 header_row_->settings_button()->HasFocus()); |
714 | 778 |
715 header_row_->SetControlButtonsVisible(target_visibility); | 779 header_row_->SetControlButtonsVisible(target_visibility); |
716 } | 780 } |
717 | 781 |
718 } // namespace message_center | 782 } // namespace message_center |
OLD | NEW |