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

Side by Side Diff: chrome/browser/ui/cocoa/infobars/infobar_controller.mm

Issue 7601028: [Mac] Polish the infobars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typo Created 9 years, 4 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 | « DEPS ('k') | chrome/browser/ui/cocoa/translate/before_translate_infobar_controller.mm » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/logging.h" // for NOTREACHED() 7 #include "base/logging.h" // for NOTREACHED()
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
11 #include "chrome/browser/tab_contents/link_infobar_delegate.h" 11 #include "chrome/browser/tab_contents/link_infobar_delegate.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
13 #import "chrome/browser/ui/cocoa/animatable_view.h" 13 #import "chrome/browser/ui/cocoa/animatable_view.h"
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #include "chrome/browser/ui/cocoa/event_utils.h" 15 #include "chrome/browser/ui/cocoa/event_utils.h"
16 #include "chrome/browser/ui/cocoa/infobars/infobar.h" 16 #include "chrome/browser/ui/cocoa/infobars/infobar.h"
17 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 17 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
18 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" 18 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h"
19 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" 19 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h"
20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
21 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 21 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
22 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
23 #include "webkit/glue/window_open_disposition.h" 23 #include "webkit/glue/window_open_disposition.h"
24 24
25 namespace { 25 namespace {
26 // Durations set to match the default SlideAnimation duration. 26 // Durations set to match the default SlideAnimation duration.
27 const float kAnimateOpenDuration = 0.12; 27 const float kAnimateOpenDuration = 0.12;
28 const float kAnimateCloseDuration = 0.12; 28 const float kAnimateCloseDuration = 0.12;
29
30 // The baseline shift for text in the NSTextView.
31 const float kTextBaselineShift = -1.0;
29 } 32 }
30 33
31 // This simple subclass of |NSTextView| just doesn't show the (text) cursor 34 // This simple subclass of |NSTextView| just doesn't show the (text) cursor
32 // (|NSTextView| displays the cursor with full keyboard accessibility enabled). 35 // (|NSTextView| displays the cursor with full keyboard accessibility enabled).
33 @interface InfoBarTextView : NSTextView 36 @interface InfoBarTextView : NSTextView
34 - (void)fixupCursor; 37 - (void)fixupCursor;
35 @end 38 @end
36 39
37 @implementation InfoBarTextView 40 @implementation InfoBarTextView
38 41
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 229 }
227 230
228 - (void)setLabelToMessage:(NSString*)message { 231 - (void)setLabelToMessage:(NSString*)message {
229 NSMutableDictionary* attributes = [NSMutableDictionary dictionary]; 232 NSMutableDictionary* attributes = [NSMutableDictionary dictionary];
230 NSFont* font = [NSFont labelFontOfSize: 233 NSFont* font = [NSFont labelFontOfSize:
231 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; 234 [NSFont systemFontSizeForControlSize:NSRegularControlSize]];
232 [attributes setObject:font 235 [attributes setObject:font
233 forKey:NSFontAttributeName]; 236 forKey:NSFontAttributeName];
234 [attributes setObject:[NSCursor arrowCursor] 237 [attributes setObject:[NSCursor arrowCursor]
235 forKey:NSCursorAttributeName]; 238 forKey:NSCursorAttributeName];
239 [attributes setObject:[NSNumber numberWithFloat:kTextBaselineShift]
240 forKey:NSBaselineOffsetAttributeName];
236 scoped_nsobject<NSAttributedString> attributedString( 241 scoped_nsobject<NSAttributedString> attributedString(
237 [[NSAttributedString alloc] initWithString:message 242 [[NSAttributedString alloc] initWithString:message
238 attributes:attributes]); 243 attributes:attributes]);
239 [[label_.get() textStorage] setAttributedString:attributedString]; 244 [[label_.get() textStorage] setAttributedString:attributedString];
240 } 245 }
241 246
242 - (void)removeButtons { 247 - (void)removeButtons {
243 // Extend the label all the way across. 248 // Extend the label all the way across.
244 NSRect labelFrame = [label_.get() frame]; 249 NSRect labelFrame = [label_.get() frame];
245 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame); 250 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 - (void)setLabelToMessage:(NSString*)message 319 - (void)setLabelToMessage:(NSString*)message
315 withLink:(NSString*)link 320 withLink:(NSString*)link
316 atOffset:(NSUInteger)linkOffset { 321 atOffset:(NSUInteger)linkOffset {
317 if (linkOffset == std::wstring::npos) { 322 if (linkOffset == std::wstring::npos) {
318 // linkOffset == std::wstring::npos means the link should be right-aligned, 323 // linkOffset == std::wstring::npos means the link should be right-aligned,
319 // which is not supported on Mac (http://crbug.com/47728). 324 // which is not supported on Mac (http://crbug.com/47728).
320 NOTIMPLEMENTED(); 325 NOTIMPLEMENTED();
321 linkOffset = [message length]; 326 linkOffset = [message length];
322 } 327 }
323 // Create an attributes dictionary for the entire message. We have 328 // Create an attributes dictionary for the entire message. We have
324 // to expicitly set the font the control's font. We also override 329 // to explicitly set the control's font. We also override the cursor to give
325 // the cursor to give us the normal cursor rather than the text 330 // us the normal cursor rather than the text insertion cursor.
326 // insertion cursor.
327 NSMutableDictionary* linkAttributes = [NSMutableDictionary dictionary]; 331 NSMutableDictionary* linkAttributes = [NSMutableDictionary dictionary];
328 [linkAttributes setObject:[NSCursor arrowCursor] 332 [linkAttributes setObject:[NSCursor arrowCursor]
329 forKey:NSCursorAttributeName]; 333 forKey:NSCursorAttributeName];
330 NSFont* font = [NSFont labelFontOfSize: 334 NSFont* font = [NSFont labelFontOfSize:
331 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]; 335 [NSFont systemFontSizeForControlSize:NSRegularControlSize]];
332 [linkAttributes setObject:font 336 [linkAttributes setObject:font
333 forKey:NSFontAttributeName]; 337 forKey:NSFontAttributeName];
334 338
335 // Create the attributed string for the main message text. 339 // Create the attributed string for the main message text.
336 scoped_nsobject<NSMutableAttributedString> infoText( 340 scoped_nsobject<NSMutableAttributedString> infoText(
(...skipping 12 matching lines...) Expand all
349 forKey:NSUnderlineStyleAttributeName]; 353 forKey:NSUnderlineStyleAttributeName];
350 [linkAttributes setObject:[NSString string] // dummy value 354 [linkAttributes setObject:[NSString string] // dummy value
351 forKey:NSLinkAttributeName]; 355 forKey:NSLinkAttributeName];
352 356
353 // Insert the link text into the string at the appropriate offset. 357 // Insert the link text into the string at the appropriate offset.
354 scoped_nsobject<NSAttributedString> attributedString( 358 scoped_nsobject<NSAttributedString> attributedString(
355 [[NSAttributedString alloc] initWithString:link 359 [[NSAttributedString alloc] initWithString:link
356 attributes:linkAttributes]); 360 attributes:linkAttributes]);
357 [infoText.get() insertAttributedString:attributedString.get() 361 [infoText.get() insertAttributedString:attributedString.get()
358 atIndex:linkOffset]; 362 atIndex:linkOffset];
363 // The entire text needs a baseline shift.
364 [infoText addAttribute:NSBaselineOffsetAttributeName
365 value:[NSNumber numberWithDouble:kTextBaselineShift]
366 range:NSMakeRange(0, [infoText length])];
367
359 // Update the label view with the new text. 368 // Update the label view with the new text.
360 [[label_.get() textStorage] setAttributedString:infoText]; 369 [[label_.get() textStorage] setAttributedString:infoText];
361 } 370 }
362 371
363 - (NSPoint)pointForTipApex { 372 - (NSPoint)pointForTipApex {
364 BrowserWindowController* windowController = 373 BrowserWindowController* windowController =
365 [containerController_ browserWindowController]; 374 [containerController_ browserWindowController];
366 if (!windowController) { 375 if (!windowController) {
367 // This should only happen in unit tests. 376 // This should only happen in unit tests.
368 return NSZeroPoint; 377 return NSZeroPoint;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 LinkInfoBarController* controller = 562 LinkInfoBarController* controller =
554 [[LinkInfoBarController alloc] initWithDelegate:this owner:owner]; 563 [[LinkInfoBarController alloc] initWithDelegate:this owner:owner];
555 return new InfoBar(controller, this); 564 return new InfoBar(controller, this);
556 } 565 }
557 566
558 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { 567 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) {
559 ConfirmInfoBarController* controller = 568 ConfirmInfoBarController* controller =
560 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; 569 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner];
561 return new InfoBar(controller, this); 570 return new InfoBar(controller, this);
562 } 571 }
OLDNEW
« no previous file with comments | « DEPS ('k') | chrome/browser/ui/cocoa/translate/before_translate_infobar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698