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

Side by Side 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, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text_harfbuzz.h" 5 #include "ui/gfx/render_text_harfbuzz.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 SizeF RenderTextHarfBuzz::GetStringSizeF() { 889 SizeF RenderTextHarfBuzz::GetStringSizeF() {
890 EnsureLayout(); 890 EnsureLayout();
891 return total_size_; 891 return total_size_;
892 } 892 }
893 893
894 SelectionModel RenderTextHarfBuzz::FindCursorPosition(const Point& view_point) { 894 SelectionModel RenderTextHarfBuzz::FindCursorPosition(const Point& view_point) {
895 EnsureLayout(); 895 EnsureLayout();
896 DCHECK(!lines().empty()); 896 DCHECK(!lines().empty());
897 897
898 int line_index = GetLineContainingYCoord((view_point - GetLineOffset(0)).y()); 898 int line_index = GetLineContainingYCoord((view_point - GetLineOffset(0)).y());
899 // Clip line index to a valid value in case kDragToEndIfOutsideVerticalBounds 899 // Handle kDragToEndIfOutsideVerticalBounds above or below the text in a
900 // is false. Else, drag to end. 900 // single-line by extending towards the mouse cursor.
901 if (RenderText::kDragToEndIfOutsideVerticalBounds && !multiline() &&
902 (line_index < 0 || line_index >= static_cast<int>(lines().size()))) {
903 SelectionModel selection_start = GetSelectionModelForSelectionStart();
904 bool left = view_point.x() < GetCursorBounds(selection_start, true).x();
905 return EdgeSelectionModel(left ? CURSOR_LEFT : CURSOR_RIGHT);
906 }
907 // Otherwise, clamp |line_index| to a valid value or drag to logical ends.
901 if (line_index < 0) { 908 if (line_index < 0) {
902 if (RenderText::kDragToEndIfOutsideVerticalBounds) 909 if (RenderText::kDragToEndIfOutsideVerticalBounds)
903 return EdgeSelectionModel(GetVisualDirectionOfLogicalBeginning()); 910 return EdgeSelectionModel(GetVisualDirectionOfLogicalBeginning());
904 else 911 line_index = 0;
905 line_index = 0;
906 } 912 }
907 if (line_index >= static_cast<int>(lines().size())) { 913 if (line_index >= static_cast<int>(lines().size())) {
908 if (RenderText::kDragToEndIfOutsideVerticalBounds) 914 if (RenderText::kDragToEndIfOutsideVerticalBounds)
909 return EdgeSelectionModel(GetVisualDirectionOfLogicalEnd()); 915 return EdgeSelectionModel(GetVisualDirectionOfLogicalEnd());
910 else 916 line_index = lines().size() - 1;
911 line_index = lines().size() - 1;
912 } 917 }
913 const internal::Line& line = lines()[line_index]; 918 const internal::Line& line = lines()[line_index];
914 919
915 float point_offset_relative_segment = 0; 920 float point_offset_relative_segment = 0;
916 const int segment_index = GetLineSegmentContainingXCoord( 921 const int segment_index = GetLineSegmentContainingXCoord(
917 line, (view_point - GetLineOffset(line_index)).x(), 922 line, (view_point - GetLineOffset(line_index)).x(),
918 &point_offset_relative_segment); 923 &point_offset_relative_segment);
919 if (segment_index < 0) 924 if (segment_index < 0)
920 return LineSelectionModel(line_index, CURSOR_LEFT); 925 return LineSelectionModel(line_index, CURSOR_LEFT);
921 if (segment_index >= static_cast<int>(line.segments.size())) 926 if (segment_index >= static_cast<int>(line.segments.size()))
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 1731
1727 attribute.strike = run.strike; 1732 attribute.strike = run.strike;
1728 attribute.diagonal_strike = run.diagonal_strike; 1733 attribute.diagonal_strike = run.diagonal_strike;
1729 decorated_text->attributes.push_back(attribute); 1734 decorated_text->attributes.push_back(attribute);
1730 } 1735 }
1731 } 1736 }
1732 return true; 1737 return true;
1733 } 1738 }
1734 1739
1735 } // namespace gfx 1740 } // namespace gfx
OLDNEW
« 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