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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 View::ConvertPointToScreen(src, &new_origin); | 85 View::ConvertPointToScreen(src, &new_origin); |
86 r->set_origin(new_origin); | 86 r->set_origin(new_origin); |
87 } | 87 } |
88 | 88 |
89 // Get the default command for a given key |event|. | 89 // Get the default command for a given key |event|. |
90 ui::TextEditCommand GetCommandForKeyEvent(const ui::KeyEvent& event) { | 90 ui::TextEditCommand GetCommandForKeyEvent(const ui::KeyEvent& event) { |
91 if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode()) | 91 if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode()) |
92 return ui::TextEditCommand::INVALID_COMMAND; | 92 return ui::TextEditCommand::INVALID_COMMAND; |
93 | 93 |
94 const bool shift = event.IsShiftDown(); | 94 const bool shift = event.IsShiftDown(); |
95 #if defined(OS_MACOSX) | |
96 const bool control = event.IsCommandDown(); | |
themblsha
2016/11/22 14:33:48
Fixes TextfieldTest.CutCopyPaste. "Ensure [Ctrl]+[
tapted
2016/11/23 02:09:30
This doesn't look right -- E.g. -[BridgedContentVi
themblsha
2016/11/23 15:16:39
Just EventGenerator::WINDOW is not enough, but in
| |
97 #else | |
95 const bool control = event.IsControlDown(); | 98 const bool control = event.IsControlDown(); |
99 #endif | |
96 const bool alt = event.IsAltDown() || event.IsAltGrDown(); | 100 const bool alt = event.IsAltDown() || event.IsAltGrDown(); |
97 switch (event.key_code()) { | 101 switch (event.key_code()) { |
98 case ui::VKEY_Z: | 102 case ui::VKEY_Z: |
99 if (control && !shift && !alt) | 103 if (control && !shift && !alt) |
100 return ui::TextEditCommand::UNDO; | 104 return ui::TextEditCommand::UNDO; |
101 return (control && shift && !alt) ? ui::TextEditCommand::REDO | 105 return (control && shift && !alt) ? ui::TextEditCommand::REDO |
102 : ui::TextEditCommand::INVALID_COMMAND; | 106 : ui::TextEditCommand::INVALID_COMMAND; |
103 case ui::VKEY_Y: | 107 case ui::VKEY_Y: |
104 return (control && !alt) ? ui::TextEditCommand::REDO | 108 return (control && !alt) ? ui::TextEditCommand::REDO |
105 : ui::TextEditCommand::INVALID_COMMAND; | 109 : ui::TextEditCommand::INVALID_COMMAND; |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1257 | 1261 |
1258 OnBeforeUserAction(); | 1262 OnBeforeUserAction(); |
1259 skip_input_method_cancel_composition_ = true; | 1263 skip_input_method_cancel_composition_ = true; |
1260 model_->InsertText(new_text); | 1264 model_->InsertText(new_text); |
1261 skip_input_method_cancel_composition_ = false; | 1265 skip_input_method_cancel_composition_ = false; |
1262 UpdateAfterChange(true, true); | 1266 UpdateAfterChange(true, true); |
1263 OnAfterUserAction(); | 1267 OnAfterUserAction(); |
1264 } | 1268 } |
1265 | 1269 |
1266 void Textfield::InsertChar(const ui::KeyEvent& event) { | 1270 void Textfield::InsertChar(const ui::KeyEvent& event) { |
1271 #if defined(OS_MACOSX) | |
1272 // MockInputMethod::DispatchKeyEvent() will try to incorrectly call | |
1273 // TestTextfield::InsertChar(), even though when Command is pressed text input | |
1274 // shouldn't work at all. | |
1275 if (event.IsCommandDown()) | |
1276 return; | |
1277 #endif | |
themblsha
2016/11/22 14:33:48
Fixes TextfieldTest.KeysWithModifiersTest. MockInp
tapted
2016/11/23 02:09:30
This test already behaves correctly on CrOS. I thi
themblsha
2016/11/23 15:16:39
Whoa, this really fixes it. Thanks!
| |
1278 | |
1267 if (read_only()) { | 1279 if (read_only()) { |
1268 OnEditFailed(); | 1280 OnEditFailed(); |
1269 return; | 1281 return; |
1270 } | 1282 } |
1271 | 1283 |
1272 // Filter out all control characters, including tab and new line characters, | 1284 // Filter out all control characters, including tab and new line characters, |
1273 // and all characters with Alt modifier (and Search on ChromeOS). But allow | 1285 // and all characters with Alt modifier (and Search on ChromeOS). But allow |
1274 // characters with the AltGr modifier. On Windows AltGr is represented by | 1286 // characters with the AltGr modifier. On Windows AltGr is represented by |
1275 // Alt+Ctrl or Right Alt, and on Linux it's a different flag that we don't | 1287 // Alt+Ctrl or Right Alt, and on Linux it's a different flag that we don't |
1276 // care about. | 1288 // care about. |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2047 } | 2059 } |
2048 | 2060 |
2049 void Textfield::OnCursorBlinkTimerFired() { | 2061 void Textfield::OnCursorBlinkTimerFired() { |
2050 DCHECK(ShouldBlinkCursor()); | 2062 DCHECK(ShouldBlinkCursor()); |
2051 gfx::RenderText* render_text = GetRenderText(); | 2063 gfx::RenderText* render_text = GetRenderText(); |
2052 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2064 render_text->set_cursor_visible(!render_text->cursor_visible()); |
2053 RepaintCursor(); | 2065 RepaintCursor(); |
2054 } | 2066 } |
2055 | 2067 |
2056 } // namespace views | 2068 } // namespace views |
OLD | NEW |