Add AllowTextPrediction/IsTextPredictionAllowed api
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / ubuntu-x11 / input-method-context-impl-x.h
1 #ifndef __DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H
2 #define __DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <Ecore_IMF.h>
23 #include <Ecore_X.h>
24
25 #include <dali/public-api/object/base-object.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/input-method-context.h>
29 #include <dali/internal/input/common/input-method-context-impl.h>
30
31 namespace Dali
32 {
33
34 class RenderSurface;
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 class InputMethodContextX : public Dali::Internal::Adaptor::InputMethodContext
43 {
44 public:
45   /**
46    * @brief Creates a new InputMethodContext handle
47    *
48    * @return InputMethodContext pointer
49    */
50   static InputMethodContextPtr New();
51
52   /**
53    * Constructor
54    * @param[in] ecoreXwin, The window is created by application.
55    */
56   explicit InputMethodContextX( Ecore_X_Window ecoreXwin );
57
58 public:
59
60   /**
61    * @brief Initializes member data.
62    */
63   void Initialize() override;
64
65   /**
66    * Connect Callbacks required for InputMethodContext.
67    * If you don't connect InputMethodContext callbacks, you can't get the key events.
68    * The events are PreeditChanged, Commit and DeleteSurrounding.
69    */
70   void ConnectCallbacks() override;
71
72   /**
73    * Disconnect Callbacks attached to input method context.
74    */
75   void DisconnectCallbacks() override;
76
77   /**
78    * @copydoc Dali::InputMethodContext::Finalize()
79    */
80   void Finalize() override;
81
82   /**
83    * @copydoc Dali::InputMethodContext::Activate()
84    */
85   void Activate() override;
86
87   /**
88    * @copydoc Dali::InputMethodContext::Deactivate()
89    */
90   void Deactivate() override;
91
92   /**
93    * @copydoc Dali::InputMethodContext::Reset()
94    */
95   void Reset() override;
96
97   /**
98    * @copydoc Dali::InputMethodContext::GetContext()
99    */
100   ImfContext* GetContext() override;
101
102   /**
103    * @copydoc Dali::InputMethodContext::RestoreAfterFocusLost()
104    */
105   bool RestoreAfterFocusLost() const override;
106
107   /**
108    * @copydoc Dali::InputMethodContext::SetRestoreAfterFocusLost()
109    */
110   void SetRestoreAfterFocusLost( bool toggle ) override;
111
112   /**
113    * @copydoc Dali::InputMethodContext::PreEditChanged()
114    */
115   void PreEditChanged( void* data, ImfContext* imfContext, void* event_info ) override;
116
117   /**
118    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
119    */
120   void CommitReceived( void* data, ImfContext* imfContext, void* event_info ) override;
121
122   /**
123    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
124    */
125   bool RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition ) override;
126
127   /**
128    * @copydoc Dali::InputMethodContext::DeleteSurrounding()
129    */
130   void DeleteSurrounding( void* data, ImfContext* imfContext, void* event_info ) override;
131
132   /**
133    * @copydoc Dali::InputMethodContext::SendPrivateCommand()
134    */
135   void SendPrivateCommand( void* data, ImfContext* imfContext, void* event_info ) override
136   {}
137
138   // Cursor related
139   /**
140    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
141    */
142   void NotifyCursorPosition() override;
143
144   /**
145    * @copydoc Dali::InputMethodContext::SetCursorPosition()
146    */
147   void SetCursorPosition( unsigned int cursorPosition ) override;
148
149   /**
150    * @copydoc Dali::InputMethodContext::GetCursorPosition()
151    */
152   unsigned int GetCursorPosition() const override;
153
154   /**
155    * @copydoc Dali::InputMethodContext::SetSurroundingText()
156    */
157   void SetSurroundingText( const std::string& text ) override;
158
159   /**
160    * @copydoc Dali::InputMethodContext::GetSurroundingText()
161    */
162   const std::string& GetSurroundingText() const override;
163
164   /**
165   * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
166   */
167   void NotifyTextInputMultiLine( bool multiLine ) override;
168
169   /**
170   * @copydoc Dali::InputMethodContext::GetTextDirection()
171   */
172   Dali::InputMethodContext::TextDirection GetTextDirection() override;
173
174   /**
175   * @copydoc Dali::InputMethodContext::GetInputMethodArea()
176   */
177   Dali::Rect<int> GetInputMethodArea() override;
178
179   /**
180   * @copydoc Dali::InputMethodContext::ApplyOptions()
181   */
182   void ApplyOptions( const InputMethodOptions& options ) override;
183
184   /**
185    * @copydoc Dali::InputMethodContext::SetInputPanelData()
186    */
187   void SetInputPanelData( const std::string& data ) override;
188
189   /**
190    * @copydoc Dali::InputMethodContext::GetInputPanelData()
191    */
192   void GetInputPanelData( std::string& data ) override;
193
194   /**
195    * @copydoc Dali::InputMethodContext::GetInputPanelState()
196    */
197   Dali::InputMethodContext::State GetInputPanelState() override;
198
199   /**
200    * @copydoc Dali::InputMethodContext::SetReturnKeyState()
201    */
202   void SetReturnKeyState( bool visible ) override;
203
204   /**
205    * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
206    */
207   void AutoEnableInputPanel( bool enabled ) override;
208
209   /**
210    * @copydoc Dali::InputMethodContext::ShowInputPanel()
211    */
212   void ShowInputPanel() override;
213
214   /**
215    * @copydoc Dali::InputMethodContext::HideInputPanel()
216    */
217   void HideInputPanel() override;
218
219   /**
220    * @copydoc Dali::InputMethodContext::GetKeyboardType()
221    */
222   Dali::InputMethodContext::KeyboardType GetKeyboardType() override;
223
224   /**
225    * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
226    */
227   std::string GetInputPanelLocale() override;
228
229   /**
230    * @copydoc Dali::InputMethodContext::FilterEventKey()
231    */
232   bool FilterEventKey( const Dali::KeyEvent& keyEvent ) override;
233
234   /**
235    * @copydoc Dali::InputMethodContext::AllowTextPrediction()
236    */
237   void AllowTextPrediction( bool prediction ) override;
238
239   /**
240    * @copydoc Dali::InputMethodContext::IsTextPredictionAllowed()
241    */
242   bool IsTextPredictionAllowed() const override;
243 private:
244   /**
245    * Context created the first time and kept until deleted.
246    * @param[in] ecoreXwin, The window is created by application.
247    */
248   void CreateContext( Ecore_X_Window ecoreXwin );
249
250   /**
251    * @copydoc Dali::InputMethodContext::DeleteContext()
252    */
253   void DeleteContext();
254
255 private:
256
257   /**
258    * @brief Process event key down, whether filter a key to isf.
259    *
260    * @param[in] keyEvent The event key to be handled.
261    * @return Whether the event key is handled.
262    */
263   bool ProcessEventKeyDown( const KeyEvent& keyEvent );
264
265   /**
266    * @brief Process event key up, whether filter a key to isf.
267    *
268    * @param[in] keyEvent The event key to be handled.
269    * @return Whether the event key is handled.
270    */
271   bool ProcessEventKeyUp( const KeyEvent& keyEvent );
272
273   /**
274   * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
275   * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
276   * @param[in] ecoreModifier the Ecore_Event_Modifier input.
277   * @return the Ecore_IMF_Keyboard_Modifiers output.
278   */
279   Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier );
280
281   /**
282    * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
283    * @param[in] modifier the Ecore_Event_Modifier input.
284    * @return the Ecore_IMF_Keyboard_Locks output.
285    */
286   Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier );
287
288 public:
289
290   /**
291    * Destructor.
292    */
293   virtual ~InputMethodContextX();
294
295 private:
296
297   // Undefined copy constructor
298   InputMethodContextX( const InputMethodContextX& inputMethodContext) = delete;
299
300   // Undefined assignment operator
301   InputMethodContextX& operator=( const InputMethodContextX& inputMethodContext ) = delete;
302
303 private:
304   Ecore_IMF_Context* mIMFContext;
305   Ecore_X_Window mEcoreXwin;
306   int mIMFCursorPosition;
307   std::string mSurroundingText;
308
309   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
310   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
311   InputMethodOptions        mOptions;
312 };
313
314 } // namespace Adaptor
315
316 } // namespace Internal
317
318 } // namespace Dali
319
320 #endif // __DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H