blitz-pdf 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +355 -2
  3. package/THIRD_PARTY_NOTICES.md +25 -0
  4. package/assets/icon.svg +4 -0
  5. package/dist/api.d.ts +7 -0
  6. package/dist/api.d.ts.map +1 -0
  7. package/dist/api.js +46 -0
  8. package/dist/api.js.map +1 -0
  9. package/dist/assets.d.ts +7 -0
  10. package/dist/assets.d.ts.map +1 -0
  11. package/dist/assets.js +52 -0
  12. package/dist/assets.js.map +1 -0
  13. package/dist/browser.d.ts +3 -0
  14. package/dist/browser.d.ts.map +1 -0
  15. package/dist/browser.js +3 -0
  16. package/dist/browser.js.map +1 -0
  17. package/dist/node.d.ts +3 -0
  18. package/dist/node.d.ts.map +1 -0
  19. package/dist/node.js +10 -0
  20. package/dist/node.js.map +1 -0
  21. package/dist/options.d.ts +24 -0
  22. package/dist/options.d.ts.map +1 -0
  23. package/dist/options.js +135 -0
  24. package/dist/options.js.map +1 -0
  25. package/dist/types.d.ts +51 -0
  26. package/dist/types.d.ts.map +1 -0
  27. package/dist/types.js +2 -0
  28. package/dist/types.js.map +1 -0
  29. package/examples/bun.ts +8 -0
  30. package/examples/german-invoice/README.md +70 -0
  31. package/examples/german-invoice/data.mjs +83 -0
  32. package/examples/german-invoice/invoice.css +59 -0
  33. package/examples/german-invoice/template.mjs +49 -0
  34. package/examples/german-invoice.mjs +20 -0
  35. package/examples/invoice.html +29 -0
  36. package/examples/node.mjs +8 -0
  37. package/examples/pagination.html +40 -0
  38. package/examples/pagination.mjs +8 -0
  39. package/licenses/DejaVu.txt +187 -0
  40. package/licenses/RUST_DEPENDENCIES.txt +11577 -0
  41. package/package.json +89 -4
  42. package/src/api.ts +44 -0
  43. package/src/assets.ts +43 -0
  44. package/src/browser.ts +6 -0
  45. package/src/node.ts +12 -0
  46. package/src/options.ts +101 -0
  47. package/src/types.ts +49 -0
  48. package/vendor/README.md +17 -0
  49. package/vendor/stylo/.cargo-ok +1 -0
  50. package/vendor/stylo/.cargo_vcs_info.json +6 -0
  51. package/vendor/stylo/Cargo.lock +1485 -0
  52. package/vendor/stylo/Cargo.toml +274 -0
  53. package/vendor/stylo/LICENSE +373 -0
  54. package/vendor/stylo/README.md +6 -0
  55. package/vendor/stylo/applicable_declarations.rs +328 -0
  56. package/vendor/stylo/author_styles.rs +79 -0
  57. package/vendor/stylo/bezier.rs +176 -0
  58. package/vendor/stylo/bloom.rs +414 -0
  59. package/vendor/stylo/build.rs +91 -0
  60. package/vendor/stylo/build_gecko.rs +393 -0
  61. package/vendor/stylo/color/color_function.rs +601 -0
  62. package/vendor/stylo/color/component.rs +207 -0
  63. package/vendor/stylo/color/convert.rs +935 -0
  64. package/vendor/stylo/color/gamut/raytrace.rs +265 -0
  65. package/vendor/stylo/color/gamut.rs +227 -0
  66. package/vendor/stylo/color/mix.rs +645 -0
  67. package/vendor/stylo/color/mod.rs +750 -0
  68. package/vendor/stylo/color/parsing.rs +770 -0
  69. package/vendor/stylo/color/to_css.rs +297 -0
  70. package/vendor/stylo/context.rs +716 -0
  71. package/vendor/stylo/counter_style/mod.rs +754 -0
  72. package/vendor/stylo/counter_style/predefined.rs +61 -0
  73. package/vendor/stylo/counter_style/update_predefined.py +35 -0
  74. package/vendor/stylo/custom_properties.rs +2023 -0
  75. package/vendor/stylo/custom_properties_map.rs +220 -0
  76. package/vendor/stylo/data.rs +693 -0
  77. package/vendor/stylo/device/gecko.rs +486 -0
  78. package/vendor/stylo/device/mod.rs +304 -0
  79. package/vendor/stylo/device/servo.rs +507 -0
  80. package/vendor/stylo/dom.rs +1164 -0
  81. package/vendor/stylo/dom_apis.rs +937 -0
  82. package/vendor/stylo/driver.rs +172 -0
  83. package/vendor/stylo/error_reporting.rs +484 -0
  84. package/vendor/stylo/font_face.rs +558 -0
  85. package/vendor/stylo/font_metrics.rs +124 -0
  86. package/vendor/stylo/gecko/anon_boxes.toml +113 -0
  87. package/vendor/stylo/gecko/arc_types.rs +211 -0
  88. package/vendor/stylo/gecko/conversions.rs +59 -0
  89. package/vendor/stylo/gecko/data.rs +222 -0
  90. package/vendor/stylo/gecko/media_features.rs +971 -0
  91. package/vendor/stylo/gecko/mod.rs +20 -0
  92. package/vendor/stylo/gecko/non_ts_pseudo_class_list.rs +119 -0
  93. package/vendor/stylo/gecko/pseudo_element.rs +640 -0
  94. package/vendor/stylo/gecko/pseudo_element_definition.mako.rs +298 -0
  95. package/vendor/stylo/gecko/pseudo_elements.py +137 -0
  96. package/vendor/stylo/gecko/pseudo_elements.toml +197 -0
  97. package/vendor/stylo/gecko/regen_pseudo_elements.py +33 -0
  98. package/vendor/stylo/gecko/restyle_damage.rs +127 -0
  99. package/vendor/stylo/gecko/selector_parser.rs +627 -0
  100. package/vendor/stylo/gecko/snapshot.rs +202 -0
  101. package/vendor/stylo/gecko/snapshot_helpers.rs +334 -0
  102. package/vendor/stylo/gecko/traversal.rs +52 -0
  103. package/vendor/stylo/gecko/wrapper.rs +2258 -0
  104. package/vendor/stylo/gecko_bindings/mod.rs +34 -0
  105. package/vendor/stylo/gecko_bindings/sugar/mod.rs +12 -0
  106. package/vendor/stylo/gecko_bindings/sugar/ns_com_ptr.rs +15 -0
  107. package/vendor/stylo/gecko_bindings/sugar/ns_compatibility.rs +19 -0
  108. package/vendor/stylo/gecko_bindings/sugar/ns_style_auto_array.rs +111 -0
  109. package/vendor/stylo/gecko_bindings/sugar/origin_flags.rs +31 -0
  110. package/vendor/stylo/gecko_bindings/sugar/ownership.rs +70 -0
  111. package/vendor/stylo/gecko_bindings/sugar/refptr.rs +299 -0
  112. package/vendor/stylo/gecko_string_cache/mod.rs +543 -0
  113. package/vendor/stylo/gecko_string_cache/namespace.rs +106 -0
  114. package/vendor/stylo/global_style_data.rs +224 -0
  115. package/vendor/stylo/invalidation/element/document_state.rs +156 -0
  116. package/vendor/stylo/invalidation/element/element_wrapper.rs +432 -0
  117. package/vendor/stylo/invalidation/element/invalidation_map.rs +1631 -0
  118. package/vendor/stylo/invalidation/element/invalidator.rs +1470 -0
  119. package/vendor/stylo/invalidation/element/mod.rs +13 -0
  120. package/vendor/stylo/invalidation/element/relative_selector.rs +1399 -0
  121. package/vendor/stylo/invalidation/element/restyle_hints.rs +226 -0
  122. package/vendor/stylo/invalidation/element/state_and_attributes.rs +756 -0
  123. package/vendor/stylo/invalidation/media_queries.rs +144 -0
  124. package/vendor/stylo/invalidation/mod.rs +10 -0
  125. package/vendor/stylo/invalidation/stylesheets.rs +745 -0
  126. package/vendor/stylo/invalidation/viewport_units.rs +71 -0
  127. package/vendor/stylo/lib.rs +336 -0
  128. package/vendor/stylo/logical_geometry.rs +1684 -0
  129. package/vendor/stylo/macros.rs +70 -0
  130. package/vendor/stylo/matching.rs +1226 -0
  131. package/vendor/stylo/media_queries/media_list.rs +168 -0
  132. package/vendor/stylo/media_queries/media_query.rs +190 -0
  133. package/vendor/stylo/media_queries/mod.rs +13 -0
  134. package/vendor/stylo/parallel.rs +205 -0
  135. package/vendor/stylo/parser.rs +276 -0
  136. package/vendor/stylo/piecewise_linear.rs +282 -0
  137. package/vendor/stylo/prefs.rs +33 -0
  138. package/vendor/stylo/properties/build.py +119 -0
  139. package/vendor/stylo/properties/cascade.rs +2704 -0
  140. package/vendor/stylo/properties/computed_value_flags.rs +206 -0
  141. package/vendor/stylo/properties/counted_unknown_properties.py +104 -0
  142. package/vendor/stylo/properties/counter_style_descriptors.toml +45 -0
  143. package/vendor/stylo/properties/data.py +1375 -0
  144. package/vendor/stylo/properties/declaration_block.rs +1788 -0
  145. package/vendor/stylo/properties/font_face_descriptors.toml +50 -0
  146. package/vendor/stylo/properties/gecko.mako.rs +1555 -0
  147. package/vendor/stylo/properties/helpers/animated_properties.mako.rs +800 -0
  148. package/vendor/stylo/properties/helpers.mako.rs +812 -0
  149. package/vendor/stylo/properties/longhands.toml +4305 -0
  150. package/vendor/stylo/properties/mod.rs +1857 -0
  151. package/vendor/stylo/properties/properties.html.mako +31 -0
  152. package/vendor/stylo/properties/properties.mako.rs +3103 -0
  153. package/vendor/stylo/properties/property_descriptors.toml +18 -0
  154. package/vendor/stylo/properties/shorthands.rs +4241 -0
  155. package/vendor/stylo/properties/shorthands.toml +575 -0
  156. package/vendor/stylo/properties/vendored_python/mako-1.3.10-py3-none-any.whl +0 -0
  157. package/vendor/stylo/properties/vendored_python/markupsafe/LICENSE.txt +28 -0
  158. package/vendor/stylo/properties/vendored_python/markupsafe/__init__.py +384 -0
  159. package/vendor/stylo/properties/vendored_python/toml-0.10.2-py2.py3-none-any.whl +0 -0
  160. package/vendor/stylo/properties/view_transition_descriptors.toml +11 -0
  161. package/vendor/stylo/properties_and_values/mod.rs +12 -0
  162. package/vendor/stylo/properties_and_values/registry.rs +65 -0
  163. package/vendor/stylo/properties_and_values/rule.rs +331 -0
  164. package/vendor/stylo/properties_and_values/syntax/ascii.rs +60 -0
  165. package/vendor/stylo/properties_and_values/syntax/data_type.rs +146 -0
  166. package/vendor/stylo/properties_and_values/syntax/mod.rs +437 -0
  167. package/vendor/stylo/properties_and_values/value.rs +758 -0
  168. package/vendor/stylo/queries/condition.rs +996 -0
  169. package/vendor/stylo/queries/feature.rs +199 -0
  170. package/vendor/stylo/queries/feature_expression.rs +1170 -0
  171. package/vendor/stylo/queries/mod.rs +19 -0
  172. package/vendor/stylo/queries/values.rs +46 -0
  173. package/vendor/stylo/rule_cache.rs +267 -0
  174. package/vendor/stylo/rule_collector.rs +554 -0
  175. package/vendor/stylo/rule_tree/core.rs +787 -0
  176. package/vendor/stylo/rule_tree/level.rs +396 -0
  177. package/vendor/stylo/rule_tree/map.rs +201 -0
  178. package/vendor/stylo/rule_tree/mod.rs +427 -0
  179. package/vendor/stylo/rule_tree/source.rs +80 -0
  180. package/vendor/stylo/rule_tree/unsafe_box.rs +78 -0
  181. package/vendor/stylo/scoped_tls.rs +80 -0
  182. package/vendor/stylo/selector_map.rs +1050 -0
  183. package/vendor/stylo/selector_parser.rs +305 -0
  184. package/vendor/stylo/servo/animation.rs +1922 -0
  185. package/vendor/stylo/servo/attr.rs +714 -0
  186. package/vendor/stylo/servo/encoding_support.rs +81 -0
  187. package/vendor/stylo/servo/media_features.rs +254 -0
  188. package/vendor/stylo/servo/mod.rs +16 -0
  189. package/vendor/stylo/servo/restyle_damage.rs +215 -0
  190. package/vendor/stylo/servo/selector_parser.rs +1036 -0
  191. package/vendor/stylo/servo/shadow_parts.rs +207 -0
  192. package/vendor/stylo/shared_lock.rs +271 -0
  193. package/vendor/stylo/sharing/checks.rs +281 -0
  194. package/vendor/stylo/sharing/mod.rs +1000 -0
  195. package/vendor/stylo/simple_buckets_map.rs +52 -0
  196. package/vendor/stylo/str.rs +168 -0
  197. package/vendor/stylo/style_adjuster.rs +1086 -0
  198. package/vendor/stylo/style_resolver.rs +658 -0
  199. package/vendor/stylo/stylesheet_set.rs +658 -0
  200. package/vendor/stylo/stylesheets/appearance_base_rule.rs +51 -0
  201. package/vendor/stylo/stylesheets/container_rule.rs +769 -0
  202. package/vendor/stylo/stylesheets/counter_style_rule.rs +7 -0
  203. package/vendor/stylo/stylesheets/document_rule.rs +272 -0
  204. package/vendor/stylo/stylesheets/font_face_rule.rs +7 -0
  205. package/vendor/stylo/stylesheets/font_feature_values_rule.rs +481 -0
  206. package/vendor/stylo/stylesheets/font_palette_values_rule.rs +304 -0
  207. package/vendor/stylo/stylesheets/import_rule.rs +259 -0
  208. package/vendor/stylo/stylesheets/keyframes_rule.rs +733 -0
  209. package/vendor/stylo/stylesheets/layer_rule.rs +221 -0
  210. package/vendor/stylo/stylesheets/loader.rs +29 -0
  211. package/vendor/stylo/stylesheets/margin_rule.rs +190 -0
  212. package/vendor/stylo/stylesheets/media_rule.rs +191 -0
  213. package/vendor/stylo/stylesheets/mod.rs +918 -0
  214. package/vendor/stylo/stylesheets/namespace_rule.rs +43 -0
  215. package/vendor/stylo/stylesheets/nested_declarations_rule.rs +51 -0
  216. package/vendor/stylo/stylesheets/origin.rs +249 -0
  217. package/vendor/stylo/stylesheets/page_rule.rs +354 -0
  218. package/vendor/stylo/stylesheets/position_try_rule.rs +68 -0
  219. package/vendor/stylo/stylesheets/property_rule.rs +5 -0
  220. package/vendor/stylo/stylesheets/rule_list.rs +167 -0
  221. package/vendor/stylo/stylesheets/rule_parser.rs +1189 -0
  222. package/vendor/stylo/stylesheets/rules_iterator.rs +397 -0
  223. package/vendor/stylo/stylesheets/scope_rule.rs +511 -0
  224. package/vendor/stylo/stylesheets/starting_style_rule.rs +54 -0
  225. package/vendor/stylo/stylesheets/style_rule.rs +80 -0
  226. package/vendor/stylo/stylesheets/stylesheet.rs +570 -0
  227. package/vendor/stylo/stylesheets/supports_rule.rs +486 -0
  228. package/vendor/stylo/stylesheets/view_transition_rule.rs +81 -0
  229. package/vendor/stylo/stylist.rs +5076 -0
  230. package/vendor/stylo/thread_state.rs +87 -0
  231. package/vendor/stylo/traversal.rs +765 -0
  232. package/vendor/stylo/traversal_flags.rs +68 -0
  233. package/vendor/stylo/typed_om/mod.rs +981 -0
  234. package/vendor/stylo/typed_om/numeric.rs +128 -0
  235. package/vendor/stylo/typed_om/numeric_declaration.rs +93 -0
  236. package/vendor/stylo/typed_om/numeric_type.rs +640 -0
  237. package/vendor/stylo/typed_om/sum_value.rs +426 -0
  238. package/vendor/stylo/url/gecko.rs +367 -0
  239. package/vendor/stylo/url/mod.rs +71 -0
  240. package/vendor/stylo/url/servo.rs +239 -0
  241. package/vendor/stylo/use_counters/mod.rs +137 -0
  242. package/vendor/stylo/values/animated/color.rs +103 -0
  243. package/vendor/stylo/values/animated/effects.rs +26 -0
  244. package/vendor/stylo/values/animated/font.rs +37 -0
  245. package/vendor/stylo/values/animated/grid.rs +161 -0
  246. package/vendor/stylo/values/animated/lists.rs +141 -0
  247. package/vendor/stylo/values/animated/mod.rs +550 -0
  248. package/vendor/stylo/values/animated/svg.rs +46 -0
  249. package/vendor/stylo/values/animated/text.rs +58 -0
  250. package/vendor/stylo/values/animated/transform.rs +1592 -0
  251. package/vendor/stylo/values/computed/align.rs +90 -0
  252. package/vendor/stylo/values/computed/angle.rs +130 -0
  253. package/vendor/stylo/values/computed/animation.rs +124 -0
  254. package/vendor/stylo/values/computed/background.rs +13 -0
  255. package/vendor/stylo/values/computed/basic_shape.rs +267 -0
  256. package/vendor/stylo/values/computed/border.rs +163 -0
  257. package/vendor/stylo/values/computed/box.rs +267 -0
  258. package/vendor/stylo/values/computed/calc.rs +334 -0
  259. package/vendor/stylo/values/computed/color.rs +161 -0
  260. package/vendor/stylo/values/computed/column.rs +11 -0
  261. package/vendor/stylo/values/computed/corner_shape.rs +155 -0
  262. package/vendor/stylo/values/computed/counters.rs +26 -0
  263. package/vendor/stylo/values/computed/easing.rs +109 -0
  264. package/vendor/stylo/values/computed/effects.rs +30 -0
  265. package/vendor/stylo/values/computed/flex.rs +19 -0
  266. package/vendor/stylo/values/computed/font.rs +1517 -0
  267. package/vendor/stylo/values/computed/image.rs +273 -0
  268. package/vendor/stylo/values/computed/length.rs +576 -0
  269. package/vendor/stylo/values/computed/length_percentage.rs +1055 -0
  270. package/vendor/stylo/values/computed/list.rs +16 -0
  271. package/vendor/stylo/values/computed/mod.rs +1141 -0
  272. package/vendor/stylo/values/computed/motion.rs +73 -0
  273. package/vendor/stylo/values/computed/outline.rs +7 -0
  274. package/vendor/stylo/values/computed/page.rs +77 -0
  275. package/vendor/stylo/values/computed/param.rs +9 -0
  276. package/vendor/stylo/values/computed/percentage.rs +143 -0
  277. package/vendor/stylo/values/computed/position.rs +273 -0
  278. package/vendor/stylo/values/computed/ratio.rs +88 -0
  279. package/vendor/stylo/values/computed/rect.rs +19 -0
  280. package/vendor/stylo/values/computed/resolution.rs +76 -0
  281. package/vendor/stylo/values/computed/svg.rs +66 -0
  282. package/vendor/stylo/values/computed/table.rs +7 -0
  283. package/vendor/stylo/values/computed/text.rs +199 -0
  284. package/vendor/stylo/values/computed/time.rs +83 -0
  285. package/vendor/stylo/values/computed/transform.rs +559 -0
  286. package/vendor/stylo/values/computed/tree_counting.rs +30 -0
  287. package/vendor/stylo/values/computed/ui.rs +23 -0
  288. package/vendor/stylo/values/computed/url.rs +12 -0
  289. package/vendor/stylo/values/distance.rs +139 -0
  290. package/vendor/stylo/values/generics/animation.rs +363 -0
  291. package/vendor/stylo/values/generics/background.rs +65 -0
  292. package/vendor/stylo/values/generics/basic_shape.rs +1389 -0
  293. package/vendor/stylo/values/generics/border.rs +303 -0
  294. package/vendor/stylo/values/generics/box.rs +552 -0
  295. package/vendor/stylo/values/generics/calc.rs +2986 -0
  296. package/vendor/stylo/values/generics/color.rs +318 -0
  297. package/vendor/stylo/values/generics/column.rs +44 -0
  298. package/vendor/stylo/values/generics/counters.rs +320 -0
  299. package/vendor/stylo/values/generics/easing.rs +132 -0
  300. package/vendor/stylo/values/generics/effects.rs +131 -0
  301. package/vendor/stylo/values/generics/flex.rs +34 -0
  302. package/vendor/stylo/values/generics/font.rs +376 -0
  303. package/vendor/stylo/values/generics/grid.rs +962 -0
  304. package/vendor/stylo/values/generics/image.rs +653 -0
  305. package/vendor/stylo/values/generics/length.rs +656 -0
  306. package/vendor/stylo/values/generics/mod.rs +303 -0
  307. package/vendor/stylo/values/generics/motion.rs +274 -0
  308. package/vendor/stylo/values/generics/page.rs +167 -0
  309. package/vendor/stylo/values/generics/position.rs +669 -0
  310. package/vendor/stylo/values/generics/ratio.rs +88 -0
  311. package/vendor/stylo/values/generics/rect.rs +147 -0
  312. package/vendor/stylo/values/generics/size.rs +102 -0
  313. package/vendor/stylo/values/generics/svg.rs +226 -0
  314. package/vendor/stylo/values/generics/text.rs +268 -0
  315. package/vendor/stylo/values/generics/transform.rs +1157 -0
  316. package/vendor/stylo/values/generics/ui.rs +147 -0
  317. package/vendor/stylo/values/generics/url.rs +51 -0
  318. package/vendor/stylo/values/mod.rs +820 -0
  319. package/vendor/stylo/values/resolved/animation.rs +33 -0
  320. package/vendor/stylo/values/resolved/color.rs +53 -0
  321. package/vendor/stylo/values/resolved/counters.rs +45 -0
  322. package/vendor/stylo/values/resolved/mod.rs +316 -0
  323. package/vendor/stylo/values/specified/align.rs +711 -0
  324. package/vendor/stylo/values/specified/angle.rs +407 -0
  325. package/vendor/stylo/values/specified/animation.rs +921 -0
  326. package/vendor/stylo/values/specified/background.rs +270 -0
  327. package/vendor/stylo/values/specified/basic_shape.rs +986 -0
  328. package/vendor/stylo/values/specified/border.rs +430 -0
  329. package/vendor/stylo/values/specified/box.rs +2231 -0
  330. package/vendor/stylo/values/specified/calc.rs +1657 -0
  331. package/vendor/stylo/values/specified/color.rs +1210 -0
  332. package/vendor/stylo/values/specified/column.rs +11 -0
  333. package/vendor/stylo/values/specified/corner_shape.rs +152 -0
  334. package/vendor/stylo/values/specified/counters.rs +242 -0
  335. package/vendor/stylo/values/specified/easing.rs +225 -0
  336. package/vendor/stylo/values/specified/effects.rs +421 -0
  337. package/vendor/stylo/values/specified/flex.rs +42 -0
  338. package/vendor/stylo/values/specified/font.rs +2103 -0
  339. package/vendor/stylo/values/specified/frequency.rs +39 -0
  340. package/vendor/stylo/values/specified/grid.rs +407 -0
  341. package/vendor/stylo/values/specified/image.rs +1385 -0
  342. package/vendor/stylo/values/specified/intersection_observer.rs +80 -0
  343. package/vendor/stylo/values/specified/length.rs +2024 -0
  344. package/vendor/stylo/values/specified/list.rs +190 -0
  345. package/vendor/stylo/values/specified/mod.rs +531 -0
  346. package/vendor/stylo/values/specified/motion.rs +316 -0
  347. package/vendor/stylo/values/specified/number.rs +603 -0
  348. package/vendor/stylo/values/specified/outline.rs +69 -0
  349. package/vendor/stylo/values/specified/page.rs +94 -0
  350. package/vendor/stylo/values/specified/param.rs +121 -0
  351. package/vendor/stylo/values/specified/percentage.rs +364 -0
  352. package/vendor/stylo/values/specified/position.rs +2247 -0
  353. package/vendor/stylo/values/specified/ratio.rs +29 -0
  354. package/vendor/stylo/values/specified/rect.rs +28 -0
  355. package/vendor/stylo/values/specified/resolution.rs +237 -0
  356. package/vendor/stylo/values/specified/source_size_list.rs +135 -0
  357. package/vendor/stylo/values/specified/svg.rs +427 -0
  358. package/vendor/stylo/values/specified/svg_path.rs +1115 -0
  359. package/vendor/stylo/values/specified/table.rs +38 -0
  360. package/vendor/stylo/values/specified/text.rs +1561 -0
  361. package/vendor/stylo/values/specified/time.rs +313 -0
  362. package/vendor/stylo/values/specified/transform.rs +599 -0
  363. package/vendor/stylo/values/specified/tree_counting.rs +32 -0
  364. package/vendor/stylo/values/specified/ui.rs +344 -0
  365. package/vendor/stylo/values/specified/url.rs +12 -0
  366. package/vendor/stylo/values/tagged_numeric.rs +253 -0
  367. package/wasm/blitz_pdf.d.ts +67 -0
  368. package/wasm/blitz_pdf.js +699 -0
  369. package/wasm/blitz_pdf_bg.wasm +0 -0
  370. package/wasm/blitz_pdf_bg.wasm.d.ts +20 -0
