Index: ui/gfx/render_text.cc |
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
index 5b9b8c4a56718b8a92e1d98aa41aae5f39da0fc3..35eb30360ecb4291a8e5cb9c0f3cca09d22452a7 100644 |
--- a/ui/gfx/render_text.cc |
+++ b/ui/gfx/render_text.cc |
@@ -10,15 +10,20 @@ |
#include "base/i18n/break_iterator.h" |
#include "base/logging.h" |
#include "base/stl_util.h" |
+#include "base/utf_offset_string_conversions.h" |
#include "third_party/skia/include/core/SkTypeface.h" |
#include "third_party/skia/include/effects/SkGradientShader.h" |
#include "ui/gfx/canvas.h" |
#include "ui/gfx/canvas_skia.h" |
#include "ui/gfx/native_theme.h" |
-#include "unicode/uchar.h" |
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 kPasswordReplacementChar = '*'; |
+ |
// Color settings for text, backgrounds and cursor. |
// These are tentative, and should be derived from theme, system |
// settings and current settings. |
@@ -366,11 +371,27 @@ const Font& RenderText::GetFont() const { |
return font_list_.GetFonts()[0]; |
} |
+string16 RenderText::GetDisplayText() const { |
+ if (!obscured_) { |
+ return text_; |
+ } else { |
msw
2012/02/22 00:33:26
Drop the braces and make the else block just follo
benrg
2012/02/24 19:07:44
Done.
|
+ size_t obscured_text_length = |
+ static_cast<size_t>(Utf16IndexToOffset(text_, 0, text_.length())); |
msw
2012/02/22 00:33:26
Does this work on Win? If not, comment here or blo
benrg
2012/02/24 19:07:44
This method is currently not called on Windows (bu
|
+ return string16(obscured_text_length, kPasswordReplacementChar); |
+ } |
+} |
+ |
void RenderText::ToggleInsertMode() { |
insert_mode_ = !insert_mode_; |
cached_bounds_and_offset_valid_ = false; |
} |
+void RenderText::SetObscured(bool obscured) { |
+ obscured_ = obscured; |
+ cached_bounds_and_offset_valid_ = false; |
+ UpdateLayout(); |
xji
2012/02/18 01:28:47
guard all 3 statements under "if (obscured != obsc
benrg
2012/02/24 19:07:44
Done.
|
+} |
+ |
void RenderText::SetDisplayRect(const Rect& r) { |
display_rect_ = r; |
cached_bounds_and_offset_valid_ = false; |
@@ -494,6 +515,11 @@ void RenderText::SelectAll() { |
} |
void RenderText::SelectWord() { |
+ if (obscured_) { |
+ SelectAll(); |
+ return; |
+ } |
+ |
size_t cursor_position = GetCursorPosition(); |
base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
@@ -612,6 +638,7 @@ RenderText::RenderText() |
insert_mode_(true), |
focused_(false), |
composition_range_(ui::Range::InvalidRange()), |
+ obscured_(false), |
fade_head_(false), |
fade_tail_(false), |
cached_bounds_and_offset_valid_(false) { |