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

Side by Side Diff: ui/base/cocoa/controls/hyperlink_text_view.mm

Issue 1364113003: Only (and always) put URLs in NSLinkAttributeName. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@infobar1
Patch Set: Created 5 years, 3 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
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 "ui/base/cocoa/controls/hyperlink_text_view.h" 5 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
6 6
7 #include "base/logging.h"
7 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
8 #include "ui/base/cocoa/nsview_additions.h" 9 #include "ui/base/cocoa/nsview_additions.h"
9 10
10 // The baseline shift for text in the NSTextView. 11 // The baseline shift for text in the NSTextView.
11 const float kTextBaselineShift = -1.0; 12 const float kTextBaselineShift = -1.0;
12 13
13 @interface HyperlinkTextView(Private) 14 @interface HyperlinkTextView(Private)
14 // Initialize the NSTextView properties for this subclass. 15 // Initialize the NSTextView properties for this subclass.
15 - (void)configureTextView; 16 - (void)configureTextView;
16 17
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Create the attributed string for the message. 116 // Create the attributed string for the message.
116 base::scoped_nsobject<NSAttributedString> attributedMessage( 117 base::scoped_nsobject<NSAttributedString> attributedMessage(
117 [[NSMutableAttributedString alloc] initWithString:message 118 [[NSMutableAttributedString alloc] initWithString:message
118 attributes:attributes]); 119 attributes:attributes]);
119 120
120 // Update the text view with the new text. 121 // Update the text view with the new text.
121 [[self textStorage] setAttributedString:attributedMessage]; 122 [[self textStorage] setAttributedString:attributedMessage];
122 } 123 }
123 124
124 - (void)addLinkRange:(NSRange)range 125 - (void)addLinkRange:(NSRange)range
125 withName:(id)name 126 withURL:(NSString*)url
126 linkColor:(NSColor*)linkColor { 127 linkColor:(NSColor*)linkColor {
128 // When the NSLinkAttributeName attribute is used, AppKit makes the link
129 // draggable. If no URL is provided, dropping it on the tab strip will crash
130 // <http://crbug.com/528228>. Require that a URL is used, and that only a URL
131 // is used.
132 DCHECK_GE([url length], 0u);
133 DCHECK([NSURL URLWithString:url]);
127 NSDictionary* attributes = @{ 134 NSDictionary* attributes = @{
128 NSForegroundColorAttributeName : linkColor, 135 NSForegroundColorAttributeName : linkColor,
129 NSUnderlineStyleAttributeName : @(YES), 136 NSUnderlineStyleAttributeName : @(YES),
130 NSCursorAttributeName : [NSCursor pointingHandCursor], 137 NSCursorAttributeName : [NSCursor pointingHandCursor],
131 NSLinkAttributeName : name, 138 NSLinkAttributeName : url,
132 NSUnderlineStyleAttributeName : @(NSSingleUnderlineStyle) 139 NSUnderlineStyleAttributeName : @(NSSingleUnderlineStyle)
133 }; 140 };
134 141
135 [[self textStorage] addAttributes:attributes range:range]; 142 [[self textStorage] addAttributes:attributes range:range];
136 } 143 }
137 144
138 - (void)setRefusesFirstResponder:(BOOL)refusesFirstResponder { 145 - (void)setRefusesFirstResponder:(BOOL)refusesFirstResponder {
139 refusesFirstResponder_ = refusesFirstResponder; 146 refusesFirstResponder_ = refusesFirstResponder;
140 } 147 }
141 148
142 @end 149 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698