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 INPUT_METHOD_PANEL_H 17 #define INPUT_METHOD_PANEL_H 18 19 #include <cstdint> 20 #include <map> 21 #include <string> 22 23 #include "input_window_info.h" 24 #include "js_runtime_utils.h" 25 #include "panel_info.h" 26 #include "panel_status_listener.h" 27 #include "window.h" 28 29 namespace OHOS { 30 namespace MiscServices { 31 class InputMethodPanel { 32 public: 33 static constexpr uint32_t INVALID_WINDOW_ID = 0; 34 InputMethodPanel() = default; 35 ~InputMethodPanel(); 36 int32_t SetUiContent(const std::string &contentInfo, napi_env env, std::shared_ptr<NativeReference> contentStorage); 37 int32_t CreatePanel(const std::shared_ptr<AbilityRuntime::Context> &context, const PanelInfo &panelInfo); 38 int32_t DestroyPanel(); 39 40 int32_t Resize(uint32_t width, uint32_t height); 41 int32_t MoveTo(int32_t x, int32_t y); 42 int32_t ChangePanelFlag(PanelFlag panelFlag); 43 PanelType GetPanelType(); 44 PanelFlag GetPanelFlag(); 45 int32_t ShowPanel(); 46 int32_t HidePanel(); 47 void SetPanelStatusListener(std::shared_ptr<PanelStatusListener> statusListener, const std::string &type); 48 void ClearPanelListener(const std::string &type); 49 int32_t SetCallingWindow(uint32_t windowId); 50 int32_t SetPrivacyMode(bool isPrivacyMode); 51 bool IsShowing(); 52 int32_t SetTextFieldAvoidInfo(double positionY, double height); 53 uint32_t GetHeight(); 54 uint32_t windowId_ = INVALID_WINDOW_ID; 55 56 private: 57 bool IsHidden(); 58 int32_t SetPanelProperties(); 59 std::string GeneratePanelName(); 60 void PanelStatusChange(const InputWindowStatus &status); 61 bool MarkListener(const std::string &type, bool isRegister); 62 static uint32_t GenerateSequenceId(); 63 bool IsSizeValid(uint32_t width, uint32_t height); 64 65 sptr<OHOS::Rosen::Window> window_ = nullptr; 66 sptr<OHOS::Rosen::WindowOption> winOption_ = nullptr; 67 PanelType panelType_ = PanelType::SOFT_KEYBOARD; 68 PanelFlag panelFlag_ = PanelFlag::FLG_FIXED; 69 bool showRegistered_ = false; 70 bool hideRegistered_ = false; 71 uint32_t invalidGravityPercent = 0; 72 std::shared_ptr<PanelStatusListener> panelStatusListener_ = nullptr; 73 74 static std::atomic<uint32_t> sequenceId_; 75 std::mutex heightLock_; 76 uint32_t panelHeight_ = 0; 77 }; 78 } // namespace MiscServices 79 } // namespace OHOS 80 81 #endif //INPUT_METHOD_PANEL_H 82