1 #ifndef DALI_INPUT_METHOD_CONTEXT_H
2 #define DALI_INPUT_METHOD_CONTEXT_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/events/key-event.h>
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/signals/dali-signal.h>
27 #include <dali/devel-api/adaptor-framework/input-method-options.h>
32 namespace Internal DALI_INTERNAL
36 class InputMethodContext;
43 * @brief The InputMethodContext class
45 * Specifically manages the ecore input method framework which enables the virtual or hardware keyboards.
47 class DALI_ADAPTOR_API InputMethodContext : public BaseHandle
52 * @brief The direction of text.
61 * @brief Events that are generated by the InputMethodContext.
66 PRE_EDIT, ///< Pre-Edit changed
67 COMMIT, ///< Commit recieved
68 DELETE_SURROUNDING, ///< Event to delete a range of characters from the string
69 GET_SURROUNDING, ///< Event to query string and cursor position
70 PRIVATE_COMMAND ///< Private command sent from the input panel
74 * @brief Enumeration for state of the input panel.
78 DEFAULT = 0, ///< Unknown state
79 SHOW, ///< Input panel is shown
80 HIDE, ///< Input panel is hidden
81 WILL_SHOW ///< Input panel in process of being shown
85 * @brief Enumeration for the type of Keyboard.
89 SOFTWARE_KEYBOARD, ///< Software keyboard (Virtual keyboard) is default
90 HARDWARE_KEYBOARD ///< Hardware keyboard
93 enum class InputPanelLanguage
95 AUTOMATIC, ///< IME Language automatically set depending on the system display
96 ALPHABET ///< Latin alphabet at all times
100 * @brief This structure is used to pass on data from the InputMethodContext regarding predictive text.
105 * @brief Default Constructor.
108 : predictiveString(),
118 * @param[in] aEventName The name of the event from the InputMethodContext.
119 * @param[in] aPredictiveString The pre-edit or commit string.
120 * @param[in] aCursorOffset Start position from the current cursor position to start deleting characters.
121 * @param[in] aNumberOfChars The number of characters to delete from the cursorOffset.
123 EventData( EventType aEventName, const std::string& aPredictiveString, int aCursorOffset, int aNumberOfChars )
124 : predictiveString( aPredictiveString ),
125 eventName( aEventName ),
126 cursorOffset( aCursorOffset ),
127 numberOfChars( aNumberOfChars )
132 std::string predictiveString; ///< The pre-edit or commit string.
133 EventType eventName; ///< The name of the event from the InputMethodContext.
134 int cursorOffset; ///< Start position from the current cursor position to start deleting characters.
135 int numberOfChars; ///< number of characters to delete from the cursorOffset.
139 * @brief Data required by InputMethodContext from the callback
150 preeditResetRequired( false )
156 * @param[in] aUpdate True if cursor position needs to be updated
157 * @param[in] aCursorPosition new position of cursor
158 * @param[in] aCurrentText current text string
159 * @param[in] aPreeditResetRequired flag if preedit reset is required.
161 CallbackData( bool aUpdate, int aCursorPosition, const std::string& aCurrentText, bool aPreeditResetRequired )
162 : currentText( aCurrentText ),
163 cursorPosition( aCursorPosition ),
165 preeditResetRequired( aPreeditResetRequired )
169 std::string currentText; ///< current text string
170 int cursorPosition; ///< new position of cursor
171 bool update :1; ///< if cursor position needs to be updated
172 bool preeditResetRequired :1; ///< flag if preedit reset is required.
175 typedef Signal< void (InputMethodContext&) > ActivatedSignalType; ///< Keyboard actived signal
176 typedef Signal< CallbackData ( InputMethodContext&, const EventData& ) > KeyboardEventSignalType; ///< keyboard events
177 typedef Signal< void () > VoidSignalType;
178 typedef Signal< void ( bool ) > StatusSignalType;
179 typedef Signal< void ( KeyboardType ) > KeyboardTypeSignalType; ///< keyboard type
180 typedef Signal< void ( int ) > KeyboardResizedSignalType; ///< Keyboard resized signal
181 typedef Signal< void ( int ) > LanguageChangedSignalType; ///< Language changed signal
182 typedef Signal< void ( const std::string&, const std::string&, const std::string& ) > ContentReceivedSignalType; ///< Content received signal
187 * @brief Retrieve a handle to the instance of InputMethodContext.
188 * @return A handle to the InputMethodContext.
189 * @brief Constructor.
191 InputMethodContext();
196 * This is non-virtual since derived Handle types must not contain data or virtual methods.
198 ~InputMethodContext();
201 * @brief Create a new instance of an InputMethodContext.
203 static InputMethodContext New();
206 * @brief Create a new instance of an InputMethodContext.
208 * @param[in] actor The actor that uses the new InputMethodContext instance.
210 static InputMethodContext New( Actor actor );
213 * @brief Copy constructor.
215 * @param[in] inputMethodContext InputMethodContext to copy. The copied inputMethodContext will point at the same implementation.
217 InputMethodContext( const InputMethodContext& inputMethodContext );
220 * @brief Assignment operator.
222 * @param[in] inputMethodContext The InputMethodContext to assign from.
223 * @return The updated InputMethodContext.
225 InputMethodContext& operator=( const InputMethodContext& inputMethodContext );
228 * @brief Downcast a handle to InputMethodContext handle.
230 * If handle points to an InputMethodContext the downcast produces valid
231 * handle. If not the returned handle is left uninitialized.
233 * @param[in] handle Handle to an object.
234 * @return Handle to an InputMethodContext or an uninitialized handle.
236 static InputMethodContext DownCast( BaseHandle handle );
241 * @brief Finalize the InputMethodContext.
243 * It means that the context will be deleted.
248 * @brief Activate the InputMethodContext.
250 * It means that the text editing is started at somewhere.
251 * If the H/W keyboard isn't connected then it will show the virtual keyboard.
256 * @brief Deactivate the InputMethodContext.
258 * It means that the text editing is finished at somewhere.
263 * @brief Get the restoration status, which controls if the keyboard is restored after the focus lost then regained.
265 * If true then keyboard will be restored (activated) after focus is regained.
266 * @return restoration status.
268 bool RestoreAfterFocusLost() const;
271 * @brief Set status whether the InputMethodContext has to restore the keyboard after losing focus.
273 * @param[in] toggle True means that keyboard should be restored after focus lost and regained.
275 void SetRestoreAfterFocusLost( bool toggle );
278 * @brief Send message reset the pred-edit state / InputMethodContext module.
280 * Used to interupt pre-edit state maybe due to a touch input.
285 * @brief Notifies InputMethodContext that the cursor position has changed, required for features like auto-capitalisation.
287 void NotifyCursorPosition();
290 * @brief Sets cursor position stored in VirtualKeyboard, this is required by the InputMethodContext.
292 * @param[in] cursorPosition position of cursor
294 void SetCursorPosition( unsigned int cursorPosition );
297 * @brief Gets cursor position stored in VirtualKeyboard, this is required by the InputMethodContext.
299 * @return current position of cursor
301 unsigned int GetCursorPosition() const;
304 * @brief Method to store the string required by the InputMethodContext, this is used to provide predictive word suggestions.
306 * @param[in] text The text string surrounding the current cursor point.
308 void SetSurroundingText( const std::string& text );
311 * @brief Gets current text string set within the InputMethodContext manager, this is used to offer predictive suggestions.
313 * @return current position of cursor
315 const std::string& GetSurroundingText() const;
318 * @brief Notifies InputMethodContext that text input is set to multi line or not
320 * @param[in] multiLine True if multiline text input is used
322 void NotifyTextInputMultiLine( bool multiLine );
325 * @brief Returns text direction of the keyboard's current input language.
326 * @return The direction of the text.
328 TextDirection GetTextDirection();
331 * @brief Provides size and position of keyboard.
333 * Position is relative to whether keyboard is visible or not.
334 * If keyboard is not visible then position will be off the screen.
335 * If keyboard is not being shown when this method is called the keyboard is partially setup (IMFContext) to get
336 * the values then taken down. So ideally GetInputMethodArea() should be called after Show().
337 * @return rect which is keyboard panel x, y, width, height
339 Dali::Rect<int> GetInputMethodArea();
342 * @brief Set one or more of the Input Method options
343 * @param[in] options The options to be applied
345 void ApplyOptions( const InputMethodOptions& options );
348 * @brief Sets up the input-panel specific data.
349 * @param[in] data The specific data to be set to the input panel
351 void SetInputPanelData( const std::string& data );
354 * @brief Gets the specific data of the current active input panel.
356 * Input Panel Data is not always the data which is set by SetInputPanelData().
357 * Data can be changed internally in the input panel.
358 * It is just used to get a specific data from the input panel to an application.
359 * @param[in] data The specific data to be got from the input panel
361 void GetInputPanelData( std::string& data );
364 * @brief Gets the state of the current active input panel.
365 * @return The state of the input panel.
367 State GetInputPanelState();
370 * @brief Sets the return key on the input panel to be visible or invisible.
372 * The default is true.
373 * @param[in] visible True if the return key is visible(enabled), false otherwise.
375 void SetReturnKeyState( bool visible );
378 * @brief Enable to show the input panel automatically when focused.
379 * @param[in] enabled If true, the input panel will be shown when focused
381 void AutoEnableInputPanel( bool enabled );
384 * @brief Shows the input panel.
386 void ShowInputPanel();
389 * @brief Hides the input panel.
391 void HideInputPanel();
394 * @brief Gets the keyboard type.
396 * The default keyboard type is SOFTWARE_KEYBOARD.
397 * @return The keyboard type
399 KeyboardType GetKeyboardType();
402 * @brief Gets the current language locale of the input panel.
404 * ex) en_US, en_GB, en_PH, fr_FR, ...
405 * @return The current language locale of the input panel
407 std::string GetInputPanelLocale();
410 * @brief Sets the allowed MIME Types to deliver to the input panel.
412 * ex) std::string mimeTypes = "text/plain,image/png,image/gif,application/pdf";
414 * You can receive a media content URI and its MIME type from ContentReceivedSignal(). @see ContentReceivedSignal
415 * @param[in] mimeTypes The allowed MIME types
417 void SetContentMIMETypes( const std::string& mimeTypes );
420 * @brief Process event key down or up, whether filter a key to isf.
422 * @param[in] keyEvent The event key to be handled.
423 * @return Whether the event key is handled.
425 bool FilterEventKey( const Dali::KeyEvent& keyEvent );
428 * @brief Sets whether the IM context should allow to use the text prediction.
430 * @param[in] prediction Whether to allow text prediction or not.
432 void AllowTextPrediction( bool prediction );
435 * @brief Gets whether the IM context allow to use the text prediction.
437 * @return Whether the IM allow text prediction or not.
439 bool IsTextPredictionAllowed() const;
442 * @brief Sets the language of the input panel.
444 * This method can be used when you want to show the English keyboard.
445 * @param[in] language The language to be set to the input panel
447 void SetInputPanelLanguage( InputPanelLanguage language );
450 * @brief Gets the language of the input panel.
452 * @return The language of the input panel
454 InputPanelLanguage GetInputPanelLanguage() const;
457 * @brief Sets the x,y coordinates of the input panel.
459 * @param[in] x The top-left x coordinate of the input panel
460 * @param[in] y The top-left y coordinate of the input panel
462 void SetInputPanelPosition( unsigned int x, unsigned int y );
469 * @brief This is emitted when the virtual keyboard is connected to or the hardware keyboard is activated.
471 * @return The InputMethodContext Activated signal.
473 ActivatedSignalType& ActivatedSignal();
476 * @brief This is emitted when the InputMethodContext manager receives an event from the InputMethodContext.
478 * @return The Event signal containing the event data.
480 KeyboardEventSignalType& EventReceivedSignal();
483 * @brief Connect to this signal to be notified when the virtual keyboard is shown or hidden.
485 * A callback of the following type may be connected:
487 * void YourCallbackName(bool keyboardShown);
489 * If the parameter keyboardShown is true, then the keyboard has just shown, if it is false, then it
490 * has just been hidden.
491 * @return The signal to connect to.
493 StatusSignalType& StatusChangedSignal();
496 * @brief Connect to this signal to be notified when the virtual keyboard is resized.
498 * A callback of the following type may be connected:
500 * void YourCallbackName( int resolvedResize );
502 * The parameter sends the resolved resize defined by the InputMethodContext.
504 * User can get changed size by using GetInputMethodArea() in the callback
505 * @return The signal to connect to.
507 KeyboardResizedSignalType& ResizedSignal();
510 * @brief Connect to this signal to be notified when the virtual keyboard's language is changed.
512 * A callback of the following type may be connected:
514 * void YourCallbackName( int resolvedLanguage );
516 * The parameter sends the resolved language defined by the InputMethodContext.
518 * User can get the text direction of the language by calling GetTextDirection() in the callback.
519 * @return The signal to connect to.
521 LanguageChangedSignalType& LanguageChangedSignal();
524 * @brief Connect to this signal to be notified when the keyboard type is changed.
526 * A callback of the following type may be connected:
528 * void YourCallbackName( KeyboardType keyboard );
531 * @return The signal to connect to.
533 KeyboardTypeSignalType& KeyboardTypeChangedSignal();
536 * @brief Connect to this signal to be notified when the content, such as images, of input method is received.
538 * A callback of the following type may be connected:
540 * void YourCallbackName( const std::string& contentUri, const std::string& description, const std::string& contentMIMEType );
543 * @return The signal to connect to.
545 ContentReceivedSignalType& ContentReceivedSignal();
550 * @brief This constructor is used by InputMethodContext::New().
552 * @param[in] inputMethodContext A pointer to the InputMethodContext.
554 explicit DALI_INTERNAL InputMethodContext( Internal::Adaptor::InputMethodContext* inputMethodContext );
562 #endif // DALI_INPUT_METHOD_CONTEXT_H