Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: content/browser/android/ime_adapter_android.h

Issue 2752113005: Let ImeAdapterAndroid have the same lifecycle as its Java peer (Closed)
Patch Set: fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 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_RENDERER_HOST_IME_ADAPTER_ANDROID_H_ 5 #ifndef CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_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/strings/string16.h" 13 #include "base/memory/weak_ptr.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "content/public/browser/web_contents_observer.h"
15 #include "ui/gfx/geometry/rect_f.h" 16 #include "ui/gfx/geometry/rect_f.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
19 struct WebCompositionUnderline; 20 struct WebCompositionUnderline;
20 21
21 } // namespace blink 22 } // namespace blink
22 23
23 namespace content { 24 namespace content {
24 25
25 class RenderFrameHost; 26 class RenderFrameHost;
26 class RenderWidgetHostImpl; 27 class RenderWidgetHostImpl;
27 class RenderWidgetHostViewAndroid; 28 class RenderWidgetHostViewAndroid;
28 29
29 // This class is in charge of dispatching key events from the java side 30 // This class is in charge of dispatching key events from the java side
30 // and forward to renderer along with input method results via 31 // and forward to renderer along with input method results via
31 // corresponding host view. 32 // corresponding host view.
32 // Ownership of these objects remains on the native side (see 33 // Ownership of these objects remains on the native side (see
33 // RenderWidgetHostViewAndroid). 34 // RenderWidgetHostViewAndroid).
34 class CONTENT_EXPORT ImeAdapterAndroid { 35 class CONTENT_EXPORT ImeAdapterAndroid : public WebContentsObserver {
35 public: 36 public:
36 explicit ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva); 37 ImeAdapterAndroid(JNIEnv* env,
37 ~ImeAdapterAndroid(); 38 const base::android::JavaParamRef<jobject>& obj,
39 WebContents* web_contents);
40 ~ImeAdapterAndroid() override;
38 41
39 // Called from java -> native 42 // Called from java -> native
40 bool SendKeyEvent( 43 bool SendKeyEvent(
41 JNIEnv* env, 44 JNIEnv* env,
42 const base::android::JavaParamRef<jobject>&, 45 const base::android::JavaParamRef<jobject>&,
43 const base::android::JavaParamRef<jobject>& original_key_event, 46 const base::android::JavaParamRef<jobject>& original_key_event,
44 int type, 47 int type,
45 int modifiers, 48 int modifiers,
46 jlong time_ms, 49 jlong time_ms,
47 int key_code, 50 int key_code,
48 int scan_code, 51 int scan_code,
49 bool is_system_key, 52 bool is_system_key,
50 int unicode_text); 53 int unicode_text);
51 void SetComposingText(JNIEnv* env, 54 void SetComposingText(JNIEnv* env,
52 const base::android::JavaParamRef<jobject>& obj, 55 const base::android::JavaParamRef<jobject>& obj,
53 const base::android::JavaParamRef<jobject>& text, 56 const base::android::JavaParamRef<jobject>& text,
54 const base::android::JavaParamRef<jstring>& text_str, 57 const base::android::JavaParamRef<jstring>& text_str,
55 int relative_cursor_pos); 58 int relative_cursor_pos);
56 void CommitText(JNIEnv* env, 59 void CommitText(JNIEnv* env,
57 const base::android::JavaParamRef<jobject>& obj, 60 const base::android::JavaParamRef<jobject>& obj,
58 const base::android::JavaParamRef<jobject>& text, 61 const base::android::JavaParamRef<jobject>& text,
59 const base::android::JavaParamRef<jstring>& text_str, 62 const base::android::JavaParamRef<jstring>& text_str,
60 int relative_cursor_pos); 63 int relative_cursor_pos);
61 void FinishComposingText(JNIEnv* env, 64 void FinishComposingText(JNIEnv* env,
62 const base::android::JavaParamRef<jobject>&); 65 const base::android::JavaParamRef<jobject>&);
63 void AttachImeAdapter(
64 JNIEnv*,
65 const base::android::JavaParamRef<jobject>& java_object);
66 void SetEditableSelectionOffsets(JNIEnv*, 66 void SetEditableSelectionOffsets(JNIEnv*,
67 const base::android::JavaParamRef<jobject>&, 67 const base::android::JavaParamRef<jobject>&,
68 int start, 68 int start,
69 int end); 69 int end);
70 void SetComposingRegion(JNIEnv*, 70 void SetComposingRegion(JNIEnv*,
71 const base::android::JavaParamRef<jobject>&, 71 const base::android::JavaParamRef<jobject>&,
72 int start, 72 int start,
73 int end); 73 int end);
74 void DeleteSurroundingText(JNIEnv*, 74 void DeleteSurroundingText(JNIEnv*,
75 const base::android::JavaParamRef<jobject>&, 75 const base::android::JavaParamRef<jobject>&,
76 int before, 76 int before,
77 int after); 77 int after);
78 void DeleteSurroundingTextInCodePoints( 78 void DeleteSurroundingTextInCodePoints(
79 JNIEnv*, 79 JNIEnv*,
80 const base::android::JavaParamRef<jobject>&, 80 const base::android::JavaParamRef<jobject>&,
81 int before, 81 int before,
82 int after); 82 int after);
83 void ResetImeAdapter(JNIEnv*, const base::android::JavaParamRef<jobject>&); 83 void RequestCursorUpdate(JNIEnv*,
84 void RequestCursorUpdate(JNIEnv*, const base::android::JavaParamRef<jobject>&, 84 const base::android::JavaParamRef<jobject>&,
85 bool immediateRequest, bool monitorRequest); 85 bool immediateRequest,
86 bool monitorRequest);
86 bool RequestTextInputStateUpdate(JNIEnv*, 87 bool RequestTextInputStateUpdate(JNIEnv*,
87 const base::android::JavaParamRef<jobject>&); 88 const base::android::JavaParamRef<jobject>&);
88 89
89 // Called from native -> java 90 // Called from native -> java
90 void CancelComposition(); 91 void CancelComposition();
91 void FocusedNodeChanged(bool is_editable_node); 92 void FocusedNodeChanged(bool is_editable_node);
92 void SetCharacterBounds(const std::vector<gfx::RectF>& rects); 93 void SetCharacterBounds(const std::vector<gfx::RectF>& rects);
93 94
94 base::android::ScopedJavaLocalRef<jobject> java_ime_adapter_for_testing( 95 base::android::ScopedJavaLocalRef<jobject> java_ime_adapter_for_testing(
95 JNIEnv* env) { 96 JNIEnv* env) {
96 return java_ime_adapter_.get(env); 97 return java_ime_adapter_.get(env);
97 } 98 }
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
99 private: 108 private:
100 RenderWidgetHostImpl* GetFocusedWidget(); 109 RenderWidgetHostImpl* GetFocusedWidget();
101 RenderFrameHost* GetFocusedFrame(); 110 RenderFrameHost* GetFocusedFrame();
102 std::vector<blink::WebCompositionUnderline> GetUnderlinesFromSpans( 111 std::vector<blink::WebCompositionUnderline> GetUnderlinesFromSpans(
103 JNIEnv* env, 112 JNIEnv* env,
104 const base::android::JavaParamRef<jobject>& obj, 113 const base::android::JavaParamRef<jobject>& obj,
105 const base::android::JavaParamRef<jobject>& text, 114 const base::android::JavaParamRef<jobject>& text,
106 const base::string16& text16); 115 const base::string16& text16);
116 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const;
117 void UpdateRenderProcessConnection(RenderWidgetHostViewAndroid* new_rwhva);
107 118
108 RenderWidgetHostViewAndroid* rwhva_; 119 base::WeakPtr<RenderWidgetHostViewAndroid> rwhva_;
109 JavaObjectWeakGlobalRef java_ime_adapter_; 120 JavaObjectWeakGlobalRef java_ime_adapter_;
110 }; 121 };
111 122
112 bool RegisterImeAdapter(JNIEnv* env); 123 bool RegisterImeAdapter(JNIEnv* env);
113 124
114 } // namespace content 125 } // namespace content
115 126
116 #endif // CONTENT_BROWSER_RENDERER_HOST_IME_ADAPTER_ANDROID_H_ 127 #endif // CONTENT_BROWSER_ANDROID_IME_ADAPTER_ANDROID_H_
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.cc ('k') | content/browser/android/ime_adapter_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698