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_number_conversions.h" | |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/gfx/image/image_skia_operations.h" | 15 #include "ui/gfx/image/image_skia_operations.h" |
| 14 #include "ui/gfx/paint_vector_icon.h" | 16 #include "ui/gfx/paint_vector_icon.h" |
| 15 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
| 16 #include "ui/gfx/text_elider.h" | 18 #include "ui/gfx/text_elider.h" |
| 17 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
| 18 #include "ui/message_center/message_center_style.h" | 20 #include "ui/message_center/message_center_style.h" |
| 19 #include "ui/message_center/notification.h" | 21 #include "ui/message_center/notification.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 const gfx::ImageSkia GetProductIcon() { | 91 const gfx::ImageSkia GetProductIcon() { |
| 90 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); | 92 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); |
| 91 } | 93 } |
| 92 | 94 |
| 93 // ItemView //////////////////////////////////////////////////////////////////// | 95 // ItemView //////////////////////////////////////////////////////////////////// |
| 94 | 96 |
| 95 // ItemViews are responsible for drawing each list notification item's title and | 97 // ItemViews are responsible for drawing each list notification item's title and |
| 96 // message next to each other within a single column. | 98 // message next to each other within a single column. |
| 97 class ItemView : public views::View { | 99 class ItemView : public views::View { |
| 98 public: | 100 public: |
| 99 explicit ItemView(const message_center::NotificationItem& item); | 101 explicit ItemView(const message_center::NotificationItem& item, |
| 102 int num_remaining); | |
| 100 ~ItemView() override; | 103 ~ItemView() override; |
| 101 | 104 |
| 105 void SetRemainingCountVisible(bool visible); | |
| 106 | |
| 102 private: | 107 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(ItemView); | 108 DISALLOW_COPY_AND_ASSIGN(ItemView); |
|
yoshiki
2017/06/21 07:32:12
please place this at the last.
tetsui
2017/06/22 07:25:23
Done.
| |
| 109 | |
| 110 views::View* container_; | |
| 111 views::Label* remaining_count_; | |
| 104 }; | 112 }; |
| 105 | 113 |
| 106 ItemView::ItemView(const message_center::NotificationItem& item) { | 114 ItemView::ItemView(const message_center::NotificationItem& item, |
| 107 SetLayoutManager( | 115 int num_remaining) { |
| 116 container_ = new views::View; | |
| 117 AddChildView(container_); | |
| 118 SetLayoutManager(new views::FillLayout()); | |
| 119 | |
| 120 container_->SetLayoutManager( | |
| 108 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), | 121 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), |
| 109 message_center::kItemTitleToMessagePadding)); | 122 message_center::kItemTitleToMessagePadding)); |
| 110 | 123 |
| 111 views::Label* title = new views::Label(item.title); | 124 views::Label* title = new views::Label(item.title); |
| 112 title->set_collapse_when_hidden(true); | 125 title->set_collapse_when_hidden(true); |
| 113 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 126 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 114 title->SetEnabledColor(message_center::kRegularTextColor); | 127 title->SetEnabledColor(message_center::kRegularTextColor); |
| 115 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 128 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| 116 AddChildView(title); | 129 container_->AddChildView(title); |
| 117 | 130 |
| 118 views::Label* message = new views::Label(item.message); | 131 views::Label* message = new views::Label(item.message); |
| 119 message->set_collapse_when_hidden(true); | 132 message->set_collapse_when_hidden(true); |
| 120 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 133 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 121 message->SetEnabledColor(message_center::kDimTextColor); | 134 message->SetEnabledColor(message_center::kDimTextColor); |
| 122 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); | 135 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| 123 AddChildView(message); | 136 container_->AddChildView(message); |
| 137 | |
| 138 remaining_count_ = new views::Label(); | |
| 139 remaining_count_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | |
| 140 remaining_count_->SetEnabledColor(message_center::kDimTextColor); | |
| 141 remaining_count_->SetBackgroundColor(message_center::kDimTextBackgroundColor); | |
| 142 AddChildView(remaining_count_); | |
| 143 if (num_remaining > 0) { | |
| 144 remaining_count_->SetText(base::UTF8ToUTF16("+") + | |
| 145 base::IntToString16(num_remaining)); | |
|
yoshiki
2017/06/21 07:32:12
Could you use a localized string instead of just "
tetsui
2017/06/22 07:25:23
Done.
| |
| 146 } | |
| 147 remaining_count_->SetVisible(false); | |
| 124 } | 148 } |
| 125 | 149 |
| 126 ItemView::~ItemView() {} | 150 ItemView::~ItemView() {} |
| 127 | 151 |
| 152 void ItemView::SetRemainingCountVisible(bool visible) { | |
| 153 remaining_count_->SetVisible(visible); | |
| 154 } | |
| 155 | |
| 128 } // anonymous namespace | 156 } // anonymous namespace |
| 129 | 157 |
| 130 // //////////////////////////////////////////////////////////// | 158 // //////////////////////////////////////////////////////////// |
| 131 // NotificationViewMD | 159 // NotificationViewMD |
| 132 // //////////////////////////////////////////////////////////// | 160 // //////////////////////////////////////////////////////////// |
| 133 | 161 |
| 134 views::View* NotificationViewMD::TargetForRect(views::View* root, | 162 views::View* NotificationViewMD::TargetForRect(views::View* root, |
| 135 const gfx::Rect& rect) { | 163 const gfx::Rect& rect) { |
| 136 CHECK_EQ(root, this); | 164 CHECK_EQ(root, this); |
| 137 | 165 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 } | 420 } |
| 393 | 421 |
| 394 void NotificationViewMD::CreateOrUpdateListItemViews( | 422 void NotificationViewMD::CreateOrUpdateListItemViews( |
| 395 const Notification& notification) { | 423 const Notification& notification) { |
| 396 for (auto* item_view : item_views_) | 424 for (auto* item_view : item_views_) |
| 397 delete item_view; | 425 delete item_view; |
| 398 item_views_.clear(); | 426 item_views_.clear(); |
| 399 | 427 |
| 400 const std::vector<NotificationItem>& items = notification.items(); | 428 const std::vector<NotificationItem>& items = notification.items(); |
| 401 | 429 |
| 402 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 430 for (size_t i = 0; i < items.size() && i < kMaxLinesForExpandedMessageView; |
| 403 ItemView* item_view = new ItemView(items[i]); | 431 ++i) { |
| 432 ItemView* item_view = new ItemView(items[i], items.size() - i - 1); | |
| 404 item_views_.push_back(item_view); | 433 item_views_.push_back(item_view); |
| 405 left_content_->AddChildView(item_view); | 434 left_content_->AddChildView(item_view); |
| 406 } | 435 } |
| 407 | 436 |
| 408 // Needed when CreateOrUpdateViews is called for update. | 437 // Needed when CreateOrUpdateViews is called for update. |
| 409 if (!item_views_.empty()) | 438 if (!item_views_.empty()) |
| 410 left_content_->InvalidateLayout(); | 439 left_content_->InvalidateLayout(); |
| 411 } | 440 } |
| 412 | 441 |
| 413 void NotificationViewMD::CreateOrUpdateIconView( | 442 void NotificationViewMD::CreateOrUpdateIconView( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 | 591 |
| 563 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { | 592 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { |
| 564 header_row_->SetExpanded(expanded); | 593 header_row_->SetExpanded(expanded); |
| 565 if (message_view_) { | 594 if (message_view_) { |
| 566 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView | 595 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView |
| 567 : kMaxLinesForMessageView); | 596 : kMaxLinesForMessageView); |
| 568 } | 597 } |
| 569 if (image_container_) | 598 if (image_container_) |
| 570 image_container_->SetVisible(expanded); | 599 image_container_->SetVisible(expanded); |
| 571 actions_row_->SetVisible(expanded && actions_row_->has_children()); | 600 actions_row_->SetVisible(expanded && actions_row_->has_children()); |
| 572 for (size_t i = 1; i < item_views_.size(); ++i) { | 601 for (size_t i = kMaxLinesForMessageView; i < item_views_.size(); ++i) { |
| 573 item_views_[i]->SetVisible(expanded); | 602 item_views_[i]->SetVisible(expanded); |
| 574 } | 603 } |
| 604 if (!item_views_.empty()) { | |
| 605 item_views_.front()->SetRemainingCountVisible(!expanded); | |
| 606 item_views_.back()->SetRemainingCountVisible(expanded); | |
| 607 } | |
| 575 } | 608 } |
| 576 | 609 |
| 577 void NotificationViewMD::UpdateControlButtonsVisibility() { | 610 void NotificationViewMD::UpdateControlButtonsVisibility() { |
| 578 const bool target_visibility = IsMouseHovered() || HasFocus() || | 611 const bool target_visibility = IsMouseHovered() || HasFocus() || |
| 579 (header_row_->IsExpandButtonEnabled() && | 612 (header_row_->IsExpandButtonEnabled() && |
| 580 header_row_->expand_button()->HasFocus()) || | 613 header_row_->expand_button()->HasFocus()) || |
| 581 (header_row_->IsCloseButtonEnabled() && | 614 (header_row_->IsCloseButtonEnabled() && |
| 582 header_row_->close_button()->HasFocus()) || | 615 header_row_->close_button()->HasFocus()) || |
| 583 (header_row_->IsSettingsButtonEnabled() && | 616 (header_row_->IsSettingsButtonEnabled() && |
| 584 header_row_->settings_button()->HasFocus()); | 617 header_row_->settings_button()->HasFocus()); |
| 585 | 618 |
| 586 header_row_->SetControlButtonsVisible(target_visibility); | 619 header_row_->SetControlButtonsVisible(target_visibility); |
| 587 } | 620 } |
| 588 | 621 |
| 589 } // namespace message_center | 622 } // namespace message_center |
| OLD | NEW |