OLD | NEW |
---|---|
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 #include <climits> | 8 #include <climits> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 } | 865 } |
866 | 866 |
867 SelectionModel RenderText::GetSelectionModelForSelectionStart() { | 867 SelectionModel RenderText::GetSelectionModelForSelectionStart() { |
868 const Range& sel = selection(); | 868 const Range& sel = selection(); |
869 if (sel.is_empty()) | 869 if (sel.is_empty()) |
870 return selection_model_; | 870 return selection_model_; |
871 return SelectionModel(sel.start(), | 871 return SelectionModel(sel.start(), |
872 sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD); | 872 sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD); |
873 } | 873 } |
874 | 874 |
875 const Vector2d& RenderText::GetUpdatedDisplayOffset() { | |
876 UpdateCachedBoundsAndOffset(); | |
877 return display_offset_; | |
878 } | |
879 | |
880 void RenderText::SetDisplayOffset(int horizontal_offset) { | |
881 int extra_content = GetContentWidth() - display_rect_.width(); | |
msw
2014/07/10 00:28:54
nit: const
| |
882 | |
883 int min_offset = 0; | |
884 int max_offset = 0; | |
885 if (extra_content > 0) { | |
886 switch (horizontal_alignment_) { | |
887 case ALIGN_LEFT: | |
888 min_offset = -extra_content; | |
889 break; | |
890 case ALIGN_RIGHT: | |
891 max_offset = extra_content; | |
892 break; | |
893 case ALIGN_CENTER: | |
894 min_offset = -extra_content / 2; | |
895 max_offset = extra_content / 2; | |
896 break; | |
897 default: | |
898 break; | |
899 } | |
900 } | |
901 if (horizontal_offset < min_offset) | |
902 horizontal_offset = min_offset; | |
903 else if (horizontal_offset > max_offset) | |
904 horizontal_offset = max_offset; | |
905 | |
906 cached_bounds_and_offset_valid_ = true; | |
907 display_offset_.set_x(horizontal_offset); | |
908 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); | |
909 } | |
910 | |
875 RenderText::RenderText() | 911 RenderText::RenderText() |
876 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), | 912 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), |
877 directionality_mode_(DIRECTIONALITY_FROM_TEXT), | 913 directionality_mode_(DIRECTIONALITY_FROM_TEXT), |
878 text_direction_(base::i18n::UNKNOWN_DIRECTION), | 914 text_direction_(base::i18n::UNKNOWN_DIRECTION), |
879 cursor_enabled_(true), | 915 cursor_enabled_(true), |
880 cursor_visible_(false), | 916 cursor_visible_(false), |
881 insert_mode_(true), | 917 insert_mode_(true), |
882 cursor_color_(kDefaultColor), | 918 cursor_color_(kDefaultColor), |
883 selection_color_(kDefaultColor), | 919 selection_color_(kDefaultColor), |
884 selection_background_focused_color_(kDefaultSelectionBackgroundColor), | 920 selection_background_focused_color_(kDefaultSelectionBackgroundColor), |
885 focused_(false), | 921 focused_(false), |
886 composition_range_(Range::InvalidRange()), | 922 composition_range_(Range::InvalidRange()), |
887 colors_(kDefaultColor), | 923 colors_(kDefaultColor), |
888 styles_(NUM_TEXT_STYLES), | 924 styles_(NUM_TEXT_STYLES), |
889 composition_and_selection_styles_applied_(false), | 925 composition_and_selection_styles_applied_(false), |
890 obscured_(false), | 926 obscured_(false), |
891 obscured_reveal_index_(-1), | 927 obscured_reveal_index_(-1), |
892 truncate_length_(0), | 928 truncate_length_(0), |
893 elide_behavior_(TRUNCATE), | 929 elide_behavior_(TRUNCATE), |
894 multiline_(false), | 930 multiline_(false), |
895 background_is_transparent_(false), | 931 background_is_transparent_(false), |
896 clip_to_display_rect_(true), | 932 clip_to_display_rect_(true), |
897 baseline_(kInvalidBaseline), | 933 baseline_(kInvalidBaseline), |
898 cached_bounds_and_offset_valid_(false) { | 934 cached_bounds_and_offset_valid_(false) { |
899 } | 935 } |
900 | 936 |
901 const Vector2d& RenderText::GetUpdatedDisplayOffset() { | |
902 UpdateCachedBoundsAndOffset(); | |
903 return display_offset_; | |
904 } | |
905 | |
906 SelectionModel RenderText::GetAdjacentSelectionModel( | 937 SelectionModel RenderText::GetAdjacentSelectionModel( |
907 const SelectionModel& current, | 938 const SelectionModel& current, |
908 BreakType break_type, | 939 BreakType break_type, |
909 VisualCursorDirection direction) { | 940 VisualCursorDirection direction) { |
910 EnsureLayout(); | 941 EnsureLayout(); |
911 | 942 |
912 if (break_type == LINE_BREAK || text().empty()) | 943 if (break_type == LINE_BREAK || text().empty()) |
913 return EdgeSelectionModel(direction); | 944 return EdgeSelectionModel(direction); |
914 if (break_type == CHARACTER_BREAK) | 945 if (break_type == CHARACTER_BREAK) |
915 return AdjacentCharSelectionModel(current, direction); | 946 return AdjacentCharSelectionModel(current, direction); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1315 cursor_bounds_ += delta_offset; | 1346 cursor_bounds_ += delta_offset; |
1316 } | 1347 } |
1317 | 1348 |
1318 void RenderText::DrawSelection(Canvas* canvas) { | 1349 void RenderText::DrawSelection(Canvas* canvas) { |
1319 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1350 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1320 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1351 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1321 canvas->FillRect(*i, selection_background_focused_color_); | 1352 canvas->FillRect(*i, selection_background_focused_color_); |
1322 } | 1353 } |
1323 | 1354 |
1324 } // namespace gfx | 1355 } // namespace gfx |
OLD | NEW |