Chromium Code Reviews| Index: ui/message_center/views/notification_view_md.cc |
| diff --git a/ui/message_center/views/notification_view_md.cc b/ui/message_center/views/notification_view_md.cc |
| index 44eeb8d4b3f3af15fdb48372568ebc389bee598a..80d63053a3528dacc14e5a0315a8feebda73ecec 100644 |
| --- a/ui/message_center/views/notification_view_md.cc |
| +++ b/ui/message_center/views/notification_view_md.cc |
| @@ -61,6 +61,7 @@ const SkColor kActionsRowBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
| constexpr int kMaxLinesForMessageView = 1; |
| constexpr int kMaxLinesForExpandedMessageView = 4; |
| +constexpr int kListNotificationOverflowIndicatorSpacing = 4; |
| constexpr int kCompactTitleMessageViewSpacing = 12; |
| constexpr int kProgressBarHeight = 4; |
| @@ -102,15 +103,51 @@ const gfx::ImageSkia GetProductIcon() { |
| // message next to each other within a single column. |
| class ItemView : public views::View { |
| public: |
| - explicit ItemView(const message_center::NotificationItem& item); |
| + explicit ItemView(const message_center::NotificationItem& item, |
| + int num_remaining); |
| ~ItemView() override; |
| + void SetRemainingCountVisible(bool visible); |
| + |
| + class LayoutManager : public views::FillLayout { |
|
fukino
2017/06/26 04:00:13
nit: This class can be private.
tetsui
2017/06/26 05:10:46
Done.
|
| + public: |
| + LayoutManager(ItemView* item_view) |
| + : views::FillLayout(), item_view_(item_view) {} |
| + |
| + void Layout(View* host) override { |
| + gfx::Rect container_bounds = host->GetContentsBounds(); |
| + if (item_view_->remaining_count_->visible()) { |
| + // Show the full content of the overflow indicator and collapse the |
| + // message container. |
| + container_bounds.set_width( |
| + container_bounds.width() - |
| + item_view_->remaining_count_->GetPreferredSize().width() - |
| + kListNotificationOverflowIndicatorSpacing); |
| + } |
| + item_view_->container_->SetBoundsRect(container_bounds); |
| + item_view_->remaining_count_->SetBoundsRect(host->GetContentsBounds()); |
| + } |
| + |
| + private: |
| + ItemView* item_view_; |
| + }; |
| + |
| private: |
| + // Container of the title and the message. |
| + views::View* container_; |
| + // Overflow indicator e.g. "+3" shown on the right bottom. |
| + views::Label* remaining_count_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ItemView); |
| }; |
| -ItemView::ItemView(const message_center::NotificationItem& item) { |
| - SetLayoutManager( |
| +ItemView::ItemView(const message_center::NotificationItem& item, |
| + int num_remaining) { |
| + SetLayoutManager(new ItemView::LayoutManager(this)); |
| + |
| + container_ = new views::View; |
| + AddChildView(container_); |
| + container_->SetLayoutManager( |
| new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), |
| message_center::kItemTitleToMessagePadding)); |
| @@ -119,18 +156,34 @@ ItemView::ItemView(const message_center::NotificationItem& item) { |
| title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| title->SetEnabledColor(message_center::kRegularTextColor); |
| title->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| - AddChildView(title); |
| + container_->AddChildView(title); |
| views::Label* message = new views::Label(item.message); |
| message->set_collapse_when_hidden(true); |
| message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| message->SetEnabledColor(message_center::kDimTextColor); |
| message->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| - AddChildView(message); |
| + container_->AddChildView(message); |
| + |
| + remaining_count_ = new views::Label(); |
| + remaining_count_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| + remaining_count_->SetEnabledColor(message_center::kDimTextColor); |
| + remaining_count_->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| + AddChildView(remaining_count_); |
| + if (num_remaining > 0) { |
| + remaining_count_->SetText(l10n_util::GetStringFUTF16Int( |
| + IDS_MESSAGE_CENTER_LIST_NOTIFICATION_OVERFLOW_INDICATOR, |
| + num_remaining)); |
| + } |
| + remaining_count_->SetVisible(false); |
| } |
| ItemView::~ItemView() {} |
| +void ItemView::SetRemainingCountVisible(bool visible) { |
| + remaining_count_->SetVisible(visible); |
| +} |
| + |
| // CompactTitleMessageView ///////////////////////////////////////////////////// |
| // CompactTitleMessageView shows notification title and message in a single |
| @@ -521,8 +574,9 @@ void NotificationViewMD::CreateOrUpdateListItemViews( |
| const std::vector<NotificationItem>& items = notification.items(); |
| - for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
| - ItemView* item_view = new ItemView(items[i]); |
| + for (size_t i = 0; i < items.size() && i < kMaxLinesForExpandedMessageView; |
| + ++i) { |
| + ItemView* item_view = new ItemView(items[i], items.size() - i - 1); |
|
fukino
2017/06/26 04:18:37
Optional nit: Since only the first and the last it
tetsui
2017/06/26 05:10:46
Done.
|
| item_views_.push_back(item_view); |
| left_content_->AddChildView(item_view); |
| } |
| @@ -698,9 +752,13 @@ void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { |
| if (image_container_) |
| image_container_->SetVisible(expanded); |
| actions_row_->SetVisible(expanded && actions_row_->has_children()); |
| - for (size_t i = 1; i < item_views_.size(); ++i) { |
| + for (size_t i = kMaxLinesForMessageView; i < item_views_.size(); ++i) { |
| item_views_[i]->SetVisible(expanded); |
| } |
| + if (!item_views_.empty()) { |
| + item_views_.front()->SetRemainingCountVisible(!expanded); |
| + item_views_.back()->SetRemainingCountVisible(expanded); |
| + } |
| } |
| void NotificationViewMD::UpdateControlButtonsVisibility() { |