paintBackground method
Implementation
void paintBackground(Canvas canvas, Offset offset, ImageConfiguration configuration) {
assert(configuration.size != null);
Offset baseOffset = Offset.zero;
final TextDirection? textDirection = configuration.textDirection;
bool hasLocalAttachment = _hasLocalBackgroundImage();
// When background-clip: text is specified, the background should be applied
// to glyphs only (handled in InlineFormattingContext). Skip painting box
// background color/image here to avoid a solid rectangle behind the text.
if (renderStyle.backgroundClip == CSSBackgroundBoundary.text) {
return;
}
// Rects for color and image
Rect backgroundColorRect = _getBackgroundClipRect(baseOffset, configuration);
// Background image of background-attachment local scroll with content
Offset backgroundImageOffset = hasLocalAttachment ? offset : baseOffset;
// Rect of background image
Rect backgroundClipRect = _getBackgroundClipRect(backgroundImageOffset, configuration);
Rect backgroundOriginRect = _getBackgroundOriginRect(backgroundImageOffset, configuration);
Rect backgroundImageRect = backgroundClipRect.intersect(backgroundOriginRect);
if (DebugFlags.enableBackgroundLogs) {
final clip = renderStyle.backgroundClip;
final origin = renderStyle.backgroundOrigin;
final rep = renderStyle.backgroundRepeat;
renderingLogger.finer('[Background] container=${configuration.size} offset=$offset '
'clipRect=$backgroundClipRect originRect=$backgroundOriginRect imageRect=$backgroundImageRect '
'clip=${clip ?? CSSBackgroundBoundary.borderBox} origin=${origin ?? CSSBackgroundBoundary.paddingBox} '
'repeat=${rep.cssText()}');
}
final bool hasGradients = _hasGradientLayers();
final bool hasImages = _hasImageLayers();
if (hasGradients && hasImages) {
_paintLayeredMixedBackgrounds(canvas, backgroundClipRect, backgroundOriginRect, configuration, textDirection);
} else if (hasGradients) {
_paintBackgroundColor(canvas, backgroundColorRect, textDirection);
} else {
_paintBackgroundColor(canvas, backgroundColorRect, textDirection);
_paintBackgroundImage(canvas, backgroundClipRect, backgroundOriginRect, configuration);
}
}