!41336 旋转避让问题avoidArea部分代码

Merge pull request !41336 from CamlostShi/master
This commit is contained in:
openharmony_ci 2024-09-08 10:23:11 +00:00 committed by Gitee
commit f96b574d82
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 177 additions and 36 deletions

View File

@ -303,6 +303,94 @@ void AddAlarmLogFunc()
OHOS::Rosen::RSTransactionData::AddAlarmLog(logFunc);
}
void DeduplicateAvoidAreas(const RefPtr<NG::PipelineContext>& context,
std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets>& updatingInsets,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas,
const ViewportConfig& config)
{
CHECK_NULL_VOID(context);
auto safeAreaManager = context->GetSafeAreaManager();
CHECK_NULL_VOID(safeAreaManager);
for (auto& avoidArea : avoidAreas) {
if (avoidArea.first == OHOS::Rosen::AvoidAreaType::TYPE_SYSTEM) {
NG::SafeAreaInsets insets = ConvertAvoidArea(avoidArea.second);
if (safeAreaManager->CheckSystemSafeArea(insets)) {
updatingInsets[avoidArea.first] = insets;
}
} else if (avoidArea.first == OHOS::Rosen::AvoidAreaType::TYPE_NAVIGATION_INDICATOR) {
NG::SafeAreaInsets insets = ConvertAvoidArea(avoidArea.second);
if (safeAreaManager->CheckNavArea(insets)) {
updatingInsets[avoidArea.first] = insets;
}
} else if (avoidArea.first == OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT && context->GetUseCutout()) {
NG::SafeAreaInsets insets = ConvertAvoidArea(avoidArea.second);
if (safeAreaManager->CheckCutoutSafeArea(insets,
NG::OptionalSize<uint32_t>(config.Width(), config.Height()))) {
updatingInsets[avoidArea.first] = insets;
}
}
}
}
void ParseAvoidAreasUpdate(const RefPtr<NG::PipelineContext>& context,
const std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets>& updatingInsets,
const ViewportConfig& config)
{
if (updatingInsets.empty()) {
return;
}
CHECK_NULL_VOID(context);
auto safeAreaManager = context->GetSafeAreaManager();
CHECK_NULL_VOID(safeAreaManager);
for (auto& insets : updatingInsets) {
if (insets.first == OHOS::Rosen::AvoidAreaType::TYPE_SYSTEM) {
safeAreaManager->UpdateSystemSafeArea(insets.second);
} else if (insets.first == OHOS::Rosen::AvoidAreaType::TYPE_NAVIGATION_INDICATOR) {
safeAreaManager->UpdateNavArea(insets.second);
} else if (insets.first == OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT && context->GetUseCutout()) {
safeAreaManager->UpdateCutoutSafeArea(insets.second,
NG::OptionalSize<uint32_t>(config.Width(), config.Height()));
}
}
context->SyncSafeArea(SafeAreaSyncType::SYNC_TYPE_AVOID_AREA);
}
void AvoidAreasUpdateOnUIExtension(const RefPtr<NG::PipelineContext>& context,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas)
{
if (avoidAreas.empty()) {
return;
}
CHECK_NULL_VOID(context);
// for ui extension component
for (auto& avoidArea : avoidAreas) {
context->UpdateOriginAvoidArea(avoidArea.second, static_cast<uint32_t>(avoidArea.first));
}
}
void UpdateSafeArea(const RefPtr<PipelineBase>& pipelineContext,
const std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets>& updatingInsets,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas,
const ViewportConfig& config,
const RefPtr<Platform::AceContainer>& container)
{
CHECK_NULL_VOID(container);
CHECK_NULL_VOID(pipelineContext);
auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
CHECK_NULL_VOID(context);
auto safeAreaManager = context->GetSafeAreaManager();
CHECK_NULL_VOID(safeAreaManager);
uint32_t keyboardHeight = safeAreaManager->GetKeyboardInset().Length();
safeAreaManager->UpdateKeyboardSafeArea(keyboardHeight, config.Height());
if (updatingInsets.find(OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT) == updatingInsets.end()) {
safeAreaManager->UpdateCutoutSafeArea(container->GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_CUTOUT),
NG::OptionalSize<uint32_t>(config.Width(), config.Height()));
}
ParseAvoidAreasUpdate(context, updatingInsets, config);
AvoidAreasUpdateOnUIExtension(context, avoidAreas);
}
class OccupiedAreaChangeListener : public OHOS::Rosen::IOccupiedAreaChangeListener {
public:
explicit OccupiedAreaChangeListener(int32_t instanceId) : instanceId_(instanceId) {}
@ -1894,7 +1982,6 @@ void UIContentImpl::InitializeSafeArea(const RefPtr<Platform::AceContainer>& con
if (pipeline && pipeline->GetMinPlatformVersion() >= PLATFORM_VERSION_TEN &&
(pipeline->GetIsAppWindow() || container->IsUIExtensionWindow())) {
avoidAreaChangedListener_ = new AvoidAreaChangedListener(instanceId_);
window_->RegisterAvoidAreaChangeListener(avoidAreaChangedListener_);
pipeline->UpdateSystemSafeArea(container->GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_SYSTEM));
if (pipeline->GetUseCutout()) {
pipeline->UpdateCutoutSafeArea(container->GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_CUTOUT));
@ -2260,14 +2347,16 @@ void UIContentImpl::UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::
}
void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction)
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas)
{
UpdateViewportConfigWithAnimation(config, reason, {}, rsTransaction);
UpdateViewportConfigWithAnimation(config, reason, {}, rsTransaction, avoidAreas);
}
void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& config,
OHOS::Rosen::WindowSizeChangeReason reason, AnimationOption animationOpt,
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction)
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas)
{
LOGI("[%{public}s][%{public}s][%{public}d]: UpdateViewportConfig %{public}s, windowSizeChangeReason %d",
bundleName_.c_str(), moduleName_.c_str(), instanceId_, config.ToString().c_str(),
@ -2306,21 +2395,20 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf
RefPtr<NG::SafeAreaManager> safeAreaManager = nullptr;
auto pipelineContext = container->GetPipelineContext();
auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets> updatingInsets;
if (context) {
safeAreaManager = context->GetSafeAreaManager();
}
auto task = [config = modifyConfig, container, reason, rsTransaction, rsWindow = window_, safeAreaManager,
isDynamicRender = isDynamicRender_, animationOpt]() {
if (safeAreaManager) {
DeduplicateAvoidAreas(context, updatingInsets, avoidAreas, config);
}
auto task = [config = modifyConfig, container, reason, rsTransaction, rsWindow = window_,
isDynamicRender = isDynamicRender_, animationOpt, updatingInsets, avoidAreas]() {
container->SetWindowPos(config.Left(), config.Top());
auto pipelineContext = container->GetPipelineContext();
if (pipelineContext) {
if (safeAreaManager) {
uint32_t keyboardHeight = safeAreaManager->GetKeyboardInset().Length();
safeAreaManager->UpdateKeyboardSafeArea(keyboardHeight, config.Height());
safeAreaManager->UpdateCutoutSafeArea(
container->GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_CUTOUT),
NG::OptionalSize<uint32_t>(config.Width(), config.Height()));
}
UpdateSafeArea(pipelineContext, updatingInsets, avoidAreas, config, container);
pipelineContext->SetDisplayWindowRectInfo(
Rect(Offset(config.Left(), config.Top()), Size(config.Width(), config.Height())));
TAG_LOGI(AceLogTag::ACE_WINDOW, "Update displayAvailableRect to : %{public}s",
@ -2366,11 +2454,13 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf
};
taskExecutor->PostTask(std::move(changeBrightnessTask), TaskExecutor::TaskType::UI, "ArkUIUpdateBrightness");
AceViewportConfig aceViewportConfig(modifyConfig, reason, rsTransaction);
if (container->IsUseStageModel() && (reason == OHOS::Rosen::WindowSizeChangeReason::ROTATION ||
reason == OHOS::Rosen::WindowSizeChangeReason::UPDATE_DPI_SYNC)) {
bool isReasonRotationOrDPI = (reason == OHOS::Rosen::WindowSizeChangeReason::ROTATION ||
reason == OHOS::Rosen::WindowSizeChangeReason::UPDATE_DPI_SYNC);
if (container->IsUseStageModel() && isReasonRotationOrDPI) {
viewportConfigMgr_->UpdateConfigSync(aceViewportConfig, std::move(task));
} else if (rsTransaction != nullptr) {
} else if (rsTransaction != nullptr || !updatingInsets.empty()) {
// When rsTransaction is not nullptr, the task contains animation. It shouldn't be cancled.
// When avoidAreas need updating, the task shouldn't be cancelled.
taskExecutor->PostTask(std::move(task), TaskExecutor::TaskType::PLATFORM, "ArkUIUpdateViewportConfig");
} else {
viewportConfigMgr_->UpdateConfig(aceViewportConfig, std::move(task), container, "ArkUIUpdateViewportConfig");

View File

@ -92,9 +92,11 @@ public:
bool ProcessVsyncEvent(uint64_t timeStampNanos) override;
void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override;
void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr) override;
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {}) override;
void UpdateViewportConfigWithAnimation(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
AnimationOption animationOpt, const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr);
AnimationOption animationOpt, const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {});
void UIExtensionUpdateViewportConfig(const ViewportConfig& config);
void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override;
void UpdateDecorVisible(bool visible, bool hasDeco) override;
@ -329,12 +331,12 @@ public:
void SetContentNodeGrayScale(float grayscale) override;
void PreLayout() override;
sptr<IRemoteObject> GetRemoteObj() override
{
return instance_;
}
void SetStatusBarItemColor(uint32_t color) override;
void SetFontScaleAndWeightScale(const RefPtr<Platform::AceContainer>& container, int32_t instanceId);

View File

@ -537,7 +537,8 @@ bool UIContentImpl::ProcessVsyncEvent(uint64_t timeStampNanos)
void UIContentImpl::UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) {}
void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction)
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas)
{
LOGI("ViewportConfig: %{public}s", config.ToString().c_str());
auto container = AceContainer::GetContainerInstance(instanceId_);

View File

@ -79,7 +79,8 @@ public:
void SetIsFocusActive(bool isFocusActive) override {}
void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override;
void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr) override;
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {}) override;
void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override {}
void UpdateDecorVisible(bool visible, bool hasDeco = true) override {};
void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose) override {}
@ -147,7 +148,7 @@ public:
void SetContentNodeGrayScale(float grayscale) override {};
void PreLayout() override {};
void SetStatusBarItemColor(uint32_t color) override;
void SetForceSplitEnable(bool isForceSplit, const std::string& homePage) override {};

