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

Unified Diff: ui/message_center/notification_view.cc

Issue 11639041: Added support for image notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/notification_list.cc ('k') | ui/notifications/notification_types.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/notification_view.cc
diff --git a/ui/message_center/notification_view.cc b/ui/message_center/notification_view.cc
index 39acf9f5eaf80485d49a80476c6c4020615e0c30..bb59f169126d956b951216319d17a225c319aba0 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 {
@@ -130,8 +166,15 @@ 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.
+ if (notification_.items.size() > 0) {
+ span += notification_.items.size(); // One row per item.
+ } else {
+ span += 1; // One row for the message.
+ }
Jun Mukai 2012/12/20 18:26:49 remove braces for 1-line if.
dharcourt 2012/12/20 20:51:32 Done.
+
+ // First row: Icon.
layout->StartRow(0, 0);
views::ImageView* icon = new views::ImageView();
icon->SetImageSize(gfx::Size(message_center::kNotificationIconWidth,
@@ -141,7 +184,7 @@ void NotificationView::SetUpView() {
icon->SetVerticalAlignment(views::ImageView::LEADING);
icon->set_border(MakePadding(kIconTopPadding, kIconLeftPadding,
kIconBottomPadding, kIconToTextPadding));
- layout->AddView(icon, 1, 2 + notification_.items.size());
+ layout->AddView(icon, 1, span);
// First row: Title. This vertically spans the close button padding row and
// the close button row.
@@ -152,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();
@@ -161,23 +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.
+ // 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 = notification_.items.size(); i < n; ++i) {
int bottom_padding = (i < n - 1) ? 4 : (kTextBottomPadding - 2);
- layout->StartRow(0, 0);
+ 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
« no previous file with comments | « ui/message_center/notification_list.cc ('k') | ui/notifications/notification_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698