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

Side by Side Diff: chrome/browser/ui/cocoa/confirm_bubble_cocoa.mm

Issue 10545050: mac: Use NSWidth() and friends in a few more places. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h" 5 #import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h"
6 6
7 #import "base/mac/cocoa_protocols.h" 7 #import "base/mac/cocoa_protocols.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "chrome/browser/themes/theme_service.h" 9 #include "chrome/browser/themes/theme_service.h"
10 #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h" 10 #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // them into this bubble. This function retrieves text and images from the 166 // them into this bubble. This function retrieves text and images from the
167 // ConfirmBubbleModel object (via the ConfirmBubbleController object) and 167 // ConfirmBubbleModel object (via the ConfirmBubbleController object) and
168 // layouts them programmatically. This function layouts controls in the botom-up 168 // layouts them programmatically. This function layouts controls in the botom-up
169 // order since NSView uses bottom-up coordinate. 169 // order since NSView uses bottom-up coordinate.
170 - (void)performLayout { 170 - (void)performLayout {
171 NSRect frameRect = [self frame]; 171 NSRect frameRect = [self frame];
172 172
173 // Add the ok button and the cancel button to the first row if we have either 173 // Add the ok button and the cancel button to the first row if we have either
174 // of them. 174 // of them.
175 CGFloat left = kButtonHEdgeMargin; 175 CGFloat left = kButtonHEdgeMargin;
176 CGFloat right = frameRect.size.width - kButtonHEdgeMargin; 176 CGFloat right = NSWidth(frameRect) - kButtonHEdgeMargin;
177 CGFloat bottom = kButtonVEdgeMargin; 177 CGFloat bottom = kButtonVEdgeMargin;
178 CGFloat height = 0; 178 CGFloat height = 0;
179 if ([controller_ hasOkButton]) { 179 if ([controller_ hasOkButton]) {
180 okButton_.reset([[NSButton alloc] 180 okButton_.reset([[NSButton alloc]
181 initWithFrame:NSMakeRect(0, bottom, 0, 0)]); 181 initWithFrame:NSMakeRect(0, bottom, 0, 0)]);
182 [okButton_.get() setBezelStyle:NSRoundedBezelStyle]; 182 [okButton_.get() setBezelStyle:NSRoundedBezelStyle];
183 [okButton_.get() setTitle:[controller_ okButtonText]]; 183 [okButton_.get() setTitle:[controller_ okButtonText]];
184 [okButton_.get() setTarget:self]; 184 [okButton_.get() setTarget:self];
185 [okButton_.get() setAction:@selector(ok:)]; 185 [okButton_.get() setAction:@selector(ok:)];
186 [okButton_.get() sizeToFit]; 186 [okButton_.get() sizeToFit];
187 NSRect okButtonRect = [okButton_.get() frame]; 187 NSRect okButtonRect = [okButton_.get() frame];
188 right -= okButtonRect.size.width; 188 right -= NSWidth(okButtonRect);
189 okButtonRect.origin.x = right; 189 okButtonRect.origin.x = right;
190 [okButton_.get() setFrame:okButtonRect]; 190 [okButton_.get() setFrame:okButtonRect];
191 [self addSubview:okButton_.get()]; 191 [self addSubview:okButton_.get()];
192 height = std::max(height, okButtonRect.size.height); 192 height = std::max(height, NSHeight(okButtonRect));
193 } 193 }
194 if ([controller_ hasCancelButton]) { 194 if ([controller_ hasCancelButton]) {
195 cancelButton_.reset([[NSButton alloc] 195 cancelButton_.reset([[NSButton alloc]
196 initWithFrame:NSMakeRect(0, bottom, 0, 0)]); 196 initWithFrame:NSMakeRect(0, bottom, 0, 0)]);
197 [cancelButton_.get() setBezelStyle:NSRoundedBezelStyle]; 197 [cancelButton_.get() setBezelStyle:NSRoundedBezelStyle];
198 [cancelButton_.get() setTitle:[controller_ cancelButtonText]]; 198 [cancelButton_.get() setTitle:[controller_ cancelButtonText]];
199 [cancelButton_.get() setTarget:self]; 199 [cancelButton_.get() setTarget:self];
200 [cancelButton_.get() setAction:@selector(cancel:)]; 200 [cancelButton_.get() setAction:@selector(cancel:)];
201 [cancelButton_.get() sizeToFit]; 201 [cancelButton_.get() sizeToFit];
202 NSRect cancelButtonRect = [cancelButton_.get() frame]; 202 NSRect cancelButtonRect = [cancelButton_.get() frame];
203 right -= cancelButtonRect.size.width + kButtonHEdgeMargin; 203 right -= NSWidth(cancelButtonRect) + kButtonHEdgeMargin;
204 cancelButtonRect.origin.x = right; 204 cancelButtonRect.origin.x = right;
205 [cancelButton_.get() setFrame:cancelButtonRect]; 205 [cancelButton_.get() setFrame:cancelButtonRect];
206 [self addSubview:cancelButton_.get()]; 206 [self addSubview:cancelButton_.get()];
207 height = std::max(height, cancelButtonRect.size.height); 207 height = std::max(height, NSHeight(cancelButtonRect));
208 } 208 }
209 209
210 // Add the message label (and the link label) to the second row. 210 // Add the message label (and the link label) to the second row.
211 left = kButtonHEdgeMargin; 211 left = kButtonHEdgeMargin;
212 right = frameRect.size.width; 212 right = NSWidth(frameRect);
213 bottom += height + kRelatedControlVerticalSpacing; 213 bottom += height + kRelatedControlVerticalSpacing;
214 height = 0; 214 height = 0;
215 messageLabel_.reset([[ConfirmBubbleTextView alloc] 215 messageLabel_.reset([[ConfirmBubbleTextView alloc]
216 initWithFrame:NSMakeRect(left, bottom, kMaxMessageWidth, 0)]); 216 initWithFrame:NSMakeRect(left, bottom, kMaxMessageWidth, 0)]);
217 NSString* messageText = [controller_ messageText]; 217 NSString* messageText = [controller_ messageText];
218 NSMutableDictionary* attributes = [NSMutableDictionary dictionary]; 218 NSMutableDictionary* attributes = [NSMutableDictionary dictionary];
219 scoped_nsobject<NSMutableAttributedString> attributedMessage( 219 scoped_nsobject<NSMutableAttributedString> attributedMessage(
220 [[NSMutableAttributedString alloc] initWithString:messageText 220 [[NSMutableAttributedString alloc] initWithString:messageText
221 attributes:attributes]); 221 attributes:attributes]);
222 NSString* linkText = [controller_ linkText]; 222 NSString* linkText = [controller_ linkText];
223 if (linkText) { 223 if (linkText) {
224 scoped_nsobject<NSAttributedString> whiteSpace( 224 scoped_nsobject<NSAttributedString> whiteSpace(
225 [[NSAttributedString alloc] initWithString:@" "]); 225 [[NSAttributedString alloc] initWithString:@" "]);
226 [attributedMessage.get() appendAttributedString:whiteSpace.get()]; 226 [attributedMessage.get() appendAttributedString:whiteSpace.get()];
227 [attributes setObject:[NSString string] 227 [attributes setObject:[NSString string]
228 forKey:NSLinkAttributeName]; 228 forKey:NSLinkAttributeName];
229 scoped_nsobject<NSAttributedString> attributedLink( 229 scoped_nsobject<NSAttributedString> attributedLink(
230 [[NSAttributedString alloc] initWithString:linkText 230 [[NSAttributedString alloc] initWithString:linkText
231 attributes:attributes]); 231 attributes:attributes]);
232 [attributedMessage.get() appendAttributedString:attributedLink.get()]; 232 [attributedMessage.get() appendAttributedString:attributedLink.get()];
233 } 233 }
234 [[messageLabel_.get() textStorage] setAttributedString:attributedMessage]; 234 [[messageLabel_.get() textStorage] setAttributedString:attributedMessage];
235 [messageLabel_.get() setHorizontallyResizable:NO]; 235 [messageLabel_.get() setHorizontallyResizable:NO];
236 [messageLabel_.get() setVerticallyResizable:YES]; 236 [messageLabel_.get() setVerticallyResizable:YES];
237 [messageLabel_.get() setEditable:NO]; 237 [messageLabel_.get() setEditable:NO];
238 [messageLabel_.get() setDrawsBackground:NO]; 238 [messageLabel_.get() setDrawsBackground:NO];
239 [messageLabel_.get() setDelegate:self]; 239 [messageLabel_.get() setDelegate:self];
240 [messageLabel_.get() sizeToFit]; 240 [messageLabel_.get() sizeToFit];
241 height = [messageLabel_.get() frame].size.height; 241 height = NSHeight([messageLabel_.get() frame]);
242 [self addSubview:messageLabel_.get()]; 242 [self addSubview:messageLabel_.get()];
243 243
244 // Add the icon and the title label to the third row. 244 // Add the icon and the title label to the third row.
245 left = kButtonHEdgeMargin; 245 left = kButtonHEdgeMargin;
246 right = frameRect.size.width; 246 right = NSWidth(frameRect);
247 bottom += height + kLabelToControlVerticalSpacing; 247 bottom += height + kLabelToControlVerticalSpacing;
248 height = 0; 248 height = 0;
249 NSImage* iconImage = [controller_ icon]; 249 NSImage* iconImage = [controller_ icon];
250 if (iconImage) { 250 if (iconImage) {
251 icon_.reset([[NSImageView alloc] initWithFrame:NSMakeRect( 251 icon_.reset([[NSImageView alloc] initWithFrame:NSMakeRect(
252 left, bottom, [iconImage size].width, [iconImage size].height)]); 252 left, bottom, [iconImage size].width, [iconImage size].height)]);
253 [icon_.get() setImage:iconImage]; 253 [icon_.get() setImage:iconImage];
254 [self addSubview:icon_.get()]; 254 [self addSubview:icon_.get()];
255 left += [icon_.get() frame].size.width + kRelatedControlHorizontalSpacing; 255 left += NSWidth([icon_.get() frame]) + kRelatedControlHorizontalSpacing;
256 height = std::max(height, [icon_.get() frame].size.height); 256 height = std::max(height, NSHeight([icon_.get() frame]));
257 } 257 }
258 titleLabel_.reset([[NSTextView alloc] 258 titleLabel_.reset([[NSTextView alloc]
259 initWithFrame:NSMakeRect(left, bottom, right - left, 0)]); 259 initWithFrame:NSMakeRect(left, bottom, right - left, 0)]);
260 [titleLabel_.get() setString:[controller_ title]]; 260 [titleLabel_.get() setString:[controller_ title]];
261 [titleLabel_.get() setHorizontallyResizable:NO]; 261 [titleLabel_.get() setHorizontallyResizable:NO];
262 [titleLabel_.get() setVerticallyResizable:YES]; 262 [titleLabel_.get() setVerticallyResizable:YES];
263 [titleLabel_.get() setEditable:NO]; 263 [titleLabel_.get() setEditable:NO];
264 [titleLabel_.get() setSelectable:NO]; 264 [titleLabel_.get() setSelectable:NO];
265 [titleLabel_.get() setDrawsBackground:NO]; 265 [titleLabel_.get() setDrawsBackground:NO];
266 [titleLabel_.get() sizeToFit]; 266 [titleLabel_.get() sizeToFit];
267 [self addSubview:titleLabel_.get()]; 267 [self addSubview:titleLabel_.get()];
268 height = std::max(height, [titleLabel_.get() frame].size.height); 268 height = std::max(height, NSHeight([titleLabel_.get() frame]));
269 269
270 // Adjust the frame rectangle of this bubble so we can show all controls. 270 // Adjust the frame rectangle of this bubble so we can show all controls.
271 NSRect parentRect = [parent_ frame]; 271 NSRect parentRect = [parent_ frame];
272 frameRect.size.height = bottom + height + kButtonVEdgeMargin; 272 frameRect.size.height = bottom + height + kButtonVEdgeMargin;
273 frameRect.origin.x = (parentRect.size.width - frameRect.size.width) / 2; 273 frameRect.origin.x = (NSWidth(parentRect) - NSWidth(frameRect)) / 2;
274 frameRect.origin.y = parentRect.size.height - frameRect.size.height; 274 frameRect.origin.y = NSHeight(parentRect) - NSHeight(frameRect);
275 [self setFrame:frameRect]; 275 [self setFrame:frameRect];
276 } 276 }
277 277
278 // Closes this bubble and releases all resources. This function just puts the 278 // Closes this bubble and releases all resources. This function just puts the
279 // owner ConfirmBubbleController object to the current autorelease pool. (This 279 // owner ConfirmBubbleController object to the current autorelease pool. (This
280 // view will be deleted when the owner object is deleted.) 280 // view will be deleted when the owner object is deleted.)
281 - (void)closeBubble { 281 - (void)closeBubble {
282 [self removeFromSuperview]; 282 [self removeFromSuperview];
283 [controller_ autorelease]; 283 [controller_ autorelease];
284 parent_ = nil; 284 parent_ = nil;
(...skipping 10 matching lines...) Expand all
295 295
296 - (void)clickCancel { 296 - (void)clickCancel {
297 [self cancel:self]; 297 [self cancel:self];
298 } 298 }
299 299
300 - (void)clickLink { 300 - (void)clickLink {
301 [self textView:messageLabel_.get() clickedOnLink:nil atIndex:0]; 301 [self textView:messageLabel_.get() clickedOnLink:nil atIndex:0];
302 } 302 }
303 303
304 @end 304 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698