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

Side by Side Diff: ui/message_center/cocoa/notification_controller.mm

Issue 13560002: Added padding below text in notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased & implemented rsesek suggestion. Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/message_center/message_center_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_constants.h" 13 #include "ui/message_center/message_center_constants.h"
14 #include "ui/message_center/notification.h" 14 #include "ui/message_center/notification.h"
15 #include "ui/message_center/notification_change_observer.h" 15 #include "ui/message_center/notification_change_observer.h"
16 16
17 namespace {
18
19 const int kTextTopPaddingAdjustment = -6;
20 // Compensates for padding already provided by UI elements involved.
Robert Sesek 2013/04/08 21:15:19 Should go above the constant without any indentati
dharcourt 2013/04/08 21:30:27 Done.
21
22 } // namespace
17 @interface MCNotificationController (Private) 23 @interface MCNotificationController (Private)
18 // Configures a NSBox to be borderless, titleless, and otherwise appearance- 24 // Configures a NSBox to be borderless, titleless, and otherwise appearance-
19 // free. 25 // free.
20 - (void)configureCustomBox:(NSBox*)box; 26 - (void)configureCustomBox:(NSBox*)box;
21 27
22 // Initializes the icon_ ivar and returns the view to insert into the hierarchy. 28 // Initializes the icon_ ivar and returns the view to insert into the hierarchy.
23 - (NSView*)createImageView; 29 - (NSView*)createImageView;
24 30
25 // Initializes the closeButton_ ivar with the configured button. 31 // Initializes the closeButton_ ivar with the configured button.
26 - (void)configureCloseButtonInFrame:(NSRect)rootFrame; 32 - (void)configureCloseButtonInFrame:(NSRect)rootFrame;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Create the title. 78 // Create the title.
73 [self configureTitleInFrame:rootFrame]; 79 [self configureTitleInFrame:rootFrame];
74 [rootView addSubview:title_]; 80 [rootView addSubview:title_];
75 81
76 // Create the message body. 82 // Create the message body.
77 [self configureBodyInFrame:rootFrame maxY:NSMinY([title_ frame])]; 83 [self configureBodyInFrame:rootFrame maxY:NSMinY([title_ frame])];
78 [rootView addSubview:message_]; 84 [rootView addSubview:message_];
79 85
80 // In this basic notification UI, the message body is the bottom-most 86 // In this basic notification UI, the message body is the bottom-most
81 // vertical element. If it is out of the rootView's bounds, resize the view. 87 // vertical element. If it is out of the rootView's bounds, resize the view.
82 if (NSMinY([message_ frame]) < message_center::kTextTopPadding) { 88 if (NSMinY([message_ frame]) <
83 rootFrame.size.height += message_center::kTextTopPadding - 89 message_center::kTextTopPadding + kTextTopPaddingAdjustment) {
Robert Sesek 2013/04/08 21:15:19 nit: indent 4 spaces since this is a continuation
dharcourt 2013/04/08 21:30:27 Done.
84 NSMinY([message_ frame]); 90 rootFrame.size.height += message_center::kTextTopPadding +
91 kTextTopPaddingAdjustment -
92 NSMinY([message_ frame]);
85 } 93 }
86 94
87 [rootView setFrame:rootFrame]; 95 [rootView setFrame:rootFrame];
88 } 96 }
89 97
90 - (void)close:(id)sender { 98 - (void)close:(id)sender {
91 observer_->OnRemoveNotification(notification_->id(), /*by_user=*/true); 99 observer_->OnRemoveNotification(notification_->id(), /*by_user=*/true);
92 } 100 }
93 101
94 - (const message_center::Notification*)notification { 102 - (const message_center::Notification*)notification {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 NSRect frame = [self currentContentRect]; 160 NSRect frame = [self currentContentRect];
153 161
154 title_.reset([self newLabelWithFrame:NSMakeRect(0, 0, NSWidth(frame), 0)]); 162 title_.reset([self newLabelWithFrame:NSMakeRect(0, 0, NSWidth(frame), 0)]);
155 [title_ setAutoresizingMask:NSViewMinYMargin]; 163 [title_ setAutoresizingMask:NSViewMinYMargin];
156 [title_ setStringValue:base::SysUTF16ToNSString(notification_->title())]; 164 [title_ setStringValue:base::SysUTF16ToNSString(notification_->title())];
157 [title_ setFont:[NSFont messageFontOfSize:message_center::kTitleFontSize]]; 165 [title_ setFont:[NSFont messageFontOfSize:message_center::kTitleFontSize]];
158 166
159 CGFloat delta = 167 CGFloat delta =
160 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title_]; 168 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title_];
161 frame.size.height = delta; 169 frame.size.height = delta;
162 frame.origin.y = NSMaxY(rootFrame) - message_center::kTextTopPadding - delta; 170 frame.origin.y = NSMaxY(rootFrame) - message_center::kTextTopPadding +
171 kTextTopPaddingAdjustment - delta;
163 [title_ setFrame:frame]; 172 [title_ setFrame:frame];
164 } 173 }
165 174
166 - (void)configureBodyInFrame:(NSRect)rootFrame maxY:(CGFloat)maxY { 175 - (void)configureBodyInFrame:(NSRect)rootFrame maxY:(CGFloat)maxY {
167 NSRect frame = [self currentContentRect]; 176 NSRect frame = [self currentContentRect];
168 177
169 message_.reset([self newLabelWithFrame:NSMakeRect(0, 0, NSWidth(frame), 0)]); 178 message_.reset([self newLabelWithFrame:NSMakeRect(0, 0, NSWidth(frame), 0)]);
170 [message_ setAutoresizingMask:NSViewMinYMargin]; 179 [message_ setAutoresizingMask:NSViewMinYMargin];
171 [message_ setStringValue:base::SysUTF16ToNSString(notification_->message())]; 180 [message_ setStringValue:base::SysUTF16ToNSString(notification_->message())];
172 [message_ setFont: 181 [message_ setFont:
173 [NSFont messageFontOfSize:message_center::kMessageFontSize]]; 182 [NSFont messageFontOfSize:message_center::kMessageFontSize]];
174 183
175 CGFloat delta = 184 CGFloat delta =
176 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:message_]; 185 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:message_];
177 frame.size.height = delta; 186 frame.size.height = delta;
178 frame.origin.y = maxY - message_center::kTextTopPadding - delta; 187 frame.origin.y = maxY - message_center::kTextTopPadding +
188 kTextTopPaddingAdjustment - delta;
179 [message_ setFrame:frame]; 189 [message_ setFrame:frame];
180 } 190 }
181 191
182 - (NSTextField*)newLabelWithFrame:(NSRect)frame { 192 - (NSTextField*)newLabelWithFrame:(NSRect)frame {
183 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; 193 NSTextField* label = [[NSTextField alloc] initWithFrame:frame];
184 [label setDrawsBackground:NO]; 194 [label setDrawsBackground:NO];
185 [label setBezeled:NO]; 195 [label setBezeled:NO];
186 [label setEditable:NO]; 196 [label setEditable:NO];
187 [label setSelectable:NO]; 197 [label setSelectable:NO];
188 [label setTextColor:gfx::SkColorToCalibratedNSColor( 198 [label setTextColor:gfx::SkColorToCalibratedNSColor(
189 message_center::kRegularTextColor)]; 199 message_center::kRegularTextColor)];
190 return label; 200 return label;
191 } 201 }
192 202
193 - (NSRect)currentContentRect { 203 - (NSRect)currentContentRect {
194 DCHECK(icon_); 204 DCHECK(icon_);
195 DCHECK(closeButton_); 205 DCHECK(closeButton_);
196 206
197 NSRect iconFrame, contentFrame; 207 NSRect iconFrame, contentFrame;
198 NSDivideRect([[self view] bounds], &iconFrame, &contentFrame, 208 NSDivideRect([[self view] bounds], &iconFrame, &contentFrame,
199 NSWidth([icon_ frame]) + message_center::kIconToTextPadding, 209 NSWidth([icon_ frame]) + message_center::kIconToTextPadding,
200 NSMinXEdge); 210 NSMinXEdge);
201 contentFrame.size.width -= NSWidth([closeButton_ frame]); 211 contentFrame.size.width -= NSWidth([closeButton_ frame]);
202 return contentFrame; 212 return contentFrame;
203 } 213 }
204 214
205 @end 215 @end
OLDNEW
« no previous file with comments | « no previous file | ui/message_center/message_center_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698