OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/ime/mock_input_method.h" | 5 #include "views/ime/mock_input_method.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "ui/base/ime/text_input_client.h" | |
10 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
11 #include "views/events/event.h" | 10 #include "views/events/event.h" |
12 #include "views/widget/widget.h" | 11 #include "views/widget/widget.h" |
13 | 12 |
14 namespace views { | 13 namespace views { |
15 | 14 |
16 MockInputMethod::MockInputMethod() | 15 MockInputMethod::MockInputMethod() |
17 : composition_changed_(false), | 16 : composition_changed_(false), |
18 focus_changed_(false), | 17 focus_changed_(false), |
19 text_input_type_changed_(false), | 18 text_input_type_changed_(false), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 if (handled) { | 50 if (handled) { |
52 KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags()); | 51 KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags()); |
53 DispatchKeyEventPostIME(mock_key); | 52 DispatchKeyEventPostIME(mock_key); |
54 } else { | 53 } else { |
55 DispatchKeyEventPostIME(key); | 54 DispatchKeyEventPostIME(key); |
56 } | 55 } |
57 | 56 |
58 if (focus_changed_) | 57 if (focus_changed_) |
59 return; | 58 return; |
60 | 59 |
61 ui::TextInputClient* client = GetTextInputClient(); | 60 TextInputClient* client = GetTextInputClient(); |
62 if (client) { | 61 if (client) { |
63 if (handled) { | 62 if (handled) { |
64 if (result_text_.length()) | 63 if (result_text_.length()) |
65 client->InsertText(result_text_); | 64 client->InsertText(result_text_); |
66 if (composition_changed_) { | 65 if (composition_changed_) { |
67 if (composition_.text.length()) | 66 if (composition_.text.length()) |
68 client->SetCompositionText(composition_); | 67 client->SetCompositionText(composition_); |
69 else | 68 else |
70 client->ClearCompositionText(); | 69 client->ClearCompositionText(); |
71 } | 70 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 105 |
107 bool MockInputMethod::IsActive() { | 106 bool MockInputMethod::IsActive() { |
108 return active_; | 107 return active_; |
109 } | 108 } |
110 | 109 |
111 bool MockInputMethod::IsMock() const { | 110 bool MockInputMethod::IsMock() const { |
112 return true; | 111 return true; |
113 } | 112 } |
114 | 113 |
115 void MockInputMethod::OnWillChangeFocus(View* focused_before, View* focused) { | 114 void MockInputMethod::OnWillChangeFocus(View* focused_before, View* focused) { |
116 ui::TextInputClient* client = GetTextInputClient(); | 115 TextInputClient* client = GetTextInputClient(); |
117 if (client && client->HasCompositionText()) | 116 if (client && client->HasCompositionText()) |
118 client->ConfirmCompositionText(); | 117 client->ConfirmCompositionText(); |
119 focus_changed_ = true; | 118 focus_changed_ = true; |
120 ClearResult(); | 119 ClearResult(); |
121 } | 120 } |
122 | 121 |
123 void MockInputMethod::Clear() { | 122 void MockInputMethod::Clear() { |
124 ClearStates(); | 123 ClearStates(); |
125 ClearResult(); | 124 ClearResult(); |
126 } | 125 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 cancel_composition_called_ = false; | 163 cancel_composition_called_ = false; |
165 } | 164 } |
166 | 165 |
167 void MockInputMethod::ClearResult() { | 166 void MockInputMethod::ClearResult() { |
168 composition_.Clear(); | 167 composition_.Clear(); |
169 composition_changed_ = false; | 168 composition_changed_ = false; |
170 result_text_.clear(); | 169 result_text_.clear(); |
171 } | 170 } |
172 | 171 |
173 } // namespace views | 172 } // namespace views |
OLD | NEW |