Add to set MIME type to the input panel and add the callback
[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) 2019 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 <dali/internal/input/linux/dali-ecore-imf.h>
23 #include <dali/internal/system/linux/dali-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 *eventInfo ) override;
112
113   /**
114    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
115    */
116   void CommitReceived( void *data, ImfContext *imfContext, void *eventInfo ) 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 *eventInfo ) override;
127
128  /**
129   * @copydoc Dali::InputMethodContext::SendPrivateCommand()
130   */
131   void SendPrivateCommand( void* data, ImfContext* imfContext, void* eventInfo ) override;
132
133   /**
134    * @copydoc Dali::InputMethodContext::SendCommitContent()
135    */
136    void SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo ) override;
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::SetContentMIMETypes()
231    */
232   void SetContentMIMETypes( const std::string& mimeTypes ) override;
233
234   /**
235    * @copydoc Dali::InputMethodContext::FilterEventKey()
236    */
237   bool FilterEventKey( const Dali::KeyEvent& keyEvent ) override;
238
239   /**
240    * @copydoc Dali::InputMethodContext::AllowTextPrediction()
241    */
242   void AllowTextPrediction( bool prediction ) override;
243
244   /**
245    * @copydoc Dali::InputMethodContext::IsTextPredictionAllowed()
246    */
247   bool IsTextPredictionAllowed() const override;
248
249   /**
250    * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
251    */
252   void SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language ) override;
253
254   /**
255    * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
256    */
257   Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const override;
258
259 private:
260   /**
261    * Context created the first time and kept until deleted.
262    */
263   void CreateContext();
264
265   /**
266    * @copydoc Dali::InputMethodContext::DeleteContext()
267    */
268   void DeleteContext();
269
270 private:
271
272   /**
273    * @brief Process event key down, whether filter a key to isf.
274    *
275    * @param[in] keyEvent The event key to be handled.
276    * @return Whether the event key is handled.
277    */
278   bool ProcessEventKeyDown( const KeyEvent& keyEvent );
279
280   /**
281    * @brief Process event key up, whether filter a key to isf.
282    *
283    * @param[in] keyEvent The event key to be handled.
284    * @return Whether the event key is handled.
285    */
286   bool ProcessEventKeyUp( const KeyEvent& keyEvent );
287
288   /**
289   * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
290   * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
291   * @param[in] ecoreModifier the Ecore_Event_Modifier input.
292   * @return the Ecore_IMF_Keyboard_Modifiers output.
293   */
294   Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier );
295
296   /**
297    * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
298    * @param[in] modifier the Ecore_Event_Modifier input.
299    * @return the Ecore_IMF_Keyboard_Locks output.
300    */
301   Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier );
302
303 private:
304   /**
305    * @brief Constructor.
306    */
307   explicit InputMethodContextEcoreWl();
308
309 protected:
310   /**
311    * Destructor.
312    */
313   virtual ~InputMethodContextEcoreWl() override;
314
315 private:
316   // Undefined copy constructor
317   explicit InputMethodContextEcoreWl( const InputMethodContextEcoreWl& inputMethodContext) = delete;
318
319   // Undefined assignment operator
320   InputMethodContextEcoreWl& operator=( const InputMethodContextEcoreWl& inputMethodContext ) = delete;
321
322 private:
323   Ecore_IMF_Context* mIMFContext;
324   int mIMFCursorPosition;
325   std::string mSurroundingText;
326
327   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
328   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
329
330   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
331   InputMethodOptions        mOptions;
332 };
333
334
335 } // namespace Adaptor
336
337 } // namespace Internal
338
339 } // namespace Dali
340
341 #endif // DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_ECORE_WL_H