/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FM_IMC_PROJECT_INPUTMETHODCONTROLLER_H #define FM_IMC_PROJECT_INPUTMETHODCONTROLLER_H #include #include #include "input_data_channel_stub.h" #include "input_client_stub.h" #include "input_method_system_ability_proxy.h" #include "input_method_agent_proxy.h" #include "i_input_method_agent.h" #include "message_handler.h" #include "iremote_object.h" #include "input_method_utils.h" #include "key_event.h" namespace OHOS { namespace MiscServices { class InputDataChannelStub; class InputMethodSystemAbilityProxy; class OnTextChangedListener : public virtual RefBase { public: virtual void InsertText(const std::u16string& text) = 0; virtual void DeleteForward(int32_t length) = 0; virtual void DeleteBackward(int32_t length) = 0; virtual void SendKeyEventFromInputMethod(const KeyEvent& event) = 0; virtual void SendKeyboardInfo(const KeyboardInfo& info) = 0; virtual void SetKeyboardStatus(bool status) = 0; virtual void MoveCursor(const Direction direction) = 0; }; class ImsaDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit ImsaDeathRecipient(); ~ImsaDeathRecipient() = default; void OnRemoteDied(const wptr &object) override; }; class InputMethodController : public RefBase { public: static sptr GetInstance(); void Attach(sptr &listener); std::u16string GetTextBeforeCursor(); std::u16string GetTextAfterCursor(); void ShowTextInput(); void HideTextInput(); void Close(); void OnRemoteSaDied(const wptr &object); void OnCursorUpdate(CursorInfo cursorInfo); void OnSelectionChange(std::u16string text, int start, int end); void OnConfigurationChange(Configuration info); bool dispatchKeyEvent(std::shared_ptr keyEvent); private: InputMethodController(); ~InputMethodController(); bool Initialize(); sptr GetImsaProxy(); void PrepareInput(int32_t displayId, sptr &client, sptr &channel, InputAttribute &attribute); void StartInput(sptr &client); void StopInput(sptr &client); void ReleaseInput(sptr &client); void WorkThread(); sptr mInputDataChannel; sptr mClient; sptr mImms; sptr deathRecipient_; sptr mAgent; OnTextChangedListener *textListener; InputAttribute mAttribute; std::u16string mTextString; int mSelectOldBegin = 0; int mSelectOldEnd = 0; int mSelectNewBegin = 0; int mSelectNewEnd = 0; CursorInfo cursorInfo_; static std::mutex instanceLock_; static sptr instance_; std::thread workThreadHandler; MessageHandler *msgHandler; bool stop_; }; } } #endif