OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "content/browser/android/ime_adapter_android.h" | 5 #include "content/browser/android/ime_adapter_android.h" |
6 | 6 |
7 #include <android/input.h> | 7 #include <android/input.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/native_web_keyboard_event.h" | 26 #include "content/public/browser/native_web_keyboard_event.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "jni/ImeAdapter_jni.h" | 28 #include "jni/ImeAdapter_jni.h" |
29 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 29 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
30 #include "third_party/WebKit/public/platform/WebTextInputType.h" | 30 #include "third_party/WebKit/public/platform/WebTextInputType.h" |
31 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 31 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
32 | 32 |
33 using base::android::AttachCurrentThread; | 33 using base::android::AttachCurrentThread; |
34 using base::android::ConvertJavaStringToUTF16; | 34 using base::android::ConvertJavaStringToUTF16; |
| 35 using base::android::ConvertUTF8ToJavaString; |
35 using base::android::JavaParamRef; | 36 using base::android::JavaParamRef; |
36 using base::android::ScopedJavaLocalRef; | 37 using base::android::ScopedJavaLocalRef; |
37 | 38 |
38 namespace content { | 39 namespace content { |
39 namespace { | 40 namespace { |
40 | 41 |
41 // Maps a java KeyEvent into a NativeWebKeyboardEvent. | 42 // Maps a java KeyEvent into a NativeWebKeyboardEvent. |
42 // |java_key_event| is used to maintain a globalref for KeyEvent. | 43 // |java_key_event| is used to maintain a globalref for KeyEvent. |
43 // |type| will determine the WebInputEvent type. | 44 // |type| will determine the WebInputEvent type. |
44 // type, |modifiers|, |time_ms|, |key_code|, |unicode_char| is used to create | 45 // type, |modifiers|, |time_ms|, |key_code|, |unicode_char| is used to create |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (rwhva_) | 181 if (rwhva_) |
181 rwhva_->set_ime_adapter(nullptr); | 182 rwhva_->set_ime_adapter(nullptr); |
182 if (new_rwhva) { | 183 if (new_rwhva) { |
183 new_rwhva->set_ime_adapter(this); | 184 new_rwhva->set_ime_adapter(this); |
184 rwhva_ = new_rwhva->GetWeakPtrAndroid(); | 185 rwhva_ = new_rwhva->GetWeakPtrAndroid(); |
185 } else { | 186 } else { |
186 rwhva_.reset(); | 187 rwhva_.reset(); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
| 191 void ImeAdapterAndroid::UpdateState(const TextInputState& state) { |
| 192 JNIEnv* env = AttachCurrentThread(); |
| 193 ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
| 194 if (obj.is_null()) |
| 195 return; |
| 196 |
| 197 ScopedJavaLocalRef<jstring> jstring_text = |
| 198 ConvertUTF8ToJavaString(env, state.value); |
| 199 Java_ImeAdapter_updateState(env, obj, static_cast<int>(state.type), |
| 200 state.flags, state.mode, state.show_ime_if_needed, |
| 201 jstring_text, state.selection_start, |
| 202 state.selection_end, state.composition_start, |
| 203 state.composition_end, state.reply_to_request); |
| 204 } |
| 205 |
190 bool ImeAdapterAndroid::SendKeyEvent( | 206 bool ImeAdapterAndroid::SendKeyEvent( |
191 JNIEnv* env, | 207 JNIEnv* env, |
192 const JavaParamRef<jobject>&, | 208 const JavaParamRef<jobject>&, |
193 const JavaParamRef<jobject>& original_key_event, | 209 const JavaParamRef<jobject>& original_key_event, |
194 int type, | 210 int type, |
195 int modifiers, | 211 int modifiers, |
196 jlong time_ms, | 212 jlong time_ms, |
197 int key_code, | 213 int key_code, |
198 int scan_code, | 214 int scan_code, |
199 bool is_system_key, | 215 bool is_system_key, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 Java_ImeAdapter_populateUnderlinesFromSpans( | 434 Java_ImeAdapter_populateUnderlinesFromSpans( |
419 env, obj, text, reinterpret_cast<jlong>(&underlines)); | 435 env, obj, text, reinterpret_cast<jlong>(&underlines)); |
420 | 436 |
421 // Sort spans by |.startOffset|. | 437 // Sort spans by |.startOffset|. |
422 std::sort(underlines.begin(), underlines.end()); | 438 std::sort(underlines.begin(), underlines.end()); |
423 | 439 |
424 return underlines; | 440 return underlines; |
425 } | 441 } |
426 | 442 |
427 } // namespace content | 443 } // namespace content |
OLD | NEW |