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