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 "base/observer_list.h" | 7 #include "base/observer_list.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/win/metro.h" | 9 #include "base/win/metro.h" |
10 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 virtual ~RemoteInputMethodWin() { | 122 virtual ~RemoteInputMethodWin() { |
123 FOR_EACH_OBSERVER(InputMethodObserver, | 123 FOR_EACH_OBSERVER(InputMethodObserver, |
124 observer_list_, | 124 observer_list_, |
125 OnInputMethodDestroyed(this)); | 125 OnInputMethodDestroyed(this)); |
126 UnregisterInstance(this); | 126 UnregisterInstance(this); |
127 } | 127 } |
128 | 128 |
129 private: | 129 private: |
130 // Overridden from InputMethod: | 130 // Overridden from InputMethod: |
131 virtual void SetDelegate(internal::InputMethodDelegate* delegate) OVERRIDE { | 131 virtual void SetDelegate(internal::InputMethodDelegate* delegate) override { |
132 delegate_ = delegate; | 132 delegate_ = delegate; |
133 } | 133 } |
134 | 134 |
135 virtual void Init(bool focused) OVERRIDE { | 135 virtual void Init(bool focused) override { |
136 } | 136 } |
137 | 137 |
138 virtual void OnFocus() OVERRIDE { | 138 virtual void OnFocus() override { |
139 } | 139 } |
140 | 140 |
141 virtual void OnBlur() OVERRIDE { | 141 virtual void OnBlur() override { |
142 } | 142 } |
143 | 143 |
144 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, | 144 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, |
145 NativeEventResult* result) OVERRIDE { | 145 NativeEventResult* result) override { |
146 return false; | 146 return false; |
147 } | 147 } |
148 | 148 |
149 virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE { | 149 virtual void SetFocusedTextInputClient(TextInputClient* client) override { |
150 std::vector<int32> prev_input_scopes; | 150 std::vector<int32> prev_input_scopes; |
151 std::swap(input_scopes_, prev_input_scopes); | 151 std::swap(input_scopes_, prev_input_scopes); |
152 std::vector<gfx::Rect> prev_bounds; | 152 std::vector<gfx::Rect> prev_bounds; |
153 std::swap(composition_character_bounds_, prev_bounds); | 153 std::swap(composition_character_bounds_, prev_bounds); |
154 if (client) { | 154 if (client) { |
155 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), | 155 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), |
156 client->GetTextInputMode()); | 156 client->GetTextInputMode()); |
157 composition_character_bounds_ = GetCompositionCharacterBounds(client); | 157 composition_character_bounds_ = GetCompositionCharacterBounds(client); |
158 } | 158 } |
159 | 159 |
160 const bool text_input_client_changed = text_input_client_ != client; | 160 const bool text_input_client_changed = text_input_client_ != client; |
161 text_input_client_ = client; | 161 text_input_client_ = client; |
162 if (text_input_client_changed) { | 162 if (text_input_client_changed) { |
163 FOR_EACH_OBSERVER(InputMethodObserver, | 163 FOR_EACH_OBSERVER(InputMethodObserver, |
164 observer_list_, | 164 observer_list_, |
165 OnTextInputStateChanged(client)); | 165 OnTextInputStateChanged(client)); |
166 } | 166 } |
167 | 167 |
168 if (!remote_delegate_ || (prev_input_scopes == input_scopes_ && | 168 if (!remote_delegate_ || (prev_input_scopes == input_scopes_ && |
169 prev_bounds == composition_character_bounds_)) | 169 prev_bounds == composition_character_bounds_)) |
170 return; | 170 return; |
171 remote_delegate_->OnTextInputClientUpdated(input_scopes_, | 171 remote_delegate_->OnTextInputClientUpdated(input_scopes_, |
172 composition_character_bounds_); | 172 composition_character_bounds_); |
173 } | 173 } |
174 | 174 |
175 virtual void DetachTextInputClient(TextInputClient* client) OVERRIDE { | 175 virtual void DetachTextInputClient(TextInputClient* client) override { |
176 if (text_input_client_ != client) | 176 if (text_input_client_ != client) |
177 return; | 177 return; |
178 SetFocusedTextInputClient(NULL); | 178 SetFocusedTextInputClient(NULL); |
179 } | 179 } |
180 | 180 |
181 virtual TextInputClient* GetTextInputClient() const OVERRIDE { | 181 virtual TextInputClient* GetTextInputClient() const override { |
182 return text_input_client_; | 182 return text_input_client_; |
183 } | 183 } |
184 | 184 |
185 virtual bool DispatchKeyEvent(const ui::KeyEvent& event) OVERRIDE { | 185 virtual bool DispatchKeyEvent(const ui::KeyEvent& event) override { |
186 if (event.HasNativeEvent()) { | 186 if (event.HasNativeEvent()) { |
187 const base::NativeEvent& native_key_event = event.native_event(); | 187 const base::NativeEvent& native_key_event = event.native_event(); |
188 if (native_key_event.message != WM_CHAR) | 188 if (native_key_event.message != WM_CHAR) |
189 return false; | 189 return false; |
190 if (!text_input_client_) | 190 if (!text_input_client_) |
191 return false; | 191 return false; |
192 text_input_client_->InsertChar( | 192 text_input_client_->InsertChar( |
193 static_cast<base::char16>(native_key_event.wParam), | 193 static_cast<base::char16>(native_key_event.wParam), |
194 ui::GetModifiersFromKeyState()); | 194 ui::GetModifiersFromKeyState()); |
195 return true; | 195 return true; |
196 } | 196 } |
197 | 197 |
198 if (event.is_char()) { | 198 if (event.is_char()) { |
199 if (text_input_client_) { | 199 if (text_input_client_) { |
200 text_input_client_->InsertChar(event.key_code(), | 200 text_input_client_->InsertChar(event.key_code(), |
201 ui::GetModifiersFromKeyState()); | 201 ui::GetModifiersFromKeyState()); |
202 } | 202 } |
203 return true; | 203 return true; |
204 } | 204 } |
205 if (!delegate_) | 205 if (!delegate_) |
206 return false; | 206 return false; |
207 return delegate_->DispatchKeyEventPostIME(event); | 207 return delegate_->DispatchKeyEventPostIME(event); |
208 } | 208 } |
209 | 209 |
210 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { | 210 virtual void OnTextInputTypeChanged(const TextInputClient* client) override { |
211 if (!text_input_client_ || text_input_client_ != client) | 211 if (!text_input_client_ || text_input_client_ != client) |
212 return; | 212 return; |
213 std::vector<int32> prev_input_scopes; | 213 std::vector<int32> prev_input_scopes; |
214 std::swap(input_scopes_, prev_input_scopes); | 214 std::swap(input_scopes_, prev_input_scopes); |
215 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), | 215 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), |
216 client->GetTextInputMode()); | 216 client->GetTextInputMode()); |
217 if (input_scopes_ != prev_input_scopes && remote_delegate_) { | 217 if (input_scopes_ != prev_input_scopes && remote_delegate_) { |
218 remote_delegate_->OnTextInputClientUpdated( | 218 remote_delegate_->OnTextInputClientUpdated( |
219 input_scopes_, composition_character_bounds_); | 219 input_scopes_, composition_character_bounds_); |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE { | 223 virtual void OnCaretBoundsChanged(const TextInputClient* client) override { |
224 if (!text_input_client_ || text_input_client_ != client) | 224 if (!text_input_client_ || text_input_client_ != client) |
225 return; | 225 return; |
226 std::vector<gfx::Rect> prev_rects; | 226 std::vector<gfx::Rect> prev_rects; |
227 std::swap(composition_character_bounds_, prev_rects); | 227 std::swap(composition_character_bounds_, prev_rects); |
228 composition_character_bounds_ = GetCompositionCharacterBounds(client); | 228 composition_character_bounds_ = GetCompositionCharacterBounds(client); |
229 if (composition_character_bounds_ != prev_rects && remote_delegate_) { | 229 if (composition_character_bounds_ != prev_rects && remote_delegate_) { |
230 remote_delegate_->OnTextInputClientUpdated( | 230 remote_delegate_->OnTextInputClientUpdated( |
231 input_scopes_, composition_character_bounds_); | 231 input_scopes_, composition_character_bounds_); |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 virtual void CancelComposition(const TextInputClient* client) OVERRIDE { | 235 virtual void CancelComposition(const TextInputClient* client) override { |
236 if (CanSendRemoteNotification(client)) | 236 if (CanSendRemoteNotification(client)) |
237 remote_delegate_->CancelComposition(); | 237 remote_delegate_->CancelComposition(); |
238 } | 238 } |
239 | 239 |
240 virtual void OnInputLocaleChanged() OVERRIDE { | 240 virtual void OnInputLocaleChanged() override { |
241 } | 241 } |
242 | 242 |
243 virtual std::string GetInputLocale() OVERRIDE { | 243 virtual std::string GetInputLocale() override { |
244 const LCID locale_id = MAKELCID(langid_, SORT_DEFAULT); | 244 const LCID locale_id = MAKELCID(langid_, SORT_DEFAULT); |
245 std::string language = | 245 std::string language = |
246 GetLocaleString(locale_id, LOCALE_SISO639LANGNAME); | 246 GetLocaleString(locale_id, LOCALE_SISO639LANGNAME); |
247 if (SUBLANGID(langid_) == SUBLANG_NEUTRAL || language.empty()) | 247 if (SUBLANGID(langid_) == SUBLANG_NEUTRAL || language.empty()) |
248 return language; | 248 return language; |
249 const std::string& region = | 249 const std::string& region = |
250 GetLocaleString(locale_id, LOCALE_SISO3166CTRYNAME); | 250 GetLocaleString(locale_id, LOCALE_SISO3166CTRYNAME); |
251 if (region.empty()) | 251 if (region.empty()) |
252 return language; | 252 return language; |
253 return language.append(1, '-').append(region); | 253 return language.append(1, '-').append(region); |
254 } | 254 } |
255 | 255 |
256 virtual bool IsActive() OVERRIDE { | 256 virtual bool IsActive() override { |
257 return true; // always turned on | 257 return true; // always turned on |
258 } | 258 } |
259 | 259 |
260 virtual TextInputType GetTextInputType() const OVERRIDE { | 260 virtual TextInputType GetTextInputType() const override { |
261 return text_input_client_ ? text_input_client_->GetTextInputType() | 261 return text_input_client_ ? text_input_client_->GetTextInputType() |
262 : TEXT_INPUT_TYPE_NONE; | 262 : TEXT_INPUT_TYPE_NONE; |
263 } | 263 } |
264 | 264 |
265 virtual TextInputMode GetTextInputMode() const OVERRIDE { | 265 virtual TextInputMode GetTextInputMode() const override { |
266 return text_input_client_ ? text_input_client_->GetTextInputMode() | 266 return text_input_client_ ? text_input_client_->GetTextInputMode() |
267 : TEXT_INPUT_MODE_DEFAULT; | 267 : TEXT_INPUT_MODE_DEFAULT; |
268 } | 268 } |
269 | 269 |
270 virtual bool CanComposeInline() const OVERRIDE { | 270 virtual bool CanComposeInline() const override { |
271 return text_input_client_ ? text_input_client_->CanComposeInline() : true; | 271 return text_input_client_ ? text_input_client_->CanComposeInline() : true; |
272 } | 272 } |
273 | 273 |
274 virtual bool IsCandidatePopupOpen() const OVERRIDE { | 274 virtual bool IsCandidatePopupOpen() const override { |
275 return is_candidate_popup_open_; | 275 return is_candidate_popup_open_; |
276 } | 276 } |
277 | 277 |
278 virtual void ShowImeIfNeeded() OVERRIDE { | 278 virtual void ShowImeIfNeeded() override { |
279 } | 279 } |
280 | 280 |
281 virtual void AddObserver(InputMethodObserver* observer) OVERRIDE { | 281 virtual void AddObserver(InputMethodObserver* observer) override { |
282 observer_list_.AddObserver(observer); | 282 observer_list_.AddObserver(observer); |
283 } | 283 } |
284 | 284 |
285 virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE { | 285 virtual void RemoveObserver(InputMethodObserver* observer) override { |
286 observer_list_.RemoveObserver(observer); | 286 observer_list_.RemoveObserver(observer); |
287 } | 287 } |
288 | 288 |
289 // Overridden from RemoteInputMethodPrivateWin: | 289 // Overridden from RemoteInputMethodPrivateWin: |
290 virtual void SetRemoteDelegate( | 290 virtual void SetRemoteDelegate( |
291 internal::RemoteInputMethodDelegateWin* delegate) OVERRIDE{ | 291 internal::RemoteInputMethodDelegateWin* delegate) override{ |
292 remote_delegate_ = delegate; | 292 remote_delegate_ = delegate; |
293 | 293 |
294 // Sync initial state. | 294 // Sync initial state. |
295 if (remote_delegate_) { | 295 if (remote_delegate_) { |
296 remote_delegate_->OnTextInputClientUpdated( | 296 remote_delegate_->OnTextInputClientUpdated( |
297 input_scopes_, composition_character_bounds_); | 297 input_scopes_, composition_character_bounds_); |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 virtual void OnCandidatePopupChanged(bool visible) OVERRIDE { | 301 virtual void OnCandidatePopupChanged(bool visible) override { |
302 is_candidate_popup_open_ = visible; | 302 is_candidate_popup_open_ = visible; |
303 if (!text_input_client_) | 303 if (!text_input_client_) |
304 return; | 304 return; |
305 // TODO(kochi): Support 'update' case, in addition to show/hide. | 305 // TODO(kochi): Support 'update' case, in addition to show/hide. |
306 // http://crbug.com/238585 | 306 // http://crbug.com/238585 |
307 if (visible) | 307 if (visible) |
308 text_input_client_->OnCandidateWindowShown(); | 308 text_input_client_->OnCandidateWindowShown(); |
309 else | 309 else |
310 text_input_client_->OnCandidateWindowHidden(); | 310 text_input_client_->OnCandidateWindowHidden(); |
311 } | 311 } |
312 | 312 |
313 virtual void OnInputSourceChanged(LANGID langid, bool /*is_ime*/) OVERRIDE { | 313 virtual void OnInputSourceChanged(LANGID langid, bool /*is_ime*/) override { |
314 // Note: Currently |is_ime| is not utilized yet. | 314 // Note: Currently |is_ime| is not utilized yet. |
315 const bool changed = (langid_ != langid); | 315 const bool changed = (langid_ != langid); |
316 langid_ = langid; | 316 langid_ = langid; |
317 if (changed && GetTextInputClient()) | 317 if (changed && GetTextInputClient()) |
318 GetTextInputClient()->OnInputMethodChanged(); | 318 GetTextInputClient()->OnInputMethodChanged(); |
319 } | 319 } |
320 | 320 |
321 virtual void OnCompositionChanged( | 321 virtual void OnCompositionChanged( |
322 const CompositionText& composition_text) OVERRIDE { | 322 const CompositionText& composition_text) override { |
323 if (!text_input_client_) | 323 if (!text_input_client_) |
324 return; | 324 return; |
325 text_input_client_->SetCompositionText(composition_text); | 325 text_input_client_->SetCompositionText(composition_text); |
326 } | 326 } |
327 | 327 |
328 virtual void OnTextCommitted(const base::string16& text) OVERRIDE { | 328 virtual void OnTextCommitted(const base::string16& text) override { |
329 if (!text_input_client_) | 329 if (!text_input_client_) |
330 return; | 330 return; |
331 if (text_input_client_->GetTextInputType() == TEXT_INPUT_TYPE_NONE) { | 331 if (text_input_client_->GetTextInputType() == TEXT_INPUT_TYPE_NONE) { |
332 // According to the comment in text_input_client.h, | 332 // According to the comment in text_input_client.h, |
333 // TextInputClient::InsertText should never be called when the | 333 // TextInputClient::InsertText should never be called when the |
334 // text input type is TEXT_INPUT_TYPE_NONE. | 334 // text input type is TEXT_INPUT_TYPE_NONE. |
335 for (size_t i = 0; i < text.size(); ++i) | 335 for (size_t i = 0; i < text.size(); ++i) |
336 text_input_client_->InsertChar(text[i], 0); | 336 text_input_client_->InsertChar(text[i], 0); |
337 return; | 337 return; |
338 } | 338 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 return scoped_ptr<InputMethod>(new RemoteInputMethodWin(delegate)); | 381 return scoped_ptr<InputMethod>(new RemoteInputMethodWin(delegate)); |
382 } | 382 } |
383 | 383 |
384 // static | 384 // static |
385 RemoteInputMethodPrivateWin* RemoteInputMethodPrivateWin::Get( | 385 RemoteInputMethodPrivateWin* RemoteInputMethodPrivateWin::Get( |
386 InputMethod* input_method) { | 386 InputMethod* input_method) { |
387 return GetPrivate(input_method); | 387 return GetPrivate(input_method); |
388 } | 388 } |
389 | 389 |
390 } // namespace ui | 390 } // namespace ui |
OLD | NEW |