summaryrefslogtreecommitdiffstats
path: root/ui/message_center
diff options
context:
space:
mode:
authordharcourt@chromium.org <dharcourt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 18:22:00 +0000
committerdharcourt@chromium.org <dharcourt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-23 18:22:00 +0000
commit8f3b534d8b783ad4af18e2e20c3d313f4dac545c (patch)
tree6cf41aaf23eef4f30dc635eb0d692b05a443d384 /ui/message_center
parent3eab344d6f336a3351f1ae4fb7a465584de5a88c (diff)
downloadchromium_src-8f3b534d8b783ad4af18e2e20c3d313f4dac545c.zip
chromium_src-8f3b534d8b783ad4af18e2e20c3d313f4dac545c.tar.gz
chromium_src-8f3b534d8b783ad4af18e2e20c3d313f4dac545c.tar.bz2
Added support for icons in image and list notification action buttons.
In addition to displaying these icons in the notification's action buttons, this change adds buttonOneIconUrl and buttonTwoIconUrl properties to the experimental.notification.ShowOptions API so applications can specify these icons. BUG=12016030 Review URL: https://chromiumcodereview.appspot.com/12042018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r--ui/message_center/message_center.cc20
-rw-r--r--ui/message_center/message_center.h20
-rw-r--r--ui/message_center/message_center_constants.cc3
-rw-r--r--ui/message_center/message_center_constants.h3
-rw-r--r--ui/message_center/notification_list.cc64
-rw-r--r--ui/message_center/notification_list.h16
-rw-r--r--ui/message_center/notification_view.cc73
7 files changed, 122 insertions, 77 deletions
diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc
index f8a7b0c..6530005 100644
--- a/ui/message_center/message_center.cc
+++ b/ui/message_center/message_center.cc
@@ -82,21 +82,23 @@ void MessageCenter::RemoveNotification(const std::string& id) {
NotifyMessageCenterChanged(false);
}
-void MessageCenter::SetNotificationPrimaryIcon(const std::string& id,
- const gfx::ImageSkia& image) {
- if (notification_list_->SetNotificationPrimaryIcon(id, image))
+void MessageCenter::SetNotificationIcon(const std::string& notification_id,
+ const gfx::ImageSkia& image) {
+ if (notification_list_->SetNotificationIcon(notification_id, image))
NotifyMessageCenterChanged(true);
}
-void MessageCenter::SetNotificationSecondaryIcon(const std::string& id,
- const gfx::ImageSkia& image) {
- if (notification_list_->SetNotificationSecondaryIcon(id, image))
+void MessageCenter::SetNotificationImage(const std::string& notification_id,
+ const gfx::ImageSkia& image) {
+ if (notification_list_->SetNotificationImage(notification_id, image))
NotifyMessageCenterChanged(true);
}
-void MessageCenter::SetNotificationImage(const std::string& id,
- const gfx::ImageSkia& image) {
- if (notification_list_->SetNotificationImage(id, image))
+void MessageCenter::SetNotificationButtonIcon(
+ const std::string& notification_id, int button_index,
+ const gfx::ImageSkia& image) {
+ if (notification_list_->SetNotificationButtonIcon(notification_id,
+ button_index, image))
NotifyMessageCenterChanged(true);
}
diff --git a/ui/message_center/message_center.h b/ui/message_center/message_center.h
index ff7eb03..f060114 100644
--- a/ui/message_center/message_center.h
+++ b/ui/message_center/message_center.h
@@ -98,10 +98,10 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
// Adds a new notification. |id| is a unique identifier, used to update or
// remove notifications. |title| and |meesage| describe the notification text.
- // Use SetNotificationPrimaryIcon and SetNotificationSecondaryIcon to set
- // images. If |extension_id| is provided then 'Disable extension' will appear
- // in a dropdown menu and the id will be used to disable notifications from
- // the extension. Otherwise if |display_source| is provided, a menu item
+ // Use SetNotificationIcon, SetNotificationImage, or SetNotificationButtonIcon
+ // to set images. If |extension_id| is provided then 'Disable extension' will
+ // appear in a dropdown menu and the id will be used to disable notifications
+ // from the extension. Otherwise if |display_source| is provided, a menu item
// showing the source and allowing notifications from that source to be
// disabled will be shown. All actual disabling is handled by the Delegate.
void AddNotification(ui::notifications::NotificationType type,
@@ -123,13 +123,15 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
// Removes an existing notification.
void RemoveNotification(const std::string& id);
- void SetNotificationPrimaryIcon(const std::string& id,
- const gfx::ImageSkia& image);
+ void SetNotificationIcon(const std::string& notification_id,
+ const gfx::ImageSkia& image);
- void SetNotificationSecondaryIcon(const std::string& id,
- const gfx::ImageSkia& image);
+ void SetNotificationImage(const std::string& notification_id,
+ const gfx::ImageSkia& image);
- void SetNotificationImage(const std::string& id, const gfx::ImageSkia& image);
+ void SetNotificationButtonIcon(const std::string& notification_id,
+ int button_index,
+ const gfx::ImageSkia& image);
NotificationList* notification_list() { return notification_list_.get(); }
diff --git a/ui/message_center/message_center_constants.cc b/ui/message_center/message_center_constants.cc
index 3352704..099b7ed 100644
--- a/ui/message_center/message_center_constants.cc
+++ b/ui/message_center/message_center_constants.cc
@@ -6,8 +6,9 @@
namespace message_center {
-const int kNotificationIconWidth = 80;
+const int kNotificationIconSize = 80;
const int kNotificationPreferredImageSize = 300;
+const int kNotificationButtonIconSize = 16;
const int kSettingsIconSize = 16;
const int kNotificationMaximumImageHeight = 300;
diff --git a/ui/message_center/message_center_constants.h b/ui/message_center/message_center_constants.h
index 77b1d02..da8128f 100644
--- a/ui/message_center/message_center_constants.h
+++ b/ui/message_center/message_center_constants.h
@@ -10,8 +10,9 @@
namespace message_center {
-MESSAGE_CENTER_EXPORT extern const int kNotificationIconWidth;
+MESSAGE_CENTER_EXPORT extern const int kNotificationIconSize;
MESSAGE_CENTER_EXPORT extern const int kNotificationPreferredImageSize;
+MESSAGE_CENTER_EXPORT extern const int kNotificationButtonIconSize;
MESSAGE_CENTER_EXPORT extern const int kSettingsIconSize;
extern const int kNotificationMaximumImageHeight;
diff --git a/ui/message_center/notification_list.cc b/ui/message_center/notification_list.cc
index fcd18e6..2d8993f 100644
--- a/ui/message_center/notification_list.cc
+++ b/ui/message_center/notification_list.cc
@@ -79,36 +79,39 @@ void NotificationList::AddNotification(
PushNotification(notification);
}
-void NotificationList::UnpackOptionalFields(
- const DictionaryValue* optional_fields, Notification* notification) {
- if (!optional_fields)
+void NotificationList::UnpackOptionalFields(const DictionaryValue* fields,
+ Notification* notification) {
+ if (!fields)
return;
- optional_fields->GetInteger(ui::notifications::kPriorityKey,
- &notification->priority);
- if (optional_fields->HasKey(ui::notifications::kTimestampKey)) {
+ fields->GetInteger(ui::notifications::kPriorityKey, &notification->priority);
+ if (fields->HasKey(ui::notifications::kTimestampKey)) {
std::string time_string;
- optional_fields->GetString(ui::notifications::kTimestampKey, &time_string);
+ fields->GetString(ui::notifications::kTimestampKey, &time_string);
base::Time::FromString(time_string.c_str(), &notification->timestamp);
}
- optional_fields->GetInteger(ui::notifications::kUnreadCountKey,
- &notification->unread_count);
- if (optional_fields->HasKey(ui::notifications::kButtonOneTitleKey)) {
+ fields->GetInteger(ui::notifications::kUnreadCountKey,
+ &notification->unread_count);
+ if (fields->HasKey(ui::notifications::kButtonOneTitleKey) ||
+ fields->HasKey(ui::notifications::kButtonOneIconUrlKey)) {
string16 title;
- if (optional_fields->GetString(ui::notifications::kButtonOneTitleKey,
- &title) && !title.empty()) {
+ string16 icon;
+ if (fields->GetString(ui::notifications::kButtonOneTitleKey, &title) ||
+ fields->GetString(ui::notifications::kButtonOneIconUrlKey, &icon)) {
notification->button_titles.push_back(title);
- if (optional_fields->GetString(ui::notifications::kButtonTwoTitleKey,
- &title) && !title.empty()) {
+ notification->button_icons.push_back(gfx::ImageSkia());
+ if (fields->GetString(ui::notifications::kButtonTwoTitleKey, &title) ||
+ fields->GetString(ui::notifications::kButtonTwoIconUrlKey, &icon)) {
notification->button_titles.push_back(title);
+ notification->button_icons.push_back(gfx::ImageSkia());
}
}
}
- optional_fields->GetString(ui::notifications::kExpandedMessageKey,
- &notification->expanded_message);
- if (optional_fields->HasKey(ui::notifications::kItemsKey)) {
+ fields->GetString(ui::notifications::kExpandedMessageKey,
+ &notification->expanded_message);
+ if (fields->HasKey(ui::notifications::kItemsKey)) {
const ListValue* items;
- CHECK(optional_fields->GetList(ui::notifications::kItemsKey, &items));
+ CHECK(fields->GetList(ui::notifications::kItemsKey, &items));
for (size_t i = 0; i < items->GetSize(); ++i) {
string16 title;
string16 message;
@@ -187,31 +190,32 @@ void NotificationList::SendRemoveNotificationsByExtension(
}
}
-bool NotificationList::SetNotificationPrimaryIcon(const std::string& id,
- const gfx::ImageSkia& image) {
+bool NotificationList::SetNotificationIcon(const std::string& notification_id,
+ const gfx::ImageSkia& image) {
Notifications::iterator iter;
- if (!GetNotification(id, &iter))
+ if (!GetNotification(notification_id, &iter))
return false;
iter->primary_icon = image;
return true;
}
-bool NotificationList::SetNotificationSecondaryIcon(
- const std::string& id,
- const gfx::ImageSkia& image) {
+bool NotificationList::SetNotificationImage(const std::string& notification_id,
+ const gfx::ImageSkia& image) {
Notifications::iterator iter;
- if (!GetNotification(id, &iter))
+ if (!GetNotification(notification_id, &iter))
return false;
- iter->secondary_icon = image;
+ iter->image = image;
return true;
}
-bool NotificationList::SetNotificationImage(const std::string& id,
- const gfx::ImageSkia& image) {
+bool NotificationList::SetNotificationButtonIcon(
+ const std::string& notification_id, int button_index,
+ const gfx::ImageSkia& image) {
Notifications::iterator iter;
- if (!GetNotification(id, &iter))
+ if (!GetNotification(notification_id, &iter) ||
+ static_cast<size_t>(button_index) >= iter->button_icons.size())
return false;
- iter->image = image;
+ iter->button_icons[button_index] = image;
return true;
}
diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h
index 14bb84e..8cd6655 100644
--- a/ui/message_center/notification_list.h
+++ b/ui/message_center/notification_list.h
@@ -55,8 +55,8 @@ class MESSAGE_CENTER_EXPORT NotificationList {
// Images fetched asynchronously
gfx::ImageSkia primary_icon;
- gfx::ImageSkia secondary_icon;
gfx::ImageSkia image;
+ std::vector<gfx::ImageSkia> button_icons;
bool is_read; // True if this has been seen in the message center
bool shown_as_popup; // True if this has been shown as a popup notification
@@ -125,15 +125,17 @@ class MESSAGE_CENTER_EXPORT NotificationList {
void SendRemoveNotificationsByExtension(const std::string& id);
// Returns true if the notification exists and was updated.
- bool SetNotificationPrimaryIcon(const std::string& id,
- const gfx::ImageSkia& image);
+ bool SetNotificationIcon(const std::string& notification_id,
+ const gfx::ImageSkia& image);
// Returns true if the notification exists and was updated.
- bool SetNotificationSecondaryIcon(const std::string& id,
- const gfx::ImageSkia& image);
+ bool SetNotificationImage(const std::string& notification_id,
+ const gfx::ImageSkia& image);
- // Returns true if the notification exists and was updated.
- bool SetNotificationImage(const std::string& id, const gfx::ImageSkia& image);
+ // Returns true if the notification and button exist and were updated.
+ bool SetNotificationButtonIcon(const std::string& notification_id,
+ int button_index,
+ const gfx::ImageSkia& image);
bool HasNotification(const std::string& id);
diff --git a/ui/message_center/notification_view.cc b/ui/message_center/notification_view.cc
index b2d386c..b05a893 100644
--- a/ui/message_center/notification_view.cc
+++ b/ui/message_center/notification_view.cc
@@ -22,15 +22,17 @@
namespace {
// Dimensions.
-const int kIconColumnWidth = message_center::kNotificationIconWidth;
+const int kIconColumnWidth = message_center::kNotificationIconSize;
const int kIconToTextPadding = 16;
const int kTextTopPadding = 6;
const int kTextBottomPadding = 6;
const int kTextRightPadding = 23;
const int kItemTitleToMessagePadding = 3;
+const int kActionButtonHorizontalPadding = 16;
+const int kActionButtonVecticalPadding = 0;
+const int kActionButtonIconTopPadding = 12;
+const int kActionButtonIconToTitlePadding = 16;
const int kActionButtonTitleTopPadding = 0;
-const int kActionButtonTitleLeftPadding = 16;
-const int kActionButtonTitleRightPadding = 16;
// Notification colors. The text background colors below are used only to keep
// view::Label from modifying the text color and will not actually be drawn.
@@ -124,34 +126,64 @@ int ProportionalImageView::GetHeightForWidth(int width) {
return height;
}
-// NotificationsButtons are used to render the action buttons of notifications.
+// NotificationsButtons render the action buttons of notifications.
class NotificationButton : public views::CustomButton {
public:
NotificationButton(views::ButtonListener* listener);
virtual ~NotificationButton();
- void SetTitle(string16 title);
+ void SetIcon(const gfx::ImageSkia& icon);
+ void SetTitle(const string16& title);
+
+ private:
+ views::ImageView* icon_;
+ views::Label* title_;
};
NotificationButton::NotificationButton(views::ButtonListener* listener)
- : views::CustomButton(listener) {
- SetLayoutManager(new views::FillLayout());
+ : views::CustomButton(listener),
+ icon_(NULL),
+ title_(NULL) {
+ SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
+ kActionButtonHorizontalPadding,
+ kActionButtonVecticalPadding,
+ kActionButtonIconToTitlePadding));
}
NotificationButton::~NotificationButton() {
}
-void NotificationButton::SetTitle(string16 title) {
- RemoveAllChildViews(true);
- views::Label* label = new views::Label(title);
- label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- label->SetElideBehavior(views::Label::ELIDE_AT_END);
- label->SetEnabledColor(kTitleColor);
- label->SetBackgroundColor(kTitleBackgroundColor);
- label->set_border(MakePadding(
- kActionButtonTitleTopPadding, kActionButtonTitleLeftPadding,
- 0, kActionButtonTitleRightPadding));
- AddChildView(label);
+void NotificationButton::SetIcon(const gfx::ImageSkia& image) {
+ if (icon_ != NULL)
+ delete icon_; // This removes the icon from this view's children.
+ if (image.isNull()) {
+ icon_ = NULL;
+ } else {
+ icon_ = new views::ImageView();
+ icon_->SetImageSize(gfx::Size(message_center::kNotificationButtonIconSize,
+ message_center::kNotificationButtonIconSize));
+ icon_->SetImage(image);
+ icon_->SetHorizontalAlignment(views::ImageView::LEADING);
+ icon_->SetVerticalAlignment(views::ImageView::LEADING);
+ icon_->set_border(MakePadding(kActionButtonIconTopPadding, 0, 0, 0));
+ AddChildViewAt(icon_, 0);
+ }
+}
+
+void NotificationButton::SetTitle(const string16& title) {
+ if (title_ != NULL)
+ delete title_; // This removes the title from this view's children.
+ if (title.empty()) {
+ title_ = NULL;
+ } else {
+ title_ = new views::Label(title);
+ title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ title_->SetElideBehavior(views::Label::ELIDE_AT_END);
+ title_->SetEnabledColor(kTitleColor);
+ title_->SetBackgroundColor(kTitleBackgroundColor);
+ title_->set_border(MakePadding(kActionButtonTitleTopPadding, 0, 0, 0));
+ AddChildView(title_);
+ }
}
} // namespace
@@ -266,8 +298,8 @@ views::View* NotificationView::MakeContentView() {
// to its right as well as the padding view below them.
layout->StartRow(0, 0);
views::ImageView* icon = new views::ImageView();
- icon->SetImageSize(gfx::Size(message_center::kNotificationIconWidth,
- message_center::kNotificationIconWidth));
+ icon->SetImageSize(gfx::Size(message_center::kNotificationIconSize,
+ message_center::kNotificationIconSize));
icon->SetImage(notification().primary_icon);
icon->SetHorizontalAlignment(views::ImageView::LEADING);
icon->SetVerticalAlignment(views::ImageView::LEADING);
@@ -316,6 +348,7 @@ views::View* NotificationView::MakeContentView() {
views::GridLayout::FILL, views::GridLayout::FILL, 0, 1);
NotificationButton* button = new NotificationButton(this);
button->SetTitle(notification().button_titles[i]);
+ button->SetIcon(notification().button_icons[i]);
action_buttons_.push_back(button);
layout->StartRow(0, 0);
layout->AddView(button, 2, 1,