From 388764f3716648543ee8698671afc6259d54ec7a Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Thu, 31 Mar 2022 16:50:22 +0800 Subject: [PATCH] support window clip content Signed-off-by: jiangdayuan Change-Id: I4709f8c64a7bd5bfa7c33cd843806f86b049e2c2 --- adapter/ohos/entrance/ace_ability.cpp | 32 +++++++------------ adapter/ohos/entrance/ui_content_impl.cpp | 20 ++++-------- .../core/components/clip/clip_component.h | 8 +++++ .../core/components/clip/render_clip.cpp | 12 ++----- frameworks/core/components/clip/render_clip.h | 13 ++++++++ .../components/clip/rosen_render_clip.cpp | 25 +++++---------- .../core/components/clip/rosen_render_clip.h | 5 --- .../container_modal_component.cpp | 11 +++---- .../container_modal_element.cpp | 31 ++++++++++-------- 9 files changed, 73 insertions(+), 84 deletions(-) diff --git a/adapter/ohos/entrance/ace_ability.cpp b/adapter/ohos/entrance/ace_ability.cpp index 3d5399996b3..4909c6cfb81 100644 --- a/adapter/ohos/entrance/ace_ability.cpp +++ b/adapter/ohos/entrance/ace_ability.cpp @@ -571,6 +571,10 @@ void AceAbility::OnRemoteTerminated() void AceAbility::OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason) { + LOGI("AceAbility::OnSizeChange width: %{public}u, height: %{public}u, left: %{public}d, top: %{public}d", + rect.width_, rect.height_, rect.posX_, rect.posY_); + SystemProperties::SetDeviceOrientation(rect.height_ >= rect.width_ ? 0 : 1); + SystemProperties::SetWindowPos(rect.posX_, rect.posY_); auto container = Platform::AceContainer::GetContainer(abilityId_); if (!container) { LOGE("OnSizeChange: container is null."); @@ -581,33 +585,20 @@ void AceAbility::OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeCha LOGE("OnSizeChange: taskExecutor is null."); return; } - taskExecutor->PostTask( - [rect, abilityId = abilityId_, density = density_, reason]() { - uint32_t width = rect.width_; - uint32_t height = rect.height_; - LOGI("AceAbility::OnSizeChange width: %{public}u, height: %{public}u, left: %{public}d, top: %{public}d", - width, height, rect.posX_, rect.posY_); - SystemProperties::SetDeviceOrientation(height >= width ? 0 : 1); - SystemProperties::SetWindowPos(rect.posX_, rect.posY_); - auto container = Platform::AceContainer::GetContainer(abilityId); - if (!container) { - LOGE("container may be destroyed."); - return; - } + taskExecutor->PostTask([rect, density = density_, reason, container]() { auto flutterAceView = static_cast(container->GetView()); if (!flutterAceView) { - LOGE("flutterAceView is null"); + LOGE("OnSizeChange: flutterAceView is null."); return; } flutter::ViewportMetrics metrics; - metrics.physical_width = width; - metrics.physical_height = height; + metrics.physical_width = rect.width_; + metrics.physical_height = rect.height_; metrics.device_pixel_ratio = density; Platform::FlutterAceView::SetViewportMetrics(flutterAceView, metrics); - Platform::FlutterAceView::SurfaceChanged( - flutterAceView, width, height, 0, static_cast(reason)); - }, - TaskExecutor::TaskType::PLATFORM); + Platform::FlutterAceView::SurfaceChanged(flutterAceView, rect.width_, rect.height_, + rect.height_ >= rect.width_ ? 0 : 1, static_cast(reason)); + }, TaskExecutor::TaskType::PLATFORM); } void AceAbility::OnModeChange(OHOS::Rosen::WindowMode mode) @@ -623,6 +614,7 @@ void AceAbility::OnModeChange(OHOS::Rosen::WindowMode mode) LOGE("OnModeChange failed: taskExecutor is null."); return; } + ContainerScope scope(abilityId_); taskExecutor->PostTask([container, mode]() { auto pipelineContext = container->GetPipelineContext(); if (!pipelineContext) { diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index e302ecdc893..843a987611f 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -511,6 +511,7 @@ void UIContentImpl::Focus() LOGE("Window focus failed: taskExecutor is null."); return; } + ContainerScope scope(instanceId_); taskExecutor->PostTask([container]() { auto pipelineContext = container->GetPipelineContext(); if (!pipelineContext) { @@ -535,6 +536,7 @@ void UIContentImpl::UnFocus() LOGE("Window unFocus failed: taskExecutor is null."); return; } + ContainerScope scope(instanceId_); taskExecutor->PostTask([container]() { auto pipelineContext = container->GetPipelineContext(); if (!pipelineContext) { @@ -608,7 +610,6 @@ void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Ros { LOGI("UIContent UpdateViewportConfig %{public}s", config.ToString().c_str()); SystemProperties::SetResolution(config.Density()); - SystemProperties::SetColorMode(ColorMode::LIGHT); SystemProperties::SetDeviceOrientation(config.Height() >= config.Width() ? 0 : 1); SystemProperties::SetWindowPos(config.Left(), config.Top()); auto container = Platform::AceContainer::GetContainer(instanceId_); @@ -621,17 +622,10 @@ void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Ros LOGE("UpdateViewportConfig: taskExecutor is null."); return; } - taskExecutor->PostTask( - [config, instanceId = instanceId_, reason]() { - auto container = Platform::AceContainer::GetContainer(instanceId); - if (!container) { - LOGE("container may be destroyed."); - return; - } - + taskExecutor->PostTask([config, container, reason]() { auto aceView = static_cast(container->GetAceView()); if (!aceView) { - LOGE("aceView is null"); + LOGE("UpdateViewportConfig: aceView is null."); return; } flutter::ViewportMetrics metrics; @@ -641,8 +635,7 @@ void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Ros Platform::FlutterAceView::SetViewportMetrics(aceView, metrics); Platform::FlutterAceView::SurfaceChanged(aceView, config.Width(), config.Height(), config.Orientation(), static_cast(reason)); - }, - TaskExecutor::TaskType::PLATFORM); + }, TaskExecutor::TaskType::PLATFORM); } void UIContentImpl::UpdateWindowMode(OHOS::Rosen::WindowMode mode) @@ -658,6 +651,7 @@ void UIContentImpl::UpdateWindowMode(OHOS::Rosen::WindowMode mode) LOGE("UpdateWindowMode failed: taskExecutor is null."); return; } + ContainerScope scope(instanceId_); taskExecutor->PostTask([container, mode]() { auto pipelineContext = container->GetPipelineContext(); if (!pipelineContext) { @@ -765,7 +759,7 @@ void UIContentImpl::InitializeSubWindow(OHOS::Rosen::Window* window) std::weak_ptr runtimeContext; container = AceType::MakeRefPtr(instanceId_, FrontendType::DECLARATIVE_JS, true, runtimeContext, abilityInfo, std::make_unique([] { - // Subwindow ,just return. + // Sub-window ,just return. LOGI("Content event callback"); }), false, true); diff --git a/frameworks/core/components/clip/clip_component.h b/frameworks/core/components/clip/clip_component.h index 2556eed28b1..9f995cc72fb 100644 --- a/frameworks/core/components/clip/clip_component.h +++ b/frameworks/core/components/clip/clip_component.h @@ -73,6 +73,14 @@ public: offsetY_ = offsetY; } + void SetClipRadius(const Radius& clipRadius) + { + topLeftRadius_ = clipRadius; + topRightRadius_ = clipRadius; + bottomLeftRadius_ = clipRadius; + bottomRightRadius_ = clipRadius; + } + const Radius& GetTopLeftRadius() const { return topLeftRadius_; diff --git a/frameworks/core/components/clip/render_clip.cpp b/frameworks/core/components/clip/render_clip.cpp index 47a8ab36483..03a3cc03f1a 100644 --- a/frameworks/core/components/clip/render_clip.cpp +++ b/frameworks/core/components/clip/render_clip.cpp @@ -74,7 +74,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap() return; } clip->SetWidth(value); - clip->MarkNeedRender(); }; map[PropertyAnimatableType::PROPERTY_HEIGHT] = [weak](float value) { auto clip = weak.Upgrade(); @@ -83,7 +82,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap() return; } clip->SetHeight(value); - clip->MarkNeedRender(); }; map[PropertyAnimatableType::PROPERTY_OFFSET_X] = [weak](float value) { auto clip = weak.Upgrade(); @@ -93,7 +91,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap() } clip->SetOffsetX(value); clip->UpdateBoxForShadowAnimation(); - clip->MarkNeedRender(); }; map[PropertyAnimatableType::PROPERTY_OFFSET_Y] = [weak](float value) { auto clip = weak.Upgrade(); @@ -103,7 +100,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap() } clip->SetOffsetY(value); clip->UpdateBoxForShadowAnimation(); - clip->MarkNeedRender(); }; map[PropertyAnimatableType::PROPERTY_BORDER_RADIUS] = [weak](float value) { auto clip = weak.Upgrade(); @@ -111,11 +107,7 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap() LOGE("set border radius failed. clip is null."); return; } - clip->topLeftRadius_ = Radius(value); - clip->topRightRadius_ = Radius(value); - clip->bottomLeftRadius_ = Radius(value); - clip->bottomRightRadius_ = Radius(value); - clip->MarkNeedRender(); + clip->SetClipRadius(Radius(value)); }; return map; }; @@ -191,7 +183,7 @@ void RenderClip::UpdateBoxForShadowAnimation() return; } - // If clip if used for animation, then there will be exist display and transform. + // If clip is used for animation, then there will be existed display and transform. auto renderTransform = AceType::DynamicCast(GetParent().Upgrade()); if (!renderTransform) { return; diff --git a/frameworks/core/components/clip/render_clip.h b/frameworks/core/components/clip/render_clip.h index 3b1eba60c86..904c777dade 100644 --- a/frameworks/core/components/clip/render_clip.h +++ b/frameworks/core/components/clip/render_clip.h @@ -43,6 +43,7 @@ public: return; } offsetX_ = offsetX; + MarkNeedRender(); } virtual void SetOffsetY(double offsetY) @@ -51,6 +52,7 @@ public: return; } offsetY_ = offsetY; + MarkNeedRender(); } Rect GetClipRect(const Offset& offset) const; @@ -61,6 +63,7 @@ public: return; } width_ = width; + MarkNeedRender(); } virtual void SetHeight(double height) @@ -69,6 +72,7 @@ public: return; } height_ = height; + MarkNeedRender(); } double GetHeight() const @@ -83,6 +87,15 @@ public: void Dump() override; + void SetClipRadius(const Radius& clipRadius) + { + topLeftRadius_ = clipRadius; + topRightRadius_ = clipRadius; + bottomLeftRadius_ = clipRadius; + bottomRightRadius_ = clipRadius; + MarkNeedRender(); + } + protected: double width_ = 0.0; double height_ = 0.0; diff --git a/frameworks/core/components/clip/rosen_render_clip.cpp b/frameworks/core/components/clip/rosen_render_clip.cpp index 8711fcb017b..3d1f4c9f20e 100644 --- a/frameworks/core/components/clip/rosen_render_clip.cpp +++ b/frameworks/core/components/clip/rosen_render_clip.cpp @@ -22,23 +22,6 @@ namespace OHOS::Ace { -void RosenRenderClip::Update(const RefPtr& component) -{ - RenderClip::Update(component); - - auto rsNode = GetRSNode(); - if (!rsNode) { - return; - } - auto context = context_.Upgrade(); - if (!context) { - return; - } - double dipScale = context->GetDipScale(); - rsNode->SetCornerRadius(topLeftRadius_.GetX().ConvertToPx(dipScale)); - rsNode->SetClipToBounds(true); -} - void RosenRenderClip::SetOffsetX(double offsetX) { RenderClip::SetOffsetX(offsetX); @@ -69,6 +52,14 @@ void RosenRenderClip::SyncGeometryProperties() if (!rsNode) { return; } + auto context = context_.Upgrade(); + if (!context) { + return; + } + double dipScale = context->GetDipScale(); + rsNode->SetCornerRadius(topLeftRadius_.GetX().ConvertToPx(dipScale)); + rsNode->SetClipToBounds(true); + Rect paintSize = GetTransitionPaintRect(); Offset paintOffset = GetPaintOffset(); Offset clipOffset = paintOffset + Offset(offsetX_, offsetY_); diff --git a/frameworks/core/components/clip/rosen_render_clip.h b/frameworks/core/components/clip/rosen_render_clip.h index 9c7151d6a21..62a891bef65 100644 --- a/frameworks/core/components/clip/rosen_render_clip.h +++ b/frameworks/core/components/clip/rosen_render_clip.h @@ -27,8 +27,6 @@ public: RosenRenderClip() = default; ~RosenRenderClip() override = default; - void Update(const RefPtr& component) override; - bool HasGeometryProperties() const override { return true; @@ -39,9 +37,6 @@ public: void SetOffsetY(double offsetY) override; void SetWidth(double width) override; void SetHeight(double height) override; - -private: - void UpdateClipSize(); }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/container_modal/container_modal_component.cpp b/frameworks/core/components/container_modal/container_modal_component.cpp index 36971b4a017..00d70824886 100644 --- a/frameworks/core/components/container_modal/container_modal_component.cpp +++ b/frameworks/core/components/container_modal/container_modal_component.cpp @@ -17,6 +17,7 @@ #include "core/components/box/box_component.h" #include "core/components/button/button_component.h" +#include "core/components/clip/clip_component.h" #include "core/components/container_modal/container_modal_constants.h" #include "core/components/container_modal/container_modal_element.h" #include "core/components/container_modal/render_container_modal.h" @@ -95,16 +96,14 @@ RefPtr ContainerModalComponent::BuildContent() { auto contentBox = AceType::MakeRefPtr(); contentBox->SetChild(GetChild()); - Border contentBorder; - contentBorder.SetBorderRadius(Radius(CONTAINER_INNER_RADIUS)); auto contentDecoration = AceType::MakeRefPtr(); contentDecoration->SetBackgroundColor(CONTENT_BACKGROUND_COLOR); - contentDecoration->SetBorder(contentBorder); contentBox->SetBackDecoration(contentDecoration); - // adaptive height - contentBox->SetFlexWeight(1.0); - return contentBox; + auto clip = AceType::MakeRefPtr(contentBox); + clip->SetClipRadius(Radius(CONTAINER_INNER_RADIUS)); + clip->SetFlexWeight(1.0); + return clip; } RefPtr ContainerModalComponent::BuildControlButton( diff --git a/frameworks/core/components/container_modal/container_modal_element.cpp b/frameworks/core/components/container_modal/container_modal_element.cpp index d56472dce0e..2e81cd2d0a8 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -16,10 +16,11 @@ #include "core/components/container_modal/container_modal_element.h" #include "core/components/box/box_element.h" +#include "core/components/clip/clip_element.h" +#include "core/components/clip/render_clip.h" #include "core/components/container_modal/container_modal_constants.h" #include "core/components/container_modal/render_container_modal.h" #include "core/components/flex/flex_element.h" -#include "core/components/flex/flex_item_element.h" #include "core/components/padding/render_padding.h" #include "core/gestures/tap_gesture.h" @@ -60,7 +61,13 @@ RefPtr ContainerModalElement::GetStackElement() const } // Get second child : content - auto contentBox = AceType::DynamicCast(column->GetLastChild()); + auto clip = AceType::DynamicCast(column->GetLastChild()); + if (!clip) { + LOGE("Get stack element failed, clip element is null!"); + return {}; + } + + auto contentBox = AceType::DynamicCast(clip->GetFirstChild()); if (!contentBox) { LOGE("Get stack element failed, content box element is null!"); return {}; @@ -153,17 +160,15 @@ void ContainerModalElement::ShowTitle(bool isShow) return; } - // full screen need to hide border. - auto contentRenderBox = AceType::DynamicCast(column->GetLastChild()->GetRenderNode()); - if (contentRenderBox) { - auto contentDecoration = AceType::MakeRefPtr(); - contentDecoration->SetBackgroundColor(CONTENT_BACKGROUND_COLOR); - if (isShow) { - Border contentBorder; - contentBorder.SetBorderRadius(Radius(CONTAINER_INNER_RADIUS)); - contentDecoration->SetBorder(contentBorder); - } - contentRenderBox->SetBackDecoration(contentDecoration); + // full screen need to hide content border radius. + auto clip = AceType::DynamicCast(column->GetLastChild()); + if (!clip) { + LOGE("ContainerModalElement showTitle failed, clip element is null!"); + return; + } + auto renderClip = AceType::DynamicCast(clip->GetRenderNode()); + if (renderClip) { + isShow ? renderClip->SetClipRadius(Radius(CONTAINER_INNER_RADIUS)) : renderClip->SetClipRadius(Radius(0.0)); } // Get first child : title -- Gitee