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

Side by Side Diff: ui/views/controls/textfield/native_textfield_views.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, 9 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
« no previous file with comments | « ui/ui_unittests.gypi ('k') | ui/views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, 313 DCHECK_NE(ui::DragDropTypes::DRAG_NONE,
314 GetDragOperationsForView(sender, press_pt)); 314 GetDragOperationsForView(sender, press_pt));
315 data->SetString(GetSelectedText()); 315 data->SetString(GetSelectedText());
316 TextfieldController* controller = textfield_->GetController(); 316 TextfieldController* controller = textfield_->GetController();
317 if (controller) 317 if (controller)
318 controller->OnWriteDragData(data); 318 controller->OnWriteDragData(data);
319 } 319 }
320 320
321 int NativeTextfieldViews::GetDragOperationsForView(views::View* sender, 321 int NativeTextfieldViews::GetDragOperationsForView(views::View* sender,
322 const gfx::Point& p) { 322 const gfx::Point& p) {
323 if (!textfield_->enabled() || !GetRenderText()->IsPointInSelection(p)) 323 if (!textfield_->enabled() || textfield_->IsObscured() ||
324 !GetRenderText()->IsPointInSelection(p))
324 return ui::DragDropTypes::DRAG_NONE; 325 return ui::DragDropTypes::DRAG_NONE;
325 if (sender == this && !textfield_->read_only()) 326 if (sender == this && !textfield_->read_only())
326 return ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY; 327 return ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY;
327 return ui::DragDropTypes::DRAG_COPY; 328 return ui::DragDropTypes::DRAG_COPY;
328 } 329 }
329 330
330 bool NativeTextfieldViews::CanStartDragForView(View* sender, 331 bool NativeTextfieldViews::CanStartDragForView(View* sender,
331 const gfx::Point& press_pt, 332 const gfx::Point& press_pt,
332 const gfx::Point& p) { 333 const gfx::Point& p) {
333 return GetRenderText()->IsPointInSelection(press_pt); 334 return GetRenderText()->IsPointInSelection(press_pt);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // For ChromeOS, we support a pre-defined font list per locale. UpdateFont() 420 // For ChromeOS, we support a pre-defined font list per locale. UpdateFont()
420 // only changes the font size, not the font family names. 421 // only changes the font size, not the font family names.
421 GetRenderText()->SetFontSize(textfield_->font().GetFontSize()); 422 GetRenderText()->SetFontSize(textfield_->font().GetFontSize());
422 #else 423 #else
423 GetRenderText()->SetFontList(gfx::FontList(textfield_->font())); 424 GetRenderText()->SetFontList(gfx::FontList(textfield_->font()));
424 #endif 425 #endif
425 OnCaretBoundsChanged(); 426 OnCaretBoundsChanged();
426 } 427 }
427 428
428 void NativeTextfieldViews::UpdateIsObscured() { 429 void NativeTextfieldViews::UpdateIsObscured() {
429 // TODO(benrg): GetRenderText()->SetObscured(textfield_->IsObscured()); 430 GetRenderText()->SetObscured(textfield_->IsObscured());
430 OnCaretBoundsChanged(); 431 OnCaretBoundsChanged();
431 SchedulePaint(); 432 SchedulePaint();
432 OnTextInputTypeChanged(); 433 OnTextInputTypeChanged();
433 } 434 }
434 435
435 void NativeTextfieldViews::UpdateEnabled() { 436 void NativeTextfieldViews::UpdateEnabled() {
436 SetEnabled(textfield_->enabled()); 437 SetEnabled(textfield_->enabled());
437 SchedulePaint(); 438 SchedulePaint();
438 OnTextInputTypeChanged(); 439 OnTextInputTypeChanged();
439 } 440 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 561
561 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const { 562 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const {
562 return true; 563 return true;
563 } 564 }
564 565
565 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const { 566 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const {
566 bool editable = !textfield_->read_only(); 567 bool editable = !textfield_->read_only();
567 string16 result; 568 string16 result;
568 switch (command_id) { 569 switch (command_id) {
569 case IDS_APP_CUT: 570 case IDS_APP_CUT:
570 return editable && model_->HasSelection(); 571 return editable && model_->HasSelection() && !textfield_->IsObscured();
571 case IDS_APP_COPY: 572 case IDS_APP_COPY:
572 return model_->HasSelection(); 573 return model_->HasSelection() && !textfield_->IsObscured();
573 case IDS_APP_PASTE: 574 case IDS_APP_PASTE:
574 ViewsDelegate::views_delegate->GetClipboard() 575 ViewsDelegate::views_delegate->GetClipboard()
575 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 576 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
576 return editable && !result.empty(); 577 return editable && !result.empty();
577 case IDS_APP_DELETE: 578 case IDS_APP_DELETE:
578 return editable && model_->HasSelection(); 579 return editable && model_->HasSelection();
579 case IDS_APP_SELECT_ALL: 580 case IDS_APP_SELECT_ALL:
580 return true; 581 return true;
581 default: 582 default:
582 return textfield_->GetController()->IsCommandIdEnabled(command_id); 583 return textfield_->GetController()->IsCommandIdEnabled(command_id);
583 } 584 }
584 } 585 }
585 586
586 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id, 587 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id,
587 ui::Accelerator* accelerator) { 588 ui::Accelerator* accelerator) {
588 return false; 589 return false;
589 } 590 }
590 591
591 void NativeTextfieldViews::ExecuteCommand(int command_id) { 592 void NativeTextfieldViews::ExecuteCommand(int command_id) {
593 if (!IsCommandIdEnabled(command_id))
594 return;
595
592 bool text_changed = false; 596 bool text_changed = false;
593 bool editable = !textfield_->read_only();
594 OnBeforeUserAction(); 597 OnBeforeUserAction();
595 switch (command_id) { 598 switch (command_id) {
596 case IDS_APP_CUT: 599 case IDS_APP_CUT:
597 if (editable) 600 text_changed = Cut();
598 text_changed = Cut();
599 break; 601 break;
600 case IDS_APP_COPY: 602 case IDS_APP_COPY:
601 Copy(); 603 Copy();
602 break; 604 break;
603 case IDS_APP_PASTE: 605 case IDS_APP_PASTE:
604 if (editable) 606 text_changed = Paste();
605 text_changed = Paste();
606 break; 607 break;
607 case IDS_APP_DELETE: 608 case IDS_APP_DELETE:
608 if (editable) 609 text_changed = model_->Delete();
609 text_changed = model_->Delete();
610 break; 610 break;
611 case IDS_APP_SELECT_ALL: 611 case IDS_APP_SELECT_ALL:
612 SelectAll(); 612 SelectAll();
613 break; 613 break;
614 default: 614 default:
615 textfield_->GetController()->ExecuteCommand(command_id); 615 textfield_->GetController()->ExecuteCommand(command_id);
616 break; 616 break;
617 } 617 }
618 618
619 // The cursor must have changed if text changed during cut/paste/delete. 619 // The cursor must have changed if text changed during cut/paste/delete.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { 853 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
854 // TODO(oshima): Refactor and consolidate with ExecuteCommand. 854 // TODO(oshima): Refactor and consolidate with ExecuteCommand.
855 if (key_event.type() == ui::ET_KEY_PRESSED) { 855 if (key_event.type() == ui::ET_KEY_PRESSED) {
856 ui::KeyboardCode key_code = key_event.key_code(); 856 ui::KeyboardCode key_code = key_event.key_code();
857 // TODO(oshima): shift-tab does not work. Figure out why and fix. 857 // TODO(oshima): shift-tab does not work. Figure out why and fix.
858 if (key_code == ui::VKEY_TAB) 858 if (key_code == ui::VKEY_TAB)
859 return false; 859 return false;
860 860
861 OnBeforeUserAction(); 861 OnBeforeUserAction();
862 bool editable = !textfield_->read_only(); 862 bool editable = !textfield_->read_only();
863 bool readable = !textfield_->IsObscured();
863 bool selection = key_event.IsShiftDown(); 864 bool selection = key_event.IsShiftDown();
864 bool control = key_event.IsControlDown(); 865 bool control = key_event.IsControlDown();
865 bool text_changed = false; 866 bool text_changed = false;
866 bool cursor_changed = false; 867 bool cursor_changed = false;
867 switch (key_code) { 868 switch (key_code) {
868 case ui::VKEY_Z: 869 case ui::VKEY_Z:
869 if (control && editable) 870 if (control && editable)
870 cursor_changed = text_changed = model_->Undo(); 871 cursor_changed = text_changed = model_->Undo();
871 break; 872 break;
872 case ui::VKEY_Y: 873 case ui::VKEY_Y:
873 if (control && editable) 874 if (control && editable)
874 cursor_changed = text_changed = model_->Redo(); 875 cursor_changed = text_changed = model_->Redo();
875 break; 876 break;
876 case ui::VKEY_A: 877 case ui::VKEY_A:
877 if (control) { 878 if (control) {
878 model_->SelectAll(); 879 model_->SelectAll();
879 cursor_changed = true; 880 cursor_changed = true;
880 } 881 }
881 break; 882 break;
882 case ui::VKEY_X: 883 case ui::VKEY_X:
883 if (control && editable) 884 if (control && editable && readable)
884 cursor_changed = text_changed = Cut(); 885 cursor_changed = text_changed = Cut();
885 break; 886 break;
886 case ui::VKEY_C: 887 case ui::VKEY_C:
887 if (control) 888 if (control && readable)
888 Copy(); 889 Copy();
889 break; 890 break;
890 case ui::VKEY_V: 891 case ui::VKEY_V:
891 if (control && editable) 892 if (control && editable)
892 cursor_changed = text_changed = Paste(); 893 cursor_changed = text_changed = Paste();
893 break; 894 break;
894 case ui::VKEY_RIGHT: 895 case ui::VKEY_RIGHT:
895 case ui::VKEY_LEFT: 896 case ui::VKEY_LEFT:
896 model_->MoveCursor( 897 model_->MoveCursor(
897 control ? gfx::WORD_BREAK : gfx::CHARACTER_BREAK, 898 control ? gfx::WORD_BREAK : gfx::CHARACTER_BREAK,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 1139
1139 #if defined(USE_AURA) 1140 #if defined(USE_AURA)
1140 // static 1141 // static
1141 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 1142 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
1142 Textfield* field) { 1143 Textfield* field) {
1143 return new NativeTextfieldViews(field); 1144 return new NativeTextfieldViews(field);
1144 } 1145 }
1145 #endif 1146 #endif
1146 1147
1147 } // namespace views 1148 } // namespace views
OLDNEW
« no previous file with comments | « ui/ui_unittests.gypi ('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