1 #ifndef __DALI_WAYLAND_TEXT_INPUT_MANAGER_H__
2 #define __DALI_WAYLAND_TEXT_INPUT_MANAGER_H__
5 * Copyright (c) 2017 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.
25 #include <input/text/text-input-interface.h>
26 #include <input/seat.h>
27 #include <virtual-keyboard.h>
29 #include <base/interfaces/window-event-interface.h>
42 * Handles wayland text input interface which deals with the input panel (virtual keyboard ).
45 class TextInputManager : private TextInputInterface
61 * @brief Assign the window event interface
62 * Used to send key events to DALi
63 * @param[in] eventInterface event interface
65 void AssignWindowEventInterface( WindowEventInterface* eventInterface );
68 * @brief Assign the Wayland connection
69 * @param[in] display Wayland display
71 void AssignDisplay( WlDisplay* display );
75 * @param seat seat pointer
77 void AddSeat( Seat* seat );
80 * Get the global TextInputManager
82 static TextInputManager& Get();
84 private: // TextInputInterface
87 * @copydoc TextInputInterface::Enter
89 virtual void Enter( Seat* seat, WlSurface* surface );
92 * @copydoc TextInputInterface::Leave
94 virtual void Leave( Seat* seat );
97 * @copydoc TextInputInterface::ModifiersMap
99 virtual void ModifiersMap( Seat* seat, WlArray *map );
102 * @copydoc TextInputInterface::InputPanelState
104 virtual void InputPanelState( Seat* seat, uint32_t state );
107 * @copydoc TextInputInterface::PreeditString
109 virtual void PreeditString( Seat* seat, uint32_t serial, const char *text, const char *commit );
112 * @copydoc TextInputInterface::PreeditStyling
114 virtual void PreeditStyling( Seat* seat, uint32_t index, uint32_t length, uint32_t style );
117 * @copydoc TextInputInterface::PreeditCursor
119 virtual void PreeditCursor( Seat* seat, int32_t index );
122 * @copydoc TextInputInterface::CommitString
124 virtual void CommitString( Seat* seat, uint32_t serial, const char *text );
127 * @copydoc TextInputInterface::CursorPosition
129 virtual void CursorPosition( Seat* seat, int32_t index, int32_t anchor );
132 * @copydoc TextInputInterface::DeleteSurroundingText
134 virtual void DeleteSurroundingText( Seat* seat, int32_t index, uint32_t length );
138 * @copydoc TextInputInterface::Keysym
140 virtual void Keysym( Seat* seat,
148 * @copydoc TextInputInterface::Language
150 virtual void Language( Seat* seat, uint32_t serial, const char *language );
153 * @copydoc TextInputInterface::TextDirection
155 virtual void TextDirection( Seat* seat, uint32_t serial, uint32_t direction );
158 * @copydoc TextInputInterface::SelectionRegion
160 virtual void SelectionRegion( Seat* seat, uint32_t serial, int32_t start, int32_t end );
163 * @copydoc TextInputInterface::PrivateCommand
165 virtual void PrivateCommand( Seat* seat, uint32_t serial, const char *command );
168 * @copydoc TextInputInterface::InputPanelGeometry
170 virtual void InputPanelGeometry( Seat* seat, uint32_t x, uint32_t y, uint32_t width, uint32_t height );
173 * @copydoc TextInputInterface::InputPanelData
175 virtual void InputPanelData( Seat* seat,
178 uint32_t dataLength );
181 * @copydoc TextInputInterface::GetSeat
183 virtual Seat* GetSeat( const WlTextInput* textInput );
188 * @brief show the input panel (virtual keyboard)
190 void ShowInputPanel();
193 * @brief hide the input panel
195 void HideInputPanel();
198 * @brief see if the input panel is visible
199 * @return true if panel is visible
201 bool IsInputPanelVisible();
204 * @brief set the return key type
205 * @param[in] type return key type
207 void SetReturnKeyType( const InputMethod::ActionButton type );
210 * @brief reset inputs state
211 * Should be called by an editor widget when the input state should be
212 * reset, for example after the text was changed outside of the normal
219 * Set the plain surrounding text around the input position. Text is
220 * UTF-8 encoded. Cursor is the byte offset within the
221 * surrounding text. Anchor is the byte offset of the
222 * selection anchor within the surrounding text. If there is no selected
223 * text anchor is the same as cursor.
224 * @param[in] text the text
225 * @param[in] cursor cursor position
226 * @param[in] anchor anchor position
228 void SetSurroundingText( std::string text, unsigned int cursor, unsigned int anchor );
232 public: // virtual keyboard signals
235 * @copydoc Dali::VirtualKeyboard::StatusChangedSignal
237 Dali::VirtualKeyboard::StatusSignalType& StatusChangedSignal();
240 * @copydoc Dali::VirtualKeyboard::ResizedSignal
242 Dali::VirtualKeyboard::VoidSignalType& ResizedSignal();
245 * @copydoc Dali::VirtualKeyboard::LanguageChangedSignal
247 Dali::VirtualKeyboard::VoidSignalType& LanguageChangedSignal();
249 public: ///< Input Panel Signals ( DALi currently doesn't use these, it only uses signals from IMF interface).
251 typedef Signal< void ( unsigned int, const std::string, const std::string ) > PreEditStringSignalType;
252 typedef Signal< void ( unsigned int, unsigned int length, unsigned int ) > PreEditStylingSignalType;
253 typedef Signal< void ( int ) > PreEditCursorSignalType;
254 typedef Signal< void ( unsigned int, const std::string ) > CommitStringSignalType;
255 typedef Signal< void ( int , int ) > CursorPositionSignalType;
256 typedef Signal< void ( int , unsigned int ) > DeleteSurroundingTextSignalType;
257 typedef Signal< void ( unsigned int ,int, int ) > SelectionRegionSignalType;
260 * @brief Notify when composing new text
261 * Description from wayland-extension/protocol/text.xml:
262 * Notify when a new composing text (pre-edit) should be set around the
263 * current cursor position. Any previously set composing text should
266 * The commit text can be used to replace the preedit text on reset (for example on unfocus).
267 * The text input should also handle all preedit_style and preedit_cursor
268 * events occurring directly before preedit_string.
271 * void YourCallbackName( unsigned int serial, std::string text, std::string commit );
274 PreEditStringSignalType& PreEditStringSignal();
277 * @brief Pre-edit styling
279 * Description from wayland-extension/protocol/text.xml:
280 * Set styling information on composing text. The style is applied for
281 * length bytes from index relative to the beginning of the composing
282 * text (as byte offset). Multiple styles can be applied to a composing
283 * text by sending multiple preedit_styling events.
287 * void YourCallbackName( unsigned int index, unsigned int length, unsigned int style );
290 PreEditStylingSignalType& PreEditStylingSignal();
293 * @brief Notify pre-edit cursor position
294 * Description from wayland-extension/protocol/text.xml:
295 * Set the cursor position inside the composing text (as byte
296 * offset) relative to the start of the composing text. When index is a
297 * negative number no cursor is shown.
300 * void YourCallbackName( int index );
303 PreEditCursorSignalType& PreEditCursorSignal();
306 * @brief Commit string text
307 * From wayland-extension/protocol/text.xml:
308 * Notify when text should be inserted into the editor widget. The text to
309 * commit could be either just a single character after a key press or the
310 * result of some composing (pre-edit). It could be also an empty text
311 * when some text should be removed (see delete_surrounding_text) or when
312 * the input cursor should be moved (see cursor_position).
314 * Any previously set composing text should be removed.
317 * void YourCallbackName( const std::string text );
320 CommitStringSignalType& CommitStringSignal();
323 * @brief Cursor position signal
324 * From wayland-extension/protocol/text.xml:
325 * Notify when the cursor or anchor position should be modified.
326 * This event should be handled as part of a following commit_string event.
328 * void YourCallbackName( int index, int anchor );
331 CursorPositionSignalType& CursorPositionSignal();
334 * @brief delete surrounding text
335 * From wayland-extension/protocol/text.xml:
336 * Notify when the text around the current cursor position should be deleted.
338 * Index is relative to the current cursor (in bytes).
339 * Length is the length of deleted text (in bytes).
341 * void YourCallbackName( int index, unsigned int length );
343 * This event should be handled as part of a following commit_string event.
345 DeleteSurroundingTextSignalType& DeleteSurroundingTextSignal();
348 * @brief text selection region
349 * Notify when the input panels ask to select the characters
350 * from the start cursor position to the end cursor position.
352 * Index is relative to the current cursor (in bytes).
353 * Length is the length of deleted text (in bytes).
355 * void YourCallbackName( unsigned int serial, int start, int end );
358 SelectionRegionSignalType& SelectionRegionSignal();
363 * POD to store text input data for each seat.
368 : mTextDirection( Dali::VirtualKeyboard::LeftToRight ),
370 mInputPanelDimensions( 0,0,0,0 ),
371 mReturnKeyType( InputMethod::ACTION_UNSPECIFIED ),
372 mInputPanelVisible( false ),
377 Dali::VirtualKeyboard::TextDirection mTextDirection;
379 Dali::Rect<int> mInputPanelDimensions; ///< size of the input panel
380 std::string mLanguage; ///< input panel language
381 InputMethod::ActionButton mReturnKeyType; ///< return key
382 bool mInputPanelVisible:1; ///< panel status
387 * @brief get the last active seat
388 * @return the last active seat
390 SeatInfo& GetLastActiveSeat();
394 WlDisplay* mDisplay; ///< Wayland display, handles all the data sent from and to the compositor
395 Seat* mLastActiveSeat; ///< Seat that was last used
396 WindowEventInterface* mWindowEventInterface;
398 std::vector< SeatInfo > mSeats; ///< keeps track of text input information for each seat
399 Dali::VirtualKeyboard::StatusSignalType mKeyboardStatusSignal;
400 Dali::VirtualKeyboard::VoidSignalType mKeyboardResizeSignal;
401 Dali::VirtualKeyboard::VoidSignalType mKeyboardLanguageChangedSignal;
403 // Input Panel (Virtual Keyboard) signals
404 PreEditStringSignalType mPreEditStringSignal;
405 PreEditStylingSignalType mPreEditStylingSignal;
406 PreEditCursorSignalType mPreEditCursorSignal;
407 CommitStringSignalType mCommitStringSignal;
408 CursorPositionSignalType mCursorPositionSignal;
409 DeleteSurroundingTextSignalType mDeleteSurroundingTextSignal;
410 SelectionRegionSignalType mSelectionRegionSignal;