about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-04-07 01:31:32 +0200
committerbptato <nincsnevem662@gmail.com>2025-04-07 01:31:32 +0200
commit6c48f2389c116c98abdd46d5c85aeec1a9e22519 (patch)
treec40b266ecac24a2fb89ab9c2b62cc492f67c4f43 /src
parent27fb1388b0644da1e733b07042e0cf30eea8d7b9 (diff)
downloadchawan-6c48f2389c116c98abdd46d5c85aeec1a9e22519.tar.gz
layout: factor out canClear flag
ugly hack that is no longer needed
Diffstat (limited to 'src')
-rw-r--r--src/css/layout.nim33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim
index e2b04e6d..2b2d1030 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -739,8 +739,7 @@ type
     firstBaselineSet: bool
 
 # Forward declarations
-proc layout(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes;
-  canClear: bool)
+proc layout(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes)
 
 iterator relevantExclusions(bctx: BlockContext): lent Exclusion {.inline.} =
   for i in bctx.clearIndex[FloatNone] ..< bctx.exclusions.len:
@@ -1458,7 +1457,7 @@ proc layoutRootBlock(lctx: LayoutContext; box: BlockBox; offset: Offset;
   var bctx = BlockContext(lctx: lctx)
   box.resetState()
   box.state.offset = offset
-  bctx.layout(box, sizes, canClear = false)
+  bctx.layout(box, sizes)
   assert bctx.unpositionedFloats.len == 0
   let marginBottom = bctx.marginTodo.sum()
   # If the highest float edge is higher than the box itself, set that as
@@ -1637,14 +1636,14 @@ proc layoutBlockChild(fstate: var FlowState; child: BlockBox;
   var offset = fstate.offset
   offset.x += sizes.margin.left
   fstate.bctx.marginTodo.append(sizes.margin.top)
+  let clear = child.computed{"clear"}
   if child.computed{"display"} in DisplayWithBFC or
       child.computed{"overflow-x"} notin {OverflowVisible, OverflowClip}:
     # This box establishes a new BFC.
     lctx.layoutRootBlock(child, offset, sizes)
     fstate.bctx.flushMargins(child.state.offset.y)
-    if child.computed{"clear"} != ClearNone:
-      fstate.offset.y.clearFloats(fstate.bctx, fstate.bfcOffset.y,
-        child.computed{"clear"})
+    if clear != ClearNone:
+      fstate.offset.y.clearFloats(fstate.bctx, fstate.bfcOffset.y, clear)
     if fstate.bctx.exclusions.len > 0:
       # From the standard (abridged):
       #
@@ -1685,7 +1684,10 @@ proc layoutBlockChild(fstate: var FlowState; child: BlockBox;
   else:
     child.resetState()
     child.state.offset = offset
-    fstate.bctx.layout(child, sizes, canClear = true)
+    if clear != ClearNone:
+      fstate.bctx.flushMargins(child.state.offset.y)
+      child.state.offset.y.clearFloats(fstate.bctx, fstate.bfcOffset.y, clear)
+    fstate.bctx.layout(child, sizes)
   fstate.bctx.marginTodo.append(sizes.margin.bottom)
   let outerSize = size(
     w = child.outerSize(dtHorizontal, sizes),
@@ -2053,15 +2055,9 @@ proc initReLayout(fstate: var FlowState; bctx: var BlockContext; box: BlockBox;
 # In general, this is only true for block boxes that do not establish
 # a BFC; other boxes (e.g. flex) either have nothing to clear, or clear
 # in their parent BFC (e.g. flow-root).
-proc layoutFlow(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes;
-    canClear: bool) =
+proc layoutFlow(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
   if box.computed{"position"} != PositionStatic:
     bctx.lctx.pushPositioned(box)
-  if canClear and box.computed{"clear"} != ClearNone and
-      box.computed{"position"} notin PositionAbsoluteFixed:
-    bctx.flushMargins(box.state.offset.y)
-    box.state.offset.y.clearFloats(bctx, bctx.bfcOffset.y,
-      box.computed{"clear"})
   var fstate = bctx.initFlowState(box, sizes)
   fstate.initBlockPositionStates(box)
   if box.computed{"position"} notin PositionAbsoluteFixed and
@@ -2170,7 +2166,7 @@ proc layoutTableCell(lctx: LayoutContext; box: BlockBox;
     sizes.space.w.u -= sizes.padding[dtHorizontal].sum()
   box.resetState()
   var bctx = BlockContext(lctx: lctx)
-  bctx.layout(box, sizes, canClear = false)
+  bctx.layout(box, sizes)
   assert bctx.unpositionedFloats.len == 0
   # Table cells ignore margins.
   box.state.offset.y = 0
@@ -2891,12 +2887,11 @@ proc layoutFlex(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
 
 proc layoutGrid(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
   #TODO implement grid
-  bctx.layoutFlow(box, sizes, canClear = false)
+  bctx.layoutFlow(box, sizes)
 
-proc layout(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes;
-    canClear: bool) =
+proc layout(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
   case box.computed{"display"}
-  of DisplayInnerBlock: bctx.layoutFlow(box, sizes, canClear)
+  of DisplayInnerBlock: bctx.layoutFlow(box, sizes)
   of DisplayInnerTable: bctx.layoutTable(box, sizes)
   of DisplayInnerFlex: bctx.layoutFlex(box, sizes)
   of DisplayInnerGrid: bctx.layoutGrid(box, sizes)
hoang/Nim/commit/contributing.rst?h=devel&id=a7c6279b147e749cd84a57cc19180d5f9bddfc10'>a7c6279b1 ^
c4fb1246d ^
a7c6279b1 ^





39dd16b5e ^

a7c6279b1 ^







c4fb1246d ^
a7c6279b1 ^

c4fb1246d ^
a7c6279b1 ^

c4fb1246d ^














39dd16b5e ^
c4fb1246d ^
57964a0ef ^


























57964a0ef ^
39dd16b5e ^
c03502943 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226