8727249f57aed61ae39b404b3a976d676d44513d
[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) 2021 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-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 class RenderSurface;
34
35 namespace Internal
36 {
37 namespace Adaptor
38 {
39 class InputMethodContextX : public Dali::Internal::Adaptor::InputMethodContext, public Dali::ConnectionTracker
40 {
41 public:
42   /**
43    * @brief Creates a new InputMethodContext handle
44    *
45    * @param[in] actor The actor that uses the new InputMethodContext instance.
46    * @return InputMethodContext pointer
47    */
48   static InputMethodContextPtr New(Dali::Actor actor);
49
50   /**
51    * Constructor
52    * @param[in] actor The actor that uses the new InputMethodContext instance.
53    */
54   explicit InputMethodContextX(Dali::Actor actor);
55
56 public:
57   /**
58    * @brief Initializes member data.
59    */
60   void Initialize() 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 and DeleteSurrounding.
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::Finalize()
76    */
77   void Finalize() 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* eventInfo) override;
113
114   /**
115    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
116    */
117   void CommitReceived(void* data, ImfContext* imfContext, void* eventInfo) 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* eventInfo) override;
128
129   /**
130    * @copydoc Dali::InputMethodContext::SendPrivateCommand()
131    */
132   void SendPrivateCommand(void* data, ImfContext* imfContext, void* eventInfo) override
133   {
134   }
135
136   /**
137    * @copydoc Dali::InputMethodContext::SendCommitContent()
138    */
139   void SendCommitContent(void* data, ImfContext* imfContext, void* eventInfo) override
140   {
141   }
142
143   // Cursor related
144   /**
145    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
146    */
147   void NotifyCursorPosition() override;
148
149   /**
150    * @copydoc Dali::InputMethodContext::SetCursorPosition()
151    */
152   void SetCursorPosition(unsigned int cursorPosition) override;
153
154   /**
155    * @copydoc Dali::InputMethodContext::GetCursorPosition()
156    */
157   unsigned int GetCursorPosition() const override;
158
159   /**
160    * @copydoc Dali::InputMethodContext::SetSurroundingText()
161    */
162   void SetSurroundingText(const std::string& text) override;
163
164   /**
165    * @copydoc Dali::InputMethodContext::GetSurroundingText()
166    */
167   const std::string& GetSurroundingText() const override;
168
169   /**
170   * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
171   */
172   void NotifyTextInputMultiLine(bool multiLine) override;
173
174   /**
175   * @copydoc Dali::InputMethodContext::GetTextDirection()
176   */
177   Dali::InputMethodContext::TextDirection GetTextDirection() override;
178
179   /**
180   * @copydoc Dali::InputMethodContext::GetInputMethodArea()
181   */
182   Dali::Rect<int> GetInputMethodArea() override;
183
184   /**
185   * @copydoc Dali::InputMethodContext::ApplyOptions()
186   */
187   void ApplyOptions(const InputMethodOptions& options) override;
188
189   /**
190    * @copydoc Dali::InputMethodContext::SetInputPanelData()
191    */
192   void SetInputPanelData(const std::string& data) override;
193
194   /**
195    * @copydoc Dali::InputMethodContext::GetInputPanelData()
196    */
197   void GetInputPanelData(std::string& data) override;
198
199   /**
200    * @copydoc Dali::InputMethodContext::GetInputPanelState()
201    */
202   Dali::InputMethodContext::State GetInputPanelState() override;
203
204   /**
205    * @copydoc Dali::InputMethodContext::SetReturnKeyState()
206    */
207   void SetReturnKeyState(bool visible) override;
208
209   /**
210    * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
211    */
212   void AutoEnableInputPanel(bool enabled) override;
213
214   /**
215    * @copydoc Dali::InputMethodContext::ShowInputPanel()
216    */
217   void ShowInputPanel() override;
218
219   /**
220    * @copydoc Dali::InputMethodContext::HideInputPanel()
221    */
222   void HideInputPanel() override;
223
224   /**
225    * @copydoc Dali::InputMethodContext::GetKeyboardType()
226    */
227   Dali::InputMethodContext::KeyboardType GetKeyboardType() override;
228
229   /**
230    * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
231    */
232   std::string GetInputPanelLocale() override;
233
234   /**
235    * @copydoc Dali::InputMethodContext::SetContentMIMETypes()
236    */
237   void SetContentMIMETypes(const std::string& mimeTypes) override;
238
239   /**
240    * @copydoc Dali::InputMethodContext::FilterEventKey()
241    */
242   bool FilterEventKey(const Dali::KeyEvent& keyEvent) override;
243
244   /**
245    * @copydoc Dali::InputMethodContext::AllowTextPrediction()
246    */
247   void AllowTextPrediction(bool prediction) override;
248
249   /**
250    * @copydoc Dali::InputMethodContext::IsTextPredictionAllowed()
251    */
252   bool IsTextPredictionAllowed() const override;
253
254   /**
255    * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
256    */
257   void SetInputPanelLanguage(Dali::InputMethodContext::InputPanelLanguage language) override;
258
259   /**
260    * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
261    */
262   Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const override;
263
264   /**
265    * @copydoc Dali::InputMethodContext::SetInputPanelPosition()
266    */
267   void SetInputPanelPosition(unsigned int x, unsigned int y) override;
268
269   /**
270    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
271    */
272   void GetPreeditStyle(Dali::InputMethodContext::PreEditAttributeDataContainer& attrs) const override;
273
274 private:
275   /**
276    * Context created the first time and kept until deleted.
277    */
278   void CreateContext();
279
280   /**
281    * @copydoc Dali::InputMethodContext::DeleteContext()
282    */
283   void DeleteContext();
284
285 private:
286   /**
287    * @brief Process event key down, whether filter a key to isf.
288    *
289    * @param[in] keyEvent The event key to be handled.
290    * @return Whether the event key is handled.
291    */
292   bool ProcessEventKeyDown(const Dali::KeyEvent& keyEvent);
293
294   /**
295    * @brief Process event key up, whether filter a key to isf.
296    *
297    * @param[in] keyEvent The event key to be handled.
298    * @return Whether the event key is handled.
299    */
300   bool ProcessEventKeyUp(const Dali::KeyEvent& keyEvent);
301
302   /**
303   * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
304   * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
305   * @param[in] ecoreModifier the Ecore_Event_Modifier input.
306   * @return the Ecore_IMF_Keyboard_Modifiers output.
307   */
308   Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier);
309
310   /**
311    * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
312    * @param[in] modifier the Ecore_Event_Modifier input.
313    * @return the Ecore_IMF_Keyboard_Locks output.
314    */
315   Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock(unsigned int modifier);
316
317   /**
318    * Called when the binded actor is added to a window.
319    */
320   void OnStaged(Dali::Actor actor);
321
322 public:
323   /**
324    * Destructor.
325    */
326   virtual ~InputMethodContextX();
327
328 private:
329   // Undefined copy constructor
330   InputMethodContextX(const InputMethodContextX& inputMethodContext) = delete;
331
332   // Undefined assignment operator
333   InputMethodContextX& operator=(const InputMethodContextX& inputMethodContext) = delete;
334
335 private:
336   Ecore_IMF_Context* mIMFContext;
337   Ecore_X_Window     mEcoreXwin;
338   int                mIMFCursorPosition;
339   std::string        mSurroundingText;
340
341   bool               mRestoreAfterFocusLost : 1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
342   bool               mIdleCallbackConnected : 1; ///< Whether the idle callback is already connected.
343   InputMethodOptions mOptions;
344
345   Dali::InputMethodContext::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data
346 };
347
348 } // namespace Adaptor
349
350 } // namespace Internal
351
352 } // namespace Dali
353
354 #endif // DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H