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

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: for dcommit Created 8 years, 10 months 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
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698