Commit d66b5aa5 authored by dewittj@chromium.org's avatar dewittj@chromium.org

Add an empty message to the notification center.

This will now match the UI on Windows and ChromeOS.

BUG=284556

Review URL: https://codereview.chromium.org/142413005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247981 0039d316-1c4b-4281-b951-d872f2087c98
parent 399c463f
...@@ -46,6 +46,12 @@ MESSAGE_CENTER_EXPORT ...@@ -46,6 +46,12 @@ MESSAGE_CENTER_EXPORT
// The "Notifications" label at the top. // The "Notifications" label at the top.
base::scoped_nsobject<NSTextField> title_; base::scoped_nsobject<NSTextField> title_;
// The 1px horizontal divider between the scroll view and the title bar.
base::scoped_nsobject<NSBox> divider_;
// The "Nothing to see here" label in an empty message center.
base::scoped_nsobject<NSTextField> emptyDescription_;
// The scroll view that contains all the notifications in its documentView. // The scroll view that contains all the notifications in its documentView.
base::scoped_nsobject<NSScrollView> scrollView_; base::scoped_nsobject<NSScrollView> scrollView_;
...@@ -157,6 +163,8 @@ MESSAGE_CENTER_EXPORT ...@@ -157,6 +163,8 @@ MESSAGE_CENTER_EXPORT
// Testing API ///////////////////////////////////////////////////////////////// // Testing API /////////////////////////////////////////////////////////////////
@interface MCTrayViewController (TestingAPI) @interface MCTrayViewController (TestingAPI)
- (NSBox*)divider;
- (NSTextField*)emptyDescription;
- (NSScrollView*)scrollView; - (NSScrollView*)scrollView;
- (HoverImageButton*)pauseButton; - (HoverImageButton*)pauseButton;
- (HoverImageButton*)clearAllButton; - (HoverImageButton*)clearAllButton;
......
...@@ -359,6 +359,14 @@ const CGFloat kTrayBottomMargin = 75; ...@@ -359,6 +359,14 @@ const CGFloat kTrayBottomMargin = 75;
// Testing API ///////////////////////////////////////////////////////////////// // Testing API /////////////////////////////////////////////////////////////////
- (NSBox*)divider {
return divider_.get();
}
- (NSTextField*)emptyDescription {
return emptyDescription_.get();
}
- (NSScrollView*)scrollView { - (NSScrollView*)scrollView {
return scrollView_.get(); return scrollView_.get();
} }
...@@ -390,16 +398,21 @@ const CGFloat kTrayBottomMargin = 75; ...@@ -390,16 +398,21 @@ const CGFloat kTrayBottomMargin = 75;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
NSView* view = [self view]; NSView* view = [self view];
auto configureLabel = ^(NSTextField* textField) {
[textField setAutoresizingMask:NSViewMinYMargin];
[textField setBezeled:NO];
[textField setBordered:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
};
// Create the "Notifications" label at the top of the tray. // Create the "Notifications" label at the top of the tray.
NSFont* font = [NSFont labelFontOfSize:message_center::kTitleFontSize]; NSFont* font = [NSFont labelFontOfSize:message_center::kTitleFontSize];
title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
[title_ setAutoresizingMask:NSViewMinYMargin]; configureLabel(title_);
[title_ setBezeled:NO];
[title_ setBordered:NO];
[title_ setDrawsBackground:NO];
[title_ setEditable:NO];
[title_ setFont:font]; [title_ setFont:font];
[title_ setSelectable:NO];
[title_ setStringValue: [title_ setStringValue:
l10n_util::GetNSString(IDS_MESSAGE_CENTER_FOOTER_TITLE)]; l10n_util::GetNSString(IDS_MESSAGE_CENTER_FOOTER_TITLE)];
[title_ setTextColor:gfx::SkColorToCalibratedNSColor( [title_ setTextColor:gfx::SkColorToCalibratedNSColor(
...@@ -445,16 +458,17 @@ const CGFloat kTrayBottomMargin = 75; ...@@ -445,16 +458,17 @@ const CGFloat kTrayBottomMargin = 75;
[[self view] addSubview:backButton_]; [[self view] addSubview:backButton_];
// Create the divider line between the control area and the notifications. // Create the divider line between the control area and the notifications.
base::scoped_nsobject<NSBox> divider( divider_.reset(
[[NSBox alloc] initWithFrame:NSMakeRect(0, 0, NSWidth([view frame]), 1)]); [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, NSWidth([view frame]), 1)]);
[divider setAutoresizingMask:NSViewMinYMargin]; [divider_ setAutoresizingMask:NSViewMinYMargin];
[divider setBorderType:NSNoBorder]; [divider_ setBorderType:NSNoBorder];
[divider setBoxType:NSBoxCustom]; [divider_ setBoxType:NSBoxCustom];
[divider setContentViewMargins:NSZeroSize]; [divider_ setContentViewMargins:NSZeroSize];
[divider setFillColor:gfx::SkColorToCalibratedNSColor( [divider_ setFillColor:gfx::SkColorToCalibratedNSColor(
message_center::kFooterDelimiterColor)]; message_center::kFooterDelimiterColor)];
[divider setTitlePosition:NSNoTitle]; [divider_ setTitlePosition:NSNoTitle];
[view addSubview:divider]; [view addSubview:divider_];
auto getButtonFrame = ^NSRect(CGFloat maxX, NSImage* image) { auto getButtonFrame = ^NSRect(CGFloat maxX, NSImage* image) {
NSSize size = [image size]; NSSize size = [image size];
...@@ -524,13 +538,45 @@ const CGFloat kTrayBottomMargin = 75; ...@@ -524,13 +538,45 @@ const CGFloat kTrayBottomMargin = 75;
[pauseButton_ setAction:@selector(toggleQuietMode:)]; [pauseButton_ setAction:@selector(toggleQuietMode:)];
configureButton(pauseButton_); configureButton(pauseButton_);
[view addSubview:pauseButton_]; [view addSubview:pauseButton_];
// Create the description field for the empty message center. Initially it is
// invisible.
emptyDescription_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
configureLabel(emptyDescription_);
NSFont* smallFont =
[NSFont labelFontOfSize:message_center::kEmptyCenterFontSize];
[emptyDescription_ setFont:smallFont];
[emptyDescription_ setStringValue:
l10n_util::GetNSString(IDS_MESSAGE_CENTER_NO_MESSAGES)];
[emptyDescription_ setTextColor:gfx::SkColorToCalibratedNSColor(
message_center::kDimTextColor)];
[emptyDescription_ sizeToFit];
[emptyDescription_ setHidden:YES];
[view addSubview:emptyDescription_];
} }
- (void)updateTrayViewAndWindow { - (void)updateTrayViewAndWindow {
CGFloat scrollContentHeight = 0; CGFloat scrollContentHeight = message_center::kMinScrollViewHeight;
if ([notifications_ count]) { if ([notifications_ count]) {
[emptyDescription_ setHidden:YES];
[scrollView_ setHidden:NO];
[divider_ setHidden:NO];
scrollContentHeight = NSMaxY([[[notifications_ lastObject] view] frame]) + scrollContentHeight = NSMaxY([[[notifications_ lastObject] view] frame]) +
message_center::kMarginBetweenItems;; message_center::kMarginBetweenItems;;
} else {
[emptyDescription_ setHidden:NO];
[scrollView_ setHidden:YES];
[divider_ setHidden:YES];
NSRect centeredFrame = [emptyDescription_ frame];
NSPoint centeredOrigin = NSMakePoint(
floor((NSWidth([[self view] frame]) - NSWidth(centeredFrame))/2 + 0.5),
floor((scrollContentHeight - NSHeight(centeredFrame))/2 + 0.5));
centeredFrame.origin = centeredOrigin;
[emptyDescription_ setFrame:centeredFrame];
} }
// Resize the scroll view's content. // Resize the scroll view's content.
......
...@@ -98,7 +98,10 @@ TEST_F(TrayViewControllerTest, AddRemoveOne) { ...@@ -98,7 +98,10 @@ TEST_F(TrayViewControllerTest, AddRemoveOne) {
center_->RemoveNotification("1", true); center_->RemoveNotification("1", true);
[tray_ onMessageCenterTrayChanged]; [tray_ onMessageCenterTrayChanged];
EXPECT_EQ(0u, [[view subviews] count]); EXPECT_EQ(0u, [[view subviews] count]);
EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); // The empty tray is now 100px tall to accommodate
// the empty message.
EXPECT_CGFLOAT_EQ(message_center::kMinScrollViewHeight,
NSHeight([view frame]));
} }
TEST_F(TrayViewControllerTest, AddThreeClearAll) { TEST_F(TrayViewControllerTest, AddThreeClearAll) {
...@@ -146,7 +149,10 @@ TEST_F(TrayViewControllerTest, AddThreeClearAll) { ...@@ -146,7 +149,10 @@ TEST_F(TrayViewControllerTest, AddThreeClearAll) {
[tray_ onMessageCenterTrayChanged]; [tray_ onMessageCenterTrayChanged];
EXPECT_EQ(0u, [[view subviews] count]); EXPECT_EQ(0u, [[view subviews] count]);
EXPECT_CGFLOAT_EQ(0, NSHeight([view frame])); // The empty tray is now 100px tall to accommodate
// the empty message.
EXPECT_CGFLOAT_EQ(message_center::kMinScrollViewHeight,
NSHeight([view frame]));
} }
TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) {
...@@ -244,4 +250,30 @@ TEST_F(TrayViewControllerTest, Settings) { ...@@ -244,4 +250,30 @@ TEST_F(TrayViewControllerTest, Settings) {
EXPECT_EQ(trayHeight, NSHeight([[tray_ view] frame])); EXPECT_EQ(trayHeight, NSHeight([[tray_ view] frame]));
} }
TEST_F(TrayViewControllerTest, EmptyCenter) {
EXPECT_FALSE([[tray_ emptyDescription] isHidden]);
// With no notifications, the divider should be hidden.
EXPECT_TRUE([[tray_ divider] isHidden]);
EXPECT_TRUE([[tray_ scrollView] isHidden]);
scoped_ptr<message_center::Notification> notification;
notification.reset(new message_center::Notification(
message_center::NOTIFICATION_TYPE_SIMPLE,
"1",
ASCIIToUTF16("First notification"),
ASCIIToUTF16("This is a simple test."),
gfx::Image(),
base::string16(),
DummyNotifierId(),
message_center::RichNotificationData(),
NULL));
center_->AddNotification(notification.Pass());
[tray_ onMessageCenterTrayChanged];
EXPECT_FALSE([[tray_ divider] isHidden]);
EXPECT_FALSE([[tray_ scrollView] isHidden]);
EXPECT_TRUE([[tray_ emptyDescription] isHidden]);
}
} // namespace message_center } // namespace message_center
...@@ -31,6 +31,7 @@ const size_t kMaxVisiblePopupNotifications = 3; ...@@ -31,6 +31,7 @@ const size_t kMaxVisiblePopupNotifications = 3;
// DIP dimension; H size of the whole card. // DIP dimension; H size of the whole card.
const int kNotificationWidth = 360; const int kNotificationWidth = 360;
const int kMinScrollViewHeight = 100;
// Colors. // Colors.
MESSAGE_CENTER_EXPORT extern const SkColor kMessageCenterBorderColor; MESSAGE_CENTER_EXPORT extern const SkColor kMessageCenterBorderColor;
...@@ -64,6 +65,7 @@ const int kIconBottomPadding = 16; // Minimum non-zero V space between icon ...@@ -64,6 +65,7 @@ const int kIconBottomPadding = 16; // Minimum non-zero V space between icon
// Text sizes. // Text sizes.
const int kTitleFontSize = 14; // For title only. const int kTitleFontSize = 14; // For title only.
const int kEmptyCenterFontSize = 13; // For empty message only.
const int kTitleLineHeight = 20; // In DIPs. const int kTitleLineHeight = 20; // In DIPs.
const int kMessageFontSize = 12; // For everything but title. const int kMessageFontSize = 12; // For everything but title.
const int kMessageLineHeight = 18; // In DIPs. const int kMessageLineHeight = 18; // In DIPs.
......
...@@ -51,7 +51,6 @@ const SkColor kNoNotificationsTextColor = SkColorSetRGB(0xb4, 0xb4, 0xb4); ...@@ -51,7 +51,6 @@ const SkColor kNoNotificationsTextColor = SkColorSetRGB(0xb4, 0xb4, 0xb4);
const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0);
#endif #endif
const int kAnimateClearingNextNotificationDelayMS = 40; const int kAnimateClearingNextNotificationDelayMS = 40;
const int kMinScrollViewHeight = 100;
const int kDefaultAnimationDurationMs = 120; const int kDefaultAnimationDurationMs = 120;
const int kDefaultFrameRateHz = 60; const int kDefaultFrameRateHz = 60;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment