diff options
-rw-r--r-- | src/layout/box.nim | 25 | ||||
-rw-r--r-- | src/layout/engine.nim | 23 | ||||
-rw-r--r-- | src/render/renderdocument.nim | 8 |
3 files changed, 15 insertions, 41 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim index b22a388a..913fa705 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -5,20 +5,10 @@ import html/dom import io/term type - OffsetType* = enum - OFFSET_BLOCK_CONTEXT - -type - Position = object + Offset* = object x*: int y*: int - Offset* = ref object - case t*: OffsetType - of OFFSET_BLOCK_CONTEXT: - rel*: Position - prev_sibling*: Offset - Viewport* = ref object term*: TermAttributes root*: BlockBoxBuilder @@ -75,8 +65,7 @@ type lineheight*: int #line-height property InlineContext* = ref object - relx*: int - rely*: int + offset*: Offset height*: int rows*: seq[InlineRow] thisrow*: InlineRow @@ -115,13 +104,3 @@ type # outside*: bool #ListItemBox* = ref object of BlockBox - -func absx*(offset: Offset): int {.inline.} = - offset.rel.x - -#TODO cache -func absy*(offset: Offset): int {.inline.} = - if offset.prev_sibling != nil: - offset.prev_sibling.absy + offset.rel.y - else: - offset.rel.y diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 2144ac84..7d622076 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -316,9 +316,6 @@ proc newBlockContext_common(parent: BlockContext, box: BoxBuilder): BlockContext proc newBlockContext(parent: BlockContext, box: BlockBoxBuilder): BlockContext = result = newBlockContext_common(parent, box) - result.offset = Offset(t: OFFSET_BLOCK_CONTEXT) - if parent.nested.len > 0: - result.offset.prev_sibling = parent.nested[^1].offset result.shrink = result.specified{"width"}.auto and parent.shrink proc newInlineBlockContext(parent: BlockContext, box: InlineBlockBoxBuilder): BlockContext = @@ -334,7 +331,6 @@ proc newBlockContext(parent: BlockContext): BlockContext = new(result) result.specified = parent.specified.inheritProperties() result.viewport = parent.viewport - result.offset = Offset(t: OFFSET_BLOCK_CONTEXT) result.computedDimensions(parent.compwidth, parent.compheight) result.shrink = result.specified{"width"}.auto and parent.shrink @@ -343,7 +339,6 @@ proc newBlockContext(viewport: Viewport): BlockContext = new(result) result.specified = rootProperties() result.viewport = viewport - result.offset = Offset(t: OFFSET_BLOCK_CONTEXT) result.computedDimensions(viewport.term.width_px, none(int)) proc newInlineContext(bctx: BlockContext): InlineContext = @@ -368,10 +363,10 @@ proc positionBlocks(bctx: BlockContext, selfcontained: bool) = x += bctx.compwidth div 2 template apply_child(child: BlockContext) = - child.offset.rel.y = y - child.offset.rel.x = x + child.margin_left + child.offset.y = y + child.offset.x = x + child.margin_left if bctx.specified{"text-align"} == TEXT_ALIGN_MOZ_CENTER: - child.offset.rel.x -= child.width div 2 + child.offset.x -= child.width div 2 y += child.height bctx.height += child.height bctx.width = max(bctx.width, child.width) @@ -426,15 +421,15 @@ proc positionInlines(bctx: BlockContext, selfcontained: bool) = bctx.margin_bottom = bctx.specified{"margin-bottom"}.px(bctx.viewport, bctx.compwidth) bctx.width += bctx.padding_left - bctx.inline.relx += bctx.padding_left + bctx.inline.offset.x += bctx.padding_left if selfcontained: - bctx.inline.rely += bctx.margin_top + bctx.inline.offset.x += bctx.margin_top bctx.height += bctx.margin_top bctx.height += bctx.margin_bottom bctx.height += bctx.padding_top - bctx.inline.rely += bctx.padding_top + bctx.inline.offset.x += bctx.padding_top bctx.height += bctx.padding_bottom @@ -642,9 +637,9 @@ template flush_ibox() = template generate_from_elem(child: Element) = if child.tagType == TAG_BR: - flush_ibox ibox = box.getTextBox() ibox.newline = true + flush_ibox case child.css{"display"} of DISPLAY_BLOCK, DISPLAY_LIST_ITEM: @@ -653,7 +648,6 @@ template generate_from_elem(child: Element) = box.children.add(childbox) of DISPLAY_INLINE: flush_ibox - box.generateInlineBoxes(child, blockgroup, viewport) of DISPLAY_INLINE_BLOCK: flush_ibox @@ -762,6 +756,7 @@ proc generateBlockBox(elem: Element, viewport: Viewport): BlockBoxBuilder = for child in elem.childNodes: case child.nodeType of ELEMENT_NODE: + flush_ibox let child = Element(child) generate_from_elem(child) of TEXT_NODE: @@ -783,5 +778,5 @@ proc generateBoxBuilders(elem: Element, viewport: Viewport): BlockBoxBuilder = return generateBlockBox(elem, viewport) proc renderLayout*(viewport: var Viewport, document: Document) = - viewport.root = document.root.generateBlockBox(viewport) + viewport.root = document.root.generateBoxBuilders(viewport) viewport.root.bctx = buildBlock(viewport.root, viewport) diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim index 798709c4..3dc72c38 100644 --- a/src/render/renderdocument.nim +++ b/src/render/renderdocument.nim @@ -205,8 +205,8 @@ proc paintBackground(lines: var FlexibleGrid, color: CSSColor, startx, starty, e proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int, term: TermAttributes) proc renderInlineContext(grid: var FlexibleGrid, ctx: InlineContext, x, y: int, term: TermAttributes) = - let x = x + ctx.relx - let y = y + ctx.rely + let x = x + ctx.offset.x + let y = y + ctx.offset.y for row in ctx.rows: let x = x + row.relx let y = y + row.rely @@ -232,8 +232,8 @@ proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int, te while stack.len > 0: var (ctx, x, y) = stack.pop() - x += ctx.offset.absx - y += ctx.offset.absy + x += ctx.offset.x + y += ctx.offset.y if ctx.specified{"background-color"}.rgba.a != 0: #TODO color blending grid.paintBackground(ctx.specified{"background-color"}, x, y, x + ctx.width, y + ctx.height, term) |