!42023 新增接口支持设置窗口标题栏背景颜色

Merge pull request !42023 from sunyalei/master
This commit is contained in:
openharmony_ci 2024-09-03 04:02:46 +00:00 committed by Gitee
commit 0540ce6db7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 112 additions and 4 deletions

View File

@ -2076,6 +2076,25 @@ void UIContentImpl::SetBackgroundColor(uint32_t color)
TaskExecutor::TaskType::UI, "ArkUISetAppBackgroundColor");
}
void UIContentImpl::SetWindowContainerColor(uint32_t activeColor, uint32_t inactiveColor)
{
TAG_LOGI(AceLogTag::ACE_APPBAR, "[%{public}s][%{public}s][%{public}d]: SetWindowContainerColor:"
"active color %{public}u, inactive color %{public}u",
bundleName_.c_str(), moduleName_.c_str(), instanceId_, activeColor, inactiveColor);
auto container = AceEngine::Get().GetContainer(instanceId_);
CHECK_NULL_VOID(container);
ContainerScope scope(instanceId_);
auto taskExecutor = container->GetTaskExecutor();
CHECK_NULL_VOID(taskExecutor);
taskExecutor->PostSyncTask(
[container, activeColor, inactiveColor]() {
auto pipelineContext = container->GetPipelineContext();
CHECK_NULL_VOID(pipelineContext);
pipelineContext->SetWindowContainerColor(Color(activeColor), Color(inactiveColor));
},
TaskExecutor::TaskType::UI, "ArkUISetWindowContainerColor");
}
void UIContentImpl::GetAppPaintSize(OHOS::Rosen::Rect& paintrect)
{
auto container = AceEngine::Get().GetContainer(instanceId_);

View File

@ -109,6 +109,7 @@ public:
// Window color
uint32_t GetBackgroundColor() override;
void SetBackgroundColor(uint32_t color) override;
void SetWindowContainerColor(uint32_t activeColor, uint32_t inactiveColor) override;
bool NeedSoftKeyboard() override;

View File

@ -478,6 +478,25 @@ void UIContentImpl::SetBackgroundColor(uint32_t color)
TaskExecutor::TaskType::UI, "ArkUISetAppBackgroundColor");
}
void UIContentImpl::SetWindowContainerColor(uint32_t activeColor, uint32_t inactiveColor)
{
TAG_LOGI(AceLogTag::ACE_APPBAR, "[%{public}s][%{public}s][%{public}d]: SetWindowContainerColor:"
"active color %{public}u, inactive color %{public}u",
bundleName_.c_str(), moduleName_.c_str(), instanceId_, activeColor, inactiveColor);
auto container = AceEngine::Get().GetContainer(instanceId_);
CHECK_NULL_VOID(container);
ContainerScope scope(instanceId_);
auto taskExecutor = container->GetTaskExecutor();
CHECK_NULL_VOID(taskExecutor);
taskExecutor->PostSyncTask(
[container, activeColor, inactiveColor]() {
auto pipelineContext = container->GetPipelineContext();
CHECK_NULL_VOID(pipelineContext);
pipelineContext->SetWindowContainerColor(Color(activeColor), Color(inactiveColor));
},
TaskExecutor::TaskType::UI, "ArkUISetWindowContainerColor");
}
bool UIContentImpl::ProcessBackPressed()
{
LOGI("Process Back Pressed Event");

View File

@ -89,6 +89,7 @@ public:
// Window color
uint32_t GetBackgroundColor() override;
void SetBackgroundColor(uint32_t color) override;
void SetWindowContainerColor(uint32_t activeColor, uint32_t inactiveColor) override;
void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;

View File

@ -94,7 +94,7 @@ void ContainerModalPattern::ShowTitle(bool isShow, bool hasDeco, bool needUpdate
auto renderContext = containerNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
renderContext->UpdateBackgroundColor(theme->GetBackGroundColor(isFocus_));
renderContext->UpdateBackgroundColor(GetContainerColor(isFocus_));
BorderRadiusProperty borderRadius;
borderRadius.SetRadius(isShow ? CONTAINER_OUTER_RADIUS : 0.0_vp);
renderContext->UpdateBorderRadius(borderRadius);
@ -324,7 +324,7 @@ void ContainerModalPattern::WindowFocus(bool isFocus)
// update container modal background
auto renderContext = containerNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
renderContext->UpdateBackgroundColor(theme->GetBackGroundColor(isFocus));
renderContext->UpdateBackgroundColor(GetContainerColor(isFocus_));
BorderColorProperty borderColor;
borderColor.SetColor(isFocus ? CONTAINER_BORDER_COLOR : CONTAINER_BORDER_COLOR_LOST_FOCUS);
renderContext->UpdateBorderColor(borderColor);
@ -510,6 +510,29 @@ void ContainerModalPattern::SetCloseButtonStatus(bool isEnabled)
LOGI("Set close button status %{public}s", isEnabled ? "enable" : "disable");
}
void ContainerModalPattern::SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor)
{
auto theme = PipelineContext::GetCurrentContext()->GetTheme<ContainerModalTheme>();
auto containerNode = GetHost();
CHECK_NULL_VOID(containerNode);
// update container modal background
auto renderContext = containerNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
renderContext->UpdateBackgroundColor(GetContainerColor(isFocus_));
activeColor_ = activeColor;
inactiveColor_ = inactiveColor;
}
Color ContainerModalPattern::GetContainerColor(bool isFocus)
{
if (isFocus) {
return activeColor_;
} else {
return inactiveColor_;
}
}
void ContainerModalPattern::UpdateGestureRowVisible()
{
auto gestureRow = GetGestureRow();
@ -672,11 +695,21 @@ void ContainerModalPattern::InitTitle()
void ContainerModalPattern::Init()
{
InitContainerColor();
InitContainerEvent();
InitTitle();
InitLayoutProperty();
}
void ContainerModalPattern::InitContainerColor()
{
auto pipelineContext = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipelineContext);
auto theme = pipelineContext->GetTheme<ContainerModalTheme>();
activeColor_ = theme->GetBackGroundColor(true);
inactiveColor_ = theme->GetBackGroundColor(false);
}
void ContainerModalPattern::OnColorConfigurationUpdate()
{
WindowFocus(isFocus_);

View File

@ -74,6 +74,8 @@ public:
void SetCloseButtonStatus(bool isEnabled);
virtual void SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor);
bool GetIsFocus() const
{
return isFocus_;
@ -207,6 +209,7 @@ protected:
bool CanShowFloatingTitle();
bool CanShowCustomTitle();
void TrimFloatingWindowLayout();
Color GetContainerColor(bool isFocus);
WindowMode windowMode_;
bool customTitleSettedShow_ = true;
@ -214,6 +217,8 @@ protected:
std::function<void(RectF&, RectF&)> controlButtonsRectChangeCallback_;
RectF buttonsRect_;
Dimension titleHeight_ = CONTAINER_TITLE_HEIGHT;
Color activeColor_;
Color inactiveColor_;
void InitTitleRowLayoutProperty(RefPtr<FrameNode> titleRow);
private:
void WindowFocus(bool isFocus);
@ -223,6 +228,7 @@ private:
void InitTitle();
void InitContainerEvent();
void InitLayoutProperty();
void InitContainerColor();
void InitButtonsLayoutProperty();

View File

@ -69,7 +69,7 @@ void ContainerModalPatternEnhance::ShowTitle(bool isShow, bool hasDeco, bool nee
layoutProperty->UpdateBorderWidth(borderWidth);
auto renderContext = containerNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
renderContext->UpdateBackgroundColor(theme->GetBackGroundColor(isFocus_));
renderContext->UpdateBackgroundColor(GetContainerColor(isFocus_));
// only floating window show border
BorderRadiusProperty borderRadius;
borderRadius.SetRadius((isFloatingWindow && isShow) ? CONTAINER_OUTER_RADIUS : 0.0_vp);
@ -210,7 +210,7 @@ void ContainerModalPatternEnhance::ChangeFloatingTitle(bool isFocus)
auto pipelineContext = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipelineContext);
auto theme = pipelineContext->GetTheme<ContainerModalTheme>();
floatingContext->UpdateBackgroundColor(theme->GetBackGroundColor(isFocus));
floatingContext->UpdateBackgroundColor(GetContainerColor(isFocus));
// update floating custom title label
auto customFloatingTitleNode = GetFloatingTitleNode();
CHECK_NULL_VOID(customFloatingTitleNode);
@ -224,6 +224,11 @@ void ContainerModalPatternEnhance::ChangeTitleButtonIcon(
ContainerModalPattern::ChangeTitleButtonIcon(buttonNode, icon, isFocus, isCloseBtn);
}
Color ContainerModalPatternEnhance::GetContainerColor(bool isFocus)
{
return ContainerModalPattern::GetContainerColor(isFocus);
}
void ContainerModalPatternEnhance::SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize)
{
auto controlButtonsNode = GetControlButtonRow();

View File

@ -60,6 +60,8 @@ protected:
void UpdateLightIntensity();
Color GetContainerColor(bool isFocus);
private:
VisibleType controlButtonVisibleBeforeAnim_;
RefPtr<RenderContext> closeBtnRenderContext_;

View File

@ -334,6 +334,8 @@ public:
appBgColor_ = color;
}
virtual void SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor) {}
virtual void ChangeDarkModeBrightness() {}
void SetFormRenderingMode(int8_t renderMode)

