Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: ui/views/controls/textfield/native_textfield_views_unittest.cc

Issue 10825254: Remove views::KeyEvent, replacing uses of it with ui::KeyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/pickle.h" 14 #include "base/pickle.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 #include "grit/ui_strings.h" 18 #include "grit/ui_strings.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/base/clipboard/clipboard.h" 20 #include "ui/base/clipboard/clipboard.h"
21 #include "ui/base/clipboard/scoped_clipboard_writer.h" 21 #include "ui/base/clipboard/scoped_clipboard_writer.h"
22 #include "ui/base/dragdrop/drag_drop_types.h" 22 #include "ui/base/dragdrop/drag_drop_types.h"
23 #include "ui/base/event.h"
23 #include "ui/base/ime/text_input_client.h" 24 #include "ui/base/ime/text_input_client.h"
24 #include "ui/base/keycodes/keyboard_codes.h" 25 #include "ui/base/keycodes/keyboard_codes.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/ui_base_switches.h" 27 #include "ui/base/ui_base_switches.h"
27 #include "ui/gfx/render_text.h" 28 #include "ui/gfx/render_text.h"
28 #include "ui/views/controls/textfield/native_textfield_views.h" 29 #include "ui/views/controls/textfield/native_textfield_views.h"
29 #include "ui/views/controls/textfield/textfield.h" 30 #include "ui/views/controls/textfield/textfield.h"
30 #include "ui/views/controls/textfield/textfield_controller.h" 31 #include "ui/views/controls/textfield/textfield_controller.h"
31 #include "ui/views/controls/textfield/textfield_views_model.h" 32 #include "ui/views/controls/textfield/textfield_views_model.h"
32 #include "ui/views/events/event.h" 33 #include "ui/views/events/event.h"
(...skipping 10 matching lines...) Expand all
43 // A wrapper of Textfield to intercept the result of OnKeyPressed() and 44 // A wrapper of Textfield to intercept the result of OnKeyPressed() and
44 // OnKeyReleased() methods. 45 // OnKeyReleased() methods.
45 class TestTextfield : public views::Textfield { 46 class TestTextfield : public views::Textfield {
46 public: 47 public:
47 explicit TestTextfield(StyleFlags style) 48 explicit TestTextfield(StyleFlags style)
48 : Textfield(style), 49 : Textfield(style),
49 key_handled_(false), 50 key_handled_(false),
50 key_received_(false) { 51 key_received_(false) {
51 } 52 }
52 53
53 virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE { 54 virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE {
54 key_received_ = true; 55 key_received_ = true;
55 key_handled_ = views::Textfield::OnKeyPressed(e); 56 key_handled_ = views::Textfield::OnKeyPressed(e);
56 return key_handled_; 57 return key_handled_;
57 } 58 }
58 59
59 virtual bool OnKeyReleased(const views::KeyEvent& e) OVERRIDE { 60 virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE {
60 key_received_ = true; 61 key_received_ = true;
61 key_handled_ = views::Textfield::OnKeyReleased(e); 62 key_handled_ = views::Textfield::OnKeyReleased(e);
62 return key_handled_; 63 return key_handled_;
63 } 64 }
64 65
65 bool key_handled() const { return key_handled_; } 66 bool key_handled() const { return key_handled_; }
66 bool key_received() const { return key_received_; } 67 bool key_received() const { return key_received_; }
67 68
68 void clear() { key_received_ = key_handled_ = false; } 69 void clear() { key_received_ = key_handled_ = false; }
69 70
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ViewsTestBase::TearDown(); 129 ViewsTestBase::TearDown();
129 } 130 }
130 131
131 // TextfieldController: 132 // TextfieldController:
132 virtual void ContentsChanged(Textfield* sender, 133 virtual void ContentsChanged(Textfield* sender,
133 const string16& new_contents) { 134 const string16& new_contents) {
134 ASSERT_NE(last_contents_, new_contents); 135 ASSERT_NE(last_contents_, new_contents);
135 last_contents_ = new_contents; 136 last_contents_ = new_contents;
136 } 137 }
137 138
138 virtual bool HandleKeyEvent(Textfield* sender, const KeyEvent& key_event) { 139 virtual bool HandleKeyEvent(Textfield* sender,
140 const ui::KeyEvent& key_event) {
139 // TODO(oshima): figure out how to test the keystroke. 141 // TODO(oshima): figure out how to test the keystroke.
140 return false; 142 return false;
141 } 143 }
142 144
143 virtual void OnBeforeUserAction(Textfield* sender) { 145 virtual void OnBeforeUserAction(Textfield* sender) {
144 ++on_before_user_action_; 146 ++on_before_user_action_;
145 } 147 }
146 148
147 virtual void OnAfterUserAction(Textfield* sender) { 149 virtual void OnAfterUserAction(Textfield* sender) {
148 ++on_after_user_action_; 150 ++on_after_user_action_;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 202 }
201 203
202 protected: 204 protected:
203 void SendKeyEvent(ui::KeyboardCode key_code, 205 void SendKeyEvent(ui::KeyboardCode key_code,
204 bool shift, 206 bool shift,
205 bool control, 207 bool control,
206 bool caps_lock) { 208 bool caps_lock) {
207 int flags = (shift ? ui::EF_SHIFT_DOWN : 0) | 209 int flags = (shift ? ui::EF_SHIFT_DOWN : 0) |
208 (control ? ui::EF_CONTROL_DOWN : 0) | 210 (control ? ui::EF_CONTROL_DOWN : 0) |
209 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); 211 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0);
210 KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); 212 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags);
211 input_method_->DispatchKeyEvent(event); 213 input_method_->DispatchKeyEvent(event);
212 } 214 }
213 215
214 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { 216 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) {
215 SendKeyEvent(key_code, shift, control, false); 217 SendKeyEvent(key_code, shift, control, false);
216 } 218 }
217 219
218 void SendKeyEvent(ui::KeyboardCode key_code) { 220 void SendKeyEvent(ui::KeyboardCode key_code) {
219 SendKeyEvent(key_code, false, false); 221 SendKeyEvent(key_code, false, false);
220 } 222 }
221 223
222 void SendKeyEvent(char16 ch) { 224 void SendKeyEvent(char16 ch) {
223 if (ch < 0x80) { 225 if (ch < 0x80) {
224 ui::KeyboardCode code = 226 ui::KeyboardCode code =
225 ch == ' ' ? ui::VKEY_SPACE : 227 ch == ' ' ? ui::VKEY_SPACE :
226 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); 228 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a');
227 SendKeyEvent(code); 229 SendKeyEvent(code);
228 } else { 230 } else {
229 KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0); 231 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0);
230 event.set_character(ch); 232 event.set_character(ch);
231 input_method_->DispatchKeyEvent(event); 233 input_method_->DispatchKeyEvent(event);
232 } 234 }
233 } 235 }
234 236
235 string16 GetClipboardText() const { 237 string16 GetClipboardText() const {
236 string16 text; 238 string16 text;
237 views::ViewsDelegate::views_delegate->GetClipboard()-> 239 views::ViewsDelegate::views_delegate->GetClipboard()->
238 ReadText(ui::Clipboard::BUFFER_STANDARD, &text); 240 ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
239 return text; 241 return text;
(...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i; 1663 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i;
1662 } 1664 }
1663 1665
1664 // Return false if the index is out of range. 1666 // Return false if the index is out of range.
1665 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); 1667 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect));
1666 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); 1668 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect));
1667 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); 1669 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect));
1668 } 1670 }
1669 1671
1670 } // namespace views 1672 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.cc ('k') | ui/views/controls/textfield/native_textfield_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698