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/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 #include "base/strings/utf_string_conversions.h" | 57 #include "base/strings/utf_string_conversions.h" |
58 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | 58 #include "ui/base/ime/linux/text_edit_command_auralinux.h" |
59 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 59 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
60 #endif | 60 #endif |
61 | 61 |
62 namespace views { | 62 namespace views { |
63 | 63 |
64 namespace { | 64 namespace { |
65 | 65 |
66 #if defined(OS_MACOSX) | 66 #if defined(OS_MACOSX) |
67 const ui::EventFlags kPlatformModifier = ui::EF_COMMAND_DOWN; | |
68 #else | |
69 const ui::EventFlags kPlatformModifier = ui::EF_CONTROL_DOWN; | |
70 #endif // OS_MACOSX | |
71 | |
72 #if defined(OS_MACOSX) | |
67 const gfx::SelectionBehavior kLineSelectionBehavior = gfx::SELECTION_EXTEND; | 73 const gfx::SelectionBehavior kLineSelectionBehavior = gfx::SELECTION_EXTEND; |
68 const gfx::SelectionBehavior kWordSelectionBehavior = gfx::SELECTION_CARET; | 74 const gfx::SelectionBehavior kWordSelectionBehavior = gfx::SELECTION_CARET; |
69 const gfx::SelectionBehavior kMoveParagraphSelectionBehavior = | 75 const gfx::SelectionBehavior kMoveParagraphSelectionBehavior = |
70 gfx::SELECTION_CARET; | 76 gfx::SELECTION_CARET; |
71 #else | 77 #else |
72 const gfx::SelectionBehavior kLineSelectionBehavior = gfx::SELECTION_RETAIN; | 78 const gfx::SelectionBehavior kLineSelectionBehavior = gfx::SELECTION_RETAIN; |
73 const gfx::SelectionBehavior kWordSelectionBehavior = gfx::SELECTION_RETAIN; | 79 const gfx::SelectionBehavior kWordSelectionBehavior = gfx::SELECTION_RETAIN; |
74 const gfx::SelectionBehavior kMoveParagraphSelectionBehavior = | 80 const gfx::SelectionBehavior kMoveParagraphSelectionBehavior = |
75 gfx::SELECTION_RETAIN; | 81 gfx::SELECTION_RETAIN; |
76 #endif | 82 #endif |
77 | 83 |
78 // Default placeholder text color. | 84 // Default placeholder text color. |
79 const SkColor kDefaultPlaceholderTextColor = SK_ColorLTGRAY; | 85 const SkColor kDefaultPlaceholderTextColor = SK_ColorLTGRAY; |
80 | 86 |
81 void ConvertRectToScreen(const View* src, gfx::Rect* r) { | 87 void ConvertRectToScreen(const View* src, gfx::Rect* r) { |
82 DCHECK(src); | 88 DCHECK(src); |
83 | 89 |
84 gfx::Point new_origin = r->origin(); | 90 gfx::Point new_origin = r->origin(); |
85 View::ConvertPointToScreen(src, &new_origin); | 91 View::ConvertPointToScreen(src, &new_origin); |
86 r->set_origin(new_origin); | 92 r->set_origin(new_origin); |
87 } | 93 } |
88 | 94 |
89 // Get the default command for a given key |event|. | 95 // Get the default command for a given key |event|. |
90 ui::TextEditCommand GetCommandForKeyEvent(const ui::KeyEvent& event) { | 96 ui::TextEditCommand GetCommandForKeyEvent(const ui::KeyEvent& event) { |
91 if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode()) | 97 if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode()) |
92 return ui::TextEditCommand::INVALID_COMMAND; | 98 return ui::TextEditCommand::INVALID_COMMAND; |
93 | 99 |
94 const bool shift = event.IsShiftDown(); | 100 const bool shift = event.IsShiftDown(); |
95 const bool control = event.IsControlDown(); | 101 const bool control = event.IsControlDown() || event.IsCommandDown(); |
Peter Kasting
2016/11/23 17:35:22
This doesn't need to check the specific platform m
tapted
2016/11/23 23:43:21
I think this is right, and it's the simplest thing
| |
96 const bool alt = event.IsAltDown() || event.IsAltGrDown(); | 102 const bool alt = event.IsAltDown() || event.IsAltGrDown(); |
97 switch (event.key_code()) { | 103 switch (event.key_code()) { |
98 case ui::VKEY_Z: | 104 case ui::VKEY_Z: |
99 if (control && !shift && !alt) | 105 if (control && !shift && !alt) |
100 return ui::TextEditCommand::UNDO; | 106 return ui::TextEditCommand::UNDO; |
101 return (control && shift && !alt) ? ui::TextEditCommand::REDO | 107 return (control && shift && !alt) ? ui::TextEditCommand::REDO |
102 : ui::TextEditCommand::INVALID_COMMAND; | 108 : ui::TextEditCommand::INVALID_COMMAND; |
103 case ui::VKEY_Y: | 109 case ui::VKEY_Y: |
104 return (control && !alt) ? ui::TextEditCommand::REDO | 110 return (control && !alt) ? ui::TextEditCommand::REDO |
105 : ui::TextEditCommand::INVALID_COMMAND; | 111 : ui::TextEditCommand::INVALID_COMMAND; |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1175 | 1181 |
1176 bool Textfield::IsCommandIdEnabled(int command_id) const { | 1182 bool Textfield::IsCommandIdEnabled(int command_id) const { |
1177 return Textfield::IsTextEditCommandEnabled( | 1183 return Textfield::IsTextEditCommandEnabled( |
1178 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1184 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
1179 } | 1185 } |
1180 | 1186 |
1181 bool Textfield::GetAcceleratorForCommandId(int command_id, | 1187 bool Textfield::GetAcceleratorForCommandId(int command_id, |
1182 ui::Accelerator* accelerator) const { | 1188 ui::Accelerator* accelerator) const { |
1183 switch (command_id) { | 1189 switch (command_id) { |
1184 case IDS_APP_UNDO: | 1190 case IDS_APP_UNDO: |
1185 *accelerator = ui::Accelerator(ui::VKEY_Z, ui::EF_CONTROL_DOWN); | 1191 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier); |
1186 return true; | 1192 return true; |
1187 | 1193 |
1188 case IDS_APP_CUT: | 1194 case IDS_APP_CUT: |
1189 *accelerator = ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN); | 1195 *accelerator = ui::Accelerator(ui::VKEY_X, kPlatformModifier); |
1190 return true; | 1196 return true; |
1191 | 1197 |
1192 case IDS_APP_COPY: | 1198 case IDS_APP_COPY: |
1193 *accelerator = ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN); | 1199 *accelerator = ui::Accelerator(ui::VKEY_C, kPlatformModifier); |
1194 return true; | 1200 return true; |
1195 | 1201 |
1196 case IDS_APP_PASTE: | 1202 case IDS_APP_PASTE: |
1197 *accelerator = ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN); | 1203 *accelerator = ui::Accelerator(ui::VKEY_V, kPlatformModifier); |
1198 return true; | 1204 return true; |
1199 | 1205 |
1200 case IDS_APP_SELECT_ALL: | 1206 case IDS_APP_SELECT_ALL: |
1201 *accelerator = ui::Accelerator(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 1207 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier); |
1202 return true; | 1208 return true; |
1203 | 1209 |
1204 default: | 1210 default: |
1205 return false; | 1211 return false; |
1206 } | 1212 } |
1207 } | 1213 } |
1208 | 1214 |
1209 void Textfield::ExecuteCommand(int command_id, int event_flags) { | 1215 void Textfield::ExecuteCommand(int command_id, int event_flags) { |
1210 Textfield::ExecuteTextEditCommand( | 1216 Textfield::ExecuteTextEditCommand( |
1211 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1217 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2047 } | 2053 } |
2048 | 2054 |
2049 void Textfield::OnCursorBlinkTimerFired() { | 2055 void Textfield::OnCursorBlinkTimerFired() { |
2050 DCHECK(ShouldBlinkCursor()); | 2056 DCHECK(ShouldBlinkCursor()); |
2051 gfx::RenderText* render_text = GetRenderText(); | 2057 gfx::RenderText* render_text = GetRenderText(); |
2052 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2058 render_text->set_cursor_visible(!render_text->cursor_visible()); |
2053 RepaintCursor(); | 2059 RepaintCursor(); |
2054 } | 2060 } |
2055 | 2061 |
2056 } // namespace views | 2062 } // namespace views |
OLD | NEW |