You.i Engine
YiKeyboardInputBridge.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_KEYBOARD_INPUT_BRIDGE_H_
3 #define _YI_KEYBOARD_INPUT_BRIDGE_H_
4 
5 #include "graphics/YiRectangle.h"
6 #include "network/YiUrl.h"
7 #include "signal/YiSignal.h"
9 #include "utility/YiString.h"
10 
30 {
31 public:
41  enum class InputType
42  {
46  Text,
50  Phone,
54  Number,
58  Email,
62  URI
63  };
64 
73  enum class ReturnKeyType
74  {
75  Default,
76  Go,
77  Search,
78  Next,
79  Done
80  };
81 
90  enum class InputModifiers
91  {
95  None = 0x0,
99  NoSuggestions = 0x1,
110  MaskInput = 0x2
111  };
112 
120  class Receiver
121  {
122  public:
126  struct Description
127  {
129  : maximumCharacterCount(0)
130  , currentCursorPosition(0)
131  {
132  }
133 
139  };
140 
141  virtual ~Receiver();
142 
148  virtual bool OnTextEntered(const CYIString &text, int32_t cursor) = 0;
153  virtual bool OnTextDeleted(int32_t beforeCursor, int32_t afterCursor) = 0;
154 
158  virtual void OnTextReplaced(const CYIString &text, size_t cursor) = 0;
159 
163  virtual void OnCursorPositionChanged(size_t cursor) = 0;
164 
170  virtual bool OnKeyboardHidden() = 0;
171 
175  virtual void OnReturnKeyPressed() = 0;
176 
180  virtual void OnNextKeyPressed() = 0;
181 
187  virtual void OnSynchronizeKeyboard(Description &receiverKeyboardInfo);
188 
192  virtual CYIKeyboardInputBridge::InputType GetInputType() const;
193 
197  virtual CYIKeyboardInputBridge::InputModifiers GetInputModifiers() const;
198 
204  ReturnKeyType GetReturnKeyType() const;
205 
212  void SetReturnKeyType(ReturnKeyType keyType);
213 
217  bool SetAccessoryImageUrl(const CYIUrl &url);
218 
223  const CYIUrl &GetAccessoryImageUrl() const;
224 
225  protected:
227  : m_keyType(ReturnKeyType::Default)
228  {
229  }
230 
233  };
234 
236  virtual ~CYIKeyboardInputBridge();
237 
241  void ResetKeyboard(Receiver *pSource);
242 
247  virtual bool ShowKeyboard(Receiver *pSource);
248 
253  virtual bool HideKeyboard();
254 
258  bool IsKeyboardShowing() const;
259 
263  bool IsHardwareKeyboardAvailable() const;
264 
268  bool ShouldShowKeyboardForActivationEvent(CYIKeyEvent *pKeyEvent) const;
269 
279  void OnTextChanged(const CYIString &text, Receiver *pSource);
289  void OnCursorPositionChanged(size_t cursor, Receiver *pSource);
290 
300  void OnCursorPositionWillChange(Receiver *pSource);
301 
306 
313  void ShowSelectionMenu(bool textSelected, YI_RECT rect);
314 
318  void HideSelectionMenu();
319 
325 
331 
332 protected:
342  {
343  LeftToRight,
344  RightToLeft,
345  Unknown
346  };
347 
351  virtual bool HasAccessoryImageSupport() const;
352 
356  virtual void AddAccessoryImageUrl(const CYIUrl &url);
357 
361  virtual void RemoveAccessoryImageUrl(const CYIUrl &url);
362 
363  virtual void ResetKeyboardInternal() = 0;
364  virtual bool ShowKeyboardInternal(Receiver *pSource) = 0;
365  virtual bool HideKeyboardInternal() = 0;
366  virtual bool IsKeyboardShowingInternal() const = 0;
367  virtual bool IsHardwareKeyboardAvailableInternal() const = 0;
368  virtual bool ShouldShowKeyboardForActivationEventInternal(CYIKeyEvent *pKeyEvent) const;
369  virtual void OnCursorPositionWillChangeInternal() = 0;
370  virtual void OnCursorPositionChangedInternal(size_t start, size_t end) = 0;
371  virtual void OnTextChangedInternal(const CYIString &text) = 0;
372  virtual void ShowSelectionMenuInternal(bool textSelected, YI_RECT rect) = 0;
373  virtual void HideSelectionMenuInternal() = 0;
374  virtual void OnKeyboardShown();
375  virtual void OnKeyboardHidden();
376  virtual void SetCurrentReceiver(Receiver *pReceiver);
377 
382 
389 
394 
395 private:
396  Receiver *m_pCurrentReceiver;
397 };
398 
401 template<>
403 {
404  static const bool enable = true;
405 };
406 
408 {
409  return InputType::Text;
410 }
411 
413 {
414  return InputModifiers::None;
415 }
416 
418 {
419  return m_keyType;
420 }
421 
423 {
424  m_keyType = keyType;
425 }
426 
428 {
429  return m_accessoryImageUrl;
430 }
431 
432 #endif /* _YI_KEYBOARD_INPUT_METHOD_H_ */
static CYIKeyboardInputBridge::KeyboardTextInputDirection GetDirectionFromLanguageCode(const CYIString &languageCode)
virtual bool HideKeyboardInternal()=0
void OnCursorPositionChanged(size_t cursor, Receiver *pSource)
Class for key events.
Definition: YiKeyEvent.h:16
virtual void RemoveAccessoryImageUrl(const CYIUrl &url)
Provides an interface to interact with the system software keyboard.
Definition: YiKeyboardInputBridge.h:120
Definition: YiRectangle.h:38
virtual void AddAccessoryImageUrl(const CYIUrl &url)
bool ShouldShowKeyboardForActivationEvent(CYIKeyEvent *pKeyEvent) const
YI_RECT_REL screenRect
The screen space area occupied by the Receiver&#39;s visual representation. This is used to position the ...
Definition: YiKeyboardInputBridge.h:137
void OnCursorPositionWillChange(Receiver *pSource)
virtual void OnCursorPositionChangedInternal(size_t start, size_t end)=0
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:32
CYISignal< KeyboardTextInputDirection > KeyboardTextInputDirectionChanged
Definition: YiKeyboardInputBridge.h:393
ReturnKeyType
The preferred return key type.
Definition: YiKeyboardInputBridge.h:73
KeyboardTextInputDirection
The keyboard text input direction.
Definition: YiKeyboardInputBridge.h:341
virtual bool IsHardwareKeyboardAvailableInternal() const =0
virtual void SetCurrentReceiver(Receiver *pReceiver)
Definition: YiRectangle.h:15
virtual void OnKeyboardShown()
void ResetKeyboard(Receiver *pSource)
virtual ~CYIKeyboardInputBridge()
bool IsHardwareKeyboardAvailable() const
A struct used to enable bitmask operators for an enum class type.
Definition: YiEnumBitmaskOperators.h:26
Description()
Definition: YiKeyboardInputBridge.h:128
virtual bool IsKeyboardShowingInternal() const =0
virtual bool ShowKeyboardInternal(Receiver *pSource)=0
virtual void ShowSelectionMenuInternal(bool textSelected, YI_RECT rect)=0
virtual CYIKeyboardInputBridge::InputType GetInputType() const
Definition: YiKeyboardInputBridge.h:407
void SetReturnKeyType(ReturnKeyType keyType)
Definition: YiKeyboardInputBridge.h:422
constexpr std::enable_if< YiEnableBitmaskOperators< E >::enable, bool >::type None(E a)
Definition: YiEnumBitmaskOperators.h:136
const CYIUrl & GetAccessoryImageUrl() const
Definition: YiKeyboardInputBridge.h:427
CYISignal KeyboardHidden
Definition: YiKeyboardInputBridge.h:330
virtual void HideSelectionMenuInternal()=0
virtual bool ShowKeyboard(Receiver *pSource)
void ShowSelectionMenu(bool textSelected, YI_RECT rect)
void OnTextChanged(const CYIString &text, Receiver *pSource)
Provides access to the system software keyboard.
Definition: YiKeyboardInputBridge.h:29
virtual bool HideKeyboard()
virtual void OnKeyboardHidden()
size_t currentCursorPosition
The position of the cursor in Description::defaultText. Must be greater than or equal to 0 and less t...
Definition: YiKeyboardInputBridge.h:138
size_t maximumCharacterCount
The maxiumum character count.
Definition: YiKeyboardInputBridge.h:136
CYISignal KeyboardShown
Definition: YiKeyboardInputBridge.h:324
virtual KeyboardTextInputDirection GetCurrentKeyboardTextInputDirection() const
A class used to encapsulate an URL.
Definition: YiUrl.h:24
CYIString placeholderText
The placeholder text maintained by the Receiver.
Definition: YiKeyboardInputBridge.h:135
virtual void ResetKeyboardInternal()=0
Receiver * GetCurrentReceiver()
virtual void OnCursorPositionWillChangeInternal()=0
ReturnKeyType GetReturnKeyType() const
Definition: YiKeyboardInputBridge.h:417
InputModifiers
The preferred modifiers for the platform keyboard.
Definition: YiKeyboardInputBridge.h:90
ReturnKeyType m_keyType
Definition: YiKeyboardInputBridge.h:232
Provides details to the system software keyboard.
Definition: YiKeyboardInputBridge.h:126
virtual bool ShouldShowKeyboardForActivationEventInternal(CYIKeyEvent *pKeyEvent) const
virtual void OnTextChangedInternal(const CYIString &text)=0
virtual bool HasAccessoryImageSupport() const
virtual CYIKeyboardInputBridge::InputModifiers GetInputModifiers() const
Definition: YiKeyboardInputBridge.h:412
CYIString currentText
The existing text maintained by the Receiver.
Definition: YiKeyboardInputBridge.h:134
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:169
bool IsKeyboardShowing() const
CYIUrl m_accessoryImageUrl
Definition: YiKeyboardInputBridge.h:231
Receiver()
Definition: YiKeyboardInputBridge.h:226
InputType
The preferred input type.
Definition: YiKeyboardInputBridge.h:41