about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-01-08 16:00:26 +0100
committerbptato <nincsnevem662@gmail.com>2023-01-08 16:19:17 +0100
commit4e40c70ebc19807a0bd121b2376ff147adae765c (patch)
treece6fcab0bc9c35d42cf69141725adcf2cd60c20f /src/css
parent7bed16fa67df23f1bd1156e709a4b959b274b2ca (diff)
downloadchawan-4e40c70ebc19807a0bd121b2376ff147adae765c.tar.gz
css/cascade, layout/engine: add table align
Also fix margin-left/right: auto, to some extent.
Diffstat (limited to 'src/css')
-rw-r--r--src/css/cascade.nim10
-rw-r--r--src/css/values.nim12
2 files changed, 17 insertions, 5 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index c7d6dfd0..0cea87b7 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -109,6 +109,15 @@ func calcPresentationalHints(element: Element): CSSComputedValues =
     of "center", "middle": set_cv "text-align", TEXT_ALIGN_CHA_CENTER
     of "left": set_cv "text-align", TEXT_ALIGN_CHA_LEFT
     of "right": set_cv "text-align", TEXT_ALIGN_CHA_RIGHT
+  template map_table_align =
+    case element.attr("align").toLowerAscii()
+    of "left":
+     set_cv "margin-right", CSSLengthAuto #TODO should be float: left
+    of "right":
+      set_cv "margin-left", CSSLengthAuto #TODO should be float: right
+    of "center":
+      set_cv "margin-left", CSSLengthAuto #TODO should be inline-start
+      set_cv "margin-right", CSSLengthAuto #TODO should be inline-end
   template map_text =
     let c = parseLegacyColor(element.attr("text"))
     if c.isSome:
@@ -137,6 +146,7 @@ func calcPresentationalHints(element: Element): CSSComputedValues =
     map_height_nozero
     map_width_nozero
     map_bgcolor
+    map_table_align
   of TAG_TD, TAG_TH:
     map_height_nozero
     map_width_nozero
diff --git a/src/css/values.nim b/src/css/values.nim
index 5916bc89..82cc9419 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -446,6 +446,8 @@ func cssLength(val: float64, unit: string): CSSLength =
   else:
     raise newException(CSSValueError, "Invalid unit")
 
+const CSSLengthAuto* = CSSLength(auto: true)
+
 func parseDimensionValues*(s: string): Option[CSSLength] =
   if s == "": return
   var i = 0
@@ -560,7 +562,7 @@ func cssLength(val: CSSComponentValue, has_auto: static bool = true, allow_negat
       of CSS_IDENT_TOKEN:
         when has_auto:
           if tok.value == "auto":
-            return CSSLength(auto: true)
+            return CSSLengthAuto
       else: discard
   raise newException(CSSValueError, "Invalid length")
 
@@ -585,7 +587,7 @@ func cssWordSpacing(cval: CSSComponentValue): CSSLength =
       return cssLength(tok.nvalue, tok.unit)
     of CSS_IDENT_TOKEN:
       if tok.value == "normal":
-        return CSSLength(auto: true)
+        return CSSLengthAuto
     else: discard
   raise newException(CSSValueError, "Invalid word spacing")
 
@@ -772,7 +774,7 @@ func cssLineHeight(cval: CSSComponentValue): CSSLength =
       return cssLength(tok.nvalue * 100, "%")
     of CSS_IDENT_TOKEN:
       if tok.value == "normal":
-        return CSSLength(auto: true)
+        return CSSLengthAuto
     else:
       return cssLength(tok, has_auto = false)
   raise newException(CSSValueError, "Invalid line height")
@@ -867,7 +869,7 @@ func cssMaxMinSize(cval: CSSComponentValue): CSSLength =
     case tok.tokenType
     of CSS_IDENT_TOKEN:
       if tok.value == "none":
-        return CSSLength(auto: true)
+        return CSSLengthAuto
     of CSS_NUMBER_TOKEN, CSS_DIMENSION_TOKEN:
       return cssLength(tok, allow_negative = false)
     else: discard
@@ -986,7 +988,7 @@ func getInitialLength(t: CSSPropertyType): CSSLength =
      PROPERTY_LINE_HEIGHT, PROPERTY_LEFT, PROPERTY_RIGHT, PROPERTY_TOP,
      PROPERTY_BOTTOM, PROPERTY_MAX_WIDTH, PROPERTY_MAX_HEIGHT,
      PROPERTY_MIN_WIDTH, PROPERTY_MIN_HEIGHT:
-    return CSSLength(auto: true)
+    return CSSLengthAuto
   else:
     return CSSLength(auto: false, unit: UNIT_PX, num: 0)