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

Side by Side Diff: ui/views/controls/textfield/textfield_model.cc

Issue 2358463002: Views::Textfield: Prevent revealing password text. (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/views/controls/textfield/textfield_model.h" 5 #include "ui/views/controls/textfield/textfield_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 render_text_->SetCursorPosition(save); 342 render_text_->SetCursorPosition(save);
343 ClearSelection(); 343 ClearSelection();
344 } 344 }
345 345
346 bool TextfieldModel::Delete(bool add_to_kill_buffer) { 346 bool TextfieldModel::Delete(bool add_to_kill_buffer) {
347 if (HasCompositionText()) { 347 if (HasCompositionText()) {
348 // No undo/redo for composition text. 348 // No undo/redo for composition text.
349 CancelCompositionText(); 349 CancelCompositionText();
350 return true; 350 return true;
351 } 351 }
352 // |add_to_kill_buffer| should never be true for an obscured textfield.
Peter Kasting 2016/09/20 17:29:30 Nit: Why not DCHECK this atop the function instead
karandeepb 2016/09/21 03:36:12 Done.
353 DCHECK(!(add_to_kill_buffer && render_text_->obscured()));
Peter Kasting 2016/09/20 17:29:30 Nit: Distribute "!" through and eliminate parens
karandeepb 2016/09/21 03:36:12 Done.
354
352 if (HasSelection()) { 355 if (HasSelection()) {
353 if (add_to_kill_buffer) 356 if (add_to_kill_buffer)
354 SetKillBuffer(GetSelectedText()); 357 SetKillBuffer(GetSelectedText());
355 DeleteSelection(); 358 DeleteSelection();
356 return true; 359 return true;
357 } 360 }
358 if (text().length() > GetCursorPosition()) { 361 if (text().length() > GetCursorPosition()) {
359 size_t cursor_position = GetCursorPosition(); 362 size_t cursor_position = GetCursorPosition();
360 size_t next_grapheme_index = render_text_->IndexOfAdjacentGrapheme( 363 size_t next_grapheme_index = render_text_->IndexOfAdjacentGrapheme(
361 cursor_position, gfx::CURSOR_FORWARD); 364 cursor_position, gfx::CURSOR_FORWARD);
362 gfx::Range range_to_delete(cursor_position, next_grapheme_index); 365 gfx::Range range_to_delete(cursor_position, next_grapheme_index);
363 if (add_to_kill_buffer) 366 if (add_to_kill_buffer)
364 SetKillBuffer(GetTextFromRange(range_to_delete)); 367 SetKillBuffer(GetTextFromRange(range_to_delete));
365 ExecuteAndRecordDelete(range_to_delete, true); 368 ExecuteAndRecordDelete(range_to_delete, true);
366 return true; 369 return true;
367 } 370 }
368 return false; 371 return false;
369 } 372 }
370 373
371 bool TextfieldModel::Backspace(bool add_to_kill_buffer) { 374 bool TextfieldModel::Backspace(bool add_to_kill_buffer) {
372 if (HasCompositionText()) { 375 if (HasCompositionText()) {
373 // No undo/redo for composition text. 376 // No undo/redo for composition text.
374 CancelCompositionText(); 377 CancelCompositionText();
375 return true; 378 return true;
376 } 379 }
380 // |add_to_kill_buffer| should never be true for an obscured textfield.
381 DCHECK(!(add_to_kill_buffer && render_text_->obscured()));
Peter Kasting 2016/09/20 17:29:30 Same comments
karandeepb 2016/09/21 03:36:12 Done.
382
377 if (HasSelection()) { 383 if (HasSelection()) {
378 if (add_to_kill_buffer) 384 if (add_to_kill_buffer)
379 SetKillBuffer(GetSelectedText()); 385 SetKillBuffer(GetSelectedText());
380 DeleteSelection(); 386 DeleteSelection();
381 return true; 387 return true;
382 } 388 }
383 size_t cursor_position = GetCursorPosition(); 389 size_t cursor_position = GetCursorPosition();
384 if (cursor_position > 0) { 390 if (cursor_position > 0) {
385 // Delete one code point, which may be two UTF-16 words. 391 // Delete one code point, which may be two UTF-16 words.
386 size_t previous_grapheme_index = 392 size_t previous_grapheme_index =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 bool TextfieldModel::MoveCursorTo(const gfx::Point& point, bool select) { 429 bool TextfieldModel::MoveCursorTo(const gfx::Point& point, bool select) {
424 if (HasCompositionText()) 430 if (HasCompositionText())
425 ConfirmCompositionText(); 431 ConfirmCompositionText();
426 gfx::SelectionModel cursor = render_text_->FindCursorPosition(point); 432 gfx::SelectionModel cursor = render_text_->FindCursorPosition(point);
427 if (select) 433 if (select)
428 cursor.set_selection_start(render_text_->selection().start()); 434 cursor.set_selection_start(render_text_->selection().start());
429 return render_text_->MoveCursorTo(cursor); 435 return render_text_->MoveCursorTo(cursor);
430 } 436 }
431 437
432 base::string16 TextfieldModel::GetSelectedText() const { 438 base::string16 TextfieldModel::GetSelectedText() const {
433 return text().substr(render_text_->selection().GetMin(), 439 return GetTextFromRange(render_text_->selection());
434 render_text_->selection().length());
435 } 440 }
436 441
437 void TextfieldModel::SelectRange(const gfx::Range& range) { 442 void TextfieldModel::SelectRange(const gfx::Range& range) {
438 if (HasCompositionText()) 443 if (HasCompositionText())
439 ConfirmCompositionText(); 444 ConfirmCompositionText();
440 render_text_->SelectRange(range); 445 render_text_->SelectRange(range);
441 } 446 }
442 447
443 void TextfieldModel::SelectSelectionModel(const gfx::SelectionModel& sel) { 448 void TextfieldModel::SelectSelectionModel(const gfx::SelectionModel& sel) {
444 if (HasCompositionText()) 449 if (HasCompositionText())
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 render_text_->SetCursorPosition(new_cursor_pos); 851 render_text_->SetCursorPosition(new_cursor_pos);
847 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). 852 // TODO(oshima): Select text that was just undone, like Mac (but not GTK).
848 } 853 }
849 854
850 // static 855 // static
851 void TextfieldModel::ClearKillBuffer() { 856 void TextfieldModel::ClearKillBuffer() {
852 SetKillBuffer(base::string16()); 857 SetKillBuffer(base::string16());
853 } 858 }
854 859
855 } // namespace views 860 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698