| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const gfx::ImageSkia masked_small_image = | 83 const gfx::ImageSkia masked_small_image = |
| 84 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon); | 84 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, icon); |
| 85 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, | 85 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, |
| 86 masked_small_image); | 86 masked_small_image); |
| 87 } | 87 } |
| 88 | 88 |
| 89 const gfx::ImageSkia GetProductIcon() { | 89 const gfx::ImageSkia GetProductIcon() { |
| 90 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); | 90 return gfx::CreateVectorIcon(kProductIcon, kSmallImageColor); |
| 91 } | 91 } |
| 92 | 92 |
| 93 // ItemView //////////////////////////////////////////////////////////////////// |
| 94 |
| 95 // ItemViews are responsible for drawing each list notification item's title and |
| 96 // message next to each other within a single column. |
| 97 class ItemView : public views::View { |
| 98 public: |
| 99 explicit ItemView(const message_center::NotificationItem& item); |
| 100 ~ItemView() override; |
| 101 |
| 102 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(ItemView); |
| 104 }; |
| 105 |
| 106 ItemView::ItemView(const message_center::NotificationItem& item) { |
| 107 SetLayoutManager( |
| 108 new views::BoxLayout(views::BoxLayout::kHorizontal, gfx::Insets(), |
| 109 message_center::kItemTitleToMessagePadding)); |
| 110 |
| 111 views::Label* title = new views::Label(item.title); |
| 112 title->set_collapse_when_hidden(true); |
| 113 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 114 title->SetEnabledColor(message_center::kRegularTextColor); |
| 115 title->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| 116 AddChildView(title); |
| 117 |
| 118 views::Label* message = new views::Label(item.message); |
| 119 message->set_collapse_when_hidden(true); |
| 120 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 121 message->SetEnabledColor(message_center::kDimTextColor); |
| 122 message->SetBackgroundColor(message_center::kDimTextBackgroundColor); |
| 123 AddChildView(message); |
| 124 } |
| 125 |
| 126 ItemView::~ItemView() {} |
| 127 |
| 93 } // anonymous namespace | 128 } // anonymous namespace |
| 94 | 129 |
| 95 // //////////////////////////////////////////////////////////// | 130 // //////////////////////////////////////////////////////////// |
| 96 // NotificationViewMD | 131 // NotificationViewMD |
| 97 // //////////////////////////////////////////////////////////// | 132 // //////////////////////////////////////////////////////////// |
| 98 | 133 |
| 99 views::View* NotificationViewMD::TargetForRect(views::View* root, | 134 views::View* NotificationViewMD::TargetForRect(views::View* root, |
| 100 const gfx::Rect& rect) { | 135 const gfx::Rect& rect) { |
| 101 CHECK_EQ(root, this); | 136 CHECK_EQ(root, this); |
| 102 | 137 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 375 |
| 341 if (!message_view_) { | 376 if (!message_view_) { |
| 342 message_view_ = new BoundedLabel(text, font_list); | 377 message_view_ = new BoundedLabel(text, font_list); |
| 343 message_view_->SetLineLimit(kMaxLinesForMessageView); | 378 message_view_->SetLineLimit(kMaxLinesForMessageView); |
| 344 message_view_->SetColors(message_center::kDimTextColor, | 379 message_view_->SetColors(message_center::kDimTextColor, |
| 345 kContextTextBackgroundColor); | 380 kContextTextBackgroundColor); |
| 346 left_content_->AddChildView(message_view_); | 381 left_content_->AddChildView(message_view_); |
| 347 } else { | 382 } else { |
| 348 message_view_->SetText(text); | 383 message_view_->SetText(text); |
| 349 } | 384 } |
| 385 |
| 386 message_view_->SetVisible(notification.items().empty()); |
| 350 } | 387 } |
| 351 | 388 |
| 352 void NotificationViewMD::CreateOrUpdateProgressBarView( | 389 void NotificationViewMD::CreateOrUpdateProgressBarView( |
| 353 const Notification& notification) { | 390 const Notification& notification) { |
| 354 // TODO(yoshiki): Implement this. | 391 // TODO(yoshiki): Implement this. |
| 355 } | 392 } |
| 356 | 393 |
| 357 void NotificationViewMD::CreateOrUpdateListItemViews( | 394 void NotificationViewMD::CreateOrUpdateListItemViews( |
| 358 const Notification& notification) { | 395 const Notification& notification) { |
| 359 // TODO(yoshiki): Implement this. | 396 for (auto* item_view : item_views_) |
| 397 delete item_view; |
| 398 item_views_.clear(); |
| 399 |
| 400 const std::vector<NotificationItem>& items = notification.items(); |
| 401 |
| 402 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
| 403 ItemView* item_view = new ItemView(items[i]); |
| 404 item_views_.push_back(item_view); |
| 405 left_content_->AddChildView(item_view); |
| 406 } |
| 407 |
| 408 // Needed when CreateOrUpdateViews is called for update. |
| 409 if (!item_views_.empty()) |
| 410 left_content_->InvalidateLayout(); |
| 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 |