| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/ime_adapter_android.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 7 #include <android/input.h> | 8 #include <android/input.h> |
| 8 #include <algorithm> | |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/android/jni_array.h" | 12 #include "base/android/jni_array.h" |
| 13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
| 14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "content/browser/frame_host/interstitial_page_impl.h" | |
| 18 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 19 #include "content/browser/renderer_host/render_view_host_delegate.h" | 18 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 20 #include "content/browser/renderer_host/render_widget_host_impl.h" | 19 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 21 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 20 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 22 #include "content/browser/web_contents/web_contents_impl.h" | |
| 23 #include "content/common/input_messages.h" | 21 #include "content/common/input_messages.h" |
| 24 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 25 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/native_web_keyboard_event.h" | 24 #include "content/public/browser/native_web_keyboard_event.h" |
| 27 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 28 #include "jni/ImeAdapter_jni.h" | 26 #include "jni/ImeAdapter_jni.h" |
| 29 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 27 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 30 #include "third_party/WebKit/public/platform/WebTextInputType.h" | 28 #include "third_party/WebKit/public/platform/WebTextInputType.h" |
| 31 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 29 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| 32 | 30 |
| 33 using base::android::AttachCurrentThread; | 31 using base::android::AttachCurrentThread; |
| 34 using base::android::ConvertJavaStringToUTF16; | 32 using base::android::ConvertJavaStringToUTF16; |
| 35 using base::android::ConvertUTF8ToJavaString; | |
| 36 using base::android::JavaParamRef; | 33 using base::android::JavaParamRef; |
| 37 using base::android::ScopedJavaLocalRef; | |
| 38 | 34 |
| 39 namespace content { | 35 namespace content { |
| 40 namespace { | 36 namespace { |
| 41 | 37 |
| 42 // Maps a java KeyEvent into a NativeWebKeyboardEvent. | 38 // Maps a java KeyEvent into a NativeWebKeyboardEvent. |
| 43 // |java_key_event| is used to maintain a globalref for KeyEvent. | 39 // |java_key_event| is used to maintain a globalref for KeyEvent. |
| 44 // |type| will determine the WebInputEvent type. | 40 // |type| will determine the WebInputEvent type. |
| 45 // type, |modifiers|, |time_ms|, |key_code|, |unicode_char| is used to create | 41 // type, |modifiers|, |time_ms|, |key_code|, |unicode_char| is used to create |
| 46 // WebKeyboardEvent. |key_code| is also needed ad need to treat the enter key | 42 // WebKeyboardEvent. |key_code| is also needed ad need to treat the enter key |
| 47 // as a key press of character \r. | 43 // as a key press of character \r. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 modifiers, time_ms / 1000.0, key_code, | 56 modifiers, time_ms / 1000.0, key_code, |
| 61 scan_code, unicode_char, is_system_key); | 57 scan_code, unicode_char, is_system_key); |
| 62 } | 58 } |
| 63 | 59 |
| 64 } // anonymous namespace | 60 } // anonymous namespace |
| 65 | 61 |
| 66 bool RegisterImeAdapter(JNIEnv* env) { | 62 bool RegisterImeAdapter(JNIEnv* env) { |
| 67 return RegisterNativesImpl(env); | 63 return RegisterNativesImpl(env); |
| 68 } | 64 } |
| 69 | 65 |
| 70 jlong Init(JNIEnv* env, | |
| 71 const JavaParamRef<jobject>& obj, | |
| 72 const JavaParamRef<jobject>& jweb_contents) { | |
| 73 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | |
| 74 DCHECK(web_contents); | |
| 75 return reinterpret_cast<intptr_t>( | |
| 76 new ImeAdapterAndroid(env, obj, web_contents)); | |
| 77 } | |
| 78 | |
| 79 // Callback from Java to convert BackgroundColorSpan data to a | 66 // Callback from Java to convert BackgroundColorSpan data to a |
| 80 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. | 67 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
| 81 void AppendBackgroundColorSpan(JNIEnv*, | 68 void AppendBackgroundColorSpan(JNIEnv*, |
| 82 const JavaParamRef<jclass>&, | 69 const JavaParamRef<jclass>&, |
| 83 jlong underlines_ptr, | 70 jlong underlines_ptr, |
| 84 jint start, | 71 jint start, |
| 85 jint end, | 72 jint end, |
| 86 jint background_color) { | 73 jint background_color) { |
| 87 DCHECK_GE(start, 0); | 74 DCHECK_GE(start, 0); |
| 88 DCHECK_GE(end, 0); | 75 DCHECK_GE(end, 0); |
| 89 // Do not check |background_color|. | 76 // Do not check |background_color|. |
| 90 std::vector<blink::WebCompositionUnderline>* underlines = | 77 std::vector<blink::WebCompositionUnderline>* underlines = |
| 91 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( | 78 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
| 92 underlines_ptr); | 79 underlines_ptr); |
| 93 underlines->push_back(blink::WebCompositionUnderline( | 80 underlines->push_back( |
| 94 static_cast<unsigned>(start), static_cast<unsigned>(end), | 81 blink::WebCompositionUnderline(static_cast<unsigned>(start), |
| 95 SK_ColorTRANSPARENT, false, static_cast<unsigned>(background_color))); | 82 static_cast<unsigned>(end), |
| 83 SK_ColorTRANSPARENT, |
| 84 false, |
| 85 static_cast<unsigned>(background_color))); |
| 96 } | 86 } |
| 97 | 87 |
| 98 // Callback from Java to convert UnderlineSpan data to a | 88 // Callback from Java to convert UnderlineSpan data to a |
| 99 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. | 89 // blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
| 100 void AppendUnderlineSpan(JNIEnv*, | 90 void AppendUnderlineSpan(JNIEnv*, |
| 101 const JavaParamRef<jclass>&, | 91 const JavaParamRef<jclass>&, |
| 102 jlong underlines_ptr, | 92 jlong underlines_ptr, |
| 103 jint start, | 93 jint start, |
| 104 jint end) { | 94 jint end) { |
| 105 DCHECK_GE(start, 0); | 95 DCHECK_GE(start, 0); |
| 106 DCHECK_GE(end, 0); | 96 DCHECK_GE(end, 0); |
| 107 std::vector<blink::WebCompositionUnderline>* underlines = | 97 std::vector<blink::WebCompositionUnderline>* underlines = |
| 108 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( | 98 reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
| 109 underlines_ptr); | 99 underlines_ptr); |
| 110 underlines->push_back(blink::WebCompositionUnderline( | 100 underlines->push_back( |
| 111 static_cast<unsigned>(start), static_cast<unsigned>(end), SK_ColorBLACK, | 101 blink::WebCompositionUnderline(static_cast<unsigned>(start), |
| 112 false, SK_ColorTRANSPARENT)); | 102 static_cast<unsigned>(end), |
| 103 SK_ColorBLACK, |
| 104 false, |
| 105 SK_ColorTRANSPARENT)); |
| 113 } | 106 } |
| 114 | 107 |
| 115 ImeAdapterAndroid::ImeAdapterAndroid(JNIEnv* env, | 108 ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) |
| 116 const JavaParamRef<jobject>& obj, | 109 : rwhva_(rwhva) { |
| 117 WebContents* web_contents) | 110 DCHECK(rwhva_); |
| 118 : WebContentsObserver(web_contents), rwhva_(nullptr) { | |
| 119 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, obj); | |
| 120 } | 111 } |
| 121 | 112 |
| 122 ImeAdapterAndroid::~ImeAdapterAndroid() { | 113 ImeAdapterAndroid::~ImeAdapterAndroid() { |
| 123 JNIEnv* env = AttachCurrentThread(); | 114 JNIEnv* env = AttachCurrentThread(); |
| 124 ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | 115 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
| 125 if (!obj.is_null()) | 116 if (!obj.is_null()) |
| 126 Java_ImeAdapter_destroy(env, obj); | 117 Java_ImeAdapter_detach(env, obj); |
| 127 | |
| 128 UpdateRenderProcessConnection(nullptr); | |
| 129 } | |
| 130 | |
| 131 RenderWidgetHostViewAndroid* ImeAdapterAndroid::GetRenderWidgetHostViewAndroid() | |
| 132 const { | |
| 133 RenderWidgetHostView* rwhv = web_contents()->GetRenderWidgetHostView(); | |
| 134 WebContentsImpl* web_contents_impl = | |
| 135 static_cast<WebContentsImpl*>(web_contents()); | |
| 136 if (web_contents_impl->ShowingInterstitialPage()) { | |
| 137 rwhv = web_contents_impl->GetInterstitialPage() | |
| 138 ->GetMainFrame() | |
| 139 ->GetRenderViewHost() | |
| 140 ->GetWidget() | |
| 141 ->GetView(); | |
| 142 } | |
| 143 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | |
| 144 } | |
| 145 | |
| 146 void ImeAdapterAndroid::RenderViewReady() { | |
| 147 UpdateRenderProcessConnection(GetRenderWidgetHostViewAndroid()); | |
| 148 | |
| 149 JNIEnv* env = AttachCurrentThread(); | |
| 150 ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | |
| 151 if (!obj.is_null()) | |
| 152 Java_ImeAdapter_onConnectedToRenderProcess(env, obj); | |
| 153 } | |
| 154 | |
| 155 void ImeAdapterAndroid::RenderViewHostChanged(RenderViewHost* old_host, | |
| 156 RenderViewHost* new_host) { | |
| 157 if (new_host) { | |
| 158 UpdateRenderProcessConnection(static_cast<RenderWidgetHostViewAndroid*>( | |
| 159 new_host->GetWidget()->GetView())); | |
| 160 } else { | |
| 161 UpdateRenderProcessConnection(nullptr); | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 void ImeAdapterAndroid::DidAttachInterstitialPage() { | |
| 166 UpdateRenderProcessConnection(GetRenderWidgetHostViewAndroid()); | |
| 167 } | |
| 168 | |
| 169 void ImeAdapterAndroid::DidDetachInterstitialPage() { | |
| 170 UpdateRenderProcessConnection(GetRenderWidgetHostViewAndroid()); | |
| 171 } | |
| 172 | |
| 173 void ImeAdapterAndroid::WebContentsDestroyed() { | |
| 174 delete this; | |
| 175 } | |
| 176 | |
| 177 void ImeAdapterAndroid::UpdateRenderProcessConnection( | |
| 178 RenderWidgetHostViewAndroid* new_rwhva) { | |
| 179 if (rwhva_.get() == new_rwhva) | |
| 180 return; | |
| 181 if (rwhva_) | |
| 182 rwhva_->set_ime_adapter(nullptr); | |
| 183 if (new_rwhva) { | |
| 184 new_rwhva->set_ime_adapter(this); | |
| 185 rwhva_ = new_rwhva->GetWeakPtrAndroid(); | |
| 186 } else { | |
| 187 rwhva_.reset(); | |
| 188 } | |
| 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 } | 118 } |
| 205 | 119 |
| 206 bool ImeAdapterAndroid::SendKeyEvent( | 120 bool ImeAdapterAndroid::SendKeyEvent( |
| 207 JNIEnv* env, | 121 JNIEnv* env, |
| 208 const JavaParamRef<jobject>&, | 122 const JavaParamRef<jobject>&, |
| 209 const JavaParamRef<jobject>& original_key_event, | 123 const JavaParamRef<jobject>& original_key_event, |
| 210 int type, | 124 int type, |
| 211 int modifiers, | 125 int modifiers, |
| 212 jlong time_ms, | 126 jlong time_ms, |
| 213 int key_code, | 127 int key_code, |
| 214 int scan_code, | 128 int scan_code, |
| 215 bool is_system_key, | 129 bool is_system_key, |
| 216 int unicode_char) { | 130 int unicode_char) { |
| 217 if (!rwhva_) | |
| 218 return false; | |
| 219 NativeWebKeyboardEvent event = NativeWebKeyboardEventFromKeyEvent( | 131 NativeWebKeyboardEvent event = NativeWebKeyboardEventFromKeyEvent( |
| 220 env, original_key_event, type, modifiers, time_ms, key_code, scan_code, | 132 env, original_key_event, type, modifiers, time_ms, key_code, scan_code, |
| 221 is_system_key, unicode_char); | 133 is_system_key, unicode_char); |
| 222 rwhva_->SendKeyEvent(event); | 134 rwhva_->SendKeyEvent(event); |
| 223 return true; | 135 return true; |
| 224 } | 136 } |
| 225 | 137 |
| 226 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, | 138 void ImeAdapterAndroid::SetComposingText(JNIEnv* env, |
| 227 const JavaParamRef<jobject>& obj, | 139 const JavaParamRef<jobject>& obj, |
| 228 const JavaParamRef<jobject>& text, | 140 const JavaParamRef<jobject>& text, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 193 |
| 282 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, | 194 void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, |
| 283 const JavaParamRef<jobject>&) { | 195 const JavaParamRef<jobject>&) { |
| 284 RenderWidgetHostImpl* rwhi = GetFocusedWidget(); | 196 RenderWidgetHostImpl* rwhi = GetFocusedWidget(); |
| 285 if (!rwhi) | 197 if (!rwhi) |
| 286 return; | 198 return; |
| 287 | 199 |
| 288 rwhi->ImeFinishComposingText(true); | 200 rwhi->ImeFinishComposingText(true); |
| 289 } | 201 } |
| 290 | 202 |
| 203 void ImeAdapterAndroid::AttachImeAdapter( |
| 204 JNIEnv* env, |
| 205 const JavaParamRef<jobject>& java_object) { |
| 206 java_ime_adapter_ = JavaObjectWeakGlobalRef(env, java_object); |
| 207 } |
| 208 |
| 291 void ImeAdapterAndroid::CancelComposition() { | 209 void ImeAdapterAndroid::CancelComposition() { |
| 292 JNIEnv* env = AttachCurrentThread(); | 210 base::android::ScopedJavaLocalRef<jobject> obj = |
| 293 ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | 211 java_ime_adapter_.get(AttachCurrentThread()); |
| 294 if (!obj.is_null()) | 212 if (!obj.is_null()) |
| 295 Java_ImeAdapter_cancelComposition(env, obj); | 213 Java_ImeAdapter_cancelComposition(AttachCurrentThread(), obj); |
| 296 } | 214 } |
| 297 | 215 |
| 298 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { | 216 void ImeAdapterAndroid::FocusedNodeChanged(bool is_editable_node) { |
| 299 JNIEnv* env = AttachCurrentThread(); | 217 base::android::ScopedJavaLocalRef<jobject> obj = |
| 300 ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | 218 java_ime_adapter_.get(AttachCurrentThread()); |
| 301 if (!obj.is_null()) { | 219 if (!obj.is_null()) { |
| 302 Java_ImeAdapter_focusedNodeChanged(env, obj, is_editable_node); | 220 Java_ImeAdapter_focusedNodeChanged(AttachCurrentThread(), obj, |
| 221 is_editable_node); |
| 303 } | 222 } |
| 304 } | 223 } |
| 305 | 224 |
| 306 void ImeAdapterAndroid::SetEditableSelectionOffsets( | 225 void ImeAdapterAndroid::SetEditableSelectionOffsets( |
| 307 JNIEnv*, | 226 JNIEnv*, |
| 308 const JavaParamRef<jobject>&, | 227 const JavaParamRef<jobject>&, |
| 309 int start, | 228 int start, |
| 310 int end) { | 229 int end) { |
| 311 RenderFrameHost* rfh = GetFocusedFrame(); | 230 RenderFrameHost* rfh = GetFocusedFrame(); |
| 312 if (!rfh) | 231 if (!rfh) |
| 313 return; | 232 return; |
| 314 | 233 |
| 315 rfh->Send(new InputMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), start, | 234 rfh->Send(new InputMsg_SetEditableSelectionOffsets(rfh->GetRoutingID(), start, |
| 316 end)); | 235 end)); |
| 317 } | 236 } |
| 318 | 237 |
| 319 void ImeAdapterAndroid::SetCharacterBounds( | 238 void ImeAdapterAndroid::SetCharacterBounds( |
| 320 const std::vector<gfx::RectF>& character_bounds) { | 239 const std::vector<gfx::RectF>& character_bounds) { |
| 321 JNIEnv* env = AttachCurrentThread(); | 240 JNIEnv* env = AttachCurrentThread(); |
| 322 ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); | 241 base::android::ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
| 323 if (obj.is_null()) | 242 if (obj.is_null()) |
| 324 return; | 243 return; |
| 325 | 244 |
| 326 const size_t coordinates_array_size = character_bounds.size() * 4; | 245 const size_t coordinates_array_size = character_bounds.size() * 4; |
| 327 std::unique_ptr<float[]> coordinates_array(new float[coordinates_array_size]); | 246 std::unique_ptr<float[]> coordinates_array(new float[coordinates_array_size]); |
| 328 for (size_t i = 0; i < character_bounds.size(); ++i) { | 247 for (size_t i = 0; i < character_bounds.size(); ++i) { |
| 329 const gfx::RectF& rect = character_bounds[i]; | 248 const gfx::RectF& rect = character_bounds[i]; |
| 330 const size_t coordinates_array_index = i * 4; | 249 const size_t coordinates_array_index = i * 4; |
| 331 coordinates_array[coordinates_array_index + 0] = rect.x(); | 250 coordinates_array[coordinates_array_index + 0] = rect.x(); |
| 332 coordinates_array[coordinates_array_index + 1] = rect.y(); | 251 coordinates_array[coordinates_array_index + 1] = rect.y(); |
| 333 coordinates_array[coordinates_array_index + 2] = rect.right(); | 252 coordinates_array[coordinates_array_index + 2] = rect.right(); |
| 334 coordinates_array[coordinates_array_index + 3] = rect.bottom(); | 253 coordinates_array[coordinates_array_index + 3] = rect.bottom(); |
| 335 } | 254 } |
| 336 Java_ImeAdapter_setCharacterBounds( | 255 Java_ImeAdapter_setCharacterBounds( |
| 337 env, obj, | 256 env, obj, base::android::ToJavaFloatArray(env, coordinates_array.get(), |
| 338 base::android::ToJavaFloatArray(env, coordinates_array.get(), | 257 coordinates_array_size)); |
| 339 coordinates_array_size)); | |
| 340 } | 258 } |
| 341 | 259 |
| 342 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, | 260 void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, |
| 343 const JavaParamRef<jobject>&, | 261 const JavaParamRef<jobject>&, |
| 344 int start, | 262 int start, |
| 345 int end) { | 263 int end) { |
| 346 RenderFrameHost* rfh = GetFocusedFrame(); | 264 RenderFrameHost* rfh = GetFocusedFrame(); |
| 347 if (!rfh) | 265 if (!rfh) |
| 348 return; | 266 return; |
| 349 | 267 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 const base::android::JavaParamRef<jobject>& obj, | 309 const base::android::JavaParamRef<jobject>& obj, |
| 392 bool immediate_request, | 310 bool immediate_request, |
| 393 bool monitor_request) { | 311 bool monitor_request) { |
| 394 RenderWidgetHostImpl* rwhi = GetFocusedWidget(); | 312 RenderWidgetHostImpl* rwhi = GetFocusedWidget(); |
| 395 if (!rwhi) | 313 if (!rwhi) |
| 396 return; | 314 return; |
| 397 rwhi->Send(new InputMsg_RequestCompositionUpdates( | 315 rwhi->Send(new InputMsg_RequestCompositionUpdates( |
| 398 rwhi->GetRoutingID(), immediate_request, monitor_request)); | 316 rwhi->GetRoutingID(), immediate_request, monitor_request)); |
| 399 } | 317 } |
| 400 | 318 |
| 319 void ImeAdapterAndroid::ResetImeAdapter(JNIEnv* env, |
| 320 const JavaParamRef<jobject>&) { |
| 321 java_ime_adapter_.reset(); |
| 322 } |
| 323 |
| 401 RenderWidgetHostImpl* ImeAdapterAndroid::GetFocusedWidget() { | 324 RenderWidgetHostImpl* ImeAdapterAndroid::GetFocusedWidget() { |
| 402 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 325 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 403 return rwhva_ ? rwhva_->GetFocusedWidget() : nullptr; | 326 return rwhva_->GetFocusedWidget(); |
| 404 } | 327 } |
| 405 | 328 |
| 406 RenderFrameHost* ImeAdapterAndroid::GetFocusedFrame() { | 329 RenderFrameHost* ImeAdapterAndroid::GetFocusedFrame() { |
| 407 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 330 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 408 // We get the focused frame from the WebContents of the page. Although | 331 // We get the focused frame from the WebContents of the page. Although |
| 409 // |rwhva_->GetFocusedWidget()| does a similar thing, there is no direct way | 332 // |rwhva_->GetFocusedWidget()| does a similar thing, there is no direct way |
| 410 // to get a RenderFrameHost from its RWH. | 333 // to get a RenderFrameHost from its RWH. |
| 411 if (!rwhva_) | |
| 412 return nullptr; | |
| 413 RenderWidgetHostImpl* rwh = | 334 RenderWidgetHostImpl* rwh = |
| 414 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); | 335 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); |
| 415 if (!rwh || !rwh->delegate()) | 336 if (!rwh || !rwh->delegate()) |
| 416 return nullptr; | 337 return nullptr; |
| 417 | 338 |
| 418 if (auto* contents = rwh->delegate()->GetAsWebContents()) | 339 if (auto* contents = rwh->delegate()->GetAsWebContents()) |
| 419 return contents->GetFocusedFrame(); | 340 return contents->GetFocusedFrame(); |
| 420 | 341 |
| 421 return nullptr; | 342 return nullptr; |
| 422 } | 343 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 434 Java_ImeAdapter_populateUnderlinesFromSpans( | 355 Java_ImeAdapter_populateUnderlinesFromSpans( |
| 435 env, obj, text, reinterpret_cast<jlong>(&underlines)); | 356 env, obj, text, reinterpret_cast<jlong>(&underlines)); |
| 436 | 357 |
| 437 // Sort spans by |.startOffset|. | 358 // Sort spans by |.startOffset|. |
| 438 std::sort(underlines.begin(), underlines.end()); | 359 std::sort(underlines.begin(), underlines.end()); |
| 439 | 360 |
| 440 return underlines; | 361 return underlines; |
| 441 } | 362 } |
| 442 | 363 |
| 443 } // namespace content | 364 } // namespace content |
| OLD | NEW |