From c20e6cb486e312ea44945f5055248b9d327dfb3c Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Wed, 23 Feb 2022 15:34:15 +0800 Subject: [PATCH 1/2] fix some bugs Signed-off-by: jiangdayuan Change-Id: I3c97678bf5d39964398f97de749afd2ac137c269 --- .../container_modal_component.cpp | 57 +++++++--------- .../container_modal_component.h | 18 +++-- .../container_modal_element.cpp | 66 +++++++++++++++---- .../container_modal/container_modal_element.h | 10 ++- .../render_container_modal.cpp | 9 --- 5 files changed, 100 insertions(+), 60 deletions(-) diff --git a/frameworks/core/components/container_modal/container_modal_component.cpp b/frameworks/core/components/container_modal/container_modal_component.cpp index 646081ac74b..dc577fcecbc 100644 --- a/frameworks/core/components/container_modal/container_modal_component.cpp +++ b/frameworks/core/components/container_modal/container_modal_component.cpp @@ -17,11 +17,9 @@ #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" -#include "core/components/flex/flex_component.h" #include "core/components/flex/flex_item_component.h" #include "core/components/image/image_component.h" #include "core/components/padding/padding_component.h" @@ -49,22 +47,12 @@ RefPtr ContainerModalComponent::CreateRenderNode() return RenderContainerModal::Create(); } -RefPtr ContainerModalComponent::GetMaximizeRecoverButtonIcon() const -{ - if (!titleMaximizeRecoverButton_ || titleMaximizeRecoverButton_->GetChildren().empty()) { - LOGE("tile maximize recover button is null"); - return nullptr; - } - return titleMaximizeRecoverButton_->GetChildren().front(); -} - RefPtr ContainerModalComponent::BuildTitle() { // build title box - titleChildren_ = BuildTitleChildren(); auto titleBox = AceType::MakeRefPtr(); titleBox->SetHeight(CONTAINER_TITLE_HEIGHT); - auto row = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, titleChildren_); + titleChildrenRow_ = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, BuildTitleChildren(false)); // handle mouse move titleBox->SetOnMouseId([contextWptr = context_](MouseInfo& info) { @@ -81,7 +69,7 @@ RefPtr ContainerModalComponent::BuildTitle() context->FireWindowStartMoveCallBack(); } }); - titleBox->SetChild(row); + titleBox->SetChild(titleChildrenRow_); auto display = AceType::MakeRefPtr(titleBox); return display; } @@ -96,8 +84,8 @@ RefPtr ContainerModalComponent::BuildFloatingTitle() titleBox->SetHeight(CONTAINER_TITLE_HEIGHT); titleBox->SetBackDecoration(titleDecoration); - auto row = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, titleChildren_); - titleBox->SetChild(row); + floatingTitleChildrenRow_ = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, BuildTitleChildren(true)); + titleBox->SetChild(floatingTitleChildrenRow_); auto tween = AceType::MakeRefPtr("ContainerModal", titleBox); return tween; } @@ -180,23 +168,27 @@ void ContainerModalComponent::BuildInnerChild() SetChild(containerBox); } -std::list> ContainerModalComponent::BuildTitleChildren() +std::list> ContainerModalComponent::BuildTitleChildren(bool isFloating) { // title icon - titleIcon_ = AceType::MakeRefPtr(); - titleIcon_->SetWidth(TITLE_ICON_SIZE); - titleIcon_->SetHeight(TITLE_ICON_SIZE); + if (!titleIcon_) { + titleIcon_ = AceType::MakeRefPtr(); + titleIcon_->SetWidth(TITLE_ICON_SIZE); + titleIcon_->SetHeight(TITLE_ICON_SIZE); + } // title text - titleLabel_ = AceType::MakeRefPtr(""); - TextStyle style; - style.SetFontSize(TITLE_TEXT_FONT_SIZE); - style.SetTextColor(TITLE_TEXT_COLOR); - style.SetFontWeight(FontWeight::W500); - style.SetAllowScale(false); - titleLabel_->SetTextStyle(style); - - // title button + if (!titleLabel_) { + titleLabel_ = AceType::MakeRefPtr(""); + TextStyle style; + style.SetFontSize(TITLE_TEXT_FONT_SIZE); + style.SetTextColor(TITLE_TEXT_COLOR); + style.SetFontWeight(FontWeight::W500); + style.SetAllowScale(false); + titleLabel_->SetTextStyle(style); + } + + // title control button auto contextWptr = context_; auto titleLeftSplitButton = BuildControlButton(InternalResource::ResourceId::CONTAINER_MODAL_WINDOW_SPLIT_LEFT, [contextWptr]() { @@ -207,8 +199,9 @@ std::list> ContainerModalComponent::BuildTitleChildren() context->ShowContainerTitle(false); } }); - titleMaximizeRecoverButton_ = - BuildControlButton(InternalResource::ResourceId::CONTAINER_MODAL_WINDOW_MAXIMIZE, [contextWptr]() { + auto buttonResourceId = isFloating ? InternalResource::ResourceId::CONTAINER_MODAL_WINDOW_RECOVER + : InternalResource::ResourceId::CONTAINER_MODAL_WINDOW_MAXIMIZE; + auto titleMaximizeRecoverButton = BuildControlButton(buttonResourceId, [contextWptr]() { auto context = contextWptr.Upgrade(); if (context) { auto mode = context->FireWindowGetModeCallBack(); @@ -243,7 +236,7 @@ std::list> ContainerModalComponent::BuildTitleChildren() titleChildren.emplace_back(SetPadding(titleIcon_, TITLE_PADDING_START, TITLE_ELEMENT_MARGIN_HORIZONTAL)); titleChildren.emplace_back(AceType::MakeRefPtr(1.0, 1.0, 0.0, titleLabel_)); titleChildren.emplace_back(SetPadding(titleLeftSplitButton, ZERO_PADDING, TITLE_ELEMENT_MARGIN_HORIZONTAL)); - titleChildren.emplace_back(SetPadding(titleMaximizeRecoverButton_, ZERO_PADDING, TITLE_ELEMENT_MARGIN_HORIZONTAL)); + titleChildren.emplace_back(SetPadding(titleMaximizeRecoverButton, ZERO_PADDING, TITLE_ELEMENT_MARGIN_HORIZONTAL)); titleChildren.emplace_back(SetPadding(titleMinimizeButton, ZERO_PADDING, TITLE_ELEMENT_MARGIN_HORIZONTAL)); titleChildren.emplace_back(SetPadding(titleCloseButton, ZERO_PADDING, TITLE_PADDING_END)); return titleChildren; diff --git a/frameworks/core/components/container_modal/container_modal_component.h b/frameworks/core/components/container_modal/container_modal_component.h index 81a1920ef5b..996260c28b1 100644 --- a/frameworks/core/components/container_modal/container_modal_component.h +++ b/frameworks/core/components/container_modal/container_modal_component.h @@ -17,6 +17,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONTAINER_MODAL_COMPONENT_H #include "core/components/button/button_component.h" +#include "core/components/flex/flex_component.h" #include "core/components/image/image_component.h" #include "core/components/text/text_component.h" #include "core/pipeline/base/sole_child_component.h" @@ -37,7 +38,6 @@ public: RefPtr CreateElement() override; RefPtr CreateRenderNode() override; void BuildInnerChild(); - RefPtr GetMaximizeRecoverButtonIcon() const; RefPtr GetTitleIcon() const { @@ -49,21 +49,31 @@ public: return titleLabel_; } + RefPtr GetTitleChildrenRow() const + { + return titleChildrenRow_; + } + + RefPtr GetFloatingTitleChildrenRow() const + { + return floatingTitleChildrenRow_; + } + private: RefPtr BuildTitle(); RefPtr BuildFloatingTitle(); RefPtr BuildContent(); RefPtr BuildControlButton( InternalResource::ResourceId icon, std::function&& clickCallback); - std::list> BuildTitleChildren(); + std::list> BuildTitleChildren(bool isFloating); static RefPtr SetPadding( const RefPtr& component, const Dimension& leftPadding, const Dimension& rightPadding); WeakPtr context_; RefPtr titleIcon_; RefPtr titleLabel_; - RefPtr titleMaximizeRecoverButton_; - std::list> titleChildren_; + RefPtr titleChildrenRow_; + RefPtr floatingTitleChildrenRow_; }; } // 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 be69188b62c..e31668bf41b 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -108,6 +108,8 @@ void ContainerModalElement::ShowTitle(bool isShow) LOGE("ContainerModalElement showTitle failed, container box element is null!"); return; } + + // full screen need to hide border and padding. auto containerRenderBox = AceType::DynamicCast(containerBox->GetRenderNode()); if (containerRenderBox) { auto containerDecoration = AceType::MakeRefPtr(); @@ -138,6 +140,7 @@ 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(); @@ -160,11 +163,13 @@ void ContainerModalElement::ShowTitle(bool isShow) if (renderDisplay) { renderDisplay->UpdateVisibleType(isShow ? VisibleType::VISIBLE : VisibleType::GONE); } + ChangeFloatingTitleIcon(); // hide floating title anyway. - if (renderDisplay_) { - renderDisplay_->UpdateVisibleType(VisibleType::GONE); + if (floatingTitleDisplay_) { + floatingTitleDisplay_->UpdateVisibleType(VisibleType::GONE); } + isFirstShowTitle_ = false; } void ContainerModalElement::PerformBuild() @@ -196,17 +201,25 @@ void ContainerModalElement::PerformBuild() LOGE("ContainerModalElement PerformBuild failed, tween element is null."); return; } + floatingTitleBox_ = AceType::DynamicCast(tween->GetContentElement()); auto display = AceType::DynamicCast(tween->GetFirstChild()); - if (display && !renderDisplay_) { - renderDisplay_ = AceType::DynamicCast(display->GetRenderNode()); - if (renderDisplay_) { - renderDisplay_->UpdateVisibleType(VisibleType::GONE); + if (display && !floatingTitleDisplay_) { + floatingTitleDisplay_ = AceType::DynamicCast(display->GetRenderNode()); + if (floatingTitleDisplay_) { + floatingTitleDisplay_->UpdateVisibleType(VisibleType::GONE); } } tween->SetController(controller_); tween->SetOption(option); tween->ApplyKeyframes(); } + + // The first time it starts up, it needs to hide title if mode as follows. + auto mode = context_.Upgrade()->FireWindowGetModeCallBack(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN || mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || + mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { + ShowTitle(false); + } } void ContainerModalElement::Update() @@ -218,6 +231,8 @@ void ContainerModalElement::Update() LOGE("ContainerModalElement update failed, container modal component is null."); return; } + titleChildrenRow_ = container->GetTitleChildrenRow(); + floatingTitleChildrenRow_ = container->GetFloatingTitleChildrenRow(); auto containerBox = AceType::DynamicCast(container->GetChild()); if (!containerBox) { LOGE("ContainerModalElement update failed, container box component is null."); @@ -231,7 +246,7 @@ void ContainerModalElement::Update() return; } if (info.GetChangedTouches().begin()->GetGlobalLocation().GetY() <= TITLE_POPUP_DISTANCE) { - containerElement->renderDisplay_->UpdateVisibleType(VisibleType::VISIBLE); + containerElement->floatingTitleDisplay_->UpdateVisibleType(VisibleType::VISIBLE); containerElement->controller_->Forward(); } }); @@ -243,7 +258,7 @@ void ContainerModalElement::Update() return; } if (info.GetAction() == MouseAction::MOVE && info.GetLocalLocation().GetY() <= TITLE_POPUP_DISTANCE) { - containerElement->renderDisplay_->UpdateVisibleType(VisibleType::VISIBLE); + containerElement->floatingTitleDisplay_->UpdateVisibleType(VisibleType::VISIBLE); containerElement->controller_->Forward(); } }); @@ -252,20 +267,45 @@ void ContainerModalElement::Update() bool ContainerModalElement::CanShowFloatingTitle() { auto context = context_.Upgrade(); - if (!context || !renderDisplay_ || !controller_) { - LOGI("Show floating title failed, context, renderDisplay_ or controller is null."); + if (!context || !floatingTitleDisplay_ || !controller_ || isFirstShowTitle_) { + LOGI("Show floating title failed, context, floatingTitleDisplay_ or controller is null."); return false; } auto mode = context->FireWindowGetModeCallBack(); - if (mode != WindowMode::WINDOW_MODE_FULLSCREEN && mode != WindowMode::WINDOW_MODE_SPLIT_PRIMARY) { - LOGI("Window is not full screen or split primary, can not show floating title."); + if (mode != WindowMode::WINDOW_MODE_FULLSCREEN && mode != WindowMode::WINDOW_MODE_SPLIT_PRIMARY && + mode != WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { + LOGI("Window is not full screen or split screen, can not show floating title."); return false; } - if (renderDisplay_->GetVisibleType() == VisibleType::VISIBLE) { + if (floatingTitleDisplay_->GetVisibleType() == VisibleType::VISIBLE) { LOGI("Floating tittle is visible now, no need to show again."); return false; } return true; } +void ContainerModalElement::ChangeFloatingTitleIcon() +{ + if (!floatingTitleBox_ || !titleChildrenRow_ || !floatingTitleChildrenRow_) { + LOGE("ChangeFloatingTitleIcon failed."); + return; + } + auto context = context_.Upgrade(); + if (!context) { + LOGE("ChangeFloatingTitleIcon failed, context is null."); + return; + } + auto row = AceType::DynamicCast(floatingTitleBox_->GetFirstChild()); + if (!row) { + LOGE("ChangeFloatingTitleIcon failed, row element is null"); + return; + } + auto mode = context->FireWindowGetModeCallBack(); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN) { + row->SetUpdateComponent(floatingTitleChildrenRow_); + } else { + row->SetUpdateComponent(titleChildrenRow_); + } +} + } // 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 0ba18d8aa00..cd698f40af4 100644 --- a/frameworks/core/components/container_modal/container_modal_element.h +++ b/frameworks/core/components/container_modal/container_modal_element.h @@ -16,6 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONTAINER_MODAL_ELEMENT_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_CONTAINER_MODAL_ELEMENT_H +#include "core/components/flex/flex_component.h" #include "core/components/overlay/overlay_element.h" #include "core/components/stage/stage_element.h" #include "core/pipeline/base/sole_child_element.h" @@ -34,9 +35,14 @@ public: private: RefPtr GetStackElement() const; - RefPtr controller_; - RefPtr renderDisplay_; bool CanShowFloatingTitle(); + void ChangeFloatingTitleIcon(); + RefPtr controller_; + RefPtr floatingTitleDisplay_; + RefPtr floatingTitleBox_; + RefPtr titleChildrenRow_; + RefPtr floatingTitleChildrenRow_; + bool isFirstShowTitle_ = true; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/container_modal/render_container_modal.cpp b/frameworks/core/components/container_modal/render_container_modal.cpp index 69bee675d77..3c48ff07c8c 100644 --- a/frameworks/core/components/container_modal/render_container_modal.cpp +++ b/frameworks/core/components/container_modal/render_container_modal.cpp @@ -64,15 +64,6 @@ void RenderContainerModal::UpdateStyle(const RefPtr& component) const auto appIconSrc = themeConstants->GetMediaPath(iconId); appIconComponent->SetSrc(appIconSrc); } - - auto buttonIconComponent = AceType::DynamicCast(containerModal->GetMaximizeRecoverButtonIcon()); - if (buttonIconComponent) { - if (context->FireWindowGetModeCallBack() == WindowMode::WINDOW_MODE_FULLSCREEN) { - buttonIconComponent->SetResourceId(InternalResource::ResourceId::CONTAINER_MODAL_WINDOW_RECOVER); - } else { - buttonIconComponent->SetResourceId(InternalResource::ResourceId::CONTAINER_MODAL_WINDOW_MAXIMIZE); - } - } } void RenderContainerModal::Update(const RefPtr& component) -- Gitee From 933b11f52f98e198ba95a0c75ab006936078668d Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Wed, 23 Feb 2022 16:04:39 +0800 Subject: [PATCH 2/2] update code check Signed-off-by: jiangdayuan Change-Id: I8910b9bab99c2cbdbe112b0737df640b301ef3de --- .../container_modal/container_modal_component.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components/container_modal/container_modal_component.cpp b/frameworks/core/components/container_modal/container_modal_component.cpp index dc577fcecbc..5defb31cc83 100644 --- a/frameworks/core/components/container_modal/container_modal_component.cpp +++ b/frameworks/core/components/container_modal/container_modal_component.cpp @@ -52,7 +52,8 @@ RefPtr ContainerModalComponent::BuildTitle() // build title box auto titleBox = AceType::MakeRefPtr(); titleBox->SetHeight(CONTAINER_TITLE_HEIGHT); - titleChildrenRow_ = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, BuildTitleChildren(false)); + titleChildrenRow_ = + AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, BuildTitleChildren(false)); // handle mouse move titleBox->SetOnMouseId([contextWptr = context_](MouseInfo& info) { @@ -84,7 +85,8 @@ RefPtr ContainerModalComponent::BuildFloatingTitle() titleBox->SetHeight(CONTAINER_TITLE_HEIGHT); titleBox->SetBackDecoration(titleDecoration); - floatingTitleChildrenRow_ = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, BuildTitleChildren(true)); + floatingTitleChildrenRow_ = + AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, BuildTitleChildren(true)); titleBox->SetChild(floatingTitleChildrenRow_); auto tween = AceType::MakeRefPtr("ContainerModal", titleBox); return tween; -- Gitee