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

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: delete more dead code, address recent comments Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 void NativeTextfieldViews::WriteDragDataForView(views::View* sender, 292 void NativeTextfieldViews::WriteDragDataForView(views::View* sender,
293 const gfx::Point& press_pt, 293 const gfx::Point& press_pt,
294 OSExchangeData* data) { 294 OSExchangeData* data) {
295 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, 295 DCHECK_NE(ui::DragDropTypes::DRAG_NONE,
296 GetDragOperationsForView(sender, press_pt)); 296 GetDragOperationsForView(sender, press_pt));
297 data->SetString(GetSelectedText()); 297 data->SetString(GetSelectedText());
298 } 298 }
299 299
300 int NativeTextfieldViews::GetDragOperationsForView(views::View* sender, 300 int NativeTextfieldViews::GetDragOperationsForView(views::View* sender,
301 const gfx::Point& p) { 301 const gfx::Point& p) {
302 if (!textfield_->IsEnabled() || !GetRenderText()->IsPointInSelection(p)) 302 if (!textfield_->IsEnabled() || textfield_->IsPassword()
303 || !GetRenderText()->IsPointInSelection(p))
303 return ui::DragDropTypes::DRAG_NONE; 304 return ui::DragDropTypes::DRAG_NONE;
304 if (sender == this && !textfield_->read_only()) 305 if (sender == this && !textfield_->read_only())
305 return ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY; 306 return ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY;
306 return ui::DragDropTypes::DRAG_COPY; 307 return ui::DragDropTypes::DRAG_COPY;
307 } 308 }
308 309
309 bool NativeTextfieldViews::CanStartDragForView(View* sender, 310 bool NativeTextfieldViews::CanStartDragForView(View* sender,
310 const gfx::Point& press_pt, 311 const gfx::Point& press_pt,
311 const gfx::Point& p) { 312 const gfx::Point& p) {
312 return GetRenderText()->IsPointInSelection(press_pt); 313 return GetRenderText()->IsPointInSelection(press_pt);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 // Update the default text style. 394 // Update the default text style.
394 gfx::StyleRange default_style(GetRenderText()->default_style()); 395 gfx::StyleRange default_style(GetRenderText()->default_style());
395 default_style.font = textfield_->font(); 396 default_style.font = textfield_->font();
396 GetRenderText()->set_default_style(default_style); 397 GetRenderText()->set_default_style(default_style);
397 GetRenderText()->ApplyDefaultStyle(); 398 GetRenderText()->ApplyDefaultStyle();
398 399
399 OnCaretBoundsChanged(); 400 OnCaretBoundsChanged();
400 } 401 }
401 402
402 void NativeTextfieldViews::UpdateIsPassword() { 403 void NativeTextfieldViews::UpdateIsPassword() {
403 model_->set_is_password(textfield_->IsPassword()); 404 GetRenderText()->SetObscured(textfield_->IsPassword());
404 OnCaretBoundsChanged(); 405 OnCaretBoundsChanged();
405 SchedulePaint(); 406 SchedulePaint();
406 OnTextInputTypeChanged(); 407 OnTextInputTypeChanged();
407 } 408 }
408 409
409 void NativeTextfieldViews::UpdateEnabled() { 410 void NativeTextfieldViews::UpdateEnabled() {
410 SetEnabled(textfield_->IsEnabled()); 411 SetEnabled(textfield_->IsEnabled());
411 SchedulePaint(); 412 SchedulePaint();
412 OnTextInputTypeChanged(); 413 OnTextInputTypeChanged();
413 } 414 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 531
531 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const { 532 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const {
532 return true; 533 return true;
533 } 534 }
534 535
535 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const { 536 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const {
536 bool editable = !textfield_->read_only(); 537 bool editable = !textfield_->read_only();
537 string16 result; 538 string16 result;
538 switch (command_id) { 539 switch (command_id) {
539 case IDS_APP_CUT: 540 case IDS_APP_CUT:
540 return editable && model_->HasSelection(); 541 return editable && model_->HasSelection() && !textfield_->IsPassword();
541 case IDS_APP_COPY: 542 case IDS_APP_COPY:
542 return model_->HasSelection(); 543 return model_->HasSelection() && !textfield_->IsPassword();
543 case IDS_APP_PASTE: 544 case IDS_APP_PASTE:
544 ViewsDelegate::views_delegate->GetClipboard() 545 ViewsDelegate::views_delegate->GetClipboard()
545 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); 546 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
546 return editable && !result.empty(); 547 return editable && !result.empty();
547 case IDS_APP_DELETE: 548 case IDS_APP_DELETE:
548 return editable && model_->HasSelection(); 549 return editable && model_->HasSelection();
549 case IDS_APP_SELECT_ALL: 550 case IDS_APP_SELECT_ALL:
550 return true; 551 return true;
551 default: 552 default:
552 NOTREACHED(); 553 NOTREACHED();
553 return false; 554 return false;
554 } 555 }
555 } 556 }
556 557
557 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id, 558 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id,
558 ui::Accelerator* accelerator) { 559 ui::Accelerator* accelerator) {
559 return false; 560 return false;
560 } 561 }
561 562
562 void NativeTextfieldViews::ExecuteCommand(int command_id) { 563 void NativeTextfieldViews::ExecuteCommand(int command_id) {
563 bool text_changed = false; 564 bool text_changed = false;
564 bool editable = !textfield_->read_only(); 565 DCHECK(IsCommandIdEnabled(command_id));
565 OnBeforeUserAction(); 566 OnBeforeUserAction();
566 switch (command_id) { 567 switch (command_id) {
567 case IDS_APP_CUT: 568 case IDS_APP_CUT:
568 if (editable) 569 text_changed = model_->Cut();
569 text_changed = model_->Cut();
570 break; 570 break;
571 case IDS_APP_COPY: 571 case IDS_APP_COPY:
572 model_->Copy(); 572 model_->Copy();
573 break; 573 break;
574 case IDS_APP_PASTE: 574 case IDS_APP_PASTE:
575 if (editable) 575 text_changed = Paste();
576 text_changed = Paste();
577 break; 576 break;
578 case IDS_APP_DELETE: 577 case IDS_APP_DELETE:
579 if (editable) 578 text_changed = model_->Delete();
580 text_changed = model_->Delete();
581 break; 579 break;
582 case IDS_APP_SELECT_ALL: 580 case IDS_APP_SELECT_ALL:
583 SelectAll(); 581 SelectAll();
584 break; 582 break;
585 default: 583 default:
586 NOTREACHED() << "unknown command: " << command_id; 584 NOTREACHED() << "unknown command: " << command_id;
587 break; 585 break;
588 } 586 }
589 587
590 // The cursor must have changed if text changed during cut/paste/delete. 588 // The cursor must have changed if text changed during cut/paste/delete.
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1087
1090 #if defined(USE_AURA) 1088 #if defined(USE_AURA)
1091 // static 1089 // static
1092 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 1090 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
1093 Textfield* field) { 1091 Textfield* field) {
1094 return new NativeTextfieldViews(field); 1092 return new NativeTextfieldViews(field);
1095 } 1093 }
1096 #endif 1094 #endif
1097 1095
1098 } // namespace views 1096 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698