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

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: tweak NativeTextfieldViews::ExecuteCommand 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
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 80550c3ad2cdd7f48a4470875f9c158007231f18..dbfd0061285d32d8de3a1092a6d8ff3fe16fd24f 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.
@@ -378,6 +383,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;
@@ -501,6 +514,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);
@@ -619,6 +637,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) {
@@ -655,6 +674,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>(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

Powered by Google App Engine
This is Rietveld 408576698