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/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/gfx/text_elider.h" | 21 #include "ui/gfx/text_elider.h" |
22 #include "ui/gfx/utf16_indexing.h" | 22 #include "ui/gfx/utf16_indexing.h" |
23 | 23 |
24 namespace gfx { | 24 namespace gfx { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // All chars are replaced by this char when the password style is set. | 28 // All chars are replaced by this char when the password style is set. |
29 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' | 29 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' |
30 // that's available in the font (find_invisible_char() in gtkentry.c). | 30 // that's available in the font (find_invisible_char() in gtkentry.c). |
31 const char16 kPasswordReplacementChar = '*'; | 31 const base::char16 kPasswordReplacementChar = '*'; |
32 | 32 |
33 // Default color used for the text and cursor. | 33 // Default color used for the text and cursor. |
34 const SkColor kDefaultColor = SK_ColorBLACK; | 34 const SkColor kDefaultColor = SK_ColorBLACK; |
35 | 35 |
36 // Default color used for drawing selection background. | 36 // Default color used for drawing selection background. |
37 const SkColor kDefaultSelectionBackgroundColor = SK_ColorGRAY; | 37 const SkColor kDefaultSelectionBackgroundColor = SK_ColorGRAY; |
38 | 38 |
39 // Fraction of the text size to lower a strike through below the baseline. | 39 // Fraction of the text size to lower a strike through below the baseline. |
40 const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21); | 40 const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21); |
41 // Fraction of the text size to lower an underline below the baseline. | 41 // Fraction of the text size to lower an underline below the baseline. |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 } | 872 } |
873 | 873 |
874 const base::string16& RenderText::GetLayoutText() const { | 874 const base::string16& RenderText::GetLayoutText() const { |
875 return layout_text_.empty() ? text_ : layout_text_; | 875 return layout_text_.empty() ? text_ : layout_text_; |
876 } | 876 } |
877 | 877 |
878 const BreakList<size_t>& RenderText::GetLineBreaks() { | 878 const BreakList<size_t>& RenderText::GetLineBreaks() { |
879 if (line_breaks_.max() != 0) | 879 if (line_breaks_.max() != 0) |
880 return line_breaks_; | 880 return line_breaks_; |
881 | 881 |
882 const string16& layout_text = GetLayoutText(); | 882 const base::string16& layout_text = GetLayoutText(); |
883 const size_t text_length = layout_text.length(); | 883 const size_t text_length = layout_text.length(); |
884 line_breaks_.SetValue(0); | 884 line_breaks_.SetValue(0); |
885 line_breaks_.SetMax(text_length); | 885 line_breaks_.SetMax(text_length); |
886 base::i18n::BreakIterator iter(layout_text, | 886 base::i18n::BreakIterator iter(layout_text, |
887 base::i18n::BreakIterator::BREAK_LINE); | 887 base::i18n::BreakIterator::BREAK_LINE); |
888 const bool success = iter.Init(); | 888 const bool success = iter.Init(); |
889 DCHECK(success); | 889 DCHECK(success); |
890 if (success) { | 890 if (success) { |
891 do { | 891 do { |
892 line_breaks_.ApplyValue(iter.pos(), Range(iter.pos(), text_length)); | 892 line_breaks_.ApplyValue(iter.pos(), Range(iter.pos(), text_length)); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 cursor_bounds_ += delta_offset; | 1167 cursor_bounds_ += delta_offset; |
1168 } | 1168 } |
1169 | 1169 |
1170 void RenderText::DrawSelection(Canvas* canvas) { | 1170 void RenderText::DrawSelection(Canvas* canvas) { |
1171 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1171 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1172 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1172 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1173 canvas->FillRect(*i, selection_background_focused_color_); | 1173 canvas->FillRect(*i, selection_background_focused_color_); |
1174 } | 1174 } |
1175 | 1175 |
1176 } // namespace gfx | 1176 } // namespace gfx |
OLD | NEW |