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 <string> 20 21 namespace OHOS::NWeb { 22 enum class IMFAdapterTextInputType { 23 NONE = -1, 24 TEXT = 0, 25 MULTILINE, 26 NUMBER, 27 PHONE, 28 DATETIME, 29 EMAIL_ADDRESS, 30 URL, 31 VISIBLE_PASSWORD, 32 }; 33 34 enum class IMFAdapterDirection { 35 NONE = 0, 36 UP = 1, 37 DOWN, 38 LEFT, 39 RIGHT, 40 }; 41 42 struct IMFAdapterCursorInfo { 43 double left = 0.0; 44 double top = 0.0; 45 double width = 0.0; 46 double height = 0.0; 47 }; 48 49 enum class IMFAdapterKeyboardStatus : int32_t { NONE = 0, HIDE, SHOW }; 50 51 enum class IMFAdapterFunctionKey : int32_t { NONE = 0, CONFIRM }; 52 53 struct IMFAdapterKeyboardInfo { 54 IMFAdapterKeyboardStatus keyboardStatus = IMFAdapterKeyboardStatus::NONE; 55 IMFAdapterFunctionKey functionKey = IMFAdapterFunctionKey::NONE; 56 }; 57 58 class IMFTextListenerAdapter { 59 public: 60 IMFTextListenerAdapter() = default; 61 62 virtual ~IMFTextListenerAdapter() = default; 63 64 virtual void InsertText(const std::u16string &text) = 0; 65 66 virtual void DeleteForward(int32_t length) = 0; 67 68 virtual void DeleteBackward(int32_t length) = 0; 69 70 virtual void SendKeyEventFromInputMethod() = 0; 71 72 virtual void SendKeyboardInfo(const IMFAdapterKeyboardInfo &info) = 0; 73 74 virtual void SetKeyboardStatus(bool status) = 0; 75 76 virtual void MoveCursor(const IMFAdapterDirection direction) = 0; 77 78 virtual void HandleSetSelection(int32_t start, int32_t end) = 0; 79 80 virtual void HandleExtendAction(int32_t action) = 0; 81 82 virtual void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) = 0; 83 }; 84 85 class IMFAdapter { 86 public: 87 IMFAdapter() = default; 88 89 virtual ~IMFAdapter() = default; 90 91 virtual bool Attach(std::shared_ptr<IMFTextListenerAdapter> listener, bool isShowKeyboard) = 0; 92 93 virtual void ShowCurrentInput(const IMFAdapterTextInputType &inputType) = 0; 94 95 virtual void HideTextInput() = 0; 96 97 virtual void Close() = 0; 98 99 virtual void OnCursorUpdate(IMFAdapterCursorInfo cursorInfo) = 0; 100 101 virtual void OnSelectionChange(std::u16string text, int start, int end) = 0; 102 }; 103 } // namespace OHOS::NWeb 104 105 #endif // IMF_ADAPTER_H 106