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

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

Issue 9467017: Password support for NativeTextfieldViews, in the model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/views/controls/textfield/native_textfield_views.h" 5 #include "ui/views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, 302 DCHECK_NE(ui::DragDropTypes::DRAG_NONE,
303 GetDragOperationsForView(sender, press_pt)); 303 GetDragOperationsForView(sender, press_pt));
304 data->SetString(GetSelectedText()); 304 data->SetString(GetSelectedText());
305 TextfieldController* controller = textfield_->GetController(); 305 TextfieldController* controller = textfield_->GetController();
306 if (controller) 306 if (controller)
307 controller->OnWriteDragData(data); 307 controller->OnWriteDragData(data);
308 } 308 }
309 309
310 int NativeTextfieldViews::GetDragOperationsForView(views::View* sender, 310 int NativeTextfieldViews::GetDragOperationsForView(views::View* sender,
311 const gfx::Point& p) { 311 const gfx::Point& p) {
312 if (!textfield_->enabled() || !GetRenderText()->IsPointInSelection(p)) 312 if (!textfield_->enabled() || textfield_->IsObscured() ||
313 !GetRenderText()->IsPointInSelection(p))
313 return ui::DragDropTypes::DRAG_NONE; 314 return ui::DragDropTypes::DRAG_NONE;
314 if (sender == this && !textfield_->read_only()) 315 if (sender == this && !textfield_->read_only())
315 return ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY; 316 return ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY;
316 return ui::DragDropTypes::DRAG_COPY; 317 return ui::DragDropTypes::DRAG_COPY;
317 } 318 }
318 319
319 bool NativeTextfieldViews::CanStartDragForView(View* sender, 320 bool NativeTextfieldViews::CanStartDragForView(View* sender,
320 const gfx::Point& press_pt, 321 const gfx::Point& press_pt,
321 const gfx::Point& p) { 322 const gfx::Point& p) {
322 return GetRenderText()->IsPointInSelection(press_pt); 323 return GetRenderText()->IsPointInSelection(press_pt);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // For ChromeOS, we support a pre-defined font list per locale. UpdateFont() 405 // For ChromeOS, we support a pre-defined font list per locale. UpdateFont()
405 // only changes the font size, not the font family names. 406 // only changes the font size, not the font family names.
406 GetRenderText()->SetFontSize(textfield_->font().GetFontSize()); 407 GetRenderText()->SetFontSize(textfield_->font().GetFontSize());
407 #else 408 #else
408 GetRenderText()->SetFontList(gfx::FontList(textfield_->font())); 409 GetRenderText()->SetFontList(gfx::FontList(textfield_->font()));
409 #endif 410 #endif
410 OnCaretBoundsChanged(); 411 OnCaretBoundsChanged();
411 } 412 }
412 413
413 void NativeTextfieldViews::UpdateIsObscured() { 414 void NativeTextfieldViews::UpdateIsObscured() {
414 // TODO(benrg): GetRenderText()->SetObscured(textfield_->IsObscured()); 415 model_->SetObscured(textfield_->IsObscured());
415 OnCaretBoundsChanged(); 416 OnCaretBoundsChanged();
416 SchedulePaint(); 417 SchedulePaint();
417 OnTextInputTypeChanged(); 418 OnTextInputTypeChanged();
418 } 419 }
419 420
420 void NativeTextfieldViews::UpdateEnabled() { 421 void NativeTextfieldViews::UpdateEnabled() {
421 SetEnabled(textfield_->enabled()); 422 SetEnabled(textfield_->enabled());
422 SchedulePaint(); 423 SchedulePaint();
423 OnTextInputTypeChanged(); 424 OnTextInputTypeChanged();
424 } 425 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 546
546 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const { 547 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const {
547 return true; 548 return true;
548 } 549 }
549 550
550 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const { 551 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const {
551 bool editable = !textfield_->read_only(); 552 bool editable = !textfield_->read_only();
552 string16 result; 553 string16 result;
553 switch (command_id) { 554 switch (command_id) {
554 case IDS_APP_CUT: 555 case IDS_APP_CUT:
555 return editable && model_->HasSelection(); 556 return editable && model_->HasSelection() && !textfield_->IsObscured();
556 case IDS_APP_COPY: 557 case IDS_APP_COPY:
557 return model_->HasSelection(); 558 return model_->HasSelection() && !textfield_->IsObscured();
558 case IDS_APP_PASTE: 559 case IDS_APP_PASTE:
559 ViewsDelegate::views_delegate->GetClipboard() 560 ViewsDelegate::views_delegate->GetClipboard()
560 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 561 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
561 return editable && !result.empty(); 562 return editable && !result.empty();
562 case IDS_APP_DELETE: 563 case IDS_APP_DELETE:
563 return editable && model_->HasSelection(); 564 return editable && model_->HasSelection();
564 case IDS_APP_SELECT_ALL: 565 case IDS_APP_SELECT_ALL:
565 return true; 566 return true;
566 default: 567 default:
567 return textfield_->GetController()->IsCommandIdEnabled(command_id); 568 return textfield_->GetController()->IsCommandIdEnabled(command_id);
568 } 569 }
569 } 570 }
570 571
571 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id, 572 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id,
572 ui::Accelerator* accelerator) { 573 ui::Accelerator* accelerator) {
573 return false; 574 return false;
574 } 575 }
575 576
576 void NativeTextfieldViews::ExecuteCommand(int command_id) { 577 void NativeTextfieldViews::ExecuteCommand(int command_id) {
577 bool text_changed = false; 578 bool text_changed = false;
578 bool editable = !textfield_->read_only();
579 OnBeforeUserAction(); 579 OnBeforeUserAction();
580 switch (command_id) { 580 if (IsCommandIdEnabled(command_id)) {
581 case IDS_APP_CUT: 581 switch (command_id) {
582 if (editable) 582 case IDS_APP_CUT:
583 text_changed = Cut(); 583 text_changed = Cut();
584 break; 584 break;
585 case IDS_APP_COPY: 585 case IDS_APP_COPY:
586 Copy(); 586 Copy();
587 break; 587 break;
588 case IDS_APP_PASTE: 588 case IDS_APP_PASTE:
589 if (editable)
590 text_changed = Paste(); 589 text_changed = Paste();
591 break; 590 break;
592 case IDS_APP_DELETE: 591 case IDS_APP_DELETE:
593 if (editable)
594 text_changed = model_->Delete(); 592 text_changed = model_->Delete();
595 break; 593 break;
596 case IDS_APP_SELECT_ALL: 594 case IDS_APP_SELECT_ALL:
597 SelectAll(); 595 SelectAll();
598 break; 596 break;
599 default: 597 default:
600 textfield_->GetController()->ExecuteCommand(command_id); 598 textfield_->GetController()->ExecuteCommand(command_id);
601 break; 599 break;
600 }
602 } 601 }
603 602
604 // The cursor must have changed if text changed during cut/paste/delete. 603 // The cursor must have changed if text changed during cut/paste/delete.
605 UpdateAfterChange(text_changed, text_changed); 604 UpdateAfterChange(text_changed, text_changed);
606 OnAfterUserAction(); 605 OnAfterUserAction();
607 } 606 }
608 607
609 void NativeTextfieldViews::ApplyStyleRange(const gfx::StyleRange& style) { 608 void NativeTextfieldViews::ApplyStyleRange(const gfx::StyleRange& style) {
610 GetRenderText()->ApplyStyleRange(style); 609 GetRenderText()->ApplyStyleRange(style);
611 SchedulePaint(); 610 SchedulePaint();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { 830 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
832 // TODO(oshima): Refactor and consolidate with ExecuteCommand. 831 // TODO(oshima): Refactor and consolidate with ExecuteCommand.
833 if (key_event.type() == ui::ET_KEY_PRESSED) { 832 if (key_event.type() == ui::ET_KEY_PRESSED) {
834 ui::KeyboardCode key_code = key_event.key_code(); 833 ui::KeyboardCode key_code = key_event.key_code();
835 // TODO(oshima): shift-tab does not work. Figure out why and fix. 834 // TODO(oshima): shift-tab does not work. Figure out why and fix.
836 if (key_code == ui::VKEY_TAB) 835 if (key_code == ui::VKEY_TAB)
837 return false; 836 return false;
838 837
839 OnBeforeUserAction(); 838 OnBeforeUserAction();
840 bool editable = !textfield_->read_only(); 839 bool editable = !textfield_->read_only();
840 bool readable = !textfield_->IsObscured();
841 bool selection = key_event.IsShiftDown(); 841 bool selection = key_event.IsShiftDown();
842 bool control = key_event.IsControlDown(); 842 bool control = key_event.IsControlDown();
843 bool text_changed = false; 843 bool text_changed = false;
844 bool cursor_changed = false; 844 bool cursor_changed = false;
845 switch (key_code) { 845 switch (key_code) {
846 case ui::VKEY_Z: 846 case ui::VKEY_Z:
847 if (control && editable) 847 if (control && editable)
848 cursor_changed = text_changed = model_->Undo(); 848 cursor_changed = text_changed = model_->Undo();
849 break; 849 break;
850 case ui::VKEY_Y: 850 case ui::VKEY_Y:
851 if (control && editable) 851 if (control && editable)
852 cursor_changed = text_changed = model_->Redo(); 852 cursor_changed = text_changed = model_->Redo();
853 break; 853 break;
854 case ui::VKEY_A: 854 case ui::VKEY_A:
855 if (control) { 855 if (control) {
856 model_->SelectAll(); 856 model_->SelectAll();
857 cursor_changed = true; 857 cursor_changed = true;
858 } 858 }
859 break; 859 break;
860 case ui::VKEY_X: 860 case ui::VKEY_X:
861 if (control && editable) 861 if (control && editable && readable)
862 cursor_changed = text_changed = Cut(); 862 cursor_changed = text_changed = Cut();
863 break; 863 break;
864 case ui::VKEY_C: 864 case ui::VKEY_C:
865 if (control) 865 if (control && readable)
866 Copy(); 866 Copy();
867 break; 867 break;
868 case ui::VKEY_V: 868 case ui::VKEY_V:
869 if (control && editable) 869 if (control && editable)
870 cursor_changed = text_changed = Paste(); 870 cursor_changed = text_changed = Paste();
871 break; 871 break;
872 case ui::VKEY_RIGHT: 872 case ui::VKEY_RIGHT:
873 case ui::VKEY_LEFT: 873 case ui::VKEY_LEFT:
874 model_->MoveCursor( 874 model_->MoveCursor(
875 control ? gfx::WORD_BREAK : gfx::CHARACTER_BREAK, 875 control ? gfx::WORD_BREAK : gfx::CHARACTER_BREAK,
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 1123
1124 #if defined(USE_AURA) 1124 #if defined(USE_AURA)
1125 // static 1125 // static
1126 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 1126 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
1127 Textfield* field) { 1127 Textfield* field) {
1128 return new NativeTextfieldViews(field); 1128 return new NativeTextfieldViews(field);
1129 } 1129 }
1130 #endif 1130 #endif
1131 1131
1132 } // namespace views 1132 } // namespace views
OLDNEW
« no previous file with comments | « base/utf_offset_string_conversions_unittest.cc ('k') | ui/views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698