• 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 INPUTMETHOD_TEST_TEXT_LISTENER_H
17 #define INPUTMETHOD_TEST_TEXT_LISTENER_H
18 
19 #include <condition_variable>
20 #include <unistd.h>
21 
22 #include "input_method_controller.h"
23 #include "input_method_utils.h"
24 #include "key_event.h"
25 #include "string_ex.h"
26 
27 namespace OHOS {
28 namespace MiscServices {
29 class TextListener : public OnTextChangedListener {
30 public:
31     TextListener();
32     ~TextListener();
33     void InsertText(const std::u16string &text) override;
34     void DeleteForward(int32_t length) override;
35     void DeleteBackward(int32_t length) override;
36     void SendKeyEventFromInputMethod(const KeyEvent &event) override;
37     void SendKeyboardStatus(const KeyboardStatus &keyboardStatus) override;
38     void SendFunctionKey(const FunctionKey &functionKey) override;
39     void SetKeyboardStatus(bool status) override;
40     void MoveCursor(const Direction direction) override;
41     void HandleSetSelection(int32_t start, int32_t end) override;
42     void HandleExtendAction(int32_t action) override;
43     void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override;
44     void NotifyPanelStatusInfo(const PanelStatusInfo &info) override;
45     void NotifyKeyboardHeight(uint32_t height) override;
46     std::u16string GetLeftTextOfCursor(int32_t number) override;
47     std::u16string GetRightTextOfCursor(int32_t number) override;
48     int32_t GetTextIndexAtCursor() override;
49     int32_t ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
50     int32_t SetPreviewText(const std::u16string &text, const Range &range) override;
51     void FinishTextPreview() override;
52     static void ResetParam();
53     static bool WaitSendKeyboardStatusCallback(const KeyboardStatus &keyboardStatus);
54     static bool WaitNotifyPanelStatusInfoCallback(const PanelStatusInfo &info);
55     static bool WaitNotifyKeyboardHeightCallback(uint32_t height);
56     static bool WaitSendPrivateCommandCallback(std::unordered_map<std::string, PrivateDataValue> &privateCommand);
57     static bool WaitInsertText(const std::u16string &insertText);
58     static bool WaitMoveCursor(int32_t direction);
59     static bool WaitDeleteForward(int32_t length);
60     static bool WaitDeleteBackward(int32_t length);
61     static bool WaitSendFunctionKey(int32_t functionKey);
62     static bool WaitHandleExtendAction(int32_t action);
63     static bool WaitHandleSetSelection(int32_t start, int32_t end);
64     static bool WaitHandleSelect(int32_t keyCode, int32_t cursorMoveSkip);
65     static std::mutex textListenerCallbackLock_;
66     static std::condition_variable textListenerCv_;
67     static int32_t direction_;
68     static int32_t deleteForwardLength_;
69     static int32_t deleteBackwardLength_;
70     static std::u16string insertText_;
71     static int32_t key_;
72     static bool status_;
73     static int32_t selectionStart_;
74     static int32_t selectionEnd_;
75     static int32_t selectionDirection_;
76     static int32_t selectionSkip_;
77     static int32_t action_;
78     static uint32_t height_;
79     static KeyboardStatus keyboardStatus_;
80     static PanelStatusInfo info_;
81     std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
82     static constexpr int32_t TEXT_INDEX = 455;
83     static constexpr const char *TEXT_BEFORE_CURSOR = "before";
84     static constexpr const char *TEXT_AFTER_CURSOR = "after";
85     static std::unordered_map<std::string, PrivateDataValue> privateCommand_;
86     static std::string previewText_;
87     static Range previewRange_;
88     static bool isFinishTextPreviewCalled_;
89 };
90 } // namespace MiscServices
91 } // namespace OHOS
92 
93 #endif // INPUTMETHOD_TEST_TEXT_LISTENER_H
94