Index: ui/gfx/render_text.cc |
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
index 2e316e356b1799eb1b9524b2fd56285cc1c62b08..2ce62791b03aabd4c69556f86e36548df69ce301 100644 |
--- a/ui/gfx/render_text.cc |
+++ b/ui/gfx/render_text.cc |
@@ -12,13 +12,18 @@ |
#include "base/stl_util.h" |
#include "third_party/skia/include/core/SkTypeface.h" |
#include "third_party/skia/include/effects/SkGradientShader.h" |
+#include "ui/base/text/utf16_indexing.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 = '*'; |
+ |
// Default color used for the cursor. |
const SkColor kDefaultCursorColor = SK_ColorBLACK; |
@@ -374,6 +379,14 @@ void RenderText::ToggleInsertMode() { |
cached_bounds_and_offset_valid_ = false; |
} |
+void RenderText::SetObscured(bool obscured) { |
+ if (obscured != obscured_) { |
+ obscured_ = obscured; |
+ cached_bounds_and_offset_valid_ = false; |
+ UpdateLayout(); |
+ } |
+} |
+ |
void RenderText::SetDisplayRect(const Rect& r) { |
display_rect_ = r; |
cached_bounds_and_offset_valid_ = false; |
@@ -497,6 +510,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); |
@@ -616,6 +634,7 @@ RenderText::RenderText() |
cursor_color_(kDefaultCursorColor), |
focused_(false), |
composition_range_(ui::Range::InvalidRange()), |
+ obscured_(false), |
fade_head_(false), |
fade_tail_(false), |
background_is_transparent_(false), |
@@ -653,6 +672,14 @@ void RenderText::SetSelectionModel(const SelectionModel& model) { |
cached_bounds_and_offset_valid_ = false; |
} |
+string16 RenderText::GetDisplayText() const { |
+ if (!obscured_) |
+ return text_; |
+ size_t obscured_text_length = |
+ static_cast<size_t>(ui::UTF16IndexToOffset(text_, 0, text_.length())); |
+ return string16(obscured_text_length, kPasswordReplacementChar); |
+} |
+ |
void RenderText::ApplyCompositionAndSelectionStyles( |
StyleRanges* style_ranges) { |
// TODO(msw): This pattern ought to be reconsidered; what about composition |