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 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 int GetDragSelectionDelay() { | 68 int GetDragSelectionDelay() { |
69 switch (ui::ScopedAnimationDurationScaleMode::duration_scale_mode()) { | 69 switch (ui::ScopedAnimationDurationScaleMode::duration_scale_mode()) { |
70 case ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION: return 100; | 70 case ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION: return 100; |
71 case ui::ScopedAnimationDurationScaleMode::FAST_DURATION: return 25; | 71 case ui::ScopedAnimationDurationScaleMode::FAST_DURATION: return 25; |
72 case ui::ScopedAnimationDurationScaleMode::SLOW_DURATION: return 400; | 72 case ui::ScopedAnimationDurationScaleMode::SLOW_DURATION: return 400; |
73 case ui::ScopedAnimationDurationScaleMode::ZERO_DURATION: return 0; | 73 case ui::ScopedAnimationDurationScaleMode::ZERO_DURATION: return 0; |
74 } | 74 } |
75 return 100; | 75 return 100; |
76 } | 76 } |
77 | 77 |
| 78 // Get the default command for a given key |event| and selection state. |
78 int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) { | 79 int GetCommandForKeyEvent(const ui::KeyEvent& event, bool has_selection) { |
79 if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode()) | 80 if (event.type() != ui::ET_KEY_PRESSED || event.IsUnicodeKeyCode()) |
80 return kNoCommand; | 81 return kNoCommand; |
81 | 82 |
82 const bool shift = event.IsShiftDown(); | 83 const bool shift = event.IsShiftDown(); |
83 const bool control = event.IsControlDown(); | 84 const bool control = event.IsControlDown(); |
84 const bool alt = event.IsAltDown() || event.IsAltGrDown(); | 85 const bool alt = event.IsAltDown() || event.IsAltGrDown(); |
85 switch (event.key_code()) { | 86 switch (event.key_code()) { |
86 case ui::VKEY_Z: | 87 case ui::VKEY_Z: |
87 if (control && !shift && !alt) | 88 if (control && !shift && !alt) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 case ui::VKEY_INSERT: | 141 case ui::VKEY_INSERT: |
141 if (control && !shift) | 142 if (control && !shift) |
142 return IDS_APP_COPY; | 143 return IDS_APP_COPY; |
143 return (shift && !control) ? IDS_APP_PASTE : kNoCommand; | 144 return (shift && !control) ? IDS_APP_PASTE : kNoCommand; |
144 default: | 145 default: |
145 return kNoCommand; | 146 return kNoCommand; |
146 } | 147 } |
147 } | 148 } |
148 | 149 |
149 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 150 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 151 // Convert a custom text edit |command| to the equivalent views command ID. |
150 int GetViewsCommand(const ui::TextEditCommandAuraLinux& command, bool rtl) { | 152 int GetViewsCommand(const ui::TextEditCommandAuraLinux& command, bool rtl) { |
151 const bool select = command.extend_selection(); | 153 const bool select = command.extend_selection(); |
152 switch (command.command_id()) { | 154 switch (command.command_id()) { |
153 case ui::TextEditCommandAuraLinux::COPY: | 155 case ui::TextEditCommandAuraLinux::COPY: |
154 return IDS_APP_COPY; | 156 return IDS_APP_COPY; |
155 case ui::TextEditCommandAuraLinux::CUT: | 157 case ui::TextEditCommandAuraLinux::CUT: |
156 return IDS_APP_CUT; | 158 return IDS_APP_CUT; |
157 case ui::TextEditCommandAuraLinux::DELETE_BACKWARD: | 159 case ui::TextEditCommandAuraLinux::DELETE_BACKWARD: |
158 return IDS_DELETE_BACKWARD; | 160 return IDS_DELETE_BACKWARD; |
159 case ui::TextEditCommandAuraLinux::DELETE_FORWARD: | 161 case ui::TextEditCommandAuraLinux::DELETE_FORWARD: |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // Cancel suspected drag initiations, the user was clicking in the selection. | 595 // Cancel suspected drag initiations, the user was clicking in the selection. |
594 if (initiating_drag_) | 596 if (initiating_drag_) |
595 MoveCursorTo(event.location(), false); | 597 MoveCursorTo(event.location(), false); |
596 initiating_drag_ = false; | 598 initiating_drag_ = false; |
597 UpdateSelectionClipboard(); | 599 UpdateSelectionClipboard(); |
598 OnAfterUserAction(); | 600 OnAfterUserAction(); |
599 } | 601 } |
600 | 602 |
601 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { | 603 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { |
602 bool handled = controller_ && controller_->HandleKeyEvent(this, event); | 604 bool handled = controller_ && controller_->HandleKeyEvent(this, event); |
603 if (handled) | |
604 return true; | |
605 | 605 |
606 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 606 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
607 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = | 607 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
608 ui::GetTextEditKeyBindingsDelegate(); | 608 ui::GetTextEditKeyBindingsDelegate(); |
609 std::vector<ui::TextEditCommandAuraLinux> commands; | 609 std::vector<ui::TextEditCommandAuraLinux> commands; |
610 if (delegate) { | 610 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { |
611 if (!delegate->MatchEvent(event, &commands)) | |
612 return false; | |
613 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | 611 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
614 for (size_t i = 0; i < commands.size(); ++i) { | 612 for (size_t i = 0; i < commands.size(); ++i) { |
615 int command = GetViewsCommand(commands[i], rtl); | 613 const int command = GetViewsCommand(commands[i], rtl); |
616 if (IsCommandIdEnabled(command)) { | 614 if (IsCommandIdEnabled(command)) { |
617 ExecuteCommand(command); | 615 ExecuteCommand(command); |
618 handled = true; | 616 handled = true; |
619 } | 617 } |
620 } | 618 } |
621 return handled; | 619 return handled; |
622 } | 620 } |
623 #endif | 621 #endif |
624 | 622 |
625 const int command = GetCommandForKeyEvent(event, HasSelection()); | 623 const int command = GetCommandForKeyEvent(event, HasSelection()); |
626 if (IsCommandIdEnabled(command)) { | 624 if (!handled && IsCommandIdEnabled(command)) { |
627 ExecuteCommand(command); | 625 ExecuteCommand(command); |
628 return true; | 626 handled = true; |
629 } | 627 } |
630 return false; | 628 return handled; |
631 } | 629 } |
632 | 630 |
633 ui::TextInputClient* Textfield::GetTextInputClient() { | 631 ui::TextInputClient* Textfield::GetTextInputClient() { |
634 return read_only_ ? NULL : this; | 632 return read_only_ ? NULL : this; |
635 } | 633 } |
636 | 634 |
637 void Textfield::OnGestureEvent(ui::GestureEvent* event) { | 635 void Textfield::OnGestureEvent(ui::GestureEvent* event) { |
638 switch (event->type()) { | 636 switch (event->type()) { |
639 case ui::ET_GESTURE_TAP_DOWN: | 637 case ui::ET_GESTURE_TAP_DOWN: |
640 OnBeforeUserAction(); | 638 OnBeforeUserAction(); |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 const size_t length = selection_clipboard_text.length(); | 1708 const size_t length = selection_clipboard_text.length(); |
1711 range = gfx::Range(range.start() + length, range.end() + length); | 1709 range = gfx::Range(range.start() + length, range.end() + length); |
1712 } | 1710 } |
1713 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1711 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
1714 UpdateAfterChange(true, true); | 1712 UpdateAfterChange(true, true); |
1715 OnAfterUserAction(); | 1713 OnAfterUserAction(); |
1716 } | 1714 } |
1717 } | 1715 } |
1718 | 1716 |
1719 } // namespace views | 1717 } // namespace views |
OLD | NEW |