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_status_listener.h" 26 #include "window.h" 27 28 namespace OHOS { 29 namespace MiscServices { 30 enum PanelType { 31 SOFT_KEYBOARD = 0, 32 STATUS_BAR, 33 }; 34 35 enum PanelFlag { 36 FLG_FIXED = 0, 37 FLG_FLOATING, 38 FLG_CANDIDATE_COLUMN, 39 }; 40 41 struct PanelInfo { 42 PanelType panelType = SOFT_KEYBOARD; 43 PanelFlag panelFlag = FLG_FIXED; 44 }; 45 46 class InputMethodPanel { 47 public: 48 InputMethodPanel() = default; 49 ~InputMethodPanel(); 50 int32_t SetUiContent(const std::string &contentInfo, NativeEngine &engine, 51 std::shared_ptr<NativeReference> contentStorage); 52 int32_t CreatePanel(const std::shared_ptr<AbilityRuntime::Context> &context, const PanelInfo &panelInfo); 53 int32_t DestroyPanel(); 54 55 int32_t Resize(uint32_t width, uint32_t height); 56 int32_t MoveTo(int32_t x, int32_t y); 57 int32_t ChangePanelFlag(PanelFlag panelFlag); 58 PanelType GetPanelType(); 59 PanelFlag GetPanelFlag(); 60 int32_t ShowPanel(); 61 int32_t HidePanel(); 62 void SetPanelStatusListener(std::shared_ptr<PanelStatusListener> statusListener, const std::string &type); 63 void ClearPanelListener(const std::string &type); 64 int32_t SetCallingWindow(uint32_t windowId); 65 uint32_t windowId_ = 0; 66 67 private: 68 bool IsShowing(); 69 bool IsHidden(); 70 int32_t SetPanelProperties(); 71 std::string GeneratePanelName(); 72 void PanelStatusChange(const InputWindowStatus &status); 73 bool MarkListener(const std::string &type, bool isRegister); 74 static uint32_t GenerateSequenceId(); 75 76 sptr<OHOS::Rosen::Window> window_ = nullptr; 77 sptr<OHOS::Rosen::WindowOption> winOption_ = nullptr; 78 PanelType panelType_ = PanelType::SOFT_KEYBOARD; 79 PanelFlag panelFlag_ = PanelFlag::FLG_FIXED; 80 bool showRegistered_ = false; 81 bool hideRegistered_ = false; 82 uint32_t invalidGravityPercent = 0; 83 std::shared_ptr<PanelStatusListener> panelStatusListener_ = nullptr; 84 85 static std::atomic<uint32_t> sequenceId_; 86 }; 87 } // namespace MiscServices 88 } // namespace OHOS 89 90 #endif //INPUT_METHOD_PANEL_H 91