View File

@ -18,11 +18,11 @@
#include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
namespace OHOS::Ace::NG {
bool SafeAreaManager::UpdateCutoutSafeArea(const SafeAreaInsets& safeArea, NG::OptionalSize<uint32_t> rootSize)
SafeAreaInsets GenerateCutOutAreaWithRoot(const SafeAreaInsets& safeArea, NG::OptionalSize<uint32_t> rootSize)
{
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_RETURN(pipeline, false);
CHECK_NULL_RETURN(pipeline->GetUseCutout(), false);
CHECK_NULL_RETURN(pipeline, {});
CHECK_NULL_RETURN(pipeline->GetUseCutout(), {});
// cutout regions adjacent to edges.
auto cutoutArea = safeArea;
@ -40,14 +40,29 @@ bool SafeAreaManager::UpdateCutoutSafeArea(const SafeAreaInsets& safeArea, NG::O
cutoutArea.right_.end = rootSize.Width().has_value() ? rootSize.Width().value()
: PipelineContext::GetCurrentRootWidth();
}
return cutoutArea;
}
if (cutoutSafeArea_ == cutoutArea) {
bool SafeAreaManager::CheckCutoutSafeArea(const SafeAreaInsets& safeArea, NG::OptionalSize<uint32_t> rootSize)
{
return cutoutSafeArea_ != GenerateCutOutAreaWithRoot(safeArea, rootSize);
}
bool SafeAreaManager::UpdateCutoutSafeArea(const SafeAreaInsets& safeArea, NG::OptionalSize<uint32_t> rootSize)
{
auto safeAreaWithRoot = GenerateCutOutAreaWithRoot(safeArea, rootSize);
if (cutoutSafeArea_ == safeAreaWithRoot) {
return false;
}
cutoutSafeArea_ = cutoutArea;
cutoutSafeArea_ = safeAreaWithRoot;
return true;
}
bool SafeAreaManager::CheckSystemSafeArea(const SafeAreaInsets& safeArea)
{
return systemSafeArea_ != safeArea;
}
bool SafeAreaManager::UpdateSystemSafeArea(const SafeAreaInsets& safeArea)
{
if (systemSafeArea_ == safeArea) {
@ -57,6 +72,11 @@ bool SafeAreaManager::UpdateSystemSafeArea(const SafeAreaInsets& safeArea)
return true;
}
bool SafeAreaManager::CheckNavArea(const SafeAreaInsets& safeArea)
{
return navSafeArea_ != safeArea;
}
bool SafeAreaManager::UpdateNavArea(const SafeAreaInsets& safeArea)
{
if (navSafeArea_ == safeArea) {

View File

@ -31,6 +31,14 @@ public:
SafeAreaManager() = default;
~SafeAreaManager() override = default;
/**
* @brief Check if the incoming safe area is identical to the system safe area
*
* @param safeArea The new system safe area.
* @return True if the incoming safe area is identical to the current one, false otherwise.
*/
bool CheckSystemSafeArea(const SafeAreaInsets& safeArea);
/**
* @brief Updates the system safe area.
*
@ -39,6 +47,14 @@ public:
*/
bool UpdateSystemSafeArea(const SafeAreaInsets& safeArea);
/**
* @brief Check if the incoming safe area is identical to the navigation indictor safe area.
*
* @param safeArea The new navigation indictor safe area.
* @return True if the incoming safe area is identical to the current one, false otherwise.
*/
bool CheckNavArea(const SafeAreaInsets& safeArea);
/**
* @brief Updates the navigation indictor safe area.
*
@ -57,6 +73,15 @@ public:
*/
SafeAreaInsets GetSystemSafeArea() const;
/**
* @brief Cut the incoming area with root size, then check if the result is identical to the cutout safe area.
*
* @param safeArea The SafeAreaInsets representing the new cutout safe area, which would be modified.
* @return True if the incoming safe area is identical to the current one, false otherwise.
*/
bool CheckCutoutSafeArea(
const SafeAreaInsets& safeArea, NG::OptionalSize<uint32_t> rootSize = NG::OptionalSize<uint32_t>());
/**
* @brief Updates the cutout safe area.
*

View File

@ -897,6 +897,8 @@ public:
void CollectTouchEventsBeforeVsync(std::list<TouchEvent>& touchEvents);
void SyncSafeArea(SafeAreaSyncType syncType = SafeAreaSyncType::SYNC_TYPE_NONE);
protected:
void StartWindowSizeChangeAnimate(int32_t width, int32_t height, WindowSizeChangeReason type,
const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
@ -972,7 +974,6 @@ private:
FrameInfo* GetCurrentFrameInfo(uint64_t recvTime, uint64_t timeStamp);
void AnimateOnSafeAreaUpdate();
void SyncSafeArea(SafeAreaSyncType syncType = SafeAreaSyncType::SYNC_TYPE_NONE);
// only used for static form.
void UpdateFormLinkInfos();

View File

@ -56,6 +56,8 @@ enum class MaximizeMode : uint32_t;
class RSSurfaceNode;
class RSTransaction;
class Transform;
enum class AvoidAreaType : uint32_t;
class AvoidArea;
} // namespace Rosen
namespace AAFwk {
@ -138,7 +140,8 @@ public:
virtual void SetIsFocusActive(bool isFocusActive) = 0;
virtual void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) = 0;
virtual void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr) = 0;
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr,
const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {}) {};
virtual void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) = 0;
virtual void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose) = 0;
virtual void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) = 0;
@ -390,13 +393,13 @@ public:
* @param config Indicates the ID of the UI node which bind the pupop
*/
virtual void DestroyCustomPopupUIExtension(int32_t nodeId) {}
/**
* @description: Update the custom popup.
* @param config Indicates the custom popup configs.
*/
virtual void UpdateCustomPopupUIExtension(const CustomPopupUIExtensionConfig& config) {}
virtual SerializedGesture GetFormSerializedGesture()
{
return SerializedGesture();
@ -421,14 +424,14 @@ public:
const std::function<void(std::vector<Ace::RectF>)>& callback) const {};
virtual void SetContentNodeGrayScale(float grayscale) {};
virtual sptr<IRemoteObject> GetRemoteObj()
{
return {};
}
virtual void PreLayout() {};
virtual void SetStatusBarItemColor(uint32_t color) {};
virtual void SetForceSplitEnable(bool isForceSplit, const std::string& homePage) {};

View File

@ -58,8 +58,6 @@ public:
MOCK_METHOD1(ProcessAxisEvent, bool(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent));
MOCK_METHOD1(ProcessVsyncEvent, bool(uint64_t timeStampNanos));
MOCK_METHOD1(UpdateConfiguration, void(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config));
MOCK_METHOD3(UpdateViewportConfig, void(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction));
MOCK_METHOD2(UpdateWindowMode, void(OHOS::Rosen::WindowMode mode, bool hasDeco));
MOCK_METHOD2(UpdateTitleInTargetPos, void(bool isShow, int32_t height));
MOCK_METHOD2(UpdateDecorVisible, void(bool visible, bool hasDeco));