@@ -0,0 +1,1555 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ // `data` comes from components/style/properties.mako.rs; see build.rs for more details.
6
+
7
+ <%! from data import to_camel_case, to_camel_case_lower, Keyword, SYSTEM_FONT_LONGHANDS %>
8
+ <%namespace name="helpers" file="/helpers.mako.rs" />
9
+
10
+ use crate::Atom;
11
+ use crate::logical_geometry::PhysicalSide;
12
+ use crate::computed_value_flags::*;
13
+ use crate::custom_properties::ComputedCustomProperties;
14
+ use crate::device::Device;
15
+ use crate::gecko_bindings::bindings;
16
+ % for style_struct in data.style_structs:
17
+ use crate::gecko_bindings::bindings::Gecko_Construct_Default_${style_struct.gecko_ffi_name};
18
+ use crate::gecko_bindings::bindings::Gecko_CopyConstruct_${style_struct.gecko_ffi_name};
19
+ use crate::gecko_bindings::bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
20
+ % endfor
21
+ use crate::gecko_bindings::bindings::Gecko_EnsureImageLayersLength;
22
+ use crate::gecko_bindings::bindings::Gecko_nsStyleFont_SetLang;
23
+ use crate::gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom;
24
+ use crate::gecko_bindings::structs::{self, PseudoStyleType};
25
+ use crate::gecko::data::PerDocumentStyleData;
26
+ use crate::logical_geometry::WritingMode;
27
+ use crate::properties::longhands;
28
+ use crate::rule_tree::StrongRuleNode;
29
+ use crate::selector_parser::PseudoElement;
30
+ use servo_arc::{Arc, UniqueArc};
31
+ use std::mem::{forget, MaybeUninit, ManuallyDrop};
32
+ use std::{ops, ptr};
33
+ use crate::values;
34
+ use crate::values::computed::{Time, Zoom};
35
+ use crate::values::computed::font::FontSize;
36
+ use crate::dom::AttributeReferences;
37
+
38
+
39
+ pub mod style_structs {
40
+ % for style_struct in data.style_structs:
41
+ pub use super::${style_struct.gecko_struct_name} as ${style_struct.name};
42
+
43
+ unsafe impl Send for ${style_struct.name} {}
44
+ unsafe impl Sync for ${style_struct.name} {}
45
+ % endfor
46
+ }
47
+
48
+ /// FIXME(emilio): This is completely duplicated with the other properties code.
49
+ pub type ComputedValuesInner = structs::ServoComputedData;
50
+
51
+ #[repr(C)]
52
+ pub struct ComputedValues(structs::mozilla::ComputedStyle);
53
+
54
+ impl ComputedValues {
55
+ #[inline]
56
+ pub (crate) fn as_gecko_computed_style(&self) -> &structs::ComputedStyle {
57
+ &self.0
58
+ }
59
+
60
+ #[allow(clippy::too_many_arguments)]
61
+ pub fn new(
62
+ pseudo: Option<&PseudoElement>,
63
+ custom_properties: ComputedCustomProperties,
64
+ attributes_referenced: AttributeReferences,
65
+ writing_mode: WritingMode,
66
+ effective_zoom: Zoom,
67
+ flags: ComputedValueFlags,
68
+ rules: Option<StrongRuleNode>,
69
+ visited_style: Option<Arc<ComputedValues>>,
70
+ % for style_struct in data.style_structs:
71
+ ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
72
+ % endfor
73
+ ) -> Arc<Self> {
74
+ ComputedValuesInner::new(
75
+ pseudo,
76
+ custom_properties,
77
+ attributes_referenced,
78
+ writing_mode,
79
+ effective_zoom,
80
+ flags,
81
+ rules,
82
+ visited_style,
83
+ % for style_struct in data.style_structs:
84
+ ${style_struct.ident},
85
+ % endfor
86
+ ).into_outer()
87
+ }
88
+
89
+ pub fn default_values(doc: &structs::Document) -> Arc<Self> {
90
+ ComputedValuesInner::new(
91
+ /* pseudo = */ None,
92
+ ComputedCustomProperties::default(),
93
+ AttributeReferences::default(),
94
+ WritingMode::empty(), // FIXME(bz): This seems dubious
95
+ Zoom::ONE,
96
+ ComputedValueFlags::empty(),
97
+ /* rules = */ None,
98
+ /* visited_style = */ None,
99
+ % for style_struct in data.style_structs:
100
+ style_structs::${style_struct.name}::default(doc),
101
+ % endfor
102
+ ).into_outer()
103
+ }
104
+
105
+ /// Converts the computed values to an Arc<> from a reference.
106
+ pub fn to_arc(&self) -> Arc<Self> {
107
+ // SAFETY: We're guaranteed to be allocated as an Arc<> since the
108
+ // functions above are the only ones that create ComputedValues
109
+ // instances in Gecko (and that must be the case since ComputedValues'
110
+ // member is private).
111
+ unsafe { Arc::from_raw_addrefed(self) }
112
+ }
113
+
114
+ #[inline]
115
+ pub fn is_pseudo_style(&self) -> bool {
116
+ self.pseudo_type != PseudoStyleType::NotPseudo
117
+ }
118
+
119
+ #[inline]
120
+ pub fn pseudo(&self) -> Option<PseudoElement> {
121
+ if !self.is_pseudo_style() {
122
+ return None;
123
+ }
124
+ PseudoElement::from_pseudo_type(self.pseudo_type, None)
125
+ }
126
+
127
+ #[inline]
128
+ pub fn is_first_line_style(&self) -> bool {
129
+ self.pseudo() == Some(PseudoElement::FirstLine)
130
+ }
131
+
132
+ /// Returns true if the display property is changed from 'none' to others.
133
+ pub fn is_display_property_changed_from_none(
134
+ &self,
135
+ old_values: Option<&ComputedValues>
136
+ ) -> bool {
137
+ use crate::properties::longhands::display::computed_value::T as Display;
138
+
139
+ old_values.is_some_and(|old| {
140
+ let old_display_style = old.get_box().clone_display();
141
+ let new_display_style = self.get_box().clone_display();
142
+ old_display_style == Display::None &&
143
+ new_display_style != Display::None
144
+ })
145
+ }
146
+
147
+ /// Calls the given function for each cached lazy pseudo-element style.
148
+ pub fn each_cached_lazy_pseudo<F>(&self, mut f: F)
149
+ where
150
+ F: FnMut(&Self),
151
+ {
152
+ thin_vec::auto_thin_vec!(let array: [*const structs::ComputedStyle; 4]);
153
+ unsafe {
154
+ bindings::Gecko_GetCachedLazyPseudoStyles(
155
+ self.as_gecko_computed_style(),
156
+ array.as_mut().as_mut_ptr(),
157
+ );
158
+ }
159
+ for style in array.iter() {
160
+ // ComputedValues is a newtype around ComputedStyle, so same layout
161
+ let values: &ComputedValues = unsafe { &*(*style as *const ComputedValues) };
162
+ f(values);
163
+ }
164
+ }
165
+
166
+ }
167
+
168
+ impl Drop for ComputedValues {
169
+ fn drop(&mut self) {
170
+ // XXX this still relies on the destructor of ComputedValuesInner to run on the rust side,
171
+ // that's pretty wild.
172
+ unsafe {
173
+ bindings::Gecko_ComputedStyle_Destroy(&mut self.0);
174
+ }
175
+ }
176
+ }
177
+
178
+ unsafe impl Sync for ComputedValues {}
179
+ unsafe impl Send for ComputedValues {}
180
+
181
+ impl Drop for ComputedValuesInner {
182
+ fn drop(&mut self) {
183
+ % for style_struct in data.style_structs:
184
+ let _ = unsafe { Arc::from_raw(self.${style_struct.name_lower}_ptr()) };
185
+ % endfor
186
+ if !self.visited_style.is_null() {
187
+ let _ = unsafe { Arc::from_raw(self.visited_style_ptr()) };
188
+ }
189
+ }
190
+ }
191
+
192
+ impl ComputedValuesInner {
193
+ #[allow(clippy::too_many_arguments)]
194
+ pub fn new(
195
+ pseudo: Option<&PseudoElement>,
196
+ custom_properties: ComputedCustomProperties,
197
+ attribute_references: AttributeReferences,
198
+ writing_mode: WritingMode,
199
+ effective_zoom: Zoom,
200
+ flags: ComputedValueFlags,
201
+ rules: Option<StrongRuleNode>,
202
+ visited_style: Option<Arc<ComputedValues>>,
203
+ % for style_struct in data.style_structs:
204
+ ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
205
+ % endfor
206
+ ) -> Self {
207
+ let pseudo_type = match pseudo {
208
+ Some(p) => p.pseudo_type(),
209
+ None => PseudoStyleType::NotPseudo,
210
+ };
211
+ Self {
212
+ custom_properties,
213
+ attribute_references,
214
+ writing_mode,
215
+ rules,
216
+ visited_style: visited_style.map_or(ptr::null(), Arc::into_raw) as *const _,
217
+ flags,
218
+ pseudo_type,
219
+ effective_zoom,
220
+ % for style_struct in data.style_structs:
221
+ ${style_struct.gecko_name}: Arc::into_raw(${style_struct.ident}) as *const _,
222
+ % endfor
223
+ }
224
+ }
225
+
226
+ // Share ComputedValues but with different flags.
227
+ pub fn clone_with_flags(&self, flags: ComputedValueFlags, pseudo: Option<&PseudoElement>) -> Arc<ComputedValues> {
228
+ Self::new(
229
+ pseudo,
230
+ self.custom_properties.clone(),
231
+ self.attribute_references.clone(),
232
+ self.writing_mode,
233
+ self.effective_zoom,
234
+ flags,
235
+ self.rules.clone(),
236
+ if self.visited_style.is_null() {
237
+ None
238
+ } else {
239
+ Some(unsafe { Arc::from_raw_addrefed(self.visited_style as *const _) })
240
+ },
241
+ % for style_struct in data.style_structs:
242
+ unsafe { Arc::from_raw_addrefed(self.${style_struct.gecko_name} as *const _) },
243
+ % endfor
244
+ ).into_outer()
245
+ }
246
+
247
+ fn into_outer(self) -> Arc<ComputedValues> {
248
+ unsafe {
249
+ let mut arc = UniqueArc::<ComputedValues>::new_uninit();
250
+ bindings::Gecko_ComputedStyle_Init(
251
+ arc.as_mut_ptr() as *mut _,
252
+ &self
253
+ );
254
+ // We're simulating move semantics by having C++ do a memcpy and
255
+ // then forgetting it on this end.
256
+ forget(self);
257
+ UniqueArc::assume_init(arc).shareable()
258
+ }
259
+ }
260
+ }
261
+
262
+ impl ops::Deref for ComputedValues {
263
+ type Target = ComputedValuesInner;
264
+ #[inline]
265
+ fn deref(&self) -> &ComputedValuesInner {
266
+ &self.0.mSource
267
+ }
268
+ }
269
+
270
+ impl ops::DerefMut for ComputedValues {
271
+ #[inline]
272
+ fn deref_mut(&mut self) -> &mut ComputedValuesInner {
273
+ &mut self.0.mSource
274
+ }
275
+ }
276
+
277
+ impl ComputedValuesInner {
278
+ /// Returns true if the value of the `content` property would make a
279
+ /// pseudo-element not rendered.
280
+ #[inline]
281
+ pub fn ineffective_content_property(&self) -> bool {
282
+ self.get_counters().ineffective_content_property()
283
+ }
284
+
285
+ #[inline]
286
+ fn visited_style_ptr(&self) -> *const ComputedValues {
287
+ self.visited_style as *const _
288
+ }
289
+
290
+ /// Returns the visited style, if any.
291
+ pub fn visited_style(&self) -> Option<&ComputedValues> {
292
+ unsafe { self.visited_style_ptr().as_ref() }
293
+ }
294
+
295
+ % for style_struct in data.style_structs:
296
+ #[inline]
297
+ fn ${style_struct.name_lower}_ptr(&self) -> *const style_structs::${style_struct.name} {
298
+ // This is sound because the wrapper we create is repr(transparent).
299
+ self.${style_struct.gecko_name} as *const _
300
+ }
301
+
302
+ #[inline]
303
+ pub fn get_${style_struct.name_lower}(&self) -> &style_structs::${style_struct.name} {
304
+ unsafe { &*self.${style_struct.name_lower}_ptr() }
305
+ }
306
+ % endfor
307
+ }
308
+
309
+ <%def name="impl_simple_setter(ident, gecko_ffi_name)">
310
+ #[allow(non_snake_case)]
311
+ pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
312
+ ${set_gecko_property(gecko_ffi_name, "From::from(v)")}
313
+ }
314
+ </%def>
315
+
316
+ <%def name="impl_simple_eq(ident, gecko_ffi_name)">
317
+ #[allow(non_snake_case)]
318
+ pub fn ${ident}_equals(&self, other: &Self) -> bool {
319
+ self.${gecko_ffi_name} == other.${gecko_ffi_name}
320
+ }
321
+ </%def>
322
+
323
+ <%def name="impl_fallback_eq(ident)">
324
+ #[allow(non_snake_case)]
325
+ pub fn ${ident}_equals(&self, other: &Self) -> bool {
326
+ // TODO: Could be more efficient
327
+ self.clone_${ident}() == other.clone_${ident}()
328
+ }
329
+ </%def>
330
+
331
+ <%def name="impl_simple_clone(ident, gecko_ffi_name)">
332
+ #[allow(non_snake_case)]
333
+ pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
334
+ From::from(self.${gecko_ffi_name}.clone())
335
+ }
336
+ </%def>
337
+
338
+ <%def name="impl_physical_sides(ident, props)">
339
+ pub fn get_${ident}(&self, s: PhysicalSide) -> &longhands::${data.longhands_by_name[props[0]].ident}::computed_value::T {
340
+ match s {
341
+ PhysicalSide::Top => &self.${data.longhands_by_name[props[0]].gecko_ffi_name},
342
+ PhysicalSide::Right => &self.${data.longhands_by_name[props[1]].gecko_ffi_name},
343
+ PhysicalSide::Bottom => &self.${data.longhands_by_name[props[2]].gecko_ffi_name},
344
+ PhysicalSide::Left => &self.${data.longhands_by_name[props[3]].gecko_ffi_name},
345
+ }
346
+ }
347
+ pub fn set_${ident}(&mut self, s: PhysicalSide, v: longhands::${data.longhands_by_name[props[0]].ident}::computed_value::T) {
348
+ match s {
349
+ PhysicalSide::Top => self.set_${data.longhands_by_name[props[0]].ident}(v),
350
+ PhysicalSide::Right => self.set_${data.longhands_by_name[props[1]].ident}(v),
351
+ PhysicalSide::Bottom => self.set_${data.longhands_by_name[props[2]].ident}(v),
352
+ PhysicalSide::Left => self.set_${data.longhands_by_name[props[3]].ident}(v),
353
+ }
354
+ }
355
+ </%def>
356
+
357
+ <%def name="impl_simple_copy(ident, gecko_ffi_name, *kwargs)">
358
+ #[allow(non_snake_case)]
359
+ pub fn copy_${ident}_from(&mut self, other: &Self) {
360
+ self.${gecko_ffi_name} = other.${gecko_ffi_name}.clone();
361
+ }
362
+
363
+ #[allow(non_snake_case)]
364
+ pub fn reset_${ident}(&mut self, other: &Self) {
365
+ self.copy_${ident}_from(other)
366
+ }
367
+ </%def>
368
+
369
+ <%!
370
+ def get_gecko_property(ffi_name, self_param = "self"):
371
+ return "%s.%s" % (self_param, ffi_name)
372
+
373
+ def set_gecko_property(ffi_name, expr):
374
+ return "self.%s = %s;" % (ffi_name, expr)
375
+ %>
376
+
377
+ <%def name="impl_keyword_setter(ident, gecko_ffi_name, keyword, cast_type='u8')">
378
+ #[allow(non_snake_case)]
379
+ pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
380
+ use crate::properties::longhands::${ident}::computed_value::T as Keyword;
381
+ // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
382
+ let result = match v {
383
+ % for value in keyword.values_for('gecko'):
384
+ Keyword::${to_camel_case(value)} =>
385
+ structs::${keyword.gecko_constant(value)} ${keyword.maybe_cast(cast_type)},
386
+ % endfor
387
+ };
388
+ ${set_gecko_property(gecko_ffi_name, "result")}
389
+ }
390
+ </%def>
391
+
392
+ <%def name="impl_keyword_clone(ident, gecko_ffi_name, keyword, cast_type='u8')">
393
+ #[allow(non_snake_case)]
394
+ pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
395
+ use crate::properties::longhands::${ident}::computed_value::T as Keyword;
396
+ // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
397
+
398
+ // Some constant macros in the gecko are defined as negative integer(e.g. font-width).
399
+ // And they are convert to signed integer in Rust bindings. We need to cast then
400
+ // as signed type when we have both signed/unsigned integer in order to use them
401
+ // as match's arms.
402
+ // Also, to use same implementation here we use casted constant if we have only singed values.
403
+ % if keyword.gecko_enum_prefix is None:
404
+ % for value in keyword.values_for('gecko'):
405
+ const ${keyword.casted_constant_name(value, cast_type)} : ${cast_type} =
406
+ structs::${keyword.gecko_constant(value)} as ${cast_type};
407
+ % endfor
408
+
409
+ match ${get_gecko_property(gecko_ffi_name)} as ${cast_type} {
410
+ % for value in keyword.values_for('gecko'):
411
+ ${keyword.casted_constant_name(value, cast_type)} => Keyword::${to_camel_case(value)},
412
+ % endfor
413
+ % if keyword.gecko_inexhaustive:
414
+ _ => panic!("Found unexpected value in style struct for ${ident} property"),
415
+ % endif
416
+ }
417
+ % else:
418
+ match ${get_gecko_property(gecko_ffi_name)} {
419
+ % for value in keyword.values_for('gecko'):
420
+ structs::${keyword.gecko_constant(value)} => Keyword::${to_camel_case(value)},
421
+ % endfor
422
+ % if keyword.gecko_inexhaustive:
423
+ _ => panic!("Found unexpected value in style struct for ${ident} property"),
424
+ % endif
425
+ }
426
+ % endif
427
+ }
428
+ </%def>
429
+
430
+ <%def name="impl_keyword(ident, gecko_ffi_name, keyword, cast_type='u8', **kwargs)">
431
+ <%call expr="impl_keyword_setter(ident, gecko_ffi_name, keyword, cast_type, **kwargs)"></%call>
432
+ <%call expr="impl_simple_copy(ident, gecko_ffi_name, **kwargs)"></%call>
433
+ <%call expr="impl_keyword_clone(ident, gecko_ffi_name, keyword, cast_type)"></%call>
434
+ <%call expr="impl_simple_eq(ident, gecko_ffi_name)"></%call>
435
+ </%def>
436
+
437
+ <%def name="impl_simple(ident, gecko_ffi_name)">
438
+ <%call expr="impl_simple_setter(ident, gecko_ffi_name)"></%call>
439
+ <%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
440
+ <%call expr="impl_simple_clone(ident, gecko_ffi_name)"></%call>
441
+ <%call expr="impl_simple_eq(ident, gecko_ffi_name)"></%call>
442
+ </%def>
443
+
444
+ <%def name="impl_border_width(ident, gecko_ffi_name, inherit_from)">
445
+ #[allow(non_snake_case)]
446
+ pub fn set_${ident}(&mut self, v: Au) {
447
+ let value = v.0;
448
+ self.${inherit_from} = value;
449
+ self.${gecko_ffi_name} = value;
450
+ }
451
+
452
+ #[allow(non_snake_case)]
453
+ pub fn copy_${ident}_from(&mut self, other: &Self) {
454
+ self.${inherit_from} = other.${inherit_from};
455
+ // NOTE: This is needed to easily handle the `unset` and `initial`
456
+ // keywords, which are implemented calling this function.
457
+ //
458
+ // In practice, this means that we may have an incorrect value here, but
459
+ // we'll adjust that properly in the style fixup phase.
460
+ //
461
+ // FIXME(emilio): We could clean this up a bit special-casing the reset_
462
+ // function below.
463
+ self.${gecko_ffi_name} = other.${inherit_from};
464
+ }
465
+
466
+ #[allow(non_snake_case)]
467
+ pub fn reset_${ident}(&mut self, other: &Self) {
468
+ self.copy_${ident}_from(other)
469
+ }
470
+
471
+ #[allow(non_snake_case)]
472
+ pub fn clone_${ident}(&self) -> Au {
473
+ Au(self.${gecko_ffi_name})
474
+ }
475
+
476
+ ${impl_simple_eq(ident, gecko_ffi_name)}
477
+ </%def>
478
+
479
+ <%def name="impl_style_struct(style_struct)">
480
+ /// A wrapper for ${style_struct.gecko_ffi_name}, to be able to manually construct / destruct /
481
+ /// clone it.
482
+ #[repr(transparent)]
483
+ pub struct ${style_struct.gecko_struct_name}(ManuallyDrop<structs::${style_struct.gecko_ffi_name}>);
484
+
485
+ impl ops::Deref for ${style_struct.gecko_struct_name} {
486
+ type Target = structs::${style_struct.gecko_ffi_name};
487
+ #[inline]
488
+ fn deref(&self) -> &Self::Target {
489
+ &self.0
490
+ }
491
+ }
492
+
493
+ impl ops::DerefMut for ${style_struct.gecko_struct_name} {
494
+ #[inline]
495
+ fn deref_mut(&mut self) -> &mut <Self as ops::Deref>::Target {
496
+ &mut self.0
497
+ }
498
+ }
499
+
500
+ impl ${style_struct.gecko_struct_name} {
501
+ #[allow(dead_code, unused_variables)]
502
+ pub fn default(document: &structs::Document) -> Arc<Self> {
503
+ % if style_struct.document_dependent:
504
+ unsafe {
505
+ let mut result = UniqueArc::<Self>::new_uninit();
506
+ Gecko_Construct_Default_${style_struct.gecko_ffi_name}(
507
+ result.as_mut_ptr() as *mut _,
508
+ document,
509
+ );
510
+ UniqueArc::assume_init(result).shareable()
511
+ }
512
+ % else:
513
+ static DEFAULT: std::sync::LazyLock<Arc<${style_struct.gecko_struct_name}>> = std::sync::LazyLock::new(|| unsafe {
514
+ let mut result = UniqueArc::<${style_struct.gecko_struct_name}>::new_uninit();
515
+ Gecko_Construct_Default_${style_struct.gecko_ffi_name}(
516
+ result.as_mut_ptr() as *mut _,
517
+ std::ptr::null(),
518
+ );
519
+ let arc = UniqueArc::assume_init(result).shareable();
520
+ arc.mark_as_intentionally_leaked();
521
+ arc
522
+ });
523
+ DEFAULT.clone()
524
+ % endif
525
+ }
526
+ }
527
+
528
+ impl Drop for ${style_struct.gecko_struct_name} {
529
+ fn drop(&mut self) {
530
+ unsafe {
531
+ Gecko_Destroy_${style_struct.gecko_ffi_name}(&mut **self);
532
+ }
533
+ }
534
+ }
535
+ impl Clone for ${style_struct.gecko_struct_name} {
536
+ fn clone(&self) -> Self {
537
+ unsafe {
538
+ let mut result = MaybeUninit::<Self>::uninit();
539
+ // FIXME(bug 1595895): Zero the memory to keep valgrind happy, but
540
+ // these looks like Valgrind false-positives at a quick glance.
541
+ ptr::write_bytes::<Self>(result.as_mut_ptr(), 0, 1);
542
+ Gecko_CopyConstruct_${style_struct.gecko_ffi_name}(result.as_mut_ptr() as *mut _, &**self);
543
+ result.assume_init()
544
+ }
545
+ }
546
+ }
547
+ </%def>
548
+
549
+ <%def name="impl_font_settings(ident, gecko_type, tag_type, value_type, gecko_value_type)">
550
+ <% gecko_ffi_name = to_camel_case_lower(ident) %>
551
+
552
+ pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
553
+ let iter = v.0.iter().map(|other| structs::${gecko_type} {
554
+ mTag: other.tag.0,
555
+ mValue: other.value as ${gecko_value_type},
556
+ });
557
+ self.mFont.${gecko_ffi_name}.clear();
558
+ self.mFont.${gecko_ffi_name}.extend(iter);
559
+ }
560
+
561
+ ${impl_simple_copy(ident, "mFont." + gecko_ffi_name)}
562
+ ${impl_fallback_eq(ident)}
563
+
564
+ pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
565
+ use crate::values::generics::font::{FontSettings, FontTag, ${tag_type}};
566
+
567
+ FontSettings(
568
+ self.mFont.${gecko_ffi_name}.iter().map(|gecko_font_setting| {
569
+ ${tag_type} {
570
+ tag: FontTag(gecko_font_setting.mTag),
571
+ value: gecko_font_setting.mValue as ${value_type},
572
+ }
573
+ }).collect()
574
+ )
575
+ }
576
+ </%def>
577
+
578
+ <%def name="impl_trait(style_struct_name, skip_longhands='')">
579
+ <%
580
+ style_struct = next(x for x in data.style_structs if x.name == style_struct_name)
581
+ longhands = [x for x in style_struct.longhands
582
+ if not (skip_longhands == "*" or x.name in skip_longhands.split())]
583
+
584
+ def longhand_method(longhand):
585
+ args = dict(ident=longhand.ident, gecko_ffi_name=longhand.gecko_ffi_name)
586
+
587
+ if longhand.logical:
588
+ return
589
+ # get the method and pass additional keyword or type-specific arguments
590
+ if longhand.keyword:
591
+ method = impl_keyword
592
+ args.update(keyword=longhand.keyword)
593
+ if "font" in longhand.ident:
594
+ args.update(cast_type=longhand.cast_type)
595
+ else:
596
+ method = impl_simple
597
+
598
+ method(**args)
599
+ %>
600
+ impl ${style_struct.gecko_struct_name} {
601
+ /*
602
+ * Manually-Implemented Methods.
603
+ */
604
+ ${caller.body().strip()}
605
+
606
+ /*
607
+ * Auto-Generated Methods.
608
+ */
609
+ <%
610
+ for longhand in longhands:
611
+ longhand_method(longhand)
612
+ %>
613
+ }
614
+ </%def>
615
+
616
+ <%!
617
+ class Side(object):
618
+ def __init__(self, name, index):
619
+ self.name = name
620
+ self.ident = name.lower()
621
+ self.index = index
622
+
623
+ SIDES = [Side("Top", 0), Side("Right", 1), Side("Bottom", 2), Side("Left", 3)]
624
+ %>
625
+
626
+ #[allow(dead_code)]
627
+ fn static_assert() {
628
+ // Note: using the above technique with an enum hits a rust bug when |structs| is in a different crate.
629
+ % for side in SIDES:
630
+ { const DETAIL: u32 = [0][(structs::Side::eSide${side.name} as usize != ${side.index}) as usize]; let _ = DETAIL; }
631
+ % endfor
632
+ }
633
+
634
+
635
+ <%self:impl_trait style_struct_name="Border">
636
+ </%self:impl_trait>
637
+
638
+ <%self:impl_trait style_struct_name="Margin">
639
+ ${impl_physical_sides("margin", ["margin-top", "margin-right", "margin-bottom", "margin-left"])}
640
+ </%self:impl_trait>
641
+ <%self:impl_trait style_struct_name="Padding"></%self:impl_trait>
642
+ <%self:impl_trait style_struct_name="Page"></%self:impl_trait>
643
+
644
+ <%self:impl_trait style_struct_name="Position">
645
+ ${impl_physical_sides("inset", ["top", "right", "bottom", "left"])}
646
+ pub fn set_computed_justify_items(&mut self, v: values::specified::JustifyItems) {
647
+ debug_assert_ne!(v, values::specified::JustifyItems::legacy());
648
+ self.mJustifyItems.computed = v;
649
+ }
650
+ </%self:impl_trait>
651
+
652
+ <%self:impl_trait style_struct_name="Outline">
653
+ </%self:impl_trait>
654
+
655
+ <% skip_font_longhands = """font-size -x-lang font-feature-settings font-variation-settings""" %>
656
+ <%self:impl_trait style_struct_name="Font"
657
+ skip_longhands="${skip_font_longhands}">
658
+
659
+ // Negative numbers are invalid at parse time, but <integer> is still an
660
+ // i32.
661
+ <% impl_font_settings("font_feature_settings", "gfxFontFeature", "FeatureTagValue", "i32", "u32") %>
662
+ <% impl_font_settings("font_variation_settings", "gfxFontVariation", "VariationValue", "f32", "f32") %>
663
+
664
+ pub fn unzoom_fonts(&mut self, device: &Device) {
665
+ use crate::values::generics::NonNegative;
666
+ self.mSize = NonNegative(device.unzoom_text(self.mSize.0));
667
+ self.mScriptUnconstrainedSize = NonNegative(device.unzoom_text(self.mScriptUnconstrainedSize.0));
668
+ self.mFont.size = NonNegative(device.unzoom_text(self.mFont.size.0));
669
+ }
670
+
671
+ pub fn copy_font_size_from(&mut self, other: &Self) {
672
+ self.mScriptUnconstrainedSize = other.mScriptUnconstrainedSize;
673
+
674
+ self.mSize = other.mScriptUnconstrainedSize;
675
+ // NOTE: Intentionally not copying from mFont.size. The cascade process
676
+ // recomputes the used size as needed.
677
+ self.mFont.size = other.mSize;
678
+ self.mFontSizeKeyword = other.mFontSizeKeyword;
679
+
680
+ // TODO(emilio): Should we really copy over these two?
681
+ self.mFontSizeFactor = other.mFontSizeFactor;
682
+ self.mFontSizeOffset = other.mFontSizeOffset;
683
+ }
684
+
685
+ pub fn reset_font_size(&mut self, other: &Self) {
686
+ self.copy_font_size_from(other)
687
+ }
688
+
689
+ pub fn font_size_equals(&self, other: &Self) -> bool {
690
+ self.mSize == other.mSize
691
+ }
692
+
693
+ pub fn set_font_size(&mut self, v: FontSize) {
694
+ let computed_size = v.computed_size;
695
+ self.mScriptUnconstrainedSize = computed_size;
696
+
697
+ // These two may be changed from Cascade::fixup_font_stuff.
698
+ self.mSize = computed_size;
699
+ // NOTE: Intentionally not copying from used_size. The cascade process
700
+ // recomputes the used size as needed.
701
+ self.mFont.size = computed_size;
702
+
703
+ self.mFontSizeKeyword = v.keyword_info.kw;
704
+ self.mFontSizeFactor = v.keyword_info.factor;
705
+ self.mFontSizeOffset = v.keyword_info.offset;
706
+ }
707
+
708
+ pub fn clone_font_size(&self) -> FontSize {
709
+ use crate::values::specified::font::KeywordInfo;
710
+
711
+ FontSize {
712
+ computed_size: self.mSize,
713
+ used_size: self.mFont.size,
714
+ keyword_info: KeywordInfo {
715
+ kw: self.mFontSizeKeyword,
716
+ factor: self.mFontSizeFactor,
717
+ offset: self.mFontSizeOffset,
718
+ }
719
+ }
720
+ }
721
+
722
+ #[allow(non_snake_case)]
723
+ pub fn set__x_lang(&mut self, v: longhands::_x_lang::computed_value::T) {
724
+ let ptr = v.0.as_ptr();
725
+ forget(v);
726
+ unsafe {
727
+ Gecko_nsStyleFont_SetLang(&mut **self, ptr);
728
+ }
729
+ }
730
+
731
+ #[allow(non_snake_case)]
732
+ pub fn copy__x_lang_from(&mut self, other: &Self) {
733
+ unsafe {
734
+ Gecko_nsStyleFont_CopyLangFrom(&mut **self, &**other);
735
+ }
736
+ }
737
+
738
+ #[allow(non_snake_case)]
739
+ pub fn reset__x_lang(&mut self, other: &Self) {
740
+ self.copy__x_lang_from(other)
741
+ }
742
+
743
+ #[allow(non_snake_case)]
744
+ pub fn clone__x_lang(&self) -> longhands::_x_lang::computed_value::T {
745
+ longhands::_x_lang::computed_value::T(unsafe {
746
+ Atom::from_raw(self.mLanguage.mRawPtr)
747
+ })
748
+ }
749
+
750
+ #[allow(non_snake_case)]
751
+ pub fn _x_lang_equals(&self, other: &Self) -> bool {
752
+ self.mLanguage.mRawPtr == other.mLanguage.mRawPtr
753
+ }
754
+ </%self:impl_trait>
755
+
756
+
757
+ <%def name="impl_coordinated_property(type, ident, gecko_ffi_name)">
758
+ #[allow(non_snake_case)]
759
+ pub fn set_${type}_${ident}<I>(&mut self, v: I)
760
+ where
761
+ I: IntoIterator<Item = longhands::${type}_${ident}::computed_value::single_value::T>,
762
+ I::IntoIter: ExactSizeIterator + Clone
763
+ {
764
+ let v = v.into_iter();
765
+ debug_assert_ne!(v.len(), 0);
766
+ let input_len = v.len();
767
+ self.m${to_camel_case(type)}s.ensure_len(input_len);
768
+
769
+ self.m${to_camel_case(type)}${gecko_ffi_name}Count = input_len as u32;
770
+ for (gecko, servo) in self.m${to_camel_case(type)}s.iter_mut().take(input_len as usize).zip(v) {
771
+ gecko.m${gecko_ffi_name} = servo;
772
+ }
773
+ }
774
+ #[allow(non_snake_case)]
775
+ pub fn ${type}_${ident}_at(&self, index: usize)
776
+ -> longhands::${type}_${ident}::computed_value::SingleComputedValue {
777
+ self.m${to_camel_case(type)}s[index % self.${type}_${ident}_count()].m${gecko_ffi_name}.clone()
778
+ }
779
+ #[allow(non_snake_case)]
780
+ pub fn copy_${type}_${ident}_from(&mut self, other: &Self) {
781
+ self.m${to_camel_case(type)}s.ensure_len(other.m${to_camel_case(type)}s.len());
782
+
783
+ let count = other.m${to_camel_case(type)}${gecko_ffi_name}Count;
784
+ self.m${to_camel_case(type)}${gecko_ffi_name}Count = count;
785
+
786
+ let iter = self.m${to_camel_case(type)}s.iter_mut().take(count as usize).zip(
787
+ other.m${to_camel_case(type)}s.iter()
788
+ );
789
+
790
+ for (ours, others) in iter {
791
+ ours.m${gecko_ffi_name} = others.m${gecko_ffi_name}.clone();
792
+ }
793
+ }
794
+ #[allow(non_snake_case)]
795
+ pub fn reset_${type}_${ident}(&mut self, other: &Self) {
796
+ self.copy_${type}_${ident}_from(other)
797
+ }
798
+ #[allow(non_snake_case)]
799
+ pub fn ${type}_${ident}_count(&self) -> usize {
800
+ self.m${to_camel_case(type)}${gecko_ffi_name}Count as usize
801
+ }
802
+ #[allow(non_snake_case)]
803
+ pub fn ${type}_${ident}_equals(&self, other: &Self) -> bool {
804
+ let count = self.${type}_${ident}_count();
805
+ if count != other.${type}_${ident}_count() {
806
+ return false;
807
+ }
808
+ let iter = self.m${to_camel_case(type)}s.iter().take(count).zip(
809
+ other.m${to_camel_case(type)}s.iter()
810
+ );
811
+ for (ours, others) in iter {
812
+ if ours.m${gecko_ffi_name} != others.m${gecko_ffi_name} {
813
+ return false;
814
+ }
815
+ }
816
+ true
817
+ }
818
+ </%def>
819
+
820
+ <% skip_box_longhands= """display contain""" %>
821
+ <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
822
+ #[inline]
823
+ pub fn set_display(&mut self, v: longhands::display::computed_value::T) {
824
+ self.mDisplay = v;
825
+ self.mOriginalDisplay = v;
826
+ }
827
+
828
+ #[inline]
829
+ pub fn copy_display_from(&mut self, other: &Self) {
830
+ self.set_display(other.mDisplay);
831
+ }
832
+
833
+ #[inline]
834
+ pub fn reset_display(&mut self, other: &Self) {
835
+ self.copy_display_from(other)
836
+ }
837
+
838
+ #[inline]
839
+ pub fn set_adjusted_display(
840
+ &mut self,
841
+ v: longhands::display::computed_value::T,
842
+ _is_item_or_root: bool
843
+ ) {
844
+ self.mDisplay = v;
845
+ }
846
+
847
+ #[inline]
848
+ pub fn clone_display(&self) -> longhands::display::computed_value::T {
849
+ self.mDisplay
850
+ }
851
+
852
+ #[inline]
853
+ pub fn display_equals(&self, other: &Self) -> bool {
854
+ self.mDisplay == other.mDisplay
855
+ }
856
+
857
+ #[inline]
858
+ pub fn set_contain(&mut self, v: longhands::contain::computed_value::T) {
859
+ self.mContain = v;
860
+ self.mEffectiveContainment = v;
861
+ }
862
+
863
+ #[inline]
864
+ pub fn copy_contain_from(&mut self, other: &Self) {
865
+ self.set_contain(other.mContain);
866
+ }
867
+
868
+ #[inline]
869
+ pub fn reset_contain(&mut self, other: &Self) {
870
+ self.copy_contain_from(other)
871
+ }
872
+
873
+ #[inline]
874
+ pub fn clone_contain(&self) -> longhands::contain::computed_value::T {
875
+ self.mContain
876
+ }
877
+
878
+ #[inline]
879
+ pub fn contain_equals(&self, other: &Self) -> bool {
880
+ self.mContain == other.mContain
881
+ }
882
+
883
+ #[inline]
884
+ pub fn set_effective_containment(
885
+ &mut self,
886
+ v: longhands::contain::computed_value::T
887
+ ) {
888
+ self.mEffectiveContainment = v;
889
+ }
890
+
891
+ #[inline]
892
+ pub fn clone_effective_containment(&self) -> longhands::contain::computed_value::T {
893
+ self.mEffectiveContainment
894
+ }
895
+ </%self:impl_trait>
896
+
897
+ <%def name="simple_image_array_property(name, shorthand, field_name)">
898
+ <%
899
+ image_layers_field = "mImage" if shorthand == "background" else "mMask"
900
+ copy_simple_image_array_property(name, shorthand, image_layers_field, field_name)
901
+ %>
902
+
903
+ pub fn set_${shorthand}_${name}<I>(&mut self, v: I)
904
+ where I: IntoIterator<Item=longhands::${shorthand}_${name}::computed_value::single_value::T>,
905
+ I::IntoIter: ExactSizeIterator
906
+ {
907
+ use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
908
+ let v = v.into_iter();
909
+
910
+ unsafe {
911
+ Gecko_EnsureImageLayersLength(&mut self.${image_layers_field}, v.len(),
912
+ LayerType::${shorthand.title()});
913
+ }
914
+
915
+ self.${image_layers_field}.${field_name}Count = v.len() as u32;
916
+ for (servo, geckolayer) in v.zip(self.${image_layers_field}.mLayers.iter_mut()) {
917
+ geckolayer.${field_name} = {
918
+ ${caller.body()}
919
+ };
920
+ }
921
+ }
922
+ ${impl_fallback_eq(f"{shorthand}_{name}")}
923
+ </%def>
924
+
925
+ <%def name="copy_simple_image_array_property(name, shorthand, layers_field_name, field_name)">
926
+ pub fn copy_${shorthand}_${name}_from(&mut self, other: &Self) {
927
+ use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
928
+
929
+ let count = other.${layers_field_name}.${field_name}Count;
930
+ unsafe {
931
+ Gecko_EnsureImageLayersLength(&mut self.${layers_field_name},
932
+ count as usize,
933
+ LayerType::${shorthand.title()});
934
+ }
935
+ // FIXME(emilio): This may be bogus in the same way as bug 1426246.
936
+ for (layer, other) in self.${layers_field_name}.mLayers.iter_mut()
937
+ .zip(other.${layers_field_name}.mLayers.iter())
938
+ .take(count as usize) {
939
+ layer.${field_name} = other.${field_name}.clone();
940
+ }
941
+ self.${layers_field_name}.${field_name}Count = count;
942
+ }
943
+
944
+ pub fn reset_${shorthand}_${name}(&mut self, other: &Self) {
945
+ self.copy_${shorthand}_${name}_from(other)
946
+ }
947
+ </%def>
948
+
949
+ <%def name="impl_simple_image_array_property(name, shorthand, layer_field_name, field_name, struct_name)">
950
+ <%
951
+ ident = "%s_%s" % (shorthand, name)
952
+ style_struct = next(x for x in data.style_structs if x.name == struct_name)
953
+ longhand = next(x for x in style_struct.longhands if x.ident == ident)
954
+ keyword = longhand.keyword
955
+ %>
956
+
957
+ <% copy_simple_image_array_property(name, shorthand, layer_field_name, field_name) %>
958
+
959
+ pub fn set_${ident}<I>(&mut self, v: I)
960
+ where
961
+ I: IntoIterator<Item=longhands::${ident}::computed_value::single_value::T>,
962
+ I::IntoIter: ExactSizeIterator,
963
+ {
964
+ % if keyword:
965
+ use crate::properties::longhands::${ident}::single_value::computed_value::T as Keyword;
966
+ % endif
967
+ use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
968
+
969
+ let v = v.into_iter();
970
+
971
+ unsafe {
972
+ Gecko_EnsureImageLayersLength(&mut self.${layer_field_name}, v.len(),
973
+ LayerType::${shorthand.title()});
974
+ }
975
+
976
+ self.${layer_field_name}.${field_name}Count = v.len() as u32;
977
+ for (servo, geckolayer) in v.zip(self.${layer_field_name}.mLayers.iter_mut()) {
978
+ geckolayer.${field_name} = {
979
+ % if keyword:
980
+ match servo {
981
+ % for value in keyword.values_for("gecko"):
982
+ Keyword::${to_camel_case(value)} =>
983
+ structs::${keyword.gecko_constant(value)} ${keyword.maybe_cast('u8')},
984
+ % endfor
985
+ }
986
+ % else:
987
+ // The Gecko field stores the computed value directly.
988
+ servo
989
+ % endif
990
+ };
991
+ }
992
+ }
993
+
994
+ ${impl_fallback_eq(ident)}
995
+
996
+ pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
997
+ % if keyword:
998
+ use crate::properties::longhands::${ident}::single_value::computed_value::T as Keyword;
999
+ % endif
1000
+ longhands::${ident}::computed_value::List(
1001
+ self.${layer_field_name}.mLayers.iter()
1002
+ .take(self.${layer_field_name}.${field_name}Count as usize)
1003
+ .map(|layer| {
1004
+ % if keyword:
1005
+ match layer.${field_name} {
1006
+ % for value in longhand.keyword.values_for("gecko"):
1007
+ structs::${keyword.gecko_constant(value)}
1008
+ => Keyword::${to_camel_case(value)},
1009
+ % endfor
1010
+ % if keyword.gecko_inexhaustive:
1011
+ _ => panic!("Found unexpected value in style struct for ${ident} property"),
1012
+ % endif
1013
+ }
1014
+ % else:
1015
+ layer.${field_name}
1016
+ % endif
1017
+ }).collect()
1018
+ )
1019
+ }
1020
+ </%def>
1021
+
1022
+ <%def name="impl_common_image_layer_properties(shorthand)">
1023
+ <%
1024
+ if shorthand == "background":
1025
+ image_layers_field = "mImage"
1026
+ struct_name = "Background"
1027
+ else:
1028
+ image_layers_field = "mMask"
1029
+ struct_name = "SVG"
1030
+ %>
1031
+
1032
+ <%self:simple_image_array_property name="repeat" shorthand="${shorthand}" field_name="mRepeat">
1033
+ use crate::values::specified::background::BackgroundRepeatKeyword;
1034
+ use crate::gecko_bindings::structs::nsStyleImageLayers_Repeat;
1035
+ use crate::gecko_bindings::structs::StyleImageLayerRepeat;
1036
+
1037
+ fn to_ns(repeat: BackgroundRepeatKeyword) -> StyleImageLayerRepeat {
1038
+ match repeat {
1039
+ BackgroundRepeatKeyword::Repeat => StyleImageLayerRepeat::Repeat,
1040
+ BackgroundRepeatKeyword::Space => StyleImageLayerRepeat::Space,
1041
+ BackgroundRepeatKeyword::Round => StyleImageLayerRepeat::Round,
1042
+ BackgroundRepeatKeyword::NoRepeat => StyleImageLayerRepeat::NoRepeat,
1043
+ }
1044
+ }
1045
+
1046
+ let repeat_x = to_ns(servo.0);
1047
+ let repeat_y = to_ns(servo.1);
1048
+ nsStyleImageLayers_Repeat {
1049
+ mXRepeat: repeat_x,
1050
+ mYRepeat: repeat_y,
1051
+ }
1052
+ </%self:simple_image_array_property>
1053
+
1054
+ pub fn clone_${shorthand}_repeat(&self) -> longhands::${shorthand}_repeat::computed_value::T {
1055
+ use crate::properties::longhands::${shorthand}_repeat::single_value::computed_value::T;
1056
+ use crate::values::specified::background::BackgroundRepeatKeyword;
1057
+ use crate::gecko_bindings::structs::StyleImageLayerRepeat;
1058
+
1059
+ fn to_servo(repeat: StyleImageLayerRepeat) -> BackgroundRepeatKeyword {
1060
+ match repeat {
1061
+ StyleImageLayerRepeat::Repeat => BackgroundRepeatKeyword::Repeat,
1062
+ StyleImageLayerRepeat::Space => BackgroundRepeatKeyword::Space,
1063
+ StyleImageLayerRepeat::Round => BackgroundRepeatKeyword::Round,
1064
+ StyleImageLayerRepeat::NoRepeat => BackgroundRepeatKeyword::NoRepeat,
1065
+ _ => panic!("Found unexpected value in style struct for ${shorthand}_repeat property"),
1066
+ }
1067
+ }
1068
+
1069
+ longhands::${shorthand}_repeat::computed_value::List(
1070
+ self.${image_layers_field}.mLayers.iter()
1071
+ .take(self.${image_layers_field}.mRepeatCount as usize)
1072
+ .map(|layer| {
1073
+ T(to_servo(layer.mRepeat.mXRepeat), to_servo(layer.mRepeat.mYRepeat))
1074
+ }).collect()
1075
+ )
1076
+ }
1077
+
1078
+ <% impl_simple_image_array_property("clip", shorthand, image_layers_field, "mClip", struct_name) %>
1079
+ <% impl_simple_image_array_property("origin", shorthand, image_layers_field, "mOrigin", struct_name) %>
1080
+
1081
+ % for (orientation, keyword) in [("x", "horizontal"), ("y", "vertical")]:
1082
+ pub fn copy_${shorthand}_position_${orientation}_from(&mut self, other: &Self) {
1083
+ use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
1084
+
1085
+ let count = other.${image_layers_field}.mPosition${orientation.upper()}Count;
1086
+
1087
+ unsafe {
1088
+ Gecko_EnsureImageLayersLength(&mut self.${image_layers_field},
1089
+ count as usize,
1090
+ LayerType::${shorthand.capitalize()});
1091
+ }
1092
+
1093
+ for (layer, other) in self.${image_layers_field}.mLayers.iter_mut()
1094
+ .zip(other.${image_layers_field}.mLayers.iter())
1095
+ .take(count as usize) {
1096
+ layer.mPosition.${keyword} = other.mPosition.${keyword}.clone();
1097
+ }
1098
+ self.${image_layers_field}.mPosition${orientation.upper()}Count = count;
1099
+ }
1100
+
1101
+ pub fn reset_${shorthand}_position_${orientation}(&mut self, other: &Self) {
1102
+ self.copy_${shorthand}_position_${orientation}_from(other)
1103
+ }
1104
+
1105
+ pub fn clone_${shorthand}_position_${orientation}(&self)
1106
+ -> longhands::${shorthand}_position_${orientation}::computed_value::T {
1107
+ longhands::${shorthand}_position_${orientation}::computed_value::List(
1108
+ self.${image_layers_field}.mLayers.iter()
1109
+ .take(self.${image_layers_field}.mPosition${orientation.upper()}Count as usize)
1110
+ .map(|position| position.mPosition.${keyword}.clone())
1111
+ .collect()
1112
+ )
1113
+ }
1114
+
1115
+ ${impl_fallback_eq(f"{shorthand}_position_{orientation}")}
1116
+
1117
+ pub fn set_${shorthand}_position_${orientation[0]}<I>(&mut self, v: I)
1118
+ where
1119
+ I: IntoIterator<Item = longhands::${shorthand}_position_${orientation[0]}::computed_value::single_value::T>,
1120
+ I::IntoIter: ExactSizeIterator
1121
+ {
1122
+ use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
1123
+
1124
+ let v = v.into_iter();
1125
+
1126
+ unsafe {
1127
+ Gecko_EnsureImageLayersLength(&mut self.${image_layers_field}, v.len(),
1128
+ LayerType::${shorthand.capitalize()});
1129
+ }
1130
+
1131
+ self.${image_layers_field}.mPosition${orientation[0].upper()}Count = v.len() as u32;
1132
+ for (servo, geckolayer) in v.zip(self.${image_layers_field}
1133
+ .mLayers.iter_mut()) {
1134
+ geckolayer.mPosition.${keyword} = servo;
1135
+ }
1136
+ }
1137
+ % endfor
1138
+
1139
+ <%self:simple_image_array_property name="size" shorthand="${shorthand}" field_name="mSize">
1140
+ servo
1141
+ </%self:simple_image_array_property>
1142
+
1143
+ pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T {
1144
+ longhands::${shorthand}_size::computed_value::List(
1145
+ self.${image_layers_field}.mLayers.iter().map(|layer| layer.mSize.clone()).collect()
1146
+ )
1147
+ }
1148
+
1149
+ pub fn copy_${shorthand}_image_from(&mut self, other: &Self) {
1150
+ use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
1151
+ unsafe {
1152
+ let count = other.${image_layers_field}.mImageCount;
1153
+ Gecko_EnsureImageLayersLength(&mut self.${image_layers_field},
1154
+ count as usize,
1155
+ LayerType::${shorthand.capitalize()});
1156
+
1157
+ for (layer, other) in self.${image_layers_field}.mLayers.iter_mut()
1158
+ .zip(other.${image_layers_field}.mLayers.iter())
1159
+ .take(count as usize) {
1160
+ layer.mImage = other.mImage.clone();
1161
+ }
1162
+ self.${image_layers_field}.mImageCount = count;
1163
+ }
1164
+ }
1165
+
1166
+ pub fn reset_${shorthand}_image(&mut self, other: &Self) {
1167
+ self.copy_${shorthand}_image_from(other)
1168
+ }
1169
+
1170
+ #[allow(unused_variables)]
1171
+ pub fn set_${shorthand}_image<I>(&mut self, images: I)
1172
+ where
1173
+ I: IntoIterator<Item = longhands::${shorthand}_image::computed_value::single_value::T>,
1174
+ I::IntoIter: ExactSizeIterator
1175
+ {
1176
+ use crate::gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
1177
+
1178
+ let images = images.into_iter();
1179
+
1180
+ unsafe {
1181
+ Gecko_EnsureImageLayersLength(
1182
+ &mut self.${image_layers_field},
1183
+ images.len(),
1184
+ LayerType::${shorthand.title()},
1185
+ );
1186
+ }
1187
+
1188
+ self.${image_layers_field}.mImageCount = images.len() as u32;
1189
+ for (image, geckoimage) in images.zip(self.${image_layers_field}.mLayers.iter_mut()) {
1190
+ geckoimage.mImage = image;
1191
+ }
1192
+ }
1193
+
1194
+ ${impl_fallback_eq(f"{shorthand}_image")}
1195
+
1196
+ pub fn clone_${shorthand}_image(&self) -> longhands::${shorthand}_image::computed_value::T {
1197
+ longhands::${shorthand}_image::computed_value::List(
1198
+ self.${image_layers_field}.mLayers.iter()
1199
+ .take(self.${image_layers_field}.mImageCount as usize)
1200
+ .map(|layer| layer.mImage.clone())
1201
+ .collect()
1202
+ )
1203
+ }
1204
+
1205
+ <%
1206
+ fill_fields = "mRepeat mClip mOrigin mPositionX mPositionY mImage mSize"
1207
+ if shorthand == "background":
1208
+ fill_fields += " mAttachment mBlendMode"
1209
+ else:
1210
+ # mSourceURI uses mImageCount
1211
+ fill_fields += " mMaskMode mComposite"
1212
+ %>
1213
+ pub fn fill_arrays(&mut self) {
1214
+ use crate::gecko_bindings::bindings::Gecko_FillAllImageLayers;
1215
+ use std::cmp;
1216
+ let mut max_len = 1;
1217
+ % for member in fill_fields.split():
1218
+ max_len = cmp::max(max_len, self.${image_layers_field}.${member}Count);
1219
+ % endfor
1220
+ unsafe {
1221
+ // While we could do this manually, we'd need to also manually
1222
+ // run all the copy constructors, so we just delegate to gecko
1223
+ Gecko_FillAllImageLayers(&mut self.${image_layers_field}, max_len);
1224
+ }
1225
+ }
1226
+ </%def>
1227
+
1228
+ // TODO: Gecko accepts lists in most background-related properties. We just use
1229
+ // the first element (which is the common case), but at some point we want to
1230
+ // add support for parsing these lists in servo and pushing to nsTArray's.
1231
+ <% skip_background_longhands = """background-repeat
1232
+ background-image background-clip
1233
+ background-origin background-attachment
1234
+ background-size background-position
1235
+ background-blend-mode
1236
+ background-position-x
1237
+ background-position-y""" %>
1238
+ <%self:impl_trait style_struct_name="Background"
1239
+ skip_longhands="${skip_background_longhands}">
1240
+
1241
+ <% impl_common_image_layer_properties("background") %>
1242
+ <% impl_simple_image_array_property("attachment", "background", "mImage", "mAttachment", "Background") %>
1243
+ <% impl_simple_image_array_property("blend_mode", "background", "mImage", "mBlendMode", "Background") %>
1244
+ </%self:impl_trait>
1245
+
1246
+ <%self:impl_trait style_struct_name="List">
1247
+ </%self:impl_trait>
1248
+
1249
+ <%self:impl_trait style_struct_name="Table">
1250
+ </%self:impl_trait>
1251
+
1252
+ <%self:impl_trait style_struct_name="Effects">
1253
+ </%self:impl_trait>
1254
+
1255
+ <%self:impl_trait style_struct_name="InheritedBox">
1256
+ </%self:impl_trait>
1257
+
1258
+ <%self:impl_trait style_struct_name="InheritedTable">
1259
+ </%self:impl_trait>
1260
+
1261
+ <%self:impl_trait style_struct_name="InheritedText">
1262
+ </%self:impl_trait>
1263
+
1264
+ <%self:impl_trait style_struct_name="Text">
1265
+ </%self:impl_trait>
1266
+
1267
+ <% skip_svg_longhands = """
1268
+ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-position-y mask-size mask-image
1269
+ """
1270
+ %>
1271
+ <%self:impl_trait style_struct_name="SVG"
1272
+ skip_longhands="${skip_svg_longhands}">
1273
+ <% impl_common_image_layer_properties("mask") %>
1274
+ <% impl_simple_image_array_property("mode", "mask", "mMask", "mMaskMode", "SVG") %>
1275
+ <% impl_simple_image_array_property("composite", "mask", "mMask", "mComposite", "SVG") %>
1276
+ </%self:impl_trait>
1277
+
1278
+ <%self:impl_trait style_struct_name="InheritedSVG">
1279
+ </%self:impl_trait>
1280
+
1281
+ <%self:impl_trait style_struct_name="InheritedUI">
1282
+ #[inline]
1283
+ pub fn color_scheme_bits(&self) -> values::specified::color::ColorSchemeFlags {
1284
+ self.mColorScheme.bits
1285
+ }
1286
+ </%self:impl_trait>
1287
+
1288
+ <%self:impl_trait style_struct_name="Column">
1289
+ </%self:impl_trait>
1290
+
1291
+ <%self:impl_trait style_struct_name="Counters">
1292
+ pub fn ineffective_content_property(&self) -> bool {
1293
+ !self.mContent.is_items()
1294
+ }
1295
+ </%self:impl_trait>
1296
+
1297
+ <% skip_ui_longhands = """animation-name animation-delay animation-duration
1298
+ animation-direction animation-fill-mode
1299
+ animation-play-state animation-iteration-count
1300
+ animation-timing-function animation-composition animation-timeline
1301
+ animation-range-start animation-range-end
1302
+ transition-behavior transition-duration transition-delay
1303
+ transition-timing-function transition-property
1304
+ scroll-timeline-name scroll-timeline-axis
1305
+ view-timeline-name view-timeline-axis view-timeline-inset""" %>
1306
+
1307
+ <%self:impl_trait style_struct_name="UI" skip_longhands="${skip_ui_longhands}">
1308
+ ${impl_coordinated_property('transition', 'behavior', 'Behavior')}
1309
+ ${impl_coordinated_property('transition', 'delay', 'Delay')}
1310
+ ${impl_coordinated_property('transition', 'duration', 'Duration')}
1311
+ ${impl_coordinated_property('transition', 'timing_function', 'TimingFunction')}
1312
+ ${impl_coordinated_property('transition', 'property', 'Property')}
1313
+
1314
+ pub fn transition_combined_duration_at(&self, index: usize) -> Time {
1315
+ // https://drafts.csswg.org/css-transitions/#transition-combined-duration
1316
+ Time::from_seconds(
1317
+ self.transition_duration_at(index).seconds().max(0.0) +
1318
+ self.transition_delay_at(index).seconds()
1319
+ )
1320
+ }
1321
+
1322
+ /// Returns whether there are any transitions specified.
1323
+ pub fn specifies_transitions(&self) -> bool {
1324
+ if self.mTransitionPropertyCount == 1 &&
1325
+ self.transition_combined_duration_at(0).seconds() <= 0.0f32 {
1326
+ return false;
1327
+ }
1328
+ self.mTransitionPropertyCount > 0
1329
+ }
1330
+
1331
+ /// Returns whether animation-timeline is initial value. We need this information to resolve
1332
+ /// animation-duration.
1333
+ pub fn has_initial_animation_timeline(&self) -> bool {
1334
+ self.mAnimationTimelineCount == 1 && self.animation_timeline_at(0).is_auto()
1335
+ }
1336
+
1337
+ pub fn animations_equals(&self, other: &Self) -> bool {
1338
+ self.mAnimationNameCount == other.mAnimationNameCount
1339
+ && self.mAnimationDelayCount == other.mAnimationDelayCount
1340
+ && self.mAnimationDirectionCount == other.mAnimationDirectionCount
1341
+ && self.mAnimationDurationCount == other.mAnimationDurationCount
1342
+ && self.mAnimationFillModeCount == other.mAnimationFillModeCount
1343
+ && self.mAnimationIterationCountCount == other.mAnimationIterationCountCount
1344
+ && self.mAnimationPlayStateCount == other.mAnimationPlayStateCount
1345
+ && self.mAnimationTimingFunctionCount == other.mAnimationTimingFunctionCount
1346
+ && self.mAnimationCompositionCount == other.mAnimationCompositionCount
1347
+ && self.mAnimationTimelineCount == other.mAnimationTimelineCount
1348
+ && self.mAnimationRangeStartCount == other.mAnimationRangeStartCount
1349
+ && self.mAnimationRangeEndCount == other.mAnimationRangeEndCount
1350
+ && unsafe { bindings::Gecko_StyleAnimationsEquals(&self.mAnimations, &other.mAnimations) }
1351
+ }
1352
+
1353
+ ${impl_coordinated_property('animation', 'name', 'Name')}
1354
+ ${impl_coordinated_property('animation', 'delay', 'Delay')}
1355
+ ${impl_coordinated_property('animation', 'duration', 'Duration')}
1356
+ ${impl_coordinated_property('animation', 'direction', 'Direction')}
1357
+ ${impl_coordinated_property('animation', 'fill_mode', 'FillMode')}
1358
+ ${impl_coordinated_property('animation', 'play_state', 'PlayState')}
1359
+ ${impl_coordinated_property('animation', 'composition', 'Composition')}
1360
+ ${impl_coordinated_property('animation', 'iteration_count', 'IterationCount')}
1361
+ ${impl_coordinated_property('animation', 'timeline', 'Timeline')}
1362
+ ${impl_coordinated_property('animation', 'timing_function', 'TimingFunction')}
1363
+ ${impl_coordinated_property('animation', 'range_start', 'RangeStart')}
1364
+ ${impl_coordinated_property('animation', 'range_end', 'RangeEnd')}
1365
+
1366
+ ${impl_coordinated_property('scroll_timeline', 'name', 'Name')}
1367
+ ${impl_coordinated_property('scroll_timeline', 'axis', 'Axis')}
1368
+
1369
+ pub fn scroll_timelines_equals(&self, other: &Self) -> bool {
1370
+ self.mScrollTimelineNameCount == other.mScrollTimelineNameCount
1371
+ && self.mScrollTimelineAxisCount == other.mScrollTimelineAxisCount
1372
+ && unsafe {
1373
+ bindings::Gecko_StyleScrollTimelinesEquals(
1374
+ &self.mScrollTimelines,
1375
+ &other.mScrollTimelines,
1376
+ )
1377
+ }
1378
+ }
1379
+
1380
+ ${impl_coordinated_property('view_timeline', 'name', 'Name')}
1381
+ ${impl_coordinated_property('view_timeline', 'axis', 'Axis')}
1382
+ ${impl_coordinated_property('view_timeline', 'inset', 'Inset')}
1383
+
1384
+ pub fn view_timelines_equals(&self, other: &Self) -> bool {
1385
+ self.mViewTimelineNameCount == other.mViewTimelineNameCount
1386
+ && self.mViewTimelineAxisCount == other.mViewTimelineAxisCount
1387
+ && self.mViewTimelineInsetCount == other.mViewTimelineInsetCount
1388
+ && unsafe {
1389
+ bindings::Gecko_StyleViewTimelinesEquals(
1390
+ &self.mViewTimelines,
1391
+ &other.mViewTimelines,
1392
+ )
1393
+ }
1394
+ }
1395
+ </%self:impl_trait>
1396
+
1397
+ <%self:impl_trait style_struct_name="XUL">
1398
+ </%self:impl_trait>
1399
+
1400
+ % for style_struct in data.style_structs:
1401
+ ${impl_style_struct(style_struct)}
1402
+ % endfor
1403
+
1404
+ /// Assert that the initial values set in Gecko style struct constructors
1405
+ /// match the values returned by `get_initial_value()` for each longhand.
1406
+ #[cfg(feature = "gecko")]
1407
+ #[inline]
1408
+ pub fn assert_initial_values_match(data: &PerDocumentStyleData) {
1409
+ if cfg!(debug_assertions) {
1410
+ let data = data.borrow();
1411
+ let cv = data.stylist.device().default_computed_values();
1412
+ <%
1413
+ # Skip properties with initial values that change at computed
1414
+ # value time, or whose initial value depends on the document
1415
+ # / other prefs.
1416
+ SKIPPED = [
1417
+ "border-top-width",
1418
+ "border-bottom-width",
1419
+ "border-left-width",
1420
+ "border-right-width",
1421
+ "column-rule-width",
1422
+ "font-family",
1423
+ "font-size",
1424
+ "outline-width",
1425
+ "color",
1426
+ ]
1427
+ TO_TEST = [p for p in data.longhands if p.enabled_in != "" and not p.logical and not p.name in SKIPPED]
1428
+ %>
1429
+ % for property in TO_TEST:
1430
+ assert_eq!(
1431
+ cv.clone_${property.ident}(),
1432
+ longhands::${property.ident}::get_initial_value(),
1433
+ concat!(
1434
+ "initial value in Gecko style struct for ",
1435
+ stringify!(${property.ident}),
1436
+ " must match longhands::",
1437
+ stringify!(${property.ident}),
1438
+ "::get_initial_value()"
1439
+ )
1440
+ );
1441
+ % endfor
1442
+ }
1443
+ }
1444
+
1445
+ % if engine == "gecko":
1446
+ pub mod system_font {
1447
+ //! We deal with system fonts here
1448
+ //!
1449
+ //! System fonts can only be set as a group via the font shorthand.
1450
+ //! They resolve at compute time (not parse time -- this lets the
1451
+ //! browser respond to changes to the OS font settings).
1452
+ //!
1453
+ //! While Gecko handles these as a separate property and keyword
1454
+ //! values on each property indicating that the font should be picked
1455
+ //! from the -x-system-font property, we avoid this. Instead,
1456
+ //! each font longhand has a special SystemFont variant which contains
1457
+ //! the specified system font. When the cascade function (in helpers)
1458
+ //! detects that a value has a system font, it will resolve it, and
1459
+ //! cache it on the ComputedValues. After this, it can be just fetched
1460
+ //! whenever a font longhand on the same element needs the system font.
1461
+ //!
1462
+ //! When a longhand property is holding a SystemFont, it's serialized
1463
+ //! to an empty string as if its value comes from a shorthand with
1464
+ //! variable reference. We may want to improve this behavior at some
1465
+ //! point. See also https://github.com/w3c/csswg-drafts/issues/1586.
1466
+
1467
+ use crate::properties::longhands;
1468
+ use std::hash::{Hash, Hasher};
1469
+ use crate::values::computed::{ToComputedValue, Context};
1470
+ use crate::values::specified::font::SystemFont;
1471
+ // ComputedValues are compared at times
1472
+ // so we need these impls. We don't want to
1473
+ // add Eq to Number (which contains a float)
1474
+ // so instead we have an eq impl which skips the
1475
+ // cached values
1476
+ impl PartialEq for ComputedSystemFont {
1477
+ fn eq(&self, other: &Self) -> bool {
1478
+ self.system_font == other.system_font
1479
+ }
1480
+ }
1481
+ impl Eq for ComputedSystemFont {}
1482
+
1483
+ impl Hash for ComputedSystemFont {
1484
+ fn hash<H: Hasher>(&self, hasher: &mut H) {
1485
+ self.system_font.hash(hasher)
1486
+ }
1487
+ }
1488
+
1489
+ impl ToComputedValue for SystemFont {
1490
+ type ComputedValue = ComputedSystemFont;
1491
+
1492
+ fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
1493
+ use crate::gecko_bindings::bindings;
1494
+ use crate::gecko_bindings::structs::nsFont;
1495
+ use crate::values::computed::font::FontSize;
1496
+ use crate::values::specified::font::KeywordInfo;
1497
+ use crate::values::generics::NonNegative;
1498
+ use std::mem;
1499
+
1500
+ let mut system = mem::MaybeUninit::<nsFont>::uninit();
1501
+ let system = unsafe {
1502
+ bindings::Gecko_nsFont_InitSystem(
1503
+ system.as_mut_ptr(),
1504
+ *self,
1505
+ &**cx.style().get_font(),
1506
+ cx.device().document()
1507
+ );
1508
+ &mut *system.as_mut_ptr()
1509
+ };
1510
+ let size = NonNegative(cx.maybe_zoom_text(system.size.0));
1511
+ let ret = ComputedSystemFont {
1512
+ font_family: system.family.clone(),
1513
+ font_size: FontSize {
1514
+ computed_size: size,
1515
+ used_size: size,
1516
+ keyword_info: KeywordInfo::none()
1517
+ },
1518
+ font_weight: system.weight,
1519
+ font_width: system.width,
1520
+ font_style: system.style,
1521
+ system_font: *self,
1522
+ };
1523
+ unsafe { bindings::Gecko_nsFont_Destroy(system); }
1524
+ ret
1525
+ }
1526
+
1527
+ fn from_computed_value(_: &ComputedSystemFont) -> Self {
1528
+ unreachable!()
1529
+ }
1530
+ }
1531
+
1532
+ #[inline]
1533
+ /// Compute and cache a system font
1534
+ ///
1535
+ /// Must be called before attempting to compute a system font
1536
+ /// specified value
1537
+ pub fn resolve_system_font(system: SystemFont, context: &mut Context) {
1538
+ // Checking if context.cached_system_font.is_none() isn't enough,
1539
+ // if animating from one system font to another the cached system font
1540
+ // may change
1541
+ if context.cached_system_font.as_ref().is_none_or(|x| x.system_font != system) {
1542
+ let computed = system.to_computed_value(context);
1543
+ context.cached_system_font = Some(computed);
1544
+ }
1545
+ }
1546
+
1547
+ #[derive(Clone, Debug)]
1548
+ pub struct ComputedSystemFont {
1549
+ % for name in SYSTEM_FONT_LONGHANDS:
1550
+ pub ${name}: longhands::${name}::computed_value::T,
1551
+ % endfor
1552
+ pub system_font: SystemFont,
1553
+ }
1554
+ }
1555
+ % endif