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

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

Issue 21118002: Show progress bar notifications for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months 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/cocoa/notification_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 afea9e6ca4e6a57b0a240c842f641c8e29010f90..50cec6b21cd40288305bbc0435b8e8633b5ddea8 100644
--- a/ui/message_center/cocoa/notification_controller.mm
+++ b/ui/message_center/cocoa/notification_controller.mm
@@ -19,6 +19,41 @@
#include "ui/message_center/message_center_style.h"
#include "ui/message_center/notification.h"
+const CGFloat kProgressBarThickness = 8;
+const CGFloat kProgressBarTopPadding = 12;
+const SkColor kProgressBarBackgroundColor = SkColorSetRGB(230, 230, 230);
Robert Sesek 2013/07/29 18:50:26 Should these be shared in the constants file?
jianli 2013/07/29 19:05:40 The constants used to paint progress bar for Windo
+const SkColor kProgressBarBackgroundBorderColor = SkColorSetRGB(208, 208, 208);
+const SkColor kProgressBarSliceColor = SkColorSetRGB(78, 156, 245);
+const SkColor kProgressBarSliceBorderColor = SkColorSetRGB(110, 188, 249);
+
+@interface MCNotificationProgressBar : NSProgressIndicator {
Robert Sesek 2013/07/29 18:50:26 nit: remove {}
jianli 2013/07/29 19:05:40 Done.
+}
+@end
+
+@implementation MCNotificationProgressBar
+- (void)drawRect:(NSRect)dirtyRect {
+ NSRect sliceRect, remainderRect;
+ double progressFraction = ([self doubleValue] - [self minValue]) /
+ ([self maxValue] - [self minValue]);
+ NSDivideRect(dirtyRect, &sliceRect, &remainderRect,
+ NSWidth(dirtyRect) * progressFraction, NSMinXEdge);
+
+ // For slice part.
+ [gfx::SkColorToCalibratedNSColor(kProgressBarSliceBorderColor)
+ drawSwatchInRect:sliceRect];
+ [gfx::SkColorToCalibratedNSColor(kProgressBarSliceColor)
+ drawSwatchInRect:NSInsetRect(sliceRect, 1.0, 1.0)];
+
+ // For remainder part.
+ [gfx::SkColorToCalibratedNSColor(kProgressBarBackgroundBorderColor)
+ drawSwatchInRect:remainderRect];
+ [gfx::SkColorToCalibratedNSColor(kProgressBarBackgroundColor)
+ drawSwatchInRect:NSInsetRect(remainderRect, 1.0, 1.0)];
+}
+@end
+
+////////////////////////////////////////////////////////////////////////////////
+
@interface MCNotificationButtonCell : NSButtonCell {
BOOL hovered_;
}
@@ -318,17 +353,37 @@
[[self view] addSubview:listItemView_];
}
+ // Create the progress bar view if needed.
+ [progressBarView_ removeFromSuperview];
+ NSRect progressBarFrame = NSZeroRect;
+ if (notification->type() == message_center::NOTIFICATION_TYPE_PROGRESS) {
+ progressBarFrame = [self currentContentRect];
+ progressBarFrame.origin.y = NSMinY(messageFrame) -
+ kProgressBarTopPadding - kProgressBarThickness;
+ progressBarFrame.size.height = kProgressBarThickness;
+ progressBarView_.reset([[MCNotificationProgressBar alloc]
+ initWithFrame:progressBarFrame]);
Robert Sesek 2013/07/29 18:50:26 nit: does this fit if you break after the .reset(
jianli 2013/07/29 19:05:40 Done.
+ // Setting indeterminate to NO does not work with custom drawRect.
+ [progressBarView_ setIndeterminate:YES];
+ [progressBarView_ setStyle:NSProgressIndicatorBarStyle];
+ [progressBarView_ setDoubleValue:notification->progress()];
+ [[self view] addSubview:progressBarView_];
+ }
+
// If the bottom-most element so far is out of the rootView's bounds, resize
// the view.
CGFloat minY = NSMinY(messageFrame);
if (listItemView_ && NSMinY(listFrame) < minY)
minY = NSMinY(listFrame);
+ if (progressBarView_ && NSMinY(progressBarFrame) < minY)
+ minY = NSMinY(progressBarFrame);
if (minY < messagePadding) {
CGFloat delta = messagePadding - minY;
rootFrame.size.height += delta;
titleFrame.origin.y += delta;
messageFrame.origin.y += delta;
listFrame.origin.y += delta;
+ progressBarFrame.origin.y += delta;
}
// Add the bottom container view.
@@ -398,11 +453,13 @@
titleFrame.origin.y += NSHeight(frame);
messageFrame.origin.y += NSHeight(frame);
listFrame.origin.y += NSHeight(frame);
+ progressBarFrame.origin.y += NSHeight(frame);
[[self view] setFrame:rootFrame];
[title_ setFrame:titleFrame];
[message_ setFrame:messageFrame];
[listItemView_ setFrame:listFrame];
+ [progressBarView_ setFrame:progressBarFrame];
return rootFrame;
}
« no previous file with comments | « ui/message_center/cocoa/notification_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698