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
// The "Notifications" label at the top.
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.
base::scoped_nsobject<NSScrollView> scrollView_;
......@@ -157,6 +163,8 @@ MESSAGE_CENTER_EXPORT
// Testing API /////////////////////////////////////////////////////////////////
@interface MCTrayViewController (TestingAPI)
- (NSBox*)divider;
- (NSTextField*)emptyDescription;
- (NSScrollView*)scrollView;
- (HoverImageButton*)pauseButton;
- (HoverImageButton*)clearAllButton;
......
......@@ -359,6 +359,14 @@ const CGFloat kTrayBottomMargin = 75;
// Testing API /////////////////////////////////////////////////////////////////
- (NSBox*)divider {
return divider_.get();
}
- (NSTextField*)emptyDescription {
return emptyDescription_.get();
}
- (NSScrollView*)scrollView {
return scrollView_.get();
}
......@@ -390,16 +398,21 @@ const CGFloat kTrayBottomMargin = 75;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
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.
NSFont* font = [NSFont labelFontOfSize:message_center::kTitleFontSize];
title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
[title_ setAutoresizingMask:NSViewMinYMargin];
[title_ setBezeled:NO];
[title_ setBordered:NO];
[title_ setDrawsBackground:NO];
[title_ setEditable:NO];
configureLabel(title_);
[title_ setFont:font];
[title_ setSelectable:NO];
[title_ setStringValue:
l10n_util::GetNSString(IDS_MESSAGE_CENTER_FOOTER_TITLE)];
[title_ setTextColor:gfx::SkColorToCalibratedNSColor(
......@@ -445,16 +458,17 @@ const CGFloat kTrayBottomMargin = 75;
[[self view] addSubview:backButton_];
// 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)]);
[divider setAutoresizingMask:NSViewMinYMargin];
[divider setBorderType:NSNoBorder];
[divider setBoxType:NSBoxCustom];
[divider setContentViewMargins:NSZeroSize];
[divider setFillColor:gfx::SkColorToCalibratedNSColor(
[divider_ setAutoresizingMask:NSViewMinYMargin];
[divider_ setBorderType:NSNoBorder];
[divider_ setBoxType:NSBoxCustom];
[divider_ setContentViewMargins:NSZeroSize];
[divider_ setFillColor:gfx::SkColorToCalibratedNSColor(
message_center::kFooterDelimiterColor)];
[divider setTitlePosition:NSNoTitle];
[view addSubview:divider];
[divider_ setTitlePosition:NSNoTitle];
[view addSubview:divider_];
auto getButtonFrame = ^NSRect(CGFloat maxX, NSImage* image) {
NSSize size = [image size];
......@@ -524,13 +538,45 @@ const CGFloat kTrayBottomMargin = 75;
[pauseButton_ setAction:@selector(toggleQuietMode:)];
configureButton(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 {
CGFloat scrollContentHeight = 0;
CGFloat scrollContentHeight = message_center::kMinScrollViewHeight;
if ([notifications_ count]) {
[emptyDescription_ setHidden:YES];
[scrollView_ setHidden:NO];
[divider_ setHidden:NO];
scrollContentHeight = NSMaxY([[[notifications_ lastObject] view] frame]) +
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.
......
......@@ -98,7 +98,10 @@ TEST_F(TrayViewControllerTest, AddRemoveOne) {
center_->RemoveNotification("1", true);
[tray_ onMessageCenterTrayChanged];
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) {
......@@ -146,7 +149,10 @@ TEST_F(TrayViewControllerTest, AddThreeClearAll) {
[tray_ onMessageCenterTrayChanged];
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) {
......@@ -244,4 +250,30 @@ TEST_F(TrayViewControllerTest, Settings) {
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
......@@ -31,6 +31,7 @@ const size_t kMaxVisiblePopupNotifications = 3;
// DIP dimension; H size of the whole card.
const int kNotificationWidth = 360;
const int kMinScrollViewHeight = 100;
// Colors.
MESSAGE_CENTER_EXPORT extern const SkColor kMessageCenterBorderColor;
......@@ -64,6 +65,7 @@ const int kIconBottomPadding = 16; // Minimum non-zero V space between icon
// Text sizes.
const int kTitleFontSize = 14; // For title only.
const int kEmptyCenterFontSize = 13; // For empty message only.
const int kTitleLineHeight = 20; // In DIPs.
const int kMessageFontSize = 12; // For everything but title.
const int kMessageLineHeight = 18; // In DIPs.
......
......@@ -51,7 +51,6 @@ const SkColor kNoNotificationsTextColor = SkColorSetRGB(0xb4, 0xb4, 0xb4);
const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0);
#endif
const int kAnimateClearingNextNotificationDelayMS = 40;
const int kMinScrollViewHeight = 100;
const int kDefaultAnimationDurationMs = 120;
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