about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-11 19:29:28 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-11 19:29:28 +0100
commitfca4ef9b8fabebb3a9173293908ee9b56acc9cc5 (patch)
treee8891433f9a5a3d80223670aa86d1cf53a3f12b0 /src
parentcea337a78c6dca00bf37e60b4b2792faf28aeffe (diff)
downloadchawan-fca4ef9b8fabebb3a9173293908ee9b56acc9cc5.tar.gz
Add div align
Diffstat (limited to 'src')
-rw-r--r--src/css/cascade.nim9
-rw-r--r--src/css/values.nim3
-rw-r--r--src/layout/engine.nim27
3 files changed, 29 insertions, 10 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index 6484d39e..cfcbd724 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -103,8 +103,15 @@ func calcPresentationalHints(element: Element): CSSComputedValues =
     of "middle": set_cv(PROPERTY_VERTICAL_ALIGN, verticalalign, CSSVerticalAlign(keyword: VERTICAL_ALIGN_MIDDLE))
     of "bottom": set_cv(PROPERTY_VERTICAL_ALIGN, verticalalign, CSSVerticalAlign(keyword: VERTICAL_ALIGN_BOTTOM))
     of "baseline": set_cv(PROPERTY_VERTICAL_ALIGN, verticalalign, CSSVerticalAlign(keyword: VERTICAL_ALIGN_BASELINE))
+  template map_align =
+    case element.attr("align").toLowerAscii()
+    of "center", "middle": set_cv(PROPERTY_TEXT_ALIGN, textalign, TEXT_ALIGN_CHA_CENTER)
+    of "left": set_cv(PROPERTY_TEXT_ALIGN, textalign, TEXT_ALIGN_CHA_LEFT)
+    of "right": set_cv(PROPERTY_TEXT_ALIGN, textalign, TEXT_ALIGN_CHA_RIGHT)
 
   case element.tagType
+  of TAG_DIV:
+    map_align
   of TAG_TABLE:
     map_height_nozero
     map_width_nozero
@@ -114,10 +121,12 @@ func calcPresentationalHints(element: Element): CSSComputedValues =
     map_width_nozero
     map_bgcolor
     map_valign
+    map_align
   of TAG_THEAD, TAG_TBODY, TAG_TFOOT, TAG_TR:
     map_height
     map_bgcolor
     map_valign
+    map_align
   of TAG_COL:
     map_width
   of TAG_BODY:
diff --git a/src/css/values.nim b/src/css/values.nim
index 49cb6b1b..5bf9c2d1 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -81,7 +81,8 @@ type
 
   CSSTextAlign* = enum
     TEXT_ALIGN_START, TEXT_ALIGN_END, TEXT_ALIGN_LEFT, TEXT_ALIGN_RIGHT,
-    TEXT_ALIGN_CENTER, TEXT_ALIGN_JUSTIFY, TEXT_ALIGN_CHA_CENTER
+    TEXT_ALIGN_CENTER, TEXT_ALIGN_JUSTIFY, TEXT_ALIGN_CHA_CENTER,
+    TEXT_ALIGN_CHA_LEFT, TEXT_ALIGN_CHA_RIGHT
 
   CSSListStylePosition* = enum
     LIST_STYLE_POSITION_OUTSIDE, LIST_STYLE_POSITION_INSIDE
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 73b19ef5..bb1e160c 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -77,9 +77,9 @@ proc horizontalAlignLine(ictx: InlineContext, line: LineBox, computed: CSSComput
     maxwidth
   # we don't support directions for now so left = start and right = end
   case computed{"text-align"}
-  of TEXT_ALIGN_START, TEXT_ALIGN_LEFT:
+  of TEXT_ALIGN_START, TEXT_ALIGN_LEFT, TEXT_ALIGN_CHA_LEFT:
     discard
-  of TEXT_ALIGN_END, TEXT_ALIGN_RIGHT:
+  of TEXT_ALIGN_END, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CHA_RIGHT:
     # move everything
     let x = max(maxwidth, line.width) - line.width
     for atom in line.atoms:
@@ -397,9 +397,6 @@ proc newListItem(parent: BlockBox, builder: ListItemBoxBuilder): ListItemBox =
   new(result)
   result.newBlockBox_common2(parent, builder.content)
 
-proc newBlockBox(viewport: Viewport, box: BlockBoxBuilder): BlockBox =
-  return newFlowRootBox(viewport, box, viewport.window.width_px)
-
 proc newInlineBlock(viewport: Viewport, builder: InlineBlockBoxBuilder, parentWidth: int, parentHeight = none(int)): InlineBlockBox =
   new(result)
   result.innerbox = newFlowRootBox(viewport, builder.content, parentWidth, parentHeight)
@@ -680,14 +677,25 @@ proc positionBlocks(box: BlockBox) =
   box.height += box.padding_top
 
   x += box.padding_left
-  if box.computed{"text-align"} == TEXT_ALIGN_CHA_CENTER:
+  case box.computed{"text-align"}
+  of TEXT_ALIGN_CHA_CENTER:
     x += box.compwidth div 2
+  of TEXT_ALIGN_CHA_LEFT: discard
+  of TEXT_ALIGN_CHA_RIGHT:
+    eprint "cha-right"
+    x += box.compwidth
+  else: discard
 
   template apply_child(child: BlockBox) =
     child.offset.y = y
     child.offset.x = x
-    if box.computed{"text-align"} == TEXT_ALIGN_CHA_CENTER:
+    case
+    box.computed{"text-align"}
+    of TEXT_ALIGN_CHA_CENTER:
       child.offset.x -= child.width div 2
+    of TEXT_ALIGN_CHA_LEFT: discard
+    of TEXT_ALIGN_CHA_RIGHT:
+      child.offset.x -= child.width
     elif not child.computed{"width"}.auto and child.compwidth < box.compwidth:
       let margin_left = child.computed{"margin-left"}
       let margin_right = child.computed{"margin-right"}
@@ -947,7 +955,7 @@ proc buildTable(box: TableBoxBuilder, parent: BlockBox): BlockBox =
       let x = int(unit * ctx.cols[j].weight)
       ctx.cols[j].width += x
       reflow[j] = true
-  elif table.compwidth < ctx.maxwidth and (table.shrink or forceresize):
+  elif table.compwidth < ctx.maxwidth:
     var dw = (ctx.maxwidth - table.compwidth)
     var weight: float64
     var avail = ctx.calcUnspecifiedColIndices(dw, weight)
@@ -1039,7 +1047,8 @@ proc buildBlock(box: BlockBoxBuilder, parent: BlockBox): BlockBox =
 
 # Establish a new flow-root context and build a block box.
 proc buildRootBlock(viewport: Viewport, builder: BlockBoxBuilder) =
-  let box = viewport.newBlockBox(builder)
+  let box = viewport.newFlowRootBox(builder, viewport.window.width_px)
+  #box.shrink = false
   viewport.root.add(box)
   if builder.inlinelayout:
     box.buildInlineLayout(builder.children)