| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/cocoa/hyperlink_button_cell.h" |
| 6 |
| 7 @interface HyperlinkButtonCell (Private) |
| 8 - (NSDictionary*)linkAttributres; |
| 9 - (void)customizeButtonCell; |
| 10 @end |
| 11 |
| 12 @implementation HyperlinkButtonCell |
| 13 @dynamic textColor; |
| 14 |
| 15 // Designated initializer. |
| 16 - (id)init { |
| 17 if ((self = [super init])) { |
| 18 [self customizeButtonCell]; |
| 19 } |
| 20 return self; |
| 21 } |
| 22 |
| 23 // Initializer called when the cell is loaded from the NIB. |
| 24 - (id)initWithCoder:(NSCoder*)aDecoder { |
| 25 if ((self = [super initWithCoder:aDecoder])) { |
| 26 [self customizeButtonCell]; |
| 27 } |
| 28 return self; |
| 29 } |
| 30 |
| 31 // Initializer for code-based creation. |
| 32 - (id)initTextCell:(NSString*)title { |
| 33 if ((self = [super initTextCell:title])) { |
| 34 [self customizeButtonCell]; |
| 35 } |
| 36 return self; |
| 37 } |
| 38 |
| 39 // Because an NSButtonCell has multiple initializers, this method performs the |
| 40 // common cell customization code. |
| 41 - (void)customizeButtonCell { |
| 42 [self setBordered:NO]; |
| 43 [self setTextColor:[NSColor blueColor]]; |
| 44 |
| 45 CGFloat fontSize = [NSFont systemFontSizeForControlSize:[self controlSize]]; |
| 46 NSFont* font = [NSFont controlContentFontOfSize:fontSize]; |
| 47 [self setFont:font]; |
| 48 |
| 49 // Do not change button appearance when we are pushed. |
| 50 // TODO(rsesek): Change text color to red? |
| 51 [self setHighlightsBy:NSNoCellMask]; |
| 52 |
| 53 // We need to set this so that we can override |-mouseEntered:| and |
| 54 // |-mouseExited:| to change the cursor style on hover states. |
| 55 [self setShowsBorderOnlyWhileMouseInside:YES]; |
| 56 } |
| 57 |
| 58 // Creates the NSDictionary of attributes for the attributed string. |
| 59 - (NSDictionary*)linkAttributes { |
| 60 NSUInteger underlineMask = NSUnderlinePatternSolid | NSUnderlineStyleSingle; |
| 61 NSMutableParagraphStyle* paragraphStyle = |
| 62 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; |
| 63 [paragraphStyle setAlignment:[self alignment]]; |
| 64 |
| 65 return [NSDictionary dictionaryWithObjectsAndKeys: |
| 66 [self textColor], NSForegroundColorAttributeName, |
| 67 [NSNumber numberWithInt:underlineMask], NSUnderlineStyleAttributeName, |
| 68 [self font], NSFontAttributeName, |
| 69 [NSCursor pointingHandCursor], NSCursorAttributeName, |
| 70 paragraphStyle, NSParagraphStyleAttributeName, |
| 71 nil |
| 72 ]; |
| 73 } |
| 74 |
| 75 // Override the drawing point for the cell so that the custom style attributes |
| 76 // can always be applied. |
| 77 - (NSRect)drawTitle:(NSAttributedString*)title |
| 78 withFrame:(NSRect)frame |
| 79 inView:(NSView*)controlView { |
| 80 NSAttributedString* attrString = |
| 81 [[NSAttributedString alloc] initWithString:[title string] |
| 82 attributes:[self linkAttributes]]; |
| 83 [attrString autorelease]; |
| 84 return [super drawTitle:attrString withFrame:frame inView:controlView]; |
| 85 } |
| 86 |
| 87 // Override the default behavior to draw the border. Instead, change the cursor. |
| 88 - (void)mouseEntered:(NSEvent*)event { |
| 89 [[NSCursor pointingHandCursor] push]; |
| 90 } |
| 91 |
| 92 - (void)mouseExited:(NSEvent*)event { |
| 93 [NSCursor pop]; |
| 94 } |
| 95 |
| 96 // Setters and getters. |
| 97 - (NSColor*)textColor { |
| 98 return textColor_.get(); |
| 99 } |
| 100 |
| 101 - (void)setTextColor:(NSColor*)color { |
| 102 textColor_.reset(color); |
| 103 } |
| 104 |
| 105 @end |
| OLD | NEW |