summaryrefslogtreecommitdiffstats
path: root/ui/message_center
diff options
context:
space:
mode:
authormiket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-14 01:53:10 +0000
committermiket@chromium.org <miket@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-14 01:53:10 +0000
commit7af7a3ec9ffc803d7fb19048920a7102f209bfe8 (patch)
treef482753affa3dc437a2e05cc7d5a08da311ef3c5 /ui/message_center
parent61bf48eafc0f98f57036f777c253f178b8744ef0 (diff)
downloadchromium_src-7af7a3ec9ffc803d7fb19048920a7102f209bfe8.zip
chromium_src-7af7a3ec9ffc803d7fb19048920a7102f209bfe8.tar.gz
chromium_src-7af7a3ec9ffc803d7fb19048920a7102f209bfe8.tar.bz2
Plumb the ButtonPressed callback of the two buttons in BaseFormatView through to the NotificationDelegate's new ButtonClick() method.
The practical point of this CL is twofold: (1) provide a good stopping point for the larger goal of sending this new ButtonClick event to JavaScript callers, and (2) provide new useful functionality to C++ code that is interested in button-click events. 0. Remove vestigal intents fields, which we're replacing with explicit callbacks. 1. Make BaseFormatView's ButtonPressed() send a new NotificationList::Delegate::OnButtonClicked(). 2. MessageCenter passes that through to MessageCenter::Delegate::OnButtonClicked(), which has the same name as the above delegate method but is NOT directly related. 3. BalloonCollectionImplAsh looks up the specific balloon whose button was clicked, then calls the appropriate OnButtonClick() (note the change in tense). 4. chrome/browser/notifications/balloon passes the baton to the Notification that it owns, calling its ButtonClick() method. 5. The Notification's delegate handles ButtonClick(). Again, these two method share the name but are not strictly related. 6. In the case we'll eventually care about, notification_api.cc will implement a functional ButtonClick(). But for now this implementation is a stub. BUG=164249 Review URL: https://chromiumcodereview.appspot.com/11546003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r--ui/message_center/base_format_view.cc34
-rw-r--r--ui/message_center/base_format_view.h4
-rw-r--r--ui/message_center/message_center.cc9
-rw-r--r--ui/message_center/message_center.h21
-rw-r--r--ui/message_center/notification_list.cc9
-rw-r--r--ui/message_center/notification_list.h8
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,
- &notification.message_intent);
if (optional_fields->HasKey(ui::notifications::kPriorityKey))
optional_fields->GetInteger(ui::notifications::kPriorityKey,
&notification.priority);
@@ -102,15 +99,9 @@ void NotificationList::UnpackOptionalFields(
if (optional_fields->HasKey(ui::notifications::kButtonOneTitleKey))
optional_fields->GetString(ui::notifications::kButtonOneTitleKey,
&notification.button_one_title);
- if (optional_fields->HasKey(ui::notifications::kButtonOneIntentKey))
- optional_fields->GetString(ui::notifications::kButtonOneIntentKey,
- &notification.button_one_intent);
if (optional_fields->HasKey(ui::notifications::kButtonTwoTitleKey))
optional_fields->GetString(ui::notifications::kButtonTwoTitleKey,
&notification.button_two_title);
- if (optional_fields->HasKey(ui::notifications::kButtonTwoIntentKey))
- optional_fields->GetString(ui::notifications::kButtonTwoIntentKey,
- &notification.button_two_intent);
if (optional_fields->HasKey(ui::notifications::kExpandedMessageKey))
optional_fields->GetString(ui::notifications::kExpandedMessageKey,
&notification.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;
};