Commit 5b217ee7 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Make LabelLink working with unbreakable spaces

When the LabelLink is displaying a text containing an unbreakable space,
the unbreakable space is preventing two words from being broken at the
end of a line. However, the ManualTextFramer used to get the position of
the link isn't respecting the unbreakable spaces.
So the displayed text isn't breaking the words at the end of the line
but the link is positioned as if the words were broken. So the position
of the link is wrong.

Bug: 872290
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I9b2bae32a47e19b14c397e230aade87b3cb88157
Reviewed-on: https://chromium-review.googlesource.com/1169014
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582098}
parent 2b29d1e4
......@@ -340,6 +340,7 @@ NSArray* GetParagraphStringsForString(NSAttributedString* string) {
NSMutableCharacterSet* lineEndSet =
[NSMutableCharacterSet whitespaceAndNewlineCharacterSet];
[lineEndSet addCharactersInString:@"-\u2013\u2014"];
[lineEndSet removeCharactersInString:@"\u00A0"];
_lineEndSet = lineEndSet;
}
return _lineEndSet;
......
......@@ -108,6 +108,20 @@ TEST_F(ManualTextFramerTest, NoSpacesText) {
CheckForLineCountAndFramedRange(0, NSMakeRange(0, 0));
}
// Tests that unbreakable spaces are accounted for.
TEST_F(ManualTextFramerTest, UnbreakableSpace) {
SetText(@"This is a long text with\u00A0unbreakable\u00A0spaces");
attributes()[NSFontAttributeName] = TypographyFontWithSize(16.0);
attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
ApplyAttributesForRange(text_range());
CGRect bounds = CGRectMake(0, 0, 200, 60);
FrameTextInBounds(bounds);
ASSERT_EQ(2UL, text_frame().lines.count);
FramedLine* line = text_frame().lines[1];
EXPECT_TRUE(NSEqualRanges(NSMakeRange(20, 23), line.stringRange));
}
// Tests that multiple newlines are accounted for. Only the first three
// newlines should be added to |lines_|.
TEST_F(ManualTextFramerTest, MultipleNewlineTest) {
......
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