summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authordharcourt@chromium.org <dharcourt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-05 01:15:28 +0000
committerdharcourt@chromium.org <dharcourt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-05 01:15:28 +0000
commit0e11e9fa745c6174f709773346368c4f771ddb2f (patch)
tree8ee137ca6ce7be521f37091229ba69a5b3775a15 /ui
parent36d1cadbff117e27f4f0e7d9d66ec6d5b1601190 (diff)
downloadchromium_src-0e11e9fa745c6174f709773346368c4f771ddb2f.zip
chromium_src-0e11e9fa745c6174f709773346368c4f771ddb2f.tar.gz
chromium_src-0e11e9fa745c6174f709773346368c4f771ddb2f.tar.bz2
Added support for image notifications.
Main review by mukai, miket for OWNERS review of ui/notifications/notification_types.{h,cc} changes. TBR=derat@chromium.org for OWNERS review of balloon_view_ash.cc changes. BUG=164292 Review URL: https://chromiumcodereview.appspot.com/11639041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/message_center/message_center.cc6
-rw-r--r--ui/message_center/message_center.h2
-rw-r--r--ui/message_center/message_center_constants.cc5
-rw-r--r--ui/message_center/message_center_constants.h5
-rw-r--r--ui/message_center/message_view_factory.cc2
-rw-r--r--ui/message_center/notification_list.cc9
-rw-r--r--ui/message_center/notification_list.h4
-rw-r--r--ui/message_center/notification_view.cc115
-rw-r--r--ui/notifications/notification_types.cc14
-rw-r--r--ui/notifications/notification_types.h1
10 files changed, 133 insertions, 30 deletions
diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc
index 0462a03..917d498 100644
--- a/ui/message_center/message_center.cc
+++ b/ui/message_center/message_center.cc
@@ -94,6 +94,12 @@ void MessageCenter::SetNotificationSecondaryIcon(const std::string& id,
NotifyMessageCenterChanged(true);
}
+void MessageCenter::SetNotificationImage(const std::string& id,
+ const gfx::ImageSkia& image) {
+ if (notification_list_->SetNotificationImage(id, image))
+ NotifyMessageCenterChanged(true);
+}
+
//------------------------------------------------------------------------------
// Overridden from NotificationList::Delegate.
diff --git a/ui/message_center/message_center.h b/ui/message_center/message_center.h
index 0815501..ff7eb03 100644
--- a/ui/message_center/message_center.h
+++ b/ui/message_center/message_center.h
@@ -129,6 +129,8 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
void SetNotificationSecondaryIcon(const std::string& id,
const gfx::ImageSkia& image);
+ void SetNotificationImage(const std::string& id, const gfx::ImageSkia& image);
+
NotificationList* notification_list() { return notification_list_.get(); }
// Overridden from NotificationList::Delegate.
diff --git a/ui/message_center/message_center_constants.cc b/ui/message_center/message_center_constants.cc
index f495180..61075ca 100644
--- a/ui/message_center/message_center_constants.cc
+++ b/ui/message_center/message_center_constants.cc
@@ -7,6 +7,9 @@
namespace message_center {
const int kNotificationIconWidth = 80;
-const size_t kNotificationMaxItems = 8;
+const int kNotificationPreferredImageSize = 300;
+
+const int kNotificationMaximumImageHeight = 300;
+const size_t kNotificationMaximumItems = 8;
} // namespace message_center
diff --git a/ui/message_center/message_center_constants.h b/ui/message_center/message_center_constants.h
index be0bdb4..470733c 100644
--- a/ui/message_center/message_center_constants.h
+++ b/ui/message_center/message_center_constants.h
@@ -11,7 +11,10 @@
namespace message_center {
MESSAGE_CENTER_EXPORT extern const int kNotificationIconWidth;
-extern const size_t kNotificationMaxItems;
+MESSAGE_CENTER_EXPORT extern const int kNotificationPreferredImageSize;
+
+extern const int kNotificationMaximumImageHeight;
+extern const size_t kNotificationMaximumItems;
} // namespace message_center
diff --git a/ui/message_center/message_view_factory.cc b/ui/message_center/message_view_factory.cc
index 903dac9..8ea7c51 100644
--- a/ui/message_center/message_view_factory.cc
+++ b/ui/message_center/message_view_factory.cc
@@ -20,6 +20,8 @@ MessageView* MessageViewFactory::ViewForNotification(
switch (notification.type) {
case ui::notifications::NOTIFICATION_TYPE_BASE_FORMAT:
return new BaseFormatView(list_delegate, notification);
+ case ui::notifications::NOTIFICATION_TYPE_IMAGE:
+ return new NotificationView(list_delegate, notification);
case ui::notifications::NOTIFICATION_TYPE_MULTIPLE:
return new NotificationView(list_delegate, notification);
case ui::notifications::NOTIFICATION_TYPE_SIMPLE:
diff --git a/ui/message_center/notification_list.cc b/ui/message_center/notification_list.cc
index 4add984..d92051a7e 100644
--- a/ui/message_center/notification_list.cc
+++ b/ui/message_center/notification_list.cc
@@ -201,6 +201,15 @@ bool NotificationList::SetNotificationSecondaryIcon(
return true;
}
+bool NotificationList::SetNotificationImage(const std::string& id,
+ const gfx::ImageSkia& image) {
+ Notifications::iterator iter;
+ if (!GetNotification(id, &iter))
+ return false;
+ iter->image = image;
+ return true;
+}
+
bool NotificationList::HasNotification(const std::string& id) {
Notifications::iterator dummy;
return GetNotification(id, &dummy);
diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h
index 575f9ce6..87cf509 100644
--- a/ui/message_center/notification_list.h
+++ b/ui/message_center/notification_list.h
@@ -57,6 +57,7 @@ class MESSAGE_CENTER_EXPORT NotificationList {
// Images fetched asynchronously
gfx::ImageSkia primary_icon;
gfx::ImageSkia secondary_icon;
+ gfx::ImageSkia image;
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
@@ -132,6 +133,9 @@ class MESSAGE_CENTER_EXPORT NotificationList {
bool SetNotificationSecondaryIcon(const std::string& id,
const gfx::ImageSkia& image);
+ // Returns true if the notification exists and was updated.
+ bool SetNotificationImage(const std::string& id, const gfx::ImageSkia& image);
+
bool HasNotification(const std::string& id);
// Returns false if the first notification has been shown as a popup (which
diff --git a/ui/message_center/notification_view.cc b/ui/message_center/notification_view.cc
index 76fc38c..459441a 100644
--- a/ui/message_center/notification_view.cc
+++ b/ui/message_center/notification_view.cc
@@ -22,18 +22,22 @@
namespace {
// Notification dimensions.
+const int kIconTopPadding = 0;
const int kIconLeftPadding = 0;
+const int kIconBottomPadding = 0;
const int kIconColumnWidth = message_center::kNotificationIconWidth;
const int kIconToTextPadding = 15;
-const int kTextToClosePadding = 10;
-const int kCloseColumnWidth = 8;
-const int kCloseRightPadding = 6;
-const int kIconTopPadding = 0;
const int kTextTopPadding = 9;
-const int kCloseTopPadding = 6;
-const int kIconBottomPadding = 0;
const int kTextBottomPadding = 12;
+const int kTextToClosePadding = 10;
+const int kCloseTopPadding = 6;
+const int kCloseRightPadding = 6;
+const int kCloseColumnWidth = 8;
const int kItemTitleToDetailsPadding = 3;
+const int kImageTopPadding = 0;
+const int kImageLeftPadding = 0;
+const int kImageBottomPadding = 0;
+const int kImageRightPadding = 0;
// 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.
@@ -88,6 +92,38 @@ ItemView::ItemView(
ItemView::~ItemView() {
}
+// ProportionalImageViews match their heights to their widths to preserve the
+// proportions of their images.
+class ProportionalImageView : public views::ImageView {
+ public:
+ ProportionalImageView();
+ virtual ~ProportionalImageView();
+
+ // Overridden from views::View.
+ virtual int GetHeightForWidth(int width) OVERRIDE;
+};
+
+ProportionalImageView::ProportionalImageView() {
+}
+
+ProportionalImageView::~ProportionalImageView() {
+}
+
+int ProportionalImageView::GetHeightForWidth(int width) {
+ int height = 0;
+ gfx::ImageSkia image = GetImage();
+ if (image.width() > 0 && image.height() > 0) {
+ double proportion = image.height() / (double) image.width();
+ height = 0.5 + width * proportion;
+ if (height > message_center::kNotificationMaximumImageHeight) {
+ height = message_center::kNotificationMaximumImageHeight;
+ width = 0.5 + height / proportion;
+ }
+ SetImageSize(gfx::Size(width, height));
+ }
+ return height;
+}
+
} // namespace
namespace message_center {
@@ -128,8 +164,16 @@ void NotificationView::SetUpView() {
kCloseColumnWidth + kCloseRightPadding);
// Close button + padding.
- // First row: Icon. This vertically spans the close button padding row, the
- // close button row, and all item rows.
+ // Figure out how many rows the icon should span.
+ int span = 2; // Two rows for the close button padding and close button.
+ int displayed_item_count =
+ std::min(notification_.items.size(), kNotificationMaximumItems);
+ if (displayed_item_count > 0)
+ span += displayed_item_count; // + one row per item.
+ else
+ span += 1; // + one row for the message.
+
+ // First row: Icon.
layout->StartRow(0, 0);
views::ImageView* icon = new views::ImageView();
icon->SetImageSize(gfx::Size(message_center::kNotificationIconWidth,
@@ -139,9 +183,7 @@ void NotificationView::SetUpView() {
icon->SetVerticalAlignment(views::ImageView::LEADING);
icon->set_border(MakePadding(kIconTopPadding, kIconLeftPadding,
kIconBottomPadding, kIconToTextPadding));
- int displayed_item_count =
- std::min(notification_.items.size(), kNotificationMaxItems);
- layout->AddView(icon, 1, 2 + displayed_item_count);
+ layout->AddView(icon, 1, span);
// First row: Title. This vertically spans the close button padding row and
// the close button row.
@@ -153,7 +195,8 @@ void NotificationView::SetUpView() {
title->SetEnabledColor(kTitleColor);
title->SetBackgroundColor(kTitleBackgroundColor);
title->set_border(MakePadding(kTextTopPadding, 0, 3, kTextToClosePadding));
- layout->AddView(title, 1, 2);
+ layout->AddView(title, 1, 2,
+ views::GridLayout::LEADING, views::GridLayout::LEADING);
// First row: Close button padding.
views::View* padding = new views::ImageView();
@@ -162,24 +205,56 @@ void NotificationView::SetUpView() {
// Second row: Close button, which has to be on a row of its own because its
// top padding can't be set using empty borders (ImageButtons don't support
- // borders). The resize factor of this row (100) is much higher than that of
- // other rows (0) to ensure the first row's height stays at kCloseTopPadding.
- layout->StartRow(100, 0);
+ // borders). The resize factor of this row (1) is higher than that of the
+ // first rows (0) to ensure the first row's height stays at kCloseTopPadding.
+ layout->StartRow(1, 0);
layout->SkipColumns(2);
DCHECK(close_button_);
layout->AddView(close_button_);
- // One row for each notification item, including appropriate padding.
- for (int i = 0; i < displayed_item_count; ++i) {
- int bottom_padding =
- (i < displayed_item_count - 1) ? 4 : (kTextBottomPadding - 2);
- layout->StartRow(0, 0);
+ // One row for the message if appropriate. The resize factor of this row (2)
+ // is higher than that of preceding rows (0 and 1) to ensure the content of
+ // the notification is top-aligned.
+ if (notification_.items.size() == 0) {
+ layout->StartRow(2, 0);
+ layout->SkipColumns(1);
+ views::Label* message = new views::Label(notification_.message);
+ message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ message->SetElideBehavior(views::Label::ELIDE_AT_END);
+ message->SetEnabledColor(kMessageColor);
+ message->SetBackgroundColor(kMessageBackgroundColor);
+ message->set_border(MakePadding(0, 0, 3, kTextToClosePadding));
+ layout->AddView(message, 1, 1,
+ views::GridLayout::LEADING, views::GridLayout::LEADING);
+ layout->SkipColumns(1);
+ }
+
+ // One row for each notification item, including appropriate padding. The
+ // resize factor of the last row of items (3) is higher than that of all
+ // preceding rows (0, 1, and 2) to ensure the content of the notification is
+ // top-aligned.
+ for (int i = 0, n = displayed_item_count; i < n; ++i) {
+ int bottom_padding = (i < n - 1) ? 4 : (kTextBottomPadding - 2);
+ int resize_factor = (i < n - 1) ? 2 : 3;
+ layout->StartRow(resize_factor, 0);
layout->SkipColumns(1);
ItemView* item = new ItemView(notification_.items[i]);
item->set_border(MakePadding(0, 0, bottom_padding, kTextToClosePadding));
layout->AddView(item);
layout->SkipColumns(1);
}
+
+ // One row for the image.
+ layout->StartRow(0, 0);
+ views::ImageView* image = new ProportionalImageView();
+ image->SetImageSize(notification_.image.size());
+ image->SetImage(notification_.image);
+ image->SetHorizontalAlignment(views::ImageView::CENTER);
+ image->SetVerticalAlignment(views::ImageView::LEADING);
+ image->set_border(MakePadding(kImageTopPadding, kImageLeftPadding,
+ kImageBottomPadding, kImageRightPadding));
+ layout->AddView(image, 3, 1,
+ views::GridLayout::FILL, views::GridLayout::LEADING);
}
} // namespace message_center
diff --git a/ui/notifications/notification_types.cc b/ui/notifications/notification_types.cc
index 80bcead..9bfe1f5 100644
--- a/ui/notifications/notification_types.cc
+++ b/ui/notifications/notification_types.cc
@@ -25,18 +25,16 @@ const char kItemMessageKey[] = "message";
const char kSimpleType[] = "simple";
const char kBaseFormatType[] = "base";
+const char kImageType[] = "image";
const char kMultipleType[] = "multiple";
NotificationType StringToNotificationType(std::string& string_type) {
- if (string_type == kSimpleType)
- return NOTIFICATION_TYPE_SIMPLE;
- if (string_type == kBaseFormatType)
- return NOTIFICATION_TYPE_BASE_FORMAT;
- if (string_type == kMultipleType)
- return NOTIFICATION_TYPE_MULTIPLE;
-
// In case of unrecognized string, fall back to most common type.
- return NOTIFICATION_TYPE_SIMPLE;
+ return (string_type == kSimpleType) ? NOTIFICATION_TYPE_SIMPLE :
+ (string_type == kBaseFormatType) ? NOTIFICATION_TYPE_BASE_FORMAT :
+ (string_type == kImageType) ? NOTIFICATION_TYPE_IMAGE :
+ (string_type == kMultipleType) ? NOTIFICATION_TYPE_MULTIPLE :
+ NOTIFICATION_TYPE_SIMPLE;
}
} // namespace notifications
diff --git a/ui/notifications/notification_types.h b/ui/notifications/notification_types.h
index 29d6dda..e686d28 100644
--- a/ui/notifications/notification_types.h
+++ b/ui/notifications/notification_types.h
@@ -29,6 +29,7 @@ UI_EXPORT extern const char kItemMessageKey[];
enum NotificationType {
NOTIFICATION_TYPE_SIMPLE,
NOTIFICATION_TYPE_BASE_FORMAT,
+ NOTIFICATION_TYPE_IMAGE,
NOTIFICATION_TYPE_MULTIPLE,
};