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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 const gfx::ImageSkia masked_small_image = | 79 const gfx::ImageSkia masked_small_image = |
| 80 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon); | 80 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon); |
| 81 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, | 81 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, |
| 82 masked_small_image); | 82 masked_small_image); |
| 83 } | 83 } |
| 84 | 84 |
| 85 const gfx::ImageSkia GetProductIcon() { | 85 const gfx::ImageSkia GetProductIcon() { |
| 86 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); | 86 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // ItemView //////////////////////////////////////////////////////////////////// | |
| 90 | |
| 91 // ItemViews are responsible for drawing each list notification item's title and | |
| 92 // message next to each other within a single column. | |
| 93 class ItemView : public views::View { | |
| 94 public: | |
| 95 explicit ItemView(const message_center::NotificationItem& item); | |
| 96 ~ItemView() override; | |
| 97 | |
| 98 // Overridden from views::View: | |
| 99 void SetVisible(bool visible) override; | |
| 100 | |
| 101 private: | |
| 102 DISALLOW_COPY_AND_ASSIGN(ItemView); | |
| 103 }; | |
| 104 | |
| 105 ItemView::ItemView(const message_center::NotificationItem& item) { | |
| 106 SetLayoutManager( | |
| 107 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | |
| 108 message_center::kItemTitleToMessagePadding)); | |
| 109 | |
| 110 views::Label* title = new views::Label(item.title); | |
| 111 title->set_collapse_when_hidden(true); | |
| 112 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 113 title->SetEnabledColor(message_center::kRegularTextColor); | |
| 114 title->SetBackgroundColor(message_center::kRegularTextBackgroundColor); | |
| 115 AddChildView(title); | |
| 116 | |
| 117 views::Label* message = new views::Label(item.message); | |
| 118 message->set_collapse_when_hidden(true); | |
| 119 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 120 message->SetEnabledColor(message_center::kDimTextColor); | |
| 121 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); | |
| 122 AddChildView(message); | |
| 123 | |
| 124 PreferredSizeChanged(); | |
|
yoshiki
2017/06/05 04:29:13
I think this is not necessary, since the preferred
tetsui
2017/06/13 03:44:33
Done.
| |
| 125 SchedulePaint(); | |
|
yoshiki
2017/06/05 04:29:13
I also think this is not necessary, since adding a
tetsui
2017/06/13 03:44:33
Done.
| |
| 126 } | |
| 127 | |
| 128 ItemView::~ItemView() {} | |
| 129 | |
| 130 void ItemView::SetVisible(bool visible) { | |
| 131 views::View::SetVisible(visible); | |
| 132 for (int i = 0; i < child_count(); ++i) | |
| 133 child_at(i)->SetVisible(visible); | |
|
yoshiki
2017/06/05 04:29:13
It looks necessary? I think setting visibility of
tetsui
2017/06/13 03:44:33
Done.
| |
| 134 } | |
| 135 | |
| 89 } // anonymous namespace | 136 } // anonymous namespace |
| 90 | 137 |
| 91 // //////////////////////////////////////////////////////////// | 138 // //////////////////////////////////////////////////////////// |
| 92 // NotificationViewMD | 139 // NotificationViewMD |
| 93 // //////////////////////////////////////////////////////////// | 140 // //////////////////////////////////////////////////////////// |
| 94 | 141 |
| 95 views::View* NotificationViewMD::TargetForRect(views::View* root, | 142 views::View* NotificationViewMD::TargetForRect(views::View* root, |
| 96 const gfx::Rect& rect) { | 143 const gfx::Rect& rect) { |
| 97 CHECK_EQ(root, this); | 144 CHECK_EQ(root, this); |
| 98 | 145 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 } | 412 } |
| 366 } | 413 } |
| 367 | 414 |
| 368 void NotificationViewMD::CreateOrUpdateProgressBarView( | 415 void NotificationViewMD::CreateOrUpdateProgressBarView( |
| 369 const Notification& notification) { | 416 const Notification& notification) { |
| 370 // TODO(yoshiki): Implement this. | 417 // TODO(yoshiki): Implement this. |
| 371 } | 418 } |
| 372 | 419 |
| 373 void NotificationViewMD::CreateOrUpdateListItemViews( | 420 void NotificationViewMD::CreateOrUpdateListItemViews( |
| 374 const Notification& notification) { | 421 const Notification& notification) { |
| 375 // TODO(yoshiki): Implement this. | 422 for (auto* item_view : item_views_) |
| 423 delete item_view; | |
| 424 item_views_.clear(); | |
| 425 | |
| 426 const std::vector<NotificationItem>& items = notification.items(); | |
| 427 | |
| 428 if (items.size() == 0) | |
| 429 return; | |
| 430 | |
| 431 DCHECK(top_view_); | |
|
yoshiki
2017/06/05 04:29:13
Should we check main_view_ instead of top_view_, s
tetsui
2017/06/13 03:44:33
Done.
| |
| 432 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | |
| 433 ItemView* item_view = new ItemView(items[i]); | |
| 434 item_views_.push_back(item_view); | |
| 435 main_view_->AddChildView(item_view); | |
| 436 } | |
| 376 } | 437 } |
| 377 | 438 |
| 378 void NotificationViewMD::CreateOrUpdateIconView( | 439 void NotificationViewMD::CreateOrUpdateIconView( |
| 379 const Notification& notification) { | 440 const Notification& notification) { |
| 380 // TODO(yoshiki): Implement this. | 441 // TODO(yoshiki): Implement this. |
| 381 } | 442 } |
| 382 | 443 |
| 383 void NotificationViewMD::CreateOrUpdateSmallIconView( | 444 void NotificationViewMD::CreateOrUpdateSmallIconView( |
| 384 const Notification& notification) { | 445 const Notification& notification) { |
| 385 gfx::ImageSkia icon = | 446 gfx::ImageSkia icon = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 close_button_->SetVisible(target_visibility); | 507 close_button_->SetVisible(target_visibility); |
| 447 } | 508 } |
| 448 | 509 |
| 449 if (settings_button_) { | 510 if (settings_button_) { |
| 450 if (target_visibility != settings_button_->visible()) | 511 if (target_visibility != settings_button_->visible()) |
| 451 settings_button_->SetVisible(target_visibility); | 512 settings_button_->SetVisible(target_visibility); |
| 452 } | 513 } |
| 453 } | 514 } |
| 454 | 515 |
| 455 } // namespace message_center | 516 } // namespace message_center |
| OLD | NEW |