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

Side by Side Diff: ash/system/web_notification/web_notification_tray.cc

Issue 10855113: Show extension settings for extension notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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 "ash/system/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include "ash/system/status_area_widget.h" 7 #include "ash/system/status_area_widget.h"
8 #include "ash/system/tray/system_tray.h" 8 #include "ash/system/tray/system_tray.h"
9 #include "ash/system/tray/tray_bubble_view.h" 9 #include "ash/system/tray/tray_bubble_view.h"
10 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (iter == notifications_.end()) 155 if (iter == notifications_.end())
156 return false; 156 return false;
157 EraseNotification(iter); 157 EraseNotification(iter);
158 return true; 158 return true;
159 } 159 }
160 160
161 void RemoveAllNotifications() { 161 void RemoveAllNotifications() {
162 notifications_.clear(); 162 notifications_.clear();
163 } 163 }
164 164
165 void RemoveNotificationsBySource(const std::string& id) { 165 void SendRemoveNotificationsBySource(WebNotificationTray* tray,
166 const std::string& id) {
166 Notifications::iterator source_iter = GetNotification(id); 167 Notifications::iterator source_iter = GetNotification(id);
167 if (source_iter == notifications_.end()) 168 if (source_iter == notifications_.end())
168 return; 169 return;
169 string16 display_source = source_iter->display_source; 170 string16 display_source = source_iter->display_source;
170 for (Notifications::iterator loopiter = notifications_.begin(); 171 for (Notifications::iterator loopiter = notifications_.begin();
171 loopiter != notifications_.end(); ) { 172 loopiter != notifications_.end(); ) {
172 Notifications::iterator curiter = loopiter++; 173 Notifications::iterator curiter = loopiter++;
173 if (curiter->display_source == display_source) 174 if (curiter->display_source == display_source)
174 EraseNotification(curiter); 175 tray->SendRemoveNotification(curiter->id);
175 } 176 }
176 } 177 }
177 178
178 void RemoveNotificationsByExtension(const std::string& id) { 179 void SendRemoveNotificationsByExtension(WebNotificationTray* tray,
180 const std::string& id) {
179 Notifications::iterator source_iter = GetNotification(id); 181 Notifications::iterator source_iter = GetNotification(id);
180 if (source_iter == notifications_.end()) 182 if (source_iter == notifications_.end())
181 return; 183 return;
182 std::string extension_id = source_iter->extension_id; 184 std::string extension_id = source_iter->extension_id;
183 for (Notifications::iterator loopiter = notifications_.begin(); 185 for (Notifications::iterator loopiter = notifications_.begin();
184 loopiter != notifications_.end(); ) { 186 loopiter != notifications_.end(); ) {
185 Notifications::iterator curiter = loopiter++; 187 Notifications::iterator curiter = loopiter++;
186 if (curiter->extension_id == extension_id) 188 if (curiter->extension_id == extension_id)
187 EraseNotification(curiter); 189 tray->SendRemoveNotification(curiter->id);
188 } 190 }
189 } 191 }
190 192
191 bool SetNotificationImage(const std::string& id, 193 bool SetNotificationImage(const std::string& id,
192 const gfx::ImageSkia& image) { 194 const gfx::ImageSkia& image) {
193 Notifications::iterator iter = GetNotification(id); 195 Notifications::iterator iter = GetNotification(id);
194 if (iter == notifications_.end()) 196 if (iter == notifications_.end())
195 return false; 197 return false;
196 iter->image = image; 198 iter->image = image;
197 return true; 199 return true;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 const ui::Event& event) OVERRIDE { 450 const ui::Event& event) OVERRIDE {
449 if (sender == close_button_) 451 if (sender == close_button_)
450 tray_->SendRemoveNotification(notification_.id); 452 tray_->SendRemoveNotification(notification_.id);
451 } 453 }
452 454
453 // Overridden from MenuButtonListener. 455 // Overridden from MenuButtonListener.
454 virtual void OnMenuButtonClicked( 456 virtual void OnMenuButtonClicked(
455 View* source, const gfx::Point& point) OVERRIDE { 457 View* source, const gfx::Point& point) OVERRIDE {
456 if (source != menu_button_) 458 if (source != menu_button_)
457 return; 459 return;
460 tray_->set_menu_open(true);
sadrul 2012/08/13 22:09:08 This feels like a hack. The app-list controller do
stevenjb 2012/08/14 00:48:37 Sure. I'm not a huge fan of using globals, but at
458 WebNotificationMenuModel menu_model(tray_, notification_); 461 WebNotificationMenuModel menu_model(tray_, notification_);
459 views::MenuModelAdapter menu_model_adapter(&menu_model); 462 views::MenuModelAdapter menu_model_adapter(&menu_model);
460 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); 463 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu());
461 464
462 gfx::Point screen_location; 465 gfx::Point screen_location;
463 views::View::ConvertPointToScreen(menu_button_, &screen_location); 466 views::View::ConvertPointToScreen(menu_button_, &screen_location);
464 ignore_result(menu_runner.RunMenuAt( 467 ignore_result(menu_runner.RunMenuAt(
465 source->GetWidget()->GetTopLevelWidget(), 468 source->GetWidget()->GetTopLevelWidget(),
466 menu_button_, 469 menu_button_,
467 gfx::Rect(screen_location, menu_button_->size()), 470 gfx::Rect(screen_location, menu_button_->size()),
468 views::MenuItemView::TOPRIGHT, 471 views::MenuItemView::TOPRIGHT,
469 views::MenuRunner::HAS_MNEMONICS)); 472 views::MenuRunner::HAS_MNEMONICS));
473 tray_->set_menu_open(false);
470 } 474 }
471 475
472 private: 476 private:
473 WebNotificationTray* tray_; 477 WebNotificationTray* tray_;
474 WebNotification notification_; 478 WebNotification notification_;
475 views::ImageView* icon_; 479 views::ImageView* icon_;
476 views::MenuButton* menu_button_; 480 views::MenuButton* menu_button_;
477 views::ImageButton* close_button_; 481 views::ImageButton* close_button_;
478 482
479 DISALLOW_COPY_AND_ASSIGN(WebNotificationView); 483 DISALLOW_COPY_AND_ASSIGN(WebNotificationView);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 virtual void OnMouseEnteredView() OVERRIDE { 773 virtual void OnMouseEnteredView() OVERRIDE {
770 StopAutoCloseTimer(); 774 StopAutoCloseTimer();
771 } 775 }
772 776
773 virtual void OnMouseExitedView() OVERRIDE { 777 virtual void OnMouseExitedView() OVERRIDE {
774 StartAutoCloseTimer(); 778 StartAutoCloseTimer();
775 } 779 }
776 780
777 virtual void OnClickedOutsideView() OVERRIDE { 781 virtual void OnClickedOutsideView() OVERRIDE {
778 // May delete |this|. 782 // May delete |this|.
779 tray_->HideMessageCenterBubble(); 783 if (!tray_->menu_open())
784 tray_->HideMessageCenterBubble();
780 } 785 }
781 786
782 // Overridden from views::WidgetObserver: 787 // Overridden from views::WidgetObserver:
783 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { 788 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE {
784 CHECK_EQ(bubble_widget_, widget); 789 CHECK_EQ(bubble_widget_, widget);
785 bubble_widget_ = NULL; 790 bubble_widget_ = NULL;
786 tray_->HideBubble(this); // Will destroy |this|. 791 tray_->HideBubble(this); // Will destroy |this|.
787 } 792 }
788 793
789 private: 794 private:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 826
822 DISALLOW_COPY_AND_ASSIGN(Bubble); 827 DISALLOW_COPY_AND_ASSIGN(Bubble);
823 }; 828 };
824 829
825 WebNotificationTray::WebNotificationTray( 830 WebNotificationTray::WebNotificationTray(
826 internal::StatusAreaWidget* status_area_widget) 831 internal::StatusAreaWidget* status_area_widget)
827 : internal::TrayBackgroundView(status_area_widget), 832 : internal::TrayBackgroundView(status_area_widget),
828 notification_list_(new WebNotificationList()), 833 notification_list_(new WebNotificationList()),
829 count_label_(NULL), 834 count_label_(NULL),
830 delegate_(NULL), 835 delegate_(NULL),
831 show_message_center_on_unlock_(false) { 836 show_message_center_on_unlock_(false),
837 menu_open_(false) {
832 count_label_ = new views::Label(UTF8ToUTF16("0")); 838 count_label_ = new views::Label(UTF8ToUTF16("0"));
833 internal::SetupLabelForTray(count_label_); 839 internal::SetupLabelForTray(count_label_);
834 gfx::Font font = count_label_->font(); 840 gfx::Font font = count_label_->font();
835 count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); 841 count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD));
836 count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); 842 count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
837 count_label_->SetEnabledColor(kMessageCountDimmedColor); 843 count_label_->SetEnabledColor(kMessageCountDimmedColor);
838 844
839 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); 845 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight));
840 tray_container()->AddChildView(count_label_); 846 tray_container()->AddChildView(count_label_);
841 847
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 std::string notification_id = curiter->id; 993 std::string notification_id = curiter->id;
988 // May call RemoveNotification and erase curiter. 994 // May call RemoveNotification and erase curiter.
989 delegate_->NotificationRemoved(notification_id); 995 delegate_->NotificationRemoved(notification_id);
990 } 996 }
991 } 997 }
992 } 998 }
993 999
994 // When we disable notifications, we remove any existing matching 1000 // When we disable notifications, we remove any existing matching
995 // notifications to avoid adding complicated UI to re-enable the source. 1001 // notifications to avoid adding complicated UI to re-enable the source.
996 void WebNotificationTray::DisableByExtension(const std::string& id) { 1002 void WebNotificationTray::DisableByExtension(const std::string& id) {
997 // Will call SendRemoveNotification for each matching notification.
998 notification_list_->RemoveNotificationsByExtension(id);
999 if (delegate_) 1003 if (delegate_)
1000 delegate_->DisableExtension(id); 1004 delegate_->DisableExtension(id);
1005 // Will call SendRemoveNotification for each matching notification.
1006 notification_list_->SendRemoveNotificationsByExtension(this, id);
1001 } 1007 }
1002 1008
1003 void WebNotificationTray::DisableByUrl(const std::string& id) { 1009 void WebNotificationTray::DisableByUrl(const std::string& id) {
1004 // Will call SendRemoveNotification for each matching notification.
1005 notification_list_->RemoveNotificationsBySource(id);
1006 if (delegate_) 1010 if (delegate_)
1007 delegate_->DisableNotificationsFromSource(id); 1011 delegate_->DisableNotificationsFromSource(id);
1012 // Will call SendRemoveNotification for each matching notification.
1013 notification_list_->SendRemoveNotificationsBySource(this, id);
1008 } 1014 }
1009 1015
1010 bool WebNotificationTray::PerformAction(const ui::Event& event) { 1016 bool WebNotificationTray::PerformAction(const ui::Event& event) {
1011 if (message_center_bubble()) 1017 if (message_center_bubble())
1012 HideMessageCenterBubble(); 1018 HideMessageCenterBubble();
1013 else 1019 else
1014 ShowMessageCenterBubble(); 1020 ShowMessageCenterBubble();
1015 return true; 1021 return true;
1016 } 1022 }
1017 1023
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 } else if (bubble == notification_bubble()) { 1069 } else if (bubble == notification_bubble()) {
1064 HideNotificationBubble(); 1070 HideNotificationBubble();
1065 } 1071 }
1066 } 1072 }
1067 1073
1068 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { 1074 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const {
1069 return notification_list_->HasNotification(id); 1075 return notification_list_->HasNotification(id);
1070 } 1076 }
1071 1077
1072 } // namespace ash 1078 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/web_notification/web_notification_tray.h ('k') | chrome/browser/ui/views/ash/balloon_collection_impl_ash.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698