• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 IMFAdapterEnterKeyType { UNSPECIFIED = 0, NONE, GO, SEARCH, SEND, NEXT, DONE, PREVIOUS };
35 
36 enum class IMFAdapterDirection {
37     NONE = 0,
38     UP = 1,
39     DOWN,
40     LEFT,
41     RIGHT,
42 };
43 
44 struct IMFAdapterCursorInfo {
45     double left = 0.0;
46     double top = 0.0;
47     double width = 0.0;
48     double height = 0.0;
49 };
50 
51 struct IMFAdapterInputAttribute {
52     int32_t inputPattern = 0;
53     int32_t enterKeyType = 0;
54 };
55 
56 struct IMFAdapterSelectionRange {
57     int32_t start = -1;
58     int32_t end = -1;
59 };
60 
61 struct IMFAdapterTextConfig {
62     IMFAdapterInputAttribute inputAttribute = {};
63     IMFAdapterCursorInfo cursorInfo = {};
64     IMFAdapterSelectionRange range = {};
65     uint32_t windowId = -1;
66 };
67 
68 enum class IMFAdapterKeyboardStatus : int32_t { NONE = 0, HIDE, SHOW };
69 
70 class IMFAdapterFunctionKey {
71 public:
GetEnterKeyType()72     IMFAdapterEnterKeyType GetEnterKeyType() const
73     {
74         return enterKeyType;
75     }
76 
SetEnterKeyType(IMFAdapterEnterKeyType keyType)77     void SetEnterKeyType(IMFAdapterEnterKeyType keyType)
78     {
79         enterKeyType = keyType;
80     }
81 
82 private:
83     IMFAdapterEnterKeyType enterKeyType = IMFAdapterEnterKeyType::UNSPECIFIED;
84 };
85 
86 class IMFTextListenerAdapter {
87 public:
88     IMFTextListenerAdapter() = default;
89 
90     virtual ~IMFTextListenerAdapter() = default;
91 
92     virtual void InsertText(const std::u16string &text) = 0;
93 
94     virtual void DeleteForward(int32_t length) = 0;
95 
96     virtual void DeleteBackward(int32_t length) = 0;
97 
98     virtual void SendKeyEventFromInputMethod() = 0;
99 
100     virtual void SendKeyboardStatus(const IMFAdapterKeyboardStatus& keyboardStatus) = 0;
101 
102     virtual void SendFunctionKey(const IMFAdapterFunctionKey& functionKey) = 0;
103 
104     virtual void SetKeyboardStatus(bool status) = 0;
105 
106     virtual void MoveCursor(const IMFAdapterDirection direction) = 0;
107 
108     virtual void HandleSetSelection(int32_t start, int32_t end) = 0;
109 
110     virtual void HandleExtendAction(int32_t action) = 0;
111 
112     virtual void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) = 0;
113 
114     virtual int32_t GetTextIndexAtCursor() = 0;
115 
116     virtual std::u16string GetLeftTextOfCursor(int32_t number) = 0;
117 
118     virtual std::u16string GetRightTextOfCursor(int32_t number) = 0;
119 };
120 
121 class IMFAdapter {
122 public:
123     IMFAdapter() = default;
124 
125     virtual ~IMFAdapter() = default;
126 
127     virtual bool Attach(std::shared_ptr<IMFTextListenerAdapter> listener, bool isShowKeyboard) = 0;
128 
129     virtual bool Attach(
130         std::shared_ptr<IMFTextListenerAdapter> listener, bool isShowKeyboard, const IMFAdapterTextConfig& config) = 0;
131 
132     virtual void ShowCurrentInput(const IMFAdapterTextInputType &inputType) = 0;
133 
134     virtual void HideTextInput() = 0;
135 
136     virtual void Close() = 0;
137 
138     virtual void OnCursorUpdate(IMFAdapterCursorInfo cursorInfo) = 0;
139 
140     virtual void OnSelectionChange(std::u16string text, int start, int end) = 0;
141 };
142 } // namespace OHOS::NWeb
143 
144 #endif // IMF_ADAPTER_H
145