| Index: views/controls/textfield/native_textfield_views.cc
|
| diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
|
| index 3cffeb80a402ba8a0bceb30d8449363ad39d88d2..a4324be2f68fd7a6998ee266a2e65178d1bd14ab 100644
|
| --- a/views/controls/textfield/native_textfield_views.cc
|
| +++ b/views/controls/textfield/native_textfield_views.cc
|
| @@ -329,18 +329,19 @@ bool NativeTextfieldViews::IsCommandIdChecked(int command_id) const {
|
| }
|
|
|
| bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const {
|
| + bool editable = !textfield_->read_only();
|
| string16 result;
|
| switch (command_id) {
|
| case IDS_APP_CUT:
|
| - return model_->HasSelection();
|
| + return editable && model_->HasSelection();
|
| case IDS_APP_COPY:
|
| return model_->HasSelection();
|
| case IDS_APP_PASTE:
|
| views::ViewsDelegate::views_delegate->GetClipboard()
|
| ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
|
| - return !result.empty();
|
| + return editable && !result.empty();
|
| case IDS_APP_DELETE:
|
| - return model_->HasSelection();
|
| + return editable && model_->HasSelection();
|
| case IDS_APP_SELECT_ALL:
|
| return true;
|
| default:
|
| @@ -356,18 +357,22 @@ bool NativeTextfieldViews::GetAcceleratorForCommandId(int command_id,
|
|
|
| void NativeTextfieldViews::ExecuteCommand(int command_id) {
|
| bool text_changed = false;
|
| + bool editable = !textfield_->read_only();
|
| switch (command_id) {
|
| case IDS_APP_CUT:
|
| - text_changed = model_->Cut();
|
| + if (editable)
|
| + text_changed = model_->Cut();
|
| break;
|
| case IDS_APP_COPY:
|
| model_->Copy();
|
| break;
|
| case IDS_APP_PASTE:
|
| - text_changed = model_->Paste();
|
| + if (editable)
|
| + text_changed = model_->Paste();
|
| break;
|
| case IDS_APP_DELETE:
|
| - text_changed = model_->Delete();
|
| + if (editable)
|
| + text_changed = model_->Delete();
|
| break;
|
| case IDS_APP_SELECT_ALL:
|
| SelectAll();
|
| @@ -519,6 +524,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
|
| // TODO(oshima): shift-tab does not work. Figure out why and fix.
|
| if (key_code == ui::VKEY_TAB)
|
| return false;
|
| + bool editable = !textfield_->read_only();
|
| bool selection = key_event.IsShiftDown();
|
| bool control = key_event.IsControlDown();
|
| bool text_changed = false;
|
| @@ -531,7 +537,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
|
| }
|
| break;
|
| case ui::VKEY_X:
|
| - if (control)
|
| + if (control && editable)
|
| text_changed = model_->Cut();
|
| break;
|
| case ui::VKEY_C:
|
| @@ -539,7 +545,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
|
| model_->Copy();
|
| break;
|
| case ui::VKEY_V:
|
| - if (control)
|
| + if (control && editable)
|
| text_changed = model_->Paste();
|
| break;
|
| case ui::VKEY_RIGHT:
|
| @@ -561,6 +567,8 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
|
| cursor_changed = true;
|
| break;
|
| case ui::VKEY_BACK:
|
| + if (!editable)
|
| + break;
|
| if (!model_->HasSelection()) {
|
| if (selection && control) {
|
| // If both shift and control are pressed, then erase upto the
|
| @@ -579,6 +587,8 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
|
| cursor_changed = true;
|
| break;
|
| case ui::VKEY_DELETE:
|
| + if (!editable)
|
| + break;
|
| if (!model_->HasSelection()) {
|
| if (selection && control) {
|
| // If both shift and control are pressed, then erase upto the
|
| @@ -603,7 +613,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
|
| break;
|
| }
|
| char16 print_char = GetPrintableChar(key_event);
|
| - if (!control && print_char) {
|
| + if (!control && print_char && editable) {
|
| if (insert_)
|
| model_->Insert(print_char);
|
| else
|
|
|