!45119 修复:内容裁剪区域Offset

Merge pull request !45119 from 周沺耳/dev
This commit is contained in:
openharmony_ci 2024-10-08 09:55:26 +00:00 committed by Gitee
commit 2f447ab369
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 80 additions and 21 deletions

View File

@ -20,6 +20,7 @@
#include "core/components_ng/pattern/scroll/inner/scroll_bar.h"
#include "core/components_ng/pattern/scroll/scroll_edge_effect.h"
#include "core/components_ng/pattern/scrollable/scrollable_paint_method.h"
#include "core/components_ng/pattern/scrollable/scrollable_paint_property.h"
namespace OHOS::Ace::NG {
class ACE_EXPORT GridPaintMethod : public ScrollablePaintMethod {
@ -64,9 +65,9 @@ public:
}
private:
void ApplyDefaultContentClip(const RefPtr<RenderContext>& ctx, const RefPtr<GeometryNode>& geometryNode) override
ContentClipMode GetDefaultContentClip() const override
{
ctx->SetContentClip(geometryNode->GetFrameRect());
return ContentClipMode::BOUNDARY;
}
RefPtr<GridContentModifier> gridContentModifier_;

View File

@ -124,9 +124,9 @@ public:
void UpdateOverlayModifier(PaintWrapper* paintWrapper) override;
private:
void ApplyDefaultContentClip(const RefPtr<RenderContext>& ctx, const RefPtr<GeometryNode>& geometryNode) override
ContentClipMode GetDefaultContentClip() const override
{
ctx->SetContentClip(geometryNode->GetPaddingRect());
return ContentClipMode::CONTENT_ONLY;
}
V2::ItemDivider divider_;

View File

@ -68,9 +68,9 @@ public:
}
private:
void ApplyDefaultContentClip(const RefPtr<RenderContext>& ctx, const RefPtr<GeometryNode>& geometryNode) override
ContentClipMode GetDefaultContentClip() const override
{
ctx->SetContentClip(geometryNode->GetFrameRect());
return ContentClipMode::BOUNDARY;
}
RefPtr<ScrollContentModifier> scrollContentModifier_;

View File

