Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "ui/message_center/views/notification_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "ui/message_center/message_center_switches.h" | 21 #include "ui/message_center/message_center_switches.h" |
| 22 #include "ui/message_center/message_center_tray.h" | 22 #include "ui/message_center/message_center_tray.h" |
| 23 #include "ui/message_center/message_center_util.h" | 23 #include "ui/message_center/message_center_util.h" |
| 24 #include "ui/message_center/notification.h" | 24 #include "ui/message_center/notification.h" |
| 25 #include "ui/message_center/notification_types.h" | 25 #include "ui/message_center/notification_types.h" |
| 26 #include "ui/message_center/views/bounded_label.h" | 26 #include "ui/message_center/views/bounded_label.h" |
| 27 #include "ui/message_center/views/padded_button.h" | 27 #include "ui/message_center/views/padded_button.h" |
| 28 #include "ui/native_theme/native_theme.h" | 28 #include "ui/native_theme/native_theme.h" |
| 29 #include "ui/views/background.h" | 29 #include "ui/views/background.h" |
| 30 #include "ui/views/border.h" | 30 #include "ui/views/border.h" |
| 31 #include "ui/views/context_menu_controller.h" | |
| 31 #include "ui/views/controls/button/image_button.h" | 32 #include "ui/views/controls/button/image_button.h" |
| 32 #include "ui/views/controls/image_view.h" | 33 #include "ui/views/controls/image_view.h" |
| 33 #include "ui/views/controls/label.h" | 34 #include "ui/views/controls/label.h" |
| 35 #include "ui/views/controls/menu/menu_runner.h" | |
| 34 #include "ui/views/controls/progress_bar.h" | 36 #include "ui/views/controls/progress_bar.h" |
| 35 #include "ui/views/layout/box_layout.h" | 37 #include "ui/views/layout/box_layout.h" |
| 36 #include "ui/views/layout/fill_layout.h" | 38 #include "ui/views/layout/fill_layout.h" |
| 37 #include "ui/views/painter.h" | 39 #include "ui/views/painter.h" |
| 38 #include "ui/views/widget/widget.h" | 40 #include "ui/views/widget/widget.h" |
| 39 | 41 |
| 40 #if defined(USE_AURA) | 42 #if defined(USE_AURA) |
| 41 #include "ui/base/cursor/cursor.h" | 43 #include "ui/base/cursor/cursor.h" |
| 42 #endif | 44 #endif |
| 43 | 45 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 set_background( | 427 set_background( |
| 426 MakeBackground(message_center::kHoveredButtonBackgroundColor)); | 428 MakeBackground(message_center::kHoveredButtonBackgroundColor)); |
| 427 } else { | 429 } else { |
| 428 set_background(NULL); | 430 set_background(NULL); |
| 429 } | 431 } |
| 430 } | 432 } |
| 431 | 433 |
| 432 } // namespace | 434 } // namespace |
| 433 | 435 |
| 434 namespace message_center { | 436 namespace message_center { |
| 435 | 437 |
|
stevenjb
2013/12/12 21:19:46
nit: Put in internal namespace, i.e. message_cente
Jun Mukai
2013/12/14 01:13:14
this code has been removed.
| |
| 438 class NotificationViewContextMenuController | |
| 439 : public views::ContextMenuController { | |
| 440 public: | |
| 441 NotificationViewContextMenuController(MessageCenterTray* tray); | |
|
stevenjb
2013/12/12 21:19:46
explicit
| |
| 442 virtual ~NotificationViewContextMenuController(); | |
| 443 | |
| 444 protected: | |
| 445 // Overridden from views::ContextMenuController: | |
| 446 virtual void ShowContextMenuForView(views::View* source, | |
| 447 const gfx::Point& point, | |
| 448 ui::MenuSourceType source_type) OVERRIDE; | |
| 449 | |
| 450 private: | |
| 451 MessageCenterTray* tray_; | |
|
stevenjb
2013/12/12 21:19:46
nit: WS
| |
| 452 DISALLOW_COPY_AND_ASSIGN(NotificationViewContextMenuController); | |
| 453 }; | |
| 454 | |
| 455 NotificationViewContextMenuController::NotificationViewContextMenuController( | |
| 456 MessageCenterTray* tray) | |
| 457 : tray_(tray) { | |
| 458 } | |
| 459 | |
| 460 NotificationViewContextMenuController:: | |
| 461 ~NotificationViewContextMenuController() { | |
| 462 } | |
| 463 | |
| 464 void NotificationViewContextMenuController::ShowContextMenuForView( | |
| 465 views::View* source, | |
| 466 const gfx::Point& point, | |
| 467 ui::MenuSourceType source_type) { | |
| 468 NotificationView* view = static_cast<NotificationView*>(source); | |
| 469 scoped_ptr<ui::MenuModel> menu_model( | |
| 470 tray_->CreateMenuModelForNotification(view->notification_id())); | |
| 471 if (!menu_model.get() || menu_model->GetItemCount() == 0) | |
| 472 return; | |
| 473 | |
| 474 views::MenuRunner menu_runner(menu_model.get()); | |
| 475 | |
| 476 ignore_result(menu_runner.RunMenuAt( | |
| 477 source->GetWidget()->GetTopLevelWidget(), | |
| 478 NULL, | |
| 479 gfx::Rect(point, gfx::Size()), | |
| 480 views::MenuItemView::TOPRIGHT, | |
| 481 source_type, | |
| 482 views::MenuRunner::HAS_MNEMONICS)); | |
| 483 } | |
| 484 | |
| 436 // NotificationView //////////////////////////////////////////////////////////// | 485 // NotificationView //////////////////////////////////////////////////////////// |
| 437 | 486 |
| 438 // static | 487 // static |
| 439 NotificationView* NotificationView::Create(const Notification& notification, | 488 NotificationView* NotificationView::Create(const Notification& notification, |
| 440 MessageCenter* message_center, | 489 MessageCenter* message_center, |
| 441 MessageCenterTray* tray, | 490 MessageCenterTray* tray, |
| 442 bool expanded, | 491 bool expanded, |
| 443 bool top_level) { | 492 bool top_level) { |
| 444 switch (notification.type()) { | 493 switch (notification.type()) { |
| 445 case NOTIFICATION_TYPE_BASE_FORMAT: | 494 case NOTIFICATION_TYPE_BASE_FORMAT: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 470 #endif | 519 #endif |
| 471 | 520 |
| 472 notification_view->CreateShadowBorder(); | 521 notification_view->CreateShadowBorder(); |
| 473 return notification_view; | 522 return notification_view; |
| 474 } | 523 } |
| 475 | 524 |
| 476 NotificationView::NotificationView(const Notification& notification, | 525 NotificationView::NotificationView(const Notification& notification, |
| 477 MessageCenter* message_center, | 526 MessageCenter* message_center, |
| 478 MessageCenterTray* tray, | 527 MessageCenterTray* tray, |
| 479 bool expanded) | 528 bool expanded) |
| 480 : MessageView(notification.display_source()), | 529 : message_center_(message_center), |
| 481 message_center_(message_center), | |
| 482 tray_(tray), | |
| 483 notification_id_(notification.id()), | 530 notification_id_(notification.id()), |
| 484 notifier_id_(notification.notifier_id()), | 531 notifier_id_(notification.notifier_id()), |
| 485 clickable_(notification.clickable()), | 532 clickable_(notification.clickable()), |
| 486 is_expanded_(expanded) { | 533 is_expanded_(expanded), |
| 534 context_menu_controller_( | |
| 535 new NotificationViewContextMenuController(tray)) { | |
|
stevenjb
2013/12/12 21:19:46
context_menu_controller_ is a View member so it sh
| |
| 536 set_context_menu_controller(context_menu_controller_.get()); | |
|
stevenjb
2013/12/12 21:19:46
This should be:
set_context_menu_controller(new No
| |
| 537 | |
| 487 std::vector<string16> accessible_lines; | 538 std::vector<string16> accessible_lines; |
| 488 | 539 |
| 489 // Create the opaque background that's above the view's shadow. | 540 // Create the opaque background that's above the view's shadow. |
| 490 background_view_ = new views::View(); | 541 background_view_ = new views::View(); |
| 491 background_view_->set_background(MakeBackground()); | 542 background_view_->set_background(MakeBackground()); |
| 492 | 543 |
| 493 // Create the top_view_, which collects into a vertical box all content | 544 // Create the top_view_, which collects into a vertical box all content |
| 494 // at the top of the notification (to the right of the icon) except for the | 545 // at the top of the notification (to the right of the icon) except for the |
| 495 // close button. | 546 // close button. |
| 496 top_view_ = new views::View(); | 547 top_view_ = new views::View(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 } | 852 } |
| 802 | 853 |
| 803 void NotificationView::ClickOnNotification() { | 854 void NotificationView::ClickOnNotification() { |
| 804 message_center_->ClickOnNotification(notification_id_); | 855 message_center_->ClickOnNotification(notification_id_); |
| 805 } | 856 } |
| 806 | 857 |
| 807 void NotificationView::RemoveNotification(bool by_user) { | 858 void NotificationView::RemoveNotification(bool by_user) { |
| 808 message_center_->RemoveNotification(notification_id_, by_user); | 859 message_center_->RemoveNotification(notification_id_, by_user); |
| 809 } | 860 } |
| 810 | 861 |
| 811 void NotificationView::DisableNotificationsFromThisSource() { | |
| 812 message_center_->DisableNotificationsByNotifier(notifier_id_); | |
| 813 } | |
| 814 | |
| 815 void NotificationView::ShowNotifierSettingsBubble() { | |
| 816 tray_->ShowNotifierSettingsBubble(); | |
| 817 } | |
| 818 | |
| 819 bool NotificationView::IsExpansionNeeded(int width) { | 862 bool NotificationView::IsExpansionNeeded(int width) { |
| 820 return (!is_expanded_ && | 863 return (!is_expanded_ && |
| 821 (image_view_ || | 864 (image_view_ || |
| 822 item_views_.size() || | 865 item_views_.size() || |
| 823 IsMessageExpansionNeeded(width))); | 866 IsMessageExpansionNeeded(width))); |
| 824 } | 867 } |
| 825 | 868 |
| 826 bool NotificationView::IsMessageExpansionNeeded(int width) { | 869 bool NotificationView::IsMessageExpansionNeeded(int width) { |
| 827 int current = GetMessageLines(width, GetMessageLineLimit(width)); | 870 int current = GetMessageLines(width, GetMessageLineLimit(width)); |
| 828 int expanded = GetMessageLines(width, | 871 int expanded = GetMessageLines(width, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 853 return message_view_ ? | 896 return message_view_ ? |
| 854 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 897 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
| 855 } | 898 } |
| 856 | 899 |
| 857 int NotificationView::GetMessageHeight(int width, int limit) { | 900 int NotificationView::GetMessageHeight(int width, int limit) { |
| 858 return message_view_ ? | 901 return message_view_ ? |
| 859 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 902 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 860 } | 903 } |
| 861 | 904 |
| 862 } // namespace message_center | 905 } // namespace message_center |
| OLD | NEW |