1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef IMF_ADAPTER_H 17 #define IMF_ADAPTER_H 18 19 #include <memory> 20 #include <string> 21 22 namespace OHOS::NWeb { 23 enum class IMFAdapterTextInputType : int32_t { 24 NONE = -1, 25 TEXT = 0, 26 MULTILINE, 27 NUMBER, 28 PHONE, 29 DATETIME, 30 EMAIL_ADDRESS, 31 URL, 32 VISIBLE_PASSWORD, 33 NUMBER_PASSWORD, 34 SCREEN_LOCK_PASSWORD, 35 USER_NAME, 36 NEW_PASSWORD, 37 NUMBER_DECIMAL, 38 }; 39 40 enum class IMFAdapterEnterKeyType : int32_t { 41 UNSPECIFIED = 0, 42 NONE, 43 GO, 44 SEARCH, 45 SEND, 46 NEXT, 47 DONE, 48 PREVIOUS, 49 NEW_LINE, 50 }; 51 52 enum class IMFAdapterDirection : int32_t { 53 NONE = 0, 54 UP = 1, 55 DOWN, 56 LEFT, 57 RIGHT, 58 }; 59 60 class IMFCursorInfoAdapter { 61 public: 62 IMFCursorInfoAdapter() = default; 63 64 virtual ~IMFCursorInfoAdapter() = default; 65 66 virtual double GetLeft() = 0; 67 68 virtual double GetTop() = 0; 69 70 virtual double GetWidth() = 0; 71 72 virtual double GetHeight() = 0; 73 }; 74 75 class IMFInputAttributeAdapter { 76 public: 77 IMFInputAttributeAdapter() = default; 78 79 virtual ~IMFInputAttributeAdapter() = default; 80 81 virtual int32_t GetInputPattern() = 0; 82 83 virtual int32_t GetEnterKeyType() = 0; 84 }; 85 86 class IMFSelectionRangeAdapter { 87 public: 88 IMFSelectionRangeAdapter() = default; 89 90 virtual ~IMFSelectionRangeAdapter() = default; 91 92 virtual int32_t GetStart() = 0; 93 94 virtual int32_t GetEnd() = 0; 95 }; 96 97 class IMFTextConfigAdapter { 98 public: 99 IMFTextConfigAdapter() = default; 100 101 virtual ~IMFTextConfigAdapter() = default; 102 103 virtual std::shared_ptr<IMFInputAttributeAdapter> GetInputAttribute() = 0; 104 105 virtual std::shared_ptr<IMFCursorInfoAdapter> GetCursorInfo() = 0; 106 107 virtual std::shared_ptr<IMFSelectionRangeAdapter> GetSelectionRange() = 0; 108 109 virtual uint32_t GetWindowId() = 0; 110 GetPositionY()111 virtual double GetPositionY() 112 { 113 return 0.0; 114 } 115 GetHeight()116 virtual double GetHeight() 117 { 118 return 0.0; 119 } 120 }; 121 122 enum class IMFAdapterKeyboardStatus : int32_t { NONE = 0, HIDE, SHOW }; 123 124 class IMFAdapterFunctionKeyAdapter { 125 public: 126 IMFAdapterFunctionKeyAdapter() = default; 127 128 virtual ~IMFAdapterFunctionKeyAdapter() = default; 129 130 virtual IMFAdapterEnterKeyType GetEnterKeyType() = 0; 131 }; 132 133 class IMFTextListenerAdapter { 134 public: 135 IMFTextListenerAdapter() = default; 136 137 virtual ~IMFTextListenerAdapter() = default; 138 139 virtual void InsertText(const std::u16string& text) = 0; 140 141 virtual void DeleteForward(int32_t length) = 0; 142 143 virtual void DeleteBackward(int32_t length) = 0; 144 145 virtual void SendKeyEventFromInputMethod() = 0; 146 147 virtual void SendKeyboardStatus(const IMFAdapterKeyboardStatus& keyboardStatus) = 0; 148 149 virtual void SendFunctionKey(std::shared_ptr<IMFAdapterFunctionKeyAdapter> functionKey) = 0; 150 151 virtual void SetKeyboardStatus(bool status) = 0; 152 153 virtual void MoveCursor(const IMFAdapterDirection direction) = 0; 154 155 virtual void HandleSetSelection(int32_t start, int32_t end) = 0; 156 157 virtual void HandleExtendAction(int32_t action) = 0; 158 159 virtual void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) = 0; 160 161 virtual int32_t GetTextIndexAtCursor() = 0; 162 163 virtual std::u16string GetLeftTextOfCursor(int32_t number) = 0; 164 165 virtual std::u16string GetRightTextOfCursor(int32_t number) = 0; 166 167 virtual int32_t SetPreviewText(const std::u16string& text, int32_t start, int32_t end) = 0; 168 169 virtual void FinishTextPreview() = 0; 170 171 virtual void SetNeedUnderLine(bool isNeedUnderline) = 0; 172 AutoFillWithIMFEvent(bool isUsername,bool isOtherAccount,bool isNewPassword,const std::string & content)173 virtual void AutoFillWithIMFEvent(bool isUsername, bool isOtherAccount, bool isNewPassword, 174 const std::string& content) {} 175 KeyboardUpperRightCornerHide()176 virtual void KeyboardUpperRightCornerHide() {}; 177 }; 178 179 class IMFAdapter { 180 public: 181 IMFAdapter() = default; 182 183 virtual ~IMFAdapter() = default; 184 185 virtual bool Attach(std::shared_ptr<IMFTextListenerAdapter> listener, bool isShowKeyboard) = 0; 186 187 virtual bool Attach(std::shared_ptr<IMFTextListenerAdapter> listener, bool isShowKeyboard, 188 const std::shared_ptr<IMFTextConfigAdapter> config, bool isResetListener) = 0; 189 190 virtual bool AttachWithRequestKeyboardReason(std::shared_ptr<IMFTextListenerAdapter> listener, bool isShowKeyboard, 191 const std::shared_ptr<IMFTextConfigAdapter> config, bool isResetListener, int32_t requestKeyboardReason) = 0; 192 193 virtual void ShowCurrentInput(const IMFAdapterTextInputType& inputType) = 0; 194 195 virtual void HideTextInput() = 0; 196 197 virtual void Close() = 0; 198 199 virtual void OnCursorUpdate(const std::shared_ptr<IMFCursorInfoAdapter> cursorInfo) = 0; 200 201 virtual void OnSelectionChange(std::u16string text, int start, int end) = 0; 202 SendPrivateCommand(const std::string & commandKey,const std::string & commandValue)203 virtual bool SendPrivateCommand(const std::string& commandKey, const std::string& commandValue) 204 { 205 return false; 206 } 207 }; 208 209 } // namespace OHOS::NWeb 210 211 #endif // IMF_ADAPTER_H 212