@ -78,22 +78,34 @@ bool ScrollablePaintMethod::TryContentClip(PaintWrapper* wrapper)
auto renderContext = wrapper->GetRenderContext();
renderContext->SetClipToFrame(false);
renderContext->SetClipToBounds(false);
switch (clip->first) {
auto mode = clip->first;
if (mode == ContentClipMode::DEFAULT) {
mode = GetDefaultContentClip();
}
auto&& geo = wrapper->GetGeometryNode();
switch (mode) {
case ContentClipMode::CUSTOM:
renderContext->SetContentClip(clip->second);
break;
case ContentClipMode::CONTENT_ONLY:
renderContext->SetContentClip(wrapper->GetGeometryNode()->GetPaddingRect());
case ContentClipMode::CONTENT_ONLY: {
auto rect = geo->GetPaddingRect();
rect.SetOffset(rect.GetOffset() - geo->GetFrameOffset());
renderContext->SetContentClip(rect);
break;
case ContentClipMode::SAFE_AREA:
renderContext->SetContentClip(wrapper->GetGeometryNode()->GetPaddingRect(true));
}
case ContentClipMode::SAFE_AREA: {
auto rect = geo->GetPaddingRect(true);
rect.SetOffset(rect.GetOffset() - geo->GetFrameOffset());
renderContext->SetContentClip(rect);
break;
case ContentClipMode::BOUNDARY:
renderContext->SetContentClip(wrapper->GetGeometryNode()->GetFrameRect());
break;
case ContentClipMode::DEFAULT:
ApplyDefaultContentClip(renderContext, wrapper->GetGeometryNode());
}
case ContentClipMode::BOUNDARY: {
auto rect = geo->GetFrameRect();
rect.SetOffset({ 0.0f, 0.0f });
renderContext->SetContentClip(rect);
break;
}
default:
break;
}

View File

@ -16,6 +16,7 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_PAINT_METHOD_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_PAINT_METHOD_H
#include "core/components_ng/pattern/scrollable/scrollable_paint_property.h"
#include "core/components_ng/render/node_paint_method.h"
namespace OHOS::Ace::NG {
@ -59,10 +60,9 @@ protected:
private:
/**
* @brief Apply Scrollable's default content clip area
* @brief Return the default content clip mode.
*/
virtual void ApplyDefaultContentClip(
const RefPtr<RenderContext>& ctx, const RefPtr<GeometryNode>& geometryNode) = 0;
virtual ContentClipMode GetDefaultContentClip() const = 0;
RefPtr<RenderContext> overlayRenderContext_;
bool isFadingTop_ = false;

View File

@ -70,9 +70,9 @@ public:
void UpdateOverlayModifier(PaintWrapper* paintWrapper) override;
private:
void ApplyDefaultContentClip(const RefPtr<RenderContext>& ctx, const RefPtr<GeometryNode>& geometryNode) override
ContentClipMode GetDefaultContentClip() const override
{
ctx->SetContentClip(geometryNode->GetPaddingRect());
return ContentClipMode::CONTENT_ONLY;
}
RefPtr<WaterFlowContentModifier> contentModifier_;

View File

@ -301,6 +301,7 @@ public:
virtual void UpdateWindowFocusState(bool isFocused) {}
/**
* @brief Only clip the content & foreground layer by @c rect.
* @param rect - offset of @c rect is relative to FrameRect.
*/
virtual void SetContentClip(const std::variant<RectF, RefPtr<ShapeRect>>& rect) {}

View File

@ -56,4 +56,49 @@ HWTEST_F(WaterFlowTestNg, Clip001, TestSize.Level1)
props->UpdateContentClip({ ContentClipMode::BOUNDARY, nullptr });
FlushLayoutTask(frameNode_);
}
/**
* @tc.name: Clip002
* @tc.desc: Test contentClip with relative offset.
* @tc.type: FUNC
*/
HWTEST_F(WaterFlowTestNg, Clip002, TestSize.Level1)
{
RefPtr<UINode> col;
CreateColumn([&](ColumnModelNG colModel) {
ViewAbstract::SetMargin(CalcLength(5.0f));
col = ViewStackProcessor::GetInstance()->GetMainElementNode();
WaterFlowModelNG model = CreateWaterFlow();
ViewAbstract::SetMargin(CalcLength(5.0f));
ViewAbstract::SetPadding(CalcLength(5.0f));
model.SetColumnsTemplate("1fr 1fr 1fr");
CreateWaterFlowItems();
CreateDone();
});
ASSERT_TRUE(col);
auto ctx = AceType::DynamicCast<MockRenderContext>(frameNode_->GetRenderContext());
ASSERT_TRUE(ctx);
auto props = frameNode_->GetPaintProperty<ScrollablePaintProperty>();
auto rect = AceType::MakeRefPtr<ShapeRect>();
rect->SetWidth(Dimension(200.0f));
rect->SetHeight(Dimension(200.0f));
EXPECT_CALL(*ctx, SetContentClip(ClipRectEq(rect))).Times(1);
props->UpdateContentClip({ ContentClipMode::CUSTOM, rect });
FlushLayoutTask(frameNode_);
EXPECT_EQ(frameNode_->GetGeometryNode()->GetPaddingSize(true), SizeF(470.0f, 790.0f));
auto rect1 = frameNode_->GetGeometryNode()->GetPaddingRect();
rect1.SetOffset(OffsetF(5.0f, 5.0f)); // padding offset
EXPECT_CALL(*ctx, SetContentClip(ClipRectEq(rect1))).Times(1);
props->UpdateContentClip({ ContentClipMode::CONTENT_ONLY, nullptr });
FlushLayoutTask(frameNode_);
auto rect2 = frameNode_->GetGeometryNode()->GetFrameRect();
rect2.SetOffset(OffsetF(0.0f, 0.0f));
EXPECT_CALL(*ctx, SetContentClip(ClipRectEq(rect2))).Times(1);
props->UpdateContentClip({ ContentClipMode::BOUNDARY, nullptr });
FlushLayoutTask(frameNode_);
}
} // namespace OHOS::Ace::NG