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 blink::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 CommitText(JNIEnv*, jobject, jstring text);
     45   void FinishComposingText(JNIEnv* env, jobject);
     46   void AttachImeAdapter(JNIEnv*, jobject java_object);
     47   void SetEditableSelectionOffsets(JNIEnv*, jobject, int start, int end);
     48   void SetComposingRegion(JNIEnv*, jobject, int start, int end);
     49   void DeleteSurroundingText(JNIEnv*, jobject, int before, int after);
     50   void Unselect(JNIEnv*, jobject);
     51   void SelectAll(JNIEnv*, jobject);
     52   void Cut(JNIEnv*, jobject);
     53   void Copy(JNIEnv*, jobject);
     54   void Paste(JNIEnv*, jobject);
     55   void ResetImeAdapter(JNIEnv*, jobject);
     56 
     57   // Called from native -> java
     58   void CancelComposition();
     59 
     60  private:
     61   RenderWidgetHostImpl* GetRenderWidgetHostImpl();
     62 
     63   RenderWidgetHostViewAndroid* rwhva_;
     64   JavaObjectWeakGlobalRef java_ime_adapter_;
     65 };
     66 
     67 bool RegisterImeAdapter(JNIEnv* env);
     68 
     69 }  // namespace content
     70 
     71 #endif  // CONTENT_BROWSER_RENDERER_HOST_IME_ADAPTER_ANDROID_H_
     72