| 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" |
| 11 #include "grit/ui_strings.h" | 11 #include "grit/ui_strings.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/layout.h" | 13 #include "ui/base/layout.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
| 18 #include "ui/gfx/text_elider.h" | 18 #include "ui/gfx/text_elider.h" |
| 19 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
| 20 #include "ui/message_center/message_center_style.h" | 20 #include "ui/message_center/message_center_style.h" |
| 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_util.h" | 23 #include "ui/message_center/message_center_util.h" |
| 23 #include "ui/message_center/notification.h" | 24 #include "ui/message_center/notification.h" |
| 24 #include "ui/message_center/notification_types.h" | 25 #include "ui/message_center/notification_types.h" |
| 25 #include "ui/message_center/views/bounded_label.h" | 26 #include "ui/message_center/views/bounded_label.h" |
| 26 #include "ui/message_center/views/padded_button.h" | 27 #include "ui/message_center/views/padded_button.h" |
| 27 #include "ui/native_theme/native_theme.h" | 28 #include "ui/native_theme/native_theme.h" |
| 28 #include "ui/views/controls/button/image_button.h" | 29 #include "ui/views/controls/button/image_button.h" |
| 29 #include "ui/views/controls/image_view.h" | 30 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| 31 #include "ui/views/controls/progress_bar.h" | 32 #include "ui/views/controls/progress_bar.h" |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 414 } |
| 414 } | 415 } |
| 415 | 416 |
| 416 } // namespace | 417 } // namespace |
| 417 | 418 |
| 418 namespace message_center { | 419 namespace message_center { |
| 419 | 420 |
| 420 // NotificationView //////////////////////////////////////////////////////////// | 421 // NotificationView //////////////////////////////////////////////////////////// |
| 421 | 422 |
| 422 // static | 423 // static |
| 423 MessageView* NotificationView::Create(const Notification& notification, | 424 NotificationView* NotificationView::Create(const Notification& notification, |
| 424 MessageCenter* message_center, | 425 MessageCenter* message_center, |
| 425 MessageCenterTray* tray, | 426 MessageCenterTray* tray, |
| 426 bool expanded, | 427 bool expanded, |
| 427 bool top_level) { | 428 bool top_level) { |
| 428 switch (notification.type()) { | 429 switch (notification.type()) { |
| 429 case NOTIFICATION_TYPE_BASE_FORMAT: | 430 case NOTIFICATION_TYPE_BASE_FORMAT: |
| 430 case NOTIFICATION_TYPE_IMAGE: | 431 case NOTIFICATION_TYPE_IMAGE: |
| 431 case NOTIFICATION_TYPE_MULTIPLE: | 432 case NOTIFICATION_TYPE_MULTIPLE: |
| 432 case NOTIFICATION_TYPE_SIMPLE: | 433 case NOTIFICATION_TYPE_SIMPLE: |
| 433 case NOTIFICATION_TYPE_PROGRESS: | 434 case NOTIFICATION_TYPE_PROGRESS: |
| 434 break; | 435 break; |
| 435 default: | 436 default: |
| 436 // If the caller asks for an unrecognized kind of view (entirely possible | 437 // If the caller asks for an unrecognized kind of view (entirely possible |
| 437 // if an application is running on an older version of this code that | 438 // if an application is running on an older version of this code that |
| 438 // doesn't have the requested kind of notification template), we'll fall | 439 // doesn't have the requested kind of notification template), we'll fall |
| 439 // back to a notification instance that will provide at least basic | 440 // back to a notification instance that will provide at least basic |
| 440 // functionality. | 441 // functionality. |
| 441 LOG(WARNING) << "Unable to fulfill request for unrecognized " | 442 LOG(WARNING) << "Unable to fulfill request for unrecognized " |
| 442 << "notification type " << notification.type() << ". " | 443 << "notification type " << notification.type() << ". " |
| 443 << "Falling back to simple notification type."; | 444 << "Falling back to simple notification type."; |
| 444 } | 445 } |
| 445 | 446 |
| 446 // Currently all roads lead to the generic NotificationView. | 447 // Currently all roads lead to the generic NotificationView. |
| 447 MessageView* notification_view = | 448 NotificationView* notification_view = |
| 448 new NotificationView(notification, message_center, tray, expanded); | 449 new NotificationView(notification, message_center, tray, expanded); |
| 449 | 450 |
| 450 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 451 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 451 // Don't create shadows for notification toasts on linux wih aura. | 452 // Don't create shadows for notification toasts on linux wih aura. |
| 452 if (top_level) | 453 if (top_level) |
| 453 return notification_view; | 454 return notification_view; |
| 454 #endif | 455 #endif |
| 455 | 456 |
| 456 notification_view->CreateShadowBorder(); | 457 notification_view->CreateShadowBorder(); |
| 457 return notification_view; | 458 return notification_view; |
| 458 } | 459 } |
| 459 | 460 |
| 460 NotificationView::NotificationView(const Notification& notification, | 461 NotificationView::NotificationView(const Notification& notification, |
| 461 MessageCenter* message_center, | 462 MessageCenter* message_center, |
| 462 MessageCenterTray* tray, | 463 MessageCenterTray* tray, |
| 463 bool expanded) | 464 bool expanded) |
| 464 : MessageView(notification, message_center, tray), | 465 : MessageView(notification.display_source()), |
| 466 message_center_(message_center), |
| 467 tray_(tray), |
| 468 notification_id_(notification.id()), |
| 469 notifier_id_(notification.notifier_id()), |
| 465 clickable_(notification.clickable()), | 470 clickable_(notification.clickable()), |
| 466 is_expanded_(expanded) { | 471 is_expanded_(expanded) { |
| 467 std::vector<string16> accessible_lines; | 472 std::vector<string16> accessible_lines; |
| 468 | 473 |
| 469 // Create the opaque background that's above the view's shadow. | 474 // Create the opaque background that's above the view's shadow. |
| 470 background_view_ = new views::View(); | 475 background_view_ = new views::View(); |
| 471 background_view_->set_background(MakeBackground()); | 476 background_view_->set_background(MakeBackground()); |
| 472 | 477 |
| 473 // Create the top_view_, which collects into a vertical box all content | 478 // Create the top_view_, which collects into a vertical box all content |
| 474 // at the top of the notification (to the right of the icon) except for the | 479 // at the top of the notification (to the right of the icon) except for the |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 gfx::Point point_in_child = point; | 737 gfx::Point point_in_child = point; |
| 733 ConvertPointToTarget(this, buttons[i], &point_in_child); | 738 ConvertPointToTarget(this, buttons[i], &point_in_child); |
| 734 if (buttons[i]->HitTestPoint(point_in_child)) | 739 if (buttons[i]->HitTestPoint(point_in_child)) |
| 735 return buttons[i]->GetEventHandlerForPoint(point_in_child); | 740 return buttons[i]->GetEventHandlerForPoint(point_in_child); |
| 736 } | 741 } |
| 737 | 742 |
| 738 return this; | 743 return this; |
| 739 } | 744 } |
| 740 | 745 |
| 741 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { | 746 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { |
| 742 if (!clickable_ || !message_center()->HasClickedListener(notification_id())) | 747 if (!clickable_ || !message_center_->HasClickedListener(notification_id_)) |
| 743 return views::View::GetCursor(event); | 748 return views::View::GetCursor(event); |
| 744 | 749 |
| 745 #if defined(USE_AURA) | 750 #if defined(USE_AURA) |
| 746 return ui::kCursorHand; | 751 return ui::kCursorHand; |
| 747 #elif defined(OS_WIN) | 752 #elif defined(OS_WIN) |
| 748 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); | 753 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); |
| 749 return g_hand_cursor; | 754 return g_hand_cursor; |
| 750 #endif | 755 #endif |
| 751 } | 756 } |
| 752 | 757 |
| 753 void NotificationView::ButtonPressed(views::Button* sender, | 758 void NotificationView::ButtonPressed(views::Button* sender, |
| 754 const ui::Event& event) { | 759 const ui::Event& event) { |
| 755 // See if the button pressed was an action button. | 760 // See if the button pressed was an action button. |
| 756 for (size_t i = 0; i < action_buttons_.size(); ++i) { | 761 for (size_t i = 0; i < action_buttons_.size(); ++i) { |
| 757 if (sender == action_buttons_[i]) { | 762 if (sender == action_buttons_[i]) { |
| 758 message_center()->ClickOnNotificationButton(notification_id(), i); | 763 message_center_->ClickOnNotificationButton(notification_id_, i); |
| 759 return; | 764 return; |
| 760 } | 765 } |
| 761 } | 766 } |
| 762 | 767 |
| 763 // Adjust notification subviews for expansion. | 768 // Adjust notification subviews for expansion. |
| 764 if (sender == expand_button_) { | 769 if (sender == expand_button_) { |
| 765 if (message_view_ && item_views_.size()) | 770 if (message_view_ && item_views_.size()) |
| 766 message_view_->SetVisible(false); | 771 message_view_->SetVisible(false); |
| 767 for (size_t i = 0; i < item_views_.size(); ++i) | 772 for (size_t i = 0; i < item_views_.size(); ++i) |
| 768 item_views_[i]->SetVisible(true); | 773 item_views_[i]->SetVisible(true); |
| 769 if (image_view_) | 774 if (image_view_) |
| 770 image_view_->SetVisible(true); | 775 image_view_->SetVisible(true); |
| 771 | 776 |
| 772 is_expanded_ = true; | 777 is_expanded_ = true; |
| 773 message_center()->ExpandNotification(notification_id()); | 778 message_center_->ExpandNotification(notification_id_); |
| 774 return; | 779 return; |
| 775 } | 780 } |
| 776 | 781 |
| 777 // Let the superclass handled anything other than action buttons. | 782 // Let the superclass handled anything other than action buttons. |
| 778 // Warning: This may cause the NotificationView itself to be deleted, | 783 // Warning: This may cause the NotificationView itself to be deleted, |
| 779 // so don't do anything afterwards. | 784 // so don't do anything afterwards. |
| 780 MessageView::ButtonPressed(sender, event); | 785 MessageView::ButtonPressed(sender, event); |
| 781 } | 786 } |
| 782 | 787 |
| 788 void NotificationView::ClickOnNotification() { |
| 789 message_center_->ClickOnNotification(notification_id_); |
| 790 } |
| 791 |
| 792 void NotificationView::RemoveNotification(bool by_user) { |
| 793 message_center_->RemoveNotification(notification_id_, by_user); |
| 794 } |
| 795 |
| 796 void NotificationView::DisableNotificationsFromThisSource() { |
| 797 message_center_->DisableNotificationsByNotifier(notifier_id_); |
| 798 } |
| 799 |
| 800 void NotificationView::ShowNotifierSettingsBubble() { |
| 801 tray_->ShowNotifierSettingsBubble(); |
| 802 } |
| 803 |
| 783 bool NotificationView::IsExpansionNeeded(int width) { | 804 bool NotificationView::IsExpansionNeeded(int width) { |
| 784 return (!is_expanded_ && | 805 return (!is_expanded_ && |
| 785 (image_view_ || | 806 (image_view_ || |
| 786 item_views_.size() || | 807 item_views_.size() || |
| 787 IsMessageExpansionNeeded(width))); | 808 IsMessageExpansionNeeded(width))); |
| 788 } | 809 } |
| 789 | 810 |
| 790 bool NotificationView::IsMessageExpansionNeeded(int width) { | 811 bool NotificationView::IsMessageExpansionNeeded(int width) { |
| 791 int current = GetMessageLines(width, GetMessageLineLimit(width)); | 812 int current = GetMessageLines(width, GetMessageLineLimit(width)); |
| 792 int expanded = GetMessageLines(width, | 813 int expanded = GetMessageLines(width, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 817 return message_view_ ? | 838 return message_view_ ? |
| 818 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 839 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
| 819 } | 840 } |
| 820 | 841 |
| 821 int NotificationView::GetMessageHeight(int width, int limit) { | 842 int NotificationView::GetMessageHeight(int width, int limit) { |
| 822 return message_view_ ? | 843 return message_view_ ? |
| 823 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 844 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 824 } | 845 } |
| 825 | 846 |
| 826 } // namespace message_center | 847 } // namespace message_center |
| OLD | NEW |