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