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 "base/strings/utf_string_conversions.h" | |
|
fukino
2017/06/13 05:48:24
seems unnecessary?
tetsui
2017/06/13 05:52:39
Done.
| |
| 10 #include "ui/base/cursor/cursor.h" | 11 #include "ui/base/cursor/cursor.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/gfx/image/image_skia_operations.h" | 14 #include "ui/gfx/image/image_skia_operations.h" |
| 14 #include "ui/gfx/paint_vector_icon.h" | 15 #include "ui/gfx/paint_vector_icon.h" |
| 15 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 16 #include "ui/gfx/text_elider.h" | 17 #include "ui/gfx/text_elider.h" |
| 17 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
| 18 #include "ui/message_center/message_center_style.h" | 19 #include "ui/message_center/message_center_style.h" |
| 19 #include "ui/message_center/notification.h" | 20 #include "ui/message_center/notification.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 const gfx::ImageSkia masked_small_image = | 84 const gfx::ImageSkia masked_small_image = |
| 84 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon); | 85 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon); |
| 85 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, | 86 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, |
| 86 masked_small_image); | 87 masked_small_image); |
| 87 } | 88 } |
| 88 | 89 |
| 89 const gfx::ImageSkia GetProductIcon() { | 90 const gfx::ImageSkia GetProductIcon() { |
| 90 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); | 91 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); |
| 91 } | 92 } |
| 92 | 93 |
| 94 // ItemView //////////////////////////////////////////////////////////////////// | |
| 95 | |
| 96 // ItemViews are responsible for drawing each list notification item's title and | |
| 97 // message next to each other within a single column. | |
| 98 class ItemView : public views::View { | |
| 99 public: | |
| 100 explicit ItemView(const message_center::NotificationItem& item); | |
| 101 ~ItemView() override; | |
| 102 | |
| 103 private: | |
| 104 DISALLOW_COPY_AND_ASSIGN(ItemView); | |
| 105 }; | |
| 106 | |
| 107 ItemView::ItemView(const message_center::NotificationItem& item) { | |
| 108 SetLayoutManager( | |
| 109 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), | |
| 110 message_center::kItemTitleToMessagePadding)); | |
| 111 | |
| 112 views::Label* title = new views::Label(item.title); | |
| 113 title->set_collapse_when_hidden(true); | |
| 114 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 115 title->SetEnabledColor(message_center::kRegularTextColor); | |
| 116 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); | |
| 117 AddChildView(title); | |
| 118 | |
| 119 views::Label* message = new views::Label(item.message); | |
| 120 message->set_collapse_when_hidden(true); | |
| 121 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 122 message->SetEnabledColor(message_center::kDimTextColor); | |
| 123 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); | |
| 124 AddChildView(message); | |
| 125 } | |
| 126 | |
| 127 ItemView::~ItemView() {} | |
| 128 | |
| 93 } // anonymous namespace | 129 } // anonymous namespace |
| 94 | 130 |
| 95 // //////////////////////////////////////////////////////////// | 131 // //////////////////////////////////////////////////////////// |
| 96 // NotificationViewMD | 132 // NotificationViewMD |
| 97 // //////////////////////////////////////////////////////////// | 133 // //////////////////////////////////////////////////////////// |
| 98 | 134 |
| 99 views::View* NotificationViewMD::TargetForRect(views::View* root, | 135 views::View* NotificationViewMD::TargetForRect(views::View* root, |
| 100 const gfx::Rect& rect) { | 136 const gfx::Rect& rect) { |
| 101 CHECK_EQ(root, this); | 137 CHECK_EQ(root, this); |
| 102 | 138 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 133 CreateOrUpdateMessageView(notification); | 169 CreateOrUpdateMessageView(notification); |
| 134 CreateOrUpdateProgressBarView(notification); | 170 CreateOrUpdateProgressBarView(notification); |
| 135 CreateOrUpdateListItemViews(notification); | 171 CreateOrUpdateListItemViews(notification); |
| 136 CreateOrUpdateIconView(notification); | 172 CreateOrUpdateIconView(notification); |
| 137 CreateOrUpdateSmallIconView(notification); | 173 CreateOrUpdateSmallIconView(notification); |
| 138 CreateOrUpdateImageView(notification); | 174 CreateOrUpdateImageView(notification); |
| 139 CreateOrUpdateActionButtonViews(notification); | 175 CreateOrUpdateActionButtonViews(notification); |
| 140 CreateOrUpdateCloseButtonView(notification); | 176 CreateOrUpdateCloseButtonView(notification); |
| 141 CreateOrUpdateSettingsButtonView(notification); | 177 CreateOrUpdateSettingsButtonView(notification); |
| 142 UpdateViewForExpandedState(expanded_); | 178 UpdateViewForExpandedState(expanded_); |
| 179 | |
| 180 // Needed when CreateOrUpdateListItemViews is called for update. | |
| 181 left_content_->Layout(); | |
| 143 } | 182 } |
| 144 | 183 |
| 145 NotificationViewMD::NotificationViewMD(MessageCenterController* controller, | 184 NotificationViewMD::NotificationViewMD(MessageCenterController* controller, |
| 146 const Notification& notification) | 185 const Notification& notification) |
| 147 : MessageView(controller, notification), | 186 : MessageView(controller, notification), |
| 148 clickable_(notification.clickable()) { | 187 clickable_(notification.clickable()) { |
| 149 SetLayoutManager( | 188 SetLayoutManager( |
| 150 new views::BoxLayout(views::BoxLayout::kVertical, gfx::Insets(), 0)); | 189 new views::BoxLayout(views::BoxLayout::kVertical, gfx::Insets(), 0)); |
| 151 | 190 |
| 152 // |header_row_| contains app_icon, app_name, control buttons, etc... | 191 // |header_row_| contains app_icon, app_name, control buttons, etc... |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 | 379 |
| 341 if (!message_view_) { | 380 if (!message_view_) { |
| 342 message_view_ = new BoundedLabel(text, font_list); | 381 message_view_ = new BoundedLabel(text, font_list); |
| 343 message_view_->SetLineLimit(kMaxLinesForMessageView); | 382 message_view_->SetLineLimit(kMaxLinesForMessageView); |
| 344 message_view_->SetColors(message_center::kDimTextColor, | 383 message_view_->SetColors(message_center::kDimTextColor, |
| 345 kContextTextBackgroundColor); | 384 kContextTextBackgroundColor); |
| 346 left_content_->AddChildView(message_view_); | 385 left_content_->AddChildView(message_view_); |
| 347 } else { | 386 } else { |
| 348 message_view_->SetText(text); | 387 message_view_->SetText(text); |
| 349 } | 388 } |
| 389 | |
| 390 message_view_->SetVisible(notification.items().empty()); | |
| 350 } | 391 } |
| 351 | 392 |
| 352 void NotificationViewMD::CreateOrUpdateProgressBarView( | 393 void NotificationViewMD::CreateOrUpdateProgressBarView( |
| 353 const Notification& notification) { | 394 const Notification& notification) { |
| 354 // TODO(yoshiki): Implement this. | 395 // TODO(yoshiki): Implement this. |
| 355 } | 396 } |
| 356 | 397 |
| 357 void NotificationViewMD::CreateOrUpdateListItemViews( | 398 void NotificationViewMD::CreateOrUpdateListItemViews( |
| 358 const Notification& notification) { | 399 const Notification& notification) { |
| 359 // TODO(yoshiki): Implement this. | 400 for (auto* item_view : item_views_) |
| 401 delete item_view; | |
| 402 item_views_.clear(); | |
| 403 | |
| 404 const std::vector<NotificationItem>& items = notification.items(); | |
| 405 | |
| 406 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | |
| 407 ItemView* item_view = new ItemView(items[i]); | |
| 408 item_views_.push_back(item_view); | |
| 409 left_content_->AddChildView(item_view); | |
| 410 } | |
| 360 } | 411 } |
| 361 | 412 |
| 362 void NotificationViewMD::CreateOrUpdateIconView( | 413 void NotificationViewMD::CreateOrUpdateIconView( |
| 363 const Notification& notification) { | 414 const Notification& notification) { |
| 364 gfx::Size image_view_size(30, 30); | 415 gfx::Size image_view_size(30, 30); |
| 365 if (!icon_view_) { | 416 if (!icon_view_) { |
| 366 icon_view_ = new ProportionalImageView(image_view_size); | 417 icon_view_ = new ProportionalImageView(image_view_size); |
| 367 right_content_->AddChildView(icon_view_); | 418 right_content_->AddChildView(icon_view_); |
| 368 } | 419 } |
| 369 | 420 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 return true; | 529 return true; |
| 479 } | 530 } |
| 480 // Expandable if there is at least one inline action. | 531 // Expandable if there is at least one inline action. |
| 481 if (actions_row_->has_children()) | 532 if (actions_row_->has_children()) |
| 482 return true; | 533 return true; |
| 483 | 534 |
| 484 // Expandable if the notification has image. | 535 // Expandable if the notification has image. |
| 485 if (image_view_) | 536 if (image_view_) |
| 486 return true; | 537 return true; |
| 487 | 538 |
| 539 // Expandable if there are multiple list items. | |
| 540 if (item_views_.size() > 1) | |
| 541 return true; | |
| 542 | |
| 488 // TODO(fukino): Expandable if both progress bar and message exist. | 543 // TODO(fukino): Expandable if both progress bar and message exist. |
| 489 | 544 |
| 490 return false; | 545 return false; |
| 491 } | 546 } |
| 492 | 547 |
| 493 void NotificationViewMD::ToggleExpanded() { | 548 void NotificationViewMD::ToggleExpanded() { |
| 494 expanded_ = !expanded_; | 549 expanded_ = !expanded_; |
| 495 UpdateViewForExpandedState(expanded_); | 550 UpdateViewForExpandedState(expanded_); |
| 496 content_row_->InvalidateLayout(); | 551 content_row_->InvalidateLayout(); |
| 497 if (controller()) | 552 if (controller()) |
| 498 controller()->UpdateNotificationSize(notification_id()); | 553 controller()->UpdateNotificationSize(notification_id()); |
| 499 } | 554 } |
| 500 | 555 |
| 501 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { | 556 void NotificationViewMD::UpdateViewForExpandedState(bool expanded) { |
| 502 header_row_->SetExpanded(expanded); | 557 header_row_->SetExpanded(expanded); |
| 503 if (message_view_) { | 558 if (message_view_) { |
| 504 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView | 559 message_view_->SetLineLimit(expanded ? kMaxLinesForExpandedMessageView |
| 505 : kMaxLinesForMessageView); | 560 : kMaxLinesForMessageView); |
| 506 } | 561 } |
| 507 if (image_container_) | 562 if (image_container_) |
| 508 image_container_->SetVisible(expanded); | 563 image_container_->SetVisible(expanded); |
| 509 actions_row_->SetVisible(expanded && actions_row_->has_children()); | 564 actions_row_->SetVisible(expanded && actions_row_->has_children()); |
| 565 for (size_t i = 1; i < item_views_.size(); ++i) { | |
| 566 item_views_[i]->SetVisible(expanded); | |
| 567 } | |
| 510 } | 568 } |
| 511 | 569 |
| 512 void NotificationViewMD::UpdateControlButtonsVisibility() { | 570 void NotificationViewMD::UpdateControlButtonsVisibility() { |
| 513 const bool target_visibility = IsMouseHovered() || HasFocus() || | 571 const bool target_visibility = IsMouseHovered() || HasFocus() || |
| 514 (header_row_->IsExpandButtonEnabled() && | 572 (header_row_->IsExpandButtonEnabled() && |
| 515 header_row_->expand_button()->HasFocus()) || | 573 header_row_->expand_button()->HasFocus()) || |
| 516 (header_row_->IsCloseButtonEnabled() && | 574 (header_row_->IsCloseButtonEnabled() && |
| 517 header_row_->close_button()->HasFocus()) || | 575 header_row_->close_button()->HasFocus()) || |
| 518 (header_row_->IsSettingsButtonEnabled() && | 576 (header_row_->IsSettingsButtonEnabled() && |
| 519 header_row_->settings_button()->HasFocus()); | 577 header_row_->settings_button()->HasFocus()); |
| 520 | 578 |
| 521 header_row_->SetControlButtonsVisible(target_visibility); | 579 header_row_->SetControlButtonsVisible(target_visibility); |
| 522 } | 580 } |
| 523 | 581 |
| 524 } // namespace message_center | 582 } // namespace message_center |
| OLD | NEW |