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

Side by Side 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: new implementation, linux only 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/i18n/break_iterator.h" 10 #include "base/i18n/break_iterator.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/utf_offset_string_conversions.h"
13 #include "third_party/skia/include/core/SkTypeface.h" 14 #include "third_party/skia/include/core/SkTypeface.h"
14 #include "third_party/skia/include/effects/SkGradientShader.h" 15 #include "third_party/skia/include/effects/SkGradientShader.h"
15 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/canvas_skia.h" 17 #include "ui/gfx/canvas_skia.h"
17 #include "ui/gfx/native_theme.h" 18 #include "ui/gfx/native_theme.h"
18 #include "unicode/uchar.h"
19 19
20 namespace { 20 namespace {
21 21
22 // All chars are replaced by this char when the password style is set.
23 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*'
24 // that's available in the font (find_invisible_char() in gtkentry.c).
25 const char16 kPasswordReplacementChar = '*';
26
22 // Color settings for text, backgrounds and cursor. 27 // Color settings for text, backgrounds and cursor.
23 // These are tentative, and should be derived from theme, system 28 // These are tentative, and should be derived from theme, system
24 // settings and current settings. 29 // settings and current settings.
25 // TODO(oshima): Change this to match the standard chrome 30 // TODO(oshima): Change this to match the standard chrome
26 // before dogfooding textfield views. 31 // before dogfooding textfield views.
27 const SkColor kCursorColor = SK_ColorBLACK; 32 const SkColor kCursorColor = SK_ColorBLACK;
28 33
29 #ifndef NDEBUG 34 #ifndef NDEBUG
30 // Check StyleRanges invariant conditions: sorted and non-overlapping ranges. 35 // Check StyleRanges invariant conditions: sorted and non-overlapping ranges.
31 void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) { 36 void CheckStyleRanges(const gfx::StyleRanges& style_ranges, size_t length) {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 364
360 void RenderText::SetCursorEnabled(bool cursor_enabled) { 365 void RenderText::SetCursorEnabled(bool cursor_enabled) {
361 cursor_enabled_ = cursor_enabled; 366 cursor_enabled_ = cursor_enabled;
362 cached_bounds_and_offset_valid_ = false; 367 cached_bounds_and_offset_valid_ = false;
363 } 368 }
364 369
365 const Font& RenderText::GetFont() const { 370 const Font& RenderText::GetFont() const {
366 return font_list_.GetFonts()[0]; 371 return font_list_.GetFonts()[0];
367 } 372 }
368 373
374 string16 RenderText::GetDisplayText() const {
375 if (!obscured_) {
376 return text_;
377 } 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.
378 size_t obscured_text_length =
379 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
380 return string16(obscured_text_length, kPasswordReplacementChar);
381 }
382 }
383
369 void RenderText::ToggleInsertMode() { 384 void RenderText::ToggleInsertMode() {
370 insert_mode_ = !insert_mode_; 385 insert_mode_ = !insert_mode_;
371 cached_bounds_and_offset_valid_ = false; 386 cached_bounds_and_offset_valid_ = false;
372 } 387 }
373 388
389 void RenderText::SetObscured(bool obscured) {
390 obscured_ = obscured;
391 cached_bounds_and_offset_valid_ = false;
392 UpdateLayout();
xji 2012/02/18 01:28:47 guard all 3 statements under "if (obscured != obsc
benrg 2012/02/24 19:07:44 Done.
393 }
394
374 void RenderText::SetDisplayRect(const Rect& r) { 395 void RenderText::SetDisplayRect(const Rect& r) {
375 display_rect_ = r; 396 display_rect_ = r;
376 cached_bounds_and_offset_valid_ = false; 397 cached_bounds_and_offset_valid_ = false;
377 UpdateLayout(); 398 UpdateLayout();
378 } 399 }
379 400
380 size_t RenderText::GetCursorPosition() const { 401 size_t RenderText::GetCursorPosition() const {
381 return selection_model_.selection_end(); 402 return selection_model_.selection_end();
382 } 403 }
383 404
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 SetSelectionModel(sel); 508 SetSelectionModel(sel);
488 } 509 }
489 510
490 void RenderText::SelectAll() { 511 void RenderText::SelectAll() {
491 SelectionModel sel = EdgeSelectionModel(CURSOR_RIGHT); 512 SelectionModel sel = EdgeSelectionModel(CURSOR_RIGHT);
492 sel.set_selection_start(EdgeSelectionModel(CURSOR_LEFT).selection_start()); 513 sel.set_selection_start(EdgeSelectionModel(CURSOR_LEFT).selection_start());
493 SetSelectionModel(sel); 514 SetSelectionModel(sel);
494 } 515 }
495 516
496 void RenderText::SelectWord() { 517 void RenderText::SelectWord() {
518 if (obscured_) {
519 SelectAll();
520 return;
521 }
522
497 size_t cursor_position = GetCursorPosition(); 523 size_t cursor_position = GetCursorPosition();
498 524
499 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); 525 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD);
500 bool success = iter.Init(); 526 bool success = iter.Init();
501 DCHECK(success); 527 DCHECK(success);
502 if (!success) 528 if (!success)
503 return; 529 return;
504 530
505 size_t selection_start = cursor_position; 531 size_t selection_start = cursor_position;
506 for (; selection_start != 0; --selection_start) { 532 for (; selection_start != 0; --selection_start) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return selection_model_; 631 return selection_model_;
606 } 632 }
607 633
608 RenderText::RenderText() 634 RenderText::RenderText()
609 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), 635 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
610 cursor_enabled_(true), 636 cursor_enabled_(true),
611 cursor_visible_(false), 637 cursor_visible_(false),
612 insert_mode_(true), 638 insert_mode_(true),
613 focused_(false), 639 focused_(false),
614 composition_range_(ui::Range::InvalidRange()), 640 composition_range_(ui::Range::InvalidRange()),
641 obscured_(false),
615 fade_head_(false), 642 fade_head_(false),
616 fade_tail_(false), 643 fade_tail_(false),
617 cached_bounds_and_offset_valid_(false) { 644 cached_bounds_and_offset_valid_(false) {
618 } 645 }
619 646
620 const Point& RenderText::GetUpdatedDisplayOffset() { 647 const Point& RenderText::GetUpdatedDisplayOffset() {
621 UpdateCachedBoundsAndOffset(); 648 UpdateCachedBoundsAndOffset();
622 return display_offset_; 649 return display_offset_;
623 } 650 }
624 651
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 if (cursor_enabled() && cursor_visible() && focused()) { 879 if (cursor_enabled() && cursor_visible() && focused()) {
853 const Rect& bounds = GetUpdatedCursorBounds(); 880 const Rect& bounds = GetUpdatedCursorBounds();
854 if (bounds.width() != 0) 881 if (bounds.width() != 0)
855 canvas->FillRect(bounds, kCursorColor); 882 canvas->FillRect(bounds, kCursorColor);
856 else 883 else
857 canvas->DrawRect(bounds, kCursorColor); 884 canvas->DrawRect(bounds, kCursorColor);
858 } 885 }
859 } 886 }
860 887
861 } // namespace gfx 888 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698