1 /*
2  * Copyright (c) 2024 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 #ifndef NATIVE_TEXT_CHANGED_LISTENER_H
16 #define NATIVE_TEXT_CHANGED_LISTENER_H
17 #include "input_method_controller.h"
18 #include "native_inputmethod_types.h"
19 namespace OHOS {
20 namespace MiscServices {
21 class NativeTextChangedListener : public OHOS::MiscServices::OnTextChangedListener {
22 public:
NativeTextChangedListener(InputMethod_TextEditorProxy * textEditor)23     explicit NativeTextChangedListener(InputMethod_TextEditorProxy *textEditor) : textEditor_(textEditor) {};
~NativeTextChangedListener()24     ~NativeTextChangedListener() {};
25     void InsertText(const std::u16string &text) override;
26     void DeleteForward(int32_t length) override;
27     void DeleteBackward(int32_t length) override;
28     void SendKeyboardStatus(const OHOS::MiscServices::KeyboardStatus &status) override;
29     void SendFunctionKey(const OHOS::MiscServices::FunctionKey &functionKey) override;
30     void MoveCursor(const OHOS::MiscServices::Direction direction) override;
31     void HandleSetSelection(int32_t start, int32_t end) override;
32     void HandleExtendAction(int32_t action) override;
33     std::u16string GetLeftTextOfCursor(int32_t number) override;
34     std::u16string GetRightTextOfCursor(int32_t number) override;
35     int32_t GetTextIndexAtCursor() override;
36     int32_t ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
37     int32_t SetPreviewText(const std::u16string &text, const OHOS::MiscServices::Range &range) override;
38     void FinishTextPreview() override;
39     void OnDetach() override;
40 
41     // empty impl
SendKeyEventFromInputMethod(const KeyEvent & event)42     void SendKeyEventFromInputMethod(const KeyEvent &event) override {};
SetKeyboardStatus(bool status)43     void SetKeyboardStatus(bool status) override {};
HandleSelect(int32_t keyCode,int32_t cursorMoveSkip)44     void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override {};
45 
46 private:
47     InputMethod_KeyboardStatus ConvertToCKeyboardStatus(OHOS::MiscServices::KeyboardStatus status);
48     InputMethod_EnterKeyType ConvertToCEnterKeyType(OHOS::MiscServices::EnterKeyType enterKeyType);
49     InputMethod_Direction ConvertToCDirection(OHOS::MiscServices::Direction direction);
50     InputMethod_ExtendAction ConvertToCExtendAction(int32_t action);
51     InputMethod_TextEditorProxy *textEditor_;
52 };
53 } // namespace MiscServices
54 } // namespace OHOS
55 #endif // NATIVE_TEXT_CHANGED_LISTENE_H