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

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 2903193003: MacViews: Tweak kDragToEndIfOutsideVerticalBounds for single line fields. (Closed)
Patch Set: respond to comments Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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];
« no previous file with comments | « no previous file | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698