code wiki / (root) / nx_layout_from_dom.nx

nx_layout_from_dom.nx

buildroot/runtime/nx_layout_from_dom.nx

21696 B417 linesdepth 4pulls 5 transitivereach 88 importersview sourcekind librarytopic layout
docsdependenciesstructsconstsfunctions

about

nx_layout_from_dom.nx -- build a LayoutBox tree from an HTML byte stream by streaming nx_html_tokenizer tokens. Phase 3 fourth primitive of NISHI_BROWSER_ROADMAP. THE bridge primitive between Phase 1 (HTML parse) and Phase 3 (layout). Closes the gap that prior layout smokes covered with hand-built fixtures. Algorithm: streaming token walk with a parent-stack arena. 1. Append a synthetic root LayoutBox of kind BLOCK at index 0. (Production wraps this around a viewport-sized "html" box. Phase 3b will detect the actual <html> / <body> root.) 2. Maintain a stack of "current parent" LayoutBox indices. Root is the bottom of the stack. 3. For each token from the HTML tokenizer: START_TAG -> create LayoutBox with kind from nx_layout_default_display(tag name); attach to current parent; push onto stack. END_TAG -> pop the stack (back to parent). SELF_CLOSING -> create LayoutBox; attach; do NOT push. TEXT -> create LayoutBox of kind TEXT with the text body offset/length recorded via nx_layout_box_set_text. DOCTYPE -> skip. COMMENT -> skip. UNKNOWN -> skip. EOF -> end the walk. The output LayoutTree is ready for nx_layout_block to lay out (provided cascade decls are computed via nx_css_apply against the same source buffer first). What it does NOT handle yet (Phase 3b queued, explicit in header): - HTML5 implicit-tag rules (auto-close on certain transitions, e.g. <li><li> -> implicit </li> before second <li>; <p><div> -> implicit </p>; <table> children must be <tr>; etc.) - foster parenting of stray text inside <table> - HTML5 raw-text content (script / style bodies are tokenized as TEXT by nx_html_tokenizer's CAPABILITY_COMPLETENESS=PARTIAL; CSS interpretation lives in Phase 2) - foreign content (SVG, MathML namespace switches)

dependencies 4 imports · 28 importers

nx_syscalls.nx nx_html_tokenizer.nx nx_layout_box.nx nx_layout_default_display.nx nx_layout_from_dom.nx nx_align_gate.nx nx_browser.nx nx_browser_demo_html.nx nx_browser_demo_html_nishi.nx nx_browser_demo_styled.nx nx_browser_render.nx nx_cdata_probe.nx nx_css_boxmap_test.nx nx_flexgrow_gate.nx nx_flexgrow_probe.nx

diagram shows first 10 each side; +0 more imports, +18 more importers in the complete lists below.

imports: nx_syscalls.nxnx_html_tokenizer.nxnx_layout_box.nxnx_layout_default_display.nx

imported by: nx_align_gate.nxnx_browser.nxnx_browser_demo_html.nxnx_browser_demo_html_nishi.nxnx_browser_demo_styled.nxnx_browser_render.nxnx_cdata_probe.nxnx_css_boxmap_test.nxnx_flexgrow_gate.nxnx_flexgrow_probe.nxnx_float_gate.nxnx_float_test.nxnx_grid_gate.nxnx_grid_test.nxnx_grid_track_gate.nxnx_justify_gate.nxnx_layout_debug.nxnx_layout_example_com_real_test.nxnx_layout_from_dom_test.nxnx_negmargin_gate.nxnx_real_page_gate.nxnx_render_ascii.nxnx_render_html.nxnx_render_wiki_bmp.nxnx_render_wiki_styled_window.nxnx_render_wiki_window.nxnx_table_cell_gate.nxnx_wiki_boxdump.nx

structs

71struct LayoutFromDomStack

consts

66const NX_MAGIC_65536: i64 = 65536
77const NX_LAYOUT_FROM_DOM_STACK_BYTES: i64 = 24

functions

81func _lfd_push(stk: *LayoutFromDomStack, idx: i64) -> i64
called by 1: nx_layout_from_dom
88func _lfd_pop(stk: *LayoutFromDomStack) -> i64
called by 1: nx_layout_from_dom
94func _lfd_top(stk: *LayoutFromDomStack) -> i64
100func _lfd_top_kind(tree: *LayoutTree, stk: *LayoutFromDomStack) -> i64
called by 1: nx_layout_from_dom calls 1: _lfd_top
110func nx_layout_from_dom_stack_init(stk: *LayoutFromDomStack,
125func _lfd_lc(b: i64) -> i64 { if b >= 65 { if b <= 90 { return b + 32 } } return b }
called by 1: _lfd_name_eq
126func _lfd_name_eq(src: *u8, off: i64, len: i64, lit: *u8) -> i64
136func _lfd_suppress_tag(src: *u8, off: i64, len: i64) -> i64
called by 1: nx_layout_from_dom calls 1: _lfd_name_eq
156func _lfd_is_void_tag(src: *u8, off: i64, len: i64) -> i64
called by 1: br_extract calls 1: _lfd_name_eq
179func _lfd_chrome_tag(src: *u8, off: i64, len: i64) -> i64
185func _lfd_has_role_nav(src: *u8, src_off: i64, src_len: i64) -> i64
called by 1: _lfd_is_chrome_start calls 1: _lfd_name_eq
200func _lfd_src_has_sub(src: *u8, off: i64, len: i64, lit: *u8) -> i64
220func _lfd_has_chrome_class(src: *u8, src_off: i64, src_len: i64) -> i64
229func _lfd_inline_hidden(src: *u8, src_off: i64, src_len: i64) -> i64
236func _lfd_is_chrome_start(src: *u8, name_off: i64, name_len: i64, src_off: i64, src_len: i64) -> i64
244func _lfd_is_blank(src: *u8, off: i64, len: i64) -> i64
called by 1: nx_layout_from_dom
253func _lfd_ws(c: i64) -> i64 { if c==32 {return 1} if c==9 {return 1} if c==10 {return 1} if c==13 {return 1} if c==12 {return 1} return 0 }
260func _lfd_trim_start(src: *u8, off: i64, end: i64) -> i64
called by 1: nx_layout_from_dom calls 1: _lfd_ws
275func _lfd_trim_end(src: *u8, off: i64, end: i64) -> i64
called by 1: nx_layout_from_dom calls 1: _lfd_ws
290func nx_layout_from_dom(src: *u8, src_len: i64,