about summary refs log tree commit diff stats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-24 14:23:28 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-24 14:23:28 +0100
commita71024058bf6fb0e30045aaf6033be104b4328a1 (patch)
tree7a994f96d78f002b9e3dfa9d00284d1adf32dedd /src/layout
parentf8dbdbc8777cda6d45e8e05f9807319db4542572 (diff)
downloadchawan-a71024058bf6fb0e30045aaf6033be104b4328a1.tar.gz
layout: make position: fixed, sticky act like static
It's better to not implement them at all than to implement them badly.

(In particular, making fixed act like absolute breaks horribly on
websites that actually use it. Fixing it is not really possible without
changinge the way we currently draw things to the screen.)
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/engine.nim15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 06e95cdc..049da947 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -1150,7 +1150,7 @@ const DisplayBlockLike = {DISPLAY_BLOCK, DISPLAY_LIST_ITEM,
 
 # Return true if no more margin collapsing can occur for the current strut.
 func canFlushMargins(builder: BlockBoxBuilder, sizes: ResolvedSizes): bool =
-  if builder.computed{"position"} in {POSITION_ABSOLUTE, POSITION_FIXED}:
+  if builder.computed{"position"} == POSITION_ABSOLUTE:
     return false
   return sizes.padding.top != 0 or sizes.padding.bottom != 0 or
     builder.inlinelayout or builder.computed{"display"} notin DisplayBlockLike
@@ -1272,7 +1272,7 @@ proc positionFloats(bctx: var BlockContext) =
 
 func establishesBFC(computed: CSSComputedValues): bool =
   return computed{"float"} != FLOAT_NONE or
-    computed{"position"} in {POSITION_ABSOLUTE, POSITION_FIXED} or
+    computed{"position"} in POSITION_ABSOLUTE or
     computed{"display"} in {DISPLAY_INLINE_BLOCK, DISPLAY_FLOW_ROOT} +
       InternalTableBox
     #TODO overflow, contain, flex, grid, multicol, column-span
@@ -2176,8 +2176,8 @@ proc layoutBlockChildren(state: var BlockState, bctx: var BlockContext,
     var dy: LayoutUnit = 0 # delta
     var child: BlockBox
     let isfloat = builder.computed{"float"} != FLOAT_NONE
-    let isinflow = builder.computed{"position"} notin {POSITION_ABSOLUTE,
-      POSITION_FIXED} and not isfloat
+    let isinflow = builder.computed{"position"} != POSITION_ABSOLUTE
+      and not isfloat
     if builder.computed.establishesBFC():
       var marginBottomOut: LayoutUnit
       child = bctx.lctx.layoutRootBlock(builder, state.space, state.offset,
@@ -2206,8 +2206,7 @@ proc layoutBlockChildren(state: var BlockState, bctx: var BlockContext,
     let childWidth = child.margin.left + child.size.w + child.margin.right
     state.maxChildWidth = max(state.maxChildWidth, childWidth)
     state.xminwidth = max(state.xminwidth, child.xminwidth)
-    if child.computed{"position"} notin {POSITION_ABSOLUTE, POSITION_FIXED} and
-        not isfloat:
+    if child.computed{"position"} != POSITION_ABSOLUTE and not isfloat:
       # Not absolute, and not a float.
       state.offset.y += dy
     elif isfloat:
@@ -2299,7 +2298,9 @@ proc repositionChildren(state: BlockState, box: BlockBox, lctx: LayoutState) =
 proc layoutBlock(bctx: var BlockContext, box: BlockBox,
     builder: BlockBoxBuilder, sizes: ResolvedSizes) =
   let lctx = bctx.lctx
-  let positioned = box.computed{"position"} != POSITION_STATIC
+  let positioned = box.computed{"position"} != {
+    POSITION_STATIC, POSITION_FIXED, POSITION_STICKY
+  }
   if positioned:
     lctx.positioned.add(sizes.space)
   var state = BlockState(