diff options
| -rw-r--r-- | src/layout/engine.nim | 11 | ||||
| -rw-r--r-- | src/layout/renderdocument.nim | 33 | ||||
| -rw-r--r-- | test/layout/absolute-container-indefinite-height.expected | 34 | ||||
| -rw-r--r-- | test/layout/absolute-container-indefinite-height.html | 37 |
4 files changed, 97 insertions, 18 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 68685f11..8cd94c7d 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -1572,19 +1572,16 @@ proc layoutRootInline(bctx: var BlockContext; root: RootInlineFragment; proc positionAbsolute(lctx: LayoutContext; box: BlockBox; margin: RelativeRect) = - let last = lctx.positioned[^1] - let parentWidth = applySizeConstraint(lctx.attrs.width_px, last.w) - let parentHeight = applySizeConstraint(lctx.attrs.height_px, last.h) if not box.computed{"left"}.auto: box.state.offset.x = box.state.positioned.left + margin.left elif not box.computed{"right"}.auto: - box.state.offset.x = parentWidth - box.state.positioned.right - - box.state.size.w - margin.right + box.state.offset.x = -box.state.positioned.right - box.state.size.w - + margin.right if not box.computed{"top"}.auto: box.state.offset.y = box.state.positioned.top + margin.top elif not box.computed{"bottom"}.auto: - box.state.offset.y = parentHeight - box.state.positioned.bottom - - box.state.size.h - margin.bottom + box.state.offset.y = -box.state.positioned.bottom - box.state.size.h - + margin.bottom proc positionRelative(parent, box: BlockBox) = if not box.computed{"left"}.auto: diff --git a/src/layout/renderdocument.nim b/src/layout/renderdocument.nim index de324f37..939e9035 100644 --- a/src/layout/renderdocument.nim +++ b/src/layout/renderdocument.nim @@ -237,10 +237,14 @@ type height*: int bmp*: Bitmap + AbsolutePos = object + offset: Offset + size: Size + RenderState = object # Position of the absolute positioning containing block: # https://drafts.csswg.org/css-position/#absolute-positioning-containing-block - absolutePos: seq[Offset] + absolutePos: seq[AbsolutePos] bgcolor: CellColor attrsp: ptr WindowAttributes images: seq[PosBitmap] @@ -402,7 +406,10 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState; if fragment.computed{"position"} != PositionStatic: if fragment.splitType != {stSplitStart, stSplitEnd}: if stSplitStart in fragment.splitType: - state.absolutePos.add(offset + fragment.state.startOffset) + state.absolutePos.add(AbsolutePos( + offset: offset + fragment.state.startOffset, + # looks like it's OK to set size to 0 here + )) if stSplitEnd in fragment.splitType: discard state.absolutePos.pop() @@ -424,13 +431,20 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState; discard state.absolutePos.pop() continue if box.computed{"position"} == PositionAbsolute: - if not box.computed{"left"}.auto or not box.computed{"right"}.auto: - offset.x = state.absolutePos[^1].x - if not box.computed{"top"}.auto or not box.computed{"bottom"}.auto: - offset.y = state.absolutePos[^1].y + if not box.computed{"left"}.auto: + offset.x = state.absolutePos[^1].offset.x + elif not box.computed{"right"}.auto: + offset.x = state.absolutePos[^1].offset.x + state.absolutePos[^1].size.w + if not box.computed{"top"}.auto: + offset.y = state.absolutePos[^1].offset.y + elif not box.computed{"bottom"}.auto: + offset.y = state.absolutePos[^1].offset.y + state.absolutePos[^1].size.h offset += box.state.offset if box.computed{"position"} != PositionStatic: - state.absolutePos.add(offset) + state.absolutePos.add(AbsolutePos( + offset: offset, + size: box.state.size + )) stack.add((nil, offset(-1, -1))) if box.computed{"visibility"} == VisibilityVisible: let bgcolor = box.computed{"background-color"} @@ -475,10 +489,7 @@ proc renderDocument*(grid: var FlexibleGrid; bgcolor: var CellColor; if styledRoot == nil: # no HTML element when we run cascade; just clear all lines. return - var state = RenderState( - absolutePos: @[offset(0, 0)], - attrsp: attrsp - ) + var state = RenderState(absolutePos: @[AbsolutePos()], attrsp: attrsp) let rootBox = styledRoot.layout(attrsp) grid.renderBlockBox(state, rootBox, offset(0, 0)) if grid.len == 0: diff --git a/test/layout/absolute-container-indefinite-height.expected b/test/layout/absolute-container-indefinite-height.expected new file mode 100644 index 00000000..de5dab5e --- /dev/null +++ b/test/layout/absolute-container-indefinite-height.expected @@ -0,0 +1,34 @@ + + +outer 1 +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +bottom 21 + + +outer 2 +bottom 43 diff --git a/test/layout/absolute-container-indefinite-height.html b/test/layout/absolute-container-indefinite-height.html new file mode 100644 index 00000000..eb6fe811 --- /dev/null +++ b/test/layout/absolute-container-indefinite-height.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<pre style="position: relative"> +<div style="position: absolute; bottom: 0">bottom .1</div> +outer 1 +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +. +<div style="position: absolute; bottom: 0">bottom 2</div> +</pre> +<pre style="position: relative"> +<div style="position: absolute; bottom: 0">bottom .3</div> +outer 2 +<div style="position: absolute; bottom: 0">bottom 4</div> +</pre> |