From bf7d04d82d713754aaa7149114496b1e1ae6db62 Mon Sep 17 00:00:00 2001 From: jiyujia926 Date: Sat, 28 Oct 2023 17:53:10 +0800 Subject: [PATCH] =?UTF-8?q?UIExtension=E8=BD=AF=E9=94=AE=E7=9B=98=E9=81=BF?= =?UTF-8?q?=E8=AE=A9=20Signed-off-by:=20jiyujia926=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../innerkits/wm/occupied_area_change_info.h | 9 ++++++- interfaces/innerkits/wm/window.h | 7 +++++ .../common/include/window_session_property.h | 9 +++++++ .../common/src/window_session_property.cpp | 27 ++++++++++++++++++- .../session/host/include/scene_session.h | 4 +++ .../host/include/zidl/session_interface.h | 1 + .../session/host/src/scene_session.cpp | 7 +++++ .../include/scene_session_manager.h | 2 +- .../src/scene_session_manager.cpp | 13 ++++----- wm/include/window_session_impl.h | 4 +++ wm/src/window_scene_session_impl.cpp | 2 ++ wm/src/window_session_impl.cpp | 7 +++++ 12 files changed, 83 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/wm/occupied_area_change_info.h b/interfaces/innerkits/wm/occupied_area_change_info.h index 4fbf8043eb..c253052a6f 100644 --- a/interfaces/innerkits/wm/occupied_area_change_info.h +++ b/interfaces/innerkits/wm/occupied_area_change_info.h @@ -29,6 +29,8 @@ public: OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect) : type_(type), rect_(rect) {}; OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect, uint32_t safeHeight) : type_(type), rect_(rect), safeHeight_(safeHeight) {}; + OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect, uint32_t safeHeight, double textFieldPositionY, double textFieldHeight) + : type_(type), rect_(rect), safeHeight_(safeHeight), textFieldPositionY_(textFieldPositionY), textFieldHeight_(textFieldHeight) {}; ~OccupiedAreaChangeInfo() = default; virtual bool Marshalling(Parcel& parcel) const @@ -36,7 +38,8 @@ public: return parcel.WriteInt32(rect_.posX_) && parcel.WriteInt32(rect_.posY_) && parcel.WriteUint32(rect_.width_) && parcel.WriteUint32(rect_.height_) && parcel.WriteUint32(static_cast(type_)) && - parcel.WriteUint32(safeHeight_); + parcel.WriteUint32(safeHeight_) && + parcel.WriteDouble(textFieldPositionY_) && parcel.WriteDouble(textFieldHeight_); } static OccupiedAreaChangeInfo* Unmarshalling(Parcel& parcel) @@ -52,12 +55,16 @@ public: } occupiedAreaChangeInfo->type_ = static_cast(parcel.ReadUint32()); occupiedAreaChangeInfo->safeHeight_ = parcel.ReadUint32(); + occupiedAreaChangeInfo->textFieldPositionY_ = parcel.ReadDouble(); + occupiedAreaChangeInfo->textFieldHeight_ = parcel.ReadDouble(); return occupiedAreaChangeInfo; } OccupiedAreaType type_ = OccupiedAreaType::TYPE_INPUT; Rect rect_ = { 0, 0, 0, 0 }; uint32_t safeHeight_ = 0; + double textFieldPositionY_ = 0.0; + double textFieldHeight_ = 0.0; }; } // namespace OHOS::Rosen #endif // OHOS_OCCUPIED_AREA_CHANGE_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 2703d12b8d..c8ee062769 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -1376,6 +1376,13 @@ public: * @return True means floating window of app type, false means the opposite. */ virtual bool IsFloatingWindowAppType() const { return false; } + + /** + * @brief Set Text Field Avoid Info. + * + * @return Errorcode of window. + */ + virtual WMError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) { return WMError::WM_OK; } }; } } diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index a8cf8cf853..2323039365 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -136,6 +136,12 @@ public: bool Marshalling(Parcel& parcel) const override; static WindowSessionProperty* Unmarshalling(Parcel& parcel); + void SetTextFieldPositionY(double textFieldPositionY); + void SetTextFieldHeight(double textFieldHeight); + + double GetTextFieldPositionY() const; + double GetTextFieldHeight() const; + private: bool MarshallingTouchHotAreas(Parcel& parcel) const; static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowSessionProperty* property); @@ -179,6 +185,9 @@ private: std::vector touchHotAreas_; // coordinates relative to window. bool hideNonSystemFloatingWindows_ = false; bool forceHide_ = false; + + double textFieldPositionY_ = 0.0; + double textFieldHeight_ = 0.0; }; struct SystemSessionConfig : public Parcelable { diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp index 3b07b52e2d..20824285d7 100755 --- a/window_scene/common/src/window_session_property.cpp +++ b/window_scene/common/src/window_session_property.cpp @@ -495,7 +495,8 @@ bool WindowSessionProperty::Marshalling(Parcel& parcel) const MarshallingWindowLimits(parcel) && parcel.WriteFloat(brightness_) && MarshallingSystemBarMap(parcel) && parcel.WriteUint32(animationFlag_) && parcel.WriteBool(isFloatingWindowAppType_) && MarshallingTouchHotAreas(parcel) && - parcel.WriteBool(isSystemCalling_); + parcel.WriteBool(isSystemCalling_) && + parcel.WriteDouble(textFieldPositionY_) && parcel.WriteDouble(textFieldHeight_); } WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) @@ -539,6 +540,8 @@ WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) property->SetFloatingWindowAppType(parcel.ReadBool()); UnmarshallingTouchHotAreas(parcel, property); property->SetSystemCalling(parcel.ReadBool()); + property->SetTextFieldPositionY(parcel.ReadDouble()); + property->SetTextFieldHeight(parcel.ReadDouble()); return property; } @@ -577,6 +580,8 @@ void WindowSessionProperty::CopyFrom(const sptr& property isFloatingWindowAppType_ = property->isFloatingWindowAppType_; touchHotAreas_ = property->touchHotAreas_; isSystemCalling_ = property->isSystemCalling_; + textFieldPositionY_ = property->textFieldPositionY_; + textFieldHeight_ = property->textFieldHeight_; } void WindowSessionProperty::SetTransform(const Transform& trans) @@ -588,5 +593,25 @@ const Transform& WindowSessionProperty::GetTransform() const { return trans_; } + +void WindowSessionProperty::SetTextFieldPositionY(double textFieldPositionY) +{ + textFieldPositionY_ = textFieldPositionY; +} + +void WindowSessionProperty::SetTextFieldHeight(double textFieldHeight) +{ + textFieldHeight_ = textFieldHeight; +} + +double WindowSessionProperty::GetTextFieldPositionY() const +{ + return textFieldPositionY_; +} + +double WindowSessionProperty::GetTextFieldHeight() const +{ + return textFieldHeight_; +} } // namespace Rosen } // namespace OHOS diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 518171f071..9636ad06c6 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -236,6 +236,10 @@ private: WSRect lastSafeRect = { 0, 0, 0, 0 }; std::vector> subSession_; bool needDefaultAnimationFlag_ = true; +public: + double textFieldPositionY_ = 0.0; + double textFieldHeight_ = 0.0; + WSError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index dbead64430..34d037321a 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -63,6 +63,7 @@ public: { return WSError::WS_OK; } virtual WSError TerminateSession(const sptr abilitySessionInfo) { return WSError::WS_OK; } virtual WSError NotifySessionException(const sptr abilitySessionInfo) { return WSError::WS_OK; } + virtual WSError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) { return WSError::WS_OK; } // extension session virtual WSError TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want) { return WSError::WS_OK; } diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 7318482da6..bad11e5ea5 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -127,6 +127,7 @@ WSError SceneSession::Foreground(sptr property) session->setWindowScenePatternFunc_->setOpacityFunc_(0.0f); } } + weakThis->SetTextFieldAvoidInfo(property->GetTextFieldPositionY(), property->GetTextFieldHeight()); auto ret = session->Session::Foreground(property); if (ret != WSError::WS_OK) { return ret; @@ -1807,4 +1808,10 @@ void SceneSession::SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFun moveDragController_->SetWindowDragHotAreaFunc(func); } } +WSError SceneSession::SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) +{ + textFieldPositionY_ = textFieldPositionY; + textFieldHeight_ = textFieldHeight; + return WSError::WS_OK; +} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 961d028c29..f3b3bf428a 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -183,7 +183,7 @@ public: WMError GetAccessibilityWindowInfo(std::vector>& infos); WSError SetWindowFlags(const sptr& sceneSession, uint32_t flags); - void NotifyOccupiedAreaChangeInfo(const sptr callingSession, + void NotifyOccupiedAreaChangeInfo(const sptr sceneSession, const WSRect& rect, const WSRect& occupiedArea); void OnScreenshot(DisplayId displayId); void NotifyDumpInfoResult(const std::vector& info); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 98b3b28bf0..3af10974c0 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -954,6 +954,7 @@ void SceneSessionManager::OnInputMethodShown(const int32_t& persistentId) return; } callingSession_ = GetSceneSession(focusedSessionId_); + callingSession_->SetTextFieldAvoidInfo(scnSession->textFieldPositionY_, scnSession->textFieldHeight_); ResizeSoftInputCallingSessionIfNeed(scnSession); } @@ -4009,29 +4010,29 @@ void SceneSessionManager::ResizeSoftInputCallingSessionIfNeed( if (!isInputUpdated) { callingWindowRestoringRect_ = callingSessionRect; } - NotifyOccupiedAreaChangeInfo(callingSession_, newRect, softInputSessionRect); + NotifyOccupiedAreaChangeInfo(sceneSession, newRect, softInputSessionRect); if (isCallingSessionFloating) { needUpdateSessionRect_ = true; callingSession_->UpdateSessionRect(newRect, SizeChangeReason::UNDEFINED); } } -void SceneSessionManager::NotifyOccupiedAreaChangeInfo(const sptr callingSession, +void SceneSessionManager::NotifyOccupiedAreaChangeInfo(const sptr sceneSession, const WSRect& rect, const WSRect& occupiedArea) { // if keyboard will occupy calling, notify calling window the occupied area and safe height const WSRect& safeRect = SessionHelper::GetOverlap(occupiedArea, rect, 0, 0); - const WSRect& lastSafeRect = callingSession->GetLastSafeRect(); + const WSRect& lastSafeRect = callingSession_->GetLastSafeRect(); if (lastSafeRect == safeRect) { WLOGFI("NotifyOccupiedAreaChangeInfo lastSafeRect is same to safeRect"); return; } - callingSession->SetLastSafeRect(safeRect); + callingSession_->SetLastSafeRect(safeRect); sptr info = new OccupiedAreaChangeInfo(OccupiedAreaType::TYPE_INPUT, - SessionHelper::TransferToRect(safeRect), safeRect.height_); + SessionHelper::TransferToRect(safeRect), safeRect.height_, sceneSession->textFieldPositionY_, sceneSession->textFieldHeight_); WLOGFD("OccupiedAreaChangeInfo rect: %{public}u %{public}u %{public}u %{public}u", occupiedArea.posX_, occupiedArea.posY_, occupiedArea.width_, occupiedArea.height_); - callingSession->NotifyOccupiedAreaChangeInfo(info); + callingSession_->NotifyOccupiedAreaChangeInfo(info); } void SceneSessionManager::RestoreCallingSessionSizeIfNeed() diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 4b97bdff44..e4959afd82 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -53,6 +53,7 @@ public: const sptr& iSession); WMError Show(uint32_t reason = 0, bool withAnimation = false) override; WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) override; + WMError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; WMError Destroy() override; virtual WMError Destroy(bool needNotifyServer, bool needClearListener = true); WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, @@ -155,6 +156,9 @@ public: WindowState state_ { WindowState::STATE_INITIAL }; WindowState requestState_ { WindowState::STATE_INITIAL }; + double textFieldPositionY_ = 0; + double textFieldHeight_ = 0; + protected: WMError Connect(); bool IsWindowSessionInvalid() const; diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 41c8bca1bd..9c9d06c3aa 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -438,6 +438,8 @@ WMError WindowSceneSessionImpl::Show(uint32_t reason, bool withAnimation) return ret; } UpdateTitleButtonVisibility(); + property_->SetTextFieldPositionY(textFieldPositionY_); + property_->SetTextFieldHeight(textFieldHeight_); ret = static_cast(hostSession_->Foreground(property_)); if (ret == WMError::WM_OK) { // update sub window state if this is main window diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 631948bc30..3deb4ac7e3 100755 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1631,6 +1631,13 @@ WMError WindowSessionImpl::SetSystemBarProperty(WindowType type, const SystemBar return WMError::WM_OK; } +WMError WindowSessionImpl::SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) +{ + textFieldPositionY_ = textFieldPositionY; + textFieldHeight_ = textFieldHeight; + return WMError::WM_OK; +} + void WindowSessionImpl::NotifyOccupiedAreaChangeInfo(sptr info) { WLOGFD("NotifyOccupiedAreaChangeInfo, safeHeight: %{public}u " -- Gitee