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

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

Issue 2966693002: Move overflow indicator to notifiction header. (Closed)
Patch Set: 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const float kActionButtonInkDropRippleVisibleOpacity = 0.08f; 65 const float kActionButtonInkDropRippleVisibleOpacity = 0.08f;
66 // Highlight (hover) ink drop opacity of action buttons. 66 // Highlight (hover) ink drop opacity of action buttons.
67 const float kActionButtonInkDropHighlightVisibleOpacity = 0.08f; 67 const float kActionButtonInkDropHighlightVisibleOpacity = 0.08f;
68 // Text color of action button. 68 // Text color of action button.
69 const SkColor kActionButtonTextColor = SkColorSetRGB(0x33, 0x67, 0xD6); 69 const SkColor kActionButtonTextColor = SkColorSetRGB(0x33, 0x67, 0xD6);
70 70
71 // Max number of lines for message_view_. 71 // Max number of lines for message_view_.
72 constexpr int kMaxLinesForMessageView = 1; 72 constexpr int kMaxLinesForMessageView = 1;
73 constexpr int kMaxLinesForExpandedMessageView = 4; 73 constexpr int kMaxLinesForExpandedMessageView = 4;
74 74
75 constexpr int kListNotificationOverflowIndicatorSpacing = 4;
76 constexpr int kCompactTitleMessageViewSpacing = 12; 75 constexpr int kCompactTitleMessageViewSpacing = 12;
77 76
78 constexpr int kProgressBarHeight = 4; 77 constexpr int kProgressBarHeight = 4;
79 78
80 const gfx::ImageSkia CreateSolidColorImage(int width, 79 const gfx::ImageSkia CreateSolidColorImage(int width,
81 int height, 80 int height,
82 SkColor color) { 81 SkColor color) {
83 SkBitmap bitmap; 82 SkBitmap bitmap;
84 bitmap.allocN32Pixels(width, height); 83 bitmap.allocN32Pixels(width, height);
85 bitmap.eraseColor(color); 84 bitmap.eraseColor(color);
(...skipping 24 matching lines...) Expand all
110 109
111 // ItemView //////////////////////////////////////////////////////////////////// 110 // ItemView ////////////////////////////////////////////////////////////////////
112 111
113 // 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
114 // message next to each other within a single column. 113 // message next to each other within a single column.
115 class ItemView : public views::View { 114 class ItemView : public views::View {
116 public: 115 public:
117 explicit ItemView(const message_center::NotificationItem& item); 116 explicit ItemView(const message_center::NotificationItem& item);
118 ~ItemView() override; 117 ~ItemView() override;
119 118
120 void SetRemainingCount(int num_remaining);
121 void SetRemainingCountVisible(bool visible);
122
123 private: 119 private:
124 class LayoutManager : public views::FillLayout {
125 public:
126 LayoutManager(ItemView* item_view)
127 : views::FillLayout(), item_view_(item_view) {}
128
129 void Layout(View* host) override {
130 gfx::Rect container_bounds = host->GetContentsBounds();
131 if (item_view_->remaining_count_->visible()) {
132 // Show the full content of the overflow indicator and collapse the
133 // message container.
134 container_bounds.set_width(
135 container_bounds.width() -
136 item_view_->remaining_count_->GetPreferredSize().width() -
137 kListNotificationOverflowIndicatorSpacing);
138 }
139 item_view_->container_->SetBoundsRect(container_bounds);
140 item_view_->remaining_count_->SetBoundsRect(host->GetContentsBounds());
141 }
142
143 private:
144 ItemView* item_view_;
145 };
146
147 // Container of the title and the message.
148 views::View* container_;
149 // Overflow indicator e.g. "+3" shown on the right bottom.
150 views::Label* remaining_count_;
151
152 DISALLOW_COPY_AND_ASSIGN(ItemView); 120 DISALLOW_COPY_AND_ASSIGN(ItemView);
153 }; 121 };
154 122
155 ItemView::ItemView(const message_center::NotificationItem& item) { 123 ItemView::ItemView(const message_center::NotificationItem& item) {
156 SetLayoutManager(new ItemView::LayoutManager(this)); 124 SetLayoutManager(
157 125 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), 0));
158 container_ = new views::View;
159 AddChildView(container_);
160 container_->SetLayoutManager(
161 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(),
162 message_center::kItemTitleToMessagePadding));
163 126
164 views::Label* title = new views::Label(item.title); 127 views::Label* title = new views::Label(item.title);
165 title->set_collapse_when_hidden(true); 128 title->set_collapse_when_hidden(true);
166 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); 129 title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
167 title->SetEnabledColor(message_center::kRegularTextColor); 130 title->SetEnabledColor(message_center::kRegularTextColor);
168 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); 131 title->SetBackgroundColor(message_center::kDimTextBackgroundColor);
169 container_->AddChildView(title); 132 AddChildView(title);
170 133
171 views::Label* message = new views::Label(item.message); 134 views::Label* message = new views::Label(l10n_util::GetStringFUTF16(
135 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_MESSAGE_WITH_DIVIDER, item.message));
172 message->set_collapse_when_hidden(true); 136 message->set_collapse_when_hidden(true);
173 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); 137 message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
174 message->SetEnabledColor(message_center::kDimTextColor); 138 message->SetEnabledColor(message_center::kDimTextColor);
175 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); 139 message->SetBackgroundColor(message_center::kDimTextBackgroundColor);
176 container_->AddChildView(message); 140 AddChildView(message);
177
178 remaining_count_ = new views::Label();
179 remaining_count_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
180 remaining_count_->SetEnabledColor(message_center::kDimTextColor);
181 remaining_count_->SetBackgroundColor(message_center::kDimTextBackgroundColor);
182 remaining_count_->SetVisible(false);
183 AddChildView(remaining_count_);
184 } 141 }
185 142
186 ItemView::~ItemView() {} 143 ItemView::~ItemView() = default;
187
188 void ItemView::SetRemainingCount(int num_remaining) {
189 if (num_remaining > 0) {
190 remaining_count_->SetText(l10n_util::GetStringFUTF16Int(
191 IDS_MESSAGE_CENTER_LIST_NOTIFICATION_OVERFLOW_INDICATOR,
192 num_remaining));
193 }
194 }
195
196 void ItemView::SetRemainingCountVisible(bool visible) {
197 remaining_count_->SetVisible(visible);
198 }
199 144
200 // CompactTitleMessageView ///////////////////////////////////////////////////// 145 // CompactTitleMessageView /////////////////////////////////////////////////////
201 146
202 // CompactTitleMessageView shows notification title and message in a single 147 // CompactTitleMessageView shows notification title and message in a single
203 // line. This view is used for NOTIFICATION_TYPE_PROGRESS. 148 // line. This view is used for NOTIFICATION_TYPE_PROGRESS.
204 class CompactTitleMessageView : public views::View { 149 class CompactTitleMessageView : public views::View {
205 public: 150 public:
206 explicit CompactTitleMessageView(); 151 explicit CompactTitleMessageView();
207 ~CompactTitleMessageView() override; 152 ~CompactTitleMessageView() override;
208 153
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 575
631 const std::vector<NotificationItem>& items = notification.items(); 576 const std::vector<NotificationItem>& items = notification.items();
632 577
633 for (size_t i = 0; i < items.size() && i < kMaxLinesForExpandedMessageView; 578 for (size_t i = 0; i < items.size() && i < kMaxLinesForExpandedMessageView;
634 ++i) { 579 ++i) {
635 ItemView* item_view = new ItemView(items[i]); 580 ItemView* item_view = new ItemView(items[i]);
636 item_views_.push_back(item_view); 581 item_views_.push_back(item_view);
637 left_content_->AddChildView(item_view); 582 left_content_->AddChildView(item_view);
638 } 583 }
639 584
640 if (!item_views_.empty()) { 585 list_items_count_ = items.size();
641 item_views_.front()->SetRemainingCount(items.size() - 1);
642 item_views_.back()->SetRemainingCount(items.size() - item_views_.size());
643 586
644 // Needed when CreateOrUpdateViews is called for update. 587 // Needed when CreateOrUpdateViews is called for update.
588 if (!item_views_.empty())
645 left_content_->InvalidateLayout(); 589 left_content_->InvalidateLayout();
646 }
647 } 590 }
648 591
649 void NotificationViewMD::CreateOrUpdateIconView( 592 void NotificationViewMD::CreateOrUpdateIconView(
650 const Notification& notification) { 593 const Notification& notification) {
651 if (notification.type() == NOTIFICATION_TYPE_PROGRESS || 594 if (notification.type() == NOTIFICATION_TYPE_PROGRESS ||
652 notification.type() == NOTIFICATION_TYPE_MULTIPLE) { 595 notification.type() == NOTIFICATION_TYPE_MULTIPLE) {
653 right_content_->RemoveChildView(icon_view_); 596 right_content_->RemoveChildView(icon_view_);
654 icon_view_ = nullptr; 597 icon_view_ = nullptr;
655 return; 598 return;
656 } 599 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 747
805 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { 748 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) {
806 header_row_->SetExpanded(expanded); 749 header_row_->SetExpanded(expanded);
807 if (message_view_) { 750 if (message_view_) {
808 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView 751 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView
809 : kMaxLinesForMessageView); 752 : kMaxLinesForMessageView);
810 } 753 }
811 if (image_container_) 754 if (image_container_)
812 image_container_->SetVisible(expanded); 755 image_container_->SetVisible(expanded);
813 actions_row_->SetVisible(expanded && actions_row_->has_children()); 756 actions_row_->SetVisible(expanded && actions_row_->has_children());
814 for (size_t i = 1; i < item_views_.size(); ++i) { 757 for (size_t i = kMaxLinesForMessageView; i < item_views_.size(); ++i) {
815 item_views_[i]->SetVisible(expanded); 758 item_views_[i]->SetVisible(expanded);
816 } 759 }
817 if (!item_views_.empty()) { 760 header_row_->SetOverflowIndicator(
818 item_views_.front()->SetRemainingCountVisible(!expanded); 761 expanded ? list_items_count_ - item_views_.size()
819 item_views_.back()->SetRemainingCountVisible(expanded); 762 : list_items_count_ - kMaxLinesForMessageView);
yoshiki 2017/07/03 07:27:20 nit: "list_items_count_ - (expanded ? item_views_.
tetsui 2017/07/03 07:36:00 Done.
820 }
821 } 763 }
822 764
823 void NotificationViewMD::UpdateControlButtonsVisibility() { 765 void NotificationViewMD::UpdateControlButtonsVisibility() {
824 const bool target_visibility = IsMouseHovered() || HasFocus() || 766 const bool target_visibility = IsMouseHovered() || HasFocus() ||
825 (header_row_->IsExpandButtonEnabled() && 767 (header_row_->IsExpandButtonEnabled() &&
826 header_row_->expand_button()->HasFocus()) || 768 header_row_->expand_button()->HasFocus()) ||
827 (header_row_->IsCloseButtonEnabled() && 769 (header_row_->IsCloseButtonEnabled() &&
828 header_row_->close_button()->HasFocus()) || 770 header_row_->close_button()->HasFocus()) ||
829 (header_row_->IsSettingsButtonEnabled() && 771 (header_row_->IsSettingsButtonEnabled() &&
830 header_row_->settings_button()->HasFocus()); 772 header_row_->settings_button()->HasFocus());
831 773
832 header_row_->SetControlButtonsVisible(target_visibility); 774 header_row_->SetControlButtonsVisible(target_visibility);
833 } 775 }
834 776
835 } // namespace message_center 777 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698