| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ | |
| 6 #define CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/android/jni_weak_ref.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 #include "content/common/content_export.h" | |
| 15 #include "content/public/browser/web_contents_observer.h" | |
| 16 #include "ui/gfx/geometry/rect_f.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 struct WebCompositionUnderline; | |
| 21 | |
| 22 } // namespace blink | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 class RenderFrameHost; | |
| 27 class RenderWidgetHostImpl; | |
| 28 class RenderWidgetHostViewAndroid; | |
| 29 | |
| 30 // This class is in charge of dispatching key events from the java side | |
| 31 // and forward to renderer along with input method results via | |
| 32 // corresponding host view. | |
| 33 // Ownership of these objects remains on the native side (see | |
| 34 // RenderWidgetHostViewAndroid). | |
| 35 class CONTENT_EXPORT ImeAdapterAndroid : public WebContentsObserver { | |
| 36 public: | |
| 37 ImeAdapterAndroid(JNIEnv* env, | |
| 38 const base::android::JavaParamRef<jobject>& obj, | |
| 39 WebContents* web_contents); | |
| 40 ~ImeAdapterAndroid() override; | |
| 41 | |
| 42 // Called from java -> native | |
| 43 bool SendKeyEvent( | |
| 44 JNIEnv* env, | |
| 45 const base::android::JavaParamRef<jobject>&, | |
| 46 const base::android::JavaParamRef<jobject>& original_key_event, | |
| 47 int type, | |
| 48 int modifiers, | |
| 49 jlong time_ms, | |
| 50 int key_code, | |
| 51 int scan_code, | |
| 52 bool is_system_key, | |
| 53 int unicode_text); | |
| 54 void SetComposingText(JNIEnv* env, | |
| 55 const base::android::JavaParamRef<jobject>& obj, | |
| 56 const base::android::JavaParamRef<jobject>& text, | |
| 57 const base::android::JavaParamRef<jstring>& text_str, | |
| 58 int relative_cursor_pos); | |
| 59 void CommitText(JNIEnv* env, | |
| 60 const base::android::JavaParamRef<jobject>& obj, | |
| 61 const base::android::JavaParamRef<jobject>& text, | |
| 62 const base::android::JavaParamRef<jstring>& text_str, | |
| 63 int relative_cursor_pos); | |
| 64 void FinishComposingText(JNIEnv* env, | |
| 65 const base::android::JavaParamRef<jobject>&); | |
| 66 void SetEditableSelectionOffsets(JNIEnv*, | |
| 67 const base::android::JavaParamRef<jobject>&, | |
| 68 int start, | |
| 69 int end); | |
| 70 void SetComposingRegion(JNIEnv*, | |
| 71 const base::android::JavaParamRef<jobject>&, | |
| 72 int start, | |
| 73 int end); | |
| 74 void DeleteSurroundingText(JNIEnv*, | |
| 75 const base::android::JavaParamRef<jobject>&, | |
| 76 int before, | |
| 77 int after); | |
| 78 void DeleteSurroundingTextInCodePoints( | |
| 79 JNIEnv*, | |
| 80 const base::android::JavaParamRef<jobject>&, | |
| 81 int before, | |
| 82 int after); | |
| 83 void RequestCursorUpdate(JNIEnv*, | |
| 84 const base::android::JavaParamRef<jobject>&, | |
| 85 bool immediateRequest, | |
| 86 bool monitorRequest); | |
| 87 bool RequestTextInputStateUpdate(JNIEnv*, | |
| 88 const base::android::JavaParamRef<jobject>&); | |
| 89 | |
| 90 // Called from native -> java | |
| 91 void CancelComposition(); | |
| 92 void FocusedNodeChanged(bool is_editable_node); | |
| 93 void SetCharacterBounds(const std::vector<gfx::RectF>& rects); | |
| 94 | |
| 95 base::android::ScopedJavaLocalRef<jobject> java_ime_adapter_for_testing( | |
| 96 JNIEnv* env) { | |
| 97 return java_ime_adapter_.get(env); | |
| 98 } | |
| 99 | |
| 100 // WebContentsObserver implementation. | |
| 101 void RenderViewReady() override; | |
| 102 void RenderViewHostChanged(RenderViewHost* old_host, | |
| 103 RenderViewHost* new_host) override; | |
| 104 void DidAttachInterstitialPage() override; | |
| 105 void DidDetachInterstitialPage() override; | |
| 106 void WebContentsDestroyed() override; | |
| 107 | |
| 108 private: | |
| 109 RenderWidgetHostImpl* GetFocusedWidget(); | |
| 110 RenderFrameHost* GetFocusedFrame(); | |
| 111 std::vector<blink::WebCompositionUnderline> GetUnderlinesFromSpans( | |
| 112 JNIEnv* env, | |
| 113 const base::android::JavaParamRef<jobject>& obj, | |
| 114 const base::android::JavaParamRef<jobject>& text, | |
| 115 const base::string16& text16); | |
| 116 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const; | |
| 117 void UpdateRenderProcessConnection(RenderWidgetHostViewAndroid* new_rwhva); | |
| 118 | |
| 119 RenderWidgetHostViewAndroid* rwhva_; | |
| 120 JavaObjectWeakGlobalRef java_ime_adapter_; | |
| 121 }; | |
| 122 | |
| 123 bool RegisterImeAdapter(JNIEnv* env); | |
| 124 | |
| 125 } // namespace content | |
| 126 | |
| 127 #endif // CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ | |
| OLD | NEW |