OLD | NEW |
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/hyperlink_button_cell.h" | 5 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
6 | 6 |
7 @interface HyperlinkButtonCell () | 7 @interface HyperlinkButtonCell () |
8 - (void)customizeButtonCell; | 8 - (void)customizeButtonCell; |
9 @end | 9 @end |
10 | 10 |
11 @implementation HyperlinkButtonCell | 11 @implementation HyperlinkButtonCell |
12 | 12 |
13 @dynamic textColor; | 13 @dynamic textColor; |
14 @synthesize underlineOnHover = underlineOnHover_; | 14 @synthesize underlineOnHover = underlineOnHover_; |
15 @synthesize shouldUnderline = shouldUnderline_; | 15 @synthesize shouldUnderline = shouldUnderline_; |
16 | 16 |
17 + (NSColor*)defaultTextColor { | 17 + (NSColor*)defaultTextColor { |
18 return [NSColor blueColor]; | 18 return [NSColor blueColor]; |
19 } | 19 } |
20 | 20 |
21 + (NSButton*)buttonWithString:(NSString*)string { | 21 + (NSButton*)buttonWithString:(NSString*)string { |
22 NSButton* button = [[[NSButton alloc] initWithFrame:NSZeroRect] autorelease]; | 22 NSButton* button = [[[NSButton alloc] initWithFrame:NSZeroRect] autorelease]; |
23 scoped_nsobject<HyperlinkButtonCell> cell( | 23 base::scoped_nsobject<HyperlinkButtonCell> cell( |
24 [[HyperlinkButtonCell alloc] initTextCell:string]); | 24 [[HyperlinkButtonCell alloc] initTextCell:string]); |
25 [cell setAlignment:NSLeftTextAlignment]; | 25 [cell setAlignment:NSLeftTextAlignment]; |
26 [button setCell:cell.get()]; | 26 [button setCell:cell.get()]; |
27 [button setBezelStyle:NSRegularSquareBezelStyle]; | 27 [button setBezelStyle:NSRegularSquareBezelStyle]; |
28 return button; | 28 return button; |
29 } | 29 } |
30 | 30 |
31 // Designated initializer. | 31 // Designated initializer. |
32 - (id)init { | 32 - (id)init { |
33 if ((self = [super init])) { | 33 if ((self = [super init])) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 [self customizeButtonCell]; // recompute |font|. | 76 [self customizeButtonCell]; // recompute |font|. |
77 } | 77 } |
78 | 78 |
79 // Creates the NSDictionary of attributes for the attributed string. | 79 // Creates the NSDictionary of attributes for the attributed string. |
80 - (NSDictionary*)linkAttributes { | 80 - (NSDictionary*)linkAttributes { |
81 NSUInteger underlineMask = NSNoUnderlineStyle; | 81 NSUInteger underlineMask = NSNoUnderlineStyle; |
82 if (shouldUnderline_ && | 82 if (shouldUnderline_ && |
83 (!underlineOnHover_ || (mouseIsInside_ && [self isEnabled]))) | 83 (!underlineOnHover_ || (mouseIsInside_ && [self isEnabled]))) |
84 underlineMask = NSUnderlinePatternSolid | NSUnderlineStyleSingle; | 84 underlineMask = NSUnderlinePatternSolid | NSUnderlineStyleSingle; |
85 | 85 |
86 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 86 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
87 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); | 87 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); |
88 [paragraphStyle setAlignment:[self alignment]]; | 88 [paragraphStyle setAlignment:[self alignment]]; |
89 [paragraphStyle setLineBreakMode:[self lineBreakMode]]; | 89 [paragraphStyle setLineBreakMode:[self lineBreakMode]]; |
90 | 90 |
91 return [NSDictionary dictionaryWithObjectsAndKeys: | 91 return [NSDictionary dictionaryWithObjectsAndKeys: |
92 [self textColor], NSForegroundColorAttributeName, | 92 [self textColor], NSForegroundColorAttributeName, |
93 [NSNumber numberWithInt:underlineMask], NSUnderlineStyleAttributeName, | 93 [NSNumber numberWithInt:underlineMask], NSUnderlineStyleAttributeName, |
94 [self font], NSFontAttributeName, | 94 [self font], NSFontAttributeName, |
95 [NSCursor pointingHandCursor], NSCursorAttributeName, | 95 [NSCursor pointingHandCursor], NSCursorAttributeName, |
96 paragraphStyle.get(), NSParagraphStyleAttributeName, | 96 paragraphStyle.get(), NSParagraphStyleAttributeName, |
97 nil | 97 nil |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 143 } |
144 | 144 |
145 // Override so that |-sizeToFit| works better with this type of cell. | 145 // Override so that |-sizeToFit| works better with this type of cell. |
146 - (NSSize)cellSize { | 146 - (NSSize)cellSize { |
147 NSSize size = [super cellSize]; | 147 NSSize size = [super cellSize]; |
148 size.width += 2; | 148 size.width += 2; |
149 return size; | 149 return size; |
150 } | 150 } |
151 | 151 |
152 @end | 152 @end |
OLD | NEW |