Home | History | Annotate | Download | only in renderer_host
      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_RENDERER_HOST_IME_ADAPTER_ANDROID_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_IME_ADAPTER_ANDROID_H_
      7 
      8 #include <jni.h>
      9 
     10 #include "base/android/jni_helper.h"
     11 
     12 namespace content {
     13 
     14 class RenderWidgetHostImpl;
     15 class RenderWidgetHostViewAndroid;
     16 struct NativeWebKeyboardEvent;
     17 
     18 // This class is in charge of dispatching key events from the java side
     19 // and forward to renderer along with input method results via
     20 // corresponding host view.
     21 // Ownership of these objects remains on the native side (see
     22 // RenderWidgetHostViewAndroid).
     23 class ImeAdapterAndroid {
     24  public:
     25   explicit ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva);
     26   ~ImeAdapterAndroid();
     27 
     28   // Called from java -> native
     29   // The java side is responsible to translate android KeyEvent various enums
     30   // and values into the corresponding WebKit::WebInputEvent.
     31   bool SendKeyEvent(JNIEnv* env, jobject,
     32                     jobject original_key_event,
     33                     int action, int meta_state,
     34                     long event_time, int key_code,
     35                     bool is_system_key, int unicode_text);
     36   // |event_type| is a value of WebInputEvent::Type.
     37   bool SendSyntheticKeyEvent(JNIEnv*,
     38                              jobject,
     39                              int event_type,
     40                              long timestamp_ms,
     41                              int native_key_code,
     42                              int unicode_char);
     43   void SetComposingText(JNIEnv*, jobject, jstring text, int new_cursor_pos);
     44   void ImeBatchStateChanged(JNIEnv*, jobject, jboolean is_begin);
     45   void CommitText(JNIEnv*, jobject, jstring text);
     46   void FinishComposingText(JNIEnv* env, jobject);
     47   void AttachImeAdapter(JNIEnv*, jobject java_object);
     48   void SetEditableSelectionOffsets(JNIEnv*, jobject, int start, int end);
     49   void SetComposingRegion(JNIEnv*, jobject, int start, int end);
     50   void DeleteSurroundingText(JNIEnv*, jobject, int before, int after);
     51   void Unselect(JNIEnv*, jobject);
     52   void SelectAll(JNIEnv*, jobject);
     53   void Cut(JNIEnv*, jobject);
     54   void Copy(JNIEnv*, jobject);
     55   void Paste(JNIEnv*, jobject);
     56   void ResetImeAdapter(JNIEnv*, jobject);
     57 
     58   // Called from native -> java
     59   void CancelComposition();
     60 
     61  private:
     62   RenderWidgetHostImpl* GetRenderWidgetHostImpl();
     63 
     64   RenderWidgetHostViewAndroid* rwhva_;
     65   JavaObjectWeakGlobalRef java_ime_adapter_;
     66 };
     67 
     68 bool RegisterImeAdapter(JNIEnv* env);
     69 
     70 }  // namespace content
     71 
     72 #endif  // CONTENT_BROWSER_RENDERER_HOST_IME_ADAPTER_ANDROID_H_
     73