Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: ui/message_center/views/notification_view.cc

Issue 75133006: Move knowledge about MessageCenter out of MessageView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build break Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 MessageViewTypes NotificationView::GetType() {
789 return NOTIFICATION_VIEW;
790 }
791
792 void NotificationView::ClickOnNotification() {
793 message_center_->ClickOnNotification(notification_id_);
794 }
795
796 void NotificationView::RemoveNotification(bool by_user) {
797 message_center_->RemoveNotification(notification_id_, by_user);
798 }
799
800 void NotificationView::DisableNotificationsFromThisSource() {
801 message_center_->DisableNotificationsByNotifier(notifier_id_);
802 }
803
804 void NotificationView::ShowNotifierSettingsBubble() {
805 tray_->ShowNotifierSettingsBubble();
806 }
807
783 bool NotificationView::IsExpansionNeeded(int width) { 808 bool NotificationView::IsExpansionNeeded(int width) {
784 return (!is_expanded_ && 809 return (!is_expanded_ &&
785 (image_view_ || 810 (image_view_ ||
786 item_views_.size() || 811 item_views_.size() ||
787 IsMessageExpansionNeeded(width))); 812 IsMessageExpansionNeeded(width)));
788 } 813 }
789 814
790 bool NotificationView::IsMessageExpansionNeeded(int width) { 815 bool NotificationView::IsMessageExpansionNeeded(int width) {
791 int current = GetMessageLines(width, GetMessageLineLimit(width)); 816 int current = GetMessageLines(width, GetMessageLineLimit(width));
792 int expanded = GetMessageLines(width, 817 int expanded = GetMessageLines(width,
(...skipping 24 matching lines...) Expand all
817 return message_view_ ? 842 return message_view_ ?
818 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; 843 message_view_->GetLinesForWidthAndLimit(width, limit) : 0;
819 } 844 }
820 845
821 int NotificationView::GetMessageHeight(int width, int limit) { 846 int NotificationView::GetMessageHeight(int width, int limit) {
822 return message_view_ ? 847 return message_view_ ?
823 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 848 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
824 } 849 }
825 850
826 } // namespace message_center 851 } // namespace message_center
OLDNEW
« ui/message_center/views/message_center_view.cc ('K') | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698