Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Unified Diff: ui/gfx/render_text.cc

Issue 8747001: Reintroduce password support to NativeTextfieldViews (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rerebase Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 696a4f040911421072729dcd7ee58fc7c8b6def7..cf065157da70dbf635c52a532e514b1f271ed31f 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -15,6 +15,11 @@
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 = '*';
+
#ifndef NDEBUG
// Check StyleRanges invariant conditions: sorted and non-overlapping ranges.
void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) {
@@ -83,6 +88,7 @@ StyleRange::StyleRange()
foreground(SK_ColorBLACK),
strike(false),
underline(false),
+ password(false),
range() {
}
@@ -127,6 +133,22 @@ void RenderText::SetText(const string16& text) {
UpdateLayout();
}
+string16 RenderText::GetCensoredText() const {
+ string16 txt = text();
+ for (gfx::StyleRanges::const_iterator i = style_ranges().begin();
+ i != style_ranges().end(); ++i) {
+ if (i->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() + i->range.start(),
+ txt.begin() + i->range.end(), PASSWORD_REPLACEMENT_CHAR);
+ }
+ }
+ return txt;
+}
+
void RenderText::ToggleInsertMode() {
insert_mode_ = !insert_mode_;
cached_bounds_and_offset_valid_ = false;

Powered by Google App Engine
This is Rietveld 408576698