From aac86e5e1e714c03930ce40acd65433449289caf Mon Sep 17 00:00:00 2001 From: Caleb Hearon Date: Tue, 16 Jul 2024 14:56:30 -0400 Subject: [PATCH] add Box.isPaintRoot the change to paintInlinesAndDescendents is non-consequential since it doesn't descend into inlines and so cannot encounter floats, but it's more readable --- src/layout-box.ts | 4 ++++ src/paint.ts | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/layout-box.ts b/src/layout-box.ts index c6814a5..aacb049 100644 --- a/src/layout-box.ts +++ b/src/layout-box.ts @@ -123,6 +123,10 @@ export class Box extends RenderItem { return this.isPositioned() && this.style.zIndex !== 'auto'; } + isPaintRoot(): boolean { + return this.isBlockContainer() && this.isFloat() || this.isPositioned(); + } + getRelativeVerticalShift() { const height = this.containingBlock.height; let {top, bottom} = this.style; diff --git a/src/paint.ts b/src/paint.ts index 3736a32..1ca5ef9 100644 --- a/src/paint.ts +++ b/src/paint.ts @@ -160,13 +160,7 @@ function paintBackgroundDescendents(root: BlockContainer | Inline, b: PaintBacke } for (let i = block.children.length - 1; i >= 0; i--) { const child = block.children[i]; - if ( - child.isBox() && - !child.isPositioned() && - !(child.isBlockContainer() && child.isFloat()) - ) { - stack.push(child); - } + if (child.isBox() && !child.isPaintRoot()) stack.push(child); } } } @@ -313,7 +307,7 @@ function paintInlinesAndDescendents(block: BlockContainer, b: PaintBackend) { if (box.isBlockContainer()) { for (let i = box.children.length - 1; i >= 0; i--) { const child = box.children[i]; - if (!child.isPositioned()) stack.push(child); + if (!child.isPaintRoot()) stack.push(child); } } else { paintInlines(box, b);