Skip to content

Commit

Permalink
mac: Minor tweaks to notifications code.
Browse files Browse the repository at this point in the history
Fixes the lower padding, and simplifies the code a bit.

BUG=none
TEST=Open a notification with more than 2 lines of text. Bottom margin doesn't
look too small.

R=rsesek@chromium.org

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=199777

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199808 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thakis@chromium.org committed May 13, 2013
1 parent e8c44e6 commit b754bc2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
32 changes: 17 additions & 15 deletions ui/message_center/cocoa/notification_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
#include "ui/message_center/message_center_constants.h"
#include "ui/message_center/notification.h"

namespace {

// Compensates for padding already provided by UI elements involved.
const int kTextTopPaddingAdjustment = -6;

} // namespace

@interface MCNotificationController (Private)
// Configures a NSBox to be borderless, titleless, and otherwise appearance-
// free.
Expand Down Expand Up @@ -100,27 +93,36 @@ - (NSRect)updateNotification:(const message_center::Notification*)notification {
// Update the icon.
[icon_ setImage:notification_->icon().AsNSImage()];

// The message_center:: constants are relative to capHeight at the top and
// relative to the baseline at the bottom, but NSTextField uses the full line
// height for its height.
CGFloat titleTopGap = [[title_ font] ascender] - [[title_ font] capHeight];
CGFloat titleBottomGap = fabs([[title_ font] descender]);
CGFloat titlePadding = message_center::kTextTopPadding - titleTopGap;

CGFloat messageTopGap =
[[message_ font] ascender] - [[message_ font] capHeight];
CGFloat messagePadding =
message_center::kTextTopPadding - titleBottomGap - messageTopGap;

// Set the title and recalculate the frame.
[title_ setStringValue:base::SysUTF16ToNSString(notification_->title())];
[GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title_];
NSRect titleFrame = [title_ frame];
titleFrame.origin.y = NSMaxY(rootFrame) - message_center::kTextTopPadding -
NSHeight(titleFrame);
titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame);

// Set the message and recalculate the frame.
[message_ setStringValue:base::SysUTF16ToNSString(notification_->message())];
[GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:message_];
NSRect messageFrame = [message_ frame];
messageFrame.origin.y = NSMinY(titleFrame) - message_center::kTextTopPadding -
NSHeight(messageFrame);
messageFrame.origin.y =
NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame);
messageFrame.size.height = NSHeight([message_ frame]);

// In this basic notification UI, the message body is the bottom-most
// vertical element. If it is out of the rootView's bounds, resize the view.
if (NSMinY(messageFrame) <
message_center::kTextTopPadding + kTextTopPaddingAdjustment) {
CGFloat delta = message_center::kTextTopPadding +
kTextTopPaddingAdjustment - NSMinY(messageFrame);
if (NSMinY(messageFrame) < messagePadding) {
CGFloat delta = messagePadding - NSMinY(messageFrame);
rootFrame.size.height += delta;
titleFrame.origin.y += delta;
messageFrame.origin.y += delta;
Expand Down
7 changes: 3 additions & 4 deletions ui/message_center/cocoa/popup_collection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ - (void)layoutNotificationsStartingAt:(NSUInteger)index;

virtual void OnNotificationAdded(
const std::string& notification_id) OVERRIDE {
const auto& popups = message_center_->GetPopupNotifications();
for (auto it = popups.begin(); it != popups.end(); ++it) {
if ((*it)->id() == notification_id) {
[popup_collection_ addNotification:*it];
for (const auto& notification : message_center_->GetPopupNotifications()) {
if (notification->id() == notification_id) {
[popup_collection_ addNotification:notification];
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/message_center/message_center.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MESSAGE_CENTER_EXPORT MessageCenter {
virtual void SetNotificationImage(const std::string& notification_id,
const gfx::Image& image) = 0;

// Sets the image for the icon of the specific aaction button.
// Sets the image for the icon of the specific action button.
virtual void SetNotificationButtonIcon(const std::string& notification_id,
int button_index,
const gfx::Image& image) = 0;
Expand Down
2 changes: 2 additions & 0 deletions ui/message_center/message_center_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_OBSERVER_H_
#define UI_MESSAGE_CENTER_MESSAGE_CENTER_OBSERVER_H_

#include <string>

#include "ui/message_center/message_center_export.h"

namespace message_center {
Expand Down

0 comments on commit b754bc2

Please sign in to comment.