| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <climits> | 10 #include <climits> |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 Rect clip_rect(display_rect()); | 857 Rect clip_rect(display_rect()); |
| 858 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); | 858 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); |
| 859 | 859 |
| 860 canvas->Save(); | 860 canvas->Save(); |
| 861 canvas->ClipRect(clip_rect); | 861 canvas->ClipRect(clip_rect); |
| 862 } | 862 } |
| 863 | 863 |
| 864 if (!text().empty() && focused()) | 864 if (!text().empty() && focused()) |
| 865 DrawSelection(canvas); | 865 DrawSelection(canvas); |
| 866 | 866 |
| 867 if (cursor_enabled() && cursor_visible() && focused()) | |
| 868 DrawCursor(canvas, selection_model_); | |
| 869 | |
| 870 if (!text().empty()) { | 867 if (!text().empty()) { |
| 871 internal::SkiaTextRenderer renderer(canvas); | 868 internal::SkiaTextRenderer renderer(canvas); |
| 872 if (halo_effect()) | 869 if (halo_effect()) |
| 873 renderer.SetHaloEffect(); | 870 renderer.SetHaloEffect(); |
| 874 DrawVisualText(&renderer); | 871 DrawVisualText(&renderer); |
| 875 } | 872 } |
| 876 | 873 |
| 877 if (clip_to_display_rect()) | 874 if (clip_to_display_rect()) |
| 878 canvas->Restore(); | 875 canvas->Restore(); |
| 879 } | 876 } |
| 880 | 877 |
| 881 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { | |
| 882 // Paint cursor. Replace cursor is drawn as rectangle for now. | |
| 883 // TODO(msw): Draw a better cursor with a better indication of association. | |
| 884 canvas->FillRect(GetCursorBounds(position, true), cursor_color_); | |
| 885 } | |
| 886 | |
| 887 bool RenderText::IsValidLogicalIndex(size_t index) const { | 878 bool RenderText::IsValidLogicalIndex(size_t index) const { |
| 888 // Check that the index is at a valid code point (not mid-surrgate-pair) and | 879 // Check that the index is at a valid code point (not mid-surrgate-pair) and |
| 889 // that it's not truncated from the display text (its glyph may be shown). | 880 // that it's not truncated from the display text (its glyph may be shown). |
| 890 // | 881 // |
| 891 // Indices within truncated text are disallowed so users can easily interact | 882 // Indices within truncated text are disallowed so users can easily interact |
| 892 // with the underlying truncated text using the ellipsis as a proxy. This lets | 883 // with the underlying truncated text using the ellipsis as a proxy. This lets |
| 893 // users select all text, select the truncated text, and transition from the | 884 // users select all text, select the truncated text, and transition from the |
| 894 // last rendered glyph to the end of the text without getting invisible cursor | 885 // last rendered glyph to the end of the text without getting invisible cursor |
| 895 // positions nor needing unbounded arrow key presses to traverse the ellipsis. | 886 // positions nor needing unbounded arrow key presses to traverse the ellipsis. |
| 896 return index == 0 || index == text().length() || | 887 return index == 0 || index == text().length() || |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 if (range.IsValid() && range.GetMin() < text().length()) | 1063 if (range.IsValid() && range.GetMin() < text().length()) |
| 1073 return text().substr(range.GetMin(), range.length()); | 1064 return text().substr(range.GetMin(), range.length()); |
| 1074 return base::string16(); | 1065 return base::string16(); |
| 1075 } | 1066 } |
| 1076 | 1067 |
| 1077 RenderText::RenderText() | 1068 RenderText::RenderText() |
| 1078 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), | 1069 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), |
| 1079 directionality_mode_(DIRECTIONALITY_FROM_TEXT), | 1070 directionality_mode_(DIRECTIONALITY_FROM_TEXT), |
| 1080 text_direction_(base::i18n::UNKNOWN_DIRECTION), | 1071 text_direction_(base::i18n::UNKNOWN_DIRECTION), |
| 1081 cursor_enabled_(true), | 1072 cursor_enabled_(true), |
| 1082 cursor_visible_(false), | |
| 1083 cursor_color_(kDefaultColor), | |
| 1084 selection_color_(kDefaultColor), | 1073 selection_color_(kDefaultColor), |
| 1085 selection_background_focused_color_(kDefaultSelectionBackgroundColor), | 1074 selection_background_focused_color_(kDefaultSelectionBackgroundColor), |
| 1086 focused_(false), | 1075 focused_(false), |
| 1087 composition_range_(Range::InvalidRange()), | 1076 composition_range_(Range::InvalidRange()), |
| 1088 colors_(kDefaultColor), | 1077 colors_(kDefaultColor), |
| 1089 baselines_(NORMAL_BASELINE), | 1078 baselines_(NORMAL_BASELINE), |
| 1090 weights_(Font::Weight::NORMAL), | 1079 weights_(Font::Weight::NORMAL), |
| 1091 styles_(NUM_TEXT_STYLES), | 1080 styles_(NUM_TEXT_STYLES), |
| 1092 composition_and_selection_styles_applied_(false), | 1081 composition_and_selection_styles_applied_(false), |
| 1093 obscured_(false), | 1082 obscured_(false), |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 | 1703 |
| 1715 for (; range_max < length; ++range_max) | 1704 for (; range_max < length; ++range_max) |
| 1716 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) | 1705 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) |
| 1717 break; | 1706 break; |
| 1718 | 1707 |
| 1719 return range.is_reversed() ? Range(range_max, range_min) | 1708 return range.is_reversed() ? Range(range_max, range_min) |
| 1720 : Range(range_min, range_max); | 1709 : Range(range_min, range_max); |
| 1721 } | 1710 } |
| 1722 | 1711 |
| 1723 } // namespace gfx | 1712 } // namespace gfx |
| OLD | NEW |