paintOverflow method
void
paintOverflow(
- PaintingContext context,
- Offset offset,
- EdgeInsets borderEdge,
- CSSBoxDecoration? decoration,
- PaintingContextCallback callback,
Implementation
void paintOverflow(
PaintingContext context,
Offset offset,
EdgeInsets borderEdge,
CSSBoxDecoration? decoration,
PaintingContextCallback callback
) {
if (clipX == false && clipY == false) return callback(context, offset);
final double paintOffsetX = _paintOffsetX;
final double paintOffsetY = _paintOffsetY;
final Offset paintOffset = Offset(paintOffsetX, paintOffsetY);
// Overflow should not cover border.
Rect clipRect = Offset(borderEdge.left, borderEdge.top) & Size(
size.width - borderEdge.right - borderEdge.left,
size.height - borderEdge.bottom - borderEdge.top,
);
if (_shouldClipAtPaintOffset(paintOffset, size)) {
// ignore: prefer_function_declarations_over_variables
PaintingContextCallback painter = (PaintingContext context, Offset offset) {
callback(context, offset + paintOffset);
};
// If current or its descendants has a compositing layer caused by styles
// (eg. transform, opacity, overflow...), then it needs to create a new layer
// or else the clip in the older layer will not work.
bool _needsCompositing = needsCompositing;
if (decoration != null && decoration.hasBorderRadius) {
BorderRadius radius = decoration.borderRadius!;
Rect rect = Offset.zero & size;
RRect borderRRect = radius.toRRect(rect);
// A borderRadius can only be given for a uniform Border in Flutter.
// https://github.com/flutter/flutter/issues/12583
double? borderTop = renderStyle.borderTopWidth?.computedValue;
// The content of overflow is trimmed to the padding edge curve.
// https://www.w3.org/TR/css-backgrounds-3/#corner-clipping
RRect clipRRect = borderTop != null
? borderRRect.deflate(borderTop)
: borderRRect;
// The content of replaced elements is trimmed to the content edge curve.
if (this is RenderReplaced) {
// @TODO: Currently only support clip uniform padding for replaced element.
double paddingTop = renderStyle.paddingTop.computedValue;
clipRRect = clipRRect.deflate(paddingTop);
}
_clipRRectLayer.layer = context.pushClipRRect(_needsCompositing, offset, clipRect, clipRRect, painter, oldLayer: _clipRRectLayer.layer);
} else {
_clipRectLayer.layer = context.pushClipRect(_needsCompositing, offset, clipRect, painter, oldLayer: _clipRectLayer.layer);
}
} else {
_clipRectLayer.layer = null;
_clipRRectLayer.layer = null;
callback(context, offset);
}
}