about summary refs log tree commit diff stats
path: root/src/css/values.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-22 18:53:03 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-22 18:53:03 +0100
commit9e04a6cca10fe934ae6ad101c2f35d18a7d712b2 (patch)
tree3eafce3a25f80e2a5f83e860e1b8310b8d6bc658 /src/css/values.nim
parent7b06c22d8f24de727ce5b62b4d7fd8cd4007123d (diff)
downloadchawan-9e04a6cca10fe934ae6ad101c2f35d18a7d712b2.tar.gz
Fix media query bug, do not refresh page without css change (wip)
Diffstat (limited to 'src/css/values.nim')
-rw-r--r--src/css/values.nim26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/css/values.nim b/src/css/values.nim
index e064e909..7da9a248 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -691,7 +691,8 @@ func getSpecifiedValue(d: CSSDeclaration, parent: CSSSpecifiedValues): tuple[a:C
 
   return (val, cssGlobal(d))
 
-proc applyValue(vals, parent: CSSSpecifiedValues, t: CSSPropertyType, val: CSSSpecifiedValue, global: CSSGlobalValueType) =
+proc applyValue(vals, parent: CSSSpecifiedValues, t: CSSPropertyType, val: CSSSpecifiedValue, global: CSSGlobalValueType): bool =
+  let oval = vals[t]
   case global
   of VALUE_INHERIT, VALUE_UNSET:
     if inherited(t):
@@ -704,36 +705,39 @@ proc applyValue(vals, parent: CSSSpecifiedValues, t: CSSPropertyType, val: CSSSp
     vals[t] = getDefault(t) #TODO
   of VALUE_NOGLOBAL:
     vals[t] = val
+  return oval != vals[t]
 
-proc applyShorthand(vals, parent: CSSSpecifiedValues, left, right, top, bottom: CSSSpecifiedValue, global: CSSGlobalValueType) =
-  vals.applyValue(parent, left.t, left, global)
-  vals.applyValue(parent, right.t, right, global)
-  vals.applyValue(parent, top.t, top, global)
-  vals.applyValue(parent, bottom.t, bottom, global)
+proc applyShorthand(vals, parent: CSSSpecifiedValues, left, right, top, bottom: CSSSpecifiedValue, global: CSSGlobalValueType): bool =
+  result = result or vals.applyValue(parent, left.t, left, global)
+  result = result or vals.applyValue(parent, right.t, right, global)
+  result = result or vals.applyValue(parent, top.t, top, global)
+  result = result or vals.applyValue(parent, bottom.t, bottom, global)
 
-proc applyValue*(vals, parent: CSSSpecifiedValues, d: CSSDeclaration) =
+# Returns true if anything has changed. (TODO: not always...)
+proc applyValue*(vals, parent: CSSSpecifiedValues, d: CSSDeclaration): bool =
   let vv = getSpecifiedValue(d, parent)
   let val = vv.a
+  let oval = vals[val.t]
   case val.t
   of PROPERTY_ALL:
     let global = cssGlobal(d)
     if global != VALUE_NOGLOBAL:
       for t in CSSPropertyType:
-        vals.applyValue(parent, t, nil, global)
+        result = result or vals.applyValue(parent, t, nil, global)
   of PROPERTY_MARGIN:
     let left = CSSSpecifiedValue(t: PROPERTY_MARGIN_LEFT, v: VALUE_LENGTH, length: val.length)
     let right = CSSSpecifiedValue(t: PROPERTY_MARGIN_RIGHT, v: VALUE_LENGTH, length: val.length)
     let top = CSSSpecifiedValue(t: PROPERTY_MARGIN_TOP, v: VALUE_LENGTH, length: val.length)
     let bottom = CSSSpecifiedValue(t: PROPERTY_MARGIN_BOTTOM, v: VALUE_LENGTH, length: val.length)
-    vals.applyShorthand(parent, left, right, top, bottom, vv.b)
+    return vals.applyShorthand(parent, left, right, top, bottom, vv.b)
   of PROPERTY_PADDING:
     let left = CSSSpecifiedValue(t: PROPERTY_PADDING_LEFT, v: VALUE_LENGTH, length: val.length)
     let right = CSSSpecifiedValue(t: PROPERTY_PADDING_RIGHT, v: VALUE_LENGTH, length: val.length)
     let top = CSSSpecifiedValue(t: PROPERTY_PADDING_TOP, v: VALUE_LENGTH, length: val.length)
     let bottom = CSSSpecifiedValue(t: PROPERTY_PADDING_BOTTOM, v: VALUE_LENGTH, length: val.length)
-    vals.applyShorthand(parent, left, right, top, bottom, vv.b)
+    return vals.applyShorthand(parent, left, right, top, bottom, vv.b)
   else:
-    vals.applyValue(parent, val.t, vv.a, vv.b)
+    return vals.applyValue(parent, val.t, vv.a, vv.b)
 
 func inheritProperties*(parent: CSSSpecifiedValues): CSSSpecifiedValues =
   new(result)