browser_html.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /* browser_html: a small tolerant HTML tree + CSS cascade for the browser.
  2. *
  3. * Freestanding and independent of ngui: it parses a byte buffer into a static
  4. * node/string arena and resolves the subset of CSS the browser understands.
  5. * One document is live at a time (the browser is single-threaded). */
  6. #ifndef BROWSER_HTML_H
  7. #define BROWSER_HTML_H
  8. #include "cursor_abi.h"
  9. #define BR_CURSOR_AUTO 0
  10. #define BR_MAX_NODES 16384
  11. /* CSS transitions the engine animates (br_style.tr_mask). */
  12. #define BR_TR_OPACITY 1
  13. #define BR_TR_TRANSFORM 2
  14. #define BR_EASE_LINEAR 0
  15. #define BR_EASE_EASE 1
  16. #define BR_EASE_IN 2
  17. #define BR_EASE_OUT 3
  18. #define BR_EASE_IN_OUT 4
  19. #define BR_TEXT_SIZE 524288
  20. #define BR_ATTR_SIZE 4194304
  21. #define BR_CSS_SIZE 262144 /* inline <style> text; google.com has ~94 KB */
  22. #define BR_MAX_RULES 8192
  23. #define BR_RULE_FALLBACK 256
  24. #define BR_MAX_FACES 16
  25. #define BR_FACE_FAMILY 40
  26. #define BR_FACE_URL 192
  27. #define BR_MAX_VARS 512
  28. #define BR_MAX_LAYERS 48
  29. /* br_style.content for `content: ""`: a box without generated text. */
  30. #define BR_CONTENT_EMPTY 0x7FFF
  31. #define BR_RULE_USES_SCOPED 1
  32. #define BR_RULE_DEFINES_SCOPED 2
  33. #define BR_MAX_CONTENT 512
  34. #define BR_TAG_MAX 128
  35. #define BR_RULE_HASH 256
  36. #define BR_DECLS 48
  37. #define BR_TITLE_MAX 96
  38. #define BR_MAX_SCRIPTS 32
  39. /* href/src values: google.com links its main script with a ~3.7 KB URL.
  40. * Matches BR_URL_MAX in browser.c and UHTTP_PATH_MAX. */
  41. #define BR_URL_ATTR_MAX 4095
  42. /* Node types. */
  43. #define BR_NODE_TEXT 0
  44. #define BR_NODE_ELEM 1
  45. #define BR_NODE_COMMENT 2
  46. #define BR_NODE_FRAGMENT 3
  47. /* Text-node flag: whitespace was preserved (<pre>). */
  48. #define BR_NODE_PREFORMAT 1
  49. /* Element flag: the HTML hidden attribute is present. */
  50. #define BR_NODE_HIDDEN 2
  51. /* Element flag: width_attr/height_attr hold an SVG viewBox. */
  52. #define BR_NODE_VIEWBOX 4
  53. /* Node is not part of the document tree (created or removed at runtime). */
  54. #define BR_NODE_DETACHED 8
  55. /* Extra attribute presence flags (data-collapse-*, state attributes).
  56. * Stored separately because struct br_style/selector matching needs them
  57. * but the node flags byte is already used. */
  58. #define BR_ATTR_COLLAPSE_TARGET 0x01
  59. #define BR_ATTR_COLLAPSE_TRIGGER 0x02
  60. #define BR_ATTR_IS_OPEN 0x04
  61. #define BR_ATTR_DISABLED 0x08
  62. #define BR_ATTR_OPEN 0x10
  63. #define BR_ATTR_INERT 0x20
  64. #define BR_ATTR_ANCHOR_MIDDLE 0x40
  65. #define BR_ATTR_ANCHOR_END 0x80
  66. /* Display values in struct br_style. */
  67. #define BR_DISPLAY_INLINE 0
  68. #define BR_DISPLAY_BLOCK 1
  69. #define BR_DISPLAY_NONE 2
  70. #define BR_DISPLAY_FLEX 3
  71. #define BR_DISPLAY_GRID 4
  72. #define BR_DISPLAY_INLINE_BLOCK 5
  73. #define BR_GRID_FIXED 16 /* grid_auto: fixed column count base */
  74. /* Decl-only bit: display:inline-flex is FLEX plus st->inline_flex. */
  75. #define BR_DISPLAY_INLINE_FLAG 0x40
  76. /* Text alignment. */
  77. #define BR_ALIGN_LEFT 0
  78. #define BR_ALIGN_CENTER 1
  79. #define BR_ALIGN_RIGHT 2
  80. /* list-style-type; AUTO follows the parent ul/ol. */
  81. #define BR_LIST_AUTO 0
  82. #define BR_LIST_DISC 1
  83. #define BR_LIST_CIRCLE 2
  84. #define BR_LIST_SQUARE 3
  85. #define BR_LIST_DECIMAL 4
  86. #define BR_LIST_LOWER_ALPHA 5
  87. #define BR_LIST_UPPER_ALPHA 6
  88. #define BR_LIST_LOWER_ROMAN 7
  89. #define BR_LIST_UPPER_ROMAN 8
  90. #define BR_LIST_NONE 9
  91. #define BR_BORDER_SOLID 0
  92. #define BR_BORDER_DASHED 1
  93. #define BR_BORDER_DOTTED 2
  94. enum br_tag {
  95. BR_TAG_UNKNOWN = 0,
  96. BR_TAG_HTML, BR_TAG_HEAD, BR_TAG_BODY, BR_TAG_TITLE, BR_TAG_STYLE,
  97. BR_TAG_SCRIPT, BR_TAG_META, BR_TAG_LINK, BR_TAG_BASE, BR_TAG_NOSCRIPT,
  98. BR_TAG_P, BR_TAG_DIV, BR_TAG_SPAN, BR_TAG_A, BR_TAG_B, BR_TAG_STRONG,
  99. BR_TAG_I, BR_TAG_EM, BR_TAG_U, BR_TAG_CODE, BR_TAG_FONT, BR_TAG_SMALL,
  100. BR_TAG_BIG, BR_TAG_BR, BR_TAG_HR, BR_TAG_IMG, BR_TAG_PICTURE,
  101. BR_TAG_H1, BR_TAG_H2, BR_TAG_H3, BR_TAG_H4, BR_TAG_H5, BR_TAG_H6,
  102. BR_TAG_UL, BR_TAG_OL, BR_TAG_LI, BR_TAG_BLOCKQUOTE, BR_TAG_PRE,
  103. BR_TAG_CENTER, BR_TAG_TABLE, BR_TAG_THEAD, BR_TAG_TBODY, BR_TAG_TFOOT,
  104. BR_TAG_TR, BR_TAG_TD, BR_TAG_TH, BR_TAG_CAPTION,
  105. BR_TAG_FORM, BR_TAG_INPUT, BR_TAG_BUTTON, BR_TAG_LABEL, BR_TAG_SELECT,
  106. BR_TAG_OPTION, BR_TAG_TEXTAREA, BR_TAG_IFRAME, BR_TAG_SVG,
  107. BR_TAG_VIDEO, BR_TAG_AUDIO, BR_TAG_CANVAS, BR_TAG_OBJECT,
  108. BR_TAG_MAIN, BR_TAG_HEADER, BR_TAG_FOOTER, BR_TAG_NAV, BR_TAG_SECTION,
  109. BR_TAG_ARTICLE, BR_TAG_ASIDE, BR_TAG_FIGURE, BR_TAG_FIGCAPTION,
  110. BR_TAG_DETAILS, BR_TAG_SUMMARY, BR_TAG_DL, BR_TAG_DT, BR_TAG_DD,
  111. BR_TAG_ADDRESS, BR_TAG_MARK, BR_TAG_TIME, BR_TAG_ABBR, BR_TAG_CITE,
  112. BR_TAG_Q, BR_TAG_S, BR_TAG_STRIKE, BR_TAG_SUB, BR_TAG_SUP,
  113. BR_TAG_BGSOUND, BR_TAG_EMBED, BR_TAG_PARAM, BR_TAG_SOURCE,
  114. BR_TAG_TRACK, BR_TAG_WBR, BR_TAG_AREA, BR_TAG_COL, BR_TAG_COLGROUP,
  115. BR_TAG_TEMPLATE
  116. };
  117. struct br_style {
  118. unsigned short color;
  119. unsigned short bg;
  120. unsigned short border_c[4]; /* top, right, bottom, left */
  121. unsigned short bg_image; /* 1-based background URL, 0 none */
  122. unsigned char bg_repeat; /* 0 repeat, 1 no-repeat, 2 repeat-x, 3 repeat-y */
  123. unsigned char bg_pos_x_kind, bg_pos_y_kind; /* 0 px, 1 percent */
  124. signed short bg_pos_x, bg_pos_y;
  125. unsigned char bg_size_kind; /* 0 auto/stretch, 1 px, 2 percent, 3 cover, 4 contain */
  126. unsigned short bg_size_w, bg_size_h;
  127. unsigned char has_bg;
  128. unsigned char bg_set; /* author set background (colour or transparent) */
  129. unsigned char font_px; /* 8..48 */
  130. unsigned short font_raw; /* font-size before unit resolution */
  131. unsigned char font_unit; /* 0 inherited, 1 px, 2 em, 3 rem, 4 % */
  132. unsigned char bold;
  133. unsigned char italic;
  134. unsigned char mono;
  135. unsigned char font_face; /* 1-based @font-face id, 0 = built-in */
  136. unsigned char underline;
  137. unsigned char strike; /* text-decoration: line-through */
  138. unsigned char overline; /* text-decoration: overline */
  139. unsigned char align; /* BR_ALIGN_* */
  140. unsigned char display; /* BR_DISPLAY_* */
  141. unsigned char vis_hidden, opacity_hidden, overflow_hidden;
  142. unsigned char float_left; /* float: left/right */
  143. unsigned char clear; /* 0 none, 1 left, 2 right, 3 both */
  144. unsigned char flex_grow; /* flex-grow, 0..100 */
  145. unsigned char flex_col; /* flex-direction: column */
  146. unsigned char flex_wrap; /* flex-wrap: wrap */
  147. unsigned char justify; /* 0 start, 1 center, 2 end, 3 between, 4 around */
  148. unsigned char align_items; /* 0 stretch, 1 center, 2 end, 3 start */
  149. unsigned char align_self; /* 0 auto, else align_items + 1 */
  150. unsigned char grid_ncols; /* 1 or 2 supported */
  151. unsigned char grid_gap; /* px */
  152. unsigned char grid_slot; /* 0 auto, 1 full, 2 left, 3 right */
  153. unsigned char grid_auto; /* 1: repeat(auto-fit, minmax(width, 1fr));
  154. * BR_GRID_FIXED + N: N equal columns */
  155. unsigned char pos; /* 0 static, 1 absolute, 2 fixed, 3 relative */
  156. unsigned char left_set, top_set, right_set, bottom_set;
  157. signed short left, top, right, bottom;
  158. signed short z_index;
  159. unsigned char z_set;
  160. signed short tx, ty;
  161. unsigned char tx_pct, ty_pct; /* tx/ty are percent of the own box */
  162. unsigned char transform_set;
  163. unsigned char opacity; /* 0..255 (255 opaque); not inherited */
  164. unsigned char tr_mask; /* BR_TR_*: transitioned properties */
  165. unsigned char tr_ease; /* BR_EASE_* */
  166. unsigned short tr_ms; /* transition duration */
  167. unsigned char transform_scale; /* scale()/rotate() paint hint */
  168. signed short scale_x, scale_y; /* hundredths, 100 = 1.0 */
  169. signed short rotate_x100; /* hundredths of a degree */
  170. signed short origin_x, origin_y;
  171. unsigned char origin_x_kind, origin_y_kind; /* 0 px, 1 percent */
  172. unsigned char no_bullet; /* list-style: none (inherited) */
  173. unsigned char list_style; /* BR_LIST_* (inherited from ul/ol) */
  174. unsigned char list_item; /* li marker is drawn */
  175. unsigned char nowrap; /* white-space: nowrap (inherited) */
  176. unsigned char uppercase; /* text-transform: uppercase (inherited) */
  177. unsigned char pe_none; /* pointer-events: none (inherited) */
  178. unsigned char cursor; /* CSS cursor (inherited): BR_CURSOR_AUTO or
  179. enum cursor_shape + 1 */
  180. unsigned char border_w[4]; /* top, right, bottom, left */
  181. unsigned char border_s[4]; /* BR_BORDER_* per side */
  182. unsigned char border_t[4]; /* 1 = fully transparent border side */
  183. /* border-radius in pixels, one entry per corner: TL, TR, BR, BL.
  184. * Percentages are stored as 255 so they clamp to the box half. */
  185. unsigned char radius[4];
  186. unsigned char width_kind; /* 0 none, 1 px, 2 percent, 3 calc */
  187. unsigned short width;
  188. signed short width_calc_pct;
  189. signed short width_calc_px;
  190. unsigned char max_width_kind;
  191. unsigned short max_width;
  192. unsigned char min_width_kind;
  193. unsigned short min_width;
  194. unsigned char height_kind;
  195. unsigned short height;
  196. signed short height_calc_pct, height_calc_px;
  197. unsigned char min_height_kind;
  198. unsigned short min_height;
  199. signed short min_height_calc_pct, min_height_calc_px;
  200. unsigned char max_height_kind;
  201. unsigned short max_height;
  202. signed short max_height_calc_pct, max_height_calc_px;
  203. signed short min_width_calc_pct, min_width_calc_px;
  204. signed short max_width_calc_pct, max_width_calc_px;
  205. unsigned char box_sizing; /* 0 content-box, 1 border-box */
  206. unsigned char ml_auto, mr_auto;
  207. unsigned char line_h_pct; /* percent of font size, 0 = default */
  208. unsigned short line_h_px; /* absolute px, 0 = default */
  209. signed short mt, mb, ml, mr;
  210. signed short pt, pb, pl, pr;
  211. /* mt, mr, mb, ml, pt, pr, pb, pl: 0 px, 1 %, 2 em, 3 rem, 4 auto,
  212. * 5 calc (the raw value is the percent, mp_calc_px the px part) */
  213. unsigned char mp_unit[8];
  214. signed short mp_calc_px[8];
  215. /* SVG paint (inherited, like CSS fill/stroke): BR_PAINT_* modes.
  216. * stroke_w is in 1/16 user units; 0 means the default 1. */
  217. unsigned char fill_mode, stroke_mode, fill_evenodd;
  218. unsigned short fill, stroke;
  219. unsigned short stroke_w;
  220. unsigned char inline_flex; /* display:inline-flex (not inherited) */
  221. unsigned short content; /* ::before/::after content: index + 1 */
  222. unsigned short aspect_w, aspect_h; /* aspect-ratio (x100), 0 = auto */
  223. };
  224. #define BR_PAINT_UNSET 0 /* fill: black, stroke: none */
  225. #define BR_PAINT_COLOR 1
  226. #define BR_PAINT_NONE 2
  227. #define BR_PAINT_CURRENT 3 /* currentColor -> style color */
  228. #define BR_PAINT_URL 4 /* url(#id): resolved from the attribute */
  229. struct br_node {
  230. unsigned char type;
  231. unsigned char tag;
  232. unsigned char flags;
  233. unsigned char attr_flags;
  234. unsigned short parent;
  235. unsigned short first;
  236. unsigned short last;
  237. unsigned short next;
  238. unsigned int text_off; /* text arena offset (text nodes) */
  239. unsigned short text_len;
  240. unsigned int href_off;
  241. unsigned int class_off;
  242. unsigned int id_off;
  243. unsigned int style_off;
  244. unsigned int src_off;
  245. unsigned int alt_off;
  246. unsigned int color_off;
  247. unsigned int rel_off;
  248. unsigned int name_off; /* raw tag name for custom elements */
  249. unsigned int extra_off; /* packed name\0value\0 list for getAttribute */
  250. unsigned short extra_len;
  251. unsigned short width_attr;
  252. unsigned short height_attr;
  253. unsigned char width_pct;
  254. unsigned char height_pct;
  255. unsigned char colspan;
  256. unsigned char rowspan;
  257. short bg_img_index; /* -1 until loaded, -2 failed */
  258. short img_index; /* -1 until the image is loaded */
  259. signed short svg_x, svg_y; /* inline SVG x/y or line x1/y1 */
  260. unsigned char svg_rx; /* inline SVG rect corner radius */
  261. struct br_style style; /* computed-style cache */
  262. unsigned char style_valid;
  263. unsigned char pe_state; /* br_pseudo() cache: 1/4 checked, 2/8 has */
  264. };
  265. struct br_decl {
  266. unsigned char prop;
  267. unsigned char important;
  268. short val;
  269. };
  270. struct br_rule {
  271. unsigned int sel_off; /* selector text in the attr arena */
  272. unsigned int key_off; /* rightmost compound, for a fast prefilter */
  273. unsigned short spec; /* selector specificity */
  274. unsigned char nd;
  275. unsigned char single; /* one compound, no ancestor walk needed */
  276. unsigned char pe; /* 0 element, 1 ::before, 2 ::after */
  277. unsigned char layer; /* 0 unlayered, else @layer order (1-based) */
  278. /* BR_RULE_USES_SCOPED / BR_RULE_DEFINES_SCOPED: the block uses or
  279. * defines a custom property whose value depends on the element (see
  280. * br_style_for); raw_off/raw_len keep the unexpanded block. */
  281. unsigned char var_scope;
  282. unsigned short raw_len;
  283. unsigned int raw_off;
  284. struct br_decl d[BR_DECLS];
  285. };
  286. /* An inline <script> body. off/len index script_src, the buffer passed to
  287. * br_parse(); the caller must keep it alive for as long as the document (the
  288. * browser keeps the page body until the next navigation). */
  289. struct br_script {
  290. unsigned int off; /* inline body, or empty for src scripts */
  291. unsigned int len;
  292. unsigned int src_off; /* src attribute in the attr arena, 0 if inline */
  293. unsigned int module; /* type="module": run as an ES module */
  294. unsigned int node; /* the <script> element (document.currentScript) */
  295. };
  296. struct br_doc {
  297. struct br_node *nodes;
  298. unsigned int nnode;
  299. unsigned int root;
  300. char *text;
  301. unsigned int text_used;
  302. char *attrs;
  303. unsigned int attrs_used;
  304. struct br_rule *rules;
  305. unsigned int nrules;
  306. unsigned int rule_cap;
  307. char title[BR_TITLE_MAX];
  308. unsigned int inline_css_len;
  309. /* CSS custom properties, stored in the attr arena. A pragmatic
  310. * single table: the last definition wins, which matches :root. */
  311. unsigned int var_name[BR_MAX_VARS];
  312. unsigned int var_val[BR_MAX_VARS];
  313. /* BR_VAR_ROOT: set by a :root, html, body or * rule; BR_VAR_CONFLICT: two
  314. * component rules disagree, so var() uses its fallback. */
  315. unsigned char var_flags[BR_MAX_VARS];
  316. unsigned short var_slot[1024];
  317. unsigned int nvars;
  318. /* @layer names (hash of the full dotted name) in order of first
  319. * appearance; a rule's `layer` indexes this table + 1. */
  320. unsigned int layer_hash[BR_MAX_LAYERS];
  321. unsigned int nlayers;
  322. /* Rule index: rightmost class/id/tag -> linked list of rule indices. */
  323. unsigned short rule_next[BR_MAX_RULES];
  324. unsigned short rule_bucket[BR_RULE_HASH];
  325. unsigned short rule_tag[BR_TAG_MAX];
  326. unsigned short rule_any;
  327. /* ::before/::after content strings (attr arena offsets); attr(x) is
  328. * stored as \001x\002 and expanded per element. */
  329. unsigned int content_off[BR_MAX_CONTENT];
  330. unsigned short ncontent;
  331. unsigned short npe_rules;
  332. int truncated;
  333. int plain; /* text/plain: one preformatted text node */
  334. const char *script_src; /* buffer the script offsets point into */
  335. struct br_script scripts[BR_MAX_SCRIPTS];
  336. unsigned short nscripts;
  337. unsigned short scripts_truncated;
  338. };
  339. void br_doc_init(struct br_doc *d);
  340. /* ::before (pe 1) or ::after (pe 2) of an element: the pseudo-element's
  341. * style (inheriting from the element's style `elem`) and its generated
  342. * text. Returns the text length; 0 when there is no content, or when the
  343. * pseudo-element is display:none or absolutely positioned. `content: ""`
  344. * returns 0 with out->content == BR_CONTENT_EMPTY and a visible display
  345. * when the box has a size and a background (an icon to draw). */
  346. unsigned int br_pseudo(struct br_doc *d, unsigned int node, int pe,
  347. const struct br_style *elem, struct br_style *out,
  348. char *buf, unsigned int cap);
  349. void br_set_rule_store(struct br_doc *d, struct br_rule *buf,
  350. unsigned int cap);
  351. int br_parse(struct br_doc *d, const char *html, unsigned int len);
  352. int br_parse_plain(struct br_doc *d, const char *text, unsigned int len);
  353. unsigned int br_parse_image_doc(struct br_doc *d, const char *src);
  354. /* External CSS is parsed by the browser after br_parse(); parse the inline
  355. * <style> blocks last so the cascade order matches the document. */
  356. void br_set_viewport(unsigned int width);
  357. /* A media query list (`screen and (min-width: 600px)`) against the
  358. * viewport set above; window.matchMedia() uses the same answers as CSS. */
  359. int br_media_matches(const char *query);
  360. void br_set_theme(unsigned short text, unsigned short bg,
  361. unsigned short panel, unsigned short link);
  362. void br_parse_css_text(struct br_doc *d, const char *css, unsigned int len);
  363. /* CSS colour value (names, #hex, rgb()/rgba()) -> RGB565; 1 on success. */
  364. int br_parse_color(const char *s, unsigned int len, unsigned short *out);
  365. void br_parse_inline_css(struct br_doc *d);
  366. void br_reset_styles(struct br_doc *d);
  367. /* A node's style: parent inherited values, UA defaults, matching rules, then
  368. * the inline style attribute. Results are cached in the node until
  369. * br_reset_styles(). */
  370. void br_style_for(struct br_doc *d, unsigned int node,
  371. const struct br_style *parent, struct br_style *out);
  372. int br_tag_is_block(unsigned int tag);
  373. int br_tag_is_void(unsigned int tag);
  374. const char *br_tag_name(unsigned int tag);
  375. unsigned int br_tag_from_name(const char *name);
  376. const char *br_bg_image_url(unsigned int idx);
  377. unsigned int br_root_font_px(void);
  378. /* @font-face table. Ids are 1-based; the browser resolves URLs against the
  379. * stored base (the stylesheet URL or the page URL) and loads the faces.
  380. * Each (family, weight, style) is one entry; br_style.font_face holds the
  381. * family's first entry and the browser picks the variant at layout. */
  382. struct br_font_face_info {
  383. int family_id; /* 1-based id of the family's first face */
  384. unsigned int wmin, wmax; /* weight range, 400 = normal */
  385. int italic;
  386. int used; /* named by a font-family declaration */
  387. };
  388. int br_font_face_count(void);
  389. int br_font_face_info(int id, struct br_font_face_info *out);
  390. const char *br_font_face_url(int id);
  391. const char *br_font_face_base(int id);
  392. const char *br_font_face_family(int id);
  393. void br_set_font_base(const char *base);
  394. /* Runtime DOM helpers used by the JavaScript bindings. br_find_id returns
  395. * node + 1 (0 means no match); br_text_content concatenates the subtree's
  396. * text nodes into out and returns the (possibly truncated) length. */
  397. unsigned int br_find_id(struct br_doc *d, const char *id);
  398. unsigned int br_find_tag(struct br_doc *d, unsigned int tag);
  399. /* 1 when the node is not in the document (removed, or never inserted). */
  400. int br_node_detached(struct br_doc *d, unsigned int node);
  401. unsigned int br_text_content(struct br_doc *d, unsigned int node,
  402. char *out, unsigned int cap);
  403. int br_set_text_content(struct br_doc *d, unsigned int node,
  404. const char *text, unsigned int len);
  405. int br_set_text_node(struct br_doc *d, unsigned int node,
  406. const char *text, unsigned int len);
  407. /* Runtime DOM construction and mutation (node handles are index + 1). */
  408. unsigned int br_create_element(struct br_doc *d, const char *name,
  409. unsigned int len);
  410. unsigned int br_create_text(struct br_doc *d, const char *text,
  411. unsigned int len);
  412. unsigned int br_create_comment(struct br_doc *d, const char *text,
  413. unsigned int len);
  414. unsigned int br_create_fragment(struct br_doc *d);
  415. unsigned int br_clone_node(struct br_doc *d, unsigned int node, int deep);
  416. int br_append_child(struct br_doc *d, unsigned int parent,
  417. unsigned int child);
  418. int br_insert_before(struct br_doc *d, unsigned int parent,
  419. unsigned int child, unsigned int before);
  420. int br_remove_child(struct br_doc *d, unsigned int parent,
  421. unsigned int child);
  422. unsigned int br_find_child(struct br_doc *d, unsigned int parent,
  423. unsigned int child);
  424. const char *br_find_attr(struct br_doc *d, unsigned int node,
  425. const char *name);
  426. int br_set_attr(struct br_doc *d, unsigned int node, const char *name,
  427. const char *value, unsigned int len);
  428. int br_remove_attr(struct br_doc *d, unsigned int node, const char *name);
  429. /* Replace a node's children with a parsed HTML fragment. */
  430. int br_set_inner_html(struct br_doc *d, unsigned int node,
  431. const char *html, unsigned int len);
  432. /* Simple selector subset: #id, .class, tag, [attr], [attr=v],
  433. * [attr^=v], [attr$=v], [attr*=v], compounds and descendant chains. */
  434. unsigned int br_query_all(struct br_doc *d, unsigned int root,
  435. const char *selector, unsigned int *out,
  436. unsigned int max);
  437. int br_matches(struct br_doc *d, unsigned int node, const char *selector);
  438. const char *br_href(struct br_doc *d, unsigned int node);
  439. const char *br_src(struct br_doc *d, unsigned int node);
  440. const char *br_alt(struct br_doc *d, unsigned int node);
  441. const char *br_rel(struct br_doc *d, unsigned int node);
  442. const char *br_value(struct br_doc *d, unsigned int node);
  443. const char *br_placeholder(struct br_doc *d, unsigned int node);
  444. const char *br_type(struct br_doc *d, unsigned int node);
  445. #endif