From 19af37068f61a4ad176447d4e021aa9034a95938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E6=B5=B7=E9=BE=99?= Date: Wed, 13 Aug 2025 17:23:21 +0800 Subject: [PATCH] add judgment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 曹海龙 --- .../sheet_presentation_layout_algorithm.cpp | 3 + .../overlay/sheet_presentation_pattern.cpp | 42 +++++------ .../sheet_wrapper_layout_algorithm.cpp | 2 +- .../pattern/panel/close_icon_pattern.cpp | 14 ++-- .../panel/sliding_panel_layout_algorithm.cpp | 19 +++-- .../pattern/particle/particle_pattern.cpp | 3 + .../indexer/indexer_pattern_test_three_ng.cpp | 69 +++++++++++++++++++ 7 files changed, 120 insertions(+), 32 deletions(-) diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp index 99764da4402..e7bcf6fda6f 100755 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp @@ -135,6 +135,9 @@ void SheetPresentationLayoutAlgorithm::ComputeWidthAndHeight(LayoutWrapper* layo auto layoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); auto parentConstraint = layoutWrapper->GetGeometryNode()->GetParentLayoutConstraint(); + if (!parentConstraint.has_value()) { + return; + } LayoutConstraintF layoutConstraint = parentConstraint.value(); layoutProperty->UpdateLayoutConstraint(layoutConstraint); auto maxSize = layoutConstraint.maxSize; diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp index 028c85f0ccc..f66b7229674 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp @@ -99,7 +99,7 @@ void SheetPresentationPattern::OnModifyDone() CHECK_NULL_VOID(sheetTheme); auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); BlurStyle blurStyle = static_cast(sheetTheme->GetSheetBackgroundBlurStyle()); if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE) && blurStyle != BlurStyle::NO_MATERIAL) { @@ -168,7 +168,7 @@ float SheetPresentationPattern::GetSheetTopSafeArea() if (!Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_RETURN(layoutProperty, 0.0f); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.sheetType.has_value() && sheetStyle.sheetType.value() == SheetType::SHEET_BOTTOM && IsPhoneInLandScape()) { sheetTopSafeArea = 0.0f; @@ -202,7 +202,7 @@ void SheetPresentationPattern::InitPageHeight() } auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.sheetType.has_value() && sheetStyle.sheetType.value() == SheetType::SHEET_BOTTOM && IsPhoneInLandScape()) { sheetTopSafeArea_ = 0.0f; @@ -268,7 +268,7 @@ void SheetPresentationPattern::CheckBuilderChange() CHECK_NULL_VOID(sheetPattern); auto layoutProperty = sheetNode->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.sheetHeight.sheetMode == SheetMode::AUTO) { auto sheetWrapper = sheetNode->GetParent(); CHECK_NULL_VOID(sheetWrapper); @@ -430,7 +430,7 @@ void SheetPresentationPattern::SetSheetBorderWidth(bool isPartialUpdate) CHECK_NULL_VOID(sheetTheme); auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); auto renderContext = host->GetRenderContext(); CHECK_NULL_VOID(renderContext); renderContext->SetClipToBounds(true); @@ -540,7 +540,7 @@ void SheetPresentationPattern::SetShadowStyle(bool isFocused) CHECK_NULL_VOID(host); auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.shadow.has_value()) { return; } @@ -1247,7 +1247,7 @@ void SheetPresentationPattern::UpdateTitleColumnSize() CHECK_NULL_VOID(host); auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); auto operationColumn = GetTitleBuilderNode(); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); @@ -1286,7 +1286,7 @@ bool SheetPresentationPattern::IsShowCloseIcon() CHECK_NULL_RETURN(host, false); auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_RETURN(layoutProperty, false); - return layoutProperty->GetSheetStyleValue().showCloseIcon.value_or(true); + return layoutProperty->GetSheetStyleValue(SheetStyle()).showCloseIcon.value_or(true); } RefPtr SheetPresentationPattern::GetTitleNode() @@ -1319,7 +1319,7 @@ void SheetPresentationPattern::UpdateTitleTextColor() auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.sheetSubtitle.has_value()) { auto subRow = sheetTitleColumn->GetChildAtIndex(1); CHECK_NULL_VOID(subRow); @@ -1338,7 +1338,7 @@ void SheetPresentationPattern::UpdateTitlePadding() CHECK_NULL_VOID(host); auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); - if (!layoutProperty->GetSheetStyleValue().isTitleBuilder.has_value()) { + if (!layoutProperty->GetSheetStyleValue(SheetStyle()).isTitleBuilder.has_value()) { return; } @@ -1394,7 +1394,7 @@ void SheetPresentationPattern::UpdateSheetTitle() CHECK_NULL_VOID(pipeline); auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.sheetTitle.has_value()) { auto titleId = GetTitleId(); auto titleNode = DynamicCast(ElementRegister::GetInstance()->GetNodeById(titleId)); @@ -1437,7 +1437,7 @@ void SheetPresentationPattern::UpdateFontScaleStatus() CHECK_NULL_VOID(pipeline); auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (pipeline->GetFontScale() != scale_) { auto operationNode = GetTitleBuilderNode(); CHECK_NULL_VOID(operationNode); @@ -1515,7 +1515,7 @@ void SheetPresentationPattern::UpdateSheetBackgroundColor() CHECK_NULL_VOID(host); auto layoutProperty = DynamicCast(host->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.backgroundColor.has_value()) { return; } @@ -1598,7 +1598,7 @@ void SheetPresentationPattern::UpdateMaskBackgroundColor() CHECK_NULL_VOID(sheetTheme); auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); sheetMaskColor_ = sheetStyle.maskColor.value_or(sheetTheme->GetMaskColor()); if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_ELEVEN)) { if (sheetStyle.maskColor.has_value()) { @@ -1671,7 +1671,7 @@ void SheetPresentationPattern::CheckSheetHeightChange() CHECK_NULL_VOID(overlayManager); auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); overlayManager->ComputeSheetOffset(sheetStyle, host); overlayManager->PlaySheetTransition(host, true, false); auto maskNode = overlayManager->GetSheetMask(host); @@ -1717,7 +1717,7 @@ void SheetPresentationPattern::InitSheetDetents() // record input detents auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); IsCustomDetentsChanged(sheetStyle); preDetents_.clear(); sheetDetentHeight_.clear(); @@ -1861,7 +1861,7 @@ SheetType SheetPresentationPattern::ComputeSheetTypeInSubWindow() const } auto layoutProperty = GetLayoutProperty(); CHECK_NULL_RETURN(layoutProperty, SheetType::SHEET_CENTER); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); auto sheetType = SheetType::SHEET_CENTER; if (manager && manager->IsPcOrPadFreeMultiWindowMode()) { // Two in one or pad free-window mode @@ -2054,7 +2054,7 @@ void SheetPresentationPattern::GetSheetTypeWithAuto(SheetType& sheetType) const sheetType = SheetType::SHEET_CENTER; auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_FOURTEEN) && sheetStyle.sheetType.has_value() && sheetStyle.sheetType.value() == SheetType::SHEET_POPUP) { sheetType = SheetType::SHEET_POPUP; @@ -2079,7 +2079,7 @@ void SheetPresentationPattern::GetSheetTypeWithPopup(SheetType& sheetType) const } auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); #ifdef PREVIEW rootWidth = pipelineContext->GetDisplayWindowRectInfo().Width(); #endif @@ -2108,7 +2108,7 @@ void SheetPresentationPattern::GetSheetTypeWithCenter(SheetType& sheetType) cons { auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.sheetType.has_value()) { sheetType = sheetStyle.sheetType.value(); return; @@ -2528,7 +2528,7 @@ void SheetPresentationPattern::CalculateSheetRadius(BorderRadiusProperty& sheetR auto sheetSize = geometryNode->GetFrameSize(); auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetSize.IsPositive()) { CalculateAloneSheetRadius(sheetRadius.radiusTopLeft, sheetStyle.radius->radiusTopLeft); CalculateAloneSheetRadius(sheetRadius.radiusTopRight, sheetStyle.radius->radiusTopRight); diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp index 95330498e8f..d1810bbb1c1 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp @@ -191,7 +191,7 @@ void SheetWrapperLayoutAlgorithm::InitParameter(LayoutWrapper* layoutWrapper) sheetPattern->CalculateSheetRadius(sheetRadius_); auto layoutProperty = sheetPage->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); - auto sheetStyle = layoutProperty->GetSheetStyleValue(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); placement_ = sheetStyle.placement.value_or(Placement::BOTTOM); sheetPopupInfo_.Reset(); // everytime sheetWrapper changed, we need to reset sheetPopupInfo to default value sheetPopupInfo_.finalPlacement = placement_; diff --git a/frameworks/core/components_ng/pattern/panel/close_icon_pattern.cpp b/frameworks/core/components_ng/pattern/panel/close_icon_pattern.cpp index 53d00a58afe..be20da0fb32 100644 --- a/frameworks/core/components_ng/pattern/panel/close_icon_pattern.cpp +++ b/frameworks/core/components_ng/pattern/panel/close_icon_pattern.cpp @@ -16,6 +16,7 @@ #include "core/components_ng/pattern/panel/close_icon_pattern.h" #include "core/components_ng/pattern/image/image_pattern.h" +#include "core/components/close_icon/close_icon_theme.h" namespace OHOS::Ace::NG { void CloseIconPattern::OnModifyDone() @@ -40,9 +41,12 @@ void CloseIconPattern::InitCloseIcon() auto buttonLayoutProperty = buttonNode->GetLayoutProperty(); buttonNode->GetRenderContext()->UpdateBackgroundColor(Color::TRANSPARENT); CHECK_NULL_VOID(buttonLayoutProperty); + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + auto closeIconTheme = pipeline->GetTheme(); buttonLayoutProperty->UpdateUserDefinedIdealSize( - CalcSize(CalcLength(closeIconLayoutProperty->GetCloseIconWidthValue()), - CalcLength(closeIconLayoutProperty->GetCloseIconHeightValue()))); + CalcSize(CalcLength(closeIconLayoutProperty->GetCloseIconWidthValue(closeIconTheme->GetCloseIconWidth())), + CalcLength(closeIconLayoutProperty->GetCloseIconHeightValue(closeIconTheme->GetCloseIconHeight())))); buttonNode->MarkModifyDone(); auto pattern = buttonNode->GetPattern(); CHECK_NULL_VOID(pattern); @@ -52,8 +56,8 @@ void CloseIconPattern::InitCloseIcon() auto imageLayoutProperty = imageNode->GetLayoutProperty(); CHECK_NULL_VOID(imageLayoutProperty); imageLayoutProperty->UpdateUserDefinedIdealSize( - CalcSize(CalcLength(closeIconLayoutProperty->GetCloseIconWidthValue()), - CalcLength(closeIconLayoutProperty->GetCloseIconHeightValue()))); + CalcSize(CalcLength(closeIconLayoutProperty->GetCloseIconWidthValue(closeIconTheme->GetCloseIconWidth())), + CalcLength(closeIconLayoutProperty->GetCloseIconHeightValue(closeIconTheme->GetCloseIconHeight())))); imageLayoutProperty->UpdateImageFit(ImageFit::FILL); ImageSourceInfo imageSourceInfo; imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_BOTTOMSHEET_CLOSE_SVG); @@ -64,7 +68,7 @@ void CloseIconPattern::InitCloseIcon() auto renderContext = host->GetRenderContext(); CHECK_NULL_VOID(renderContext); BorderRadiusProperty radius; - radius.SetRadius(closeIconLayoutProperty->GetCloseIconRadiusValue()); + radius.SetRadius(closeIconLayoutProperty->GetCloseIconRadiusValue(closeIconTheme->GetCloseIconRadius())); renderContext->UpdateBorderRadius(radius); host->AddChild(buttonNode); buttonNode->AddChild(imageNode); diff --git a/frameworks/core/components_ng/pattern/panel/sliding_panel_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/panel/sliding_panel_layout_algorithm.cpp index 01c7e6009cd..fb3f1a142f0 100644 --- a/frameworks/core/components_ng/pattern/panel/sliding_panel_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/panel/sliding_panel_layout_algorithm.cpp @@ -18,6 +18,7 @@ #include "core/components/common/layout/grid_system_manager.h" #include "core/components_ng/pattern/panel/close_icon_layout_property.h" #include "core/components_ng/pattern/panel/sliding_panel_layout_property.h" +#include "core/components/close_icon/close_icon_theme.h" #include "core/pipeline_ng/pipeline_context.h" #include "core/components_ng/property/measure_utils.h" @@ -139,9 +140,14 @@ void SlidingPanelLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(closeIconWrapper); auto closeIconLayoutProperty = AceType::DynamicCast(closeIconWrapper->GetLayoutProperty()); CHECK_NULL_VOID(closeIconLayoutProperty); - auto closeIconWidth = closeIconLayoutProperty->GetCloseIconWidthValue(); - auto closeIconMarginTop = closeIconLayoutProperty->GetCloseIconMarginTopValue(); - auto closeIconMargionRight = closeIconLayoutProperty->GetCloseIconMarginRightValue(); + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + auto closeIconTheme = pipeline->GetTheme(); + auto closeIconWidth = closeIconLayoutProperty->GetCloseIconWidthValue(closeIconTheme->GetCloseIconWidth()); + auto closeIconMarginTop = closeIconLayoutProperty->GetCloseIconMarginTopValue( + closeIconTheme->GetCloseIconMarginTop()); + auto closeIconMargionRight = closeIconLayoutProperty->GetCloseIconMarginRightValue( + closeIconTheme->GetCloseIconMarginRight()); auto closeIconX = maxWidth_ + childOffsetX - static_cast(closeIconWidth.ConvertToPx()) - static_cast(closeIconMargionRight.ConvertToPx()); auto closeIconY = childOffset.GetY() + static_cast(closeIconMarginTop.ConvertToPx()); @@ -179,8 +185,11 @@ void SlidingPanelLayoutAlgorithm::MeasureCloseIcon( CHECK_NULL_VOID(closeIconGeometryNode); auto closeIconLayoutProperty = AceType::DynamicCast(closeIconWrapper->GetLayoutProperty()); CHECK_NULL_VOID(closeIconLayoutProperty); - auto closeIconWidth = closeIconLayoutProperty->GetCloseIconWidthValue(); - auto closeIconHeigth = closeIconLayoutProperty->GetCloseIconHeightValue(); + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + auto closeIconTheme = pipeline->GetTheme(); + auto closeIconWidth = closeIconLayoutProperty->GetCloseIconWidthValue(closeIconTheme->GetCloseIconWidth()); + auto closeIconHeigth = closeIconLayoutProperty->GetCloseIconHeightValue(closeIconTheme->GetCloseIconHeight()); SizeF frameSize = SizeF(static_cast(closeIconWidth.ConvertToPx()), static_cast(closeIconHeigth.ConvertToPx())); closeIconGeometryNode->SetFrameSize(frameSize); diff --git a/frameworks/core/components_ng/pattern/particle/particle_pattern.cpp b/frameworks/core/components_ng/pattern/particle/particle_pattern.cpp index f079a48e4ed..e790ecf67bb 100644 --- a/frameworks/core/components_ng/pattern/particle/particle_pattern.cpp +++ b/frameworks/core/components_ng/pattern/particle/particle_pattern.cpp @@ -42,6 +42,9 @@ void ParticlePattern::OnVisibleChange(bool isVisible) if (isVisible) { auto host = GetHost(); auto context = host->GetRenderContext(); + if (!context->GetParticleOptionArray().has_value()) { + return; + } context->OnParticleOptionArrayUpdate(context->GetParticleOptionArray().value()); } } diff --git a/test/unittest/core/pattern/indexer/indexer_pattern_test_three_ng.cpp b/test/unittest/core/pattern/indexer/indexer_pattern_test_three_ng.cpp index a470850636a..aa83906bb45 100644 --- a/test/unittest/core/pattern/indexer/indexer_pattern_test_three_ng.cpp +++ b/test/unittest/core/pattern/indexer/indexer_pattern_test_three_ng.cpp @@ -537,4 +537,73 @@ HWTEST_F(IndexerPatternTestThreeNg, IndexerPatternTestThreeNg007, TestSize.Level EXPECT_EQ(pattern_->GetActualIndex(-1), 0); EXPECT_EQ(pattern_->GetActualIndex(pattern_->fullArrayValue_.size() + 1), pattern_->fullArrayValue_.size() - 1); } + +/** + * @tc.name: IndexerPatternTestThreeNg008 + * @tc.desc: Test indexer pattern OnHover function. + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestThreeNg, IndexerPatternTestThreeNg008, TestSize.Level1) +{ + /** + * @tc.steps: step1. Test with voidArray. + * @tc.expected: isHover_ false. + */ + IndexerModelNG model = CreateIndexer(std::vector(), 0); + CreateDone(); + pattern_->OnHover(true); + EXPECT_FALSE(pattern_->isHover_); + + /** + * @tc.steps: step2. Test with MidArray. + * @tc.expected: isHover_ true. + */ + model.SetArrayValue(AceType::RawPtr(frameNode_), GetMidArrayValue()); + frameNode_->MarkModifyDone(); + FlushUITasks(); + pattern_->OnHover(true); + EXPECT_TRUE(pattern_->isHover_); + EXPECT_FALSE(pattern_->isTouch_); + pattern_->OnHover(true); + EXPECT_TRUE(pattern_->isHover_); + pattern_->OnHover(false); + EXPECT_FALSE(pattern_->isHover_); + EXPECT_FALSE(pattern_->isTouch_); +} + +/** + * @tc.name: KeyIndexByStepTestNg001 + * @tc.desc: Test indexer pattern KeyIndexByStep function. + * @tc.type: FUNC + */ +HWTEST_F(IndexerPatternTestThreeNg, KeyIndexByStepTestNg001, TestSize.Level1) +{ + int32_t index; + CreateIndexer(GetShortArrayValue(), 0); + CreateDone(); + + /** + * @tc.steps: step1. Test with childFocusIndex_ != nextSelected. + * @tc.expected: childFocusIndex_ changed. + */ + index = 2; + pattern_->KeyIndexByStep(index); + EXPECT_EQ(pattern_->childFocusIndex_, index); + EXPECT_EQ(pattern_->selected_, index); + EXPECT_EQ(pattern_->childPressIndex_, -1); + EXPECT_EQ(pattern_->lastSelected_, index); + EXPECT_FALSE(pattern_->selectedChangedForHaptic_); + + /** + * @tc.steps: step2. Test with childFocusIndex_ == nextSelected. + * @tc.expected: selected_ not changed. + */ + index = 1; + pattern_->childFocusIndex_ = pattern_->selected_ + index; + pattern_->KeyIndexByStep(index); + EXPECT_EQ(pattern_->selected_, 2); + EXPECT_EQ(pattern_->childPressIndex_, -1); + EXPECT_EQ(pattern_->lastSelected_, 2); + EXPECT_FALSE(pattern_->selectedChangedForHaptic_); +} } // namespace OHOS::Ace::NG -- Gitee