diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index e4b41d5c5d67b56a732e230bdab71cdf7736df26..bdae9ad063313e83031cb5c73c22abc103116f20 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -566,28 +566,26 @@ uint32_t UIContentImpl::GetBackgroundColor() LOGE("GetBackgroundColor failed: container is null. return 0x000000"); return 0x000000; } - auto pipeline = container->GetPipelineContext(); - if (!pipeline) { - LOGE("GetBackgroundColor failed: pipeline is null. return 0x000000"); + auto taskExecutor = container->GetTaskExecutor(); + if (!taskExecutor) { + LOGE("GetBackgroundColor failed: taskExecutor is null."); return 0x000000; } ContainerScope scope(instanceId_); uint32_t bgColor = 0x000000; - auto taskExecutor = container->GetTaskExecutor(); - if (taskExecutor) { - taskExecutor->PostSyncTask([&bgColor, container]() { + taskExecutor->PostSyncTask([&bgColor, container]() { if (!container) { LOGE("Post sync task GetBackgroundColor failed: container is null. return 0x000000"); return; } - auto taskPipeline = container->GetPipelineContext(); - if (!taskPipeline) { + auto pipelineContext = container->GetPipelineContext(); + if (!pipelineContext) { LOGE("Post sync task GetBackgroundColor failed: pipeline is null. return 0x000000"); return; } - bgColor = taskPipeline->GetRootBgColor().GetValue(); + bgColor = pipelineContext->GetAppBgColor().GetValue(); }, TaskExecutor::TaskType::UI); - } + LOGI("UIContentImpl::GetBackgroundColor, value is %{public}u", bgColor); return bgColor; } @@ -612,7 +610,7 @@ void UIContentImpl::SetBackgroundColor(uint32_t color) LOGE("SetBackgroundColor failed, pipeline context is null."); return; } - pipelineContext->SetRootBgColor(Color(bgColor)); + pipelineContext->SetAppBgColor(Color(bgColor)); }, TaskExecutor::TaskType::UI); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp index b607509261e0ac9f5f12a5b9b82418c3da502f1c..5e6820cbfd7238b15c3dc96a7b6bb393777d7da3 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp @@ -786,7 +786,7 @@ panda::Local SetAppBackgroundColor(panda::JsiRuntimeCallInfo } auto pipelineContext = container->GetPipelineContext(); if (pipelineContext) { - pipelineContext->SetRootBgColor(Color::FromString(backgroundColorStr)); + pipelineContext->SetAppBgColor(Color::FromString(backgroundColorStr)); } return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp index 7f70366d5801dab556a13a85da38bafbdff2a02e..c8931196c1b4b37162d9a590bc4991741cbc0be5 100644 --- a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp @@ -744,7 +744,7 @@ JSValue SetAppBackgroundColor(JSContext* ctx, JSValueConst new_target, int argc, } auto pipelineContext = container->GetPipelineContext(); if (pipelineContext) { - pipelineContext->SetRootBgColor(Color::FromString(backgroundColorStr)); + pipelineContext->SetAppBgColor(Color::FromString(backgroundColorStr)); } return JS_UNDEFINED; } diff --git a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp index 0f5bde1e729ca35c4022fec4d5082f35da2187fe..98f120cda32abc60803e361608b4964bfb307e66 100644 --- a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp @@ -559,7 +559,7 @@ void SetAppBackgroundColor(const v8::FunctionCallbackInfo& args) } auto pipelineContext = container->GetPipelineContext(); if (pipelineContext) { - pipelineContext->SetRootBgColor(Color::FromString(backgroundColorStr)); + pipelineContext->SetAppBgColor(Color::FromString(backgroundColorStr)); } } diff --git a/frameworks/core/components/box/flutter_render_box.cpp b/frameworks/core/components/box/flutter_render_box.cpp index 0460ca9c5edd069d99f5b6d9a213b3459d7cc3ea..7d72886e3a41bcb2d3c26bcc9ecc0c8d69bd6762 100644 --- a/frameworks/core/components/box/flutter_render_box.cpp +++ b/frameworks/core/components/box/flutter_render_box.cpp @@ -299,7 +299,7 @@ void FlutterRenderBox::Paint(RenderContext& context, const Offset& offset) decorationPainter->SetRenderImage(renderImage_); } - Color bgColor = pipeline->GetRootBgColor(); + Color bgColor = pipeline->GetAppBgColor(); if (backDecoration_) { flutter::Canvas* canvas = renderContext->GetCanvas(); if (canvas == nullptr) { diff --git a/frameworks/core/components/box/rosen_render_box.cpp b/frameworks/core/components/box/rosen_render_box.cpp index accb1fb551ea0f5b0e25d0808eb04f3529de1af0..4f806164e871f383b97851276dcf863db9a1cb26 100644 --- a/frameworks/core/components/box/rosen_render_box.cpp +++ b/frameworks/core/components/box/rosen_render_box.cpp @@ -288,7 +288,7 @@ void RosenRenderBox::Paint(RenderContext& context, const Offset& offset) SkRRect outerRRect = SkRRect::MakeRect(SkRect::MakeLTRB(paintSize.Left(), paintSize.Top(), paintSize.Right(), paintSize.Bottom())); SkRect focusRect = SkRect::MakeLTRB(paintSize.Left(), paintSize.Top(), paintSize.Right(), paintSize.Bottom()); - Color bgColor = pipeline->GetRootBgColor(); + Color bgColor = pipeline->GetAppBgColor(); if (backDecoration_) { auto canvas = static_cast(&context)->GetCanvas(); if (canvas == nullptr) { diff --git a/frameworks/core/components/container_modal/container_modal_component.cpp b/frameworks/core/components/container_modal/container_modal_component.cpp index 00d70824886369587e46a008a15869dc6436a718..71482f96802240cbc13d2a23a7e0af1fd3809b76 100644 --- a/frameworks/core/components/container_modal/container_modal_component.cpp +++ b/frameworks/core/components/container_modal/container_modal_component.cpp @@ -97,7 +97,10 @@ RefPtr ContainerModalComponent::BuildContent() auto contentBox = AceType::MakeRefPtr(); contentBox->SetChild(GetChild()); auto contentDecoration = AceType::MakeRefPtr(); - contentDecoration->SetBackgroundColor(CONTENT_BACKGROUND_COLOR); + auto context = context_.Upgrade(); + if (context) { + contentDecoration->SetBackgroundColor(context->GetAppBgColor()); + } contentBox->SetBackDecoration(contentDecoration); auto clip = AceType::MakeRefPtr(contentBox); diff --git a/frameworks/core/components/container_modal/container_modal_constants.h b/frameworks/core/components/container_modal/container_modal_constants.h index d418ce9f813b4fffd142e648b126bed810316833..ed4832902d17e0b61cffdd48ee4c3ed16362e543 100644 --- a/frameworks/core/components/container_modal/container_modal_constants.h +++ b/frameworks/core/components/container_modal/container_modal_constants.h @@ -36,7 +36,6 @@ const Color CONTAINER_BORDER_COLOR = Color(0x33000000); const Color CONTAINER_BORDER_COLOR_LOST_FOCUS = Color(0x19000000); const Color TITLE_TEXT_COLOR = Color(0xff000000); const Color TITLE_TEXT_COLOR_LOST_FOCUS = Color(0x66000000); -const Color CONTENT_BACKGROUND_COLOR = Color(0xffffffff); const Color TITLE_BUTTON_BACKGROUND_COLOR = Color(0x19000000); const Color TITLE_BUTTON_BACKGROUND_COLOR_LOST_FOCUS = Color(0x0a000000); const Color TITLE_BUTTON_CLICKED_COLOR = Color(0x33000000); diff --git a/frameworks/core/components/container_modal/container_modal_element.cpp b/frameworks/core/components/container_modal/container_modal_element.cpp index 2e81cd2d0a8e4da9004d263166691e470c802b9b..bd78f224d2a8c9738306b281acacf7060c937721 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -166,6 +166,9 @@ void ContainerModalElement::ShowTitle(bool isShow) LOGE("ContainerModalElement showTitle failed, clip element is null!"); return; } + if (!contentBox_) { + contentBox_ = AceType::DynamicCast(clip->GetFirstChild()); + } auto renderClip = AceType::DynamicCast(clip->GetRenderNode()); if (renderClip) { isShow ? renderClip->SetClipRadius(Radius(CONTAINER_INNER_RADIUS)) : renderClip->SetClipRadius(Radius(0.0)); @@ -470,4 +473,20 @@ void ContainerModalElement::WindowFocus(bool isFocus) } } +void ContainerModalElement::SetAppBgColor(const Color& color) +{ + if (!contentBox_) { + LOGE("SetAppBgColor failed, contentBox_ is nullptr."); + return; + } + auto renderContentBox = AceType::DynamicCast(contentBox_->GetRenderNode()); + if (!renderContentBox) { + LOGE("SetAppBgColor failed, renderContentBox is nullptr."); + return; + } + auto backDecoration = renderContentBox->GetBackDecoration(); + backDecoration->SetBackgroundColor(color); + renderContentBox->SetBackDecoration(backDecoration); +} + } // 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 12f3db16240cbc5fda85c659ec55280fc70274b0..64cfc44fb87a02d6b4c63e9e4997d721f68af7dc 100644 --- a/frameworks/core/components/container_modal/container_modal_element.h +++ b/frameworks/core/components/container_modal/container_modal_element.h @@ -33,6 +33,7 @@ public: void ShowTitle(bool isShow); void BlurWindow(bool isBlur); void WindowFocus(bool isFocus); + void SetAppBgColor(const Color& color); void Update() override; void PerformBuild() override; @@ -47,6 +48,7 @@ private: RefPtr floatingTitleDisplay_; RefPtr floatingTitleBox_; RefPtr titleBox_; + RefPtr contentBox_; RefPtr containerModalComponent_; float density_ = 1.0f; float moveX_ = 0.0f; diff --git a/frameworks/core/components/root/flutter_render_root.cpp b/frameworks/core/components/root/flutter_render_root.cpp index b85c2cb03e7840980a22957e856de93934d168b5..27bfed50159c4034d7c0b492d96895c651eaf7e5 100644 --- a/frameworks/core/components/root/flutter_render_root.cpp +++ b/frameworks/core/components/root/flutter_render_root.cpp @@ -39,9 +39,6 @@ void FlutterRenderRoot::Paint(RenderContext& context, const Offset& offset) } else { canvas->canvas()->clear(skColor); } - if (pipelineContext) { - pipelineContext->SetRootBgColor(bgColor_); - } RenderNode::Paint(context, offset); } diff --git a/frameworks/core/components/root/render_root.cpp b/frameworks/core/components/root/render_root.cpp index c32926dd1318459da7799f0f9870a99752c4a055..32b216233918d0aa5ff674c69e126daf8b8618fa 100644 --- a/frameworks/core/components/root/render_root.cpp +++ b/frameworks/core/components/root/render_root.cpp @@ -57,8 +57,8 @@ void RenderRoot::PerformLayout() auto appTheme = GetTheme(); // Use theme background color to clear canvas. if (appTheme && !isBgColorInit_) { - bgColor_ = appTheme->GetBackgroundColor(); if (IsShadowModal(context_)) { + bgColor_ = appTheme->GetBackgroundColor(); auto colorAnimation = AceType::MakeRefPtr>(Color::TRANSPARENT, bgColor_, Curves::FAST_OUT_SLOW_IN); bgColor_ = Color::TRANSPARENT; @@ -108,13 +108,13 @@ void RenderRoot::AnimateToShow(int32_t duration) } } -void RenderRoot::SetDefaultBgColor() +void RenderRoot::SetDefaultBgColor(bool isTransparent) { auto appTheme = GetTheme(); if (!appTheme) { return; } - bgColor_ = isContextMenu_ ? Color::TRANSPARENT : appTheme->GetBackgroundColor(); + bgColor_ = isContextMenu_ || isTransparent ? Color::TRANSPARENT : appTheme->GetBackgroundColor(); forceColor_ = false; MarkNeedRender(); } diff --git a/frameworks/core/components/root/render_root.h b/frameworks/core/components/root/render_root.h index 0fe2f52497ce480e8ed1db4103f6157430761970..8b5594fa9b1f0bad539605a790559f7d0499ae8a 100644 --- a/frameworks/core/components/root/render_root.h +++ b/frameworks/core/components/root/render_root.h @@ -61,7 +61,7 @@ public: void SetBgColor(const Color& color); - void SetDefaultBgColor(); + void SetDefaultBgColor(bool isTransparent = false); void NotifyOnShow() const { @@ -81,7 +81,7 @@ protected: RenderRoot(); float scale_ = 1.0f; - Color bgColor_; + Color bgColor_ = Color::WHITE; bool forceColor_ = false; bool isBgColorInit_ = false; bool isReset_ = false; diff --git a/frameworks/core/components/root/rosen_render_root.cpp b/frameworks/core/components/root/rosen_render_root.cpp index b169adf3b49cb22496ce706d483277785ac294a6..3703b75cff6826a6ad61ab295faec0f6203936a9 100644 --- a/frameworks/core/components/root/rosen_render_root.cpp +++ b/frameworks/core/components/root/rosen_render_root.cpp @@ -37,10 +37,6 @@ void RosenRenderRoot::Paint(RenderContext& context, const Offset& offset) rsNode->SetBackgroundColor(bgColor_.GetValue()); rsNode->SetPivot(0.0f, 0.0f); rsNode->SetScale(scale_); - auto pipelineContext = GetContext().Upgrade(); - if (pipelineContext) { - pipelineContext->SetRootBgColor(bgColor_); - } RenderNode::Paint(context, offset); } diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index ffa42f4374105029832d9036393b11d4bc6e8475..e52eee7dfceb5ce90cef4941b9db2e3c68df9645 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -830,6 +830,10 @@ RefPtr PipelineContext::SetupRootElement() } const auto& rootRenderNode = rootElement_->GetRenderNode(); window_->SetRootRenderNode(rootRenderNode); + auto renderRoot = AceType::DynamicCast(rootRenderNode); + if (renderRoot) { + renderRoot->SetDefaultBgColor(windowModal_ == WindowModal::CONTAINER_MODAL); + } #ifdef ENABLE_ROSEN_BACKEND if (SystemProperties::GetRosenBackendEnabled() && rsUIDirector_) { LOGI("rosen ui director call set root."); @@ -2175,29 +2179,39 @@ void PipelineContext::SetRootRect(double width, double height, double offset) co } } -void PipelineContext::SetRootBgColor(const Color& color) +void PipelineContext::SetAppBgColor(const Color& color) { - LOGI("PipelineContext::SetRootBgColor set bgColor %{public}d", color.GetValue()); - rootBgColor_ = color; + LOGI("Set bgColor %{public}u", color.GetValue()); + appBgColor_ = color; if (!themeManager_) { - LOGW("PipelineContext::SetRootBgColor:themeManager_ is nullptr!"); + LOGW("themeManager_ is nullptr!"); return; } auto appTheme = themeManager_->GetTheme(); if (!appTheme) { - LOGW("GetTheme failed!"); + LOGW("appTheme is nullptr!"); return; } - if (windowModal_ == WindowModal::CONTAINER_MODAL) { - rootBgColor_ = Color::TRANSPARENT; + appTheme->SetBackgroundColor(appBgColor_); + if (!rootElement_) { + LOGW("rootElement_ is nullptr!"); + return; } - appTheme->SetBackgroundColor(rootBgColor_); - if (rootElement_) { - auto renderRoot = DynamicCast(rootElement_->GetRenderNode()); - if (renderRoot) { - renderRoot->SetBgColor(rootBgColor_); + auto renderRoot = DynamicCast(rootElement_->GetRenderNode()); + if (!renderRoot) { + LOGW("renderRoot is nullptr!"); + return; + } + if (windowModal_ == WindowModal::CONTAINER_MODAL) { + auto containerModal = AceType::DynamicCast(rootElement_->GetFirstChild()); + if (containerModal) { + containerModal->SetAppBgColor(appBgColor_); + renderRoot->SetBgColor(Color::TRANSPARENT); + return; } } + renderRoot->SetBgColor(appBgColor_); + } void PipelineContext::Finish(bool autoFinish) const @@ -2720,7 +2734,7 @@ void PipelineContext::RefreshRootBgColor() const } const auto& render = AceType::DynamicCast(rootElement_->GetRenderNode()); if (render) { - render->SetDefaultBgColor(); + render->SetDefaultBgColor(windowModal_ == WindowModal::CONTAINER_MODAL); } } diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index 337fc59e87b9d6f2791aab489c2cd2612b8d0953..ee931f742a4ea83de4849e17244432b0e890aec1 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -809,11 +809,11 @@ public: void SetForbidePlatformQuit(bool forbidePlatformQuit); - void SetRootBgColor(const Color& color); + void SetAppBgColor(const Color& color); - const Color& GetRootBgColor() const + const Color& GetAppBgColor() const { - return rootBgColor_; + return appBgColor_; } void SetPhotoCachePath(const std::string& photoCachePath) @@ -1435,7 +1435,7 @@ private: int32_t frameCount_ = 0; #endif - Color rootBgColor_ = Color::WHITE; + Color appBgColor_ = Color::WHITE; int32_t width_ = 0; int32_t height_ = 0; bool isFirstPage_ = true;