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

Side by Side Diff: ui/gfx/render_text.cc

Issue 16867016: Windows implementation of multiline RenderText (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: removed GetMultilineTextSize Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 range = range.Intersect(styles_[i].GetRange(style_[i])); 294 range = range.Intersect(styles_[i].GetRange(style_[i]));
295 return range; 295 return range;
296 } 296 }
297 297
298 void StyleIterator::UpdatePosition(size_t position) { 298 void StyleIterator::UpdatePosition(size_t position) {
299 color_ = colors_.GetBreak(position); 299 color_ = colors_.GetBreak(position);
300 for (size_t i = 0; i < NUM_TEXT_STYLES; ++i) 300 for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
301 style_[i] = styles_[i].GetBreak(position); 301 style_[i] = styles_[i].GetBreak(position);
302 } 302 }
303 303
304 LineSegment::LineSegment() : run(0) {}
305
306 Line::Line() : preceding_heights(0), baseline(0) {}
307
304 } // namespace internal 308 } // namespace internal
305 309
306 RenderText::~RenderText() { 310 RenderText::~RenderText() {
307 } 311 }
308 312
309 void RenderText::SetText(const base::string16& text) { 313 void RenderText::SetText(const base::string16& text) {
310 DCHECK(!composition_range_.IsValid()); 314 DCHECK(!composition_range_.IsValid());
315 if (text_ == text)
316 return;
311 text_ = text; 317 text_ = text;
312 318
313 // Adjust ranged styles and colors to accommodate a new text length. 319 // Adjust ranged styles and colors to accommodate a new text length.
314 const size_t text_length = text_.length(); 320 const size_t text_length = text_.length();
315 colors_.SetMax(text_length); 321 colors_.SetMax(text_length);
316 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) 322 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
317 styles_[style].SetMax(text_length); 323 styles_[style].SetMax(text_length);
318 cached_bounds_and_offset_valid_ = false; 324 cached_bounds_and_offset_valid_ = false;
319 325
320 // Reset selection model. SetText should always followed by SetSelectionModel 326 // Reset selection model. SetText should always followed by SetSelectionModel
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 void RenderText::SetObscuredRevealIndex(int index) { 393 void RenderText::SetObscuredRevealIndex(int index) {
388 if (obscured_reveal_index_ == index) 394 if (obscured_reveal_index_ == index)
389 return; 395 return;
390 396
391 obscured_reveal_index_ = index; 397 obscured_reveal_index_ = index;
392 cached_bounds_and_offset_valid_ = false; 398 cached_bounds_and_offset_valid_ = false;
393 UpdateLayoutText(); 399 UpdateLayoutText();
394 ResetLayout(); 400 ResetLayout();
395 } 401 }
396 402
403 void RenderText::SetMultiline(bool multiline) {
404 if (multiline != multiline_) {
405 multiline_ = multiline;
406 cached_bounds_and_offset_valid_ = false;
407 lines_.clear();
408 }
409 }
410
397 void RenderText::SetDisplayRect(const Rect& r) { 411 void RenderText::SetDisplayRect(const Rect& r) {
398 display_rect_ = r; 412 display_rect_ = r;
399 cached_bounds_and_offset_valid_ = false; 413 cached_bounds_and_offset_valid_ = false;
414 lines_.clear();
400 } 415 }
401 416
402 void RenderText::SetCursorPosition(size_t position) { 417 void RenderText::SetCursorPosition(size_t position) {
403 MoveCursorTo(position, false); 418 MoveCursorTo(position, false);
404 } 419 }
405 420
406 void RenderText::MoveCursor(BreakType break_type, 421 void RenderText::MoveCursor(BreakType break_type,
407 VisualCursorDirection direction, 422 VisualCursorDirection direction,
408 bool select) { 423 bool select) {
409 SelectionModel position(cursor_position(), selection_model_.caret_affinity()); 424 SelectionModel position(cursor_position(), selection_model_.caret_affinity());
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 canvas->ClipRect(sel[i]); 692 canvas->ClipRect(sel[i]);
678 DrawVisualText(canvas); 693 DrawVisualText(canvas);
679 canvas->Restore(); 694 canvas->Restore();
680 } 695 }
681 696
682 // Restore saved transparency and selection color. 697 // Restore saved transparency and selection color.
683 set_selection_color(saved_selection_color); 698 set_selection_color(saved_selection_color);
684 set_background_is_transparent(saved_background_is_transparent); 699 set_background_is_transparent(saved_background_is_transparent);
685 } 700 }
686 701
702 // TODO(ckocagil): Support multi-line. This function should return the height of
msw 2013/09/06 23:47:45 nit: move this comment inside the function or to t
ckocagil 2013/09/11 14:59:49 Done, moved inside the function.
703 // the line the cursor is on. |GetStringSize()| now returns the
704 // multi-line size, eliminate its use here.
687 Rect RenderText::GetCursorBounds(const SelectionModel& caret, 705 Rect RenderText::GetCursorBounds(const SelectionModel& caret,
688 bool insert_mode) { 706 bool insert_mode) {
689 EnsureLayout(); 707 EnsureLayout();
690 708
691 size_t caret_pos = caret.caret_pos(); 709 size_t caret_pos = caret.caret_pos();
692 DCHECK(IsCursorablePosition(caret_pos)); 710 DCHECK(IsCursorablePosition(caret_pos));
693 // In overtype mode, ignore the affinity and always indicate that we will 711 // In overtype mode, ignore the affinity and always indicate that we will
694 // overtype the next character. 712 // overtype the next character.
695 LogicalCursorDirection caret_affinity = 713 LogicalCursorDirection caret_affinity =
696 insert_mode ? caret.caret_affinity() : CURSOR_FORWARD; 714 insert_mode ? caret.caret_affinity() : CURSOR_FORWARD;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 selection_color_(kDefaultColor), 786 selection_color_(kDefaultColor),
769 selection_background_focused_color_(kDefaultSelectionBackgroundColor), 787 selection_background_focused_color_(kDefaultSelectionBackgroundColor),
770 focused_(false), 788 focused_(false),
771 composition_range_(ui::Range::InvalidRange()), 789 composition_range_(ui::Range::InvalidRange()),
772 colors_(kDefaultColor), 790 colors_(kDefaultColor),
773 styles_(NUM_TEXT_STYLES), 791 styles_(NUM_TEXT_STYLES),
774 composition_and_selection_styles_applied_(false), 792 composition_and_selection_styles_applied_(false),
775 obscured_(false), 793 obscured_(false),
776 obscured_reveal_index_(-1), 794 obscured_reveal_index_(-1),
777 truncate_length_(0), 795 truncate_length_(0),
796 multiline_(false),
778 fade_head_(false), 797 fade_head_(false),
779 fade_tail_(false), 798 fade_tail_(false),
780 background_is_transparent_(false), 799 background_is_transparent_(false),
781 clip_to_display_rect_(true), 800 clip_to_display_rect_(true),
782 cached_bounds_and_offset_valid_(false) { 801 cached_bounds_and_offset_valid_(false) {
783 } 802 }
784 803
785 const Vector2d& RenderText::GetUpdatedDisplayOffset() { 804 const Vector2d& RenderText::GetUpdatedDisplayOffset() {
786 UpdateCachedBoundsAndOffset(); 805 UpdateCachedBoundsAndOffset();
787 return display_offset_; 806 return display_offset_;
(...skipping 23 matching lines...) Expand all
811 void RenderText::SetSelectionModel(const SelectionModel& model) { 830 void RenderText::SetSelectionModel(const SelectionModel& model) {
812 DCHECK_LE(model.selection().GetMax(), text().length()); 831 DCHECK_LE(model.selection().GetMax(), text().length());
813 selection_model_ = model; 832 selection_model_ = model;
814 cached_bounds_and_offset_valid_ = false; 833 cached_bounds_and_offset_valid_ = false;
815 } 834 }
816 835
817 const base::string16& RenderText::GetLayoutText() const { 836 const base::string16& RenderText::GetLayoutText() const {
818 return layout_text_.empty() ? text_ : layout_text_; 837 return layout_text_.empty() ? text_ : layout_text_;
819 } 838 }
820 839
840 const BreakList<size_t>& RenderText::GetLineBreaks() {
841 if (line_breaks_.max() != 0)
842 return line_breaks_;
843
844 const string16& layout_text = GetLayoutText();
845 const size_t text_length = layout_text.length();
846 line_breaks_.SetValue(0);
847 line_breaks_.SetMax(text_length);
848 base::i18n::BreakIterator iter(layout_text,
849 base::i18n::BreakIterator::BREAK_LINE);
msw 2013/09/06 23:47:45 nit: out-dent one space.
ckocagil 2013/09/11 14:59:49 Done.
850 bool success = iter.Init();
msw 2013/09/06 23:47:45 nit: const.
ckocagil 2013/09/11 14:59:49 Done.
851 DCHECK(success);
852 if (success) {
msw 2013/09/06 23:47:45 optional: I think the first break would always be
ckocagil 2013/09/11 14:59:49 I would rather keep the explicit if block.
853 do {
854 line_breaks_.ApplyValue(iter.pos(), ui::Range(iter.pos(), text_length));
855 } while (iter.Advance());
856 }
857 return line_breaks_;
858 }
859
821 void RenderText::ApplyCompositionAndSelectionStyles() { 860 void RenderText::ApplyCompositionAndSelectionStyles() {
822 // Save the underline and color breaks to undo the temporary styles later. 861 // Save the underline and color breaks to undo the temporary styles later.
823 DCHECK(!composition_and_selection_styles_applied_); 862 DCHECK(!composition_and_selection_styles_applied_);
824 saved_colors_ = colors_; 863 saved_colors_ = colors_;
825 saved_underlines_ = styles_[UNDERLINE]; 864 saved_underlines_ = styles_[UNDERLINE];
826 865
827 // Apply an underline to the composition range in |underlines|. 866 // Apply an underline to the composition range in |underlines|.
828 if (composition_range_.IsValid() && !composition_range_.is_empty()) 867 if (composition_range_.IsValid() && !composition_range_.is_empty())
829 styles_[UNDERLINE].ApplyValue(true, composition_range_); 868 styles_[UNDERLINE].ApplyValue(true, composition_range_);
830 869
831 // Apply the selected text color to the [un-reversed] selection range. 870 // Apply the selected text color to the [un-reversed] selection range.
832 if (!selection().is_empty()) { 871 if (!selection().is_empty()) {
833 const ui::Range range(selection().GetMin(), selection().GetMax()); 872 const ui::Range range(selection().GetMin(), selection().GetMax());
834 colors_.ApplyValue(selection_color_, range); 873 colors_.ApplyValue(selection_color_, range);
835 } 874 }
836 composition_and_selection_styles_applied_ = true; 875 composition_and_selection_styles_applied_ = true;
837 } 876 }
838 877
839 void RenderText::UndoCompositionAndSelectionStyles() { 878 void RenderText::UndoCompositionAndSelectionStyles() {
840 // Restore the underline and color breaks to undo the temporary styles. 879 // Restore the underline and color breaks to undo the temporary styles.
841 DCHECK(composition_and_selection_styles_applied_); 880 DCHECK(composition_and_selection_styles_applied_);
842 colors_ = saved_colors_; 881 colors_ = saved_colors_;
843 styles_[UNDERLINE] = saved_underlines_; 882 styles_[UNDERLINE] = saved_underlines_;
844 composition_and_selection_styles_applied_ = false; 883 composition_and_selection_styles_applied_ = false;
845 } 884 }
846 885
847 Vector2d RenderText::GetTextOffset() { 886 Vector2d RenderText::GetLineOffset(size_t line_number) {
848 Vector2d offset = display_rect().OffsetFromOrigin(); 887 Vector2d offset = display_rect().OffsetFromOrigin();
849 offset.Add(GetUpdatedDisplayOffset()); 888 if (!multiline())
850 offset.Add(GetAlignmentOffset()); 889 offset.Add(GetUpdatedDisplayOffset());
msw 2013/09/06 23:47:45 Shouldn't it be okay to add the display offset eve
ckocagil 2013/09/11 14:59:49 I'm disabling it in multiline because I need to te
msw 2013/09/11 17:32:37 I think an additional TODO here would help call ou
ckocagil 2013/09/11 20:31:15 Done.
890 else
891 offset.Add(Vector2d(0, lines_[line_number].preceding_heights));
892 offset.Add(GetAlignmentOffset(line_number));
851 return offset; 893 return offset;
852 } 894 }
853 895
854 Point RenderText::ToTextPoint(const Point& point) { 896 Point RenderText::ToTextPoint(const Point& point) {
855 return point - GetTextOffset(); 897 return point - GetLineOffset(0);
898 // TODO(ckocagil): implement multiline.
msw 2013/09/06 23:47:45 nit: capitalize "Implement", consider expanding th
ckocagil 2013/09/11 14:59:49 Done.
856 } 899 }
857 900
858 Point RenderText::ToViewPoint(const Point& point) { 901 Point RenderText::ToViewPoint(const Point& point) {
859 return point + GetTextOffset(); 902 if (!multiline())
903 return point + GetLineOffset(0);
904
905 // TODO(ckocagil): refactor this to traverse all line segments to support rtl.
msw 2013/09/06 23:47:45 nit: capitalize 'Refactor' and 'RTL'; consider: //
ckocagil 2013/09/11 14:59:49 Done.
906 DCHECK(!lines_.empty());
907 int x = point.x();
908 size_t line = 0;
909 while (line < lines_.size() && x > lines_[line].size.width()) {
msw 2013/09/06 23:47:45 Optionally, you could do: for (line = 0; line < li
ckocagil 2013/09/11 14:59:49 Done.
910 x -= lines_[line].size.width();
911 ++line;
912 }
913 return Point(x, point.y()) + GetLineOffset(line);
860 } 914 }
861 915
862 Vector2d RenderText::GetAlignmentOffset() { 916 std::vector<Rect> RenderText::TextBoundsToViewBounds(const ui::Range& x) {
917 std::vector<Rect> rects;
918
919 if (!multiline()) {
920 rects.push_back(Rect(ToViewPoint(Point(x.GetMin(), 0)),
921 Size(x.length(), GetStringSize().height())));
922 return rects;
923 }
924
925 EnsureLayout();
926
927 // Each line segment keeps its position in text coordinates. Traverse all line
928 // segments and if the segment intersects with the given range, add the view
929 // rect corresponding to the intersection to |rects|.
930 for (size_t line = 0; line < lines_.size(); ++line) {
931 int line_x = 0;
932 Vector2d offset = GetLineOffset(line);
msw 2013/09/06 23:47:45 nit: const
ckocagil 2013/09/11 14:59:49 Done.
933 for (size_t i = 0; i < lines_[line].segments.size(); ++i) {
934 const internal::LineSegment* segment = &lines_[line].segments[i];
935 const ui::Range intersection = segment->x_range.Intersect(x);
936 if (!intersection.is_empty()) {
937 Rect rect(line_x + intersection.start() - segment->x_range.start(),
938 0, intersection.length(), lines_[line].size.height());
939 rects.push_back(rect + offset);
940 }
941 line_x += segment->x_range.length();
942 }
943 }
944
945 return rects;
946 }
947
948 Vector2d RenderText::GetAlignmentOffset(size_t line_number) {
949 DCHECK_LT(line_number, lines_.size());
863 Vector2d offset; 950 Vector2d offset;
864 if (horizontal_alignment_ != ALIGN_LEFT) { 951 if (horizontal_alignment_ != ALIGN_LEFT) {
865 offset.set_x(display_rect().width() - GetContentWidth()); 952 const int width = lines_[line_number].size.width() +
953 (cursor_enabled_ ? 1 : 0);
954 offset.set_x(display_rect().width() - width);
866 if (horizontal_alignment_ == ALIGN_CENTER) 955 if (horizontal_alignment_ == ALIGN_CENTER)
867 offset.set_x(offset.x() / 2); 956 offset.set_x(offset.x() / 2);
868 } 957 }
869 if (vertical_alignment_ != ALIGN_TOP) { 958 if (vertical_alignment_ != ALIGN_TOP) {
870 offset.set_y(display_rect().height() - GetStringSize().height()); 959 offset.set_y(display_rect().height() - GetStringSize().height());
871 if (vertical_alignment_ == ALIGN_VCENTER) 960 if (vertical_alignment_ == ALIGN_VCENTER)
872 offset.set_y(offset.y() / 2); 961 offset.set_y(offset.y() / 2);
873 } 962 }
874 return offset; 963 return offset;
875 } 964 }
876 965
877 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { 966 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) {
878 if (!fade_head() && !fade_tail()) 967 if (multiline() || !fade_head() && !fade_tail())
879 return; 968 return;
880 969
881 const int text_width = GetStringSize().width();
882 const int display_width = display_rect().width(); 970 const int display_width = display_rect().width();
883 971
884 // If the text fits as-is, no need to fade. 972 // If the text fits as-is, no need to fade.
885 if (text_width <= display_width) 973 if (GetStringSize().width() <= display_width)
886 return; 974 return;
887 975
888 int gradient_width = CalculateFadeGradientWidth(GetPrimaryFont(), 976 int gradient_width = CalculateFadeGradientWidth(GetPrimaryFont(),
889 display_width); 977 display_width);
890 if (gradient_width == 0) 978 if (gradient_width == 0)
891 return; 979 return;
892 980
893 bool fade_left = fade_head(); 981 bool fade_left = fade_head();
894 bool fade_right = fade_tail(); 982 bool fade_right = fade_tail();
895 // Under RTL, |fade_right| == |fade_head|. 983 // Under RTL, |fade_right| == |fade_head|.
(...skipping 11 matching lines...) Expand all
907 left_part.Inset(0, 0, solid_part.width() - gradient_width, 0); 995 left_part.Inset(0, 0, solid_part.width() - gradient_width, 0);
908 solid_part.Inset(gradient_width, 0, 0, 0); 996 solid_part.Inset(gradient_width, 0, 0, 0);
909 } 997 }
910 if (fade_right) { 998 if (fade_right) {
911 right_part = solid_part; 999 right_part = solid_part;
912 right_part.Inset(solid_part.width() - gradient_width, 0, 0, 0); 1000 right_part.Inset(solid_part.width() - gradient_width, 0, 0, 0);
913 solid_part.Inset(0, 0, gradient_width, 0); 1001 solid_part.Inset(0, 0, gradient_width, 0);
914 } 1002 }
915 1003
916 Rect text_rect = display_rect(); 1004 Rect text_rect = display_rect();
917 text_rect.Inset(GetAlignmentOffset().x(), 0, 0, 0); 1005 text_rect.Inset(GetAlignmentOffset(0).x(), 0, 0, 0);
918 1006
919 // TODO(msw): Use the actual text colors corresponding to each faded part. 1007 // TODO(msw): Use the actual text colors corresponding to each faded part.
920 skia::RefPtr<SkShader> shader = CreateFadeShader( 1008 skia::RefPtr<SkShader> shader = CreateFadeShader(
921 text_rect, left_part, right_part, colors_.breaks().front().second); 1009 text_rect, left_part, right_part, colors_.breaks().front().second);
922 if (shader) 1010 if (shader)
923 renderer->SetShader(shader.get(), display_rect()); 1011 renderer->SetShader(shader.get(), display_rect());
924 } 1012 }
925 1013
926 void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) { 1014 void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) {
927 skia::RefPtr<SkDrawLooper> looper = CreateShadowDrawLooper(text_shadows_); 1015 skia::RefPtr<SkDrawLooper> looper = CreateShadowDrawLooper(text_shadows_);
(...skipping 13 matching lines...) Expand all
941 void RenderText::MoveCursorTo(size_t position, bool select) { 1029 void RenderText::MoveCursorTo(size_t position, bool select) {
942 size_t cursor = std::min(position, text().length()); 1030 size_t cursor = std::min(position, text().length());
943 if (IsCursorablePosition(cursor)) 1031 if (IsCursorablePosition(cursor))
944 SetSelectionModel(SelectionModel( 1032 SetSelectionModel(SelectionModel(
945 ui::Range(select ? selection().start() : cursor, cursor), 1033 ui::Range(select ? selection().start() : cursor, cursor),
946 (cursor == 0) ? CURSOR_FORWARD : CURSOR_BACKWARD)); 1034 (cursor == 0) ? CURSOR_FORWARD : CURSOR_BACKWARD));
947 } 1035 }
948 1036
949 void RenderText::UpdateLayoutText() { 1037 void RenderText::UpdateLayoutText() {
950 layout_text_.clear(); 1038 layout_text_.clear();
1039 line_breaks_.SetMax(0);
951 1040
952 if (obscured_) { 1041 if (obscured_) {
953 size_t obscured_text_length = 1042 size_t obscured_text_length =
954 static_cast<size_t>(ui::UTF16IndexToOffset(text_, 0, text_.length())); 1043 static_cast<size_t>(ui::UTF16IndexToOffset(text_, 0, text_.length()));
955 layout_text_.assign(obscured_text_length, kPasswordReplacementChar); 1044 layout_text_.assign(obscured_text_length, kPasswordReplacementChar);
956 1045
957 if (obscured_reveal_index_ >= 0 && 1046 if (obscured_reveal_index_ >= 0 &&
958 obscured_reveal_index_ < static_cast<int>(text_.length())) { 1047 obscured_reveal_index_ < static_cast<int>(text_.length())) {
959 // Gets the index range in |text_| to be revealed. 1048 // Gets the index range in |text_| to be revealed.
960 size_t start = obscured_reveal_index_; 1049 size_t start = obscured_reveal_index_;
(...skipping 16 matching lines...) Expand all
977 icu::StringCharacterIterator iter(text.c_str()); 1066 icu::StringCharacterIterator iter(text.c_str());
978 iter.setIndex32(truncate_length_ - 1); 1067 iter.setIndex32(truncate_length_ - 1);
979 layout_text_.assign(text.substr(0, iter.getIndex()) + ui::kEllipsisUTF16); 1068 layout_text_.assign(text.substr(0, iter.getIndex()) + ui::kEllipsisUTF16);
980 } 1069 }
981 } 1070 }
982 1071
983 void RenderText::UpdateCachedBoundsAndOffset() { 1072 void RenderText::UpdateCachedBoundsAndOffset() {
984 if (cached_bounds_and_offset_valid_) 1073 if (cached_bounds_and_offset_valid_)
985 return; 1074 return;
986 1075
1076 // TODO(ckocagil): Add vertical offset support for scrolling multi-line text.
msw 2013/09/06 23:47:45 nit: Address my GetLineOffset comment or remove "V
ckocagil 2013/09/11 14:59:49 Done, removed "vertical".
1077
987 // First, set the valid flag true to calculate the current cursor bounds using 1078 // First, set the valid flag true to calculate the current cursor bounds using
988 // the stale |display_offset_|. Applying |delta_offset| at the end of this 1079 // the stale |display_offset_|. Applying |delta_offset| at the end of this
989 // function will set |cursor_bounds_| and |display_offset_| to correct values. 1080 // function will set |cursor_bounds_| and |display_offset_| to correct values.
990 cached_bounds_and_offset_valid_ = true; 1081 cached_bounds_and_offset_valid_ = true;
991 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); 1082 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_);
992 1083
993 // Update |display_offset_| to ensure the current cursor is visible. 1084 // Update |display_offset_| to ensure the current cursor is visible.
994 const int display_width = display_rect_.width(); 1085 const int display_width = display_rect_.width();
995 const int content_width = GetContentWidth(); 1086 const int content_width = GetContentWidth();
996 1087
(...skipping 30 matching lines...) Expand all
1027 cursor_bounds_ += delta_offset; 1118 cursor_bounds_ += delta_offset;
1028 } 1119 }
1029 1120
1030 void RenderText::DrawSelection(Canvas* canvas) { 1121 void RenderText::DrawSelection(Canvas* canvas) {
1031 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1122 const std::vector<Rect> sel = GetSubstringBounds(selection());
1032 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1123 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1033 canvas->FillRect(*i, selection_background_focused_color_); 1124 canvas->FillRect(*i, selection_background_focused_color_);
1034 } 1125 }
1035 1126
1036 } // namespace gfx 1127 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698