| OLD | NEW |
| 1 // Copyright (c) 2012 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_RENDERER_HOST_IME_ADAPTER_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_IME_ADAPTER_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_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 "base/android/jni_helper.h" | 10 #include "base/android/jni_helper.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/string16.h" |
| 11 | 13 |
| 12 namespace content { | 14 namespace content { |
| 13 | 15 |
| 16 class RenderFrameHost; |
| 14 class RenderWidgetHostImpl; | 17 class RenderWidgetHostImpl; |
| 15 class RenderWidgetHostViewAndroid; | 18 class RenderWidgetHostViewAndroid; |
| 16 struct NativeWebKeyboardEvent; | 19 struct NativeWebKeyboardEvent; |
| 17 | 20 |
| 18 // This class is in charge of dispatching key events from the java side | 21 // This class is in charge of dispatching key events from the java side |
| 19 // and forward to renderer along with input method results via | 22 // and forward to renderer along with input method results via |
| 20 // corresponding host view. | 23 // corresponding host view. |
| 21 // Ownership of these objects remains on the native side (see | 24 // Ownership of these objects remains on the native side (see |
| 22 // RenderWidgetHostViewAndroid). | 25 // RenderWidgetHostViewAndroid). |
| 23 class ImeAdapterAndroid { | 26 class ImeAdapterAndroid : public base::RefCountedThreadSafe<ImeAdapterAndroid> { |
| 24 public: | 27 public: |
| 25 explicit ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva); | 28 explicit ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva); |
| 26 ~ImeAdapterAndroid(); | |
| 27 | 29 |
| 28 // Called from java -> native | 30 // Called from java -> native |
| 29 // The java side is responsible to translate android KeyEvent various enums | 31 // The java side is responsible to translate android KeyEvent various enums |
| 30 // and values into the corresponding blink::WebInputEvent. | 32 // and values into the corresponding blink::WebInputEvent. |
| 33 // Since these methods are not called on the UI thread, they must be proxied |
| 34 // to the UI thread. |
| 31 bool SendKeyEvent(JNIEnv* env, jobject, | 35 bool SendKeyEvent(JNIEnv* env, jobject, |
| 32 jobject original_key_event, | 36 jobject original_key_event, |
| 33 int action, int meta_state, | 37 int action, int meta_state, |
| 34 long event_time, int key_code, | 38 long event_time, int key_code, |
| 35 bool is_system_key, int unicode_text); | 39 bool is_system_key, int unicode_text); |
| 36 // |event_type| is a value of WebInputEvent::Type. | 40 // |event_type| is a value of WebInputEvent::Type. |
| 37 bool SendSyntheticKeyEvent(JNIEnv*, | 41 bool SendSyntheticKeyEvent(JNIEnv*, |
| 38 jobject, | 42 jobject, |
| 39 int event_type, | 43 int event_type, |
| 40 long timestamp_ms, | 44 long timestamp_ms, |
| 41 int native_key_code, | 45 int native_key_code, |
| 42 int unicode_char); | 46 int unicode_char); |
| 43 void SetComposingText(JNIEnv*, jobject, jstring text, int new_cursor_pos); | 47 void SetComposingText(JNIEnv*, jobject, jstring text, int new_cursor_pos); |
| 44 void CommitText(JNIEnv*, jobject, jstring text); | 48 void CommitText(JNIEnv*, jobject, jstring text); |
| 45 void FinishComposingText(JNIEnv* env, jobject); | 49 void FinishComposingText(JNIEnv* env, jobject); |
| 46 void AttachImeAdapter(JNIEnv*, jobject java_object); | 50 void AttachImeAdapter(JNIEnv*, jobject java_object); |
| 47 void SetEditableSelectionOffsets(JNIEnv*, jobject, int start, int end); | 51 void SetEditableSelectionOffsets(JNIEnv*, jobject, int start, int end); |
| 48 void SetComposingRegion(JNIEnv*, jobject, int start, int end); | 52 void SetComposingRegion(JNIEnv*, jobject, int start, int end); |
| 49 void DeleteSurroundingText(JNIEnv*, jobject, int before, int after); | 53 void DeleteSurroundingText(JNIEnv*, jobject, int before, int after); |
| 50 void Unselect(JNIEnv*, jobject); | 54 void Unselect(JNIEnv*, jobject); |
| 51 void SelectAll(JNIEnv*, jobject); | 55 void SelectAll(JNIEnv*, jobject); |
| 52 void Cut(JNIEnv*, jobject); | 56 void Cut(JNIEnv*, jobject); |
| 53 void Copy(JNIEnv*, jobject); | 57 void Copy(JNIEnv*, jobject); |
| 54 void Paste(JNIEnv*, jobject); | 58 void Paste(JNIEnv*, jobject); |
| 55 void ResetImeAdapter(JNIEnv*, jobject); | 59 void ResetImeAdapter(JNIEnv*, jobject); |
| 56 | 60 |
| 57 // Called from native -> java | 61 // Called from native -> java |
| 58 void CancelComposition(); | 62 void CancelComposition(); |
| 59 void FocusedNodeChanged(bool is_editable_node); | 63 void FocusedNodeChanged(bool is_editable_node); |
| 64 void RenderWidgetGone(); |
| 60 | 65 |
| 61 private: | 66 private: |
| 67 friend class base::RefCountedThreadSafe<ImeAdapterAndroid>; |
| 68 ~ImeAdapterAndroid(); |
| 69 |
| 70 void SendSyntheticKeyEventOnUI(const NativeWebKeyboardEvent& event); |
| 71 void SendKeyEventOnUI(const NativeWebKeyboardEvent& event, |
| 72 const NativeWebKeyboardEvent& char_event, |
| 73 bool key_down_text_insertion); |
| 74 void SetComposingTextOnUI(const base::string16& text16, int new_cursor_pos); |
| 75 void CommitTextOnUI(const base::string16& text16); |
| 76 void FinishComposingTextsOnUI(); |
| 77 void SetEditableSelectionOffsetsOnUI(int start, int end); |
| 78 void SetComposingRegiontOnUI(int start, int end); |
| 79 void DeleteSurroundingTextOnUI(int before, int after); |
| 80 void UnselectOnUI(); |
| 81 void SelectAllOnUI(); |
| 82 void CutOnUI(); |
| 83 void CopyOnUI(); |
| 84 void PasteOnUI(); |
| 85 |
| 62 RenderWidgetHostImpl* GetRenderWidgetHostImpl(); | 86 RenderWidgetHostImpl* GetRenderWidgetHostImpl(); |
| 87 RenderFrameHost* GetFocusedFrame(); |
| 63 | 88 |
| 64 RenderWidgetHostViewAndroid* rwhva_; | 89 RenderWidgetHostViewAndroid* rwhva_; |
| 65 JavaObjectWeakGlobalRef java_ime_adapter_; | 90 JavaObjectWeakGlobalRef java_ime_adapter_; |
| 66 }; | 91 }; |
| 67 | 92 |
| 68 bool RegisterImeAdapter(JNIEnv* env); | 93 bool RegisterImeAdapter(JNIEnv* env); |
| 69 | 94 |
| 70 } // namespace content | 95 } // namespace content |
| 71 | 96 |
| 72 #endif // CONTENT_BROWSER_RENDERER_HOST_IME_ADAPTER_ANDROID_H_ | 97 #endif // CONTENT_BROWSER_RENDERER_HOST_IME_ADAPTER_ANDROID_H_ |
| OLD | NEW |