Chromium Code Reviews| 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(const Vector2d& offset) { | |
|
msw
2014/07/08 17:38:23
nit: perhaps this should only take a horizontal of
mohsen
2014/07/08 18:36:16
Done.
| |
| 881 int display_width = display_rect_.width(); | |
| 882 int content_width = GetContentWidth(); | |
| 883 int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; | |
| 884 | |
| 885 Vector2d final_offset = offset; | |
| 886 if (content_width <= display_width) | |
| 887 final_offset.set_x(0); | |
| 888 else if (negate_rtl * final_offset.x() > 0) | |
| 889 final_offset.set_x(0); | |
|
msw
2014/07/08 17:38:23
q: does this prevent scrolling before the start of
mohsen
2014/07/08 18:36:16
Yes.
| |
| 890 else if (negate_rtl * final_offset.x() < display_width - content_width) | |
| 891 final_offset.set_x(negate_rtl * (display_width - content_width)); | |
| 892 cached_bounds_and_offset_valid_ = true; | |
| 893 display_offset_ = final_offset; | |
| 894 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); | |
| 895 } | |
| 896 | |
| 875 RenderText::RenderText() | 897 RenderText::RenderText() |
| 876 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), | 898 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), |
| 877 directionality_mode_(DIRECTIONALITY_FROM_TEXT), | 899 directionality_mode_(DIRECTIONALITY_FROM_TEXT), |
| 878 text_direction_(base::i18n::UNKNOWN_DIRECTION), | 900 text_direction_(base::i18n::UNKNOWN_DIRECTION), |
| 879 cursor_enabled_(true), | 901 cursor_enabled_(true), |
| 880 cursor_visible_(false), | 902 cursor_visible_(false), |
| 881 insert_mode_(true), | 903 insert_mode_(true), |
| 882 cursor_color_(kDefaultColor), | 904 cursor_color_(kDefaultColor), |
| 883 selection_color_(kDefaultColor), | 905 selection_color_(kDefaultColor), |
| 884 selection_background_focused_color_(kDefaultSelectionBackgroundColor), | 906 selection_background_focused_color_(kDefaultSelectionBackgroundColor), |
| 885 focused_(false), | 907 focused_(false), |
| 886 composition_range_(Range::InvalidRange()), | 908 composition_range_(Range::InvalidRange()), |
| 887 colors_(kDefaultColor), | 909 colors_(kDefaultColor), |
| 888 styles_(NUM_TEXT_STYLES), | 910 styles_(NUM_TEXT_STYLES), |
| 889 composition_and_selection_styles_applied_(false), | 911 composition_and_selection_styles_applied_(false), |
| 890 obscured_(false), | 912 obscured_(false), |
| 891 obscured_reveal_index_(-1), | 913 obscured_reveal_index_(-1), |
| 892 truncate_length_(0), | 914 truncate_length_(0), |
| 893 elide_behavior_(TRUNCATE), | 915 elide_behavior_(TRUNCATE), |
| 894 multiline_(false), | 916 multiline_(false), |
| 895 background_is_transparent_(false), | 917 background_is_transparent_(false), |
| 896 clip_to_display_rect_(true), | 918 clip_to_display_rect_(true), |
| 897 baseline_(kInvalidBaseline), | 919 baseline_(kInvalidBaseline), |
| 898 cached_bounds_and_offset_valid_(false) { | 920 cached_bounds_and_offset_valid_(false) { |
| 899 } | 921 } |
| 900 | 922 |
| 901 const Vector2d& RenderText::GetUpdatedDisplayOffset() { | |
| 902 UpdateCachedBoundsAndOffset(); | |
| 903 return display_offset_; | |
| 904 } | |
| 905 | |
| 906 SelectionModel RenderText::GetAdjacentSelectionModel( | 923 SelectionModel RenderText::GetAdjacentSelectionModel( |
| 907 const SelectionModel& current, | 924 const SelectionModel& current, |
| 908 BreakType break_type, | 925 BreakType break_type, |
| 909 VisualCursorDirection direction) { | 926 VisualCursorDirection direction) { |
| 910 EnsureLayout(); | 927 EnsureLayout(); |
| 911 | 928 |
| 912 if (break_type == LINE_BREAK || text().empty()) | 929 if (break_type == LINE_BREAK || text().empty()) |
| 913 return EdgeSelectionModel(direction); | 930 return EdgeSelectionModel(direction); |
| 914 if (break_type == CHARACTER_BREAK) | 931 if (break_type == CHARACTER_BREAK) |
| 915 return AdjacentCharSelectionModel(current, direction); | 932 return AdjacentCharSelectionModel(current, direction); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1315 cursor_bounds_ += delta_offset; | 1332 cursor_bounds_ += delta_offset; |
| 1316 } | 1333 } |
| 1317 | 1334 |
| 1318 void RenderText::DrawSelection(Canvas* canvas) { | 1335 void RenderText::DrawSelection(Canvas* canvas) { |
| 1319 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1336 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1320 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1337 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1321 canvas->FillRect(*i, selection_background_focused_color_); | 1338 canvas->FillRect(*i, selection_background_focused_color_); |
| 1322 } | 1339 } |
| 1323 | 1340 |
| 1324 } // namespace gfx | 1341 } // namespace gfx |
| OLD | NEW |