diff --git a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp index 5b082397c22c712a832afd45f6ddc04192cddb74..b2da75cb0aa63ad5c1792cead860fa92f6a43fb6 100644 --- a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp @@ -128,7 +128,8 @@ constexpr Dimension TIPS_MOUSE_SPACE = 8.0_vp; constexpr Dimension MAX_TIP_WIDTH = 480.0_vp; const std::vector FOLLOW_CURSOR_TIPS = { Placement::BOTTOM_LEFT, Placement::TOP_LEFT, - Placement::BOTTOM_RIGHT, Placement::TOP_RIGHT, Placement::BOTTOM, Placement::TOP, Placement::NONE }; + Placement::BOTTOM_RIGHT, Placement::TOP_RIGHT, Placement::BOTTOM, Placement::TOP, Placement::RIGHT_TOP, + Placement::LEFT_TOP, Placement::NONE }; static RefPtr GetPopupTheme(LayoutWrapper* layoutWrapper) { @@ -2581,9 +2582,14 @@ OffsetF BubbleLayoutAlgorithm::GetPositionWithPlacementLeftTop( float arrowHalfWidth = BUBBLE_ARROW_WIDTH.ConvertToPx() / BUBBLE_ARROW_HALF; float radius = borderRadius_.ConvertToPx(); if (resetTipsSize_) { - childPosition = OffsetF( - targetOffset_.GetX() - targetSpace_.ConvertToPx() - bubbleSpacing - childSize.Width() - marginRight, - (isHalfFoldHover_ ? wrapperRect_.Bottom() : (wrapperSize_.Height() - marginBottom_)) - childSize.Height()); + float offsetY = + (isHalfFoldHover_ ? wrapperRect_.Bottom() : (wrapperSize_.Height() - marginBottom_)) - childSize.Height(); + if (GreatNotEqual(offsetY, targetOffset_.GetY())) { + offsetY = targetOffset_.GetY(); + } + childPosition = + OffsetF(targetOffset_.GetX() - targetSpace_.ConvertToPx() - bubbleSpacing - childSize.Width() - marginRight, + offsetY); } else { childPosition = OffsetF(targetOffset_.GetX() - targetSpace_.ConvertToPx() - bubbleSpacing - childSize.Width() - marginRight, @@ -2634,9 +2640,14 @@ OffsetF BubbleLayoutAlgorithm::GetPositionWithPlacementRightTop( float arrowHalfWidth = BUBBLE_ARROW_WIDTH.ConvertToPx() / BUBBLE_ARROW_HALF; float radius = borderRadius_.ConvertToPx(); if (resetTipsSize_) { + float offsetY = + (isHalfFoldHover_ ? wrapperRect_.Bottom() : (wrapperSize_.Height() - marginBottom_)) - childSize.Height(); + if (GreatNotEqual(offsetY, targetOffset_.GetY())) { + offsetY = targetOffset_.GetY(); + } childPosition = OffsetF( targetOffset_.GetX() + targetSize_.Width() + targetSpace_.ConvertToPx() + bubbleSpacing + marginLeft, - (isHalfFoldHover_ ? wrapperRect_.Bottom() : (wrapperSize_.Height() - marginBottom_)) - childSize.Height()); + offsetY); } else { childPosition = OffsetF( targetOffset_.GetX() + targetSize_.Width() + targetSpace_.ConvertToPx() + bubbleSpacing + marginLeft, diff --git a/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp b/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp index 27cc5d8d7a9c1264c496a486d4415a0572e64359..c1fdd9c2f2b6e9e6a374e11e1ad9b5d3a7af16ef 100755 --- a/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp +++ b/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp @@ -532,12 +532,49 @@ HWTEST_F(BubbleTipsTestNg, GetPositionWithPlacementLeftTopTest001, TestSize.Leve auto position = layoutAlgorithm->GetPositionWithPlacementLeftTop(MAX_SIZE, topPosition, bottomPosition, arrowPosition); EXPECT_EQ(position.GetX(), DEVICE_WIDTH - MAX_SIZE.Width()); - EXPECT_EQ(position.GetY(), DEVICE_HEIGHT - layoutAlgorithm->marginBottom_ - MAX_SIZE.Height()); + EXPECT_EQ(position.GetY(), DEVICE_HEIGHT * HALF); layoutAlgorithm->isHalfFoldHover_ = true; position = layoutAlgorithm->GetPositionWithPlacementLeftTop(MAX_SIZE, topPosition, bottomPosition, arrowPosition); EXPECT_EQ(position.GetX(), DEVICE_WIDTH - MAX_SIZE.Width()); - EXPECT_EQ(position.GetY(), layoutAlgorithm->wrapperRect_.Bottom() - MAX_SIZE.Height()); + EXPECT_EQ(position.GetY(), DEVICE_HEIGHT * HALF); +} + +/** + * @tc.name: GetPositionWithPlacementLeftTopTest002 + * @tc.desc: Test GetPositionWithPlacementLeftTop function. + * @tc.type: FUNC + */ +HWTEST_F(BubbleTipsTestNg, GetPositionWithPlacementLeftTopTest002, TestSize.Level1) +{ + /** + * @tc.steps: step1. create bubble and get frameNode. + */ + auto tipsNode = CreateTipsNode(CreateTipsParamForCursor(), TIPS_MSG_1); + auto layoutAlgorithm = + AceType::DynamicCast(tipsNode->layoutAlgorithm_->GetLayoutAlgorithm()); + layoutAlgorithm->wrapperRect_ = { 0, 0, DEVICE_WIDTH, DEVICE_HEIGHT }; + layoutAlgorithm->wrapperSize_ = { DEVICE_WIDTH, DEVICE_HEIGHT }; + layoutAlgorithm->targetSize_ = SizeF(MOUSE_WIDTH.ConvertToPx(), MOUSE_HEIGHT.ConvertToPx()); + layoutAlgorithm->targetOffset_ = { DEVICE_WIDTH, DEVICE_HEIGHT * HALF }; + layoutAlgorithm->targetSpace_ = Dimension(); + layoutAlgorithm->resetTipsSize_ = true; + /** + * @tc.steps: step2. test GetPositionWithPlacementLeftTop. + */ + OffsetF topPosition; + OffsetF bottomPosition; + OffsetF arrowPosition; + const SizeF childSize { 480.0, DEVICE_HEIGHT * HALF }; + auto position = + layoutAlgorithm->GetPositionWithPlacementLeftTop(childSize, topPosition, bottomPosition, arrowPosition); + EXPECT_EQ(position.GetX(), DEVICE_WIDTH - childSize.Width()); + EXPECT_EQ(position.GetY(), DEVICE_HEIGHT - layoutAlgorithm->marginBottom_ - childSize.Height()); + + layoutAlgorithm->isHalfFoldHover_ = true; + position = layoutAlgorithm->GetPositionWithPlacementLeftTop(childSize, topPosition, bottomPosition, arrowPosition); + EXPECT_EQ(position.GetX(), DEVICE_WIDTH - childSize.Width()); + EXPECT_EQ(position.GetY(), layoutAlgorithm->wrapperRect_.Bottom() - childSize.Height()); } /** @@ -568,12 +605,48 @@ HWTEST_F(BubbleTipsTestNg, GetPositionWithPlacementRightTopTest001, TestSize.Lev auto position = layoutAlgorithm->GetPositionWithPlacementRightTop(MAX_SIZE, topPosition, bottomPosition, arrowPosition); EXPECT_EQ(position.GetX(), TIPS_MARGIN_SPACE.ConvertToPx() + MOUSE_WIDTH.ConvertToPx()); - EXPECT_EQ(position.GetY(), DEVICE_HEIGHT - layoutAlgorithm->marginBottom_ - MAX_SIZE.Height()); + EXPECT_EQ(position.GetY(), DEVICE_HEIGHT * HALF); layoutAlgorithm->isHalfFoldHover_ = true; position = layoutAlgorithm->GetPositionWithPlacementRightTop(MAX_SIZE, topPosition, bottomPosition, arrowPosition); EXPECT_EQ(position.GetX(), TIPS_MARGIN_SPACE.ConvertToPx() + MOUSE_WIDTH.ConvertToPx()); - EXPECT_EQ(position.GetY(), layoutAlgorithm->wrapperRect_.Bottom() - MAX_SIZE.Height()); + EXPECT_EQ(position.GetY(), DEVICE_HEIGHT * HALF); +} +/** + * @tc.name: GetPositionWithPlacementRightTopTest002 + * @tc.desc: Test GetPositionWithPlacementRightTop function. + * @tc.type: FUNC + */ +HWTEST_F(BubbleTipsTestNg, GetPositionWithPlacementRightTopTest002, TestSize.Level1) +{ + /** + * @tc.steps: step1. create bubble and get frameNode. + */ + auto tipsNode = CreateTipsNode(CreateTipsParamForCursor(), TIPS_MSG_1); + auto layoutAlgorithm = + AceType::DynamicCast(tipsNode->layoutAlgorithm_->GetLayoutAlgorithm()); + layoutAlgorithm->wrapperRect_ = { 0, 0, DEVICE_WIDTH, DEVICE_HEIGHT }; + layoutAlgorithm->wrapperSize_ = { DEVICE_WIDTH, DEVICE_HEIGHT }; + layoutAlgorithm->targetSize_ = SizeF(MOUSE_WIDTH.ConvertToPx(), MOUSE_HEIGHT.ConvertToPx()); + layoutAlgorithm->targetOffset_ = { TIPS_MARGIN_SPACE.ConvertToPx(), DEVICE_HEIGHT * HALF }; + layoutAlgorithm->targetSpace_ = Dimension(); + layoutAlgorithm->resetTipsSize_ = true; + /** + * @tc.steps: step2. test GetPositionWithPlacementRightTop. + */ + OffsetF topPosition; + OffsetF bottomPosition; + OffsetF arrowPosition; + const SizeF childSize { 480.0, DEVICE_HEIGHT * HALF }; + auto position = + layoutAlgorithm->GetPositionWithPlacementRightTop(childSize, topPosition, bottomPosition, arrowPosition); + EXPECT_EQ(position.GetX(), TIPS_MARGIN_SPACE.ConvertToPx() + MOUSE_WIDTH.ConvertToPx()); + EXPECT_EQ(position.GetY(), DEVICE_HEIGHT - layoutAlgorithm->marginBottom_ - childSize.Height()); + + layoutAlgorithm->isHalfFoldHover_ = true; + position = layoutAlgorithm->GetPositionWithPlacementRightTop(childSize, topPosition, bottomPosition, arrowPosition); + EXPECT_EQ(position.GetX(), TIPS_MARGIN_SPACE.ConvertToPx() + MOUSE_WIDTH.ConvertToPx()); + EXPECT_EQ(position.GetY(), layoutAlgorithm->wrapperRect_.Bottom() - childSize.Height()); } /**