From b842e3a4778e392d9ab8169ab73dc93c58811365 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Wed, 16 Mar 2022 11:05:07 +0800 Subject: [PATCH] add window drag with blur Signed-off-by: jiangdayuan --- adapter/ohos/entrance/ace_ability.cpp | 15 +------ adapter/ohos/entrance/ace_ability.h | 1 - adapter/ohos/entrance/ui_content_impl.cpp | 2 +- .../core/common/window_animation_config.h | 2 + .../container_modal_element.cpp | 42 +++++++++++++++---- .../container_modal/container_modal_element.h | 2 + frameworks/core/pipeline/pipeline_context.cpp | 32 +++++++++++++- frameworks/core/pipeline/pipeline_context.h | 3 ++ 8 files changed, 76 insertions(+), 23 deletions(-) diff --git a/adapter/ohos/entrance/ace_ability.cpp b/adapter/ohos/entrance/ace_ability.cpp index 8a82af0dbd5..45e093f36b3 100644 --- a/adapter/ohos/entrance/ace_ability.cpp +++ b/adapter/ohos/entrance/ace_ability.cpp @@ -639,8 +639,8 @@ void AceAbility::OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeCha metrics.physical_height = height; metrics.device_pixel_ratio = density; Platform::FlutterAceView::SetViewportMetrics(flutterAceView, metrics); - Platform::FlutterAceView::SurfaceChanged(flutterAceView, width, height, 0, - Convert2WindowSizeChangeReason(reason)); + Platform::FlutterAceView::SurfaceChanged( + flutterAceView, width, height, 0, static_cast(reason)); }, TaskExecutor::TaskType::PLATFORM); } @@ -649,17 +649,6 @@ void AceAbility::OnModeChange(OHOS::Rosen::WindowMode mode) LOGI("AceAbility::OnModeChange"); } -WindowSizeChangeReason AceAbility::Convert2WindowSizeChangeReason(OHOS::Rosen::WindowSizeChangeReason reason) -{ - auto reasonValue = static_cast(reason); - constexpr uint32_t MAX_REASON_VALUE = 5; - if (reasonValue > MAX_REASON_VALUE) { - LOGE("AceAbility: unsupported WindowSizeChangeReason"); - return WindowSizeChangeReason::UNDEFINED; - } - return static_cast(reasonValue); -} - void AceAbility::Dump(const std::vector& params, std::vector& info) { auto container = Platform::AceContainer::GetContainer(abilityId_); diff --git a/adapter/ohos/entrance/ace_ability.h b/adapter/ohos/entrance/ace_ability.h index f3c813dc97e..6e1a8f600eb 100644 --- a/adapter/ohos/entrance/ace_ability.h +++ b/adapter/ohos/entrance/ace_ability.h @@ -68,7 +68,6 @@ public: // override Rosen::IWindowChangeListener virtual callback function void OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason) override; void OnModeChange(OHOS::Rosen::WindowMode mode) override; - static WindowSizeChangeReason Convert2WindowSizeChangeReason(OHOS::Rosen::WindowSizeChangeReason reason); void Dump(const std::vector& params, std::vector& info) override; diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index ce676515bee..ea71a646ade 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -538,7 +538,7 @@ void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Ros metrics.device_pixel_ratio = config.Density(); Platform::FlutterAceView::SetViewportMetrics(aceView, metrics); Platform::FlutterAceView::SurfaceChanged(aceView, config.Width(), config.Height(), config.Orientation(), - AceAbility::Convert2WindowSizeChangeReason(reason)); + static_cast(reason)); } config_ = config; updateConfig_ = true; diff --git a/frameworks/core/common/window_animation_config.h b/frameworks/core/common/window_animation_config.h index 8055f34d97e..6191465bcb9 100644 --- a/frameworks/core/common/window_animation_config.h +++ b/frameworks/core/common/window_animation_config.h @@ -23,7 +23,9 @@ enum class WindowSizeChangeReason : uint32_t { RECOVER, ROTATION, DRAG, + DRAG_END, RESIZE, + MOVE, }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/container_modal/container_modal_element.cpp b/frameworks/core/components/container_modal/container_modal_element.cpp index 1f11f8ce5c1..8413a266f7f 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -28,8 +28,9 @@ namespace { constexpr uint32_t COLUMN_CHILD_NUM = 2; constexpr uint32_t SPLIT_BUTTON_POSITION = 2; -constexpr uint32_t TITLE_POPUP_TIME = 500; // 500ms -constexpr double TITLE_POPUP_DISTANCE = 100.0; // 100px +constexpr uint32_t BLUR_WINDOW_RADIUS = 100; +constexpr uint32_t TITLE_POPUP_TIME = 500; // 500ms +constexpr double TITLE_POPUP_DISTANCE = 48.0; // 48vp height of title } // namespace @@ -182,8 +183,8 @@ void ContainerModalElement::PerformBuild() controller_->SetDuration(TITLE_POPUP_TIME); controller_->SetFillMode(FillMode::FORWARDS); auto translateY = AceType::MakeRefPtr>( - DimensionOffset(Dimension(), Dimension(-TITLE_POPUP_DISTANCE)), DimensionOffset(Dimension(), Dimension()), - Curves::FRICTION); + DimensionOffset(Dimension(), Dimension(-TITLE_POPUP_DISTANCE * density_)), + DimensionOffset(Dimension(), Dimension()), Curves::FRICTION); TweenOption option; option.SetTranslateAnimations(AnimationType::TRANSLATE_Y, translateY); auto containerBox = AceType::DynamicCast(GetFirstChild()); @@ -240,6 +241,10 @@ void ContainerModalElement::Update() LOGE("ContainerModalElement update failed, container box component is null."); return; } + auto context = context_.Upgrade(); + if (context) { + density_ = context->GetDensity(); + } // touch top to pop-up title bar. containerBox->SetOnTouchMoveId([week = WeakClaim(this)](const TouchEventInfo& info) { @@ -247,7 +252,8 @@ void ContainerModalElement::Update() if (!containerElement || !containerElement->CanShowFloatingTitle()) { return; } - if (info.GetChangedTouches().begin()->GetGlobalLocation().GetY() <= TITLE_POPUP_DISTANCE) { + if (info.GetChangedTouches().begin()->GetGlobalLocation().GetY() <= + (TITLE_POPUP_DISTANCE * containerElement->density_)) { containerElement->floatingTitleDisplay_->UpdateVisibleType(VisibleType::VISIBLE); containerElement->controller_->ClearStopListeners(); containerElement->controller_->Forward(); @@ -260,12 +266,13 @@ void ContainerModalElement::Update() if (!containerElement || info.GetAction() != MouseAction::MOVE) { return; } - if (info.GetLocalLocation().GetY() <= TITLE_POPUP_DISTANCE && containerElement->CanShowFloatingTitle()) { + if (info.GetLocalLocation().GetY() <= 1.0 && containerElement->CanShowFloatingTitle()) { containerElement->floatingTitleDisplay_->UpdateVisibleType(VisibleType::VISIBLE); containerElement->controller_->ClearStopListeners(); containerElement->controller_->Forward(); } - if (info.GetLocalLocation().GetY() > TITLE_POPUP_DISTANCE && containerElement->CanHideFloatingTitle()) { + if (info.GetLocalLocation().GetY() > (TITLE_POPUP_DISTANCE * containerElement->density_) && + containerElement->CanHideFloatingTitle()) { containerElement->controller_->AddStopListener([weak] { auto container = weak.Upgrade(); container->floatingTitleDisplay_->UpdateVisibleType(VisibleType::GONE); @@ -358,4 +365,25 @@ void ContainerModalElement::ChangeFloatingTitleIcon() } } +void ContainerModalElement::BlurWindow(bool isBlur) +{ + auto containerBox = AceType::DynamicCast(GetFirstChild()); + if (!containerBox) { + LOGE("ContainerModalElement BlurWindow failed, container box element is null!"); + return; + } + auto containerRenderBox = AceType::DynamicCast(containerBox->GetRenderNode()); + if (!containerRenderBox) { + LOGE("ContainerModalElement BlurWindow failed, container box render is null!"); + return; + } + if (isBlur) { + auto frontDecoration = AceType::MakeRefPtr(); + frontDecoration->SetBlurRadius(Dimension(BLUR_WINDOW_RADIUS)); + containerRenderBox->SetFrontDecoration(frontDecoration); + } else { + containerRenderBox->SetFrontDecoration(nullptr); + } +} + } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/components/container_modal/container_modal_element.h b/frameworks/core/components/container_modal/container_modal_element.h index 7e2703688ca..a791e0dce66 100644 --- a/frameworks/core/components/container_modal/container_modal_element.h +++ b/frameworks/core/components/container_modal/container_modal_element.h @@ -30,6 +30,7 @@ public: RefPtr GetOverlayElement() const; RefPtr GetStageElement() const; void ShowTitle(bool isShow); + void BlurWindow(bool isBlur); void Update() override; void PerformBuild() override; @@ -43,6 +44,7 @@ private: RefPtr floatingTitleBox_; RefPtr titleChildrenRow_; RefPtr floatingTitleChildrenRow_; + float density_ = 1.0f; }; } // namespace OHOS::Ace diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 1dfa769af73..0f9fe7e9dd1 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -344,6 +344,22 @@ void PipelineContext::ShowContainerTitle(bool isShow) } } +void PipelineContext::BlurWindowWithDrag(bool isBlur) +{ + if (windowModal_ != WindowModal::CONTAINER_MODAL) { + LOGW("BlurWindowWithDrag failed, Window modal is not container."); + return; + } + if (!rootElement_) { + LOGW("BlurWindowWithDrag failed, rootElement_ is null."); + return; + } + auto containerModal = AceType::DynamicCast(rootElement_->GetFirstChild()); + if (containerModal) { + containerModal->BlurWindow(isBlur); + } +} + RefPtr PipelineContext::GetStageElement() const { CHECK_RUN_ON(UI); @@ -1832,9 +1848,19 @@ void PipelineContext::WindowSizeChangeAnimate(int32_t width, int32_t height, Win break; [[fallthrough]]; } + case WindowSizeChangeReason::DRAG: { + BlurWindowWithDrag(true); + isDragStart_ = true; + break; + } + case WindowSizeChangeReason::DRAG_END: { + BlurWindowWithDrag(false); + isDragStart_ = false; + SetRootSizeWithWidthHeight(width, height); + break; + } case WindowSizeChangeReason::ROTATION: case WindowSizeChangeReason::RESIZE: - case WindowSizeChangeReason::DRAG: case WindowSizeChangeReason::UNDEFINED: default: { LOGD("PipelineContext::RootNodeAnimation : unsupported type, no animation added"); @@ -1853,6 +1879,10 @@ void PipelineContext::OnSurfaceChanged(int32_t width, int32_t height, WindowSize return; } #endif + if (type == WindowSizeChangeReason::DRAG && isDragStart_) { + LOGD("Type is drag, no need change size."); + return; + } for (auto&& [id, callback] : surfaceChangedCallbackMap_) { if (callback) { diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index a3d14f61257..8656c552682 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -462,6 +462,8 @@ public: void ShowContainerTitle(bool isShow); + void BlurWindowWithDrag(bool isBlur); + RefPtr GetStageElement() const; RefPtr GetComposedElementById(const ComposeId& id); @@ -1379,6 +1381,7 @@ private: bool isJsPlugin_ = false; bool useLiteStyle_ = false; bool isFirstLoaded_ = true; + bool isDragStart_ = false; uint64_t flushAnimationTimestamp_ = 0; TimeProvider timeProvider_; OnPageShowCallBack onPageShowCallBack_; -- Gitee