Commit 9d159f8f authored by jdonnelly's avatar jdonnelly Committed by Commit bot

Fix issue with broken links in HyperlinkTextView.

If a link in a HyperlinkTextView does not begin at the start of the text
then a click that looks like a potential text selection will fail to
activate the link.

BUG=626021

Review-Url: https://codereview.chromium.org/2440913003
Cr-Commit-Position: refs/heads/master@{#427111}
parent 2803b8ef
......@@ -54,8 +54,12 @@ const float kTextBaselineShift = -1.0;
- (NSRange)selectionRangeForProposedRange:(NSRange)proposedSelRange
granularity:(NSSelectionGranularity)granularity {
// Do not allow selections.
return NSMakeRange(0, 0);
// Return a range of length 0 to prevent text selection. Note that the start
// of the range (the first argument) is treated as the position of the
// subsequent click so it must not be 0. If it is, links that begin at a
// non-zero position in the text will not function correctly when they are
// clicked in such a way as to look like a possible text selection.
return NSMakeRange(proposedSelRange.location, 0);
}
// Convince NSTextView to not show an I-Beam cursor when the cursor is over the
......
......@@ -58,6 +58,20 @@ class HyperlinkTextViewTest : public ui::CocoaTest {
TEST_VIEW(HyperlinkTextViewTest, view_);
TEST_F(HyperlinkTextViewTest, TestSelectionRange) {
NSRange actualRange;
// The length of the selection range should be 0.
actualRange = [view_ selectionRangeForProposedRange:NSMakeRange(0, 20)
granularity:NSSelectByCharacter];
EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, 0), actualRange));
// While the location should always match the location of the proposed range.
actualRange = [view_ selectionRangeForProposedRange:NSMakeRange(50, 100)
granularity:NSSelectByCharacter];
EXPECT_TRUE(NSEqualRanges(NSMakeRange(50, 0), actualRange));
}
TEST_F(HyperlinkTextViewTest, TestViewConfiguration) {
EXPECT_FALSE([view_ isEditable]);
EXPECT_FALSE([view_ drawsBackground]);
......
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