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

Unified Diff: ui/message_center/cocoa/notification_controller.mm

Issue 102473005: Refresh for the Chrome notifications image template. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
Index: ui/message_center/cocoa/notification_controller.mm
diff --git a/ui/message_center/cocoa/notification_controller.mm b/ui/message_center/cocoa/notification_controller.mm
index 932d35eb6a06decf39f7291e4650c3be654d3290..96daee693de0063cd08473a8197c04a08776ee6f 100644
--- a/ui/message_center/cocoa/notification_controller.mm
+++ b/ui/message_center/cocoa/notification_controller.mm
@@ -196,7 +196,11 @@
- (void)configureCustomBox:(NSBox*)box;
// Initializes the icon_ ivar and returns the view to insert into the hierarchy.
-- (NSView*)createImageView;
+- (NSView*)createIconView;
+
+// Creates a box that shows a border when the icon is not big enough to fill the
+// space.
+- (NSBox*)createImageBox;
// Initializes the closeButton_ ivar with the configured button.
- (void)configureCloseButtonInFrame:(NSRect)rootFrame;
@@ -254,7 +258,7 @@
message_center::kNotificationBackgroundColor)];
[self setView:rootView];
- [rootView addSubview:[self createImageView]];
+ [rootView addSubview:[self createIconView]];
// Create the close button.
[self configureCloseButtonInFrame:rootFrame];
@@ -505,19 +509,18 @@
}
// Create the image view if appropriate.
- if (!notification->image().IsEmpty()) {
- NSImage* image = notification->image().AsNSImage();
- NSRect imageFrame = frame;
- imageFrame.origin = NSMakePoint(0, y);
- imageFrame.size = NSSizeFromCGSize(message_center::GetImageSizeForWidth(
- NSWidth(frame), notification->image().Size()).ToCGSize());
- base::scoped_nsobject<NSImageView> imageView(
- [[NSImageView alloc] initWithFrame:imageFrame]);
- [imageView setImage:image];
- [imageView setImageScaling:NSImageScaleProportionallyUpOrDown];
- y += NSHeight(imageFrame);
- frame.size.height += NSHeight(imageFrame);
- [bottomView_ addSubview:imageView];
+ gfx::Image notificationImage = notification->image();
+ if (!notificationImage.IsEmpty()) {
+ NSBox* imageBox = [self createImageBox:notificationImage];
+ NSRect outerFrame = frame;
+ outerFrame.origin = NSMakePoint(0, y);
+ outerFrame.size = [imageBox frame].size;
+ [imageBox setFrame:outerFrame];
+
+ y += NSHeight(outerFrame);
+ frame.size.height += NSHeight(outerFrame);
+
+ [bottomView_ addSubview:imageBox];
}
[bottomView_ setFrame:frame];
@@ -584,7 +587,7 @@
[box setContentViewMargins:NSZeroSize];
}
-- (NSView*)createImageView {
+- (NSView*)createIconView {
// Create another box that shows a background color when the icon is not
// big enough to fill the space.
NSRect imageFrame = NSMakeRect(0, 0,
@@ -604,6 +607,40 @@
return imageBox.autorelease();
}
+- (NSBox*)createImageBox:(gfx::Image)notificationImage {
+ using message_center::kNotificationImageBorderSize;
+ using message_center::kNotificationPreferredImageSize;
+ using message_center::kNotificationPreferredImageRatio;
+
+ NSRect imageFrame = NSMakeRect(0, 0,
+ kNotificationPreferredImageSize,
+ kNotificationPreferredImageSize * kNotificationPreferredImageRatio);
+ base::scoped_nsobject<NSBox> imageBox(
+ [[AccessibilityIgnoredBox alloc] initWithFrame:imageFrame]);
+ [self configureCustomBox:imageBox];
+ [imageBox setFillColor:gfx::SkColorToCalibratedNSColor(
+ message_center::kImageBackgroundColor)];
+
+ // Images with non-preferred aspect ratios get a border on all sides.
+ gfx::Size size = notificationImage.Size();
+ int preferredImageHeight = size.width() * kNotificationPreferredImageRatio;
+ if (size.height() != preferredImageHeight) {
+ NSSize borderSize =
+ NSMakeSize(kNotificationImageBorderSize, kNotificationImageBorderSize);
+ [imageBox setContentViewMargins:borderSize];
+ }
+
+ NSImage* image = notificationImage.AsNSImage();
+ base::scoped_nsobject<NSImageView> imageView(
+ [[NSImageView alloc] initWithFrame:imageFrame]);
+ [imageView setImage:image];
+ [imageView setImageScaling:NSImageScaleProportionallyUpOrDown];
+ [imageBox setContentView:imageView];
+
+ return imageBox.autorelease();
+}
+
+
Robert Sesek 2013/12/05 18:36:56 nit: extra line
dewittj 2013/12/10 02:47:04 Done.
- (void)configureCloseButtonInFrame:(NSRect)rootFrame {
closeButton_.reset([[HoverImageButton alloc] initWithFrame:NSMakeRect(
NSMaxX(rootFrame) - message_center::kControlButtonSize,

Powered by Google App Engine
This is Rietveld 408576698