Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 95 const gfx::ImageSkia GetProductIcon() { | 96 const gfx::ImageSkia GetProductIcon() { |
| 96 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); | 97 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); |
| 97 } | 98 } |
| 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, |
| 107 int num_remaining); | |
| 106 ~ItemView() override; | 108 ~ItemView() override; |
| 107 | 109 |
| 110 void SetRemainingCountVisible(bool visible); | |
| 111 | |
| 112 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.
| |
| 113 public: | |
| 114 LayoutManager(ItemView* item_view) | |
| 115 : views::FillLayout(), item_view_(item_view) {} | |
| 116 | |
| 117 void Layout(View* host) override { | |
| 118 gfx::Rect container_bounds = host->GetContentsBounds(); | |
| 119 if (item_view_->remaining_count_->visible()) { | |
| 120 // Show the full content of the overflow indicator and collapse the | |
| 121 // message container. | |
| 122 container_bounds.set_width( | |
| 123 container_bounds.width() - | |
| 124 item_view_->remaining_count_->GetPreferredSize().width() - | |
| 125 kListNotificationOverflowIndicatorSpacing); | |
| 126 } | |
| 127 item_view_->container_->SetBoundsRect(container_bounds); | |
| 128 item_view_->remaining_count_->SetBoundsRect(host->GetContentsBounds()); | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 ItemView* item_view_; | |
| 133 }; | |
| 134 | |
| 108 private: | 135 private: |
| 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 int num_remaining) { |
| 146 SetLayoutManager(new ItemView::LayoutManager(this)); | |
| 147 | |
| 148 container_ = new views::View; | |
| 149 AddChildView(container_); | |
| 150 container_->SetLayoutManager( | |
| 114 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), | 151 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), |
| 115 message_center::kItemTitleToMessagePadding)); | 152 message_center::kItemTitleToMessagePadding)); |
| 116 | 153 |
| 117 views::Label* title = new views::Label(item.title); | 154 views::Label* title = new views::Label(item.title); |
| 118 title->set_collapse_when_hidden(true); | 155 title->set_collapse_when_hidden(true); |
| 119 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 156 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 120 title->SetEnabledColor(message_center::kRegularTextColor); | 157 title->SetEnabledColor(message_center::kRegularTextColor); |
| 121 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 158 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| 122 AddChildView(title); | 159 container_->AddChildView(title); |
| 123 | 160 |
| 124 views::Label* message = new views::Label(item.message); | 161 views::Label* message = new views::Label(item.message); |
| 125 message->set_collapse_when_hidden(true); | 162 message->set_collapse_when_hidden(true); |
| 126 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 163 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 127 message->SetEnabledColor(message_center::kDimTextColor); | 164 message->SetEnabledColor(message_center::kDimTextColor); |
| 128 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 165 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| 129 AddChildView(message); | 166 container_->AddChildView(message); |
| 167 | |
| 168 remaining_count_ = new views::Label(); | |
| 169 remaining_count_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | |
| 170 remaining_count_->SetEnabledColor(message_center::kDimTextColor); | |
| 171 remaining_count_->SetBackgroundColor(message_center::kDimTextBackgroundColor); | |
| 172 AddChildView(remaining_count_); | |
| 173 if (num_remaining > 0) { | |
| 174 remaining_count_->SetText(l10n_util::GetStringFUTF16Int( | |
| 175 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_OVERFLOW_INDICATOR, | |
| 176 num_remaining)); | |
| 177 } | |
| 178 remaining_count_->SetVisible(false); | |
| 130 } | 179 } |
| 131 | 180 |
| 132 ItemView::~ItemView() {} | 181 ItemView::~ItemView() {} |
| 133 | 182 |
| 183 void ItemView::SetRemainingCountVisible(bool visible) { | |
| 184 remaining_count_->SetVisible(visible); | |
| 185 } | |
| 186 | |
| 134 // CompactTitleMessageView ///////////////////////////////////////////////////// | 187 // CompactTitleMessageView ///////////////////////////////////////////////////// |
| 135 | 188 |
| 136 // CompactTitleMessageView shows notification title and message in a single | 189 // CompactTitleMessageView shows notification title and message in a single |
| 137 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. | 190 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. |
| 138 class CompactTitleMessageView : public views::View { | 191 class CompactTitleMessageView : public views::View { |
| 139 public: | 192 public: |
| 140 explicit CompactTitleMessageView(); | 193 explicit CompactTitleMessageView(); |
| 141 ~CompactTitleMessageView() override; | 194 ~CompactTitleMessageView() override; |
| 142 | 195 |
| 143 void OnPaint(gfx::Canvas* canvas) override; | 196 void OnPaint(gfx::Canvas* canvas) override; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 } | 567 } |
| 515 | 568 |
| 516 void NotificationViewMD::CreateOrUpdateListItemViews( | 569 void NotificationViewMD::CreateOrUpdateListItemViews( |
| 517 const Notification& notification) { | 570 const Notification& notification) { |
| 518 for (auto* item_view : item_views_) | 571 for (auto* item_view : item_views_) |
| 519 delete item_view; | 572 delete item_view; |
| 520 item_views_.clear(); | 573 item_views_.clear(); |
| 521 | 574 |
| 522 const std::vector<NotificationItem>& items = notification.items(); | 575 const std::vector<NotificationItem>& items = notification.items(); |
| 523 | 576 |
| 524 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 577 for (size_t i = 0; i < items.size() && i < kMaxLinesForExpandedMessageView; |
| 525 ItemView* item_view = new ItemView(items[i]); | 578 ++i) { |
| 579 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.
| |
| 526 item_views_.push_back(item_view); | 580 item_views_.push_back(item_view); |
| 527 left_content_->AddChildView(item_view); | 581 left_content_->AddChildView(item_view); |
| 528 } | 582 } |
| 529 | 583 |
| 530 // Needed when CreateOrUpdateViews is called for update. | 584 // Needed when CreateOrUpdateViews is called for update. |
| 531 if (!item_views_.empty()) | 585 if (!item_views_.empty()) |
| 532 left_content_->InvalidateLayout(); | 586 left_content_->InvalidateLayout(); |
| 533 } | 587 } |
| 534 | 588 |
| 535 void NotificationViewMD::CreateOrUpdateIconView( | 589 void NotificationViewMD::CreateOrUpdateIconView( |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 | 745 |
| 692 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { | 746 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { |
| 693 header_row_->SetExpanded(expanded); | 747 header_row_->SetExpanded(expanded); |
| 694 if (message_view_) { | 748 if (message_view_) { |
| 695 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView | 749 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView |
| 696 : kMaxLinesForMessageView); | 750 : kMaxLinesForMessageView); |
| 697 } | 751 } |
| 698 if (image_container_) | 752 if (image_container_) |
| 699 image_container_->SetVisible(expanded); | 753 image_container_->SetVisible(expanded); |
| 700 actions_row_->SetVisible(expanded && actions_row_->has_children()); | 754 actions_row_->SetVisible(expanded && actions_row_->has_children()); |
| 701 for (size_t i = 1; i < item_views_.size(); ++i) { | 755 for (size_t i = kMaxLinesForMessageView; i < item_views_.size(); ++i) { |
| 702 item_views_[i]->SetVisible(expanded); | 756 item_views_[i]->SetVisible(expanded); |
| 703 } | 757 } |
| 758 if (!item_views_.empty()) { | |
| 759 item_views_.front()->SetRemainingCountVisible(!expanded); | |
| 760 item_views_.back()->SetRemainingCountVisible(expanded); | |
| 761 } | |
| 704 } | 762 } |
| 705 | 763 |
| 706 void NotificationViewMD::UpdateControlButtonsVisibility() { | 764 void NotificationViewMD::UpdateControlButtonsVisibility() { |
| 707 const bool target_visibility = IsMouseHovered() || HasFocus() || | 765 const bool target_visibility = IsMouseHovered() || HasFocus() || |
| 708 (header_row_->IsExpandButtonEnabled() && | 766 (header_row_->IsExpandButtonEnabled() && |
| 709 header_row_->expand_button()->HasFocus()) || | 767 header_row_->expand_button()->HasFocus()) || |
| 710 (header_row_->IsCloseButtonEnabled() && | 768 (header_row_->IsCloseButtonEnabled() && |
| 711 header_row_->close_button()->HasFocus()) || | 769 header_row_->close_button()->HasFocus()) || |
| 712 (header_row_->IsSettingsButtonEnabled() && | 770 (header_row_->IsSettingsButtonEnabled() && |
| 713 header_row_->settings_button()->HasFocus()); | 771 header_row_->settings_button()->HasFocus()); |
| 714 | 772 |
| 715 header_row_->SetControlButtonsVisible(target_visibility); | 773 header_row_->SetControlButtonsVisible(target_visibility); |
| 716 } | 774 } |
| 717 | 775 |
| 718 } // namespace message_center | 776 } // namespace message_center |
| OLD | NEW |