Chromium Code Reviews| Index: ui/gfx/render_text.cc |
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
| index 696a4f040911421072729dcd7ee58fc7c8b6def7..709b708667bd012188c5e114c96d6dde7f89f758 100644 |
| --- a/ui/gfx/render_text.cc |
| +++ b/ui/gfx/render_text.cc |
| @@ -15,6 +15,21 @@ |
| namespace { |
| +// All chars are replaced by this char when the password style is set. |
| +// TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' |
| +// that's available in the font (find_invisible_char() in gtkentry.c). |
| +const char16 PASSWORD_REPLACEMENT_CHAR = '*'; |
|
msw
2011/12/03 00:22:40
Is this the correct style for a const char identif
benrg
2011/12/06 17:21:30
Done. (I misremembered the coding guidelines.)
|
| + |
| +// Color settings for text, backgrounds and cursor. |
| +// These are tentative, and should be derived from theme, system |
| +// settings and current settings. |
| +// TODO(oshima): Change this to match the standard chrome |
| +// before dogfooding textfield views. |
| +const SkColor kSelectedTextColor = SK_ColorWHITE; |
| +const SkColor kFocusedSelectionColor = SkColorSetRGB(30, 144, 255); |
| +const SkColor kUnfocusedSelectionColor = SK_ColorLTGRAY; |
| +const SkColor kCursorColor = SK_ColorBLACK; |
| + |
| #ifndef NDEBUG |
| // Check StyleRanges invariant conditions: sorted and non-overlapping ranges. |
| void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) { |
| @@ -127,11 +142,29 @@ void RenderText::SetText(const string16& text) { |
| UpdateLayout(); |
| } |
| +string16 RenderText::GetCensoredText() const { |
| + string16 txt = text(); |
| + if (password_) { |
| + // TODO(benrg): There should probably be one bullet/asterisk per |
| + // cursorable character, not one per UTF-16 word. However, I'm not sure |
| + // it's worth the effort. GTK appears to use one per code point. Do people |
| + // use non-BMP code points and combining diacritics in their passwords? |
| + std::fill(txt.begin(), txt.end(), PASSWORD_REPLACEMENT_CHAR); |
| + } |
| + return txt; |
| +} |
| + |
| void RenderText::ToggleInsertMode() { |
| insert_mode_ = !insert_mode_; |
| cached_bounds_and_offset_valid_ = false; |
| } |
| +void RenderText::SetIsPassword(bool password) { |
| + password_ = password; |
| + cached_bounds_and_offset_valid_ = false; |
| + UpdateLayout(); |
| +} |
| + |
| void RenderText::SetDisplayRect(const Rect& r) { |
| display_rect_ = r; |
| cached_bounds_and_offset_valid_ = false; |
| @@ -273,7 +306,8 @@ void RenderText::SelectAll() { |
| void RenderText::SelectWord() { |
| size_t cursor_position = GetCursorPosition(); |
| - base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
| + string16 txt = GetCensoredText(); |
| + base::i18n::BreakIterator iter(txt, base::i18n::BreakIterator::BREAK_WORD); |
| bool success = iter.Init(); |
| DCHECK(success); |
| if (!success) |
| @@ -289,7 +323,7 @@ void RenderText::SelectWord() { |
| if (selection_start == cursor_position) |
| ++cursor_position; |
| - for (; cursor_position < text().length(); ++cursor_position) { |
| + for (; cursor_position < txt.length(); ++cursor_position) { |
| if (iter.IsEndOfWord(cursor_position) || |
| iter.IsStartOfWord(cursor_position)) |
| break; |
| @@ -416,6 +450,7 @@ RenderText::RenderText() |
| composition_range_(ui::Range::InvalidRange()), |
| style_ranges_(), |
| default_style_(), |
| + password_(false), |
| display_rect_(), |
| display_offset_(), |
| cached_bounds_and_offset_valid_(false) { |
| @@ -439,7 +474,8 @@ SelectionModel RenderText::GetLeftSelectionModel(const SelectionModel& current, |
| // This is probably fast enough for our usage, but we may |
| // want to modify WordIterator so that it can start from the |
| // middle of string and advance backwards. |
| - base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
| + string16 txt = GetCensoredText(); |
| + base::i18n::BreakIterator iter(txt, base::i18n::BreakIterator::BREAK_WORD); |
| bool success = iter.Init(); |
| DCHECK(success); |
| if (!success) |
| @@ -475,7 +511,8 @@ SelectionModel RenderText::GetRightSelectionModel(const SelectionModel& current, |
| if (break_type == CHARACTER_BREAK) |
| return SelectionModel(pos, pos, SelectionModel::LEADING); |
| - base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
| + string16 txt = GetCensoredText(); |
| + base::i18n::BreakIterator iter(txt, base::i18n::BreakIterator::BREAK_WORD); |
| bool success = iter.Init(); |
| DCHECK(success); |
| if (!success) |