1 /* 2 * Copyright (C) 2021-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 FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_METHOD_UTILS_H 17 #define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_METHOD_UTILS_H 18 19 #include <stdint.h> 20 21 #include "input_attribute.h" 22 23 namespace OHOS { 24 namespace MiscServices { 25 constexpr uint32_t INIT_WINDOW_ID = 0; 26 constexpr uint32_t INVALID_WINDOW_ID = INIT_WINDOW_ID - 1; 27 constexpr int32_t INVALID_VALUE = -1; 28 enum class EnterKeyType { UNSPECIFIED = 0, NONE, GO, SEARCH, SEND, NEXT, DONE, PREVIOUS }; 29 30 enum class TextInputType { 31 NONE = -1, 32 TEXT = 0, 33 MULTILINE, 34 NUMBER, 35 PHONE, 36 DATETIME, 37 EMAIL_ADDRESS, 38 URL, 39 VISIBLE_PASSWORD, 40 }; 41 42 enum class Direction { 43 NONE = 0, 44 UP = 1, 45 DOWN, 46 LEFT, 47 RIGHT, 48 }; 49 50 enum class ExtendAction { 51 SELECT_ALL = 0, 52 CUT = 3, 53 COPY, 54 PASTE, 55 }; 56 57 class Configuration { 58 public: GetEnterKeyType()59 EnterKeyType GetEnterKeyType() const 60 { 61 return enterKeyType; 62 } 63 SetEnterKeyType(EnterKeyType keyType)64 void SetEnterKeyType(EnterKeyType keyType) 65 { 66 enterKeyType = keyType; 67 } 68 GetTextInputType()69 TextInputType GetTextInputType() const 70 { 71 return textInputType; 72 } 73 SetTextInputType(TextInputType textType)74 void SetTextInputType(TextInputType textType) 75 { 76 textInputType = textType; 77 } 78 79 private: 80 EnterKeyType enterKeyType = EnterKeyType::UNSPECIFIED; 81 TextInputType textInputType = TextInputType::TEXT; 82 }; 83 84 struct CursorInfo { 85 double left = -1.0; 86 double top = -1.0; 87 double width = -1.0; 88 double height = -1.0; 89 bool operator==(const CursorInfo &info) const 90 { 91 return (left == info.left && top == info.top && width == info.width && height == info.height); 92 } 93 }; 94 95 class KeyEvent { 96 }; 97 98 enum class KeyboardStatus { NONE = 0, HIDE, SHOW }; 99 100 class FunctionKey { 101 public: GetEnterKeyType()102 EnterKeyType GetEnterKeyType() const 103 { 104 return enterKeyType; 105 } 106 SetEnterKeyType(EnterKeyType keyType)107 void SetEnterKeyType(EnterKeyType keyType) 108 { 109 enterKeyType = keyType; 110 } 111 112 private: 113 EnterKeyType enterKeyType = EnterKeyType::UNSPECIFIED; 114 }; 115 116 struct SelectionRange { 117 int32_t start = INVALID_VALUE; 118 int32_t end = INVALID_VALUE; 119 }; 120 121 struct TextSelection { 122 int32_t oldBegin = INVALID_VALUE; 123 int32_t oldEnd = INVALID_VALUE; 124 int32_t newBegin = INVALID_VALUE; 125 int32_t newEnd = INVALID_VALUE; 126 }; 127 128 class TextTotalConfig { 129 public: 130 InputAttribute inputAttribute = {}; 131 CursorInfo cursorInfo = {}; 132 TextSelection textSelection = {}; 133 uint32_t windowId = INVALID_WINDOW_ID; 134 }; 135 136 struct TextConfig { 137 InputAttribute inputAttribute = {}; 138 CursorInfo cursorInfo = {}; 139 SelectionRange range = {}; 140 uint32_t windowId = INVALID_WINDOW_ID; 141 }; 142 } // namespace MiscServices 143 } // namespace OHOS 144 #endif // FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_METHOD_UTILS_H 145