InputHandler.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef InputHandler_h
  19. #define InputHandler_h
  20. #include "FloatPoint.h"
  21. #include "TextChecking.h"
  22. #include <BlackBerryPlatformInputEvents.h>
  23. #include <BlackBerryPlatformMisc.h>
  24. #include <BlackBerryPlatformSettings.h>
  25. #include <imf/events.h>
  26. #include <imf/input_data.h>
  27. #include <map>
  28. #include <pthread.h>
  29. #include <wtf/RefPtr.h>
  30. namespace WTF {
  31. class String;
  32. }
  33. namespace WebCore {
  34. class AttributeTextStyle;
  35. class Element;
  36. class Frame;
  37. class HTMLInputElement;
  38. class HTMLSelectElement;
  39. class IntRect;
  40. class Node;
  41. class Range;
  42. class SpellChecker;
  43. class SpellCheckRequest;
  44. class TextCheckingRequest;
  45. class VisiblePosition;
  46. class VisibleSelection;
  47. class SuggestionBoxHandler;
  48. }
  49. namespace BlackBerry {
  50. namespace Platform {
  51. class IntPoint;
  52. class KeyboardEvent;
  53. }
  54. namespace WebKit {
  55. class SpellingHandler;
  56. class WebPagePrivate;
  57. class InputHandler {
  58. public:
  59. InputHandler(WebPagePrivate*);
  60. ~InputHandler();
  61. enum FocusElementType { TextEdit, TextPopup /* Date/Time & Color */, SelectPopup, Plugin };
  62. enum CaretScrollType {
  63. CenterAlways = BlackBerry::Platform::Settings::ScrollAdjustmentCenterAlways,
  64. CenterIfNeeded = BlackBerry::Platform::Settings::ScrollAdjustmentCenterIfNeeded,
  65. EdgeIfNeeded = BlackBerry::Platform::Settings::ScrollAdjustmentEdgeIfNeeded
  66. };
  67. bool isInputModeEnabled() const;
  68. void setInputModeEnabled(bool active = true);
  69. void focusedNodeChanged();
  70. void nodeTextChanged(const WebCore::Node*);
  71. void selectionChanged();
  72. void frameUnloaded(const WebCore::Frame*);
  73. bool handleKeyboardInput(const BlackBerry::Platform::KeyboardEvent&, bool changeIsPartOfComposition = false);
  74. bool deleteSelection();
  75. void insertText(const WTF::String&);
  76. void clearField();
  77. void cut();
  78. void copy();
  79. void paste();
  80. void selectAll();
  81. void cancelSelection();
  82. void setInputValue(const WTF::String&);
  83. void focusNextField();
  84. void focusPreviousField();
  85. void submitForm();
  86. void setDelayKeyboardVisibilityChange(bool value);
  87. void processPendingKeyboardVisibilityChange();
  88. void notifyClientOfKeyboardVisibilityChange(bool visible, bool triggeredByFocusChange = false);
  89. bool isInputMode() const { return isActiveTextEdit(); }
  90. bool isMultilineInputMode() const { return isActiveTextEdit() && elementType(m_currentFocusElement.get()) == BlackBerry::Platform::InputTypeTextArea; }
  91. PassRefPtr<WebCore::Element> currentFocusElement() const { return m_currentFocusElement; }
  92. void ensureFocusElementVisible(bool centerFieldInDisplay = true);
  93. // PopupMenu methods.
  94. bool willOpenPopupForNode(WebCore::Node*);
  95. bool didNodeOpenPopup(WebCore::Node*);
  96. bool openLineInputPopup(WebCore::HTMLInputElement*);
  97. bool openSelectPopup(WebCore::HTMLSelectElement*);
  98. void setPopupListIndex(int);
  99. void setPopupListIndexes(int size, const bool* selecteds);
  100. bool processingChange() const { return m_processingChange; }
  101. void setProcessingChange(bool);
  102. WTF::String elementText();
  103. WebCore::IntRect boundingBoxForInputField();
  104. bool isCaretAtEndOfText();
  105. // IMF driven calls.
  106. bool setBatchEditingActive(bool);
  107. bool setSelection(int start, int end, bool changeIsPartOfComposition = false);
  108. int caretPosition() const;
  109. bool deleteTextRelativeToCursor(int leftOffset, int rightOffset);
  110. spannable_string_t* selectedText(int32_t flags);
  111. spannable_string_t* textBeforeCursor(int32_t length, int32_t flags);
  112. spannable_string_t* textAfterCursor(int32_t length, int32_t flags);
  113. extracted_text_t* extractedTextRequest(extracted_text_request_t*, int32_t flags);
  114. int32_t setComposingRegion(int32_t start, int32_t end);
  115. int32_t finishComposition();
  116. int32_t setComposingText(spannable_string_t*, int32_t relativeCursorPosition);
  117. int32_t commitText(spannable_string_t*, int32_t relativeCursorPosition);
  118. void requestCheckingOfString(PassRefPtr<WebCore::SpellCheckRequest>);
  119. void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*);
  120. void stopPendingSpellCheckRequests(bool isRestartRequired = false);
  121. void spellCheckTextBlock(WebCore::Element* = 0);
  122. bool shouldRequestSpellCheckingOptionsForPoint(const Platform::IntPoint& documentContentPosition, const WebCore::Element*, imf_sp_text_t&);
  123. void requestSpellingCheckingOptions(imf_sp_text_t&, WebCore::IntSize& screenOffset, const bool shouldMoveDialog = false);
  124. void clearDidSpellCheckState() { m_didSpellCheckWord = false; }
  125. void redrawSpellCheckDialogIfRequired(const bool shouldMoveDialog = true);
  126. void callRequestCheckingFor(PassRefPtr<WebCore::SpellCheckRequest>);
  127. void setSystemSpellCheckStatus(bool enabled) { m_spellCheckStatusConfirmed = true; m_globalSpellCheckStatus = enabled; }
  128. void elementTouched(WebCore::Element*);
  129. void restoreViewState();
  130. private:
  131. enum PendingKeyboardStateChange { NoChange, Visible, NotVisible };
  132. void setElementFocused(WebCore::Element*);
  133. void setPluginFocused(WebCore::Element*);
  134. void setElementUnfocused(bool refocusOccuring = false);
  135. void ensureFocusTextElementVisible(CaretScrollType = CenterAlways);
  136. void ensureFocusPluginElementVisible();
  137. void clearCurrentFocusElement();
  138. bool selectionAtStartOfElement();
  139. bool selectionAtEndOfElement();
  140. WebCore::IntRect rectForCaret(int index);
  141. bool isActiveTextEdit() const { return m_currentFocusElement && m_currentFocusElementType == TextEdit; }
  142. bool isActiveTextPopup() const { return m_currentFocusElement && m_currentFocusElementType == TextPopup; }
  143. bool isActiveSelectPopup() const { return m_currentFocusElement && m_currentFocusElementType == SelectPopup; }
  144. bool isActivePlugin() const { return m_currentFocusElement && m_currentFocusElementType == Plugin; }
  145. bool openDatePopup(WebCore::HTMLInputElement*, BlackBerry::Platform::BlackBerryInputType);
  146. bool openColorPopup(WebCore::HTMLInputElement*);
  147. bool executeTextEditCommand(const WTF::String&);
  148. BlackBerry::Platform::BlackBerryInputType elementType(WebCore::Element*) const;
  149. int selectionStart() const;
  150. int selectionEnd() const;
  151. int selectionPosition(bool start) const;
  152. bool selectionActive() const { return selectionStart() != selectionEnd(); }
  153. bool compositionActive() const { return compositionLength(); }
  154. unsigned compositionLength() const { return m_composingTextEnd - m_composingTextStart; }
  155. spannable_string_t* spannableTextInRange(int start, int end, int32_t flags);
  156. void addAttributedTextMarker(int start, int end, const WebCore::AttributeTextStyle&);
  157. void removeAttributedTextMarker();
  158. bool deleteText(int start, int end);
  159. bool setTextAttributes(int insertionPoint, spannable_string_t*);
  160. bool setText(spannable_string_t*);
  161. bool setSpannableTextAndRelativeCursor(spannable_string_t*, int relativeCursorPosition, bool markTextAsComposing);
  162. bool removeComposedText();
  163. bool setRelativeCursorPosition(int insertionPoint, int relativeCursorPosition);
  164. bool setCursorPosition(int location);
  165. span_t* firstSpanInString(spannable_string_t*, SpannableStringAttribute);
  166. bool isTrailingSingleCharacter(span_t*, unsigned, unsigned);
  167. void learnText();
  168. void sendLearnTextDetails(const WTF::String&);
  169. WebCore::SpellChecker* getSpellChecker();
  170. bool shouldSpellCheckElement(const WebCore::Element*) const;
  171. bool didSpellCheckWord() const { return m_didSpellCheckWord; }
  172. void updateFormState();
  173. bool shouldNotifyWebView(const Platform::KeyboardEvent&);
  174. void showTextInputTypeSuggestionBox(bool allowEmptyPrefix = false);
  175. void hideTextInputTypeSuggestionBox();
  176. bool isNavigationKey(unsigned character) const;
  177. WebPagePrivate* m_webPage;
  178. RefPtr<WebCore::Element> m_currentFocusElement;
  179. RefPtr<WebCore::Element> m_previousFocusableTextElement;
  180. RefPtr<WebCore::Element> m_nextFocusableTextElement;
  181. bool m_hasSubmitButton;
  182. bool m_inputModeEnabled;
  183. bool m_processingChange;
  184. bool m_shouldEnsureFocusTextElementVisibleOnSelectionChanged;
  185. FocusElementType m_currentFocusElementType;
  186. int64_t m_currentFocusElementTextEditMask;
  187. int m_composingTextStart;
  188. int m_composingTextEnd;
  189. PendingKeyboardStateChange m_pendingKeyboardVisibilityChange;
  190. bool m_delayKeyboardVisibilityChange;
  191. RefPtr<WebCore::SpellCheckRequest> m_request;
  192. int32_t m_processingTransactionId;
  193. bool m_shouldNotifyWebView;
  194. unsigned m_expectedKeyUpChar;
  195. imf_sp_text_t m_spellCheckingOptionsRequest;
  196. WebCore::IntSize m_screenOffset;
  197. bool m_didSpellCheckWord;
  198. SpellingHandler* m_spellingHandler;
  199. bool m_spellCheckStatusConfirmed;
  200. bool m_globalSpellCheckStatus;
  201. int m_minimumSpellCheckingRequestSequence;
  202. OwnPtr<WebCore::SuggestionBoxHandler> m_suggestionDropdownBoxHandler;
  203. bool m_elementTouchedIsCrossFrame;
  204. DISABLE_COPY(InputHandler);
  205. };
  206. }
  207. }
  208. #endif // InputHandler_h