From 4d8be67bafa065c1050e337f5603228f1d0d9292 Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Sat, 7 Jun 2025 16:20:34 +0800 Subject: [PATCH] optimize adjustPanelRect Signed-off-by: zhaolinglan --- .../include/input_method_panel.h | 30 +- .../include/panel_common.h | 3 +- .../src/input_method_panel.cpp | 430 +++++++----------- .../src/numkey_apps_manager.cpp | 4 +- .../src/input_method_panel_adjust_test.cpp | 72 +-- 5 files changed, 224 insertions(+), 315 deletions(-) diff --git a/frameworks/native/inputmethod_ability/include/input_method_panel.h b/frameworks/native/inputmethod_ability/include/input_method_panel.h index fcc7967e9..0d323013f 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_panel.h +++ b/frameworks/native/inputmethod_ability/include/input_method_panel.h @@ -60,13 +60,6 @@ public: 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); - int32_t ParsePanelRect(const PanelFlag panelFlag, const LayoutParams &layoutParams); - int32_t GetSysPanelAdjust(const PanelFlag panelFlag, - std::tuple, std::vector> &keys, const LayoutParams &layoutParams); - int32_t CalculatePanelRect(const PanelFlag panelFlag, PanelAdjustInfo &lanIterValue, PanelAdjustInfo &porIterValue, - const LayoutParams &layoutParams); - int32_t CalculateLandscapeRect(sptr &defaultDisplay, const LayoutParams &layoutParams, - PanelAdjustInfo &lanIterValue); std::tuple, std::vector> GetScreenStatus(const PanelFlag panelFlag); int32_t ChangePanelFlag(PanelFlag panelFlag); PanelType GetPanelType(); @@ -82,7 +75,6 @@ public: int32_t SetPrivacyMode(bool isPrivacyMode); bool IsShowing(); 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(); @@ -125,9 +117,6 @@ private: bool IsRectValid(const Rosen::Rect &rect, const WindowSize &displaySize); bool CheckSize(PanelFlag panelFlag, uint32_t width, uint32_t height, bool isDataPortrait); bool GetDisplaySize(bool isPortrait, WindowSize &size); - int32_t CalculateFloatRect(const LayoutParams &layoutParams, PanelAdjustInfo &lanIterValue, - PanelAdjustInfo &porIterValue); - int32_t CalculateNoConfigRect(const PanelFlag panelFlag, const LayoutParams &layoutParams); int32_t GetResizeParams(Rosen::Rect &portrait, Rosen::Rect &landscape, uint32_t width, uint32_t height); int32_t ParseEnhancedParams( @@ -137,6 +126,10 @@ private: int32_t CalculateAvoidHeight(EnhancedLayoutParam &layoutParam, const WindowSize &displaySize, PanelFlag panelFlag, const PanelAdjustInfo &adjustInfo); + int32_t ParseParams(PanelFlag panelFlag, const LayoutParams &input, Rosen::KeyboardLayoutParams &output); + int32_t 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, @@ -182,7 +175,7 @@ private: void SetIgnoreAdjustInputTypes(const std::vector &inputTypes); std::vector GetIgnoreAdjustInputTypes(); bool IsNeedConfig(); - int32_t IsValidParam(const ImmersiveEffect &effect); + int32_t IsValidParam(const ImmersiveEffect &effect, const Rosen::KeyboardLayoutParams &layoutParams); int32_t AdjustLayout(const Rosen::KeyboardLayoutParams ¶m); std::pair FullScreenPortraitPrepare(const Rosen::KeyboardLayoutParams ¶m); std::pair FullScreenLandscapePrepare(const Rosen::KeyboardLayoutParams ¶m); @@ -193,6 +186,14 @@ private: Rosen::KeyboardEffectOption ConvertToWmEffect(ImmersiveMode mode, const ImmersiveEffect &effect); void SetImmersiveEffectToNone(); void UpdateImmersiveHotArea(); + + CallbackFunc GetPanelHeightCallback(); + void SetPanelHeightCallback(CallbackFunc heightCallback); + Rosen::KeyboardLayoutParams GetKeyboardLayoutParams(); + void SetKeyboardLayoutParams(Rosen::KeyboardLayoutParams params); + EnhancedLayoutParams GetEnhancedLayoutParams(); + void SetEnhancedLayoutParams(EnhancedLayoutParams params); + sptr window_ = nullptr; sptr winOption_ = nullptr; PanelType panelType_ = PanelType::SOFT_KEYBOARD; @@ -218,20 +219,25 @@ private: 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 } diff --git a/frameworks/native/inputmethod_ability/include/panel_common.h b/frameworks/native/inputmethod_ability/include/panel_common.h index 659d2d99e..16023fe79 100644 --- a/frameworks/native/inputmethod_ability/include/panel_common.h +++ b/frameworks/native/inputmethod_ability/include/panel_common.h @@ -53,7 +53,8 @@ struct HotAreas { }; struct EnhancedLayoutParam { - Rosen::Rect rect{ 0, 0, 0, 0 }; + Rosen::Rect rect{ 0, 0, 0, 0 }; // rect of keyboard panel + Rosen::Rect panelRect{ 0, 0, 0, 0 }; // rect of system panel int32_t avoidY{ 0 }; uint32_t avoidHeight{ 0 }; inline std::string ToString() const diff --git a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp index 41348c6ca..5aacce4fd 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp @@ -16,6 +16,7 @@ #include "input_method_panel.h" #include +#include #include "display_info.h" #include "dm_common.h" @@ -35,7 +36,6 @@ using WindowState = OHOS::Rosen::WindowState; using namespace Rosen; constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7; constexpr float NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO = 1; -constexpr int32_t NUMBER_ZERO = 0; constexpr int32_t FIXED_PANEL_POS_X = 0; constexpr int32_t ORIGIN_POS_X = 0; constexpr int32_t ORIGIN_POS_Y = 0; @@ -261,12 +261,14 @@ int32_t InputMethodPanel::SetPanelProperties() } return ErrorCode::NO_ERROR; } - keyboardLayoutParams_.gravity_ = gravity; - auto ret = AdjustLayout(keyboardLayoutParams_); + auto params = GetKeyboardLayoutParams(); + params.gravity_ = gravity; + auto ret = AdjustLayout(params); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("SetWindowGravity failed, ret is %{public}d, start destroy window!", ret); return ErrorCode::ERROR_OPERATE_PANEL; } + SetKeyboardLayoutParams(params); return ErrorCode::NO_ERROR; } @@ -309,14 +311,16 @@ int32_t InputMethodPanel::GetResizeParams( } if (IsDisplayUnfolded()) { + std::lock_guard lock(unfoldResizeParamMutex_); IMSA_HILOGI("foldable device without fold state"); - if (!isInEnhancedAdjust_) { + if (!isInEnhancedAdjust_.load()) { RectifyResizeParams(resizePanelUnfoldParams_, displaySize); } currParams = resizePanelUnfoldParams_; } else { + std::lock_guard lock(foldResizeParamMutex_); IMSA_HILOGI("foldable device with fold state or non-foldable device"); - if (!isInEnhancedAdjust_) { + if (!isInEnhancedAdjust_.load()) { RectifyResizeParams(resizePanelFoldParams_, displaySize); } currParams = resizePanelFoldParams_; @@ -362,20 +366,21 @@ void InputMethodPanel::UpdateRectParams( void InputMethodPanel::UpdateResizeParams() { + auto layoutParams = GetKeyboardLayoutParams(); if (IsDisplayUnfolded()) { + std::lock_guard lock(unfoldResizeParamMutex_); IMSA_HILOGI("foldable device without fold state"); - resizePanelUnfoldParams_ = { keyboardLayoutParams_.LandscapeKeyboardRect_, - keyboardLayoutParams_.PortraitKeyboardRect_ }; + resizePanelUnfoldParams_ = { layoutParams.LandscapeKeyboardRect_, layoutParams.PortraitKeyboardRect_ }; } else { + std::lock_guard lock(foldResizeParamMutex_); IMSA_HILOGI("foldable device in fold state or non-foldable device"); - resizePanelFoldParams_ = { keyboardLayoutParams_.LandscapeKeyboardRect_, - keyboardLayoutParams_.PortraitKeyboardRect_ }; + resizePanelFoldParams_ = { layoutParams.LandscapeKeyboardRect_, layoutParams.PortraitKeyboardRect_ }; } } int32_t InputMethodPanel::ResizeEnhancedPanel(uint32_t width, uint32_t height) { - EnhancedLayoutParams layoutParam = enhancedLayoutParams_; + auto layoutParam = GetEnhancedLayoutParams(); auto ret = GetResizeParams(layoutParam.portrait.rect, layoutParam.landscape.rect, width, height); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to GetResizeParams, ret: %{public}d", ret); @@ -417,13 +422,14 @@ int32_t InputMethodPanel::ResizePanel(uint32_t width, uint32_t height) IMSA_HILOGE("size is invalid!"); return ErrorCode::ERROR_BAD_PARAMETERS; } - LayoutParams params = { enhancedLayoutParams_.landscape.rect, enhancedLayoutParams_.portrait.rect }; - auto ret = GetResizeParams(params.portraitRect, params.landscapeRect, width, height); + auto currentParams = GetEnhancedLayoutParams(); + LayoutParams targetParams = { currentParams.landscape.rect, currentParams.portrait.rect }; + auto ret = GetResizeParams(targetParams.portraitRect, targetParams.landscapeRect, width, height); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to GetResizeParams, ret: %{public}d", ret); return ret; } - ret = AdjustPanelRect(panelFlag_, params); + ret = AdjustPanelRect(panelFlag_, targetParams); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to resize, ret: %{public}d", ret); return ErrorCode::ERROR_OPERATE_PANEL; @@ -452,7 +458,8 @@ int32_t InputMethodPanel::Resize(uint32_t width, uint32_t height) int32_t InputMethodPanel::MovePanelRect(int32_t x, int32_t y) { - LayoutParams params = { enhancedLayoutParams_.landscape.rect, enhancedLayoutParams_.portrait.rect }; + auto currentParams = GetEnhancedLayoutParams(); + LayoutParams params = { currentParams.landscape.rect, currentParams.portrait.rect }; if (IsDisplayPortrait()) { params.portraitRect.posX_ = x; params.portraitRect.posY_ = y; @@ -469,7 +476,7 @@ int32_t InputMethodPanel::MovePanelRect(int32_t x, int32_t y) int32_t InputMethodPanel::MoveEnhancedPanelRect(int32_t x, int32_t y) { - auto params = enhancedLayoutParams_; + auto params = GetEnhancedLayoutParams(); if (IsDisplayPortrait()) { params.portrait.rect.posX_ = x; params.portrait.rect.posY_ = y; @@ -552,8 +559,8 @@ int32_t InputMethodPanel::AdjustKeyboard() { isAdjustInfoInitialized_.store(false); int32_t ret = 0; + auto params = GetEnhancedLayoutParams(); if (isInEnhancedAdjust_.load()) { - EnhancedLayoutParams params = enhancedLayoutParams_; DisplaySize displaySize; ret = GetDisplaySize(displaySize); if (ret != ErrorCode::NO_ERROR) { @@ -565,8 +572,8 @@ int32_t InputMethodPanel::AdjustKeyboard() auto hotAreas = GetHotAreas(); ret = AdjustPanelRect(panelFlag_, params, hotAreas); } else { - LayoutParams params = { enhancedLayoutParams_.landscape.rect, enhancedLayoutParams_.portrait.rect }; - ret = AdjustPanelRect(panelFlag_, params); + LayoutParams layoutParams = { params.landscape.rect, params.portrait.rect }; + ret = AdjustPanelRect(panelFlag_, layoutParams); } if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to adjust keyboard, ret: %{public}d", ret); @@ -583,34 +590,19 @@ int32_t InputMethodPanel::AdjustPanelRect( IMSA_HILOGE("window_ is nullptr!"); return ErrorCode::ERROR_WINDOW_MANAGER; } - if (layoutParams.portraitRect.posX_ < 0 || layoutParams.portraitRect.posY_ < 0 || - layoutParams.landscapeRect.posX_ < 0 || layoutParams.landscapeRect.posY_ < 0) { - IMSA_HILOGE("posX_ and posY_ cannot be less than 0!"); - return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; - } - if (!CheckSize(panelFlag, layoutParams.portraitRect.width_, layoutParams.portraitRect.height_, true)) { - IMSA_HILOGE("portrait invalid size!"); - return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; - } - if (!CheckSize(panelFlag, layoutParams.landscapeRect.width_, layoutParams.landscapeRect.height_, false)) { - IMSA_HILOGE("landscape invalid size!"); - return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; - } - auto result = ParsePanelRect(panelFlag, layoutParams); + KeyboardLayoutParams resultParams; + int32_t result = ParseParams(panelFlag, layoutParams, resultParams); if (result != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to parse panel rect, result: %{public}d!", result); return ErrorCode::ERROR_WINDOW_MANAGER; } - auto ret = AdjustLayout(keyboardLayoutParams_); + auto ret = AdjustLayout(resultParams); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("AdjustPanelRect error, err: %{public}d!", ret); return ErrorCode::ERROR_WINDOW_MANAGER; } - if (panelFlag_ != panelFlag) { - NotifyPanelStatus(panelFlag); - } UpdateResizeParams(); - UpdateLayoutInfo(panelFlag, layoutParams, {}, keyboardLayoutParams_, false); + UpdateLayoutInfo(panelFlag, layoutParams, {}, resultParams, false); if (needUpdateRegion) { UpdateHotAreas(); } @@ -629,9 +621,9 @@ Rosen::KeyboardLayoutParams InputMethodPanel::ConvertToWMSParam( wmsParams.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT; } wmsParams.LandscapeKeyboardRect_ = layoutParams.landscape.rect; - wmsParams.LandscapePanelRect_ = layoutParams.landscape.rect; + wmsParams.LandscapePanelRect_ = layoutParams.landscape.panelRect; wmsParams.PortraitKeyboardRect_ = layoutParams.portrait.rect; - wmsParams.PortraitPanelRect_ = layoutParams.portrait.rect; + wmsParams.PortraitPanelRect_ = layoutParams.portrait.panelRect; wmsParams.portraitAvoidHeight_ = layoutParams.portrait.avoidHeight; wmsParams.landscapeAvoidHeight_ = layoutParams.landscape.avoidHeight; return wmsParams; @@ -689,6 +681,7 @@ int32_t InputMethodPanel::AdjustPanelRect(PanelFlag panelFlag, EnhancedLayoutPar return ret; } // adjust rect + auto lastWmsParam = GetKeyboardLayoutParams(); auto wmsParams = ConvertToWMSParam(panelFlag, params); ret = AdjustLayout(wmsParams); if (ret != ErrorCode::NO_ERROR) { @@ -702,14 +695,11 @@ int32_t InputMethodPanel::AdjustPanelRect(PanelFlag panelFlag, EnhancedLayoutPar auto result = window_->SetKeyboardTouchHotAreas(wmsHotAreas); if (result != WMError::WM_OK) { IMSA_HILOGE("SetKeyboardTouchHotAreas error, err: %{public}d!", result); - ret = AdjustLayout(keyboardLayoutParams_); + ret = AdjustLayout(lastWmsParam); IMSA_HILOGE("restore layout param, result: %{public}d", ret); return ErrorCode::ERROR_WINDOW_MANAGER; } SetHotAreas(hotAreas); - if (panelFlag_ != panelFlag) { - NotifyPanelStatus(panelFlag); - } UpdateLayoutInfo(panelFlag, {}, params, wmsParams, true); UpdateResizeParams(); IMSA_HILOGI("success, type/flag: %{public}d/%{public}d.", static_cast(panelType_), @@ -720,14 +710,17 @@ int32_t InputMethodPanel::AdjustPanelRect(PanelFlag panelFlag, EnhancedLayoutPar void InputMethodPanel::UpdateLayoutInfo(PanelFlag panelFlag, const LayoutParams ¶ms, const EnhancedLayoutParams &enhancedParams, const KeyboardLayoutParams &wmsParams, bool isEnhanced) { + SetKeyboardLayoutParams(wmsParams); if (isEnhanced) { - enhancedLayoutParams_ = enhancedParams; - keyboardLayoutParams_ = wmsParams; + SetEnhancedLayoutParams(enhancedParams); } else { EnhancedLayoutParams enhancedLayoutParams = { .isFullScreen = false, .portrait = { .rect = params.portraitRect }, .landscape = { .rect = params.landscapeRect } }; - enhancedLayoutParams_ = std::move(enhancedLayoutParams); + SetEnhancedLayoutParams(enhancedLayoutParams); + } + if (panelFlag_ != panelFlag) { + NotifyPanelStatus(panelFlag); } panelFlag_ = panelFlag; isInEnhancedAdjust_.store(isEnhanced); @@ -790,6 +783,7 @@ int32_t InputMethodPanel::RectifyRect(bool isFullScreen, EnhancedLayoutParam &la { if (isFullScreen) { layoutParam.rect = { ORIGIN_POS_X, ORIGIN_POS_Y, displaySize.width, displaySize.height }; + layoutParam.panelRect = layoutParam.rect; return ErrorCode::NO_ERROR; } if (!IsRectValid(layoutParam.rect, displaySize)) { @@ -800,6 +794,7 @@ int32_t InputMethodPanel::RectifyRect(bool isFullScreen, EnhancedLayoutParam &la layoutParam.rect = { FIXED_PANEL_POS_X, static_cast(displaySize.height - layoutParam.rect.height_), displaySize.width, layoutParam.rect.height_ }; } + layoutParam.panelRect = layoutParam.rect; return ErrorCode::NO_ERROR; } @@ -845,10 +840,11 @@ void InputMethodPanel::UpdateHotAreas() IMSA_HILOGE("GetAdjustInfo failed ret: %{public}d", ret); return; } - CalculateDefaultHotArea(keyboardLayoutParams_.LandscapeKeyboardRect_, keyboardLayoutParams_.LandscapePanelRect_, + auto layoutParams = GetKeyboardLayoutParams(); + CalculateDefaultHotArea(layoutParams.LandscapeKeyboardRect_, layoutParams.LandscapePanelRect_, adjustInfo.landscape, hotAreas.landscape, landscapeChangeY_); - CalculateDefaultHotArea(keyboardLayoutParams_.PortraitKeyboardRect_, keyboardLayoutParams_.PortraitPanelRect_, - adjustInfo.portrait, hotAreas.portrait, portraitChangeY_); + CalculateDefaultHotArea(layoutParams.PortraitKeyboardRect_, layoutParams.PortraitPanelRect_, adjustInfo.portrait, + hotAreas.portrait, portraitChangeY_); auto wmsHotAreas = ConvertToWMSHotArea(hotAreas); WMError result = window_->SetKeyboardTouchHotAreas(wmsHotAreas); if (result != WMError::WM_OK) { @@ -893,9 +889,10 @@ void InputMethodPanel::CalculateHotArea(const Rosen::Rect &keyboard, const Rosen std::vector availableAreas = { { { ORIGIN_POS_X, ORIGIN_POS_Y, keyboard.width_, keyboard.height_ } } }; RectifyAreas(availableAreas, hotArea.keyboardHotArea); // calculate panel hot area - Rosen::Rect left = { ORIGIN_POS_X, ORIGIN_POS_Y + changeY, static_cast(adjustInfo.left), panel.height_ }; + Rosen::Rect left = { ORIGIN_POS_X, ORIGIN_POS_Y + static_cast(changeY), + static_cast(adjustInfo.left), panel.height_ }; Rosen::Rect right = { .posX_ = static_cast(panel.width_) - adjustInfo.right, - .posY_ = ORIGIN_POS_Y + changeY, + .posY_ = ORIGIN_POS_Y + static_cast(changeY), .width_ = static_cast(adjustInfo.right), .height_ = panel.height_ }; Rosen::Rect bottom = { .posX_ = ORIGIN_POS_X, @@ -921,10 +918,10 @@ void InputMethodPanel::CalculateEnhancedHotArea( .height_ = SafeSubtract(layout.avoidHeight, static_cast(adjustInfo.bottom)) }); RectifyAreas(availableAreas, hotArea.keyboardHotArea); // calculate panel hot area - Rosen::Rect left = { ORIGIN_POS_X, layout.avoidY + changeY, static_cast(adjustInfo.left), - layout.avoidHeight }; + Rosen::Rect left = { ORIGIN_POS_X, layout.avoidY + static_cast(changeY), + static_cast(adjustInfo.left), layout.avoidHeight }; Rosen::Rect right = { .posX_ = static_cast(layout.rect.width_) - adjustInfo.right, - .posY_ = layout.avoidY + changeY, + .posY_ = layout.avoidY + static_cast(changeY), .width_ = static_cast(adjustInfo.right), .height_ = layout.avoidHeight }; Rosen::Rect bottom = { .posX_ = ORIGIN_POS_X, @@ -942,9 +939,10 @@ void InputMethodPanel::CalculateDefaultHotArea(const Rosen::Rect &keyboard, cons hotArea.keyboardHotArea.clear(); hotArea.keyboardHotArea.push_back({ ORIGIN_POS_X, ORIGIN_POS_Y, keyboard.width_, keyboard.height_ }); // calculate panel hot area - Rosen::Rect left = { ORIGIN_POS_X, ORIGIN_POS_Y + changeY, static_cast(adjustInfo.left), panel.height_ }; + Rosen::Rect left = { ORIGIN_POS_X, ORIGIN_POS_Y + static_cast(changeY), + static_cast(adjustInfo.left), panel.height_ }; Rosen::Rect right = { .posX_ = static_cast(panel.width_) - adjustInfo.right, - .posY_ = ORIGIN_POS_Y + changeY, + .posY_ = ORIGIN_POS_Y + static_cast(changeY), .width_ = static_cast(adjustInfo.right), .height_ = panel.height_ }; Rosen::Rect bottom = { .posX_ = ORIGIN_POS_X, @@ -1023,7 +1021,7 @@ int32_t InputMethodPanel::UpdateRegion(std::vector region) } else { hotAreas.landscape.keyboardHotArea = region; } - CalculateHotAreas(enhancedLayoutParams_, keyboardLayoutParams_, adjustInfo, hotAreas); + CalculateHotAreas(GetEnhancedLayoutParams(), GetKeyboardLayoutParams(), adjustInfo, hotAreas); auto wmsHotAreas = ConvertToWMSHotArea(hotAreas); WMError result = window_->SetKeyboardTouchHotAreas(wmsHotAreas); if (result != WMError::WM_OK) { @@ -1073,74 +1071,75 @@ int32_t InputMethodPanel::InitAdjustInfo() return ErrorCode::NO_ERROR; } -int32_t InputMethodPanel::ParsePanelRect(const PanelFlag panelFlag, const LayoutParams &layoutParams) +int32_t InputMethodPanel::ParseParams(PanelFlag panelFlag, const LayoutParams &input, KeyboardLayoutParams &output) { - keyboardLayoutParams_.landscapeAvoidHeight_ = DEFAULT_AVOID_HEIGHT; - keyboardLayoutParams_.portraitAvoidHeight_ = DEFAULT_AVOID_HEIGHT; - std::vector configs; - auto isSuccess = SysCfgParser::ParsePanelAdjust(configs); - if (isSuccess) { - InitAdjustInfo(); - } else { - IMSA_HILOGE("there is no configuration file!"); - auto ret = CalculateNoConfigRect(panelFlag, layoutParams); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("failed to calculate NoConfigRect, err: %{public}d!", ret); - return ret; - } - return ErrorCode::NO_ERROR; + FullPanelAdjustInfo adjustInfo; + if (IsNeedConfig()) { + auto ret = GetAdjustInfo(panelFlag, adjustInfo); + IMSA_HILOGD("get adjust info: %{public}d", ret); } - std::tuple, std::vector> keys = GetScreenStatus(panelFlag); - auto ret = GetSysPanelAdjust(panelFlag, keys, layoutParams); + DisplaySize display; + int32_t ret = GetDisplaySize(display); if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("GetSysPanelAdjust failed!"); - return ErrorCode::ERROR_BAD_PARAMETERS; + IMSA_HILOGE("failed to GetDisplaySize ret: %{public}d", ret); + return ErrorCode::ERROR_WINDOW_MANAGER; + } + EnhancedLayoutParams params; + ret = ParseParam(panelFlag, adjustInfo.portrait, display.portrait, input.portraitRect, params.portrait); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("failed to parse portrait param, ret: %{public}d", ret); + return ret; + } + ret = ParseParam(panelFlag, adjustInfo.landscape, display.landscape, input.landscapeRect, params.landscape); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("failed to parse landscape param, ret: %{public}d", ret); + return ret; } + output = ConvertToWMSParam(panelFlag, params); + output.portraitAvoidHeight_ = DEFAULT_AVOID_HEIGHT; + output.landscapeAvoidHeight_ = DEFAULT_AVOID_HEIGHT; + IMSA_HILOGD("success, portrait: %{public}s, landscape: %{public}s", params.portrait.ToString().c_str(), + params.landscape.ToString().c_str()); return ErrorCode::NO_ERROR; } -int32_t InputMethodPanel::CalculateNoConfigRect(const PanelFlag panelFlag, const LayoutParams &layoutParams) +int32_t InputMethodPanel::ParseParam(PanelFlag panelFlag, const PanelAdjustInfo &adjustInfo, + const WindowSize &displaySize, const Rosen::Rect &inputRect, EnhancedLayoutParam &outputParam) { + if (inputRect.posX_ < 0 || inputRect.posY_ < 0) { + IMSA_HILOGE("posX_ and posY_ cannot be less than 0!"); + return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; + } + if (!IsSizeValid(panelFlag, inputRect.width_, inputRect.height_, displaySize.width, displaySize.height)) { + IMSA_HILOGE("invalid size!"); + return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; + } + Rosen::Rect panelRect{}; + Rosen::Rect keyboardRect{}; if (panelFlag == PanelFlag::FLG_FIXED) { - keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; - WindowSize portraitDisplaySize; - if (!GetDisplaySize(true, portraitDisplaySize)) { - IMSA_HILOGE("GetPortraitDisplaySize failed!"); - return ErrorCode::ERROR_WINDOW_MANAGER; - } - keyboardLayoutParams_.PortraitPanelRect_.width_ = portraitDisplaySize.width; - keyboardLayoutParams_.PortraitPanelRect_.height_ = layoutParams.portraitRect.height_; - keyboardLayoutParams_.PortraitPanelRect_.posY_ = - static_cast(portraitDisplaySize.height - keyboardLayoutParams_.PortraitPanelRect_.height_); - keyboardLayoutParams_.PortraitPanelRect_.posX_ = NUMBER_ZERO; - // fixed Portraitkeyboard - keyboardLayoutParams_.PortraitKeyboardRect_.width_ = keyboardLayoutParams_.PortraitPanelRect_.width_; - keyboardLayoutParams_.PortraitKeyboardRect_.height_ = keyboardLayoutParams_.PortraitPanelRect_.height_; - keyboardLayoutParams_.PortraitKeyboardRect_.posY_ = keyboardLayoutParams_.PortraitPanelRect_.posY_; - keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = keyboardLayoutParams_.PortraitPanelRect_.posX_; - - WindowSize landscapeDisplaySize; - if (!GetDisplaySize(false, landscapeDisplaySize)) { - IMSA_HILOGE("GetLandscapeDisplaySize failed!"); - return ErrorCode::ERROR_WINDOW_MANAGER; - } - keyboardLayoutParams_.LandscapePanelRect_.width_ = landscapeDisplaySize.width; - keyboardLayoutParams_.LandscapePanelRect_.height_ = layoutParams.landscapeRect.height_; - keyboardLayoutParams_.LandscapePanelRect_.posY_ = - static_cast(landscapeDisplaySize.height - keyboardLayoutParams_.LandscapePanelRect_.height_); - keyboardLayoutParams_.LandscapePanelRect_.posX_ = NUMBER_ZERO; - // Landscapekeyboard - keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = keyboardLayoutParams_.LandscapePanelRect_.width_; - keyboardLayoutParams_.LandscapeKeyboardRect_.height_ = keyboardLayoutParams_.LandscapePanelRect_.height_; - keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ = keyboardLayoutParams_.LandscapePanelRect_.posY_; - keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = keyboardLayoutParams_.LandscapePanelRect_.posX_; + // fixed panel rect + panelRect.width_ = displaySize.width; + panelRect.height_ = inputRect.height_ + static_cast(adjustInfo.top + adjustInfo.bottom); + panelRect.height_ = std::min(panelRect.height_, + static_cast(static_cast(displaySize.height) * FIXED_SOFT_KEYBOARD_PANEL_RATIO)); + panelRect.posX_ = ORIGIN_POS_Y; + panelRect.posY_ = static_cast(displaySize.height - panelRect.height_); + // fixed keyboard rect + keyboardRect.width_ = panelRect.width_ - static_cast(adjustInfo.left + adjustInfo.right); + keyboardRect.height_ = panelRect.height_ - static_cast(adjustInfo.top + adjustInfo.bottom); + keyboardRect.posY_ = panelRect.posY_ + static_cast(adjustInfo.top); + keyboardRect.posX_ = panelRect.posX_ + static_cast(adjustInfo.left); } else { - keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT; - keyboardLayoutParams_.LandscapeKeyboardRect_ = layoutParams.landscapeRect; - keyboardLayoutParams_.PortraitKeyboardRect_ = layoutParams.portraitRect; - keyboardLayoutParams_.LandscapePanelRect_ = layoutParams.landscapeRect; - keyboardLayoutParams_.PortraitPanelRect_ = layoutParams.portraitRect; - } + // floating keyboard rect + keyboardRect = inputRect; + // floating panel rect + panelRect.width_ = keyboardRect.width_ + static_cast(adjustInfo.left + adjustInfo.right); + panelRect.height_ = keyboardRect.height_ + static_cast(adjustInfo.top + adjustInfo.bottom); + panelRect.posY_ = keyboardRect.posY_ - static_cast(adjustInfo.top); + panelRect.posX_ = keyboardRect.posX_ - adjustInfo.left; + } + outputParam.rect = keyboardRect; + outputParam.panelRect = panelRect; return ErrorCode::NO_ERROR; } @@ -1151,10 +1150,8 @@ std::tuple, std::vector> InputMethodPanel: std::string foldStatus = "default"; if (panelFlag == PanelFlag::FLG_FIXED) { flag = "fix"; - keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; } else if (panelFlag == PanelFlag::FLG_FLOATING) { flag = "floating"; - keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT; } if (Rosen::DisplayManager::GetInstance().IsFoldable() && Rosen::DisplayManager::GetInstance().GetFoldStatus() != Rosen::FoldStatus::FOLDED) { @@ -1187,137 +1184,6 @@ int32_t InputMethodPanel::GetAdjustInfo(PanelFlag panelFlag, FullPanelAdjustInfo return ErrorCode::NO_ERROR; } -int32_t InputMethodPanel::GetSysPanelAdjust(const PanelFlag panelFlag, - std::tuple, std::vector> &keys, const LayoutParams &layoutParams) -{ - PanelAdjustInfo lanIterValue; - PanelAdjustInfo porIterValue; - std::lock_guard lock(panelAdjustLock_); - auto lanPanel = std::get<0>(keys); - auto porPanel = std::get<1>(keys); - auto lanIter = panelAdjust_.find(lanPanel); - auto porIter = panelAdjust_.find(porPanel); - if (lanIter != panelAdjust_.end()) { - lanIterValue = lanIter->second; - } - if (porIter != panelAdjust_.end()) { - porIterValue = porIter->second; - } - return CalculatePanelRect(panelFlag, lanIterValue, porIterValue, layoutParams); -} - -int32_t InputMethodPanel::CalculatePanelRect(const PanelFlag panelFlag, PanelAdjustInfo &lanIterValue, - PanelAdjustInfo &porIterValue, const LayoutParams &layoutParams) -{ - if (!IsNeedConfig()) { - IMSA_HILOGI("The security keyboard is handled according to no configuration file"); - return CalculateNoConfigRect(panelFlag, layoutParams); - } - auto defaultDisplay = GetCurDisplay(); - if (defaultDisplay == nullptr) { - IMSA_HILOGE("GetDefaultDisplay failed!"); - return ErrorCode::ERROR_EX_SERVICE_SPECIFIC; - } - if (panelFlag == PanelFlag::FLG_FIXED) { - // fixed PortraitPanel - WindowSize portraitDisplaySize; - if (!GetDisplaySize(true, portraitDisplaySize)) { - IMSA_HILOGE("GetDisplaySize failed!"); - return ErrorCode::ERROR_WINDOW_MANAGER; - } - keyboardLayoutParams_.PortraitPanelRect_.width_ = portraitDisplaySize.width; - keyboardLayoutParams_.PortraitPanelRect_.height_ = layoutParams.portraitRect.height_ + - static_cast(porIterValue.top + porIterValue.bottom); - if (keyboardLayoutParams_.PortraitPanelRect_.height_ > - portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO) { - keyboardLayoutParams_.PortraitPanelRect_.height_ = - portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO; - } - keyboardLayoutParams_.PortraitPanelRect_.posY_ = - static_cast(portraitDisplaySize.height - keyboardLayoutParams_.PortraitPanelRect_.height_); - keyboardLayoutParams_.PortraitPanelRect_.posX_ = NUMBER_ZERO; - // fixed Portraitkeyboard - keyboardLayoutParams_.PortraitKeyboardRect_.width_ = keyboardLayoutParams_.PortraitPanelRect_.width_ - - static_cast(porIterValue.left + porIterValue.right); - keyboardLayoutParams_.PortraitKeyboardRect_.height_ = keyboardLayoutParams_.PortraitPanelRect_.height_ - - static_cast(porIterValue.top + porIterValue.bottom); - keyboardLayoutParams_.PortraitKeyboardRect_.posY_ = - keyboardLayoutParams_.PortraitPanelRect_.posY_ + static_cast(porIterValue.top); - keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = - keyboardLayoutParams_.PortraitPanelRect_.posX_ + static_cast(porIterValue.left); - return CalculateLandscapeRect(defaultDisplay, layoutParams, lanIterValue); - } - return CalculateFloatRect(layoutParams, lanIterValue, porIterValue); -} - -int32_t InputMethodPanel::CalculateFloatRect( - const LayoutParams &layoutParams, PanelAdjustInfo &lanIterValue, PanelAdjustInfo &porIterValue) -{ - keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_FLOAT; - // portrait floating keyboard - keyboardLayoutParams_.PortraitKeyboardRect_.width_ = layoutParams.portraitRect.width_; - keyboardLayoutParams_.PortraitKeyboardRect_.height_ = layoutParams.portraitRect.height_; - keyboardLayoutParams_.PortraitKeyboardRect_.posY_ = layoutParams.portraitRect.posY_; - keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = layoutParams.portraitRect.posX_; - // portrait floating panel - keyboardLayoutParams_.PortraitPanelRect_.width_ = keyboardLayoutParams_.PortraitKeyboardRect_.width_ + - static_cast(porIterValue.left + porIterValue.right); - keyboardLayoutParams_.PortraitPanelRect_.height_ = keyboardLayoutParams_.PortraitKeyboardRect_.height_ + - static_cast(porIterValue.top + porIterValue.bottom); - keyboardLayoutParams_.PortraitPanelRect_.posY_ = - keyboardLayoutParams_.PortraitKeyboardRect_.posY_ - static_cast(porIterValue.top); - keyboardLayoutParams_.PortraitPanelRect_.posX_ = - keyboardLayoutParams_.PortraitKeyboardRect_.posX_ - static_cast(porIterValue.left); - - // landscape floating keyboard - keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = layoutParams.landscapeRect.width_; - keyboardLayoutParams_.LandscapeKeyboardRect_.height_ = layoutParams.landscapeRect.height_; - keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ = layoutParams.landscapeRect.posY_; - keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = layoutParams.landscapeRect.posX_; - // landscape floating panel - keyboardLayoutParams_.LandscapePanelRect_.width_ = keyboardLayoutParams_.LandscapeKeyboardRect_.width_ + - static_cast(lanIterValue.left + lanIterValue.right); - keyboardLayoutParams_.LandscapePanelRect_.height_ = keyboardLayoutParams_.LandscapeKeyboardRect_.height_ + - static_cast(lanIterValue.top + lanIterValue.bottom); - keyboardLayoutParams_.LandscapePanelRect_.posY_ = - keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ - static_cast(lanIterValue.top); - keyboardLayoutParams_.LandscapePanelRect_.posX_ = - keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ - static_cast(lanIterValue.left); - return ErrorCode::NO_ERROR; -} - -int32_t InputMethodPanel::CalculateLandscapeRect(sptr &defaultDisplay, - const LayoutParams &layoutParams, PanelAdjustInfo &lanIterValue) -{ - // LandscapePanel - WindowSize landscapeDisplaySize; - if (!GetDisplaySize(false, landscapeDisplaySize)) { - IMSA_HILOGE("GetDisplaySize failed!"); - return ErrorCode::ERROR_WINDOW_MANAGER; - } - keyboardLayoutParams_.LandscapePanelRect_.width_ = landscapeDisplaySize.width; - keyboardLayoutParams_.LandscapePanelRect_.height_ = layoutParams.landscapeRect.height_ + - static_cast(lanIterValue.top + lanIterValue.bottom); - if (keyboardLayoutParams_.LandscapePanelRect_.height_ > - landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO) { - keyboardLayoutParams_.LandscapePanelRect_.height_ = - landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO; - } - keyboardLayoutParams_.LandscapePanelRect_.posY_ = - static_cast(landscapeDisplaySize.height - keyboardLayoutParams_.LandscapePanelRect_.height_); - keyboardLayoutParams_.LandscapePanelRect_.posX_ = NUMBER_ZERO; - // Landscapekeyboard - keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = keyboardLayoutParams_.LandscapePanelRect_.width_ - - static_cast(lanIterValue.left + lanIterValue.right); - keyboardLayoutParams_.LandscapeKeyboardRect_.height_ = keyboardLayoutParams_.LandscapePanelRect_.height_ - - static_cast(lanIterValue.top + lanIterValue.bottom); - keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ = - keyboardLayoutParams_.LandscapePanelRect_.posY_ + static_cast(lanIterValue.top); - keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = - keyboardLayoutParams_.LandscapePanelRect_.posX_ + static_cast(lanIterValue.left); - return ErrorCode::NO_ERROR; -} - int32_t InputMethodPanel::ChangePanelFlag(PanelFlag panelFlag) { if (window_ == nullptr) { @@ -1354,12 +1220,14 @@ int32_t InputMethodPanel::ChangePanelFlag(PanelFlag panelFlag) IMSA_HILOGI("flag: %{public}d, ret: %{public}d.", panelFlag, ret); return ret == WMError::WM_OK ? ErrorCode::NO_ERROR : ErrorCode::ERROR_OPERATE_PANEL; } - keyboardLayoutParams_.gravity_ = gravity; - auto ret = AdjustLayout(keyboardLayoutParams_); + auto layoutParams = GetKeyboardLayoutParams(); + layoutParams.gravity_ = gravity; + auto ret = AdjustLayout(layoutParams); if (ret == ErrorCode::NO_ERROR) { panelFlag_ = panelFlag; + NotifyPanelStatus(panelFlag); + SetKeyboardLayoutParams(layoutParams); } - NotifyPanelStatus(panelFlag); IMSA_HILOGI("flag: %{public}d, ret: %{public}d.", panelFlag, ret); return ret == ErrorCode::NO_ERROR ? ErrorCode::NO_ERROR : ErrorCode::ERROR_OPERATE_PANEL; } @@ -1787,10 +1655,10 @@ int32_t InputMethodPanel::GetKeyboardArea(PanelFlag panelFlag, const WindowSize } if (isPortrait) { keyboardArea = adjustInfo.portrait; - keyboardArea.top = enhancedLayoutParams_.portrait.avoidY; + keyboardArea.top = GetEnhancedLayoutParams().portrait.avoidY; } else { keyboardArea = adjustInfo.landscape; - keyboardArea.top = enhancedLayoutParams_.landscape.avoidY; + keyboardArea.top = GetEnhancedLayoutParams().landscape.avoidY; } return ErrorCode::NO_ERROR; } @@ -1838,11 +1706,12 @@ void InputMethodPanel::RegisterKeyboardPanelInfoChangeListener() void InputMethodPanel::OnPanelHeightChange(const Rosen::KeyboardPanelInfo &keyboardPanelInfo) { - if (panelHeightCallback_ == nullptr) { + auto heightChangeHandler = GetPanelHeightCallback(); + if (heightChangeHandler == nullptr) { return; } if (!isInEnhancedAdjust_.load()) { - panelHeightCallback_(keyboardPanelInfo.rect_.height_, panelFlag_); + heightChangeHandler(keyboardPanelInfo.rect_.height_, panelFlag_); return; } bool isPortrait = false; @@ -1851,9 +1720,9 @@ void InputMethodPanel::OnPanelHeightChange(const Rosen::KeyboardPanelInfo &keybo return; } if (isPortrait) { - panelHeightCallback_(enhancedLayoutParams_.portrait.avoidHeight, panelFlag_); + heightChangeHandler(GetEnhancedLayoutParams().portrait.avoidHeight, panelFlag_); } else { - panelHeightCallback_(enhancedLayoutParams_.landscape.avoidHeight, panelFlag_); + heightChangeHandler(GetEnhancedLayoutParams().landscape.avoidHeight, panelFlag_); } } @@ -1954,9 +1823,16 @@ bool InputMethodPanel::IsSizeValid( void InputMethodPanel::SetPanelHeightCallback(CallbackFunc heightCallback) { + std::lock_guard lock(heightCallbackMutex_); panelHeightCallback_ = std::move(heightCallback); } +InputMethodPanel::CallbackFunc InputMethodPanel::GetPanelHeightCallback() +{ + std::lock_guard lock(heightCallbackMutex_); + return panelHeightCallback_; +} + int32_t InputMethodPanel::GetDensityDpi(float &densityDpi) { auto defaultDisplay = GetCurDisplay(); @@ -2002,9 +1878,10 @@ void InputMethodPanel::SetImmersiveEffectToNone() return; } + auto layoutParams = GetKeyboardLayoutParams(); // The SetImmersiveEffect API must be called after the AdjustPanelRect API is called. Rosen::KeyboardLayoutParams emptyParams; - if (keyboardLayoutParams_ == emptyParams) { + if (layoutParams == emptyParams) { IMSA_HILOGW("set gradientHeight to zero"); return; } @@ -2013,7 +1890,7 @@ void InputMethodPanel::SetImmersiveEffectToNone() immersiveEffect_.gradientHeight = 0; immersiveEffect_.gradientMode = GradientMode::NONE; immersiveEffect_.fluidLightMode = FluidLightMode::NONE; - auto ret = AdjustLayout(keyboardLayoutParams_); + auto ret = AdjustLayout(layoutParams); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("adjust failed, ret: %{public}d", ret); immersiveEffect_ = effectTmp; @@ -2063,7 +1940,7 @@ int32_t InputMethodPanel::SetImmersiveMode(ImmersiveMode mode) return ErrorCode::NO_ERROR; } -int32_t InputMethodPanel::IsValidParam(const ImmersiveEffect &effect) +int32_t InputMethodPanel::IsValidParam(const ImmersiveEffect &effect, const KeyboardLayoutParams &layoutParams) { if (effect.gradientMode < GradientMode::NONE || effect.gradientMode >= GradientMode::END || effect.fluidLightMode < FluidLightMode::NONE || effect.fluidLightMode >= FluidLightMode::END) { @@ -2115,7 +1992,7 @@ int32_t InputMethodPanel::IsValidParam(const ImmersiveEffect &effect) // The SetImmersiveEffect API must be called after the AdjustPanelRect API is called. Rosen::KeyboardLayoutParams emptyParams; - if (keyboardLayoutParams_ == emptyParams) { + if (layoutParams == emptyParams) { IMSA_HILOGE("adjust is not call, %{public}s", effect.ToString().c_str()); return ErrorCode::ERROR_IMA_PRECONDITION_REQUIRED; } @@ -2172,7 +2049,7 @@ void InputMethodPanel::UpdateImmersiveHotArea() return; } - CalculateHotAreas(enhancedLayoutParams_, keyboardLayoutParams_, adjustInfo, hotAreas); + CalculateHotAreas(GetEnhancedLayoutParams(), GetKeyboardLayoutParams(), adjustInfo, hotAreas); auto wmsHotAreas = ConvertToWMSHotArea(hotAreas); WMError result = window_->SetKeyboardTouchHotAreas(wmsHotAreas); if (result != WMError::WM_OK) { @@ -2191,7 +2068,8 @@ int32_t InputMethodPanel::SetImmersiveEffect(const ImmersiveEffect &effect) return ErrorCode::ERROR_DEVICE_UNSUPPORTED; } - auto ret = IsValidParam(effect); + auto layoutParams = GetKeyboardLayoutParams(); + auto ret = IsValidParam(effect, layoutParams); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("invalid param, ret:%{public}d", ret); return ret; @@ -2205,7 +2083,7 @@ int32_t InputMethodPanel::SetImmersiveEffect(const ImmersiveEffect &effect) immersiveEffect_.gradientMode = GradientMode::NONE; immersiveEffect_.fluidLightMode = FluidLightMode::NONE; } - ret = AdjustLayout(keyboardLayoutParams_); + ret = AdjustLayout(layoutParams); if (ret != ErrorCode::NO_ERROR) { immersiveEffect_ = effectTmp; IMSA_HILOGE("AdjustLayout failed, ret:%{public}d", ret); @@ -2330,5 +2208,29 @@ bool InputMethodPanel::IsNeedConfig() IMSA_HILOGD("isNeedConfig is %{public}d", needConfig); return needConfig; } + +Rosen::KeyboardLayoutParams InputMethodPanel::GetKeyboardLayoutParams() +{ + std::lock_guard lock(keyboardLayoutParamsMutex_); + return keyboardLayoutParams_; +} + +void InputMethodPanel::SetKeyboardLayoutParams(Rosen::KeyboardLayoutParams params) +{ + std::lock_guard lock(keyboardLayoutParamsMutex_); + keyboardLayoutParams_ = std::move(params); +} + +EnhancedLayoutParams InputMethodPanel::GetEnhancedLayoutParams() +{ + std::lock_guard lock(enhancedLayoutParamMutex_); + return enhancedLayoutParams_; +} + +void InputMethodPanel::SetEnhancedLayoutParams(EnhancedLayoutParams params) +{ + std::lock_guard lock(enhancedLayoutParamMutex_); + enhancedLayoutParams_ = params; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp b/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp index 84dd08793..de35689bd 100644 --- a/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp +++ b/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp @@ -150,7 +150,7 @@ int32_t NumkeyAppsManager::UpdateUserBlockList(int32_t userId) return ret; } std::lock_guard lock(blockListLock_); - usersBlockList_[userId] = blockList; + usersBlockList_.insert_or_assign(userId, blockList); IMSA_HILOGI("success, list size: %{public}zu", blockList.size()); return ErrorCode::NO_ERROR; } @@ -226,7 +226,7 @@ int32_t NumkeyAppsManager::RegisterUserBlockListData(int32_t userId) } IMSA_HILOGI("end, userId: %{public}d ", userId); std::lock_guard lock(observersLock_); - observers_[userId] = observer; + observers_.insert_or_assign(userId, observer); return ErrorCode::NO_ERROR; } } // namespace MiscServices diff --git a/test/unittest/cpp_test/src/input_method_panel_adjust_test.cpp b/test/unittest/cpp_test/src/input_method_panel_adjust_test.cpp index 9fc73dbbd..a202f34bc 100644 --- a/test/unittest/cpp_test/src/input_method_panel_adjust_test.cpp +++ b/test/unittest/cpp_test/src/input_method_panel_adjust_test.cpp @@ -256,8 +256,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_002, TestSize.L Rosen::Rect validRect = { 1, 1, 100, 100 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, 50, 50 }, - .landscape = { validRect, 50, 50 }, + .portrait = { portraitRect, {}, 50, 50 }, + .landscape = { validRect, {}, 50, 50 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -282,8 +282,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_003, TestSize.L Rosen::Rect validRect = { 1, 1, 100, 100 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { validRect, 50, 50 }, - .landscape = { portraitRect, 50, 50 }, + .portrait = { validRect, {}, 50, 50 }, + .landscape = { portraitRect, {}, 50, 50 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -310,8 +310,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_004, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, 50, 50 }, - .landscape = { landscapeRect, 50, 50 }, + .portrait = { portraitRect, {}, 50, 50 }, + .landscape = { landscapeRect, {}, 50, 50 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -338,8 +338,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_005, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, 50, 50 }, - .landscape = { landscapeRect, 50, 50 }, + .portrait = { portraitRect, {}, 50, 50 }, + .landscape = { landscapeRect, {}, 50, 50 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -366,8 +366,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_006, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width + 1, display.landscape.height - 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, 50, 50 }, - .landscape = { landscapeRect, 50, 50 }, + .portrait = { portraitRect, {}, 50, 50 }, + .landscape = { landscapeRect, {}, 50, 50 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -394,8 +394,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_007, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height + 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, 50, 50 }, - .landscape = { landscapeRect, 50, 50 }, + .portrait = { portraitRect, {}, 50, 50 }, + .landscape = { landscapeRect, {}, 50, 50 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -422,8 +422,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_008, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, -1, 0 }, - .landscape = { landscapeRect, 1, 0 }, + .portrait = { portraitRect, {}, -1, 0 }, + .landscape = { landscapeRect, {}, 1, 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -450,8 +450,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_009, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, static_cast(portraitRect.height_) + 1, 0 }, - .landscape = { landscapeRect, static_cast(landscapeRect.height_) - 1, 0 }, + .portrait = { portraitRect, {}, static_cast(portraitRect.height_) + 1, 0 }, + .landscape = { landscapeRect, {}, static_cast(landscapeRect.height_) - 1, 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -478,8 +478,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_010, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, 1, 0 }, - .landscape = { landscapeRect, -1, 0 }, + .portrait = { portraitRect, {}, 1, 0 }, + .landscape = { landscapeRect, {}, -1, 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -506,8 +506,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_011, TestSize.L Rosen::Rect landscapeRect = { 0, 0, display.landscape.width - 1, display.landscape.height - 1 }; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, static_cast(portraitRect.height_) - 1, 0 }, - .landscape = { landscapeRect, static_cast(landscapeRect.height_) + 1, 0 }, + .portrait = { portraitRect, {}, static_cast(portraitRect.height_) - 1, 0 }, + .landscape = { landscapeRect, {}, static_cast(landscapeRect.height_) + 1, 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -536,8 +536,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_012, TestSize.L uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = true, - .portrait = { {}, static_cast(portraitAvoidY), 0 }, - .landscape = { {}, static_cast(landscapeAvoidY), 0 }, + .portrait = { {}, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { {}, {}, static_cast(landscapeAvoidY), 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -566,8 +566,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_013, TestSize.L uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = true, - .portrait = { {}, static_cast(portraitAvoidY), 0 }, - .landscape = { {}, static_cast(landscapeAvoidY), 0 }, + .portrait = { {}, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { {}, {}, static_cast(landscapeAvoidY), 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -598,8 +598,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_014, TestSize.L uint32_t landscapeAvoidY = landscapeRect.height_ - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, static_cast(portraitAvoidY), 0 }, - .landscape = { landscapeRect, static_cast(landscapeAvoidY), 0 }, + .portrait = { portraitRect, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { landscapeRect, {}, static_cast(landscapeAvoidY), 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -630,8 +630,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_015, TestSize.L uint32_t landscapeAvoidY = landscapeRect.height_ - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, static_cast(portraitAvoidY), 0 }, - .landscape = { landscapeRect, static_cast(landscapeAvoidY), 0 }, + .portrait = { portraitRect, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { landscapeRect, {}, static_cast(landscapeAvoidY), 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -662,8 +662,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_016, TestSize.L uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = true, - .portrait = { portraitRect, static_cast(portraitAvoidY), 0 }, - .landscape = { landscapeRect, static_cast(landscapeAvoidY), 0 }, + .portrait = { portraitRect, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { landscapeRect, {}, static_cast(landscapeAvoidY), 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -830,8 +830,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testAdjustEnhancedPanelRect_020, TestSize.L uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = false, - .portrait = { portraitRect, static_cast(portraitAvoidY), 0 }, - .landscape = { landscapeRect, static_cast(landscapeAvoidY), 0 }, + .portrait = { portraitRect, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { landscapeRect, {}, static_cast(landscapeAvoidY), 0 }, }; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, {}); EXPECT_EQ(ret, ErrorCode::NO_ERROR); @@ -1066,8 +1066,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_007, TestSize.Level0 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = true, - .portrait = { {}, static_cast(portraitAvoidY), 0 }, - .landscape = { {}, static_cast(landscapeAvoidY), 0 }, + .portrait = { {}, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { {}, {}, static_cast(landscapeAvoidY), 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); @@ -1107,8 +1107,8 @@ HWTEST_F(InputMethodPanelAdjustTest, testSetImmersiveEffect_008, TestSize.Level0 uint32_t landscapeAvoidY = display.landscape.height - landscapeAvoidHeight; EnhancedLayoutParams params = { .isFullScreen = true, - .portrait = { {}, static_cast(portraitAvoidY), 0 }, - .landscape = { {}, static_cast(landscapeAvoidY), 0 }, + .portrait = { {}, {}, static_cast(portraitAvoidY), 0 }, + .landscape = { {}, {}, static_cast(landscapeAvoidY), 0 }, }; HotAreas hotAreas; auto ret = inputMethodPanel->AdjustPanelRect(panelFlag, params, hotAreas); -- Gitee