| 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; | |
| 36 using base::android::JavaParamRef; | 35 using base::android::JavaParamRef; |
| 37 using base::android::ScopedJavaLocalRef; | 36 using base::android::ScopedJavaLocalRef; |
| 38 | 37 |
| 39 namespace content { | 38 namespace content { |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 // Maps a java KeyEvent into a NativeWebKeyboardEvent. | 41 // Maps a java KeyEvent into a NativeWebKeyboardEvent. |
| 43 // |java_key_event| is used to maintain a globalref for KeyEvent. | 42 // |java_key_event| is used to maintain a globalref for KeyEvent. |
| 44 // |type| will determine the WebInputEvent type. | 43 // |type| will determine the WebInputEvent type. |
| 45 // type, |modifiers|, |time_ms|, |key_code|, |unicode_char| is used to create | 44 // 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... |
| 181 if (rwhva_) | 180 if (rwhva_) |
| 182 rwhva_->set_ime_adapter(nullptr); | 181 rwhva_->set_ime_adapter(nullptr); |
| 183 if (new_rwhva) { | 182 if (new_rwhva) { |
| 184 new_rwhva->set_ime_adapter(this); | 183 new_rwhva->set_ime_adapter(this); |
| 185 rwhva_ = new_rwhva->GetWeakPtrAndroid(); | 184 rwhva_ = new_rwhva->GetWeakPtrAndroid(); |
| 186 } else { | 185 } else { |
| 187 rwhva_.reset(); | 186 rwhva_.reset(); |
| 188 } | 187 } |
| 189 } | 188 } |
| 190 | 189 |
| 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 | |
| 206 bool ImeAdapterAndroid::SendKeyEvent( | 190 bool ImeAdapterAndroid::SendKeyEvent( |
| 207 JNIEnv* env, | 191 JNIEnv* env, |
| 208 const JavaParamRef<jobject>&, | 192 const JavaParamRef<jobject>&, |
| 209 const JavaParamRef<jobject>& original_key_event, | 193 const JavaParamRef<jobject>& original_key_event, |
| 210 int type, | 194 int type, |
| 211 int modifiers, | 195 int modifiers, |
| 212 jlong time_ms, | 196 jlong time_ms, |
| 213 int key_code, | 197 int key_code, |
| 214 int scan_code, | 198 int scan_code, |
| 215 bool is_system_key, | 199 bool is_system_key, |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 Java_ImeAdapter_populateUnderlinesFromSpans( | 418 Java_ImeAdapter_populateUnderlinesFromSpans( |
| 435 env, obj, text, reinterpret_cast<jlong>(&underlines)); | 419 env, obj, text, reinterpret_cast<jlong>(&underlines)); |
| 436 | 420 |
| 437 // Sort spans by |.startOffset|. | 421 // Sort spans by |.startOffset|. |
| 438 std::sort(underlines.begin(), underlines.end()); | 422 std::sort(underlines.begin(), underlines.end()); |
| 439 | 423 |
| 440 return underlines; | 424 return underlines; |
| 441 } | 425 } |
| 442 | 426 |
| 443 } // namespace content | 427 } // namespace content |
| OLD | NEW |