/* * Copyright (c) 2023 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 INPUT_METHOD_PANEL_H #define INPUT_METHOD_PANEL_H #include #include #include #include #include "calling_window_info.h" #include "display_manager.h" #include "input_window_info.h" #include "native_engine/native_engine.h" #include "panel_common.h" #include "panel_info.h" #include "window_change_listener_impl.h" #include "wm_common.h" namespace OHOS { namespace MiscServices { constexpr int FOLD_TOP = 0; constexpr int FOLD_LEFT = 0; constexpr int FOLD_RIGHT = 0; constexpr int FOLD_BOTTOM = 606; constexpr int UNFOLD_TOP = 0; constexpr int UNFOLD_LEFT = 0; constexpr int UNFOLD_RIGHT = 0; constexpr int UNFOLD_BOTTOM = 822; constexpr int COMMON_BOTTOM = 809; class InputMethodPanel { public: static constexpr uint32_t INVALID_WINDOW_ID = 0; using CallbackFunc = std::function; InputMethodPanel() = default; ~InputMethodPanel(); int32_t SetUiContent(const std::string &contentInfo, napi_env env, std::shared_ptr contentStorage); int32_t CreatePanel(const std::shared_ptr &context, const PanelInfo &panelInfo); int32_t DestroyPanel(); int32_t Resize(uint32_t width, uint32_t height); int32_t MoveTo(int32_t x, int32_t y); int32_t StartMoving(); int32_t GetDisplayId(uint64_t &displayId); int32_t AdjustKeyboard(); int32_t AdjustPanelRect(const PanelFlag panelFlag, const LayoutParams &layoutParams, bool needUpdateRegion = true); int32_t AdjustPanelRect(PanelFlag panelFlag, EnhancedLayoutParams params, HotAreas hotAreas); int32_t UpdateRegion(std::vector region); std::tuple, std::vector> GetScreenStatus(const PanelFlag panelFlag); int32_t ChangePanelFlag(PanelFlag panelFlag); PanelType GetPanelType(); PanelFlag GetPanelFlag(); int32_t ShowPanel(); int32_t HidePanel(); int32_t SizeChange(const WindowSize &size); WindowSize GetKeyboardSize(); bool SetPanelStatusListener(std::shared_ptr statusListener, const std::string &type); void ClearPanelListener(const std::string &type); int32_t SetCallingWindow(uint32_t windowId); int32_t GetCallingWindowInfo(CallingWindowInfo &windowInfo); int32_t SetPrivacyMode(bool isPrivacyMode); bool IsShowing(); bool IsDisplayPortrait(); int32_t SetTextFieldAvoidInfo(double positionY, double height); void SetPanelHeightCallback(CallbackFunc heightCallback); int32_t IsEnhancedParamValid(PanelFlag panelFlag, EnhancedLayoutParams ¶ms); int32_t SetImmersiveMode(ImmersiveMode mode); ImmersiveMode GetImmersiveMode(); bool IsInMainDisplay(); int32_t SetImmersiveEffect(const ImmersiveEffect &effect); int32_t SetKeepScreenOn(bool isKeepScreenOn); uint32_t windowId_ = INVALID_WINDOW_ID; private: class KeyboardPanelInfoChangeListener : public Rosen::IKeyboardPanelInfoChangeListener { public: using ChangeHandler = std::function; explicit KeyboardPanelInfoChangeListener(ChangeHandler handler) : handler_(std::move(handler)) { } ~KeyboardPanelInfoChangeListener() = default; void OnKeyboardPanelInfoChanged(const Rosen::KeyboardPanelInfo &keyboardPanelInfo) override { if (handler_ == nullptr) { return; } handler_(keyboardPanelInfo); } private: ChangeHandler handler_ = nullptr; }; void RegisterKeyboardPanelInfoChangeListener(); void UnregisterKeyboardPanelInfoChangeListener(); void HandleKbPanelInfoChange(const Rosen::KeyboardPanelInfo &keyboardPanelInfo); bool IsHidden(); int32_t SetPanelProperties(); std::string GeneratePanelName(); void PanelStatusChange(const InputWindowStatus &status); void PanelStatusChangeToImc(const InputWindowStatus &status, const Rosen::Rect &rect); bool MarkListener(const std::string &type, bool isRegister); bool SetPanelSizeChangeListener(std::shared_ptr statusListener); std::shared_ptr GetPanelListener(); static uint32_t GenerateSequenceId(); bool IsSizeValid(uint32_t width, uint32_t height); bool IsSizeValid(PanelFlag panelFlag, uint32_t width, uint32_t height, int32_t displayWidth, int32_t displayHeight); bool IsRectValid(const Rosen::Rect &rect, const WindowSize &displaySize); bool IsRectValid(PanelFlag panelFlag, const Rosen::Rect &rect, const WindowSize &displaySize); int32_t GetResizeParams(Rosen::Rect &portrait, Rosen::Rect &landscape, uint32_t width, uint32_t height); int32_t ParseEnhancedParams( PanelFlag panelFlag, const FullPanelAdjustInfo &adjustInfo, EnhancedLayoutParams ¶ms); int32_t RectifyRect(bool isFullScreen, EnhancedLayoutParam &layoutParam, const WindowSize &displaySize, PanelFlag panelFlag, const PanelAdjustInfo &adjustInfo); int32_t CalculateAvoidHeight(EnhancedLayoutParam &layoutParam, const WindowSize &displaySize, PanelFlag panelFlag, const PanelAdjustInfo &adjustInfo); int32_t ParseParams(PanelFlag panelFlag, const LayoutParams &input, Rosen::KeyboardLayoutParams &output); void ParseParam(PanelFlag panelFlag, const PanelAdjustInfo &adjustInfo, const WindowSize &displaySize, const Rosen::Rect &inputRect, EnhancedLayoutParam &outputParam); void CalculateHotAreas(const EnhancedLayoutParams &enhancedParams, const Rosen::KeyboardLayoutParams ¶ms, const FullPanelAdjustInfo &adjustInfo, HotAreas &hotAreas); void CalculateDefaultHotArea(const Rosen::Rect &keyboard, const Rosen::Rect &panel, const PanelAdjustInfo &adjustInfo, HotArea &hotArea, uint32_t changeY); void CalculateHotArea(const Rosen::Rect &keyboard, const Rosen::Rect &panel, const PanelAdjustInfo &adjustInfo, HotArea &hotArea, uint32_t changeY); void CalculateEnhancedHotArea( const EnhancedLayoutParam &layout, const PanelAdjustInfo &adjustInfo, HotArea &hotArea, uint32_t changeY); void RectifyAreas(const std::vector &availableAreas, std::vector &areas); Rosen::Rect GetRectIntersection(Rosen::Rect a, Rosen::Rect b); uint32_t SafeSubtract(uint32_t minuend, uint32_t subtrahend); int32_t ResizePanel(uint32_t width, uint32_t height); int32_t ResizeWithoutAdjust(uint32_t width, uint32_t height); int32_t ResizeEnhancedPanel(uint32_t width, uint32_t height); void UpdateRectParams( Rosen::Rect &portrait, Rosen::Rect &landscape, uint32_t width, uint32_t height, const LayoutParams &currParams); void RectifyResizeParams(LayoutParams ¶ms, const DisplaySize &displaySize); int32_t MovePanelRect(int32_t x, int32_t y); int32_t MoveEnhancedPanelRect(int32_t x, int32_t y); bool IsDisplayUnfolded(); int32_t GetDisplaySize(DisplaySize &size); int32_t GetDensityDpi(float &densityDpi); int32_t InitAdjustInfo(); int32_t GetAdjustInfo(PanelFlag panelFlag, FullPanelAdjustInfo &fullPanelAdjustInfo); void UpdateResizeParams(); void UpdateHotAreas(); void UpdateLayoutInfo(PanelFlag panelFlag, const LayoutParams ¶ms, const EnhancedLayoutParams &enhancedParams, const Rosen::KeyboardLayoutParams &wmsParams, bool isEnhanced); Rosen::KeyboardLayoutParams ConvertToWMSParam(PanelFlag panelFlag, const EnhancedLayoutParams &layoutParams); Rosen::KeyboardTouchHotAreas ConvertToWMSHotArea(const HotAreas &hotAreas); void OnPanelHeightChange(const Rosen::KeyboardPanelInfo &keyboardPanelInfo); int32_t GetKeyboardArea(PanelFlag panelFlag, const WindowSize &size, PanelAdjustInfo &keyboardArea); int32_t GetWindowOrientation(PanelFlag panelFlag, uint32_t windowWidth, bool &isPortrait); sptr GetCurDisplay(); uint64_t GetCurDisplayId(); bool IsNeedConfig(); int32_t IsValidParam(const ImmersiveEffect &effect, const Rosen::KeyboardLayoutParams &layoutParams); int32_t AdjustLayout(const Rosen::KeyboardLayoutParams ¶m); int32_t AdjustLayout(const Rosen::KeyboardLayoutParams ¶m, const ImmersiveEffect &effect); int32_t FullScreenPrepare(Rosen::KeyboardLayoutParams ¶m, const ImmersiveEffect &effect); int32_t NormalImePrepare(Rosen::KeyboardLayoutParams ¶m, const ImmersiveEffect &effect); int32_t PrepareAdjustLayout(Rosen::KeyboardLayoutParams ¶m, const ImmersiveEffect &effect); bool IsImmersiveEffectSupported(); Rosen::KeyboardEffectOption ConvertToWmEffect(ImmersiveMode mode, const ImmersiveEffect &effect); void SetImmersiveEffectToNone(); void UpdateImmersiveHotArea(); bool IsValidGradientHeight(uint32_t gradientHeight); // Locked read and write functions for concurrent protection Rosen::KeyboardLayoutParams GetKeyboardLayoutParams(); void SetKeyboardLayoutParams(Rosen::KeyboardLayoutParams params); EnhancedLayoutParams GetEnhancedLayoutParams(); void SetEnhancedLayoutParams(EnhancedLayoutParams params); std::vector GetIgnoreAdjustInputTypes(); void SetIgnoreAdjustInputTypes(const std::vector &inputTypes); ImmersiveEffect LoadImmersiveEffect(); void StoreImmersiveEffect(ImmersiveEffect effect); HotAreas GetHotAreas(); void SetHotAreas(const HotAreas &hotAreas); ChangeY GetChangeY(); void SetChangeY(ChangeY changeY); void StoreImmersiveMode(ImmersiveMode mode); CallbackFunc GetPanelHeightCallback(); sptr window_ = nullptr; sptr winOption_ = nullptr; PanelType panelType_ = PanelType::SOFT_KEYBOARD; PanelFlag panelFlag_ = PanelFlag::FLG_FIXED; bool showRegistered_ = false; bool hideRegistered_ = false; bool sizeChangeRegistered_ = false; bool sizeUpdateRegistered_ = false; uint32_t invalidGravityPercent = 0; std::shared_ptr panelStatusListener_ = nullptr; static std::atomic sequenceId_; sptr kbPanelInfoListener_ { nullptr }; bool isScbEnable_ { false }; std::mutex panelAdjustLock_; std::map, PanelAdjustInfo> panelAdjust_; std::mutex adjustInfoInitLock_; uint64_t adjustInfoDisplayId_ = 0; std::atomic isAdjustInfoInitialized_{ false }; std::atomic isIgnorePanelAdjustInitialized_{ false }; std::mutex ignoreAdjustInputTypeLock_; std::vector ignoreAdjustInputTypes_; std::mutex hotAreasLock_; HotAreas hotAreas_; std::mutex enhancedLayoutParamMutex_; EnhancedLayoutParams enhancedLayoutParams_; std::mutex keyboardLayoutParamsMutex_; Rosen::KeyboardLayoutParams keyboardLayoutParams_; std::mutex keyboardSizeLock_; WindowSize keyboardSize_ { 0, 0 }; std::mutex windowListenerLock_; sptr windowChangedListener_ = nullptr; std::mutex heightCallbackMutex_; CallbackFunc panelHeightCallback_ = nullptr; std::mutex foldResizeParamMutex_; LayoutParams resizePanelFoldParams_ { // FoldDefaultValue { FOLD_TOP, FOLD_LEFT, FOLD_RIGHT, FOLD_BOTTOM }, { FOLD_TOP, FOLD_LEFT, FOLD_RIGHT, COMMON_BOTTOM } }; std::mutex unfoldResizeParamMutex_; LayoutParams resizePanelUnfoldParams_ { // UnfoldDefaultValue { UNFOLD_TOP, UNFOLD_LEFT, UNFOLD_RIGHT, UNFOLD_BOTTOM }, { UNFOLD_TOP, UNFOLD_LEFT, UNFOLD_RIGHT, COMMON_BOTTOM } }; std::atomic isWaitSetUiContent_ { true }; std::atomic isInEnhancedAdjust_{ false }; std::mutex immersiveModeMutex_; ImmersiveMode immersiveMode_ { ImmersiveMode::NONE_IMMERSIVE }; std::mutex immersiveEffectMutex_; ImmersiveEffect immersiveEffect_ { 0, GradientMode::NONE, FluidLightMode::NONE }; std::mutex changeYMutex_; ChangeY changeY_; }; } // namespace MiscServices } // namespace OHOS #endif // INPUT_METHOD_PANEL_H