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