diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/css/values.nim | 13 | ||||
-rw-r--r-- | src/layout/box.nim | 1 | ||||
-rw-r--r-- | src/layout/engine.nim | 16 |
3 files changed, 24 insertions, 6 deletions
diff --git a/src/css/values.nim b/src/css/values.nim index 46c49ef5..4d3c2110 100644 --- a/src/css/values.nim +++ b/src/css/values.nim @@ -187,6 +187,14 @@ macro `{}`*(vals: CSSSpecifiedValues, s: string): untyped = let s = vs.split(Rune('_'))[1..^1].join("_").tolower() result = newDotExpr(newTree(nnkBracketExpr, vals, newLit(t)), newIdentNode(s)) +macro `{}=`*(vals: CSSSpecifiedValues, s: string, v: typed): untyped = + let t = propertyType($s) + let vs = $valueType(t) + let s = vs.split(Rune('_'))[1..^1].join("_").tolower() + let expr = newDotExpr(newTree(nnkBracketExpr, vals, newLit(t)), newIdentNode(s)) + result = quote do: + `expr` = `v` + func inherited(t: CSSPropertyType): bool = return InheritedArray[t] @@ -735,6 +743,11 @@ func inheritProperties*(parent: CSSSpecifiedValues): CSSSpecifiedValues = else: result[prop] = getDefault(prop) +func copyProperties*(parent: CSSSpecifiedValues): CSSSpecifiedValues = + new(result) + for prop in CSSPropertyType: + result[prop] = parent[prop] + func rootProperties*(): CSSSpecifiedValues = new(result) for prop in CSSPropertyType: diff --git a/src/layout/box.nim b/src/layout/box.nim index acbacd52..c92db003 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -83,4 +83,3 @@ type InlineBlockBox* = ref object of BlockBox ictx*: InlineContext ListItemBox* = ref object of CSSBox - diff --git a/src/layout/engine.nim b/src/layout/engine.nim index afd66c72..d881924b 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -759,6 +759,13 @@ proc getBox(specified: CSSSpecifiedValues): CSSBox = result.t = specified{"display"} result.specified = specified +# Returns a block box, disregarding the specified value +proc getBlockBox(specified: CSSSpecifiedValues): BlockBox = + new(result) + result.t = DISPLAY_BLOCK + result.specified = specified.copyProperties() + result.specified{"display"} = DISPLAY_BLOCK + proc getTextBox(box: CSSBox): InlineBox = new(result) result.inlinelayout = true @@ -767,6 +774,7 @@ proc getTextBox(box: CSSBox): InlineBox = proc getPseudoBox(specified: CSSSpecifiedValues): CSSBox = let box = getBox(specified) + if box == nil: return nil box.inlinelayout = true @@ -776,9 +784,7 @@ proc getPseudoBox(specified: CSSSpecifiedValues): CSSBox = box.children.add(content) return box -proc generateBox(elem: Element): CSSBox = - let box = getBox(elem.css) - +proc generateBox(elem: Element, box = getBox(elem.css)): CSSBox = if box == nil: return nil @@ -829,9 +835,9 @@ proc generateBox(elem: Element): CSSBox = return box proc generateBoxes(document: Document): BlockBox = - let box = document.root.generateBox() + let box = document.root.generateBox(getBlockBox(document.root.css)) assert box != nil - assert box.t == DISPLAY_BLOCK #TODO this shouldn't be enforced by the ua stylesheet + assert box.t == DISPLAY_BLOCK return BlockBox(box) |