| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return bounds; | 101 return bounds; |
| 102 } | 102 } |
| 103 | 103 |
| 104 class RemoteInputMethodWin : public InputMethod, | 104 class RemoteInputMethodWin : public InputMethod, |
| 105 public RemoteInputMethodPrivateWin { | 105 public RemoteInputMethodPrivateWin { |
| 106 public: | 106 public: |
| 107 explicit RemoteInputMethodWin(internal::InputMethodDelegate* delegate) | 107 explicit RemoteInputMethodWin(internal::InputMethodDelegate* delegate) |
| 108 : delegate_(delegate), | 108 : delegate_(delegate), |
| 109 remote_delegate_(NULL), | 109 remote_delegate_(NULL), |
| 110 text_input_client_(NULL), | 110 text_input_client_(NULL), |
| 111 current_input_type_(ui::TEXT_INPUT_TYPE_NONE), | |
| 112 current_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | |
| 113 is_candidate_popup_open_(false), | 111 is_candidate_popup_open_(false), |
| 114 is_ime_(false), | 112 is_ime_(false), |
| 115 langid_(kFallbackLangID) { | 113 langid_(kFallbackLangID) { |
| 116 RegisterInstance(this, this); | 114 RegisterInstance(this, this); |
| 117 } | 115 } |
| 118 | 116 |
| 119 virtual ~RemoteInputMethodWin() { | 117 virtual ~RemoteInputMethodWin() { |
| 120 FOR_EACH_OBSERVER(InputMethodObserver, | 118 FOR_EACH_OBSERVER(InputMethodObserver, |
| 121 observer_list_, | 119 observer_list_, |
| 122 OnInputMethodDestroyed(this)); | 120 OnInputMethodDestroyed(this)); |
| 123 UnregisterInstance(this); | 121 UnregisterInstance(this); |
| 124 } | 122 } |
| 125 | 123 |
| 126 private: | 124 private: |
| 127 // Overridden from InputMethod: | 125 // Overridden from InputMethod: |
| 128 virtual void SetDelegate(internal::InputMethodDelegate* delegate) OVERRIDE { | 126 virtual void SetDelegate(internal::InputMethodDelegate* delegate) OVERRIDE { |
| 129 delegate_ = delegate; | 127 delegate_ = delegate; |
| 130 } | 128 } |
| 131 | 129 |
| 132 virtual void Init(bool focused) OVERRIDE { | 130 virtual void Init(bool focused) OVERRIDE { |
| 133 if (focused) | |
| 134 OnFocus(); | |
| 135 } | 131 } |
| 136 | 132 |
| 137 virtual void OnFocus() OVERRIDE { | 133 virtual void OnFocus() OVERRIDE { |
| 138 FOR_EACH_OBSERVER(InputMethodObserver, | |
| 139 observer_list_, | |
| 140 OnFocus()); | |
| 141 } | 134 } |
| 142 | 135 |
| 143 virtual void OnBlur() OVERRIDE { | 136 virtual void OnBlur() OVERRIDE { |
| 144 FOR_EACH_OBSERVER(InputMethodObserver, | |
| 145 observer_list_, | |
| 146 OnBlur()); | |
| 147 } | 137 } |
| 148 | 138 |
| 149 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, | 139 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 150 NativeEventResult* result) OVERRIDE { | 140 NativeEventResult* result) OVERRIDE { |
| 151 return false; | 141 return false; |
| 152 } | 142 } |
| 153 | 143 |
| 154 virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE { | 144 virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE { |
| 155 std::vector<int32> prev_input_scopes; | 145 std::vector<int32> prev_input_scopes; |
| 156 std::swap(input_scopes_, prev_input_scopes); | 146 std::swap(input_scopes_, prev_input_scopes); |
| 157 std::vector<gfx::Rect> prev_bounds; | 147 std::vector<gfx::Rect> prev_bounds; |
| 158 std::swap(composition_character_bounds_, prev_bounds); | 148 std::swap(composition_character_bounds_, prev_bounds); |
| 159 if (client) { | 149 if (client) { |
| 160 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), | 150 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), |
| 161 client->GetTextInputMode()); | 151 client->GetTextInputMode()); |
| 162 composition_character_bounds_ = GetCompositionCharacterBounds(client); | 152 composition_character_bounds_ = GetCompositionCharacterBounds(client); |
| 163 current_input_type_ = client->GetTextInputType(); | |
| 164 current_input_mode_ = client->GetTextInputMode(); | |
| 165 } | 153 } |
| 166 | 154 |
| 167 const bool text_input_client_changed = text_input_client_ != client; | 155 const bool text_input_client_changed = text_input_client_ != client; |
| 168 text_input_client_ = client; | 156 text_input_client_ = client; |
| 169 if (text_input_client_changed) { | 157 if (text_input_client_changed) { |
| 170 FOR_EACH_OBSERVER(InputMethodObserver, | 158 FOR_EACH_OBSERVER(InputMethodObserver, |
| 171 observer_list_, | 159 observer_list_, |
| 172 OnTextInputStateChanged(client)); | 160 OnTextInputStateChanged(client)); |
| 173 } | 161 } |
| 174 | 162 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (!delegate_) | 200 if (!delegate_) |
| 213 return false; | 201 return false; |
| 214 return delegate_->DispatchFabricatedKeyEventPostIME(event.type(), | 202 return delegate_->DispatchFabricatedKeyEventPostIME(event.type(), |
| 215 event.key_code(), | 203 event.key_code(), |
| 216 event.flags()); | 204 event.flags()); |
| 217 } | 205 } |
| 218 | 206 |
| 219 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { | 207 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE { |
| 220 if (!text_input_client_ || text_input_client_ != client) | 208 if (!text_input_client_ || text_input_client_ != client) |
| 221 return; | 209 return; |
| 222 const ui::TextInputType prev_type = current_input_type_; | |
| 223 const ui::TextInputMode prev_mode = current_input_mode_; | |
| 224 current_input_type_ = client->GetTextInputType(); | |
| 225 current_input_mode_ = client->GetTextInputMode(); | |
| 226 | |
| 227 std::vector<int32> prev_input_scopes; | 210 std::vector<int32> prev_input_scopes; |
| 228 std::swap(input_scopes_, prev_input_scopes); | 211 std::swap(input_scopes_, prev_input_scopes); |
| 229 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), | 212 input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), |
| 230 client->GetTextInputMode()); | 213 client->GetTextInputMode()); |
| 231 if (input_scopes_ != prev_input_scopes && remote_delegate_) { | 214 if (input_scopes_ != prev_input_scopes && remote_delegate_) { |
| 232 remote_delegate_->OnTextInputClientUpdated( | 215 remote_delegate_->OnTextInputClientUpdated( |
| 233 input_scopes_, composition_character_bounds_); | 216 input_scopes_, composition_character_bounds_); |
| 234 } | 217 } |
| 235 if (current_input_type_ != prev_type || current_input_mode_ != prev_mode) { | |
| 236 FOR_EACH_OBSERVER(InputMethodObserver, | |
| 237 observer_list_, | |
| 238 OnTextInputTypeChanged(client)); | |
| 239 } | |
| 240 } | 218 } |
| 241 | 219 |
| 242 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE { | 220 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE { |
| 243 if (!text_input_client_ || text_input_client_ != client) | 221 if (!text_input_client_ || text_input_client_ != client) |
| 244 return; | 222 return; |
| 245 std::vector<gfx::Rect> prev_rects; | 223 std::vector<gfx::Rect> prev_rects; |
| 246 std::swap(composition_character_bounds_, prev_rects); | 224 std::swap(composition_character_bounds_, prev_rects); |
| 247 composition_character_bounds_ = GetCompositionCharacterBounds(client); | 225 composition_character_bounds_ = GetCompositionCharacterBounds(client); |
| 248 if (composition_character_bounds_ != prev_rects && remote_delegate_) { | 226 if (composition_character_bounds_ != prev_rects && remote_delegate_) { |
| 249 remote_delegate_->OnTextInputClientUpdated( | 227 remote_delegate_->OnTextInputClientUpdated( |
| 250 input_scopes_, composition_character_bounds_); | 228 input_scopes_, composition_character_bounds_); |
| 251 } | 229 } |
| 252 FOR_EACH_OBSERVER(InputMethodObserver, | |
| 253 observer_list_, | |
| 254 OnCaretBoundsChanged(client)); | |
| 255 } | 230 } |
| 256 | 231 |
| 257 virtual void CancelComposition(const TextInputClient* client) OVERRIDE { | 232 virtual void CancelComposition(const TextInputClient* client) OVERRIDE { |
| 258 if (CanSendRemoteNotification(client)) | 233 if (CanSendRemoteNotification(client)) |
| 259 remote_delegate_->CancelComposition(); | 234 remote_delegate_->CancelComposition(); |
| 260 } | 235 } |
| 261 | 236 |
| 262 virtual void OnInputLocaleChanged() OVERRIDE { | 237 virtual void OnInputLocaleChanged() OVERRIDE { |
| 263 } | 238 } |
| 264 | 239 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 text_input_client_ == text_input_client && | 324 text_input_client_ == text_input_client && |
| 350 remote_delegate_; | 325 remote_delegate_; |
| 351 } | 326 } |
| 352 | 327 |
| 353 ObserverList<InputMethodObserver> observer_list_; | 328 ObserverList<InputMethodObserver> observer_list_; |
| 354 | 329 |
| 355 internal::InputMethodDelegate* delegate_; | 330 internal::InputMethodDelegate* delegate_; |
| 356 internal::RemoteInputMethodDelegateWin* remote_delegate_; | 331 internal::RemoteInputMethodDelegateWin* remote_delegate_; |
| 357 | 332 |
| 358 TextInputClient* text_input_client_; | 333 TextInputClient* text_input_client_; |
| 359 ui::TextInputType current_input_type_; | |
| 360 ui::TextInputMode current_input_mode_; | |
| 361 std::vector<int32> input_scopes_; | 334 std::vector<int32> input_scopes_; |
| 362 std::vector<gfx::Rect> composition_character_bounds_; | 335 std::vector<gfx::Rect> composition_character_bounds_; |
| 363 bool is_candidate_popup_open_; | 336 bool is_candidate_popup_open_; |
| 364 bool is_ime_; | 337 bool is_ime_; |
| 365 LANGID langid_; | 338 LANGID langid_; |
| 366 | 339 |
| 367 DISALLOW_COPY_AND_ASSIGN(RemoteInputMethodWin); | 340 DISALLOW_COPY_AND_ASSIGN(RemoteInputMethodWin); |
| 368 }; | 341 }; |
| 369 | 342 |
| 370 } // namespace | 343 } // namespace |
| (...skipping 16 matching lines...) Expand all Loading... |
| 387 return scoped_ptr<InputMethod>(new RemoteInputMethodWin(delegate)); | 360 return scoped_ptr<InputMethod>(new RemoteInputMethodWin(delegate)); |
| 388 } | 361 } |
| 389 | 362 |
| 390 // static | 363 // static |
| 391 RemoteInputMethodPrivateWin* RemoteInputMethodPrivateWin::Get( | 364 RemoteInputMethodPrivateWin* RemoteInputMethodPrivateWin::Get( |
| 392 InputMethod* input_method) { | 365 InputMethod* input_method) { |
| 393 return GetPrivate(input_method); | 366 return GetPrivate(input_method); |
| 394 } | 367 } |
| 395 | 368 |
| 396 } // namespace ui | 369 } // namespace ui |
| OLD | NEW |