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