| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/base/ime/input_method.h" | 9 #include "ui/base/ime/input_method.h" |
| 9 #include "ui/base/ime/input_method_delegate.h" | 10 #include "ui/base/ime/input_method_delegate.h" |
| 11 #include "ui/base/ime/input_method_observer.h" |
| 10 #include "ui/base/ime/remote_input_method_delegate_win.h" | 12 #include "ui/base/ime/remote_input_method_delegate_win.h" |
| 11 #include "ui/base/ime/text_input_client.h" | 13 #include "ui/base/ime/text_input_client.h" |
| 12 #include "ui/base/ime/win/tsf_input_scope.h" | 14 #include "ui/base/ime/win/tsf_input_scope.h" |
| 13 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 14 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
| 15 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 16 | 18 |
| 17 namespace ui { | 19 namespace ui { |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return bounds; | 99 return bounds; |
| 98 } | 100 } |
| 99 | 101 |
| 100 class RemoteInputMethodWin : public InputMethod, | 102 class RemoteInputMethodWin : public InputMethod, |
| 101 public RemoteInputMethodPrivateWin { | 103 public RemoteInputMethodPrivateWin { |
| 102 public: | 104 public: |
| 103 explicit RemoteInputMethodWin(internal::InputMethodDelegate* delegate) | 105 explicit RemoteInputMethodWin(internal::InputMethodDelegate* delegate) |
| 104 : delegate_(delegate), | 106 : delegate_(delegate), |
| 105 remote_delegate_(NULL), | 107 remote_delegate_(NULL), |
| 106 text_input_client_(NULL), | 108 text_input_client_(NULL), |
| 109 current_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 110 current_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| 107 is_candidate_popup_open_(false), | 111 is_candidate_popup_open_(false), |
| 108 is_ime_(false), | 112 is_ime_(false), |
| 109 langid_(kFallbackLangID) { | 113 langid_(kFallbackLangID) { |
| 110 RegisterInstance(this, this); | 114 RegisterInstance(this, this); |
| 111 } | 115 } |
| 112 | 116 |
| 113 virtual ~RemoteInputMethodWin() { | 117 virtual ~RemoteInputMethodWin() { |
| 118 FOR_EACH_OBSERVER(InputMethodObserver, |
| 119 observer_list_, |
| 120 OnInputMethodDestroyed(this)); |
| 114 UnregisterInstance(this); | 121 UnregisterInstance(this); |
| 115 } | 122 } |
| 116 | 123 |
| 117 private: | 124 private: |
| 118 // Overridden from InputMethod: | 125 // Overridden from InputMethod: |
| 119 virtual void SetDelegate(internal::InputMethodDelegate* delegate) OVERRIDE { | 126 virtual void SetDelegate(internal::InputMethodDelegate* delegate) OVERRIDE { |
| 120 delegate_ = delegate; | 127 delegate_ = delegate; |
| 121 } | 128 } |
| 122 | 129 |
| 123 virtual void Init(bool focused) OVERRIDE {} | 130 virtual void Init(bool focused) OVERRIDE { |
| 131 if (focused) |
| 132 OnFocus(); |
| 133 } |
| 124 | 134 |
| 125 virtual void OnFocus() OVERRIDE {} | 135 virtual void OnFocus() OVERRIDE { |
| 136 FOR_EACH_OBSERVER(InputMethodObserver, |
| 137 observer_list_, |
| 138 OnFocus()); |
| 139 } |
| 126 | 140 |
| 127 virtual void OnBlur() OVERRIDE {} | 141 virtual void OnBlur() OVERRIDE { |
| 142 FOR_EACH_OBSERVER(InputMethodObserver, |
| 143 observer_list_, |
| 144 OnBlur()); |
| 145 } |
| 128 | 146 |
| 129 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, | 147 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 130 NativeEventResult* result) OVERRIDE { | 148 NativeEventResult* result) OVERRIDE { |
| 149 FOR_EACH_OBSERVER(InputMethodObserver, |
| 150 observer_list_, |
| 151 OnUntranslatedIMEMessage(event)); |
| 131 return false; | 152 return false; |
| 132 } | 153 } |
| 133 | 154 |
| 134 virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE { | 155 virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE { |
| 135 std::vector<int32> prev_input_scopes; | 156 std::vector<int32> prev_input_scopes; |
| 136 std::swap(input_scopes_, prev_input_scopes); | 157 std::swap(input_scopes_, prev_input_scopes); |
| 137 std::vector<gfx::Rect> prev_bounds; | 158 std::vector<gfx::Rect> prev_bounds; |
| 138 std::swap(composition_character_bounds_, prev_bounds); | 159 std::swap(composition_character_bounds_, prev_bounds); |
| 139 if (client) { | 160 if (client) { |
| 140 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), | 161 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), |
| 141 client->GetTextInputMode()); | 162 client->GetTextInputMode()); |
| 142 composition_character_bounds_ = GetCompositionCharacterBounds(client); | 163 composition_character_bounds_ = GetCompositionCharacterBounds(client); |
| 164 current_input_type_ = client->GetTextInputType(); |
| 165 current_input_mode_ = client->GetTextInputMode(); |
| 143 } | 166 } |
| 144 | 167 |
| 168 const bool text_input_client_changed = text_input_client_ != client; |
| 145 text_input_client_ = client; | 169 text_input_client_ = client; |
| 170 if (text_input_client_changed) { |
| 171 FOR_EACH_OBSERVER(InputMethodObserver, |
| 172 observer_list_, |
| 173 OnTextInputStateChanged(client)); |
| 174 } |
| 146 | 175 |
| 147 if (!remote_delegate_ || (prev_input_scopes == input_scopes_ && | 176 if (!remote_delegate_ || (prev_input_scopes == input_scopes_ && |
| 148 prev_bounds == composition_character_bounds_)) | 177 prev_bounds == composition_character_bounds_)) |
| 149 return; | 178 return; |
| 150 remote_delegate_->OnTextInputClientUpdated(input_scopes_, | 179 remote_delegate_->OnTextInputClientUpdated(input_scopes_, |
| 151 composition_character_bounds_); | 180 composition_character_bounds_); |
| 152 } | 181 } |
| 153 | 182 |
| 154 virtual void DetachTextInputClient(TextInputClient* client) OVERRIDE { | 183 virtual void DetachTextInputClient(TextInputClient* client) OVERRIDE { |
| 155 if (text_input_client_ != client) | 184 if (text_input_client_ != client) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 184 if (!delegate_) | 213 if (!delegate_) |
| 185 return false; | 214 return false; |
| 186 return delegate_->DispatchFabricatedKeyEventPostIME(event.type(), | 215 return delegate_->DispatchFabricatedKeyEventPostIME(event.type(), |
| 187 event.key_code(), | 216 event.key_code(), |
| 188 event.flags()); | 217 event.flags()); |
| 189 } | 218 } |
| 190 | 219 |
| 191 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { | 220 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { |
| 192 if (!text_input_client_ || text_input_client_ != client) | 221 if (!text_input_client_ || text_input_client_ != client) |
| 193 return; | 222 return; |
| 223 const ui::TextInputType prev_type = current_input_type_; |
| 224 const ui::TextInputMode prev_mode = current_input_mode_; |
| 225 current_input_type_ = client->GetTextInputType(); |
| 226 current_input_mode_ = client->GetTextInputMode(); |
| 227 |
| 194 std::vector<int32> prev_input_scopes; | 228 std::vector<int32> prev_input_scopes; |
| 195 std::swap(input_scopes_, prev_input_scopes); | 229 std::swap(input_scopes_, prev_input_scopes); |
| 196 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), | 230 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), |
| 197 client->GetTextInputMode()); | 231 client->GetTextInputMode()); |
| 198 if (input_scopes_ != prev_input_scopes && remote_delegate_) { | 232 if (input_scopes_ != prev_input_scopes && remote_delegate_) { |
| 199 remote_delegate_->OnTextInputClientUpdated( | 233 remote_delegate_->OnTextInputClientUpdated( |
| 200 input_scopes_, composition_character_bounds_); | 234 input_scopes_, composition_character_bounds_); |
| 201 } | 235 } |
| 236 if (current_input_type_ != prev_type || current_input_mode_ != prev_mode) { |
| 237 FOR_EACH_OBSERVER(InputMethodObserver, |
| 238 observer_list_, |
| 239 OnTextInputTypeChanged(client)); |
| 240 } |
| 202 } | 241 } |
| 203 | 242 |
| 204 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE { | 243 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE { |
| 205 if (!text_input_client_ || text_input_client_ != client) | 244 if (!text_input_client_ || text_input_client_ != client) |
| 206 return; | 245 return; |
| 207 std::vector<gfx::Rect> prev_rects; | 246 std::vector<gfx::Rect> prev_rects; |
| 208 std::swap(composition_character_bounds_, prev_rects); | 247 std::swap(composition_character_bounds_, prev_rects); |
| 209 composition_character_bounds_ = GetCompositionCharacterBounds(client); | 248 composition_character_bounds_ = GetCompositionCharacterBounds(client); |
| 210 if (composition_character_bounds_ != prev_rects && remote_delegate_) { | 249 if (composition_character_bounds_ != prev_rects && remote_delegate_) { |
| 211 remote_delegate_->OnTextInputClientUpdated( | 250 remote_delegate_->OnTextInputClientUpdated( |
| 212 input_scopes_, composition_character_bounds_); | 251 input_scopes_, composition_character_bounds_); |
| 213 } | 252 } |
| 253 FOR_EACH_OBSERVER(InputMethodObserver, |
| 254 observer_list_, |
| 255 OnCaretBoundsChanged(client)); |
| 214 } | 256 } |
| 215 | 257 |
| 216 virtual void CancelComposition(const TextInputClient* client) OVERRIDE { | 258 virtual void CancelComposition(const TextInputClient* client) OVERRIDE { |
| 217 if (CanSendRemoteNotification(client)) | 259 if (CanSendRemoteNotification(client)) |
| 218 remote_delegate_->CancelComposition(); | 260 remote_delegate_->CancelComposition(); |
| 219 } | 261 } |
| 220 | 262 |
| 221 virtual void OnInputLocaleChanged() OVERRIDE { | 263 virtual void OnInputLocaleChanged() OVERRIDE { |
| 222 // not supported. | 264 FOR_EACH_OBSERVER(InputMethodObserver, |
| 265 observer_list_, |
| 266 OnInputLocaleChanged()); |
| 223 } | 267 } |
| 224 | 268 |
| 225 virtual std::string GetInputLocale() OVERRIDE { | 269 virtual std::string GetInputLocale() OVERRIDE { |
| 226 const LCID locale_id = MAKELCID(langid_, SORT_DEFAULT); | 270 const LCID locale_id = MAKELCID(langid_, SORT_DEFAULT); |
| 227 std::string language = | 271 std::string language = |
| 228 GetLocaleString(locale_id, LOCALE_SISO639LANGNAME); | 272 GetLocaleString(locale_id, LOCALE_SISO639LANGNAME); |
| 229 if (SUBLANGID(langid_) == SUBLANG_NEUTRAL || language.empty()) | 273 if (SUBLANGID(langid_) == SUBLANG_NEUTRAL || language.empty()) |
| 230 return language; | 274 return language; |
| 231 const std::string& region = | 275 const std::string& region = |
| 232 GetLocaleString(locale_id, LOCALE_SISO3166CTRYNAME); | 276 GetLocaleString(locale_id, LOCALE_SISO3166CTRYNAME); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 309 |
| 266 virtual bool CanComposeInline() const OVERRIDE { | 310 virtual bool CanComposeInline() const OVERRIDE { |
| 267 return text_input_client_ ? text_input_client_->CanComposeInline() : true; | 311 return text_input_client_ ? text_input_client_->CanComposeInline() : true; |
| 268 } | 312 } |
| 269 | 313 |
| 270 virtual bool IsCandidatePopupOpen() const OVERRIDE { | 314 virtual bool IsCandidatePopupOpen() const OVERRIDE { |
| 271 return is_candidate_popup_open_; | 315 return is_candidate_popup_open_; |
| 272 } | 316 } |
| 273 | 317 |
| 274 virtual void AddObserver(InputMethodObserver* observer) OVERRIDE { | 318 virtual void AddObserver(InputMethodObserver* observer) OVERRIDE { |
| 275 // not supported. | 319 observer_list_.AddObserver(observer); |
| 276 NOTREACHED(); | |
| 277 } | 320 } |
| 278 | 321 |
| 279 virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE { | 322 virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE { |
| 280 // not supported. | 323 observer_list_.RemoveObserver(observer); |
| 281 NOTREACHED(); | |
| 282 } | 324 } |
| 283 | 325 |
| 284 // Overridden from RemoteInputMethodPrivateWin: | 326 // Overridden from RemoteInputMethodPrivateWin: |
| 285 virtual void SetRemoteDelegate( | 327 virtual void SetRemoteDelegate( |
| 286 internal::RemoteInputMethodDelegateWin* delegate) OVERRIDE{ | 328 internal::RemoteInputMethodDelegateWin* delegate) OVERRIDE{ |
| 287 remote_delegate_ = delegate; | 329 remote_delegate_ = delegate; |
| 288 | 330 |
| 289 // Sync initial state. | 331 // Sync initial state. |
| 290 if (remote_delegate_) { | 332 if (remote_delegate_) { |
| 291 remote_delegate_->OnTextInputClientUpdated( | 333 remote_delegate_->OnTextInputClientUpdated( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 305 GetTextInputClient()->OnInputMethodChanged(); | 347 GetTextInputClient()->OnInputMethodChanged(); |
| 306 } | 348 } |
| 307 | 349 |
| 308 bool CanSendRemoteNotification( | 350 bool CanSendRemoteNotification( |
| 309 const TextInputClient* text_input_client) const { | 351 const TextInputClient* text_input_client) const { |
| 310 return text_input_client_ && | 352 return text_input_client_ && |
| 311 text_input_client_ == text_input_client && | 353 text_input_client_ == text_input_client && |
| 312 remote_delegate_; | 354 remote_delegate_; |
| 313 } | 355 } |
| 314 | 356 |
| 357 ObserverList<InputMethodObserver> observer_list_; |
| 358 |
| 315 internal::InputMethodDelegate* delegate_; | 359 internal::InputMethodDelegate* delegate_; |
| 316 internal::RemoteInputMethodDelegateWin* remote_delegate_; | 360 internal::RemoteInputMethodDelegateWin* remote_delegate_; |
| 317 | 361 |
| 318 TextInputClient* text_input_client_; | 362 TextInputClient* text_input_client_; |
| 363 ui::TextInputType current_input_type_; |
| 364 ui::TextInputMode current_input_mode_; |
| 319 std::vector<int32> input_scopes_; | 365 std::vector<int32> input_scopes_; |
| 320 std::vector<gfx::Rect> composition_character_bounds_; | 366 std::vector<gfx::Rect> composition_character_bounds_; |
| 321 bool is_candidate_popup_open_; | 367 bool is_candidate_popup_open_; |
| 322 bool is_ime_; | 368 bool is_ime_; |
| 323 LANGID langid_; | 369 LANGID langid_; |
| 324 | 370 |
| 325 DISALLOW_COPY_AND_ASSIGN(RemoteInputMethodWin); | 371 DISALLOW_COPY_AND_ASSIGN(RemoteInputMethodWin); |
| 326 }; | 372 }; |
| 327 | 373 |
| 328 } // namespace | 374 } // namespace |
| 329 | 375 |
| 330 RemoteInputMethodPrivateWin::RemoteInputMethodPrivateWin() {} | 376 RemoteInputMethodPrivateWin::RemoteInputMethodPrivateWin() {} |
| 331 | 377 |
| 332 // static | |
| 333 scoped_ptr<InputMethod> CreateRemoteInputMethodWin( | 378 scoped_ptr<InputMethod> CreateRemoteInputMethodWin( |
| 334 internal::InputMethodDelegate* delegate) { | 379 internal::InputMethodDelegate* delegate) { |
| 335 return scoped_ptr<InputMethod>(new RemoteInputMethodWin(delegate)); | 380 return scoped_ptr<InputMethod>(new RemoteInputMethodWin(delegate)); |
| 336 } | 381 } |
| 337 | 382 |
| 338 // static | 383 // static |
| 339 RemoteInputMethodPrivateWin* RemoteInputMethodPrivateWin::Get( | 384 RemoteInputMethodPrivateWin* RemoteInputMethodPrivateWin::Get( |
| 340 InputMethod* input_method) { | 385 InputMethod* input_method) { |
| 341 return GetPrivate(input_method); | 386 return GetPrivate(input_method); |
| 342 } | 387 } |
| 343 | 388 |
| 344 } // namespace ui | 389 } // namespace ui |
| OLD | NEW |