OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults. | 58 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults. |
59 class TestTextfield : public views::Textfield { | 59 class TestTextfield : public views::Textfield { |
60 public: | 60 public: |
61 TestTextfield() | 61 TestTextfield() |
62 : Textfield(), | 62 : Textfield(), |
63 key_handled_(false), | 63 key_handled_(false), |
64 key_received_(false), | 64 key_received_(false), |
65 weak_ptr_factory_(this) {} | 65 weak_ptr_factory_(this) {} |
66 | 66 |
67 virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE { | 67 virtual bool OnKeyPressed(const ui::KeyEvent& e) override { |
68 key_received_ = true; | 68 key_received_ = true; |
69 | 69 |
70 // Since OnKeyPressed() might destroy |this|, get a weak pointer and | 70 // Since OnKeyPressed() might destroy |this|, get a weak pointer and |
71 // verify it isn't null before writing the bool value to key_handled_. | 71 // verify it isn't null before writing the bool value to key_handled_. |
72 base::WeakPtr<TestTextfield> textfield(weak_ptr_factory_.GetWeakPtr()); | 72 base::WeakPtr<TestTextfield> textfield(weak_ptr_factory_.GetWeakPtr()); |
73 bool key = views::Textfield::OnKeyPressed(e); | 73 bool key = views::Textfield::OnKeyPressed(e); |
74 | 74 |
75 if (!textfield) | 75 if (!textfield) |
76 return key; | 76 return key; |
77 | 77 |
78 key_handled_ = key; | 78 key_handled_ = key; |
79 | 79 |
80 return key_handled_; | 80 return key_handled_; |
81 } | 81 } |
82 | 82 |
83 virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE { | 83 virtual bool OnKeyReleased(const ui::KeyEvent& e) override { |
84 key_received_ = true; | 84 key_received_ = true; |
85 key_handled_ = views::Textfield::OnKeyReleased(e); | 85 key_handled_ = views::Textfield::OnKeyReleased(e); |
86 return key_handled_; | 86 return key_handled_; |
87 } | 87 } |
88 | 88 |
89 bool key_handled() const { return key_handled_; } | 89 bool key_handled() const { return key_handled_; } |
90 bool key_received() const { return key_received_; } | 90 bool key_received() const { return key_received_; } |
91 | 91 |
92 void clear() { key_received_ = key_handled_ = false; } | 92 void clear() { key_received_ = key_handled_ = false; } |
93 | 93 |
(...skipping 22 matching lines...) Expand all Loading... |
116 public: | 116 public: |
117 explicit TextfieldDestroyerController(views::Textfield* target) | 117 explicit TextfieldDestroyerController(views::Textfield* target) |
118 : target_(target) { | 118 : target_(target) { |
119 target_->set_controller(this); | 119 target_->set_controller(this); |
120 } | 120 } |
121 | 121 |
122 views::Textfield* target() { return target_.get(); } | 122 views::Textfield* target() { return target_.get(); } |
123 | 123 |
124 // views::TextfieldController: | 124 // views::TextfieldController: |
125 virtual bool HandleKeyEvent(views::Textfield* sender, | 125 virtual bool HandleKeyEvent(views::Textfield* sender, |
126 const ui::KeyEvent& key_event) OVERRIDE { | 126 const ui::KeyEvent& key_event) override { |
127 target_.reset(); | 127 target_.reset(); |
128 return false; | 128 return false; |
129 } | 129 } |
130 | 130 |
131 private: | 131 private: |
132 scoped_ptr<views::Textfield> target_; | 132 scoped_ptr<views::Textfield> target_; |
133 }; | 133 }; |
134 | 134 |
135 base::string16 GetClipboardText(ui::ClipboardType type) { | 135 base::string16 GetClipboardText(ui::ClipboardType type) { |
136 base::string16 text; | 136 base::string16 text; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 170 } |
171 | 171 |
172 ui::ClipboardType GetAndResetCopiedToClipboard() { | 172 ui::ClipboardType GetAndResetCopiedToClipboard() { |
173 ui::ClipboardType clipboard_type = copied_to_clipboard_; | 173 ui::ClipboardType clipboard_type = copied_to_clipboard_; |
174 copied_to_clipboard_ = ui::CLIPBOARD_TYPE_LAST; | 174 copied_to_clipboard_ = ui::CLIPBOARD_TYPE_LAST; |
175 return clipboard_type; | 175 return clipboard_type; |
176 } | 176 } |
177 | 177 |
178 // TextfieldController: | 178 // TextfieldController: |
179 virtual void ContentsChanged(Textfield* sender, | 179 virtual void ContentsChanged(Textfield* sender, |
180 const base::string16& new_contents) OVERRIDE { | 180 const base::string16& new_contents) override { |
181 // Paste calls TextfieldController::ContentsChanged() explicitly even if the | 181 // Paste calls TextfieldController::ContentsChanged() explicitly even if the |
182 // paste action did not change the content. So |new_contents| may match | 182 // paste action did not change the content. So |new_contents| may match |
183 // |last_contents_|. For more info, see http://crbug.com/79002 | 183 // |last_contents_|. For more info, see http://crbug.com/79002 |
184 last_contents_ = new_contents; | 184 last_contents_ = new_contents; |
185 } | 185 } |
186 | 186 |
187 virtual void OnBeforeUserAction(Textfield* sender) OVERRIDE { | 187 virtual void OnBeforeUserAction(Textfield* sender) override { |
188 ++on_before_user_action_; | 188 ++on_before_user_action_; |
189 } | 189 } |
190 | 190 |
191 virtual void OnAfterUserAction(Textfield* sender) OVERRIDE { | 191 virtual void OnAfterUserAction(Textfield* sender) override { |
192 ++on_after_user_action_; | 192 ++on_after_user_action_; |
193 } | 193 } |
194 | 194 |
195 virtual void OnAfterCutOrCopy(ui::ClipboardType clipboard_type) OVERRIDE { | 195 virtual void OnAfterCutOrCopy(ui::ClipboardType clipboard_type) override { |
196 copied_to_clipboard_ = clipboard_type; | 196 copied_to_clipboard_ = clipboard_type; |
197 } | 197 } |
198 | 198 |
199 void InitTextfield() { | 199 void InitTextfield() { |
200 InitTextfields(1); | 200 InitTextfields(1); |
201 } | 201 } |
202 | 202 |
203 void InitTextfields(int count) { | 203 void InitTextfields(int count) { |
204 ASSERT_FALSE(textfield_); | 204 ASSERT_FALSE(textfield_); |
205 textfield_ = new TestTextfield(); | 205 textfield_ = new TestTextfield(); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 625 |
626 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 626 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
627 // Install a TextEditKeyBindingsDelegateAuraLinux that does nothing. | 627 // Install a TextEditKeyBindingsDelegateAuraLinux that does nothing. |
628 class TestDelegate : public ui::TextEditKeyBindingsDelegateAuraLinux { | 628 class TestDelegate : public ui::TextEditKeyBindingsDelegateAuraLinux { |
629 public: | 629 public: |
630 TestDelegate() {} | 630 TestDelegate() {} |
631 virtual ~TestDelegate() {} | 631 virtual ~TestDelegate() {} |
632 | 632 |
633 virtual bool MatchEvent( | 633 virtual bool MatchEvent( |
634 const ui::Event& event, | 634 const ui::Event& event, |
635 std::vector<ui::TextEditCommandAuraLinux>* commands) OVERRIDE { | 635 std::vector<ui::TextEditCommandAuraLinux>* commands) override { |
636 return false; | 636 return false; |
637 } | 637 } |
638 | 638 |
639 private: | 639 private: |
640 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 640 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
641 }; | 641 }; |
642 | 642 |
643 TestDelegate delegate; | 643 TestDelegate delegate; |
644 ui::SetTextEditKeyBindingsDelegate(&delegate); | 644 ui::SetTextEditKeyBindingsDelegate(&delegate); |
645 #endif | 645 #endif |
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2064 TextfieldDestroyerController controller(textfield_); | 2064 TextfieldDestroyerController controller(textfield_); |
2065 EXPECT_TRUE(controller.target()); | 2065 EXPECT_TRUE(controller.target()); |
2066 | 2066 |
2067 // Send a key to trigger OnKeyEvent(). | 2067 // Send a key to trigger OnKeyEvent(). |
2068 SendKeyEvent('X'); | 2068 SendKeyEvent('X'); |
2069 | 2069 |
2070 EXPECT_FALSE(controller.target()); | 2070 EXPECT_FALSE(controller.target()); |
2071 } | 2071 } |
2072 | 2072 |
2073 } // namespace views | 2073 } // namespace views |
OLD | NEW |