| OLD | NEW |
| 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 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 // TODO(oshima): Refactor and consolidate with ExecuteCommand. | 853 // TODO(oshima): Refactor and consolidate with ExecuteCommand. |
| 854 if (key_event.type() == ui::ET_KEY_PRESSED) { | 854 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 855 ui::KeyboardCode key_code = key_event.key_code(); | 855 ui::KeyboardCode key_code = key_event.key_code(); |
| 856 // TODO(oshima): shift-tab does not work. Figure out why and fix. | 856 // TODO(oshima): shift-tab does not work. Figure out why and fix. |
| 857 if (key_code == ui::VKEY_TAB) | 857 if (key_code == ui::VKEY_TAB) |
| 858 return false; | 858 return false; |
| 859 | 859 |
| 860 OnBeforeUserAction(); | 860 OnBeforeUserAction(); |
| 861 bool editable = !textfield_->read_only(); | 861 bool editable = !textfield_->read_only(); |
| 862 bool readable = !textfield_->IsObscured(); | 862 bool readable = !textfield_->IsObscured(); |
| 863 bool selection = key_event.IsShiftDown(); | 863 bool shift = key_event.IsShiftDown(); |
| 864 bool control = key_event.IsControlDown(); | 864 bool control = key_event.IsControlDown(); |
| 865 bool text_changed = false; | 865 bool text_changed = false; |
| 866 bool cursor_changed = false; | 866 bool cursor_changed = false; |
| 867 switch (key_code) { | 867 switch (key_code) { |
| 868 case ui::VKEY_Z: | 868 case ui::VKEY_Z: |
| 869 if (control && editable) | 869 if (control && !shift && editable) |
| 870 cursor_changed = text_changed = model_->Undo(); | 870 cursor_changed = text_changed = model_->Undo(); |
| 871 else if (control && shift && editable) |
| 872 cursor_changed = text_changed = model_->Redo(); |
| 871 break; | 873 break; |
| 872 case ui::VKEY_Y: | 874 case ui::VKEY_Y: |
| 873 if (control && editable) | 875 if (control && editable) |
| 874 cursor_changed = text_changed = model_->Redo(); | 876 cursor_changed = text_changed = model_->Redo(); |
| 875 break; | 877 break; |
| 876 case ui::VKEY_A: | 878 case ui::VKEY_A: |
| 877 if (control) { | 879 if (control) { |
| 878 model_->SelectAll(); | 880 model_->SelectAll(); |
| 879 cursor_changed = true; | 881 cursor_changed = true; |
| 880 } | 882 } |
| 881 break; | 883 break; |
| 882 case ui::VKEY_X: | 884 case ui::VKEY_X: |
| 883 if (control && editable && readable) | 885 if (control && editable && readable) |
| 884 cursor_changed = text_changed = Cut(); | 886 cursor_changed = text_changed = Cut(); |
| 885 break; | 887 break; |
| 886 case ui::VKEY_C: | 888 case ui::VKEY_C: |
| 887 if (control && readable) | 889 if (control && readable) |
| 888 Copy(); | 890 Copy(); |
| 889 break; | 891 break; |
| 890 case ui::VKEY_V: | 892 case ui::VKEY_V: |
| 891 if (control && editable) | 893 if (control && editable) |
| 892 cursor_changed = text_changed = Paste(); | 894 cursor_changed = text_changed = Paste(); |
| 893 break; | 895 break; |
| 894 case ui::VKEY_RIGHT: | 896 case ui::VKEY_RIGHT: |
| 895 case ui::VKEY_LEFT: | 897 case ui::VKEY_LEFT: |
| 896 model_->MoveCursor( | 898 model_->MoveCursor( |
| 897 control ? gfx::WORD_BREAK : gfx::CHARACTER_BREAK, | 899 control ? gfx::WORD_BREAK : gfx::CHARACTER_BREAK, |
| 898 (key_code == ui::VKEY_RIGHT) ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT, | 900 (key_code == ui::VKEY_RIGHT) ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT, |
| 899 selection); | 901 shift); |
| 900 cursor_changed = true; | 902 cursor_changed = true; |
| 901 break; | 903 break; |
| 902 case ui::VKEY_END: | 904 case ui::VKEY_END: |
| 903 case ui::VKEY_HOME: | 905 case ui::VKEY_HOME: |
| 904 if ((key_code == ui::VKEY_HOME) == | 906 if ((key_code == ui::VKEY_HOME) == |
| 905 (GetRenderText()->GetTextDirection() == base::i18n::RIGHT_TO_LEFT)) | 907 (GetRenderText()->GetTextDirection() == base::i18n::RIGHT_TO_LEFT)) |
| 906 model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, selection); | 908 model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, shift); |
| 907 else | 909 else |
| 908 model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, selection); | 910 model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, shift); |
| 909 cursor_changed = true; | 911 cursor_changed = true; |
| 910 break; | 912 break; |
| 911 case ui::VKEY_BACK: | 913 case ui::VKEY_BACK: |
| 912 case ui::VKEY_DELETE: | 914 case ui::VKEY_DELETE: |
| 913 if (!editable) | 915 if (!editable) |
| 914 break; | 916 break; |
| 915 if (!model_->HasSelection()) { | 917 if (!model_->HasSelection()) { |
| 916 gfx::VisualCursorDirection direction = (key_code == ui::VKEY_DELETE) ? | 918 gfx::VisualCursorDirection direction = (key_code == ui::VKEY_DELETE) ? |
| 917 gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; | 919 gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; |
| 918 if (selection && control) { | 920 if (shift && control) { |
| 919 // If both shift and control are pressed, then erase up to the | 921 // If both shift and control are pressed, then erase up to the |
| 920 // beginning/end of the buffer in ChromeOS. In windows, do nothing. | 922 // beginning/end of the buffer in ChromeOS. In windows, do nothing. |
| 921 #if defined(OS_WIN) | 923 #if defined(OS_WIN) |
| 922 break; | 924 break; |
| 923 #else | 925 #else |
| 924 model_->MoveCursor(gfx::LINE_BREAK, direction, true); | 926 model_->MoveCursor(gfx::LINE_BREAK, direction, true); |
| 925 #endif | 927 #endif |
| 926 } else if (control) { | 928 } else if (control) { |
| 927 // If only control is pressed, then erase the previous/next word. | 929 // If only control is pressed, then erase the previous/next word. |
| 928 model_->MoveCursor(gfx::WORD_BREAK, direction, true); | 930 model_->MoveCursor(gfx::WORD_BREAK, direction, true); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 | 1157 |
| 1156 #if defined(USE_AURA) | 1158 #if defined(USE_AURA) |
| 1157 // static | 1159 // static |
| 1158 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1160 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 1159 Textfield* field) { | 1161 Textfield* field) { |
| 1160 return new NativeTextfieldViews(field); | 1162 return new NativeTextfieldViews(field); |
| 1161 } | 1163 } |
| 1162 #endif | 1164 #endif |
| 1163 | 1165 |
| 1164 } // namespace views | 1166 } // namespace views |
| OLD | NEW |