Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 // Update the default text style. | 392 // Update the default text style. |
| 392 gfx::StyleRange default_style(GetRenderText()->default_style()); | 393 gfx::StyleRange default_style(GetRenderText()->default_style()); |
| 393 default_style.font = textfield_->font(); | 394 default_style.font = textfield_->font(); |
| 394 GetRenderText()->set_default_style(default_style); | 395 GetRenderText()->set_default_style(default_style); |
| 395 GetRenderText()->ApplyDefaultStyle(); | 396 GetRenderText()->ApplyDefaultStyle(); |
| 396 | 397 |
| 397 OnCaretBoundsChanged(); | 398 OnCaretBoundsChanged(); |
| 398 } | 399 } |
| 399 | 400 |
| 400 void NativeTextfieldViews::UpdateIsPassword() { | 401 void NativeTextfieldViews::UpdateIsPassword() { |
| 401 model_->set_is_password(textfield_->IsPassword()); | 402 GetRenderText()->SetIsObscured(textfield_->IsPassword()); |
| 402 OnCaretBoundsChanged(); | 403 OnCaretBoundsChanged(); |
| 403 SchedulePaint(); | 404 SchedulePaint(); |
| 404 OnTextInputTypeChanged(); | 405 OnTextInputTypeChanged(); |
| 405 } | 406 } |
| 406 | 407 |
| 407 void NativeTextfieldViews::UpdateEnabled() { | 408 void NativeTextfieldViews::UpdateEnabled() { |
| 408 SetEnabled(textfield_->IsEnabled()); | 409 SetEnabled(textfield_->IsEnabled()); |
| 409 SchedulePaint(); | 410 SchedulePaint(); |
| 410 OnTextInputTypeChanged(); | 411 OnTextInputTypeChanged(); |
| 411 } | 412 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 | 527 |
| 527 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const { | 528 bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const { |
| 528 return true; | 529 return true; |
| 529 } | 530 } |
| 530 | 531 |
| 531 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const { | 532 bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const { |
| 532 bool editable = !textfield_->read_only(); | 533 bool editable = !textfield_->read_only(); |
| 533 string16 result; | 534 string16 result; |
| 534 switch (command_id) { | 535 switch (command_id) { |
| 535 case IDS_APP_CUT: | 536 case IDS_APP_CUT: |
| 536 return editable && model_->HasSelection(); | 537 return editable && model_->HasSelection() && !textfield_->IsPassword(); |
|
oshima
2011/12/06 23:57:18
I assume you'll change IsPassword in another CL?
benrg
2011/12/08 21:40:55
It's changed in 8748001, which should land someday
| |
| 537 case IDS_APP_COPY: | 538 case IDS_APP_COPY: |
| 538 return model_->HasSelection(); | 539 return model_->HasSelection() && !textfield_->IsPassword(); |
| 539 case IDS_APP_PASTE: | 540 case IDS_APP_PASTE: |
| 540 ViewsDelegate::views_delegate->GetClipboard() | 541 ViewsDelegate::views_delegate->GetClipboard() |
| 541 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); | 542 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result); |
| 542 return editable && !result.empty(); | 543 return editable && !result.empty(); |
| 543 case IDS_APP_DELETE: | 544 case IDS_APP_DELETE: |
| 544 return editable && model_->HasSelection(); | 545 return editable && model_->HasSelection(); |
| 545 case IDS_APP_SELECT_ALL: | 546 case IDS_APP_SELECT_ALL: |
| 546 return true; | 547 return true; |
| 547 default: | 548 default: |
| 548 NOTREACHED(); | 549 NOTREACHED(); |
| 549 return false; | 550 return false; |
| 550 } | 551 } |
| 551 } | 552 } |
| 552 | 553 |
| 553 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id, | 554 bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id, |
| 554 ui::Accelerator* accelerator) { | 555 ui::Accelerator* accelerator) { |
| 555 return false; | 556 return false; |
| 556 } | 557 } |
| 557 | 558 |
| 558 void NativeTextfieldViews::ExecuteCommand(int command_id) { | 559 void NativeTextfieldViews::ExecuteCommand(int command_id) { |
| 559 bool text_changed = false; | 560 bool text_changed = false; |
| 560 bool editable = !textfield_->read_only(); | 561 DCHECK(IsCommandIdEnabled(command_id)); |
|
oshima
2011/12/06 23:57:18
won't this break read_only behavior?
benrg
2011/12/08 21:40:55
I thought ExecuteCommand is only called when a men
| |
| 561 OnBeforeUserAction(); | 562 OnBeforeUserAction(); |
| 562 switch (command_id) { | 563 switch (command_id) { |
| 563 case IDS_APP_CUT: | 564 case IDS_APP_CUT: |
| 564 if (editable) | 565 text_changed = model_->Cut(); |
| 565 text_changed = model_->Cut(); | |
| 566 break; | 566 break; |
| 567 case IDS_APP_COPY: | 567 case IDS_APP_COPY: |
| 568 model_->Copy(); | 568 model_->Copy(); |
| 569 break; | 569 break; |
| 570 case IDS_APP_PASTE: | 570 case IDS_APP_PASTE: |
| 571 if (editable) | 571 text_changed = Paste(); |
| 572 text_changed = Paste(); | |
| 573 break; | 572 break; |
| 574 case IDS_APP_DELETE: | 573 case IDS_APP_DELETE: |
| 575 if (editable) | 574 text_changed = model_->Delete(); |
| 576 text_changed = model_->Delete(); | |
| 577 break; | 575 break; |
| 578 case IDS_APP_SELECT_ALL: | 576 case IDS_APP_SELECT_ALL: |
| 579 SelectAll(); | 577 SelectAll(); |
| 580 break; | 578 break; |
| 581 default: | 579 default: |
| 582 NOTREACHED() << "unknown command: " << command_id; | 580 NOTREACHED() << "unknown command: " << command_id; |
| 583 break; | 581 break; |
| 584 } | 582 } |
| 585 | 583 |
| 586 // The cursor must have changed if text changed during cut/paste/delete. | 584 // The cursor must have changed if text changed during cut/paste/delete. |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 | 1074 |
| 1077 #if defined(USE_AURA) | 1075 #if defined(USE_AURA) |
| 1078 // static | 1076 // static |
| 1079 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1077 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 1080 Textfield* field) { | 1078 Textfield* field) { |
| 1081 return new NativeTextfieldViews(field); | 1079 return new NativeTextfieldViews(field); |
| 1082 } | 1080 } |
| 1083 #endif | 1081 #endif |
| 1084 | 1082 |
| 1085 } // namespace views | 1083 } // namespace views |
| OLD | NEW |