aboutsummaryrefslogtreecommitdiffstats
path: root/src/css
diff options
context:
space:
mode:
Diffstat (limited to 'src/css')
-rw-r--r--src/css/cascade.nim5
-rw-r--r--src/css/cssvalues.nim107
2 files changed, 75 insertions, 37 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index 3a983a63..60d59a04 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -294,8 +294,9 @@ proc applyDeclarations(styledNode: StyledNode; parent: CSSValues;
rules[coUser].add(map.user[peNone])
for rule in map.author:
rules[coAuthor].add(rule[peNone])
+ var element: Element = nil
if styledNode.node != nil:
- let element = Element(styledNode.node)
+ element = Element(styledNode.node)
let style = element.cachedStyle
if window.styling and style != nil:
for decl in style.decls:
@@ -306,6 +307,8 @@ proc applyDeclarations(styledNode: StyledNode; parent: CSSValues;
rules[coAuthor].normal.add(vals)
presHints = element.calcPresHints(window.attrsp[])
styledNode.computed = rules.buildComputedValues(presHints, parent)
+ if element != nil and window.settings.scripting == smApp:
+ element.computed = styledNode.computed
func hasValues(rules: CSSValueEntryMap): bool =
for origin in CSSOrigin:
diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim
index 35487dfd..a88ae814 100644
--- a/src/css/cssvalues.nim
+++ b/src/css/cssvalues.nim
@@ -499,44 +499,79 @@ func valueType*(prop: CSSPropertyType): CSSValueType =
func isSupportedProperty*(s: string): bool =
return propertyType(s) != cptNone
-when defined(debug):
- func `$`*(length: CSSLength): string =
- if length.u == clAuto:
- return "auto"
- return $length.num & $length.u
-
- func `$`*(content: CSSContent): string =
- if content.s != "":
- return "url(" & content.s & ")"
- return "none"
-
- func `$`(quotes: CSSQuotes): string =
- if quotes.auto:
- return "auto"
- return "auto" #TODO
-
- func `$`(counterreset: seq[CSSCounterReset]): string =
- result = ""
- for it in counterreset:
- result &= $it.name
- result &= ' '
- result &= $it.num
+func `$`*(length: CSSLength): string =
+ if length.u == clAuto:
+ return "auto"
+ return $length.num & $length.u
+
+func `$`*(content: CSSContent): string =
+ if content.t == ContentImage:
+ #TODO
+ return ""
+ if content.s != "":
+ return "url(" & content.s & ")"
+ return "none"
+
+func `$`(quotes: CSSQuotes): string =
+ if quotes.auto:
+ return "auto"
+ return "auto" #TODO
+
+func `$`(counterreset: seq[CSSCounterReset]): string =
+ result = ""
+ for it in counterreset:
+ result &= $it.name
+ result &= ' '
+ result &= $it.num
+
+func serialize*(val: CSSValue): string =
+ case val.v
+ of cvtNone: return "none"
+ of cvtColor: return $val.color
+ of cvtImage: return $val.image
+ of cvtLength: return $val.length
+ of cvtInteger: return $val.integer
+ of cvtTextDecoration: return $val.textDecoration
+ of cvtVerticalAlign: return $val.verticalAlign
+ of cvtLength2: return $val.length2.a & " " & $val.length2.b
+ of cvtContent:
+ var s = ""
+ for x in val.content:
+ if s.len > 0:
+ s &= ' '
+ s &= $x
+ return s
+ of cvtQuotes: return $val.quotes
+ of cvtCounterReset: return $val.counterReset
+ of cvtNumber: return $val.number
+ else: assert false
+
+func serialize*(val: CSSValueBit; t: CSSValueType): string =
+ case t
+ of cvtDisplay: return $val.display
+ of cvtFontStyle: return $val.fontStyle
+ of cvtWhiteSpace: return $val.whiteSpace
+ of cvtWordBreak: return $val.wordBreak
+ of cvtListStyleType: return $val.listStyleType
+ of cvtTextAlign: return $val.textAlign
+ of cvtListStylePosition: return $val.listStylePosition
+ of cvtPosition: return $val.position
+ of cvtCaptionSide: return $val.captionSide
+ of cvtBorderCollapse: return $val.borderCollapse
+ of cvtFloat: return $val.float
+ of cvtVisibility: return $val.visibility
+ of cvtBoxSizing: return $val.boxSizing
+ of cvtClear: return $val.clear
+ of cvtTextTransform: return $val.textTransform
+ of cvtBgcolorIsCanvas: return $val.bgcolorIsCanvas
+ of cvtFlexDirection: return $val.flexDirection
+ of cvtFlexWrap: return $val.flexWrap
+ of cvtOverflow: return $val.overflow
+ else: assert false
+when defined(debug):
func `$`*(val: CSSValue): string =
- case val.v
- of cvtNone: return "none"
- of cvtColor: return $val.color
- of cvtImage: return $val.image
- of cvtLength: return $val.length
- of cvtInteger: return $val.integer
- of cvtTextDecoration: return $val.textDecoration
- of cvtVerticalAlign: return $val.verticalAlign
- of cvtLength2: return $val.length2.a & " " & $val.length2.b
- of cvtContent: return $val.content
- of cvtQuotes: return $val.quotes
- of cvtCounterReset: return $val.counterReset
- of cvtNumber: return $val.number
- else: assert false
+ return val.serialize()
macro `{}`*(vals: CSSValues; s: static string): untyped =
let t = propertyType(s)