38ca2c45f4ee2960d0c8e6d35127fa1eed829f78
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2014 Samsung Electronics. 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 IM_CONTEXT_EFL
6 #define IM_CONTEXT_EFL
7
8 #include <Evas.h>
9
10 #include "content/public/browser/native_web_keyboard_event.h"
11 #include "content/browser/renderer_host/web_event_factory_efl.h"
12 #include "ui/base/ime/composition_text.h"
13 #include "ui/gfx/geometry/rect.h"
14
15 typedef struct _Ecore_IMF_Context Ecore_IMF_Context;
16
17 namespace content {
18
19 class RenderWidgetHostViewEfl;
20
21 class IMContextEfl {
22  public:
23   // Returns NULL if there is no available backend.
24   static IMContextEfl* Create(RenderWidgetHostViewEfl*);
25
26   ~IMContextEfl();
27
28   void HandleKeyDownEvent(const Evas_Event_Key_Down* event, bool* was_filtered);
29   void HandleKeyUpEvent(const Evas_Event_Key_Up* event, bool* was_filtered);
30
31   void UpdateInputMethodType(ui::TextInputType, ui::TextInputMode,
32                              bool can_compose_inline);
33   void UpdateInputMethodState(ui::TextInputType, bool can_compose_inline,
34                               bool show_if_needed);
35   void UpdateCaretBounds(const gfx::Rect& caret_bounds);
36
37   void OnFocusIn();
38   void OnFocusOut();
39
40   void OnResume();
41   void OnSuspend();
42   void DoNotShowAfterResume();
43
44   void ShowPanel();
45   void HidePanel();
46
47   void ResetIMFContext();
48   void CancelComposition();
49   void ConfirmComposition();
50   void SetSurroundingText(std::string value);
51   void SetIsInFormTag(bool is_in_form_tag);
52   void SetCaretPosition(int position);
53
54   // Return visible state based on ecore_imf API.
55   bool IsVisible();
56   bool WebViewWillBeResized();
57
58   bool IsPreeditQueueEmpty() const { return preedit_queue_.empty(); }
59   bool IsCommitQueueEmpty() const { return commit_queue_.empty(); }
60   bool IsKeyUpQueueEmpty() const { return keyup_event_queue_.empty(); }
61   bool IsKeyDownQueueEmpty() const { return keydown_event_queue_.empty(); }
62   void PreeditQueuePop() { preedit_queue_.pop(); }
63   void ClearQueues();
64   void HandleKeyEvent(bool processed, blink::WebInputEvent::Type);
65
66   void PushToKeyUpEventQueue(int key);
67   void PushToKeyDownEventQueue(NativeWebKeyboardEvent key);
68
69   void SendFakeCompositionKeyEvent(const base::string16& buf);
70
71   void UpdateLayoutVariation(bool is_minimum_negative, bool is_step_integer);
72   bool IsDefaultReturnKeyType();
73 #if defined(OS_TIZEN_MOBILE_PRODUCT)
74   void PrevNextButtonUpdate(bool prev_state, bool next_state);
75 #endif
76   bool ShouldHandleImmediately(const char* key);
77   void SetIMERecommendedWords(const std::string&);
78   void SetIMERecommendedWordsType(bool should_enable);
79
80   void SetDefaultViewSize(const gfx::Size& size) { default_view_size_ = size; }
81
82  private:
83   IMContextEfl(RenderWidgetHostViewEfl*, Ecore_IMF_Context*);
84
85   void InitializeIMFContext(Ecore_IMF_Context*);
86
87   // callbacks
88   static Eina_Bool IMFRetrieveSurroundingCallback(void* data,
89                                                   Ecore_IMF_Context*,
90                                                   char** text,
91                                                   int* offset);
92   static void IMFCandidatePanelGeometryChangedCallback(void* data,
93                                                        Ecore_IMF_Context*,
94                                                        int state);
95   static void IMFCandidatePanelLanguageChangedCallback(
96       void* data,
97       Ecore_IMF_Context* context,
98       int value);
99   static void IMFCandidatePanelStateChangedCallback(void* data,
100                                                     Ecore_IMF_Context*,
101                                                     int state);
102   static void IMFCommitCallback(void* data,
103                                 Ecore_IMF_Context*,
104                                 void* event_info);
105   static void IMFDeleteSurroundingCallback(void* data,
106                                            Ecore_IMF_Context*,
107                                            void* event_info);
108 #if defined(OS_TIZEN_TV_PRODUCT)
109   static void IMFEventPrivateCommandCallback(void* data,
110                                              Ecore_IMF_Context* context,
111                                              void* eventInfo);
112 #endif
113   static void IMFInputPanelStateChangedCallback(void* data,
114                                                 Ecore_IMF_Context*,
115                                                 int state);
116   static void IMFInputPanelGeometryChangedCallback(void* data,
117                                                    Ecore_IMF_Context*,
118                                                    int state);
119   static void IMFPreeditChangedCallback(void* data,
120                                         Ecore_IMF_Context* context,
121                                         void* event_info);
122   static void IMFTransactionPrivateCommandSendCallback(
123       void* data,
124       Ecore_IMF_Context* context,
125       void* event_info);
126 #if defined(OS_TIZEN_MOBILE_PRODUCT)
127   static void IMFEventPrivateCmdCallback(void* data,
128                                          Ecore_IMF_Context* context,
129                                          void* eventInfo);
130 #endif
131   // callback handlers
132   void OnCommit(void* event_info);
133   void OnPreeditChanged(void* data,
134                         Ecore_IMF_Context* context,
135                         void* event_info);
136 #if defined(OS_TIZEN_MOBILE_PRODUCT)
137   void OnIMFPrevNextButtonPressedCallback(std::string command);
138 #endif
139   void OnInputPanelStateChanged(int state);
140   void OnInputPanelGeometryChanged();
141
142   void OnCandidateInputPanelStateChanged(int state);
143   void OnCandidateInputPanelGeometryChanged();
144
145   bool OnRetrieveSurrounding(char** text, int* offset);
146   void OnDeleteSurrounding(void* event_info);
147   void OnCandidateInputPanelLanguageChanged(Ecore_IMF_Context* context,
148                                             int value);
149 #if defined(OS_TIZEN_TV_PRODUCT)
150   void OnIMFEventPrivateCommand(std::string command);
151 #endif
152
153   void ProcessNextCommitText(bool processed);
154   void ProcessNextPreeditText(bool processed);
155   void ProcessNextKeyDownEvent();
156   void ProcessNextKeyUpEvent();
157   void SendCompositionKeyUpEvent(int windowsKeyCode);
158
159   RenderWidgetHostImpl* GetRenderWidgetHostImpl() const;
160
161   RenderWidgetHostViewEfl* view_;
162
163   Ecore_IMF_Context* context_;
164
165   // Whether or not the associated widget is focused.
166   bool is_focused_;
167
168   // Whether or not is in form tag.
169   bool is_in_form_tag_;
170
171   // The current soft keyboard mode and layout
172   ui::TextInputMode current_mode_;
173   ui::TextInputType current_type_;
174   bool can_compose_inline_;
175
176   ui::CompositionText composition_;
177
178   // View size when IME isn't shown.
179   gfx::Size default_view_size_;
180
181   typedef std::queue<base::string16> CommitQueue;
182   typedef std::queue<ui::CompositionText> PreeditQueue;
183   typedef std::queue<int> KeyUpEventQueue;
184   typedef std::queue<NativeWebKeyboardEvent> KeyDownEventQueue;
185
186   CommitQueue commit_queue_;
187   PreeditQueue preedit_queue_;
188   KeyUpEventQueue keyup_event_queue_;
189   KeyDownEventQueue keydown_event_queue_;
190
191   bool is_ime_ctx_reset_;
192
193   bool should_show_on_resume_;
194
195   bool is_get_lookup_table_from_app_;
196
197   int caret_position_;
198
199   std::string surrounding_text_;
200   bool is_surrounding_text_change_in_progress_;
201
202   bool is_keyevent_processing_;
203   bool is_transaction_finished_;
204 };
205
206 } // namespace content
207
208 #endif