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 #ifndef INTERFACE_KITS_JS_GET_INPUT_METHOD_TEXTCHANGE_LISTENER_H 16 #define INTERFACE_KITS_JS_GET_INPUT_METHOD_TEXTCHANGE_LISTENER_H 17 18 #include "input_method_controller.h" 19 namespace OHOS { 20 namespace MiscServices { 21 class JsGetInputMethodController; 22 class JsGetInputMethodTextChangedListener : public OnTextChangedListener { 23 public: 24 explicit JsGetInputMethodTextChangedListener(const std::shared_ptr<AppExecFwk::EventHandler> &handler); 25 ~JsGetInputMethodTextChangedListener() override; 26 static sptr<JsGetInputMethodTextChangedListener> GetTextListener( 27 const std::shared_ptr<AppExecFwk::EventHandler> &handler, bool newEditBox = false); 28 29 void InsertText(const std::u16string &text) override; 30 void DeleteForward(int32_t length) override; 31 void DeleteBackward(int32_t length) override; SendKeyEventFromInputMethod(const KeyEvent & event)32 void SendKeyEventFromInputMethod(const KeyEvent &event) override 33 { 34 } 35 void SendKeyboardStatus(const KeyboardStatus &status) override; 36 void SendFunctionKey(const FunctionKey &functionKey) override; SetKeyboardStatus(bool status)37 void SetKeyboardStatus(bool status) override 38 { 39 } 40 void MoveCursor(const Direction direction) override; HandleSetSelection(int32_t start,int32_t end)41 void HandleSetSelection(int32_t start, int32_t end) override 42 { 43 } 44 void HandleExtendAction(int32_t action) override; HandleSelect(int32_t keyCode,int32_t cursorMoveSkip)45 void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override 46 { 47 } 48 std::u16string GetLeftTextOfCursor(int32_t number) override; 49 std::u16string GetRightTextOfCursor(int32_t number) override; 50 int32_t GetTextIndexAtCursor() override; 51 int32_t ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override; 52 bool IsFromTs() override; 53 int32_t SetPreviewText(const std::u16string &text, const Range &range) override; 54 void FinishTextPreview() override; 55 std::shared_ptr<AppExecFwk::EventHandler> GetEventHandler() override; 56 57 private: 58 static std::mutex listenerMutex_; 59 static sptr<JsGetInputMethodTextChangedListener> inputMethodListener_; 60 std::mutex handlerMutex_; 61 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 62 }; 63 } // namespace MiscServices 64 } // namespace OHOS 65 #endif // INTERFACE_KITS_JS_GET_INPUT_METHOD_TEXTCHANGE_LISTENER_H