Commit f14f8f0e authored by shrike's avatar shrike Committed by Commit bot

Finished swap out of old API

Replaced occurrences of [HyperlinkTextView setMessageAndLink:withLink:
atOffset:font:messageColor:linkColor:] with
[HyperLinkTextView setMessage:withFont:messageColor] and
[HyperLinkTextView addLinkRange:withName:linkColor:]. Removed the
[HyperLinkTextView setMessageAndLink:withLink:...] method.

BUG=253755

TEST=it's very difficult to produce test sequences for most of these changes.
Here is the one sequence I do have:

for sad_tab_view_cocoa.mm: Launch Chrome, run
    ps augx | grep “Chrome Helper”
in a Terminal window, create a new tab and go to some page, run the ps...
commands again and figure out the process number of the new Chrome
Helper (the one that wasn’t there before). In a Terminal window type kill -9
<XXX> where <XXX> is the process id of the new Chrome Helper. Confirm
the new tab now shows the sad tab page and that the last line of text reads,
“If you're seeing this frequently, try these suggestions.” with the word
“suggestions” as a clickable link that takes you to the “Aw, Snap!” Chrome
help page.

Review URL: https://codereview.chromium.org/887823002

Cr-Commit-Position: refs/heads/master@{#315054}
parent e30fc9be
......@@ -30,15 +30,16 @@
size_t offset = base::string16::npos;
base::string16 message = delegate->GetMessageTextWithOffset(&offset);
base::string16 link = delegate->GetLinkText();
message.insert(offset, link);
NSFont* font = [NSFont labelFontOfSize:
[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
HyperlinkTextView* view = (HyperlinkTextView*)label_.get();
[view setMessageAndLink:base::SysUTF16ToNSString(message)
withLink:base::SysUTF16ToNSString(link)
atOffset:offset
font:font
messageColor:[NSColor blackColor]
linkColor:[NSColor blueColor]];
[view setMessage:base::SysUTF16ToNSString(message)
withFont:font
messageColor:[NSColor blackColor]];
[view addLinkRange:NSMakeRange(offset, link.length())
withName:@""
linkColor:[NSColor blueColor]];
}
// Called when someone clicks on the link in the infobar. This method
......
......@@ -108,20 +108,22 @@
// Set the text and link.
NSString* message = base::SysUTF16ToNSString(delegate->GetMessageText());
base::string16 link = delegate->GetLinkText();
if (!link.empty()) {
NSString* link = base::SysUTF16ToNSString(delegate->GetLinkText());
NSUInteger linkOffset = [message length];
NSUInteger linkLength = [link length];
if (linkLength != 0) {
// Add spacing between the label and the link.
message = [message stringByAppendingString:@" "];
message = [message stringByAppendingFormat:@" %@", link];
}
NSFont* font = [NSFont labelFontOfSize:
[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
HyperlinkTextView* view = (HyperlinkTextView*)label_.get();
[view setMessageAndLink:message
withLink:base::SysUTF16ToNSString(link)
atOffset:[message length]
font:font
messageColor:[NSColor blackColor]
linkColor:[NSColor blueColor]];
[view setMessage:message withFont:font messageColor:[NSColor blackColor]];
if (linkLength != 0) {
[view addLinkRange:NSMakeRange(linkOffset, linkLength)
withName:@""
linkColor:[NSColor blueColor]];
}
}
// Called when someone clicks on the link in the infobar. This method
......
......@@ -232,6 +232,7 @@ void ShiftOriginY(NSView* view, CGFloat amount) {
// Set the text.
NSString* learnMoreText = l10n_util::GetNSStringWithFixup(IDS_LEARN_MORE);
NSString* messageText;
NSUInteger learnMoreOffset = 0;
ui::ResourceBundle::FontStyle fontStyle = isSyncDialog_ ?
chrome_style::kTextFontStyle : ui::ResourceBundle::SmallFont;
......@@ -243,20 +244,21 @@ void ShiftOriginY(NSView* view, CGFloat amount) {
if (isSyncDialog_) {
messageText = l10n_util::GetNSStringFWithFixup(
IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE_NEW, email_);
messageText = [messageText stringByAppendingString:@" "];
learnMoreOffset = [messageText length];
messageText = [messageText stringByAppendingFormat:@" %@", learnMoreText];
} else {
messageText = @"";
messageText = learnMoreText;
}
NSColor* linkColor =
gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor());
[informativeTextView_ setMessageAndLink:messageText
withLink:learnMoreText
atOffset:[messageText length]
font:font
messageColor:[NSColor blackColor]
linkColor:linkColor];
[informativeTextView_ setMessage:messageText
withFont:font
messageColor:[NSColor blackColor]];
[informativeTextView_ addLinkRange:NSMakeRange(learnMoreOffset,
[learnMoreText length])
withName:@""
linkColor:linkColor];
// Make the "Advanced" link font as large as the "Learn More" link.
[[advancedLink_ cell] setFont:font];
......
......@@ -166,14 +166,17 @@ NSTextView* BuildFixedWidthTextViewWithLink(
[[HyperlinkTextView alloc] initWithFrame:NSZeroRect]);
NSColor* link_color = gfx::SkColorToCalibratedNSColor(
chrome_style::GetLinkColor());
NSMutableString* finalMessage =
[NSMutableString stringWithFormat:@"%@\n", message];
[finalMessage insertString:link atIndex:link_offset];
// Adds a padding row at the bottom, because |boundingRectWithSize| below cuts
// off the last row sometimes.
[text_view setMessageAndLink:[NSString stringWithFormat:@"%@\n", message]
withLink:link
atOffset:link_offset
font:[NSFont labelFontOfSize:kTextFontSize]
messageColor:[NSColor blackColor]
linkColor:link_color];
[text_view setMessage:finalMessage
withFont:[NSFont labelFontOfSize:kTextFontSize]
messageColor:[NSColor blackColor]];
[text_view addLinkRange:NSMakeRange(link_offset, [link length])
withName:@""
linkColor:link_color];
// Removes the underlining from the link.
[text_view setLinkTextAttributes:nil];
......
......@@ -92,12 +92,17 @@ NSTextView* AddTextView(
font_style).GetNativeFont();
NSColor* linkColor = gfx::SkColorToCalibratedNSColor(
chrome_style::GetLinkColor());
[textView setMessageAndLink:base::SysUTF16ToNSString(message)
withLink:base::SysUTF16ToNSString(link)
atOffset:offset
font:font
messageColor:[NSColor blackColor]
linkColor:linkColor];
NSMutableString* finalMessage = [NSMutableString stringWithString:
base::SysUTF16ToNSString(message)];
NSString* linkString = base::SysUTF16ToNSString(link);
[finalMessage insertString:linkString atIndex:offset];
[textView setMessage:finalMessage
withFont:font
messageColor:[NSColor blackColor]];
[textView addLinkRange:NSMakeRange(offset, [linkString length])
withName:@""
linkColor:linkColor];
RemoveUnderlining(textView, offset, link.size());
[textView setDelegate:delegate];
[parent addSubview:textView];
......
......@@ -176,16 +176,17 @@ static const CGFloat kTabHorzMargin = 13;
// Get the help text and link.
size_t linkOffset = 0;
const base::string16 helpLink =
l10n_util::GetStringUTF16(IDS_SAD_TAB_HELP_LINK);
NSString* helpMessage(base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(
IDS_SAD_TAB_HELP_MESSAGE, base::string16(), &linkOffset)));
NSString* helpLink = l10n_util::GetNSString(IDS_SAD_TAB_HELP_LINK);
IDS_SAD_TAB_HELP_MESSAGE, helpLink, &linkOffset)));
NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
[help_ setMessageAndLink:helpMessage
withLink:helpLink
atOffset:linkOffset
font:font
messageColor:[NSColor whiteColor]
linkColor:[NSColor whiteColor]];
[help_ setMessage:helpMessage
withFont:font
messageColor:[NSColor whiteColor]];
[help_ addLinkRange:NSMakeRange(linkOffset, helpLink.length())
withName:@""
linkColor:[NSColor whiteColor]];
[help_ setAlignment:NSCenterTextAlignment];
}
......
......@@ -20,16 +20,6 @@ UI_BASE_EXPORT
@property(nonatomic, assign) BOOL drawsBackgroundUsingSuperview;
// Convenience function that sets the |HyperlinkTextView| contents to the
// specified |message| with a hypertext style |link| inserted at |linkOffset|.
// Uses the supplied |font|, |messageColor|, and |linkColor|.
- (void)setMessageAndLink:(NSString*)message
withLink:(NSString*)link
atOffset:(NSUInteger)linkOffset
font:(NSFont*)font
messageColor:(NSColor*)messageColor
linkColor:(NSColor*)linkColor;
// Set the |message| displayed by the HyperlinkTextView, using |font| and
// |messageColor|.
- (void)setMessage:(NSString*)message
......
......@@ -101,22 +101,6 @@ const float kTextBaselineShift = -1.0;
[[NSCursor arrowCursor] set];
}
- (void)setMessageAndLink:(NSString*)message
withLink:(NSString*)link
atOffset:(NSUInteger)linkOffset
font:(NSFont*)font
messageColor:(NSColor*)messageColor
linkColor:(NSColor*)linkColor {
NSMutableString* finalMessage = [NSMutableString stringWithString:message];
[finalMessage insertString:link atIndex:linkOffset];
[self setMessage:finalMessage withFont:font messageColor:messageColor];
if ([link length] != 0) {
[self addLinkRange:NSMakeRange(linkOffset, [link length])
withName:@""
linkColor:linkColor];
}
}
- (void)setMessage:(NSString*)message
withFont:(NSFont*)font
messageColor:(NSColor*)messageColor {
......
......@@ -64,64 +64,6 @@ TEST_F(HyperlinkTextViewTest, TestViewConfiguration) {
EXPECT_FALSE([view_ isVerticallyResizable]);
}
TEST_F(HyperlinkTextViewTest, LinkInsertion) {
// Test that setMessage:withLink:... inserts the link text.
[view_ setMessageAndLink:@"This is a short text message"
withLink:@"alarmingly "
atOffset:10
font:GetDefaultFont()
messageColor:[NSColor blackColor]
linkColor:[NSColor blueColor]];
EXPECT_NSEQ(@"This is a alarmingly short text message",
[[view_ textStorage] string]);
// Test insertion at end - most common use case.
NSString* message=@"This is another test message ";
[view_ setMessageAndLink:message
withLink:@"with link"
atOffset:[message length]
font:GetDefaultFont()
messageColor:[NSColor blackColor]
linkColor:[NSColor blueColor]];
EXPECT_NSEQ(@"This is another test message with link",
[[view_ textStorage] string]);
}
TEST_F(HyperlinkTextViewTest, AttributesForMessageWithLink) {
// Verifies text attributes are set as expected for setMessageWithLink:...
[view_ setMessageAndLink:@"aaabbbbb"
withLink:@"xxxx"
atOffset:3
font:GetDefaultFont()
messageColor:[NSColor blackColor]
linkColor:[NSColor blueColor]];
NSDictionary* attributes;
NSRange rangeLimit = NSMakeRange(0, 12);
NSRange range;
attributes = [[view_ textStorage] attributesAtIndex:0
longestEffectiveRange:&range
inRange:rangeLimit];
EXPECT_EQ(0U, range.location);
EXPECT_EQ(3U, range.length);
EXPECT_NSEQ(GetDefaultTextAttributes(), attributes);
attributes = [[view_ textStorage] attributesAtIndex:3
longestEffectiveRange:&range
inRange:rangeLimit];
EXPECT_EQ(3U, range.location);
EXPECT_EQ(4U, range.length);
EXPECT_NSEQ(GetDefaultLinkAttributes(), attributes);
attributes = [[view_ textStorage] attributesAtIndex:7
longestEffectiveRange:&range
inRange:rangeLimit];
EXPECT_EQ(7U, range.location);
EXPECT_EQ(5U, range.length);
EXPECT_NSEQ(GetDefaultTextAttributes(), attributes);
}
TEST_F(HyperlinkTextViewTest, TestSetMessage) {
// Verifies setMessage sets text and attributes properly.
NSString* message = @"Test message";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment