| 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 #ifndef CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ | 6 #define CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/android/jni_weak_ref.h" | 12 #include "base/android/jni_weak_ref.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "content/browser/android/render_widget_host_connector.h" |
| 14 #include "content/common/content_export.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" | 15 #include "ui/gfx/geometry/rect_f.h" |
| 17 | 16 |
| 18 namespace blink { | 17 namespace blink { |
| 19 | 18 |
| 20 struct WebCompositionUnderline; | 19 struct WebCompositionUnderline; |
| 21 | 20 |
| 22 } // namespace blink | 21 } // namespace blink |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 25 | 24 |
| 26 class RenderFrameHost; | 25 class RenderFrameHost; |
| 27 class RenderWidgetHostImpl; | 26 class RenderWidgetHostImpl; |
| 28 class RenderWidgetHostViewAndroid; | 27 class RenderWidgetHostViewAndroid; |
| 29 | 28 |
| 30 // This class is in charge of dispatching key events from the java side | 29 // This class is in charge of dispatching key events from the java side |
| 31 // and forward to renderer along with input method results via | 30 // and forward to renderer along with input method results via |
| 32 // corresponding host view. | 31 // corresponding host view. |
| 33 // Ownership of these objects remains on the native side (see | 32 class CONTENT_EXPORT ImeAdapterAndroid : public RenderWidgetHostConnector { |
| 34 // RenderWidgetHostViewAndroid). | |
| 35 class CONTENT_EXPORT ImeAdapterAndroid : public WebContentsObserver { | |
| 36 public: | 33 public: |
| 37 ImeAdapterAndroid(JNIEnv* env, | 34 ImeAdapterAndroid(JNIEnv* env, |
| 38 const base::android::JavaParamRef<jobject>& obj, | 35 const base::android::JavaParamRef<jobject>& obj, |
| 39 WebContents* web_contents); | 36 WebContents* web_contents); |
| 40 ~ImeAdapterAndroid() override; | 37 ~ImeAdapterAndroid() override; |
| 41 | 38 |
| 42 // Called from java -> native | 39 // Called from java -> native |
| 43 bool SendKeyEvent( | 40 bool SendKeyEvent( |
| 44 JNIEnv* env, | 41 JNIEnv* env, |
| 45 const base::android::JavaParamRef<jobject>&, | 42 const base::android::JavaParamRef<jobject>&, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 const base::android::JavaParamRef<jobject>&, | 77 const base::android::JavaParamRef<jobject>&, |
| 81 int before, | 78 int before, |
| 82 int after); | 79 int after); |
| 83 void RequestCursorUpdate(JNIEnv*, | 80 void RequestCursorUpdate(JNIEnv*, |
| 84 const base::android::JavaParamRef<jobject>&, | 81 const base::android::JavaParamRef<jobject>&, |
| 85 bool immediateRequest, | 82 bool immediateRequest, |
| 86 bool monitorRequest); | 83 bool monitorRequest); |
| 87 bool RequestTextInputStateUpdate(JNIEnv*, | 84 bool RequestTextInputStateUpdate(JNIEnv*, |
| 88 const base::android::JavaParamRef<jobject>&); | 85 const base::android::JavaParamRef<jobject>&); |
| 89 | 86 |
| 87 // RendetWidgetHostConnector implementation. |
| 88 void UpdateRenderProcessConnection( |
| 89 RenderWidgetHostViewAndroid* old_rwhva, |
| 90 RenderWidgetHostViewAndroid* new_rhwva) override; |
| 91 |
| 90 // Called from native -> java | 92 // Called from native -> java |
| 91 void CancelComposition(); | 93 void CancelComposition(); |
| 92 void FocusedNodeChanged(bool is_editable_node); | 94 void FocusedNodeChanged(bool is_editable_node); |
| 93 void SetCharacterBounds(const std::vector<gfx::RectF>& rects); | 95 void SetCharacterBounds(const std::vector<gfx::RectF>& rects); |
| 94 | 96 |
| 95 base::android::ScopedJavaLocalRef<jobject> java_ime_adapter_for_testing( | 97 base::android::ScopedJavaLocalRef<jobject> java_ime_adapter_for_testing( |
| 96 JNIEnv* env) { | 98 JNIEnv* env) { |
| 97 return java_ime_adapter_.get(env); | 99 return java_ime_adapter_.get(env); |
| 98 } | 100 } |
| 99 | 101 |
| 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: | 102 private: |
| 109 RenderWidgetHostImpl* GetFocusedWidget(); | 103 RenderWidgetHostImpl* GetFocusedWidget(); |
| 110 RenderFrameHost* GetFocusedFrame(); | 104 RenderFrameHost* GetFocusedFrame(); |
| 111 std::vector<blink::WebCompositionUnderline> GetUnderlinesFromSpans( | 105 std::vector<blink::WebCompositionUnderline> GetUnderlinesFromSpans( |
| 112 JNIEnv* env, | 106 JNIEnv* env, |
| 113 const base::android::JavaParamRef<jobject>& obj, | 107 const base::android::JavaParamRef<jobject>& obj, |
| 114 const base::android::JavaParamRef<jobject>& text, | 108 const base::android::JavaParamRef<jobject>& text, |
| 115 const base::string16& text16); | 109 const base::string16& text16); |
| 116 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const; | |
| 117 void UpdateRenderProcessConnection(RenderWidgetHostViewAndroid* new_rwhva); | |
| 118 | 110 |
| 119 base::WeakPtr<RenderWidgetHostViewAndroid> rwhva_; | 111 // Current RenderWidgetHostView connected to this instance. Can be null. |
| 112 RenderWidgetHostViewAndroid* rwhva_; |
| 120 JavaObjectWeakGlobalRef java_ime_adapter_; | 113 JavaObjectWeakGlobalRef java_ime_adapter_; |
| 121 }; | 114 }; |
| 122 | 115 |
| 123 bool RegisterImeAdapter(JNIEnv* env); | 116 bool RegisterImeAdapter(JNIEnv* env); |
| 124 | 117 |
| 125 } // namespace content | 118 } // namespace content |
| 126 | 119 |
| 127 #endif // CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ | 120 #endif // CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_ |
| OLD | NEW |