OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/base/ime/remote_input_method_win.h" | 5 #include "ui/base/ime/remote_input_method_win.h" |
6 | 6 |
7 #include <InputScope.h> | 7 #include <InputScope.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 void set_composition_character_bounds( | 79 void set_composition_character_bounds( |
80 const std::vector<gfx::Rect>& composition_character_bounds) { | 80 const std::vector<gfx::Rect>& composition_character_bounds) { |
81 composition_character_bounds_ = composition_character_bounds; | 81 composition_character_bounds_ = composition_character_bounds; |
82 } | 82 } |
83 void set_emulate_pepper_flash(bool enabled) { | 83 void set_emulate_pepper_flash(bool enabled) { |
84 emulate_pepper_flash_ = enabled; | 84 emulate_pepper_flash_ = enabled; |
85 } | 85 } |
86 | 86 |
87 private: | 87 private: |
88 // Overriden from DummyTextInputClient. | 88 // Overriden from DummyTextInputClient. |
89 virtual void SetCompositionText( | 89 void SetCompositionText(const ui::CompositionText& composition) override { |
90 const ui::CompositionText& composition) override { | |
91 ++call_count_set_composition_text_; | 90 ++call_count_set_composition_text_; |
92 } | 91 } |
93 virtual void InsertChar(base::char16 ch, int flags) override { | 92 void InsertChar(base::char16 ch, int flags) override { |
94 inserted_text_.append(1, ch); | 93 inserted_text_.append(1, ch); |
95 ++call_count_insert_char_; | 94 ++call_count_insert_char_; |
96 } | 95 } |
97 virtual void InsertText(const base::string16& text) override { | 96 void InsertText(const base::string16& text) override { |
98 inserted_text_.append(text); | 97 inserted_text_.append(text); |
99 ++call_count_insert_text_; | 98 ++call_count_insert_text_; |
100 } | 99 } |
101 virtual ui::TextInputType GetTextInputType() const override { | 100 ui::TextInputType GetTextInputType() const override { |
102 return text_input_type_; | 101 return text_input_type_; |
103 } | 102 } |
104 virtual ui::TextInputMode GetTextInputMode() const override { | 103 ui::TextInputMode GetTextInputMode() const override { |
105 return text_input_mode_; | 104 return text_input_mode_; |
106 } | 105 } |
107 virtual gfx::Rect GetCaretBounds() const { | 106 gfx::Rect GetCaretBounds() const override { return caret_bounds_; } |
108 return caret_bounds_; | 107 bool GetCompositionCharacterBounds(uint32 index, |
109 } | 108 gfx::Rect* rect) const override { |
110 virtual bool GetCompositionCharacterBounds(uint32 index, | |
111 gfx::Rect* rect) const override { | |
112 // Emulate the situation of crbug.com/328237. | 109 // Emulate the situation of crbug.com/328237. |
113 if (emulate_pepper_flash_) | 110 if (emulate_pepper_flash_) |
114 return false; | 111 return false; |
115 if (!rect || composition_character_bounds_.size() <= index) | 112 if (!rect || composition_character_bounds_.size() <= index) |
116 return false; | 113 return false; |
117 *rect = composition_character_bounds_[index]; | 114 *rect = composition_character_bounds_[index]; |
118 return true; | 115 return true; |
119 } | 116 } |
120 virtual bool HasCompositionText() const override { | 117 bool HasCompositionText() const override { |
121 return !composition_character_bounds_.empty(); | 118 return !composition_character_bounds_.empty(); |
122 } | 119 } |
123 virtual bool GetCompositionTextRange(gfx::Range* range) const override { | 120 bool GetCompositionTextRange(gfx::Range* range) const override { |
124 if (composition_character_bounds_.empty()) | 121 if (composition_character_bounds_.empty()) |
125 return false; | 122 return false; |
126 *range = gfx::Range(0, composition_character_bounds_.size()); | 123 *range = gfx::Range(0, composition_character_bounds_.size()); |
127 return true; | 124 return true; |
128 } | 125 } |
129 virtual void OnCandidateWindowShown() override { | 126 void OnCandidateWindowShown() override { |
130 is_candidate_window_shown_called_ = true; | 127 is_candidate_window_shown_called_ = true; |
131 } | 128 } |
132 virtual void OnCandidateWindowHidden() override { | 129 void OnCandidateWindowHidden() override { |
133 is_candidate_window_hidden_called_ = true; | 130 is_candidate_window_hidden_called_ = true; |
134 } | 131 } |
135 | 132 |
136 ui::TextInputType text_input_type_; | 133 ui::TextInputType text_input_type_; |
137 ui::TextInputMode text_input_mode_; | 134 ui::TextInputMode text_input_mode_; |
138 gfx::Rect caret_bounds_; | 135 gfx::Rect caret_bounds_; |
139 std::vector<gfx::Rect> composition_character_bounds_; | 136 std::vector<gfx::Rect> composition_character_bounds_; |
140 base::string16 inserted_text_; | 137 base::string16 inserted_text_; |
141 size_t call_count_set_composition_text_; | 138 size_t call_count_set_composition_text_; |
142 size_t call_count_insert_char_; | 139 size_t call_count_insert_char_; |
143 size_t call_count_insert_text_; | 140 size_t call_count_insert_text_; |
144 bool emulate_pepper_flash_; | 141 bool emulate_pepper_flash_; |
145 bool is_candidate_window_shown_called_; | 142 bool is_candidate_window_shown_called_; |
146 bool is_candidate_window_hidden_called_; | 143 bool is_candidate_window_hidden_called_; |
147 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); | 144 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); |
148 }; | 145 }; |
149 | 146 |
150 class MockInputMethodDelegate : public internal::InputMethodDelegate { | 147 class MockInputMethodDelegate : public internal::InputMethodDelegate { |
151 public: | 148 public: |
152 MockInputMethodDelegate() {} | 149 MockInputMethodDelegate() {} |
153 | 150 |
154 const std::vector<ui::KeyboardCode>& fabricated_key_events() const { | 151 const std::vector<ui::KeyboardCode>& fabricated_key_events() const { |
155 return fabricated_key_events_; | 152 return fabricated_key_events_; |
156 } | 153 } |
157 void Reset() { | 154 void Reset() { |
158 fabricated_key_events_.clear(); | 155 fabricated_key_events_.clear(); |
159 } | 156 } |
160 | 157 |
161 private: | 158 private: |
162 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { | 159 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { |
163 EXPECT_FALSE(event.HasNativeEvent()); | 160 EXPECT_FALSE(event.HasNativeEvent()); |
164 fabricated_key_events_.push_back(event.key_code()); | 161 fabricated_key_events_.push_back(event.key_code()); |
165 return true; | 162 return true; |
166 } | 163 } |
167 | 164 |
168 std::vector<ui::KeyboardCode> fabricated_key_events_; | 165 std::vector<ui::KeyboardCode> fabricated_key_events_; |
169 DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate); | 166 DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate); |
170 }; | 167 }; |
171 | 168 |
172 class MockRemoteInputMethodDelegateWin | 169 class MockRemoteInputMethodDelegateWin |
(...skipping 17 matching lines...) Expand all Loading... |
190 return composition_character_bounds_; | 187 return composition_character_bounds_; |
191 } | 188 } |
192 void Reset() { | 189 void Reset() { |
193 cancel_composition_called_ = false; | 190 cancel_composition_called_ = false; |
194 text_input_client_updated_called_ = false; | 191 text_input_client_updated_called_ = false; |
195 input_scopes_.clear(); | 192 input_scopes_.clear(); |
196 composition_character_bounds_.clear(); | 193 composition_character_bounds_.clear(); |
197 } | 194 } |
198 | 195 |
199 private: | 196 private: |
200 virtual void CancelComposition() override { | 197 void CancelComposition() override { cancel_composition_called_ = true; } |
201 cancel_composition_called_ = true; | |
202 } | |
203 | 198 |
204 virtual void OnTextInputClientUpdated( | 199 void OnTextInputClientUpdated( |
205 const std::vector<int32>& input_scopes, | 200 const std::vector<int32>& input_scopes, |
206 const std::vector<gfx::Rect>& composition_character_bounds) override { | 201 const std::vector<gfx::Rect>& composition_character_bounds) override { |
207 text_input_client_updated_called_ = true; | 202 text_input_client_updated_called_ = true; |
208 input_scopes_ = input_scopes; | 203 input_scopes_ = input_scopes; |
209 composition_character_bounds_ = composition_character_bounds; | 204 composition_character_bounds_ = composition_character_bounds; |
210 } | 205 } |
211 | 206 |
212 bool cancel_composition_called_; | 207 bool cancel_composition_called_; |
213 bool text_input_client_updated_called_; | 208 bool text_input_client_updated_called_; |
214 std::vector<int32> input_scopes_; | 209 std::vector<int32> input_scopes_; |
(...skipping 15 matching lines...) Expand all Loading... |
230 } | 225 } |
231 size_t on_text_input_state_changed() const { | 226 size_t on_text_input_state_changed() const { |
232 return on_text_input_state_changed_; | 227 return on_text_input_state_changed_; |
233 } | 228 } |
234 size_t on_input_method_destroyed_changed() const { | 229 size_t on_input_method_destroyed_changed() const { |
235 return on_input_method_destroyed_changed_; | 230 return on_input_method_destroyed_changed_; |
236 } | 231 } |
237 | 232 |
238 private: | 233 private: |
239 // Overriden from InputMethodObserver. | 234 // Overriden from InputMethodObserver. |
240 virtual void OnTextInputTypeChanged(const TextInputClient* client) override { | 235 void OnTextInputTypeChanged(const TextInputClient* client) override {} |
241 } | 236 void OnFocus() override {} |
242 virtual void OnFocus() override { | 237 void OnBlur() override {} |
243 } | 238 void OnCaretBoundsChanged(const TextInputClient* client) override {} |
244 virtual void OnBlur() override { | 239 void OnTextInputStateChanged(const TextInputClient* client) override { |
245 } | |
246 virtual void OnCaretBoundsChanged(const TextInputClient* client) override { | |
247 } | |
248 virtual void OnTextInputStateChanged(const TextInputClient* client) override { | |
249 ++on_text_input_state_changed_; | 240 ++on_text_input_state_changed_; |
250 } | 241 } |
251 virtual void OnInputMethodDestroyed(const InputMethod* client) override { | 242 void OnInputMethodDestroyed(const InputMethod* client) override { |
252 ++on_input_method_destroyed_changed_; | 243 ++on_input_method_destroyed_changed_; |
253 } | 244 } |
254 virtual void OnShowImeIfNeeded() { | 245 void OnShowImeIfNeeded() override {} |
255 } | |
256 | 246 |
257 size_t on_text_input_state_changed_; | 247 size_t on_text_input_state_changed_; |
258 size_t on_input_method_destroyed_changed_; | 248 size_t on_input_method_destroyed_changed_; |
259 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); | 249 DISALLOW_COPY_AND_ASSIGN(MockInputMethodObserver); |
260 }; | 250 }; |
261 | 251 |
262 typedef ScopedObserver<InputMethod, InputMethodObserver> | 252 typedef ScopedObserver<InputMethod, InputMethodObserver> |
263 InputMethodScopedObserver; | 253 InputMethodScopedObserver; |
264 | 254 |
265 TEST(RemoteInputMethodWinTest, RemoteInputMethodPrivateWin) { | 255 TEST(RemoteInputMethodWinTest, RemoteInputMethodPrivateWin) { |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); | 827 scoped_ptr<InputMethod> input_method(CreateRemoteInputMethodWin(&delegate_)); |
838 input_method->AddObserver(&input_method_observer); | 828 input_method->AddObserver(&input_method_observer); |
839 | 829 |
840 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); | 830 EXPECT_EQ(0u, input_method_observer.on_input_method_destroyed_changed()); |
841 input_method.reset(); | 831 input_method.reset(); |
842 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); | 832 EXPECT_EQ(1u, input_method_observer.on_input_method_destroyed_changed()); |
843 } | 833 } |
844 | 834 |
845 } // namespace | 835 } // namespace |
846 } // namespace ui | 836 } // namespace ui |
OLD | NEW |