OLD | NEW |
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 "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 5 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 | 8 |
9 // The baseline shift for text in the NSTextView. | 9 // The baseline shift for text in the NSTextView. |
10 const float kTextBaselineShift = -1.0; | 10 const float kTextBaselineShift = -1.0; |
11 | 11 |
12 @interface HyperlinkTextView(Private) | 12 @interface HyperlinkTextView(Private) |
13 // Initialize the NSTextView properties for this subclass. | 13 // Initialize the NSTextView properties for this subclass. |
14 - (void)configureTextView; | 14 - (void)configureTextView; |
15 | 15 |
16 // Change the current IBeamCursor to an arrowCursor. | 16 // Change the current IBeamCursor to an arrowCursor. |
17 - (void)fixupCursor; | 17 - (void)fixupCursor; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 [attributes setObject:messageColor | 89 [attributes setObject:messageColor |
90 forKey:NSForegroundColorAttributeName]; | 90 forKey:NSForegroundColorAttributeName]; |
91 [attributes setObject:[NSCursor arrowCursor] | 91 [attributes setObject:[NSCursor arrowCursor] |
92 forKey:NSCursorAttributeName]; | 92 forKey:NSCursorAttributeName]; |
93 [attributes setObject:font | 93 [attributes setObject:font |
94 forKey:NSFontAttributeName]; | 94 forKey:NSFontAttributeName]; |
95 [attributes setObject:[NSNumber numberWithFloat:kTextBaselineShift] | 95 [attributes setObject:[NSNumber numberWithFloat:kTextBaselineShift] |
96 forKey:NSBaselineOffsetAttributeName]; | 96 forKey:NSBaselineOffsetAttributeName]; |
97 | 97 |
98 // Create the attributed string for the message. | 98 // Create the attributed string for the message. |
99 scoped_nsobject<NSMutableAttributedString> attributedMessage( | 99 base::scoped_nsobject<NSMutableAttributedString> attributedMessage( |
100 [[NSMutableAttributedString alloc] initWithString:message | 100 [[NSMutableAttributedString alloc] initWithString:message |
101 attributes:attributes]); | 101 attributes:attributes]); |
102 | 102 |
103 if ([link length] != 0) { | 103 if ([link length] != 0) { |
104 // Add additional attributes to style the link text appropriately as | 104 // Add additional attributes to style the link text appropriately as |
105 // well as linkify it. | 105 // well as linkify it. |
106 [attributes setObject:linkColor | 106 [attributes setObject:linkColor |
107 forKey:NSForegroundColorAttributeName]; | 107 forKey:NSForegroundColorAttributeName]; |
108 [attributes setObject:[NSNumber numberWithBool:YES] | 108 [attributes setObject:[NSNumber numberWithBool:YES] |
109 forKey:NSUnderlineStyleAttributeName]; | 109 forKey:NSUnderlineStyleAttributeName]; |
110 [attributes setObject:[NSCursor pointingHandCursor] | 110 [attributes setObject:[NSCursor pointingHandCursor] |
111 forKey:NSCursorAttributeName]; | 111 forKey:NSCursorAttributeName]; |
112 [attributes setObject:[NSNumber numberWithInt:NSSingleUnderlineStyle] | 112 [attributes setObject:[NSNumber numberWithInt:NSSingleUnderlineStyle] |
113 forKey:NSUnderlineStyleAttributeName]; | 113 forKey:NSUnderlineStyleAttributeName]; |
114 [attributes setObject:[NSString string] // dummy value | 114 [attributes setObject:[NSString string] // dummy value |
115 forKey:NSLinkAttributeName]; | 115 forKey:NSLinkAttributeName]; |
116 | 116 |
117 // Insert the link into the message at the appropriate offset. | 117 // Insert the link into the message at the appropriate offset. |
118 scoped_nsobject<NSAttributedString> attributedLink( | 118 base::scoped_nsobject<NSAttributedString> attributedLink( |
119 [[NSAttributedString alloc] initWithString:link | 119 [[NSAttributedString alloc] initWithString:link attributes:attributes]); |
120 attributes:attributes]); | |
121 [attributedMessage.get() insertAttributedString:attributedLink.get() | 120 [attributedMessage.get() insertAttributedString:attributedLink.get() |
122 atIndex:linkOffset]; | 121 atIndex:linkOffset]; |
123 // Ensure the TextView doesn't override the link style. | 122 // Ensure the TextView doesn't override the link style. |
124 [self setLinkTextAttributes:attributes]; | 123 [self setLinkTextAttributes:attributes]; |
125 } | 124 } |
126 | 125 |
127 // Update the text view with the new text. | 126 // Update the text view with the new text. |
128 [[self textStorage] setAttributedString:attributedMessage]; | 127 [[self textStorage] setAttributedString:attributedMessage]; |
129 } | 128 } |
130 | 129 |
131 @end | 130 @end |
OLD | NEW |