| 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/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 initiating_drag_ = false; | 662 initiating_drag_ = false; |
| 663 UpdateSelectionClipboard(); | 663 UpdateSelectionClipboard(); |
| 664 OnAfterUserAction(); | 664 OnAfterUserAction(); |
| 665 } | 665 } |
| 666 | 666 |
| 667 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { | 667 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { |
| 668 // Since HandleKeyEvent() might destroy |this|, get a weak pointer and verify | 668 // Since HandleKeyEvent() might destroy |this|, get a weak pointer and verify |
| 669 // it isn't null before proceeding. | 669 // it isn't null before proceeding. |
| 670 base::WeakPtr<Textfield> textfield(weak_ptr_factory_.GetWeakPtr()); | 670 base::WeakPtr<Textfield> textfield(weak_ptr_factory_.GetWeakPtr()); |
| 671 | 671 |
| 672 bool handled = controller_ && controller_->HandleKeyEvent(this, event); | 672 bool handled = HandleAsKeyEventOnly(event); |
| 673 | 673 |
| 674 if (!textfield) | 674 if (!textfield) |
| 675 return handled; | 675 return handled; |
| 676 | 676 |
| 677 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 677 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 678 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = | 678 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
| 679 ui::GetTextEditKeyBindingsDelegate(); | 679 ui::GetTextEditKeyBindingsDelegate(); |
| 680 std::vector<ui::TextEditCommandAuraLinux> commands; | 680 std::vector<ui::TextEditCommandAuraLinux> commands; |
| 681 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { | 681 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { |
| 682 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | 682 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 693 | 693 |
| 694 const int command = GetCommandForKeyEvent(event, HasSelection()); | 694 const int command = GetCommandForKeyEvent(event, HasSelection()); |
| 695 if (!handled && IsCommandIdEnabled(command)) { | 695 if (!handled && IsCommandIdEnabled(command)) { |
| 696 ExecuteCommand(command); | 696 ExecuteCommand(command); |
| 697 handled = true; | 697 handled = true; |
| 698 } | 698 } |
| 699 return handled; | 699 return handled; |
| 700 } | 700 } |
| 701 | 701 |
| 702 ui::TextInputClient* Textfield::GetTextInputClient() { | 702 ui::TextInputClient* Textfield::GetTextInputClient() { |
| 703 return read_only_ ? NULL : this; | 703 return this; |
| 704 } | 704 } |
| 705 | 705 |
| 706 void Textfield::OnGestureEvent(ui::GestureEvent* event) { | 706 void Textfield::OnGestureEvent(ui::GestureEvent* event) { |
| 707 switch (event->type()) { | 707 switch (event->type()) { |
| 708 case ui::ET_GESTURE_TAP_DOWN: | 708 case ui::ET_GESTURE_TAP_DOWN: |
| 709 RequestFocus(); | 709 RequestFocus(); |
| 710 ShowImeIfNeeded(); | 710 ShowImeIfNeeded(); |
| 711 event->SetHandled(); | 711 event->SetHandled(); |
| 712 break; | 712 break; |
| 713 case ui::ET_GESTURE_TAP: | 713 case ui::ET_GESTURE_TAP: |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 void Textfield::OnCandidateWindowHidden() {} | 1605 void Textfield::OnCandidateWindowHidden() {} |
| 1606 | 1606 |
| 1607 bool Textfield::IsEditingCommandEnabled(int command_id) { | 1607 bool Textfield::IsEditingCommandEnabled(int command_id) { |
| 1608 return IsCommandIdEnabled(command_id); | 1608 return IsCommandIdEnabled(command_id); |
| 1609 } | 1609 } |
| 1610 | 1610 |
| 1611 void Textfield::ExecuteEditingCommand(int command_id) { | 1611 void Textfield::ExecuteEditingCommand(int command_id) { |
| 1612 ExecuteCommand(command_id); | 1612 ExecuteCommand(command_id); |
| 1613 } | 1613 } |
| 1614 | 1614 |
| 1615 bool Textfield::HandleAsKeyEventOnly(const ui::KeyEvent& key_event) { |
| 1616 return controller_ && controller_->HandleKeyEvent(this, key_event); |
| 1617 } |
| 1618 |
| 1615 //////////////////////////////////////////////////////////////////////////////// | 1619 //////////////////////////////////////////////////////////////////////////////// |
| 1616 // Textfield, protected: | 1620 // Textfield, protected: |
| 1617 | 1621 |
| 1618 gfx::RenderText* Textfield::GetRenderText() const { | 1622 gfx::RenderText* Textfield::GetRenderText() const { |
| 1619 return model_->render_text(); | 1623 return model_->render_text(); |
| 1620 } | 1624 } |
| 1621 | 1625 |
| 1622 base::string16 Textfield::GetSelectionClipboardText() const { | 1626 base::string16 Textfield::GetSelectionClipboardText() const { |
| 1623 base::string16 selection_clipboard_text; | 1627 base::string16 selection_clipboard_text; |
| 1624 ui::Clipboard::GetForCurrentThread()->ReadText( | 1628 ui::Clipboard::GetForCurrentThread()->ReadText( |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1869 const size_t length = selection_clipboard_text.length(); | 1873 const size_t length = selection_clipboard_text.length(); |
| 1870 range = gfx::Range(range.start() + length, range.end() + length); | 1874 range = gfx::Range(range.start() + length, range.end() + length); |
| 1871 } | 1875 } |
| 1872 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1876 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
| 1873 UpdateAfterChange(true, true); | 1877 UpdateAfterChange(true, true); |
| 1874 OnAfterUserAction(); | 1878 OnAfterUserAction(); |
| 1875 } | 1879 } |
| 1876 } | 1880 } |
| 1877 | 1881 |
| 1878 } // namespace views | 1882 } // namespace views |
| OLD | NEW |