diff options
Diffstat (limited to 'ui/message_center')
-rw-r--r-- | ui/message_center/base_format_view.cc | 34 | ||||
-rw-r--r-- | ui/message_center/base_format_view.h | 4 | ||||
-rw-r--r-- | ui/message_center/message_center.cc | 9 | ||||
-rw-r--r-- | ui/message_center/message_center.h | 21 | ||||
-rw-r--r-- | ui/message_center/notification_list.cc | 9 | ||||
-rw-r--r-- | ui/message_center/notification_list.h | 8 |
6 files changed, 54 insertions, 31 deletions
diff --git a/ui/message_center/base_format_view.cc b/ui/message_center/base_format_view.cc index 027c724..f8ce583 100644 --- a/ui/message_center/base_format_view.cc +++ b/ui/message_center/base_format_view.cc @@ -76,19 +76,17 @@ void BaseFormatView::SetUpView() { // TODO(miket): unreadCount - views::LabelButton* button_one = NULL; if (notification_.button_one_title.length() != 0) { - button_one = new views::LabelButton( + button_one_ = new views::LabelButton( this, notification_.button_one_title); - button_one->SetHorizontalAlignment(gfx::ALIGN_CENTER); - button_one->SetNativeTheme(true); + button_one_->SetHorizontalAlignment(gfx::ALIGN_CENTER); + button_one_->SetNativeTheme(true); } - views::LabelButton* button_two = NULL; - if (button_one && notification_.button_two_title.length() != 0) { - button_two = new views::LabelButton( + if (button_one_ && notification_.button_two_title.length() != 0) { + button_two_ = new views::LabelButton( this, notification_.button_two_title); - button_two->SetHorizontalAlignment(gfx::ALIGN_CENTER); - button_two->SetNativeTheme(true); + button_two_->SetHorizontalAlignment(gfx::ALIGN_CENTER); + button_two_->SetNativeTheme(true); } views::Label* expanded_message = new views::Label( @@ -168,9 +166,9 @@ void BaseFormatView::SetUpView() { // Row 3: Continuation of big icon, two buttons, secondary icon. layout->StartRow(0,0); layout->SkipColumns(1); - if (button_one) { - layout->AddView(button_one, 1, 1); - layout->AddView(button_two, 1, 1); + if (button_one_) { + layout->AddView(button_one_, 1, 1); + layout->AddView(button_two_, 1, 1); } else { layout->SkipColumns(3); // two buttons plus padding } @@ -189,8 +187,16 @@ void BaseFormatView::SetUpView() { void BaseFormatView::ButtonPressed(views::Button* sender, const ui::Event& event) { - // TODO(miket): propagate to caller. - MessageView::ButtonPressed(sender, event); + // TODO(miket): consider changing the _one, _two etc. widgets to an array or + // map so that we can move this behavior to the superclass. It seems like + // something we wouldn't want to keep recoding for each subclass. + if (sender == button_one_) { + list_delegate_->OnButtonClicked(notification_.id, 0); + } else if (sender == button_two_) { + list_delegate_->OnButtonClicked(notification_.id, 1); + } else { + MessageView::ButtonPressed(sender, event); + } } } // namespace message_center diff --git a/ui/message_center/base_format_view.h b/ui/message_center/base_format_view.h index 7f3f15a..fc04f25 100644 --- a/ui/message_center/base_format_view.h +++ b/ui/message_center/base_format_view.h @@ -10,6 +10,7 @@ namespace views { class ImageView; +class LabelButton; } namespace message_center { @@ -31,6 +32,9 @@ class BaseFormatView : public MessageView { protected: BaseFormatView(); + views::LabelButton* button_one_; + views::LabelButton* button_two_; + DISALLOW_COPY_AND_ASSIGN(BaseFormatView); }; diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc index 3515f7d..a7be4b3 100644 --- a/ui/message_center/message_center.cc +++ b/ui/message_center/message_center.cc @@ -135,8 +135,17 @@ void MessageCenter::OnQuietModeChanged(bool quiet_mode) { host_->MessageCenterChanged(true); } +void MessageCenter::OnButtonClicked(const std::string& id, int button_index) { + if (delegate_) + delegate_->OnButtonClicked(id, button_index); +} + NotificationList* MessageCenter::GetNotificationList() { return notification_list_.get(); } +void MessageCenter::Delegate::OnButtonClicked(const std::string& id, + int button_index) { +} + } // namespace message_center diff --git a/ui/message_center/message_center.h b/ui/message_center/message_center.h index 73f6269..5f5bb4f 100644 --- a/ui/message_center/message_center.h +++ b/ui/message_center/message_center.h @@ -41,21 +41,30 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate { public: // Called when the notification associated with |notification_id| is // removed (i.e. closed by the user). - virtual void NotificationRemoved(const std::string& notifcation_id) = 0; + virtual void NotificationRemoved(const std::string& notification_id) = 0; // Request to disable the extension associated with |notification_id|. - virtual void DisableExtension(const std::string& notifcation_id) = 0; + virtual void DisableExtension(const std::string& notification_id) = 0; // Request to disable notifications from the source of |notification_id|. virtual void DisableNotificationsFromSource( - const std::string& notifcation_id) = 0; + const std::string& notification_id) = 0; // Request to show the notification settings (|notification_id| is used // to identify the requesting browser context). - virtual void ShowSettings(const std::string& notifcation_id) = 0; + virtual void ShowSettings(const std::string& notification_id) = 0; // Called when the notification body is clicked on. - virtual void OnClicked(const std::string& notifcation_id) = 0; + virtual void OnClicked(const std::string& notification_id) = 0; + + // Called when a button in a notification is clicked. |button_index| + // indicates which button was clicked, zero-indexed (button one is 0, + // button two is 1). + // + // TODO(miket): consider providing default implementations for the pure + // virtuals above, to avoid changing so many files in disparate parts of + // the codebase each time we enhance this interface. + virtual void OnButtonClicked(const std::string& id, int button_index); protected: virtual ~Delegate() {} @@ -117,6 +126,8 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate { virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; virtual void OnNotificationClicked(const std::string& id) OVERRIDE; virtual void OnQuietModeChanged(bool quiet_mode) OVERRIDE; + virtual void OnButtonClicked(const std::string& id, int button_index) + OVERRIDE; virtual NotificationList* GetNotificationList() OVERRIDE; private: diff --git a/ui/message_center/notification_list.cc b/ui/message_center/notification_list.cc index 39d7431..1fa388f 100644 --- a/ui/message_center/notification_list.cc +++ b/ui/message_center/notification_list.cc @@ -81,9 +81,6 @@ void NotificationList::UnpackOptionalFields( if (!optional_fields) return; - if (optional_fields->HasKey(ui::notifications::kMessageIntentKey)) - optional_fields->GetString(ui::notifications::kMessageIntentKey, - ¬ification.message_intent); if (optional_fields->HasKey(ui::notifications::kPriorityKey)) optional_fields->GetInteger(ui::notifications::kPriorityKey, ¬ification.priority); @@ -102,15 +99,9 @@ void NotificationList::UnpackOptionalFields( if (optional_fields->HasKey(ui::notifications::kButtonOneTitleKey)) optional_fields->GetString(ui::notifications::kButtonOneTitleKey, ¬ification.button_one_title); - if (optional_fields->HasKey(ui::notifications::kButtonOneIntentKey)) - optional_fields->GetString(ui::notifications::kButtonOneIntentKey, - ¬ification.button_one_intent); if (optional_fields->HasKey(ui::notifications::kButtonTwoTitleKey)) optional_fields->GetString(ui::notifications::kButtonTwoTitleKey, ¬ification.button_two_title); - if (optional_fields->HasKey(ui::notifications::kButtonTwoIntentKey)) - optional_fields->GetString(ui::notifications::kButtonTwoIntentKey, - ¬ification.button_two_intent); if (optional_fields->HasKey(ui::notifications::kExpandedMessageKey)) optional_fields->GetString(ui::notifications::kExpandedMessageKey, ¬ification.expanded_message); diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h index ab4406c..6429966 100644 --- a/ui/message_center/notification_list.h +++ b/ui/message_center/notification_list.h @@ -45,15 +45,12 @@ class MESSAGE_CENTER_EXPORT NotificationList { std::string extension_id; // Begin unpacked values from optional_fields - string16 message_intent; int priority; base::Time timestamp; gfx::ImageSkia second_image; int unread_count; string16 button_one_title; - string16 button_one_intent; string16 button_two_title; - string16 button_two_intent; string16 expanded_message; string16 image_url; std::vector<NotificationItem> items; @@ -88,6 +85,11 @@ class MESSAGE_CENTER_EXPORT NotificationList { // Called when the quiet mode status has been changed. virtual void OnQuietModeChanged(bool quiet_mode) = 0; + // Called when a button in a notification is clicked. |button_index| + // indicates which button was clicked, zero-indexed (button one is 0, + // button two is 1). + virtual void OnButtonClicked(const std::string& id, int button_index) = 0; + // Returns the list of notifications to display. virtual NotificationList* GetNotificationList() = 0; }; |