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