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.
- package/LICENSE +21 -0
- package/README.md +355 -2
- package/THIRD_PARTY_NOTICES.md +25 -0
- package/assets/icon.svg +4 -0
- package/dist/api.d.ts +7 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +46 -0
- package/dist/api.js.map +1 -0
- package/dist/assets.d.ts +7 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +52 -0
- package/dist/assets.js.map +1 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +3 -0
- package/dist/browser.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +10 -0
- package/dist/node.js.map +1 -0
- package/dist/options.d.ts +24 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +135 -0
- package/dist/options.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/examples/bun.ts +8 -0
- package/examples/german-invoice/README.md +70 -0
- package/examples/german-invoice/data.mjs +83 -0
- package/examples/german-invoice/invoice.css +59 -0
- package/examples/german-invoice/template.mjs +49 -0
- package/examples/german-invoice.mjs +20 -0
- package/examples/invoice.html +29 -0
- package/examples/node.mjs +8 -0
- package/examples/pagination.html +40 -0
- package/examples/pagination.mjs +8 -0
- package/licenses/DejaVu.txt +187 -0
- package/licenses/RUST_DEPENDENCIES.txt +11577 -0
- package/package.json +89 -4
- package/src/api.ts +44 -0
- package/src/assets.ts +43 -0
- package/src/browser.ts +6 -0
- package/src/node.ts +12 -0
- package/src/options.ts +101 -0
- package/src/types.ts +49 -0
- package/vendor/README.md +17 -0
- package/vendor/stylo/.cargo-ok +1 -0
- package/vendor/stylo/.cargo_vcs_info.json +6 -0
- package/vendor/stylo/Cargo.lock +1485 -0
- package/vendor/stylo/Cargo.toml +274 -0
- package/vendor/stylo/LICENSE +373 -0
- package/vendor/stylo/README.md +6 -0
- package/vendor/stylo/applicable_declarations.rs +328 -0
- package/vendor/stylo/author_styles.rs +79 -0
- package/vendor/stylo/bezier.rs +176 -0
- package/vendor/stylo/bloom.rs +414 -0
- package/vendor/stylo/build.rs +91 -0
- package/vendor/stylo/build_gecko.rs +393 -0
- package/vendor/stylo/color/color_function.rs +601 -0
- package/vendor/stylo/color/component.rs +207 -0
- package/vendor/stylo/color/convert.rs +935 -0
- package/vendor/stylo/color/gamut/raytrace.rs +265 -0
- package/vendor/stylo/color/gamut.rs +227 -0
- package/vendor/stylo/color/mix.rs +645 -0
- package/vendor/stylo/color/mod.rs +750 -0
- package/vendor/stylo/color/parsing.rs +770 -0
- package/vendor/stylo/color/to_css.rs +297 -0
- package/vendor/stylo/context.rs +716 -0
- package/vendor/stylo/counter_style/mod.rs +754 -0
- package/vendor/stylo/counter_style/predefined.rs +61 -0
- package/vendor/stylo/counter_style/update_predefined.py +35 -0
- package/vendor/stylo/custom_properties.rs +2023 -0
- package/vendor/stylo/custom_properties_map.rs +220 -0
- package/vendor/stylo/data.rs +693 -0
- package/vendor/stylo/device/gecko.rs +486 -0
- package/vendor/stylo/device/mod.rs +304 -0
- package/vendor/stylo/device/servo.rs +507 -0
- package/vendor/stylo/dom.rs +1164 -0
- package/vendor/stylo/dom_apis.rs +937 -0
- package/vendor/stylo/driver.rs +172 -0
- package/vendor/stylo/error_reporting.rs +484 -0
- package/vendor/stylo/font_face.rs +558 -0
- package/vendor/stylo/font_metrics.rs +124 -0
- package/vendor/stylo/gecko/anon_boxes.toml +113 -0
- package/vendor/stylo/gecko/arc_types.rs +211 -0
- package/vendor/stylo/gecko/conversions.rs +59 -0
- package/vendor/stylo/gecko/data.rs +222 -0
- package/vendor/stylo/gecko/media_features.rs +971 -0
- package/vendor/stylo/gecko/mod.rs +20 -0
- package/vendor/stylo/gecko/non_ts_pseudo_class_list.rs +119 -0
- package/vendor/stylo/gecko/pseudo_element.rs +640 -0
- package/vendor/stylo/gecko/pseudo_element_definition.mako.rs +298 -0
- package/vendor/stylo/gecko/pseudo_elements.py +137 -0
- package/vendor/stylo/gecko/pseudo_elements.toml +197 -0
- package/vendor/stylo/gecko/regen_pseudo_elements.py +33 -0
- package/vendor/stylo/gecko/restyle_damage.rs +127 -0
- package/vendor/stylo/gecko/selector_parser.rs +627 -0
- package/vendor/stylo/gecko/snapshot.rs +202 -0
- package/vendor/stylo/gecko/snapshot_helpers.rs +334 -0
- package/vendor/stylo/gecko/traversal.rs +52 -0
- package/vendor/stylo/gecko/wrapper.rs +2258 -0
- package/vendor/stylo/gecko_bindings/mod.rs +34 -0
- package/vendor/stylo/gecko_bindings/sugar/mod.rs +12 -0
- package/vendor/stylo/gecko_bindings/sugar/ns_com_ptr.rs +15 -0
- package/vendor/stylo/gecko_bindings/sugar/ns_compatibility.rs +19 -0
- package/vendor/stylo/gecko_bindings/sugar/ns_style_auto_array.rs +111 -0
- package/vendor/stylo/gecko_bindings/sugar/origin_flags.rs +31 -0
- package/vendor/stylo/gecko_bindings/sugar/ownership.rs +70 -0
- package/vendor/stylo/gecko_bindings/sugar/refptr.rs +299 -0
- package/vendor/stylo/gecko_string_cache/mod.rs +543 -0
- package/vendor/stylo/gecko_string_cache/namespace.rs +106 -0
- package/vendor/stylo/global_style_data.rs +224 -0
- package/vendor/stylo/invalidation/element/document_state.rs +156 -0
- package/vendor/stylo/invalidation/element/element_wrapper.rs +432 -0
- package/vendor/stylo/invalidation/element/invalidation_map.rs +1631 -0
- package/vendor/stylo/invalidation/element/invalidator.rs +1470 -0
- package/vendor/stylo/invalidation/element/mod.rs +13 -0
- package/vendor/stylo/invalidation/element/relative_selector.rs +1399 -0
- package/vendor/stylo/invalidation/element/restyle_hints.rs +226 -0
- package/vendor/stylo/invalidation/element/state_and_attributes.rs +756 -0
- package/vendor/stylo/invalidation/media_queries.rs +144 -0
- package/vendor/stylo/invalidation/mod.rs +10 -0
- package/vendor/stylo/invalidation/stylesheets.rs +745 -0
- package/vendor/stylo/invalidation/viewport_units.rs +71 -0
- package/vendor/stylo/lib.rs +336 -0
- package/vendor/stylo/logical_geometry.rs +1684 -0
- package/vendor/stylo/macros.rs +70 -0
- package/vendor/stylo/matching.rs +1226 -0
- package/vendor/stylo/media_queries/media_list.rs +168 -0
- package/vendor/stylo/media_queries/media_query.rs +190 -0
- package/vendor/stylo/media_queries/mod.rs +13 -0
- package/vendor/stylo/parallel.rs +205 -0
- package/vendor/stylo/parser.rs +276 -0
- package/vendor/stylo/piecewise_linear.rs +282 -0
- package/vendor/stylo/prefs.rs +33 -0
- package/vendor/stylo/properties/build.py +119 -0
- package/vendor/stylo/properties/cascade.rs +2704 -0
- package/vendor/stylo/properties/computed_value_flags.rs +206 -0
- package/vendor/stylo/properties/counted_unknown_properties.py +104 -0
- package/vendor/stylo/properties/counter_style_descriptors.toml +45 -0
- package/vendor/stylo/properties/data.py +1375 -0
- package/vendor/stylo/properties/declaration_block.rs +1788 -0
- package/vendor/stylo/properties/font_face_descriptors.toml +50 -0
- package/vendor/stylo/properties/gecko.mako.rs +1555 -0
- package/vendor/stylo/properties/helpers/animated_properties.mako.rs +800 -0
- package/vendor/stylo/properties/helpers.mako.rs +812 -0
- package/vendor/stylo/properties/longhands.toml +4305 -0
- package/vendor/stylo/properties/mod.rs +1857 -0
- package/vendor/stylo/properties/properties.html.mako +31 -0
- package/vendor/stylo/properties/properties.mako.rs +3103 -0
- package/vendor/stylo/properties/property_descriptors.toml +18 -0
- package/vendor/stylo/properties/shorthands.rs +4241 -0
- package/vendor/stylo/properties/shorthands.toml +575 -0
- package/vendor/stylo/properties/vendored_python/mako-1.3.10-py3-none-any.whl +0 -0
- package/vendor/stylo/properties/vendored_python/markupsafe/LICENSE.txt +28 -0
- package/vendor/stylo/properties/vendored_python/markupsafe/__init__.py +384 -0
- package/vendor/stylo/properties/vendored_python/toml-0.10.2-py2.py3-none-any.whl +0 -0
- package/vendor/stylo/properties/view_transition_descriptors.toml +11 -0
- package/vendor/stylo/properties_and_values/mod.rs +12 -0
- package/vendor/stylo/properties_and_values/registry.rs +65 -0
- package/vendor/stylo/properties_and_values/rule.rs +331 -0
- package/vendor/stylo/properties_and_values/syntax/ascii.rs +60 -0
- package/vendor/stylo/properties_and_values/syntax/data_type.rs +146 -0
- package/vendor/stylo/properties_and_values/syntax/mod.rs +437 -0
- package/vendor/stylo/properties_and_values/value.rs +758 -0
- package/vendor/stylo/queries/condition.rs +996 -0
- package/vendor/stylo/queries/feature.rs +199 -0
- package/vendor/stylo/queries/feature_expression.rs +1170 -0
- package/vendor/stylo/queries/mod.rs +19 -0
- package/vendor/stylo/queries/values.rs +46 -0
- package/vendor/stylo/rule_cache.rs +267 -0
- package/vendor/stylo/rule_collector.rs +554 -0
- package/vendor/stylo/rule_tree/core.rs +787 -0
- package/vendor/stylo/rule_tree/level.rs +396 -0
- package/vendor/stylo/rule_tree/map.rs +201 -0
- package/vendor/stylo/rule_tree/mod.rs +427 -0
- package/vendor/stylo/rule_tree/source.rs +80 -0
- package/vendor/stylo/rule_tree/unsafe_box.rs +78 -0
- package/vendor/stylo/scoped_tls.rs +80 -0
- package/vendor/stylo/selector_map.rs +1050 -0
- package/vendor/stylo/selector_parser.rs +305 -0
- package/vendor/stylo/servo/animation.rs +1922 -0
- package/vendor/stylo/servo/attr.rs +714 -0
- package/vendor/stylo/servo/encoding_support.rs +81 -0
- package/vendor/stylo/servo/media_features.rs +254 -0
- package/vendor/stylo/servo/mod.rs +16 -0
- package/vendor/stylo/servo/restyle_damage.rs +215 -0
- package/vendor/stylo/servo/selector_parser.rs +1036 -0
- package/vendor/stylo/servo/shadow_parts.rs +207 -0
- package/vendor/stylo/shared_lock.rs +271 -0
- package/vendor/stylo/sharing/checks.rs +281 -0
- package/vendor/stylo/sharing/mod.rs +1000 -0
- package/vendor/stylo/simple_buckets_map.rs +52 -0
- package/vendor/stylo/str.rs +168 -0
- package/vendor/stylo/style_adjuster.rs +1086 -0
- package/vendor/stylo/style_resolver.rs +658 -0
- package/vendor/stylo/stylesheet_set.rs +658 -0
- package/vendor/stylo/stylesheets/appearance_base_rule.rs +51 -0
- package/vendor/stylo/stylesheets/container_rule.rs +769 -0
- package/vendor/stylo/stylesheets/counter_style_rule.rs +7 -0
- package/vendor/stylo/stylesheets/document_rule.rs +272 -0
- package/vendor/stylo/stylesheets/font_face_rule.rs +7 -0
- package/vendor/stylo/stylesheets/font_feature_values_rule.rs +481 -0
- package/vendor/stylo/stylesheets/font_palette_values_rule.rs +304 -0
- package/vendor/stylo/stylesheets/import_rule.rs +259 -0
- package/vendor/stylo/stylesheets/keyframes_rule.rs +733 -0
- package/vendor/stylo/stylesheets/layer_rule.rs +221 -0
- package/vendor/stylo/stylesheets/loader.rs +29 -0
- package/vendor/stylo/stylesheets/margin_rule.rs +190 -0
- package/vendor/stylo/stylesheets/media_rule.rs +191 -0
- package/vendor/stylo/stylesheets/mod.rs +918 -0
- package/vendor/stylo/stylesheets/namespace_rule.rs +43 -0
- package/vendor/stylo/stylesheets/nested_declarations_rule.rs +51 -0
- package/vendor/stylo/stylesheets/origin.rs +249 -0
- package/vendor/stylo/stylesheets/page_rule.rs +354 -0
- package/vendor/stylo/stylesheets/position_try_rule.rs +68 -0
- package/vendor/stylo/stylesheets/property_rule.rs +5 -0
- package/vendor/stylo/stylesheets/rule_list.rs +167 -0
- package/vendor/stylo/stylesheets/rule_parser.rs +1189 -0
- package/vendor/stylo/stylesheets/rules_iterator.rs +397 -0
- package/vendor/stylo/stylesheets/scope_rule.rs +511 -0
- package/vendor/stylo/stylesheets/starting_style_rule.rs +54 -0
- package/vendor/stylo/stylesheets/style_rule.rs +80 -0
- package/vendor/stylo/stylesheets/stylesheet.rs +570 -0
- package/vendor/stylo/stylesheets/supports_rule.rs +486 -0
- package/vendor/stylo/stylesheets/view_transition_rule.rs +81 -0
- package/vendor/stylo/stylist.rs +5076 -0
- package/vendor/stylo/thread_state.rs +87 -0
- package/vendor/stylo/traversal.rs +765 -0
- package/vendor/stylo/traversal_flags.rs +68 -0
- package/vendor/stylo/typed_om/mod.rs +981 -0
- package/vendor/stylo/typed_om/numeric.rs +128 -0
- package/vendor/stylo/typed_om/numeric_declaration.rs +93 -0
- package/vendor/stylo/typed_om/numeric_type.rs +640 -0
- package/vendor/stylo/typed_om/sum_value.rs +426 -0
- package/vendor/stylo/url/gecko.rs +367 -0
- package/vendor/stylo/url/mod.rs +71 -0
- package/vendor/stylo/url/servo.rs +239 -0
- package/vendor/stylo/use_counters/mod.rs +137 -0
- package/vendor/stylo/values/animated/color.rs +103 -0
- package/vendor/stylo/values/animated/effects.rs +26 -0
- package/vendor/stylo/values/animated/font.rs +37 -0
- package/vendor/stylo/values/animated/grid.rs +161 -0
- package/vendor/stylo/values/animated/lists.rs +141 -0
- package/vendor/stylo/values/animated/mod.rs +550 -0
- package/vendor/stylo/values/animated/svg.rs +46 -0
- package/vendor/stylo/values/animated/text.rs +58 -0
- package/vendor/stylo/values/animated/transform.rs +1592 -0
- package/vendor/stylo/values/computed/align.rs +90 -0
- package/vendor/stylo/values/computed/angle.rs +130 -0
- package/vendor/stylo/values/computed/animation.rs +124 -0
- package/vendor/stylo/values/computed/background.rs +13 -0
- package/vendor/stylo/values/computed/basic_shape.rs +267 -0
- package/vendor/stylo/values/computed/border.rs +163 -0
- package/vendor/stylo/values/computed/box.rs +267 -0
- package/vendor/stylo/values/computed/calc.rs +334 -0
- package/vendor/stylo/values/computed/color.rs +161 -0
- package/vendor/stylo/values/computed/column.rs +11 -0
- package/vendor/stylo/values/computed/corner_shape.rs +155 -0
- package/vendor/stylo/values/computed/counters.rs +26 -0
- package/vendor/stylo/values/computed/easing.rs +109 -0
- package/vendor/stylo/values/computed/effects.rs +30 -0
- package/vendor/stylo/values/computed/flex.rs +19 -0
- package/vendor/stylo/values/computed/font.rs +1517 -0
- package/vendor/stylo/values/computed/image.rs +273 -0
- package/vendor/stylo/values/computed/length.rs +576 -0
- package/vendor/stylo/values/computed/length_percentage.rs +1055 -0
- package/vendor/stylo/values/computed/list.rs +16 -0
- package/vendor/stylo/values/computed/mod.rs +1141 -0
- package/vendor/stylo/values/computed/motion.rs +73 -0
- package/vendor/stylo/values/computed/outline.rs +7 -0
- package/vendor/stylo/values/computed/page.rs +77 -0
- package/vendor/stylo/values/computed/param.rs +9 -0
- package/vendor/stylo/values/computed/percentage.rs +143 -0
- package/vendor/stylo/values/computed/position.rs +273 -0
- package/vendor/stylo/values/computed/ratio.rs +88 -0
- package/vendor/stylo/values/computed/rect.rs +19 -0
- package/vendor/stylo/values/computed/resolution.rs +76 -0
- package/vendor/stylo/values/computed/svg.rs +66 -0
- package/vendor/stylo/values/computed/table.rs +7 -0
- package/vendor/stylo/values/computed/text.rs +199 -0
- package/vendor/stylo/values/computed/time.rs +83 -0
- package/vendor/stylo/values/computed/transform.rs +559 -0
- package/vendor/stylo/values/computed/tree_counting.rs +30 -0
- package/vendor/stylo/values/computed/ui.rs +23 -0
- package/vendor/stylo/values/computed/url.rs +12 -0
- package/vendor/stylo/values/distance.rs +139 -0
- package/vendor/stylo/values/generics/animation.rs +363 -0
- package/vendor/stylo/values/generics/background.rs +65 -0
- package/vendor/stylo/values/generics/basic_shape.rs +1389 -0
- package/vendor/stylo/values/generics/border.rs +303 -0
- package/vendor/stylo/values/generics/box.rs +552 -0
- package/vendor/stylo/values/generics/calc.rs +2986 -0
- package/vendor/stylo/values/generics/color.rs +318 -0
- package/vendor/stylo/values/generics/column.rs +44 -0
- package/vendor/stylo/values/generics/counters.rs +320 -0
- package/vendor/stylo/values/generics/easing.rs +132 -0
- package/vendor/stylo/values/generics/effects.rs +131 -0
- package/vendor/stylo/values/generics/flex.rs +34 -0
- package/vendor/stylo/values/generics/font.rs +376 -0
- package/vendor/stylo/values/generics/grid.rs +962 -0
- package/vendor/stylo/values/generics/image.rs +653 -0
- package/vendor/stylo/values/generics/length.rs +656 -0
- package/vendor/stylo/values/generics/mod.rs +303 -0
- package/vendor/stylo/values/generics/motion.rs +274 -0
- package/vendor/stylo/values/generics/page.rs +167 -0
- package/vendor/stylo/values/generics/position.rs +669 -0
- package/vendor/stylo/values/generics/ratio.rs +88 -0
- package/vendor/stylo/values/generics/rect.rs +147 -0
- package/vendor/stylo/values/generics/size.rs +102 -0
- package/vendor/stylo/values/generics/svg.rs +226 -0
- package/vendor/stylo/values/generics/text.rs +268 -0
- package/vendor/stylo/values/generics/transform.rs +1157 -0
- package/vendor/stylo/values/generics/ui.rs +147 -0
- package/vendor/stylo/values/generics/url.rs +51 -0
- package/vendor/stylo/values/mod.rs +820 -0
- package/vendor/stylo/values/resolved/animation.rs +33 -0
- package/vendor/stylo/values/resolved/color.rs +53 -0
- package/vendor/stylo/values/resolved/counters.rs +45 -0
- package/vendor/stylo/values/resolved/mod.rs +316 -0
- package/vendor/stylo/values/specified/align.rs +711 -0
- package/vendor/stylo/values/specified/angle.rs +407 -0
- package/vendor/stylo/values/specified/animation.rs +921 -0
- package/vendor/stylo/values/specified/background.rs +270 -0
- package/vendor/stylo/values/specified/basic_shape.rs +986 -0
- package/vendor/stylo/values/specified/border.rs +430 -0
- package/vendor/stylo/values/specified/box.rs +2231 -0
- package/vendor/stylo/values/specified/calc.rs +1657 -0
- package/vendor/stylo/values/specified/color.rs +1210 -0
- package/vendor/stylo/values/specified/column.rs +11 -0
- package/vendor/stylo/values/specified/corner_shape.rs +152 -0
- package/vendor/stylo/values/specified/counters.rs +242 -0
- package/vendor/stylo/values/specified/easing.rs +225 -0
- package/vendor/stylo/values/specified/effects.rs +421 -0
- package/vendor/stylo/values/specified/flex.rs +42 -0
- package/vendor/stylo/values/specified/font.rs +2103 -0
- package/vendor/stylo/values/specified/frequency.rs +39 -0
- package/vendor/stylo/values/specified/grid.rs +407 -0
- package/vendor/stylo/values/specified/image.rs +1385 -0
- package/vendor/stylo/values/specified/intersection_observer.rs +80 -0
- package/vendor/stylo/values/specified/length.rs +2024 -0
- package/vendor/stylo/values/specified/list.rs +190 -0
- package/vendor/stylo/values/specified/mod.rs +531 -0
- package/vendor/stylo/values/specified/motion.rs +316 -0
- package/vendor/stylo/values/specified/number.rs +603 -0
- package/vendor/stylo/values/specified/outline.rs +69 -0
- package/vendor/stylo/values/specified/page.rs +94 -0
- package/vendor/stylo/values/specified/param.rs +121 -0
- package/vendor/stylo/values/specified/percentage.rs +364 -0
- package/vendor/stylo/values/specified/position.rs +2247 -0
- package/vendor/stylo/values/specified/ratio.rs +29 -0
- package/vendor/stylo/values/specified/rect.rs +28 -0
- package/vendor/stylo/values/specified/resolution.rs +237 -0
- package/vendor/stylo/values/specified/source_size_list.rs +135 -0
- package/vendor/stylo/values/specified/svg.rs +427 -0
- package/vendor/stylo/values/specified/svg_path.rs +1115 -0
- package/vendor/stylo/values/specified/table.rs +38 -0
- package/vendor/stylo/values/specified/text.rs +1561 -0
- package/vendor/stylo/values/specified/time.rs +313 -0
- package/vendor/stylo/values/specified/transform.rs +599 -0
- package/vendor/stylo/values/specified/tree_counting.rs +32 -0
- package/vendor/stylo/values/specified/ui.rs +344 -0
- package/vendor/stylo/values/specified/url.rs +12 -0
- package/vendor/stylo/values/tagged_numeric.rs +253 -0
- package/wasm/blitz_pdf.d.ts +67 -0
- package/wasm/blitz_pdf.js +699 -0
- package/wasm/blitz_pdf_bg.wasm +0 -0
- package/wasm/blitz_pdf_bg.wasm.d.ts +20 -0
|
@@ -0,0 +1,207 @@
|
|
|
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
|
+
use crate::derives::*;
|
|
6
|
+
use crate::values::AtomIdent;
|
|
7
|
+
use crate::Atom;
|
|
8
|
+
|
|
9
|
+
type Mapping<'a> = (&'a str, &'a str);
|
|
10
|
+
|
|
11
|
+
#[derive(Clone, Debug, MallocSizeOf)]
|
|
12
|
+
pub struct ShadowParts {
|
|
13
|
+
// FIXME: Consider a smarter data structure for this.
|
|
14
|
+
// Gecko uses a hashtable in both directions:
|
|
15
|
+
// https://searchfox.org/mozilla-central/rev/5d4178378f84c7130ccb8ac1723d33e380d7f7d7/layout/style/ShadowParts.h
|
|
16
|
+
mappings: Vec<(Atom, Atom)>,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// <https://drafts.csswg.org/css-shadow-parts/#parsing-mapping>
|
|
20
|
+
///
|
|
21
|
+
/// Returns `None` in the failure case.
|
|
22
|
+
pub fn parse_part_mapping(input: &str) -> Option<Mapping<'_>> {
|
|
23
|
+
// Step 1. Let input be the string being parsed.
|
|
24
|
+
// Step 2. Let position be a pointer into input, initially pointing at the start of the string.
|
|
25
|
+
// NOTE: We don't need an explicit position, we just drop stuff from the input
|
|
26
|
+
|
|
27
|
+
// Step 3. Collect a sequence of code points that are space characters
|
|
28
|
+
let input = input.trim_start_matches(|c| c == ' ');
|
|
29
|
+
|
|
30
|
+
// Step 4. Collect a sequence of code points that are not space characters or U+003A COLON characters,
|
|
31
|
+
// and let first token be the result.
|
|
32
|
+
let space_or_colon_position = input
|
|
33
|
+
.char_indices()
|
|
34
|
+
.find(|(_, c)| matches!(c, ' ' | ':'))
|
|
35
|
+
.map(|(index, _)| index)
|
|
36
|
+
.unwrap_or(input.len());
|
|
37
|
+
let (first_token, input) = input.split_at(space_or_colon_position);
|
|
38
|
+
|
|
39
|
+
// Step 5. If first token is empty then return error.
|
|
40
|
+
if first_token.is_empty() {
|
|
41
|
+
return None;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Step 6. Collect a sequence of code points that are space characters.
|
|
45
|
+
let input = input.trim_start_matches(|c| c == ' ');
|
|
46
|
+
|
|
47
|
+
// Step 7. If the end of the input has been reached, return the tuple (first token, first token)
|
|
48
|
+
if input.is_empty() {
|
|
49
|
+
return Some((first_token, first_token));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Step 8. If character at position is not a U+003A COLON character, return error.
|
|
53
|
+
// Step 9. Consume the U+003A COLON character.
|
|
54
|
+
let Some(input) = input.strip_prefix(':') else {
|
|
55
|
+
return None;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Step 10. Collect a sequence of code points that are space characters.
|
|
59
|
+
let input = input.trim_start_matches(|c| c == ' ');
|
|
60
|
+
|
|
61
|
+
// Step 11. Collect a sequence of code points that are not space characters or U+003A COLON characters.
|
|
62
|
+
// and let second token be the result.
|
|
63
|
+
let space_or_colon_position = input
|
|
64
|
+
.char_indices()
|
|
65
|
+
.find(|(_, c)| matches!(c, ' ' | ':'))
|
|
66
|
+
.map(|(index, _)| index)
|
|
67
|
+
.unwrap_or(input.len());
|
|
68
|
+
let (second_token, input) = input.split_at(space_or_colon_position);
|
|
69
|
+
|
|
70
|
+
// Step 12. If second token is empty then return error.
|
|
71
|
+
if second_token.is_empty() {
|
|
72
|
+
return None;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Step 13. Collect a sequence of code points that are space characters.
|
|
76
|
+
let input = input.trim_start_matches(|c| c == ' ');
|
|
77
|
+
|
|
78
|
+
// Step 14. If position is not past the end of input then return error.
|
|
79
|
+
if !input.is_empty() {
|
|
80
|
+
return None;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Step 14. Return the tuple (first token, second token).
|
|
84
|
+
Some((first_token, second_token))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// <https://drafts.csswg.org/css-shadow-parts/#parsing-mapping-list>
|
|
88
|
+
fn parse_mapping_list(input: &str) -> impl Iterator<Item = Mapping<'_>> {
|
|
89
|
+
// Step 1. Let input be the string being parsed.
|
|
90
|
+
// Step 2. Split the string input on commas. Let unparsed mappings be the resulting list of strings.
|
|
91
|
+
let unparsed_mappings = input.split(',');
|
|
92
|
+
|
|
93
|
+
// Step 3. Let mappings be an initially empty list of tuples of tokens.
|
|
94
|
+
// This list will be the result of this algorithm.
|
|
95
|
+
// NOTE: We return an iterator here - it is up to the caller to turn it into a list
|
|
96
|
+
|
|
97
|
+
// Step 4. For each string unparsed mapping in unparsed mappings, run the following substeps:
|
|
98
|
+
unparsed_mappings.filter_map(|unparsed_mapping| {
|
|
99
|
+
// Step 4.1 If unparsed mapping is empty or contains only space characters,
|
|
100
|
+
// continue to the next iteration of the loop.
|
|
101
|
+
if unparsed_mapping.chars().all(|c| c == ' ') {
|
|
102
|
+
return None;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Step 4.2 Let mapping be the result of parsing unparsed mapping using the rules for parsing part mappings.
|
|
106
|
+
// Step 4.3 If mapping is an error then continue to the next iteration of the loop.
|
|
107
|
+
// This allows clients to skip over new syntax that is not understood.
|
|
108
|
+
// Step 4.4 Append mapping to mappings.
|
|
109
|
+
parse_part_mapping(unparsed_mapping)
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
impl ShadowParts {
|
|
114
|
+
pub fn parse(input: &str) -> Self {
|
|
115
|
+
Self {
|
|
116
|
+
mappings: parse_mapping_list(input)
|
|
117
|
+
.map(|(first, second)| (first.into(), second.into()))
|
|
118
|
+
.collect(),
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Call the provided callback for each exported part with the given name.
|
|
123
|
+
pub fn for_each_exported_part<F>(&self, name: &Atom, mut callback: F)
|
|
124
|
+
where
|
|
125
|
+
F: FnMut(&AtomIdent),
|
|
126
|
+
{
|
|
127
|
+
for (from, to) in &self.mappings {
|
|
128
|
+
if from == name {
|
|
129
|
+
callback(AtomIdent::cast(to));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
pub fn imported_part(&self, name: &Atom) -> Option<&Atom> {
|
|
135
|
+
self.mappings
|
|
136
|
+
.iter()
|
|
137
|
+
.find(|(_, to)| to == name)
|
|
138
|
+
.map(|(from, _)| from)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#[cfg(test)]
|
|
143
|
+
mod tests {
|
|
144
|
+
use super::*;
|
|
145
|
+
|
|
146
|
+
#[test]
|
|
147
|
+
fn parse_valid_mapping() {
|
|
148
|
+
assert_eq!(
|
|
149
|
+
parse_part_mapping("foo"),
|
|
150
|
+
Some(("foo", "foo")),
|
|
151
|
+
"Single token"
|
|
152
|
+
);
|
|
153
|
+
assert_eq!(
|
|
154
|
+
parse_part_mapping(" foo"),
|
|
155
|
+
Some(("foo", "foo")),
|
|
156
|
+
"Single token with leading whitespace"
|
|
157
|
+
);
|
|
158
|
+
assert_eq!(
|
|
159
|
+
parse_part_mapping("foo "),
|
|
160
|
+
Some(("foo", "foo")),
|
|
161
|
+
"Single token with trailing whitespace"
|
|
162
|
+
);
|
|
163
|
+
assert_eq!(
|
|
164
|
+
parse_part_mapping("foo:bar"),
|
|
165
|
+
Some(("foo", "bar")),
|
|
166
|
+
"Two tokens"
|
|
167
|
+
);
|
|
168
|
+
assert_eq!(
|
|
169
|
+
parse_part_mapping("foo:bar "),
|
|
170
|
+
Some(("foo", "bar")),
|
|
171
|
+
"Two tokens with trailing whitespace"
|
|
172
|
+
);
|
|
173
|
+
assert_eq!(
|
|
174
|
+
parse_part_mapping("🦀:🚀"),
|
|
175
|
+
Some(("🦀", "🚀")),
|
|
176
|
+
"Two tokens consisting of non-ascii characters"
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#[test]
|
|
181
|
+
fn reject_invalid_mapping() {
|
|
182
|
+
assert!(parse_part_mapping("").is_none(), "Empty input");
|
|
183
|
+
assert!(parse_part_mapping(" ").is_none(), "Only whitespace");
|
|
184
|
+
assert!(parse_part_mapping("foo bar").is_none(), "Missing colon");
|
|
185
|
+
assert!(parse_part_mapping(":bar").is_none(), "Empty first token");
|
|
186
|
+
assert!(parse_part_mapping("foo:").is_none(), "Empty second token");
|
|
187
|
+
assert!(
|
|
188
|
+
parse_part_mapping("foo:bar baz").is_none(),
|
|
189
|
+
"Trailing input"
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#[test]
|
|
194
|
+
fn parse_valid_mapping_list() {
|
|
195
|
+
let mut mappings = parse_mapping_list("foo: bar, totally-invalid-mapping:,,");
|
|
196
|
+
|
|
197
|
+
// "foo: bar" is a valid mapping
|
|
198
|
+
assert_eq!(
|
|
199
|
+
mappings.next(),
|
|
200
|
+
Some(("foo", "bar")),
|
|
201
|
+
"First mapping should be in the list"
|
|
202
|
+
);
|
|
203
|
+
// "totally-invalid-mapping" is not a valid mapping and should be ignored
|
|
204
|
+
// "" is not valid (and consists of nothing but whitespace), so it should be ignored
|
|
205
|
+
assert_eq!(mappings.next(), None, "No more mappings should exist");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
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
|
+
//! Different objects protected by the same lock
|
|
6
|
+
|
|
7
|
+
use crate::derives::MallocSizeOf;
|
|
8
|
+
use crate::stylesheets::Origin;
|
|
9
|
+
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
|
10
|
+
use servo_arc::Arc;
|
|
11
|
+
use std::cell::UnsafeCell;
|
|
12
|
+
use std::fmt;
|
|
13
|
+
use std::ptr;
|
|
14
|
+
use style_traits::{CssString, CssStringWriter};
|
|
15
|
+
use to_shmem::{SharedMemoryBuilder, ToShmem};
|
|
16
|
+
|
|
17
|
+
/// A shared read/write lock that can protect multiple objects.
|
|
18
|
+
///
|
|
19
|
+
/// We don't need the blocking behavior, just the safety. As such we implement
|
|
20
|
+
/// this with an AtomicRefCell, which is ~2x as fast as an RwLock, and panics
|
|
21
|
+
/// (rather than deadlocking) when things go wrong (which is much easier to
|
|
22
|
+
/// debug on CI).
|
|
23
|
+
///
|
|
24
|
+
/// Gecko also needs the ability to have "read only" SharedRwLocks, which are
|
|
25
|
+
/// used for objects stored in (read only) shared memory. Attempting to acquire
|
|
26
|
+
/// write access to objects protected by a read only SharedRwLock will panic.
|
|
27
|
+
#[derive(Clone)]
|
|
28
|
+
pub struct SharedRwLock {
|
|
29
|
+
cell: Option<Arc<AtomicRefCell<SomethingZeroSizedButTyped>>>,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#[cfg(feature = "servo")]
|
|
33
|
+
malloc_size_of::malloc_size_of_is_0!(SharedRwLock);
|
|
34
|
+
|
|
35
|
+
#[derive(MallocSizeOf)]
|
|
36
|
+
struct SomethingZeroSizedButTyped;
|
|
37
|
+
|
|
38
|
+
impl fmt::Debug for SharedRwLock {
|
|
39
|
+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
40
|
+
f.write_str("SharedRwLock")
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl Default for SharedRwLock {
|
|
45
|
+
fn default() -> Self {
|
|
46
|
+
Self::new()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
impl SharedRwLock {
|
|
51
|
+
/// Create a new shared lock.
|
|
52
|
+
pub fn new() -> Self {
|
|
53
|
+
SharedRwLock {
|
|
54
|
+
cell: Some(Arc::new(AtomicRefCell::new(SomethingZeroSizedButTyped))),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// Create a new global shared lock.
|
|
59
|
+
pub fn new_leaked() -> Self {
|
|
60
|
+
SharedRwLock {
|
|
61
|
+
cell: Some(Arc::new_leaked(AtomicRefCell::new(
|
|
62
|
+
SomethingZeroSizedButTyped,
|
|
63
|
+
))),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Create a new read-only shared lock.
|
|
68
|
+
pub fn read_only() -> Self {
|
|
69
|
+
SharedRwLock { cell: None }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[inline]
|
|
73
|
+
fn ptr(&self) -> *const SomethingZeroSizedButTyped {
|
|
74
|
+
self.cell
|
|
75
|
+
.as_ref()
|
|
76
|
+
.map(|cell| cell.as_ptr() as *const _)
|
|
77
|
+
.unwrap_or(ptr::null())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// Wrap the given data to make its access protected by this lock.
|
|
81
|
+
pub fn wrap<T>(&self, data: T) -> Locked<T> {
|
|
82
|
+
Locked {
|
|
83
|
+
shared_lock: self.clone(),
|
|
84
|
+
data: UnsafeCell::new(data),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// Obtain the lock for reading.
|
|
89
|
+
pub fn read(&self) -> SharedRwLockReadGuard<'_> {
|
|
90
|
+
SharedRwLockReadGuard(self.cell.as_ref().map(|cell| cell.borrow()))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// Obtain the lock for writing.
|
|
94
|
+
pub fn write(&self) -> SharedRwLockWriteGuard<'_> {
|
|
95
|
+
SharedRwLockWriteGuard(self.cell.as_ref().unwrap().borrow_mut())
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// Proof that a shared lock was obtained for reading.
|
|
100
|
+
pub struct SharedRwLockReadGuard<'a>(Option<AtomicRef<'a, SomethingZeroSizedButTyped>>);
|
|
101
|
+
|
|
102
|
+
impl<'a> SharedRwLockReadGuard<'a> {
|
|
103
|
+
#[inline]
|
|
104
|
+
fn ptr(&self) -> *const SomethingZeroSizedButTyped {
|
|
105
|
+
self.0
|
|
106
|
+
.as_ref()
|
|
107
|
+
.map(|r| &**r as *const _)
|
|
108
|
+
.unwrap_or(ptr::null())
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// Proof that a shared lock was obtained for writing.
|
|
113
|
+
pub struct SharedRwLockWriteGuard<'a>(AtomicRefMut<'a, SomethingZeroSizedButTyped>);
|
|
114
|
+
|
|
115
|
+
/// Data protect by a shared lock.
|
|
116
|
+
pub struct Locked<T> {
|
|
117
|
+
shared_lock: SharedRwLock,
|
|
118
|
+
data: UnsafeCell<T>,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Unsafe: the data inside `UnsafeCell` is only accessed in `read_with` and `write_with`,
|
|
122
|
+
// where guards ensure synchronization.
|
|
123
|
+
unsafe impl<T: Send> Send for Locked<T> {}
|
|
124
|
+
unsafe impl<T: Send + Sync> Sync for Locked<T> {}
|
|
125
|
+
|
|
126
|
+
impl<T: fmt::Debug> fmt::Debug for Locked<T> {
|
|
127
|
+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
128
|
+
let guard = self.shared_lock.read();
|
|
129
|
+
self.read_with(&guard).fmt(f)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
impl<T> Locked<T> {
|
|
134
|
+
#[inline]
|
|
135
|
+
fn is_read_only_lock(&self) -> bool {
|
|
136
|
+
self.shared_lock.cell.is_none()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
fn same_lock_as(&self, ptr: *const SomethingZeroSizedButTyped) -> bool {
|
|
140
|
+
ptr::eq(self.shared_lock.ptr(), ptr)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// Access the data for reading.
|
|
144
|
+
pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T {
|
|
145
|
+
assert!(
|
|
146
|
+
self.is_read_only_lock() || self.same_lock_as(guard.ptr()),
|
|
147
|
+
"Locked::read_with called with a guard from an unrelated SharedRwLock: {:?} vs. {:?}",
|
|
148
|
+
self.shared_lock.ptr(),
|
|
149
|
+
guard.ptr(),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
let ptr = self.data.get();
|
|
153
|
+
|
|
154
|
+
// Unsafe:
|
|
155
|
+
//
|
|
156
|
+
// * The guard guarantees that the lock is taken for reading,
|
|
157
|
+
// and we’ve checked that it’s the correct lock.
|
|
158
|
+
// * The returned reference borrows *both* the data and the guard,
|
|
159
|
+
// so that it can outlive neither.
|
|
160
|
+
unsafe { &*ptr }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// Access the data for reading without verifying the lock. Use with caution.
|
|
164
|
+
pub unsafe fn read_unchecked(&self) -> &T {
|
|
165
|
+
unsafe {
|
|
166
|
+
let ptr = self.data.get();
|
|
167
|
+
&*ptr
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// Access the data for writing.
|
|
172
|
+
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
|
|
173
|
+
assert!(
|
|
174
|
+
!self.is_read_only_lock() && self.same_lock_as(&*guard.0),
|
|
175
|
+
"Locked::write_with called with a guard from a read only or unrelated SharedRwLock"
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
let ptr = self.data.get();
|
|
179
|
+
|
|
180
|
+
// Unsafe:
|
|
181
|
+
//
|
|
182
|
+
// * The guard guarantees that the lock is taken for writing,
|
|
183
|
+
// and we’ve checked that it’s the correct lock.
|
|
184
|
+
// * The returned reference borrows *both* the data and the guard,
|
|
185
|
+
// so that it can outlive neither.
|
|
186
|
+
// * We require a mutable borrow of the guard,
|
|
187
|
+
// so that one write guard can only be used once at a time.
|
|
188
|
+
unsafe { &mut *ptr }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
impl<T: ToShmem> ToShmem for Locked<T> {
|
|
193
|
+
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> to_shmem::Result<Self> {
|
|
194
|
+
use std::mem::ManuallyDrop;
|
|
195
|
+
|
|
196
|
+
let guard = self.shared_lock.read();
|
|
197
|
+
Ok(ManuallyDrop::new(Locked {
|
|
198
|
+
shared_lock: SharedRwLock::read_only(),
|
|
199
|
+
data: UnsafeCell::new(ManuallyDrop::into_inner(
|
|
200
|
+
self.read_with(&guard).to_shmem(builder)?,
|
|
201
|
+
)),
|
|
202
|
+
}))
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#[allow(dead_code)]
|
|
207
|
+
mod compile_time_assert {
|
|
208
|
+
use super::{SharedRwLockReadGuard, SharedRwLockWriteGuard};
|
|
209
|
+
|
|
210
|
+
trait Marker1 {}
|
|
211
|
+
impl<T: Clone> Marker1 for T {}
|
|
212
|
+
impl<'a> Marker1 for SharedRwLockReadGuard<'a> {} // Assert SharedRwLockReadGuard: !Clone
|
|
213
|
+
impl<'a> Marker1 for SharedRwLockWriteGuard<'a> {} // Assert SharedRwLockWriteGuard: !Clone
|
|
214
|
+
|
|
215
|
+
trait Marker2 {}
|
|
216
|
+
impl<T: Copy> Marker2 for T {}
|
|
217
|
+
impl<'a> Marker2 for SharedRwLockReadGuard<'a> {} // Assert SharedRwLockReadGuard: !Copy
|
|
218
|
+
impl<'a> Marker2 for SharedRwLockWriteGuard<'a> {} // Assert SharedRwLockWriteGuard: !Copy
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/// Like ToCss, but with a lock guard given by the caller, and with the writer specified
|
|
222
|
+
/// concretely rather than with a parameter.
|
|
223
|
+
pub trait ToCssWithGuard {
|
|
224
|
+
/// Serialize `self` in CSS syntax, writing to `dest`, using the given lock guard.
|
|
225
|
+
fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result;
|
|
226
|
+
|
|
227
|
+
/// Serialize `self` in CSS syntax using the given lock guard and return a string.
|
|
228
|
+
///
|
|
229
|
+
/// (This is a convenience wrapper for `to_css` and probably should not be overridden.)
|
|
230
|
+
#[inline]
|
|
231
|
+
fn to_css_string(&self, guard: &SharedRwLockReadGuard) -> CssString {
|
|
232
|
+
let mut s = CssString::new();
|
|
233
|
+
self.to_css(guard, &mut s).unwrap();
|
|
234
|
+
s
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/// A trait to do a deep clone of a given CSS type. Gets a lock and a read
|
|
239
|
+
/// guard, in order to be able to read and clone nested structures.
|
|
240
|
+
pub trait DeepCloneWithLock: Sized {
|
|
241
|
+
/// Deep clones this object.
|
|
242
|
+
fn deep_clone_with_lock(&self, lock: &SharedRwLock, guard: &SharedRwLockReadGuard) -> Self;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/// Guards for a document
|
|
246
|
+
#[derive(Clone)]
|
|
247
|
+
pub struct StylesheetGuards<'a> {
|
|
248
|
+
/// For author-origin stylesheets.
|
|
249
|
+
pub author: &'a SharedRwLockReadGuard<'a>,
|
|
250
|
+
|
|
251
|
+
/// For user-agent-origin and user-origin stylesheets
|
|
252
|
+
pub ua_or_user: &'a SharedRwLockReadGuard<'a>,
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
impl<'a> StylesheetGuards<'a> {
|
|
256
|
+
/// Get the guard for a given stylesheet origin.
|
|
257
|
+
pub fn for_origin(&self, origin: Origin) -> &SharedRwLockReadGuard<'a> {
|
|
258
|
+
match origin {
|
|
259
|
+
Origin::Author => self.author,
|
|
260
|
+
_ => self.ua_or_user,
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/// Same guard for all origins
|
|
265
|
+
pub fn same(guard: &'a SharedRwLockReadGuard<'a>) -> Self {
|
|
266
|
+
StylesheetGuards {
|
|
267
|
+
author: guard,
|
|
268
|
+
ua_or_user: guard,
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|