Index: ui/gfx/render_text_harfbuzz.cc |
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc |
index 1db7d40e4c46d88dfd1ca17704fb2f1071bc2417..912ebb2e555962bace34df0facaeb2590dedac04 100644 |
--- a/ui/gfx/render_text_harfbuzz.cc |
+++ b/ui/gfx/render_text_harfbuzz.cc |
@@ -896,19 +896,24 @@ SelectionModel RenderTextHarfBuzz::FindCursorPosition(const Point& view_point) { |
DCHECK(!lines().empty()); |
int line_index = GetLineContainingYCoord((view_point - GetLineOffset(0)).y()); |
- // Clip line index to a valid value in case kDragToEndIfOutsideVerticalBounds |
- // is false. Else, drag to end. |
+ // Handle kDragToEndIfOutsideVerticalBounds above or below the text in a |
+ // single-line by extending towards the mouse cursor. |
+ if (RenderText::kDragToEndIfOutsideVerticalBounds && !multiline() && |
+ (line_index < 0 || line_index >= static_cast<int>(lines().size()))) { |
+ SelectionModel selection_start = GetSelectionModelForSelectionStart(); |
+ bool left = view_point.x() < GetCursorBounds(selection_start, true).x(); |
+ return EdgeSelectionModel(left ? CURSOR_LEFT : CURSOR_RIGHT); |
+ } |
+ // Otherwise, clamp |line_index| to a valid value or drag to logical ends. |
if (line_index < 0) { |
if (RenderText::kDragToEndIfOutsideVerticalBounds) |
return EdgeSelectionModel(GetVisualDirectionOfLogicalBeginning()); |
- else |
- line_index = 0; |
+ line_index = 0; |
} |
if (line_index >= static_cast<int>(lines().size())) { |
if (RenderText::kDragToEndIfOutsideVerticalBounds) |
return EdgeSelectionModel(GetVisualDirectionOfLogicalEnd()); |
- else |
- line_index = lines().size() - 1; |
+ line_index = lines().size() - 1; |
} |
const internal::Line& line = lines()[line_index]; |