| 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/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 } | 682 } |
| 683 #endif | 683 #endif |
| 684 | 684 |
| 685 if (edit_command == ui::TextEditCommand::INVALID_COMMAND) | 685 if (edit_command == ui::TextEditCommand::INVALID_COMMAND) |
| 686 edit_command = GetCommandForKeyEvent(event); | 686 edit_command = GetCommandForKeyEvent(event); |
| 687 | 687 |
| 688 if (!handled && IsTextEditCommandEnabled(edit_command)) { | 688 if (!handled && IsTextEditCommandEnabled(edit_command)) { |
| 689 ExecuteTextEditCommand(edit_command); | 689 ExecuteTextEditCommand(edit_command); |
| 690 handled = true; | 690 handled = true; |
| 691 } | 691 } |
| 692 | |
| 693 if (!handled) | |
| 694 OnKeypressUnhandled(); | |
| 695 return handled; | 692 return handled; |
| 696 } | 693 } |
| 697 | 694 |
| 698 bool Textfield::OnKeyReleased(const ui::KeyEvent& event) { | 695 bool Textfield::OnKeyReleased(const ui::KeyEvent& event) { |
| 699 return controller_ && controller_->HandleKeyEvent(this, event); | 696 return controller_ && controller_->HandleKeyEvent(this, event); |
| 700 } | 697 } |
| 701 | 698 |
| 702 void Textfield::OnGestureEvent(ui::GestureEvent* event) { | 699 void Textfield::OnGestureEvent(ui::GestureEvent* event) { |
| 703 switch (event->type()) { | 700 switch (event->type()) { |
| 704 case ui::ET_GESTURE_TAP_DOWN: | 701 case ui::ET_GESTURE_TAP_DOWN: |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 OnBeforeUserAction(); | 1287 OnBeforeUserAction(); |
| 1291 skip_input_method_cancel_composition_ = true; | 1288 skip_input_method_cancel_composition_ = true; |
| 1292 model_->InsertText(new_text); | 1289 model_->InsertText(new_text); |
| 1293 skip_input_method_cancel_composition_ = false; | 1290 skip_input_method_cancel_composition_ = false; |
| 1294 UpdateAfterChange(true, true); | 1291 UpdateAfterChange(true, true); |
| 1295 OnAfterUserAction(); | 1292 OnAfterUserAction(); |
| 1296 } | 1293 } |
| 1297 | 1294 |
| 1298 void Textfield::InsertChar(const ui::KeyEvent& event) { | 1295 void Textfield::InsertChar(const ui::KeyEvent& event) { |
| 1299 if (read_only()) { | 1296 if (read_only()) { |
| 1300 OnKeypressUnhandled(); | 1297 OnEditFailed(); |
| 1301 return; | 1298 return; |
| 1302 } | 1299 } |
| 1303 | 1300 |
| 1304 // Filter out all control characters, including tab and new line characters, | 1301 // Filter out all control characters, including tab and new line characters, |
| 1305 // and all characters with Alt modifier (and Search on ChromeOS). But allow | 1302 // and all characters with Alt modifier (and Search on ChromeOS). But allow |
| 1306 // characters with the AltGr modifier. On Windows AltGr is represented by | 1303 // characters with the AltGr modifier. On Windows AltGr is represented by |
| 1307 // Alt+Ctrl or Right Alt, and on Linux it's a different flag that we don't | 1304 // Alt+Ctrl or Right Alt, and on Linux it's a different flag that we don't |
| 1308 // care about. | 1305 // care about. |
| 1309 const base::char16 ch = event.GetCharacter(); | 1306 const base::char16 ch = event.GetCharacter(); |
| 1310 const bool should_insert_char = ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1307 const bool should_insert_char = ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 if (!HasFocus()) | 2043 if (!HasFocus()) |
| 2047 RequestFocus(); | 2044 RequestFocus(); |
| 2048 model_->MoveCursorTo(mouse); | 2045 model_->MoveCursorTo(mouse); |
| 2049 if (!selection_clipboard_text.empty()) { | 2046 if (!selection_clipboard_text.empty()) { |
| 2050 model_->InsertText(selection_clipboard_text); | 2047 model_->InsertText(selection_clipboard_text); |
| 2051 UpdateAfterChange(true, true); | 2048 UpdateAfterChange(true, true); |
| 2052 } | 2049 } |
| 2053 OnAfterUserAction(); | 2050 OnAfterUserAction(); |
| 2054 } | 2051 } |
| 2055 | 2052 |
| 2056 void Textfield::OnKeypressUnhandled() { | 2053 void Textfield::OnEditFailed() { |
| 2057 PlatformStyle::OnTextfieldKeypressUnhandled(); | 2054 PlatformStyle::OnTextfieldEditFailed(); |
| 2058 } | 2055 } |
| 2059 | 2056 |
| 2060 bool Textfield::ShouldShowCursor() const { | 2057 bool Textfield::ShouldShowCursor() const { |
| 2061 return HasFocus() && !HasSelection() && enabled() && !read_only() && | 2058 return HasFocus() && !HasSelection() && enabled() && !read_only() && |
| 2062 !drop_cursor_visible_; | 2059 !drop_cursor_visible_; |
| 2063 } | 2060 } |
| 2064 | 2061 |
| 2065 bool Textfield::ShouldBlinkCursor() const { | 2062 bool Textfield::ShouldBlinkCursor() const { |
| 2066 return ShouldShowCursor() && Textfield::GetCaretBlinkMs() != 0; | 2063 return ShouldShowCursor() && Textfield::GetCaretBlinkMs() != 0; |
| 2067 } | 2064 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2078 } | 2075 } |
| 2079 | 2076 |
| 2080 void Textfield::OnCursorBlinkTimerFired() { | 2077 void Textfield::OnCursorBlinkTimerFired() { |
| 2081 DCHECK(ShouldBlinkCursor()); | 2078 DCHECK(ShouldBlinkCursor()); |
| 2082 gfx::RenderText* render_text = GetRenderText(); | 2079 gfx::RenderText* render_text = GetRenderText(); |
| 2083 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2080 render_text->set_cursor_visible(!render_text->cursor_visible()); |
| 2084 RepaintCursor(); | 2081 RepaintCursor(); |
| 2085 } | 2082 } |
| 2086 | 2083 |
| 2087 } // namespace views | 2084 } // namespace views |
| OLD | NEW |