View File

@ -3785,6 +3785,20 @@ void PipelineContext::SetContainerButtonHide(bool hideSplit, bool hideMaximize,
containerPattern->SetContainerButtonHide(hideSplit, hideMaximize, hideMinimize);
}
void PipelineContext::SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor)
{
if (windowModal_ != WindowModal::CONTAINER_MODAL) {
LOGW("Set app icon failed, Window modal is not container.");
return;
}
CHECK_NULL_VOID(rootNode_);
auto containerNode = AceType::DynamicCast<FrameNode>(rootNode_->GetChildren().front());
CHECK_NULL_VOID(containerNode);
auto containerPattern = containerNode->GetPattern<ContainerModalPattern>();
CHECK_NULL_VOID(containerPattern);
containerPattern->SetWindowContainerColor(activeColor, inactiveColor);
}
void PipelineContext::AddFontNodeNG(const WeakPtr<UINode>& node)
{
if (fontManager_) {

View File

@ -233,6 +233,8 @@ public:
void SetAppBgColor(const Color& color) override;
void SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor) override;
void SetAppTitle(const std::string& title) override;
void SetAppIcon(const RefPtr<PixelMap>& icon) override;

View File

@ -149,6 +149,7 @@ public:
virtual uint32_t GetBackgroundColor() = 0;
virtual void SetBackgroundColor(uint32_t color) = 0;
virtual void SetUIContentType(UIContentType uIContentType) {};
virtual void SetWindowContainerColor(uint32_t activeColor, uint32_t inactiveColor) = 0;
// Judge whether window need soft keyboard or not
virtual bool NeedSoftKeyboard()

View File

@ -269,6 +269,8 @@ void PipelineContext::SetContainerWindow(bool isShow) {}
void PipelineContext::SetAppBgColor(const Color& color) {}
void PipelineContext::SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor) {};
void PipelineContext::ChangeDarkModeBrightness() {}
void PipelineContext::SetAppTitle(const std::string& title) {}

View File

@ -67,6 +67,7 @@ public:
MOCK_METHOD1(SetIgnoreViewSafeArea, void(bool ignoreViewSafeArea));
MOCK_METHOD0(GetBackgroundColor, uint32_t());
MOCK_METHOD1(SetBackgroundColor, void(uint32_t color));
MOCK_METHOD2(SetWindowContainerColor, void(uint32_t activeColor, uint32_t inactiveColor));
MOCK_METHOD2(DumpInfo, void(const std::vector<std::string>& params, std::vector<std::string>& info));
MOCK_METHOD1(SetNextFrameLayoutCallback, void(std::function<void()>&& callback));
MOCK_METHOD1(NotifyMemoryLevel, void(int32_t level));