• 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 FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_ABILITY_INTERFACE_H
17 #define FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_ABILITY_INTERFACE_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 
23 #include "input_method_engine_listener.h"
24 #include "keyboard_listener.h"
25 #include "input_method_types.h"
26 
27 namespace OHOS {
28 namespace MiscServices {
29 class InputMethodAbilityInterface {
30 public:
31     static InputMethodAbilityInterface &GetInstance();
32     int32_t RegisteredProxy();
33     int32_t UnRegisteredProxy(UnRegisteredType type);
34     /**
35      * @brief Register the proxy input method to input method service with displayId.
36      *
37      * This function can be successfully invoked only when the related feature is enabled.
38      *
39      * @param displayId Indicates the ID of the display where the proxy input method is located.
40      * @return Returns 0 for success, others for failure.
41      * @since 18
42      */
43     int32_t RegisterProxyIme(uint64_t displayId);
44     /**
45      * @brief Unregister proxy input method.
46      *
47      * This function can be successfully invoked only when the related feature is enabled.
48      *
49      * @param displayId Indicates the ID of the display where the proxy input method is located.
50      * @return Returns 0 for success, others for failure.
51      * @since 18
52      */
53     int32_t UnregisterProxyIme(uint64_t displayId);
54     /**
55      * @brief Bind the input method mirror to the current input session.
56      *
57      * After binding the input method mirror (ime mirror), it can perceive content changes in the current edit box,
58      * but **cannot actively input content into the edit box**.
59      * Once bound successfully, the mirror function will start receiving status information such as text updates
60      * and cursor position changes from the edit box.
61      * This interface can only be called successfully when the relevant feature is enabled.
62      *
63      * @return Returns 0 for success, other values for failure.
64      * @note The input method mirror only has content perception capability and does not support active input operations
65      * such as inserting or deleting text.
66      */
67     int32_t BindImeMirror();
68 
69     /**
70      * @brief Unbind the input method mirror from the current input session.
71      *
72      * After unbinding, the input method mirror will stop perceiving content changes in the edit box and
73      * will no longer receive any status information from the edit box.
74      * This interface can only be called successfully when the relevant feature is enabled.
75      *
76      * @return Returns 0 for success, other values for failure.
77      * @note If you need to re-perceive the edit box content after unbinding, you must call {@link BindImeMirror} again.
78      */
79     int32_t UnbindImeMirror();
80     int32_t InsertText(const std::string &text);
81     int32_t DeleteForward(int32_t length);
82     int32_t DeleteBackward(int32_t length);
83     int32_t MoveCursor(int32_t keyCode);
84     int32_t GetInputAttribute(InputAttribute &attribute);
85     int32_t SendFunctionKey(int32_t funcKey);
86     void SetImeListener(std::shared_ptr<InputMethodEngineListener> imeListener);
87     void SetKdListener(std::shared_ptr<KeyboardListener> kdListener);
88     int32_t SelectByRange(int32_t start, int32_t end);
89 
90 private:
91     InputMethodAbilityInterface() = default;
92 };
93 } // namespace MiscServices
94 } // namespace OHOS
95 #endif // FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_ABILITY_INTERFACE_H
96