mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
commit
2f447ab369
@ -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_;
|
||||
|
@ -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_;
|
||||
|
@ -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_;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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_;
|
||||
|
@ -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) {}
|
||||
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user