OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ui/message_center/cocoa/notification_controller.h" | 5 #import "ui/message_center/cocoa/notification_controller.h" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "skia/ext/skia_utils_mac.h" | 9 #include "skia/ext/skia_utils_mac.h" |
10 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 10 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
11 #import "ui/base/cocoa/hover_image_button.h" | 11 #import "ui/base/cocoa/hover_image_button.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/message_center/message_center.h" | 13 #include "ui/message_center/message_center.h" |
14 #include "ui/message_center/message_center_constants.h" | 14 #include "ui/message_center/message_center_constants.h" |
15 #include "ui/message_center/notification.h" | 15 #include "ui/message_center/notification.h" |
16 | 16 |
17 namespace { | |
18 | |
19 // Compensates for padding already provided by UI elements involved. | |
20 const int kTextTopPaddingAdjustment = -6; | |
21 | |
22 } // namespace | |
23 | |
24 @interface MCNotificationController (Private) | 17 @interface MCNotificationController (Private) |
25 // Configures a NSBox to be borderless, titleless, and otherwise appearance- | 18 // Configures a NSBox to be borderless, titleless, and otherwise appearance- |
26 // free. | 19 // free. |
27 - (void)configureCustomBox:(NSBox*)box; | 20 - (void)configureCustomBox:(NSBox*)box; |
28 | 21 |
29 // Initializes the icon_ ivar and returns the view to insert into the hierarchy. | 22 // Initializes the icon_ ivar and returns the view to insert into the hierarchy. |
30 - (NSView*)createImageView; | 23 - (NSView*)createImageView; |
31 | 24 |
32 // Initializes the closeButton_ ivar with the configured button. | 25 // Initializes the closeButton_ ivar with the configured button. |
33 - (void)configureCloseButtonInFrame:(NSRect)rootFrame; | 26 - (void)configureCloseButtonInFrame:(NSRect)rootFrame; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 DCHECK_EQ(notification->id(), notificationID_); | 86 DCHECK_EQ(notification->id(), notificationID_); |
94 notification_ = notification; | 87 notification_ = notification; |
95 | 88 |
96 NSRect rootFrame = NSMakeRect(0, 0, | 89 NSRect rootFrame = NSMakeRect(0, 0, |
97 message_center::kNotificationPreferredImageSize, | 90 message_center::kNotificationPreferredImageSize, |
98 message_center::kNotificationIconSize); | 91 message_center::kNotificationIconSize); |
99 | 92 |
100 // Update the icon. | 93 // Update the icon. |
101 [icon_ setImage:notification_->icon().AsNSImage()]; | 94 [icon_ setImage:notification_->icon().AsNSImage()]; |
102 | 95 |
| 96 // The message_center:: constants are relative to capHeight at the top and |
| 97 // relative to the baseline at the bottom, but NSTextField uses the full line |
| 98 // height for its height. |
| 99 CGFloat titleTopGap = [[title_ font] ascender] - [[title_ font] capHeight]; |
| 100 CGFloat titleBottomGap = fabs([[title_ font] descender]); |
| 101 CGFloat titlePadding = message_center::kTextTopPadding - titleTopGap; |
| 102 |
| 103 CGFloat messageTopGap = |
| 104 [[message_ font] ascender] - [[message_ font] capHeight]; |
| 105 CGFloat messagePadding = |
| 106 message_center::kTextTopPadding - titleBottomGap - messageTopGap; |
| 107 |
103 // Set the title and recalculate the frame. | 108 // Set the title and recalculate the frame. |
104 [title_ setStringValue:base::SysUTF16ToNSString(notification_->title())]; | 109 [title_ setStringValue:base::SysUTF16ToNSString(notification_->title())]; |
105 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title_]; | 110 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title_]; |
106 NSRect titleFrame = [title_ frame]; | 111 NSRect titleFrame = [title_ frame]; |
107 titleFrame.origin.y = NSMaxY(rootFrame) - message_center::kTextTopPadding - | 112 titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame); |
108 NSHeight(titleFrame); | |
109 | 113 |
110 // Set the message and recalculate the frame. | 114 // Set the message and recalculate the frame. |
111 [message_ setStringValue:base::SysUTF16ToNSString(notification_->message())]; | 115 [message_ setStringValue:base::SysUTF16ToNSString(notification_->message())]; |
112 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:message_]; | 116 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:message_]; |
113 NSRect messageFrame = [message_ frame]; | 117 NSRect messageFrame = [message_ frame]; |
114 messageFrame.origin.y = NSMinY(titleFrame) - message_center::kTextTopPadding - | 118 messageFrame.origin.y = |
115 NSHeight(messageFrame); | 119 NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame); |
116 messageFrame.size.height = NSHeight([message_ frame]); | 120 messageFrame.size.height = NSHeight([message_ frame]); |
117 | 121 |
118 // In this basic notification UI, the message body is the bottom-most | 122 // In this basic notification UI, the message body is the bottom-most |
119 // vertical element. If it is out of the rootView's bounds, resize the view. | 123 // vertical element. If it is out of the rootView's bounds, resize the view. |
120 if (NSMinY(messageFrame) < | 124 if (NSMinY(messageFrame) < messagePadding) { |
121 message_center::kTextTopPadding + kTextTopPaddingAdjustment) { | 125 CGFloat delta = messagePadding - NSMinY(messageFrame); |
122 CGFloat delta = message_center::kTextTopPadding + | |
123 kTextTopPaddingAdjustment - NSMinY(messageFrame); | |
124 rootFrame.size.height += delta; | 126 rootFrame.size.height += delta; |
125 titleFrame.origin.y += delta; | 127 titleFrame.origin.y += delta; |
126 messageFrame.origin.y += delta; | 128 messageFrame.origin.y += delta; |
127 } | 129 } |
128 | 130 |
129 [[self view] setFrame:rootFrame]; | 131 [[self view] setFrame:rootFrame]; |
130 [title_ setFrame:titleFrame]; | 132 [title_ setFrame:titleFrame]; |
131 [message_ setFrame:messageFrame]; | 133 [message_ setFrame:messageFrame]; |
132 | 134 |
133 return rootFrame; | 135 return rootFrame; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 233 |
232 NSRect iconFrame, contentFrame; | 234 NSRect iconFrame, contentFrame; |
233 NSDivideRect([[self view] bounds], &iconFrame, &contentFrame, | 235 NSDivideRect([[self view] bounds], &iconFrame, &contentFrame, |
234 NSWidth([icon_ frame]) + message_center::kIconToTextPadding, | 236 NSWidth([icon_ frame]) + message_center::kIconToTextPadding, |
235 NSMinXEdge); | 237 NSMinXEdge); |
236 contentFrame.size.width -= NSWidth([closeButton_ frame]); | 238 contentFrame.size.width -= NSWidth([closeButton_ frame]); |
237 return contentFrame; | 239 return contentFrame; |
238 } | 240 } |
239 | 241 |
240 @end | 242 @end |
OLD | NEW |