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