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 IMF_ADAPTER_IMPL_H 17 #define IMF_ADAPTER_IMPL_H 18 19 #include "imf_adapter.h" 20 #include "input_method_controller.h" 21 22 namespace OHOS::NWeb { 23 class IMFTextListenerAdapterImpl : public MiscServices::OnTextChangedListener { 24 public: 25 explicit IMFTextListenerAdapterImpl(const std::shared_ptr<IMFTextListenerAdapter> &listener); 26 27 ~IMFTextListenerAdapterImpl(); 28 29 void InsertText(const std::u16string &text) override; 30 31 void DeleteForward(int32_t length) override; 32 33 void DeleteBackward(int32_t length) override; 34 35 void SendKeyEventFromInputMethod(const MiscServices::KeyEvent &event) override; 36 37 void SendKeyboardInfo(const MiscServices::KeyboardInfo &info) override; 38 39 void SetKeyboardStatus(bool status) override; 40 41 void MoveCursor(const MiscServices::Direction direction) override; 42 43 void HandleSetSelection(int32_t start, int32_t end) override; 44 45 void HandleExtendAction(int32_t action) override; 46 47 void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override; 48 49 private: 50 std::shared_ptr<IMFTextListenerAdapter> listener_ = nullptr; 51 }; 52 53 class IMFAdapterImpl : public IMFAdapter { 54 public: 55 IMFAdapterImpl() = default; 56 57 ~IMFAdapterImpl() override = default; 58 59 bool Attach(std::shared_ptr<IMFTextListenerAdapter> listener, bool isShowKeyboard) override; 60 61 void ShowCurrentInput(const IMFAdapterTextInputType &inputType) override; 62 63 void HideTextInput() override; 64 65 void Close() override; 66 67 void OnCursorUpdate(IMFAdapterCursorInfo cursorInfo) override; 68 69 void OnSelectionChange(std::u16string text, int start, int end) override; 70 71 private: 72 sptr<MiscServices::OnTextChangedListener> textListener_ = nullptr; 73 }; 74 } // namespace OHOS::NWeb 75 76 #endif // IMF_ADAPTER_IMPL_H 77