about summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-04-10 22:23:27 +0200
committerbptato <nincsnevem662@gmail.com>2022-04-10 22:23:27 +0200
commite1f3d427d91e694fa5ada1fee39038159661724d (patch)
tree065b31560e24874fe8002c96b5138da688f0537b /doc
parent71c19058100f4aea06dcf912564037be59efdf57 (diff)
downloadchawan-e1f3d427d91e694fa5ada1fee39038159661724d.tar.gz
Document plans for new layout engine
Diffstat (limited to 'doc')
-rw-r--r--doc/layout_engine.txt67
1 files changed, 67 insertions, 0 deletions
diff --git a/doc/layout_engine.txt b/doc/layout_engine.txt
new file mode 100644
index 00000000..0dfc13cf
--- /dev/null
+++ b/doc/layout_engine.txt
@@ -0,0 +1,67 @@
+CHAWAN LAYOUT ENGINE DESIGN DOCUMENT

+

+Laying out boxes turns out to be pretty damn expensive. This is the outline of

+a simple (YMMV) yet effective layout engine that can take advantage of previous

+layout passes. It doesn't include CSS cascading, which is, by the way, pretty

+damn expensive as well but is done by a different module.

+

+Most algorithms required by this engine are recursive, which is a bit of a

+problem because nim has no guarantees of your program not running out of stack

+randomly.

+

+In most cases this shouldn't be a problem but avoiding DOS attacks will be a

+bit difficult. Currently we don't support CSS that can be much deeper than the

+DOM anyway (does that even exist?) so it shouldn't be that much of a problem if

+we can limit the DOM depth. (I've read Safari had like a 250 depth limit at

+some point, which sounds reasonable.)

+

+BUILDER GENERATION:

+-> *Box (BlockBox etc.) -> BlockBoxBuilder, InlineBoxBuilder, later also

+   Table/Ruby builders

+--> this means that it's not a direct representation of the DOM. and it follows

+    that we can't preserve builders (?), so they have to be VERY cheap to

+    create. (maybe we can, but I kind of doubt it's worth the trouble. might

+    have to investigate the performance implications here.)

+--> Builder attributes: children; css; direction; generated

+--> generated should have 1:1 correspondence to builders. this helps figure

+    out what to keep at a tree rebuild: those with matching builders are kept,

+    those without are re-generated.

+---> the re-generator algorithm sounds complicated... TODO figure something out

+     here

+

+BUILDING PROCESS:

+-> *Context -> BlockContext, InlineContext

+--> Context attributes: children; direction (for non-flow-roots, flow root

+    comes later); sizes: content box; padding box; border box; margin box

+--> meaning exact positions are NOT calculated until rendering, but sizes are.

+    this allows us to avoid rebuilding sibling contexts when a block context

+    changes.

+--> BlockContext children: children (BlockContext) OR flow root (InlineContext)

+--> BlockContext can either contain block children only or be a flow root.

+    those trying to be both are broken up in builder generation.

+--> flow root is whenever the outer display is block and the inner flow. in

+    practice it should be the same as flow-root. TODO: investigate non-flow

+    inline display.

+--> InlineContext is built from InlineBoxBuilder (TODO decide if these are

+    contexts or boxes... context should be better I think...)

+    it contains a sequence of line boxes, laid out top to bottom (ideally they

+    could be left-to-right, etc...)

+    line boxes contain inline atoms, which need to have exact positions, I

+    think. an inline atom is either an inline block or a word. inline atoms

+    are separated by inline spaces which are basically spaces you can click.

+--> apropos clicking, EVERY inline word has a reference to the html element it

+    belongs to.

+--> if ANY inline context is rebuilt, EVERY inline context in the same flow

+    root must be rebuilt as well. keeping track of line boxes that haven't

+    changed sounds like a pain in the ass with minimal benefits so we don't.

+

+RENDERING PROCESS

+-> calculating positions must be done here.

+--> so arrangeInlines/arrangeBlocks must be done here

+---> and we need to somehow manage margins as well.

+--> since we should now have box sizes we can easily draw backgrounds as well.

+-> the old layout engine renders the entire document, which kind of makes

+   rendering take way too long. so one thing we could try is to render the

+   pages the user is looking at, the one before that and the one after that.

+   not sure if this will actually help though, since it would mean we have to

+   re-render the entire page every time the user scrolls up/down...

title='Blame the previous revision' href='/ahoang/chawan/blame/src/io/loadertypes.nim?id=e7ea9c408667a4fdfefc369e51d72c3cfb9c1ee9'>^
d0931964 ^
e2203257 ^
8027e52c ^
e80ae4b1 ^
d0931964 ^



e2203257 ^
51d83224 ^
e38402df ^
a02c408f ^
51d83224 ^


d0931964 ^
5da4c6e6 ^
a02c408f ^

bfaf210d ^
3223a336 ^




d0931964 ^
51d83224 ^
e2203257 ^
7c612d65 ^






d0931964 ^







e2203257 ^



e38402df ^










































3223a336 ^


e38402df ^


3223a336 ^






d0931964 ^

















00d7836d ^



e38402df ^
d0931964 ^
00d7836d ^
e2203257 ^
d0931964 ^
e38402df ^
e2203257 ^






d0931964 ^
8027e52c ^


d9e430c8 ^




8027e52c ^
bfaf210d ^

c235e638 ^

d9e430c8 ^

8027e52c ^



d0931964 ^
d9e430c8 ^


8027e52c ^
d9e430c8 ^
bfaf210d ^










51d83224 ^
d0931964 ^
00d7836d ^
06c0dd17 ^

d0931964 ^

8027e52c ^
d0931964 ^
8027e52c ^
d0931964 ^
d0931964 ^
06c0dd17 ^



d0931964 ^
06c0dd17 ^


























e2203257 ^
d0931964 ^
e2203257 ^





d0931964 ^
e2203257 ^

d0931964 ^
e2203257 ^




51d83224 ^
34b90a0b ^

a02c408f ^
5697627a ^

34b90a0b ^


c20572d3 ^
34b90a0b ^




a02c408f ^
c20572d3 ^
a02c408f ^
c20572d3 ^
10d3154e ^
bfaf210d ^






51d83224 ^
d0931964 ^



c20572d3 ^
d0931964 ^
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337