2016-01-19 11:49:10 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2018-12-02 21:46:06 +03:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
2016-01-19 11:49:10 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
use super::error_reporter::ErrorReporter;
|
|
|
|
use super::stylesheet_loader::{AsyncStylesheetParser, StylesheetLoader};
|
2019-11-01 00:35:05 +03:00
|
|
|
use bincode::{deserialize, serialize};
|
2016-11-24 02:47:18 +03:00
|
|
|
use cssparser::ToCss as ParserToCss;
|
2019-03-30 23:18:33 +03:00
|
|
|
use cssparser::{ParseErrorKind, Parser, ParserInput, SourceLocation, UnicodeRange};
|
servo: Merge #18452 - Overhaul MallocSizeOf and related things (from nnethercote:bug-1398737); r=jdm
This patch makes the MallocSizeOf stuff in Stylo work more like the HeapSizeOf
stuff already in Servo, except better. In particular, it adds deriving support
for MallocSizeOf, which will make it easier to improve coverage.
The patch does the following.
- Combines servo/components/style/stylesheets/memory.rs and the heapsize crate
into a new crate, malloc_size_of.
- Forks the heapsize_derive crate, calling it malloc_size_of, so that
MallocSizeOf can be derived.
- Both the new crates have MIT/Apache licenses, like heapsize, in case they are
incorporated into heapsize in the future.
- Renames the methods within MallocSizeOf and the related traits so they are
more concise.
- Removes MallocSizeOfWithGuard.
- Adds `derive(MallocSizeOf)` to a lot of types, in some cases replacing an
equivalent or almost-equivalent hand-written implementation.
- Adds stuff so that Rc/Arc can be handled properly.
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because tested on Gecko side.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 7f4cb1861b172423781a369b2decca6c65d60546
--HG--
rename : servo/components/hashglobe/LICENSE-APACHE => servo/components/malloc_size_of/LICENSE-APACHE
rename : servo/components/hashglobe/LICENSE-MIT => servo/components/malloc_size_of/LICENSE-MIT
rename : servo/components/jstraceable_derive/Cargo.toml => servo/components/malloc_size_of_derive/Cargo.toml
rename : servo/components/hashglobe/LICENSE-APACHE => servo/components/malloc_size_of_derive/LICENSE-APACHE
rename : servo/components/hashglobe/LICENSE-MIT => servo/components/malloc_size_of_derive/LICENSE-MIT
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : a8254c4ae15901b764d918355e900a1e74d6eb03
2017-09-12 06:11:25 +03:00
|
|
|
use malloc_size_of::MallocSizeOfOps;
|
2019-05-15 11:57:36 +03:00
|
|
|
use nsstring::{nsCString, nsString};
|
2019-09-14 01:12:12 +03:00
|
|
|
use selectors::matching::{matches_selector, MatchingContext, MatchingMode, VisitedHandlingMode};
|
2018-04-14 19:05:44 +03:00
|
|
|
use selectors::{NthIndexCache, SelectorList};
|
2017-07-21 21:05:13 +03:00
|
|
|
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
|
2018-01-17 22:55:03 +03:00
|
|
|
use smallvec::SmallVec;
|
2017-09-14 12:28:50 +03:00
|
|
|
use std::cell::RefCell;
|
2018-04-29 02:03:31 +03:00
|
|
|
use std::collections::BTreeSet;
|
2016-11-04 07:42:06 +03:00
|
|
|
use std::fmt::Write;
|
2017-08-11 08:40:18 +03:00
|
|
|
use std::iter;
|
2018-02-19 07:13:10 +03:00
|
|
|
use std::os::raw::c_void;
|
2016-11-25 20:00:44 +03:00
|
|
|
use std::ptr;
|
2017-09-07 00:40:33 +03:00
|
|
|
use style::applicable_declarations::ApplicableDeclarationBlock;
|
2018-02-16 17:54:06 +03:00
|
|
|
use style::author_styles::AuthorStyles;
|
2017-05-12 16:56:47 +03:00
|
|
|
use style::context::ThreadLocalStyleContext;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::context::{CascadeInputs, QuirksMode, SharedStyleContext, StyleContext};
|
2017-12-05 06:22:50 +03:00
|
|
|
use style::counter_style;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::data::{self, ElementStyles};
|
2017-10-26 15:51:21 +03:00
|
|
|
use style::dom::{ShowSubtreeData, TDocument, TElement, TNode};
|
2017-08-25 20:23:41 +03:00
|
|
|
use style::driver;
|
2017-10-20 10:56:47 +03:00
|
|
|
use style::element_state::{DocumentState, ElementState};
|
2018-06-20 22:07:45 +03:00
|
|
|
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
2019-03-30 23:18:33 +03:00
|
|
|
use style::font_face::{self, ComputedFontStyleDescriptor, FontFaceSourceListComponent, Source};
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::font_metrics::{get_metrics_provider_for_product, FontMetricsProvider};
|
2017-07-02 17:00:39 +03:00
|
|
|
use style::gecko::data::{GeckoStyleSheet, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
2016-11-25 20:00:44 +03:00
|
|
|
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
2018-03-28 01:51:48 +03:00
|
|
|
use style::gecko::selector_parser::{NonTSPseudoClass, PseudoElement};
|
2016-09-26 10:36:05 +03:00
|
|
|
use style::gecko::traversal::RecalcStyleOnly;
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
use style::gecko::url;
|
2017-10-23 16:14:35 +03:00
|
|
|
use style::gecko::wrapper::{GeckoElement, GeckoNode};
|
2017-08-23 06:04:34 +03:00
|
|
|
use style::gecko_bindings::bindings;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::bindings::nsACString;
|
|
|
|
use style::gecko_bindings::bindings::nsAString;
|
2017-05-20 15:24:21 +03:00
|
|
|
use style::gecko_bindings::bindings::Gecko_AddPropertyToSet;
|
2017-07-20 08:48:47 +03:00
|
|
|
use style::gecko_bindings::bindings::Gecko_AppendPropertyValuePair;
|
2017-09-06 02:35:55 +03:00
|
|
|
use style::gecko_bindings::bindings::Gecko_ConstructFontFeatureValueSet;
|
2017-05-13 22:05:40 +03:00
|
|
|
use style::gecko_bindings::bindings::Gecko_GetOrCreateFinalKeyframe;
|
|
|
|
use style::gecko_bindings::bindings::Gecko_GetOrCreateInitialKeyframe;
|
|
|
|
use style::gecko_bindings::bindings::Gecko_GetOrCreateKeyframeAtStart;
|
servo: Merge #18452 - Overhaul MallocSizeOf and related things (from nnethercote:bug-1398737); r=jdm
This patch makes the MallocSizeOf stuff in Stylo work more like the HeapSizeOf
stuff already in Servo, except better. In particular, it adds deriving support
for MallocSizeOf, which will make it easier to improve coverage.
The patch does the following.
- Combines servo/components/style/stylesheets/memory.rs and the heapsize crate
into a new crate, malloc_size_of.
- Forks the heapsize_derive crate, calling it malloc_size_of, so that
MallocSizeOf can be derived.
- Both the new crates have MIT/Apache licenses, like heapsize, in case they are
incorporated into heapsize in the future.
- Renames the methods within MallocSizeOf and the related traits so they are
more concise.
- Removes MallocSizeOfWithGuard.
- Adds `derive(MallocSizeOf)` to a lot of types, in some cases replacing an
equivalent or almost-equivalent hand-written implementation.
- Adds stuff so that Rc/Arc can be handled properly.
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because tested on Gecko side.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 7f4cb1861b172423781a369b2decca6c65d60546
--HG--
rename : servo/components/hashglobe/LICENSE-APACHE => servo/components/malloc_size_of/LICENSE-APACHE
rename : servo/components/hashglobe/LICENSE-MIT => servo/components/malloc_size_of/LICENSE-MIT
rename : servo/components/jstraceable_derive/Cargo.toml => servo/components/malloc_size_of_derive/Cargo.toml
rename : servo/components/hashglobe/LICENSE-APACHE => servo/components/malloc_size_of_derive/LICENSE-APACHE
rename : servo/components/hashglobe/LICENSE-MIT => servo/components/malloc_size_of_derive/LICENSE-MIT
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : a8254c4ae15901b764d918355e900a1e74d6eb03
2017-09-12 06:11:25 +03:00
|
|
|
use style::gecko_bindings::bindings::Gecko_HaveSeenPtr;
|
2016-11-25 20:00:44 +03:00
|
|
|
use style::gecko_bindings::structs;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::structs::gfxFontFeatureValueSet;
|
|
|
|
use style::gecko_bindings::structs::nsAtom;
|
|
|
|
use style::gecko_bindings::structs::nsCSSCounterDesc;
|
|
|
|
use style::gecko_bindings::structs::nsCSSFontDesc;
|
|
|
|
use style::gecko_bindings::structs::nsCSSPropertyID;
|
|
|
|
use style::gecko_bindings::structs::nsChangeHint;
|
|
|
|
use style::gecko_bindings::structs::nsCompatibility;
|
|
|
|
use style::gecko_bindings::structs::nsStyleTransformMatrix::MatrixTransformOperator;
|
|
|
|
use style::gecko_bindings::structs::nsTArray;
|
|
|
|
use style::gecko_bindings::structs::nsTimingFunction;
|
|
|
|
use style::gecko_bindings::structs::nsresult;
|
2017-10-20 12:18:53 +03:00
|
|
|
use style::gecko_bindings::structs::AtomArray;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::structs::CallerType;
|
|
|
|
use style::gecko_bindings::structs::CompositeOperation;
|
|
|
|
use style::gecko_bindings::structs::DeclarationBlockMutationClosure;
|
2017-05-24 08:03:42 +03:00
|
|
|
use style::gecko_bindings::structs::IterationCompositeOperation;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::structs::Loader;
|
|
|
|
use style::gecko_bindings::structs::LoaderReusableStyleSheets;
|
2017-08-31 08:31:31 +03:00
|
|
|
use style::gecko_bindings::structs::MallocSizeOf as GeckoMallocSizeOf;
|
2017-08-13 14:39:40 +03:00
|
|
|
use style::gecko_bindings::structs::OriginFlags;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::structs::PropertyValuePair;
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::gecko_bindings::structs::PseudoStyleType;
|
2017-10-10 09:20:38 +03:00
|
|
|
use style::gecko_bindings::structs::RawServoSelectorList;
|
2017-11-13 06:01:34 +03:00
|
|
|
use style::gecko_bindings::structs::RawServoSourceSizeList;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::structs::RawServoStyleRule;
|
2017-08-03 03:39:15 +03:00
|
|
|
use style::gecko_bindings::structs::SeenPtrs;
|
2017-05-10 23:08:59 +03:00
|
|
|
use style::gecko_bindings::structs::ServoElementSnapshotTable;
|
2017-08-31 08:31:31 +03:00
|
|
|
use style::gecko_bindings::structs::ServoStyleSetSizes;
|
2017-07-28 02:29:29 +03:00
|
|
|
use style::gecko_bindings::structs::ServoTraversalFlags;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::structs::SheetLoadData;
|
|
|
|
use style::gecko_bindings::structs::SheetLoadDataHolder;
|
|
|
|
use style::gecko_bindings::structs::SheetParsingMode;
|
2017-05-25 13:50:52 +03:00
|
|
|
use style::gecko_bindings::structs::StyleRuleInclusion;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::structs::StyleSheet as DomStyleSheet;
|
2017-04-03 07:30:56 +03:00
|
|
|
use style::gecko_bindings::structs::URLExtraData;
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeckoElement};
|
|
|
|
use style::gecko_bindings::structs::{
|
|
|
|
RawServoAnimationValue, RawServoAuthorStyles, RawServoCounterStyleRule,
|
|
|
|
RawServoDeclarationBlock, RawServoFontFaceRule, RawServoFontFeatureValuesRule,
|
|
|
|
RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule, RawServoMediaList,
|
|
|
|
RawServoMediaRule, RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule,
|
|
|
|
RawServoSharedMemoryBuilder, RawServoStyleSet, RawServoStyleSheetContents,
|
|
|
|
RawServoSupportsRule, ServoCssRules,
|
|
|
|
};
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasFFI};
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::gecko_bindings::sugar::ownership::{
|
|
|
|
HasBoxFFI, HasSimpleFFI, Owned, OwnedOrNull, Strong,
|
|
|
|
};
|
2017-04-03 15:05:42 +03:00
|
|
|
use style::gecko_bindings::sugar::refptr::RefPtr;
|
2019-09-10 01:39:46 +03:00
|
|
|
use style::global_style_data::{GlobalStyleData, GLOBAL_STYLE_DATA, StyleThreadPool, STYLE_THREAD_POOL};
|
2019-03-14 14:47:50 +03:00
|
|
|
use style::invalidation::element::restyle_hints::RestyleHint;
|
2018-06-14 23:22:07 +03:00
|
|
|
use style::media_queries::MediaList;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::parser::{self, Parse, ParserContext};
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::profiler_label;
|
2019-05-20 09:04:23 +03:00
|
|
|
use style::properties::animated_properties::{AnimationValue, AnimationValueMap};
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::properties::{parse_one_declaration_into, parse_style_attribute};
|
Bug 1575062 - Support css use counters for unimplemented properties. r=emilio
For developing properties, we will handle them in an other bug.
Besides, I use an iframe for the test because we create a use counter in
the constructor of Document, which use the prefs to decide what kind of
properties we want to record. So, in the test, we have to reload iframe
to make sure we re-create the document, so does the use counter, to make
sure the prefs work properly.
The two prefs affect the css use counters:
1. layout.css.use-counters.enabled: Allocate use counters, and record
non-custom properties.
2. layout.css.use-counters-unimplemented.enabled: Record all unimplmented
properties into the use counters.
If we disable layout.css.use-counters.enblaed, we don't create use counters
object, so layout.css.use-counters-unimplemented.enabled doesn't work,
either.
Differential Revision: https://phabricator.services.mozilla.com/D43860
--HG--
extra : moz-landing-system : lando
2019-08-30 02:40:13 +03:00
|
|
|
use style::properties::{ComputedValues, CountedUnknownProperty, Importance, NonCustomPropertyId};
|
2018-05-05 18:55:52 +03:00
|
|
|
use style::properties::{LonghandId, LonghandIdSet, PropertyDeclarationBlock, PropertyId};
|
2017-09-29 18:01:52 +03:00
|
|
|
use style::properties::{PropertyDeclarationId, ShorthandId};
|
2019-03-30 03:16:27 +03:00
|
|
|
use style::properties::{SourcePropertyDeclaration, StyleBuilder, UnparsedValue};
|
2017-09-14 12:28:50 +03:00
|
|
|
use style::rule_cache::RuleCacheConditions;
|
2018-04-21 02:28:33 +03:00
|
|
|
use style::rule_tree::{CascadeLevel, StrongRuleNode};
|
2019-03-30 23:18:33 +03:00
|
|
|
use style::selector_parser::PseudoElementCascadeType;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard};
|
2017-10-20 12:18:53 +03:00
|
|
|
use style::string_cache::{Atom, WeakAtom};
|
2017-04-28 18:25:21 +03:00
|
|
|
use style::style_adjuster::StyleAdjuster;
|
2018-02-15 03:39:35 +03:00
|
|
|
use style::stylesheets::import_rule::ImportSheet;
|
2017-06-05 00:26:30 +03:00
|
|
|
use style::stylesheets::keyframes_rule::{Keyframe, KeyframeSelector, KeyframesStepValue};
|
|
|
|
use style::stylesheets::supports_rule::parse_condition_or_declaration;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
|
|
|
use style::stylesheets::{CounterStyleRule, CssRule, CssRuleType, CssRules, CssRulesHelpers};
|
|
|
|
use style::stylesheets::{DocumentRule, FontFaceRule, FontFeatureValuesRule, ImportRule};
|
|
|
|
use style::stylesheets::{KeyframesRule, MediaRule, NamespaceRule, Origin, OriginSet, PageRule};
|
|
|
|
use style::stylesheets::{StyleRule, StylesheetContents, SupportsRule, UrlExtraData};
|
2019-12-12 16:57:54 +03:00
|
|
|
use style::stylesheets::{SanitizationData, SanitizationKind};
|
2018-02-10 01:18:08 +03:00
|
|
|
use style::stylist::{add_size_of_ua_cache, AuthorStylesEnabled, RuleInclusion, Stylist};
|
2016-11-21 17:16:36 +03:00
|
|
|
use style::thread_state;
|
2016-07-20 21:38:31 +03:00
|
|
|
use style::timer::Timer;
|
2017-07-12 10:28:44 +03:00
|
|
|
use style::traversal::resolve_style;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::traversal::DomTraversal;
|
2017-10-31 02:25:45 +03:00
|
|
|
use style::traversal_flags::{self, TraversalFlags};
|
2018-08-20 20:03:11 +03:00
|
|
|
use style::use_counters::UseCounters;
|
2017-08-22 15:22:10 +03:00
|
|
|
use style::values::animated::{Animate, Procedure, ToAnimatedZero};
|
2019-05-17 02:04:31 +03:00
|
|
|
use style::values::computed::{self, Context, ToComputedValue};
|
2017-08-14 00:23:58 +03:00
|
|
|
use style::values::distance::ComputeSquaredDistance;
|
2020-01-22 22:17:39 +03:00
|
|
|
use style::values::generics;
|
2017-10-16 12:49:33 +03:00
|
|
|
use style::values::specified;
|
2019-01-26 13:00:44 +03:00
|
|
|
use style::values::specified::gecko::IntersectionObserverRootMargin;
|
2017-11-13 06:01:34 +03:00
|
|
|
use style::values::specified::source_size_list::SourceSizeList;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::values::{CustomIdent, KeyframesName};
|
2019-03-18 19:38:48 +03:00
|
|
|
use style_traits::{CssWriter, ParsingMode, StyleParseErrorKind, ToCss};
|
2019-03-30 03:16:27 +03:00
|
|
|
use to_shmem::SharedMemoryBuilder;
|
2016-09-26 10:36:05 +03:00
|
|
|
|
2018-06-06 01:04:39 +03:00
|
|
|
trait ClosureHelper {
|
2018-06-18 13:30:24 +03:00
|
|
|
fn invoke(&self);
|
2018-06-06 01:04:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ClosureHelper for DeclarationBlockMutationClosure {
|
|
|
|
#[inline]
|
2018-06-18 13:30:24 +03:00
|
|
|
fn invoke(&self) {
|
2018-06-06 01:04:39 +03:00
|
|
|
if let Some(function) = self.function.as_ref() {
|
2018-06-18 13:30:24 +03:00
|
|
|
unsafe { function(self.data) };
|
2018-06-06 01:04:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 11:49:10 +03:00
|
|
|
/*
|
|
|
|
* For Gecko->Servo function calls, we need to redeclare the same signature that was declared in
|
|
|
|
* the C header in Gecko. In order to catch accidental mismatches, we run rust-bindgen against
|
|
|
|
* those signatures as well, giving us a second declaration of all the Servo_* functions in this
|
|
|
|
* crate. If there's a mismatch, LLVM will assert and abort, which is a rather awful thing to
|
|
|
|
* depend on but good enough for our purposes.
|
|
|
|
*/
|
|
|
|
|
2017-04-03 15:05:42 +03:00
|
|
|
// A dummy url data for where we don't pass url data in.
|
|
|
|
// We need to get rid of this sooner than later.
|
2018-06-21 14:09:35 +03:00
|
|
|
static mut DUMMY_URL_DATA: *mut URLExtraData = 0 as *mut _;
|
2017-02-23 21:15:41 +03:00
|
|
|
|
2016-05-05 04:37:26 +03:00
|
|
|
#[no_mangle]
|
2018-06-21 14:09:35 +03:00
|
|
|
pub unsafe extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {
|
2017-08-14 14:42:44 +03:00
|
|
|
use style::gecko_bindings::sugar::origin_flags;
|
2019-03-20 00:10:30 +03:00
|
|
|
use style::properties::computed_value_flags;
|
2017-08-14 14:42:44 +03:00
|
|
|
|
2016-11-21 17:16:36 +03:00
|
|
|
// Pretend that we're a Servo Layout thread, to make some assertions happy.
|
2017-10-31 02:25:45 +03:00
|
|
|
thread_state::initialize(thread_state::ThreadState::LAYOUT);
|
2017-02-14 06:44:12 +03:00
|
|
|
|
|
|
|
// Perform some debug-only runtime assertions.
|
2017-08-14 14:42:44 +03:00
|
|
|
origin_flags::assert_flags_match();
|
2017-07-28 02:29:29 +03:00
|
|
|
parser::assert_parsing_mode_match();
|
2019-03-20 00:10:30 +03:00
|
|
|
computed_value_flags::assert_match();
|
2017-07-28 02:29:29 +03:00
|
|
|
traversal_flags::assert_traversal_flags_match();
|
2017-11-16 05:00:48 +03:00
|
|
|
specified::font::assert_variant_east_asian_matches();
|
2017-11-18 00:03:14 +03:00
|
|
|
specified::font::assert_variant_ligatures_matches();
|
2017-02-20 08:12:57 +03:00
|
|
|
|
2018-06-21 14:09:35 +03:00
|
|
|
DUMMY_URL_DATA = dummy_url_data;
|
2016-08-04 04:20:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-06-21 14:09:35 +03:00
|
|
|
pub unsafe extern "C" fn Servo_Shutdown() {
|
|
|
|
DUMMY_URL_DATA = ptr::null_mut();
|
2017-09-15 22:43:18 +03:00
|
|
|
Stylist::shutdown();
|
2019-03-30 03:15:53 +03:00
|
|
|
url::shutdown();
|
2017-04-03 15:05:42 +03:00
|
|
|
}
|
|
|
|
|
2018-06-21 14:09:35 +03:00
|
|
|
#[inline(always)]
|
|
|
|
unsafe fn dummy_url_data() -> &'static UrlExtraData {
|
|
|
|
UrlExtraData::from_ptr_ref(&DUMMY_URL_DATA)
|
2016-11-25 20:00:44 +03:00
|
|
|
}
|
2016-04-04 17:41:29 +03:00
|
|
|
|
2018-01-12 21:22:10 +03:00
|
|
|
#[allow(dead_code)]
|
|
|
|
fn is_main_thread() -> bool {
|
|
|
|
unsafe { bindings::Gecko_IsMainThread() }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
fn is_in_servo_traversal() -> bool {
|
|
|
|
unsafe { bindings::Gecko_IsInServoTraversal() }
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:44:09 +03:00
|
|
|
fn create_shared_context<'a>(
|
|
|
|
global_style_data: &GlobalStyleData,
|
|
|
|
guard: &'a SharedRwLockReadGuard,
|
|
|
|
per_doc_data: &'a PerDocumentStyleDataImpl,
|
|
|
|
traversal_flags: TraversalFlags,
|
|
|
|
snapshot_map: &'a ServoElementSnapshotTable,
|
|
|
|
) -> SharedStyleContext<'a> {
|
2016-11-25 20:00:44 +03:00
|
|
|
SharedStyleContext {
|
2017-05-12 16:56:47 +03:00
|
|
|
stylist: &per_doc_data.stylist,
|
2017-07-29 06:51:20 +03:00
|
|
|
visited_styles_enabled: per_doc_data.visited_styles_enabled(),
|
2017-04-12 10:27:02 +03:00
|
|
|
options: global_style_data.options.clone(),
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
guards: StylesheetGuards::same(guard),
|
2016-07-20 21:38:31 +03:00
|
|
|
timer: Timer::new(),
|
2017-11-23 14:44:09 +03:00
|
|
|
traversal_flags,
|
|
|
|
snapshot_map,
|
2016-11-25 20:00:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:44:09 +03:00
|
|
|
fn traverse_subtree(
|
|
|
|
element: GeckoElement,
|
|
|
|
global_style_data: &GlobalStyleData,
|
|
|
|
per_doc_data: &PerDocumentStyleDataImpl,
|
|
|
|
guard: &SharedRwLockReadGuard,
|
|
|
|
traversal_flags: TraversalFlags,
|
|
|
|
snapshots: &ServoElementSnapshotTable,
|
|
|
|
) {
|
2017-09-26 14:58:04 +03:00
|
|
|
let shared_style_context = create_shared_context(
|
|
|
|
&global_style_data,
|
|
|
|
&guard,
|
|
|
|
&per_doc_data,
|
|
|
|
traversal_flags,
|
|
|
|
snapshots,
|
|
|
|
);
|
2017-05-10 23:08:59 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let token = RecalcStyleOnly::pre_traverse(element, &shared_style_context);
|
2017-05-10 23:08:59 +03:00
|
|
|
|
2016-12-10 04:01:05 +03:00
|
|
|
if !token.should_traverse() {
|
2016-10-26 14:36:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-27 02:13:40 +03:00
|
|
|
debug!("Traversing subtree from {:?}", element);
|
2016-12-13 06:13:03 +03:00
|
|
|
|
2017-08-25 20:23:41 +03:00
|
|
|
let thread_pool_holder = &*STYLE_THREAD_POOL;
|
2019-09-10 01:39:46 +03:00
|
|
|
let pool;
|
2017-10-31 02:25:45 +03:00
|
|
|
let thread_pool = if traversal_flags.contains(TraversalFlags::ParallelTraversal) {
|
2019-09-10 01:39:46 +03:00
|
|
|
pool = thread_pool_holder.pool();
|
|
|
|
pool.as_ref()
|
2016-07-28 01:56:26 +03:00
|
|
|
} else {
|
2017-08-25 20:23:41 +03:00
|
|
|
None
|
2017-01-25 04:02:41 +03:00
|
|
|
};
|
|
|
|
|
2017-08-25 20:23:41 +03:00
|
|
|
let traversal = RecalcStyleOnly::new(shared_style_context);
|
2018-02-08 16:10:09 +03:00
|
|
|
driver::traverse_dom(&traversal, token, thread_pool);
|
2016-01-19 11:49:10 +03:00
|
|
|
}
|
|
|
|
|
2017-05-10 23:08:59 +03:00
|
|
|
/// Traverses the subtree rooted at `root` for restyling.
|
|
|
|
///
|
2017-09-26 14:58:04 +03:00
|
|
|
/// Returns whether the root was restyled. Whether anything else was restyled or
|
|
|
|
/// not can be inferred from the dirty bits in the rest of the tree.
|
2016-05-26 00:26:11 +03:00
|
|
|
#[no_mangle]
|
2017-08-27 02:13:40 +03:00
|
|
|
pub extern "C" fn Servo_TraverseSubtree(
|
2019-03-21 20:00:27 +03:00
|
|
|
root: &RawGeckoElement,
|
|
|
|
raw_data: &RawServoStyleSet,
|
2017-08-27 02:13:40 +03:00
|
|
|
snapshots: *const ServoElementSnapshotTable,
|
2018-11-20 07:37:53 +03:00
|
|
|
raw_flags: ServoTraversalFlags,
|
2017-08-27 02:13:40 +03:00
|
|
|
) -> bool {
|
2017-07-28 02:29:29 +03:00
|
|
|
let traversal_flags = TraversalFlags::from_bits_truncate(raw_flags);
|
2017-05-10 23:08:59 +03:00
|
|
|
debug_assert!(!snapshots.is_null());
|
2017-04-09 09:04:57 +03:00
|
|
|
|
2016-11-25 20:00:44 +03:00
|
|
|
let element = GeckoElement(root);
|
2017-03-27 07:13:44 +03:00
|
|
|
|
2017-08-09 21:03:00 +03:00
|
|
|
debug!("Servo_TraverseSubtree (flags={:?})", traversal_flags);
|
2017-08-27 02:13:40 +03:00
|
|
|
debug!("{:?}", ShowSubtreeData(element.as_node()));
|
2017-07-24 11:09:24 +03:00
|
|
|
|
2017-11-23 14:44:09 +03:00
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
if let Some(parent) = element.traversal_parent() {
|
2018-11-20 07:37:53 +03:00
|
|
|
let data = parent
|
|
|
|
.borrow_data()
|
|
|
|
.expect("Styling element with unstyled parent");
|
2017-11-23 14:44:09 +03:00
|
|
|
assert!(
|
|
|
|
!data.styles.is_display_none(),
|
|
|
|
"Styling element with display: none parent"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-20 13:18:30 +03:00
|
|
|
let needs_animation_only_restyle =
|
2018-11-20 07:37:53 +03:00
|
|
|
element.has_animation_only_dirty_descendants() || element.has_animation_restyle_hints();
|
2017-11-20 13:18:30 +03:00
|
|
|
|
2017-11-23 14:44:09 +03:00
|
|
|
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
debug_assert!(!per_doc_data.stylist.stylesheets_have_changed());
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
|
|
|
|
let was_initial_style = element.get_data().is_none();
|
|
|
|
|
2017-11-20 13:18:30 +03:00
|
|
|
if needs_animation_only_restyle {
|
2018-11-20 07:37:53 +03:00
|
|
|
debug!(
|
|
|
|
"Servo_TraverseSubtree doing animation-only restyle (aodd={})",
|
|
|
|
element.has_animation_only_dirty_descendants()
|
|
|
|
);
|
2017-11-23 14:44:09 +03:00
|
|
|
traverse_subtree(
|
|
|
|
element,
|
|
|
|
&global_style_data,
|
|
|
|
&per_doc_data,
|
|
|
|
&guard,
|
|
|
|
traversal_flags | TraversalFlags::AnimationOnly,
|
|
|
|
unsafe { &*snapshots },
|
|
|
|
);
|
2017-03-27 07:13:44 +03:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:44:09 +03:00
|
|
|
traverse_subtree(
|
|
|
|
element,
|
|
|
|
&global_style_data,
|
|
|
|
&per_doc_data,
|
|
|
|
&guard,
|
|
|
|
traversal_flags,
|
|
|
|
unsafe { &*snapshots },
|
|
|
|
);
|
2017-02-10 06:27:33 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
debug!(
|
|
|
|
"Servo_TraverseSubtree complete (dd={}, aodd={}, lfcd={}, lfc={}, data={:?})",
|
|
|
|
element.has_dirty_descendants(),
|
|
|
|
element.has_animation_only_dirty_descendants(),
|
|
|
|
element.descendants_need_frames(),
|
|
|
|
element.needs_frame(),
|
|
|
|
element.borrow_data().unwrap()
|
|
|
|
);
|
2017-08-09 21:03:00 +03:00
|
|
|
|
2017-11-23 14:44:09 +03:00
|
|
|
if was_initial_style {
|
|
|
|
debug_assert!(!element.borrow_data().unwrap().contains_restyle_data());
|
|
|
|
false
|
|
|
|
} else {
|
2018-11-20 07:37:53 +03:00
|
|
|
let element_was_restyled = element.borrow_data().unwrap().contains_restyle_data();
|
2017-11-23 14:44:09 +03:00
|
|
|
element_was_restyled
|
|
|
|
}
|
2016-05-26 00:26:11 +03:00
|
|
|
}
|
|
|
|
|
2017-06-17 00:13:38 +03:00
|
|
|
/// Checks whether the rule tree has crossed its threshold for unused nodes, and
|
|
|
|
/// if so, frees them.
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_MaybeGCRuleTree(raw_data: &RawServoStyleSet) {
|
2017-06-17 00:13:38 +03:00
|
|
|
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
|
|
|
unsafe {
|
|
|
|
per_doc_data.stylist.rule_tree().maybe_gc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 10:36:33 +03:00
|
|
|
#[no_mangle]
|
2017-10-14 16:13:59 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValues_Interpolate(
|
2019-03-21 20:00:27 +03:00
|
|
|
from: &RawServoAnimationValue,
|
|
|
|
to: &RawServoAnimationValue,
|
2017-10-14 16:13:59 +03:00
|
|
|
progress: f64,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2017-01-26 10:36:33 +03:00
|
|
|
let from_value = AnimationValue::as_arc(&from);
|
|
|
|
let to_value = AnimationValue::as_arc(&to);
|
2017-08-22 15:22:10 +03:00
|
|
|
if let Ok(value) = from_value.animate(to_value, Procedure::Interpolate { progress }) {
|
2017-01-26 10:36:33 +03:00
|
|
|
Arc::new(value).into_strong()
|
|
|
|
} else {
|
2019-03-21 20:00:27 +03:00
|
|
|
Strong::null()
|
2017-01-26 10:36:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 15:00:20 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValues_IsInterpolable(
|
2019-03-21 20:00:27 +03:00
|
|
|
from: &RawServoAnimationValue,
|
|
|
|
to: &RawServoAnimationValue,
|
2018-02-13 18:25:30 +03:00
|
|
|
) -> bool {
|
2017-04-12 15:00:20 +03:00
|
|
|
let from_value = AnimationValue::as_arc(&from);
|
|
|
|
let to_value = AnimationValue::as_arc(&to);
|
2018-11-20 07:37:53 +03:00
|
|
|
from_value
|
|
|
|
.animate(to_value, Procedure::Interpolate { progress: 0.5 })
|
|
|
|
.is_ok()
|
2017-04-12 15:00:20 +03:00
|
|
|
}
|
|
|
|
|
2017-06-05 07:41:06 +03:00
|
|
|
#[no_mangle]
|
2017-10-14 16:13:59 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValues_Add(
|
2019-03-21 20:00:27 +03:00
|
|
|
a: &RawServoAnimationValue,
|
|
|
|
b: &RawServoAnimationValue,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2017-06-05 07:41:06 +03:00
|
|
|
let a_value = AnimationValue::as_arc(&a);
|
|
|
|
let b_value = AnimationValue::as_arc(&b);
|
2017-08-22 15:22:10 +03:00
|
|
|
if let Ok(value) = a_value.animate(b_value, Procedure::Add) {
|
2017-06-05 07:41:06 +03:00
|
|
|
Arc::new(value).into_strong()
|
|
|
|
} else {
|
2019-03-21 20:00:27 +03:00
|
|
|
Strong::null()
|
2017-06-05 07:41:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-14 16:13:59 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValues_Accumulate(
|
2019-03-21 20:00:27 +03:00
|
|
|
a: &RawServoAnimationValue,
|
|
|
|
b: &RawServoAnimationValue,
|
2017-10-14 16:13:59 +03:00
|
|
|
count: u64,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2017-06-05 07:41:06 +03:00
|
|
|
let a_value = AnimationValue::as_arc(&a);
|
|
|
|
let b_value = AnimationValue::as_arc(&b);
|
2017-08-22 15:22:10 +03:00
|
|
|
if let Ok(value) = a_value.animate(b_value, Procedure::Accumulate { count }) {
|
2017-06-05 07:41:06 +03:00
|
|
|
Arc::new(value).into_strong()
|
|
|
|
} else {
|
2019-03-21 20:00:27 +03:00
|
|
|
Strong::null()
|
2017-06-05 07:41:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_AnimationValues_GetZeroValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
value_to_match: &RawServoAnimationValue,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2017-06-05 07:41:06 +03:00
|
|
|
let value_to_match = AnimationValue::as_arc(&value_to_match);
|
2017-07-19 11:56:05 +03:00
|
|
|
if let Ok(zero_value) = value_to_match.to_animated_zero() {
|
2017-06-05 07:41:06 +03:00
|
|
|
Arc::new(zero_value).into_strong()
|
|
|
|
} else {
|
2019-03-21 20:00:27 +03:00
|
|
|
Strong::null()
|
2017-06-05 07:41:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 08:52:13 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValues_ComputeDistance(
|
2019-03-21 20:00:27 +03:00
|
|
|
from: &RawServoAnimationValue,
|
|
|
|
to: &RawServoAnimationValue,
|
2018-02-13 18:25:30 +03:00
|
|
|
) -> f64 {
|
2017-04-21 08:52:13 +03:00
|
|
|
let from_value = AnimationValue::as_arc(&from);
|
|
|
|
let to_value = AnimationValue::as_arc(&to);
|
2017-08-31 07:21:49 +03:00
|
|
|
// If compute_squared_distance() failed, this function will return negative value
|
|
|
|
// in order to check whether we support the specified paced animation values.
|
2018-11-20 07:37:53 +03:00
|
|
|
from_value
|
|
|
|
.compute_squared_distance(to_value)
|
|
|
|
.map(|d| d.sqrt())
|
|
|
|
.unwrap_or(-1.0)
|
2017-04-21 08:52:13 +03:00
|
|
|
}
|
|
|
|
|
2017-10-27 22:38:43 +03:00
|
|
|
/// Compute one of the endpoints for the interpolation interval, compositing it with the
|
|
|
|
/// underlying value if needed.
|
|
|
|
/// An None returned value means, "Just use endpoint_value as-is."
|
|
|
|
/// It is the responsibility of the caller to ensure that |underlying_value| is provided
|
|
|
|
/// when it will be used.
|
|
|
|
fn composite_endpoint(
|
|
|
|
endpoint_value: Option<&RawOffsetArc<AnimationValue>>,
|
|
|
|
composite: CompositeOperation,
|
|
|
|
underlying_value: Option<&AnimationValue>,
|
|
|
|
) -> Option<AnimationValue> {
|
|
|
|
match endpoint_value {
|
2018-11-20 07:37:53 +03:00
|
|
|
Some(endpoint_value) => match composite {
|
|
|
|
CompositeOperation::Add => underlying_value
|
|
|
|
.expect("We should have an underlying_value")
|
|
|
|
.animate(endpoint_value, Procedure::Add)
|
|
|
|
.ok(),
|
|
|
|
CompositeOperation::Accumulate => underlying_value
|
|
|
|
.expect("We should have an underlying value")
|
|
|
|
.animate(endpoint_value, Procedure::Accumulate { count: 1 })
|
|
|
|
.ok(),
|
|
|
|
_ => None,
|
2017-10-27 22:38:43 +03:00
|
|
|
},
|
|
|
|
None => underlying_value.map(|v| v.clone()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Accumulate one of the endpoints of the animation interval.
|
|
|
|
/// A returned value of None means, "Just use endpoint_value as-is."
|
|
|
|
fn accumulate_endpoint(
|
|
|
|
endpoint_value: Option<&RawOffsetArc<AnimationValue>>,
|
|
|
|
composited_value: Option<AnimationValue>,
|
|
|
|
last_value: &AnimationValue,
|
2018-11-20 07:37:53 +03:00
|
|
|
current_iteration: u64,
|
2017-10-27 22:38:43 +03:00
|
|
|
) -> Option<AnimationValue> {
|
2018-11-20 07:37:53 +03:00
|
|
|
debug_assert!(
|
|
|
|
endpoint_value.is_some() || composited_value.is_some(),
|
|
|
|
"Should have a suitable value to use"
|
|
|
|
);
|
2017-10-27 22:38:43 +03:00
|
|
|
|
|
|
|
let count = current_iteration;
|
|
|
|
match composited_value {
|
2018-11-20 07:37:53 +03:00
|
|
|
Some(endpoint) => last_value
|
|
|
|
.animate(&endpoint, Procedure::Accumulate { count })
|
|
|
|
.ok()
|
|
|
|
.or(Some(endpoint)),
|
|
|
|
None => last_value
|
|
|
|
.animate(endpoint_value.unwrap(), Procedure::Accumulate { count })
|
|
|
|
.ok(),
|
2017-10-27 22:38:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Compose the animation segment. We composite it with the underlying_value and last_value if
|
|
|
|
/// needed.
|
|
|
|
/// The caller is responsible for providing an underlying value and last value
|
|
|
|
/// in all situations where there are needed.
|
|
|
|
fn compose_animation_segment(
|
2019-03-21 20:00:27 +03:00
|
|
|
segment: &structs::AnimationPropertySegment,
|
2017-10-27 22:38:43 +03:00
|
|
|
underlying_value: Option<&AnimationValue>,
|
|
|
|
last_value: Option<&AnimationValue>,
|
|
|
|
iteration_composite: IterationCompositeOperation,
|
|
|
|
current_iteration: u64,
|
|
|
|
total_progress: f64,
|
|
|
|
segment_progress: f64,
|
|
|
|
) -> AnimationValue {
|
|
|
|
// Extract keyframe values.
|
|
|
|
let raw_from_value;
|
|
|
|
let keyframe_from_value = if !segment.mFromValue.mServo.mRawPtr.is_null() {
|
|
|
|
raw_from_value = unsafe { &*segment.mFromValue.mServo.mRawPtr };
|
|
|
|
Some(AnimationValue::as_arc(&raw_from_value))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let raw_to_value;
|
|
|
|
let keyframe_to_value = if !segment.mToValue.mServo.mRawPtr.is_null() {
|
|
|
|
raw_to_value = unsafe { &*segment.mToValue.mServo.mRawPtr };
|
|
|
|
Some(AnimationValue::as_arc(&raw_to_value))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut composited_from_value = composite_endpoint(
|
|
|
|
keyframe_from_value,
|
|
|
|
segment.mFromComposite,
|
|
|
|
underlying_value,
|
|
|
|
);
|
|
|
|
let mut composited_to_value =
|
|
|
|
composite_endpoint(keyframe_to_value, segment.mToComposite, underlying_value);
|
2017-10-27 22:38:43 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
debug_assert!(
|
|
|
|
keyframe_from_value.is_some() || composited_from_value.is_some(),
|
|
|
|
"Should have a suitable from value to use"
|
|
|
|
);
|
|
|
|
debug_assert!(
|
|
|
|
keyframe_to_value.is_some() || composited_to_value.is_some(),
|
|
|
|
"Should have a suitable to value to use"
|
|
|
|
);
|
2017-10-27 22:38:43 +03:00
|
|
|
|
|
|
|
// Apply iteration composite behavior.
|
|
|
|
if iteration_composite == IterationCompositeOperation::Accumulate && current_iteration > 0 {
|
2018-11-20 07:37:53 +03:00
|
|
|
let last_value = last_value
|
|
|
|
.unwrap_or_else(|| underlying_value.expect("Should have a valid underlying value"));
|
|
|
|
|
|
|
|
composited_from_value = accumulate_endpoint(
|
|
|
|
keyframe_from_value,
|
|
|
|
composited_from_value,
|
|
|
|
last_value,
|
|
|
|
current_iteration,
|
|
|
|
);
|
|
|
|
composited_to_value = accumulate_endpoint(
|
|
|
|
keyframe_to_value,
|
|
|
|
composited_to_value,
|
|
|
|
last_value,
|
|
|
|
current_iteration,
|
|
|
|
);
|
2017-10-27 22:38:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use the composited value if there is one, otherwise, use the original keyframe value.
|
2018-11-20 07:37:53 +03:00
|
|
|
let from = composited_from_value
|
|
|
|
.as_ref()
|
|
|
|
.unwrap_or_else(|| keyframe_from_value.unwrap());
|
|
|
|
let to = composited_to_value
|
|
|
|
.as_ref()
|
|
|
|
.unwrap_or_else(|| keyframe_to_value.unwrap());
|
2017-10-27 22:38:43 +03:00
|
|
|
|
|
|
|
if segment.mToKey == segment.mFromKey {
|
2018-11-20 07:37:53 +03:00
|
|
|
return if total_progress < 0. {
|
|
|
|
from.clone()
|
|
|
|
} else {
|
|
|
|
to.clone()
|
|
|
|
};
|
2017-10-27 22:38:43 +03:00
|
|
|
}
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
match from.animate(
|
|
|
|
to,
|
|
|
|
Procedure::Interpolate {
|
|
|
|
progress: segment_progress,
|
|
|
|
},
|
|
|
|
) {
|
2017-10-27 22:38:43 +03:00
|
|
|
Ok(value) => value,
|
2018-11-20 07:37:53 +03:00
|
|
|
_ => {
|
|
|
|
if segment_progress < 0.5 {
|
|
|
|
from.clone()
|
|
|
|
} else {
|
|
|
|
to.clone()
|
|
|
|
}
|
|
|
|
},
|
2017-10-27 22:38:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_ComposeAnimationSegment(
|
2019-03-21 20:00:27 +03:00
|
|
|
segment: &structs::AnimationPropertySegment,
|
|
|
|
underlying_value: Option<&RawServoAnimationValue>,
|
|
|
|
last_value: Option<&RawServoAnimationValue>,
|
2017-10-27 22:38:43 +03:00
|
|
|
iteration_composite: IterationCompositeOperation,
|
|
|
|
progress: f64,
|
2018-11-20 07:37:53 +03:00
|
|
|
current_iteration: u64,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2017-10-27 22:38:43 +03:00
|
|
|
let underlying_value = AnimationValue::arc_from_borrowed(&underlying_value).map(|v| &**v);
|
|
|
|
let last_value = AnimationValue::arc_from_borrowed(&last_value).map(|v| &**v);
|
2018-02-13 18:25:30 +03:00
|
|
|
let result = compose_animation_segment(
|
|
|
|
segment,
|
|
|
|
underlying_value,
|
|
|
|
last_value,
|
|
|
|
iteration_composite,
|
|
|
|
current_iteration,
|
|
|
|
progress,
|
|
|
|
progress,
|
|
|
|
);
|
2017-10-27 22:38:43 +03:00
|
|
|
Arc::new(result).into_strong()
|
|
|
|
}
|
|
|
|
|
2017-04-06 06:53:30 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_AnimationCompose(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_value_map: &mut structs::RawServoAnimationValueMap,
|
|
|
|
base_values: &structs::RawServoAnimationValueTable,
|
2018-02-13 18:25:30 +03:00
|
|
|
css_property: nsCSSPropertyID,
|
2019-03-21 20:00:27 +03:00
|
|
|
segment: &structs::AnimationPropertySegment,
|
|
|
|
last_segment: &structs::AnimationPropertySegment,
|
|
|
|
computed_timing: &structs::ComputedTiming,
|
2018-02-13 18:25:30 +03:00
|
|
|
iteration_composite: IterationCompositeOperation,
|
|
|
|
) {
|
2017-04-06 06:53:30 +03:00
|
|
|
use style::gecko_bindings::bindings::Gecko_AnimationGetBaseStyle;
|
|
|
|
use style::gecko_bindings::bindings::Gecko_GetPositionInSegment;
|
|
|
|
use style::gecko_bindings::bindings::Gecko_GetProgressFromComputedTiming;
|
|
|
|
|
2017-09-29 18:01:52 +03:00
|
|
|
let property = match LonghandId::from_nscsspropertyid(css_property) {
|
|
|
|
Ok(longhand) if longhand.is_animatable() => longhand,
|
|
|
|
_ => return,
|
2017-06-15 06:17:47 +03:00
|
|
|
};
|
2017-05-01 13:51:48 +03:00
|
|
|
let value_map = AnimationValueMap::from_ffi_mut(raw_value_map);
|
2017-04-06 06:53:30 +03:00
|
|
|
|
2017-05-24 08:03:42 +03:00
|
|
|
// We will need an underlying value if either of the endpoints is null...
|
2017-05-15 07:24:48 +03:00
|
|
|
let need_underlying_value = segment.mFromValue.mServo.mRawPtr.is_null() ||
|
|
|
|
segment.mToValue.mServo.mRawPtr.is_null() ||
|
2017-05-24 08:03:42 +03:00
|
|
|
// ... or if they have a non-replace composite mode ...
|
2017-05-15 07:24:48 +03:00
|
|
|
segment.mFromComposite != CompositeOperation::Replace ||
|
2017-05-24 08:03:42 +03:00
|
|
|
segment.mToComposite != CompositeOperation::Replace ||
|
|
|
|
// ... or if we accumulate onto the last value and it is null.
|
|
|
|
(iteration_composite == IterationCompositeOperation::Accumulate &&
|
|
|
|
computed_timing.mCurrentIteration > 0 &&
|
|
|
|
last_segment.mToValue.mServo.mRawPtr.is_null());
|
2017-05-15 07:24:48 +03:00
|
|
|
|
2017-04-06 06:53:30 +03:00
|
|
|
// If either of the segment endpoints are null, get the underlying value to
|
|
|
|
// use from the current value in the values map (set by a lower-priority
|
|
|
|
// effect), or, if there is no current value, look up the cached base value
|
|
|
|
// for this property.
|
2017-05-15 07:24:48 +03:00
|
|
|
let underlying_value = if need_underlying_value {
|
2017-05-01 13:51:48 +03:00
|
|
|
let previous_composed_value = value_map.get(&property).cloned();
|
2017-04-06 06:53:30 +03:00
|
|
|
previous_composed_value.or_else(|| {
|
2019-08-26 12:58:53 +03:00
|
|
|
let raw_base_style =
|
|
|
|
unsafe { Gecko_AnimationGetBaseStyle(base_values, css_property).as_ref() };
|
2018-11-20 07:37:53 +03:00
|
|
|
AnimationValue::arc_from_borrowed(&raw_base_style)
|
|
|
|
.map(|v| &**v)
|
|
|
|
.cloned()
|
2017-04-06 06:53:30 +03:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2017-05-15 07:24:48 +03:00
|
|
|
if need_underlying_value && underlying_value.is_none() {
|
|
|
|
warn!("Underlying value should be valid when we expect to use it");
|
2017-04-06 06:53:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-27 22:38:43 +03:00
|
|
|
let raw_last_value;
|
|
|
|
let last_value = if !last_segment.mToValue.mServo.mRawPtr.is_null() {
|
|
|
|
raw_last_value = unsafe { &*last_segment.mToValue.mServo.mRawPtr };
|
|
|
|
Some(&**AnimationValue::as_arc(&raw_last_value))
|
2017-04-06 06:53:30 +03:00
|
|
|
} else {
|
2017-05-24 08:03:42 +03:00
|
|
|
None
|
2017-04-06 06:53:30 +03:00
|
|
|
};
|
|
|
|
|
2017-10-27 22:38:43 +03:00
|
|
|
let progress = unsafe { Gecko_GetProgressFromComputedTiming(computed_timing) };
|
|
|
|
let position = if segment.mToKey == segment.mFromKey {
|
|
|
|
// Note: compose_animation_segment doesn't use this value
|
|
|
|
// if segment.mFromKey == segment.mToKey, so assigning |progress| directly is fine.
|
|
|
|
progress
|
2017-04-06 06:53:30 +03:00
|
|
|
} else {
|
2017-10-27 22:38:43 +03:00
|
|
|
unsafe { Gecko_GetPositionInSegment(segment, progress, computed_timing.mBeforeFlag) }
|
2017-05-24 08:03:42 +03:00
|
|
|
};
|
|
|
|
|
2018-02-13 18:25:30 +03:00
|
|
|
let result = compose_animation_segment(
|
|
|
|
segment,
|
|
|
|
underlying_value.as_ref(),
|
|
|
|
last_value,
|
|
|
|
iteration_composite,
|
|
|
|
computed_timing.mCurrentIteration,
|
|
|
|
progress,
|
|
|
|
position,
|
|
|
|
);
|
2017-10-27 22:38:43 +03:00
|
|
|
value_map.insert(property, result);
|
2017-04-06 06:53:30 +03:00
|
|
|
}
|
|
|
|
|
2017-02-10 12:34:07 +03:00
|
|
|
macro_rules! get_property_id_from_nscsspropertyid {
|
|
|
|
($property_id: ident, $ret: expr) => {{
|
|
|
|
match PropertyId::from_nscsspropertyid($property_id) {
|
|
|
|
Ok(property_id) => property_id,
|
2018-11-20 07:37:53 +03:00
|
|
|
Err(()) => {
|
|
|
|
return $ret;
|
|
|
|
},
|
2017-02-10 12:34:07 +03:00
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
}};
|
2017-02-10 12:34:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 05:39:45 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValue_Serialize(
|
2019-03-21 20:00:27 +03:00
|
|
|
value: &RawServoAnimationValue,
|
2018-02-13 18:25:30 +03:00
|
|
|
property: nsCSSPropertyID,
|
2020-01-08 14:55:28 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2020-01-05 17:42:23 +03:00
|
|
|
buffer: &mut nsAString,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-02-10 12:34:07 +03:00
|
|
|
let uncomputed_value = AnimationValue::as_arc(&value).uncompute();
|
2020-01-08 14:55:28 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2017-03-08 14:07:04 +03:00
|
|
|
let rv = PropertyDeclarationBlock::with_one(uncomputed_value, Importance::Normal)
|
2018-11-20 07:37:53 +03:00
|
|
|
.single_value_to_css(
|
|
|
|
&get_property_id_from_nscsspropertyid!(property, ()),
|
|
|
|
buffer,
|
|
|
|
None,
|
|
|
|
None, /* No extra custom properties */
|
2020-01-08 14:56:25 +03:00
|
|
|
&data.stylist.device(),
|
2018-11-20 07:37:53 +03:00
|
|
|
);
|
2017-02-10 12:34:07 +03:00
|
|
|
debug_assert!(rv.is_ok());
|
2017-06-09 02:23:56 +03:00
|
|
|
}
|
|
|
|
|
2019-06-12 21:14:18 +03:00
|
|
|
/// Debug: MOZ_DBG for AnimationValue.
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_AnimationValue_Dump(
|
|
|
|
value: &RawServoAnimationValue,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2019-06-12 21:14:18 +03:00
|
|
|
) {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
2020-01-05 17:42:23 +03:00
|
|
|
write!(result, "{:?}", value).unwrap();
|
2019-06-12 21:14:18 +03:00
|
|
|
}
|
|
|
|
|
2018-11-28 03:58:46 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_AnimationValue_GetColor(
|
2019-03-21 20:00:27 +03:00
|
|
|
value: &RawServoAnimationValue,
|
2018-11-28 03:58:46 +03:00
|
|
|
foreground_color: structs::nscolor,
|
|
|
|
) -> structs::nscolor {
|
|
|
|
use style::gecko::values::convert_nscolor_to_rgba;
|
|
|
|
use style::gecko::values::convert_rgba_to_nscolor;
|
|
|
|
use style::values::animated::ToAnimatedValue;
|
|
|
|
use style::values::computed::color::Color as ComputedColor;
|
|
|
|
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::BackgroundColor(color) => {
|
|
|
|
let computed: ComputedColor = ToAnimatedValue::from_animated_value(color);
|
|
|
|
let foreground_color = convert_nscolor_to_rgba(foreground_color);
|
|
|
|
convert_rgba_to_nscolor(&computed.to_rgba(foreground_color))
|
2019-01-22 04:59:21 +03:00
|
|
|
},
|
2018-11-28 03:58:46 +03:00
|
|
|
_ => panic!("Other color properties are not supported yet"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 12:34:07 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValue_GetOpacity(value: &RawServoAnimationValue) -> f32 {
|
2017-02-09 05:39:45 +03:00
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
if let AnimationValue::Opacity(opacity) = **value {
|
|
|
|
opacity
|
|
|
|
} else {
|
|
|
|
panic!("The AnimationValue should be Opacity");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-26 21:16:01 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValue_Opacity(opacity: f32) -> Strong<RawServoAnimationValue> {
|
2017-10-27 22:38:43 +03:00
|
|
|
Arc::new(AnimationValue::Opacity(opacity)).into_strong()
|
|
|
|
}
|
|
|
|
|
2018-11-28 03:58:46 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_AnimationValue_Color(
|
|
|
|
color_property: nsCSSPropertyID,
|
2019-01-22 04:59:21 +03:00
|
|
|
color: structs::nscolor,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2018-11-28 03:58:46 +03:00
|
|
|
use style::gecko::values::convert_nscolor_to_rgba;
|
|
|
|
use style::values::animated::color::RGBA as AnimatedRGBA;
|
|
|
|
|
|
|
|
let property = LonghandId::from_nscsspropertyid(color_property)
|
|
|
|
.expect("We don't have shorthand property animation value");
|
|
|
|
|
|
|
|
let rgba = convert_nscolor_to_rgba(color);
|
|
|
|
|
2019-01-22 04:59:21 +03:00
|
|
|
let animatedRGBA = AnimatedRGBA::new(
|
|
|
|
rgba.red_f32(),
|
|
|
|
rgba.green_f32(),
|
|
|
|
rgba.blue_f32(),
|
|
|
|
rgba.alpha_f32(),
|
|
|
|
);
|
2018-11-28 03:58:46 +03:00
|
|
|
match property {
|
2019-01-22 04:59:21 +03:00
|
|
|
LonghandId::BackgroundColor => {
|
|
|
|
Arc::new(AnimationValue::BackgroundColor(animatedRGBA.into())).into_strong()
|
|
|
|
},
|
2018-11-28 03:58:46 +03:00
|
|
|
_ => panic!("Should be background-color property"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:25:10 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetScale(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> *const computed::Scale {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::Scale(ref value) => value,
|
|
|
|
_ => unreachable!("Expected scale"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetTranslate(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> *const computed::Translate {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::Translate(ref value) => value,
|
|
|
|
_ => unreachable!("Expected translate"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetRotate(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> *const computed::Rotate {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::Rotate(ref value) => value,
|
|
|
|
_ => unreachable!("Expected rotate"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-27 22:38:43 +03:00
|
|
|
#[no_mangle]
|
2019-02-24 06:27:51 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetTransform(
|
2019-03-21 20:00:27 +03:00
|
|
|
value: &RawServoAnimationValue,
|
2019-05-17 02:25:10 +03:00
|
|
|
) -> *const computed::Transform {
|
2017-02-09 05:39:45 +03:00
|
|
|
let value = AnimationValue::as_arc(&value);
|
2019-02-24 06:27:51 +03:00
|
|
|
match **value {
|
2019-05-17 02:25:10 +03:00
|
|
|
AnimationValue::Transform(ref value) => value,
|
|
|
|
_ => unreachable!("Unsupported transform animation value"),
|
2017-02-09 05:39:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 23:07:41 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetPath(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> *const computed::motion::OffsetPath {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::OffsetPath(ref value) => value,
|
|
|
|
_ => unreachable!("Expected offset-path"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetDistance(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> *const computed::LengthPercentage {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::OffsetDistance(ref value) => value,
|
|
|
|
_ => unreachable!("Expected offset-distance"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetRotate(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> *const computed::motion::OffsetRotate {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::OffsetRotate(ref value) => value,
|
|
|
|
_ => unreachable!("Expected offset-rotate"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetAnchor(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> *const computed::position::PositionOrAuto {
|
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
match **value {
|
|
|
|
AnimationValue::OffsetAnchor(ref value) => value,
|
|
|
|
_ => unreachable!("Expected offset-anchor"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:25:10 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_Rotate(
|
|
|
|
r: &computed::Rotate,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2019-05-17 02:25:10 +03:00
|
|
|
Arc::new(AnimationValue::Rotate(r.clone())).into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_Translate(
|
|
|
|
t: &computed::Translate,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2019-05-17 02:25:10 +03:00
|
|
|
Arc::new(AnimationValue::Translate(t.clone())).into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_Scale(
|
|
|
|
s: &computed::Scale,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2019-05-17 02:25:10 +03:00
|
|
|
Arc::new(AnimationValue::Scale(s.clone())).into_strong()
|
|
|
|
}
|
|
|
|
|
2017-10-27 22:38:43 +03:00
|
|
|
#[no_mangle]
|
2019-03-18 21:04:50 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_Transform(
|
2020-01-22 23:20:38 +03:00
|
|
|
transform: &computed::Transform,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2020-01-22 23:20:38 +03:00
|
|
|
Arc::new(AnimationValue::Transform(transform.clone())).into_strong()
|
2017-10-27 22:38:43 +03:00
|
|
|
}
|
|
|
|
|
2019-10-31 23:07:41 +03:00
|
|
|
#[no_mangle]
|
2020-01-22 22:17:39 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_SVGPath(
|
|
|
|
list: *const specified::svg_path::PathCommand,
|
|
|
|
len: usize,
|
2019-10-31 23:07:41 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2020-01-22 22:17:39 +03:00
|
|
|
use style::values::generics::motion::OffsetPath;
|
|
|
|
use style::values::specified::SVGPathData;
|
|
|
|
|
|
|
|
let slice = std::slice::from_raw_parts(list, len);
|
|
|
|
Arc::new(AnimationValue::OffsetPath(OffsetPath::Path(SVGPathData(
|
|
|
|
style_traits::arc_slice::ArcSlice::from_iter(slice.iter().cloned()),
|
|
|
|
))))
|
|
|
|
.into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_RayFunction(
|
|
|
|
r: &generics::motion::RayFunction<computed::Angle>,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
|
|
|
use style::values::generics::motion::OffsetPath;
|
|
|
|
Arc::new(AnimationValue::OffsetPath(OffsetPath::Ray(r.clone()))).into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_NoneOffsetPath() -> Strong<RawServoAnimationValue> {
|
|
|
|
use style::values::generics::motion::OffsetPath;
|
|
|
|
Arc::new(AnimationValue::OffsetPath(OffsetPath::None)).into_strong()
|
2019-10-31 23:07:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_OffsetDistance(
|
|
|
|
d: &computed::length::LengthPercentage,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2019-12-16 00:33:34 +03:00
|
|
|
Arc::new(AnimationValue::OffsetDistance(d.clone())).into_strong()
|
2019-10-31 23:07:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_OffsetRotate(
|
|
|
|
r: &computed::motion::OffsetRotate,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
|
|
|
Arc::new(AnimationValue::OffsetRotate(*r)).into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AnimationValue_OffsetAnchor(
|
|
|
|
p: &computed::position::PositionOrAuto,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2019-12-16 00:33:34 +03:00
|
|
|
Arc::new(AnimationValue::OffsetAnchor(p.clone())).into_strong()
|
2019-10-31 23:07:41 +03:00
|
|
|
}
|
|
|
|
|
2017-02-24 10:16:14 +03:00
|
|
|
#[no_mangle]
|
2017-11-23 14:44:09 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValue_DeepEqual(
|
2019-03-21 20:00:27 +03:00
|
|
|
this: &RawServoAnimationValue,
|
|
|
|
other: &RawServoAnimationValue,
|
2017-11-23 14:44:09 +03:00
|
|
|
) -> bool {
|
2017-02-24 10:16:14 +03:00
|
|
|
let this_value = AnimationValue::as_arc(&this);
|
|
|
|
let other_value = AnimationValue::as_arc(&other);
|
|
|
|
this_value == other_value
|
|
|
|
}
|
|
|
|
|
2017-04-12 15:00:20 +03:00
|
|
|
#[no_mangle]
|
2017-10-14 16:13:59 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValue_Uncompute(
|
2019-03-21 20:00:27 +03:00
|
|
|
value: &RawServoAnimationValue,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoDeclarationBlock> {
|
2017-04-12 15:00:20 +03:00
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(
|
|
|
|
global_style_data
|
|
|
|
.shared_lock
|
|
|
|
.wrap(PropertyDeclarationBlock::with_one(
|
|
|
|
value.uncompute(),
|
|
|
|
Importance::Normal,
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
.into_strong()
|
2017-04-12 15:00:20 +03:00
|
|
|
}
|
|
|
|
|
2020-01-22 22:17:39 +03:00
|
|
|
// This is an intermediate type for passing Vec<u8> through FFI.
|
|
|
|
// We convert this type into ByteBuf when passing it through IPC.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct VecU8 {
|
|
|
|
data: *mut u8,
|
|
|
|
length: usize,
|
|
|
|
capacity: usize,
|
2019-11-01 00:35:05 +03:00
|
|
|
}
|
|
|
|
|
2020-01-22 22:17:39 +03:00
|
|
|
impl VecU8 {
|
|
|
|
#[inline]
|
|
|
|
fn from_vec(mut v: Vec<u8>) -> Self {
|
|
|
|
let w = VecU8 {
|
|
|
|
data: v.as_mut_ptr(),
|
|
|
|
length: v.len(),
|
|
|
|
capacity: v.capacity(),
|
|
|
|
};
|
|
|
|
std::mem::forget(v);
|
|
|
|
w
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn flush_into_vec(&mut self) -> Vec<u8> {
|
|
|
|
if self.data.is_null() {
|
|
|
|
debug_assert_eq!(self.capacity, 0);
|
|
|
|
return Vec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
let vec = unsafe { Vec::from_raw_parts(self.data, self.length, self.capacity) };
|
|
|
|
self.data = ptr::null_mut();
|
|
|
|
self.length = 0;
|
|
|
|
self.capacity = 0;
|
|
|
|
vec
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_VecU8_Free(v: &mut VecU8) {
|
|
|
|
if !v.data.is_null() {
|
|
|
|
v.flush_into_vec();
|
2019-11-01 00:35:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_basic_serde_funcs {
|
|
|
|
($ser_name:ident, $de_name:ident, $computed_type:ty) => {
|
|
|
|
#[no_mangle]
|
2020-01-22 22:17:39 +03:00
|
|
|
pub extern "C" fn $ser_name(v: &$computed_type, output: &mut VecU8) -> bool {
|
2019-11-01 00:35:05 +03:00
|
|
|
let buf = match serialize(v) {
|
|
|
|
Ok(buf) => buf,
|
|
|
|
Err(..) => return false,
|
|
|
|
};
|
|
|
|
|
2020-01-22 22:17:39 +03:00
|
|
|
*output = VecU8::from_vec(buf);
|
2019-11-01 00:35:05 +03:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2020-01-22 22:17:39 +03:00
|
|
|
pub extern "C" fn $de_name(input: &mut VecU8, v: &mut $computed_type) -> bool {
|
|
|
|
let buf = match deserialize(&input.flush_into_vec()) {
|
2019-11-01 00:35:05 +03:00
|
|
|
Ok(buf) => buf,
|
|
|
|
Err(..) => return false,
|
|
|
|
};
|
|
|
|
|
|
|
|
*v = buf;
|
|
|
|
true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_basic_serde_funcs!(
|
|
|
|
Servo_LengthPercentage_Serialize,
|
|
|
|
Servo_LengthPercentage_Deserialize,
|
|
|
|
computed::LengthPercentage
|
|
|
|
);
|
|
|
|
|
2020-01-22 21:40:07 +03:00
|
|
|
impl_basic_serde_funcs!(
|
2020-01-22 22:17:39 +03:00
|
|
|
Servo_RayFunction_Serialize,
|
|
|
|
Servo_RayFunction_Deserialize,
|
|
|
|
generics::motion::RayFunction<computed::Angle>
|
2020-01-22 21:40:19 +03:00
|
|
|
);
|
|
|
|
|
2020-01-22 23:18:31 +03:00
|
|
|
impl_basic_serde_funcs!(
|
|
|
|
Servo_StyleRotate_Serialize,
|
|
|
|
Servo_StyleRotate_Deserialize,
|
|
|
|
computed::transform::Rotate
|
|
|
|
);
|
|
|
|
|
|
|
|
impl_basic_serde_funcs!(
|
|
|
|
Servo_StyleScale_Serialize,
|
|
|
|
Servo_StyleScale_Deserialize,
|
|
|
|
computed::transform::Scale
|
|
|
|
);
|
|
|
|
|
|
|
|
impl_basic_serde_funcs!(
|
|
|
|
Servo_StyleTranslate_Serialize,
|
|
|
|
Servo_StyleTranslate_Deserialize,
|
|
|
|
computed::transform::Translate
|
|
|
|
);
|
|
|
|
|
2020-01-22 23:20:38 +03:00
|
|
|
impl_basic_serde_funcs!(
|
|
|
|
Servo_StyleTransform_Serialize,
|
|
|
|
Servo_StyleTransform_Deserialize,
|
|
|
|
computed::transform::Transform
|
|
|
|
);
|
|
|
|
|
2019-10-31 23:07:41 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_SVGPathData_Normalize(
|
|
|
|
input: &specified::SVGPathData,
|
|
|
|
output: &mut specified::SVGPathData,
|
|
|
|
) {
|
|
|
|
*output = input.normalize();
|
|
|
|
}
|
|
|
|
|
2017-10-19 09:24:38 +03:00
|
|
|
// Return the ComputedValues by a base ComputedValues and the rules.
|
|
|
|
fn resolve_rules_for_element_with_context<'a>(
|
|
|
|
element: GeckoElement<'a>,
|
|
|
|
mut context: StyleContext<GeckoElement<'a>>,
|
2018-11-20 07:37:53 +03:00
|
|
|
rules: StrongRuleNode,
|
2017-10-19 09:24:38 +03:00
|
|
|
) -> Arc<ComputedValues> {
|
2017-08-25 10:30:50 +03:00
|
|
|
use style::style_resolver::{PseudoElementResolution, StyleResolverForElement};
|
2017-07-12 10:28:44 +03:00
|
|
|
|
2017-10-19 09:24:38 +03:00
|
|
|
// This currently ignores visited styles, which seems acceptable, as
|
|
|
|
// existing browsers don't appear to animate visited styles.
|
2018-11-20 07:37:53 +03:00
|
|
|
let inputs = CascadeInputs {
|
|
|
|
rules: Some(rules),
|
|
|
|
visited_rules: None,
|
|
|
|
};
|
2017-10-19 09:24:38 +03:00
|
|
|
|
|
|
|
// Actually `PseudoElementResolution` doesn't matter.
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut resolver = StyleResolverForElement::new(
|
|
|
|
element,
|
|
|
|
&mut context,
|
|
|
|
RuleInclusion::All,
|
|
|
|
PseudoElementResolution::IfApplicable,
|
|
|
|
);
|
|
|
|
resolver
|
|
|
|
.cascade_style_and_visited_with_default_parents(inputs)
|
|
|
|
.0
|
2017-10-19 09:24:38 +03:00
|
|
|
}
|
|
|
|
|
2019-05-20 09:04:23 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_AnimationValueMap_Create() -> Owned<structs::RawServoAnimationValueMap> {
|
|
|
|
Box::<AnimationValueMap>::default().into_ffi()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AnimationValueMap_Drop(
|
|
|
|
value_map: *mut structs::RawServoAnimationValueMap,
|
|
|
|
) {
|
2019-05-20 09:04:23 +03:00
|
|
|
AnimationValueMap::drop_ffi(value_map)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_AnimationValueMap_GetValue(
|
|
|
|
raw_value_map: &mut structs::RawServoAnimationValueMap,
|
|
|
|
property_id: nsCSSPropertyID,
|
|
|
|
) -> Strong<RawServoAnimationValue> {
|
|
|
|
let property = match LonghandId::from_nscsspropertyid(property_id) {
|
|
|
|
Ok(longhand) => longhand,
|
|
|
|
Err(()) => return Strong::null(),
|
|
|
|
};
|
|
|
|
let value_map = AnimationValueMap::from_ffi_mut(raw_value_map);
|
|
|
|
|
2019-08-26 12:58:53 +03:00
|
|
|
value_map.get(&property).map_or(Strong::null(), |value| {
|
|
|
|
Arc::new(value.clone()).into_strong()
|
|
|
|
})
|
2019-05-20 09:04:23 +03:00
|
|
|
}
|
|
|
|
|
2017-10-19 09:24:38 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_style_set: &RawServoStyleSet,
|
|
|
|
element: &RawGeckoElement,
|
|
|
|
computed_values: &ComputedValues,
|
2017-10-19 09:24:38 +03:00
|
|
|
snapshots: *const ServoElementSnapshotTable,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2017-05-10 23:08:59 +03:00
|
|
|
debug_assert!(!snapshots.is_null());
|
2017-07-21 21:05:13 +03:00
|
|
|
let computed_values = unsafe { ArcBorrow::from_ref(computed_values) };
|
2017-07-12 10:28:44 +03:00
|
|
|
|
|
|
|
let rules = match computed_values.rules {
|
2017-07-21 21:05:13 +03:00
|
|
|
None => return computed_values.clone_arc().into(),
|
2017-07-12 10:28:44 +03:00
|
|
|
Some(ref rules) => rules,
|
|
|
|
};
|
2017-04-06 06:53:30 +03:00
|
|
|
|
2017-10-19 09:24:38 +03:00
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_style_set).borrow();
|
|
|
|
let without_animations_rules = doc_data.stylist.rule_tree().remove_animation_rules(rules);
|
|
|
|
if without_animations_rules == *rules {
|
2017-07-21 21:05:13 +03:00
|
|
|
return computed_values.clone_arc().into();
|
2017-07-12 10:28:44 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 06:53:30 +03:00
|
|
|
let element = GeckoElement(element);
|
2017-07-12 10:28:44 +03:00
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2018-11-20 07:37:53 +03:00
|
|
|
let shared = create_shared_context(
|
|
|
|
&global_style_data,
|
|
|
|
&guard,
|
|
|
|
&doc_data,
|
|
|
|
TraversalFlags::empty(),
|
|
|
|
unsafe { &*snapshots },
|
|
|
|
);
|
2017-07-12 10:28:44 +03:00
|
|
|
let mut tlc = ThreadLocalStyleContext::new(&shared);
|
2017-10-19 09:24:38 +03:00
|
|
|
let context = StyleContext {
|
2017-07-12 10:28:44 +03:00
|
|
|
shared: &shared,
|
|
|
|
thread_local: &mut tlc,
|
2017-04-23 12:55:34 +03:00
|
|
|
};
|
2017-04-06 06:53:30 +03:00
|
|
|
|
2017-10-19 09:24:38 +03:00
|
|
|
resolve_rules_for_element_with_context(element, context, without_animations_rules).into()
|
|
|
|
}
|
2017-07-12 10:28:44 +03:00
|
|
|
|
2017-10-19 09:24:38 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSet_GetComputedValuesByAddingAnimation(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_style_set: &RawServoStyleSet,
|
|
|
|
element: &RawGeckoElement,
|
|
|
|
computed_values: &ComputedValues,
|
2017-10-19 09:24:38 +03:00
|
|
|
snapshots: *const ServoElementSnapshotTable,
|
2019-03-21 20:00:27 +03:00
|
|
|
animation_value: &RawServoAnimationValue,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2017-10-19 09:24:38 +03:00
|
|
|
debug_assert!(!snapshots.is_null());
|
|
|
|
let rules = match computed_values.rules {
|
2019-03-26 21:16:01 +03:00
|
|
|
None => return Strong::null(),
|
2017-10-19 09:24:38 +03:00
|
|
|
Some(ref rules) => rules,
|
|
|
|
};
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let uncomputed_value = AnimationValue::as_arc(&animation_value).uncompute();
|
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_style_set).borrow();
|
|
|
|
|
|
|
|
let with_animations_rules = {
|
|
|
|
let guards = StylesheetGuards::same(&guard);
|
2018-11-20 07:37:53 +03:00
|
|
|
let declarations = Arc::new(global_style_data.shared_lock.wrap(
|
|
|
|
PropertyDeclarationBlock::with_one(uncomputed_value, Importance::Normal),
|
|
|
|
));
|
|
|
|
doc_data
|
|
|
|
.stylist
|
2017-10-19 09:24:38 +03:00
|
|
|
.rule_tree()
|
|
|
|
.add_animation_rules_at_transition_level(rules, declarations, &guards)
|
|
|
|
};
|
|
|
|
|
|
|
|
let element = GeckoElement(element);
|
|
|
|
if element.borrow_data().is_none() {
|
2019-03-26 21:16:01 +03:00
|
|
|
return Strong::null();
|
2017-10-19 09:24:38 +03:00
|
|
|
}
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let shared = create_shared_context(
|
|
|
|
&global_style_data,
|
|
|
|
&guard,
|
|
|
|
&doc_data,
|
|
|
|
TraversalFlags::empty(),
|
|
|
|
unsafe { &*snapshots },
|
|
|
|
);
|
2017-10-19 09:24:38 +03:00
|
|
|
let mut tlc: ThreadLocalStyleContext<GeckoElement> = ThreadLocalStyleContext::new(&shared);
|
|
|
|
let context = StyleContext {
|
|
|
|
shared: &shared,
|
|
|
|
thread_local: &mut tlc,
|
|
|
|
};
|
|
|
|
|
|
|
|
resolve_rules_for_element_with_context(element, context, with_animations_rules).into()
|
2017-04-06 06:53:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-09-29 18:01:52 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_ExtractAnimationValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
computed_values: &ComputedValues,
|
2017-09-29 18:01:52 +03:00
|
|
|
property_id: nsCSSPropertyID,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2017-09-29 18:01:52 +03:00
|
|
|
let property = match LonghandId::from_nscsspropertyid(property_id) {
|
|
|
|
Ok(longhand) => longhand,
|
|
|
|
Err(()) => return Strong::null(),
|
2017-06-15 06:17:47 +03:00
|
|
|
};
|
2018-02-28 14:28:41 +03:00
|
|
|
match AnimationValue::from_computed_values(property, &computed_values) {
|
2017-09-29 18:01:52 +03:00
|
|
|
Some(v) => Arc::new(v).into_strong(),
|
|
|
|
None => Strong::null(),
|
|
|
|
}
|
2017-04-06 06:53:30 +03:00
|
|
|
}
|
|
|
|
|
2018-06-30 16:45:43 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_ResolveLogicalProperty(
|
|
|
|
property_id: nsCSSPropertyID,
|
2019-03-21 20:00:27 +03:00
|
|
|
style: &ComputedValues,
|
2018-06-30 16:45:43 +03:00
|
|
|
) -> nsCSSPropertyID {
|
2018-11-20 07:37:53 +03:00
|
|
|
let longhand = LonghandId::from_nscsspropertyid(property_id)
|
2019-01-15 04:27:44 +03:00
|
|
|
.expect("We shouldn't need to care about shorthands");
|
2018-06-30 16:45:43 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
longhand
|
|
|
|
.to_physical(style.writing_mode)
|
|
|
|
.to_nscsspropertyid()
|
2018-06-30 16:45:43 +03:00
|
|
|
}
|
|
|
|
|
2018-07-30 18:32:17 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_Property_LookupEnabledForAllContent(
|
2019-11-27 23:57:51 +03:00
|
|
|
prop: &nsACString,
|
2018-07-30 18:32:17 +03:00
|
|
|
) -> nsCSSPropertyID {
|
2019-11-27 23:57:51 +03:00
|
|
|
match PropertyId::parse_enabled_for_all_content(prop.as_str_unchecked()) {
|
2018-07-30 18:32:17 +03:00
|
|
|
Ok(p) => p.to_nscsspropertyid_resolving_aliases(),
|
|
|
|
Err(..) => nsCSSPropertyID::eCSSProperty_UNKNOWN,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 19:04:05 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_Property_GetName(
|
|
|
|
prop: nsCSSPropertyID,
|
|
|
|
out_length: *mut u32,
|
|
|
|
) -> *const u8 {
|
|
|
|
let (ptr, len) = match NonCustomPropertyId::from_nscsspropertyid(prop) {
|
|
|
|
Ok(p) => {
|
|
|
|
let name = p.name();
|
|
|
|
(name.as_bytes().as_ptr(), name.len())
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-07-30 19:04:05 +03:00
|
|
|
Err(..) => (ptr::null(), 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
*out_length = len as u32;
|
|
|
|
ptr
|
|
|
|
}
|
|
|
|
|
2018-04-29 02:03:31 +03:00
|
|
|
macro_rules! parse_enabled_property_name {
|
|
|
|
($prop_name:ident, $found:ident, $default:expr) => {{
|
2019-11-27 23:57:51 +03:00
|
|
|
let prop_name = $prop_name.as_str_unchecked();
|
2018-06-01 15:00:57 +03:00
|
|
|
match PropertyId::parse_enabled_for_all_content(prop_name) {
|
|
|
|
Ok(p) => {
|
2018-04-29 02:03:31 +03:00
|
|
|
*$found = true;
|
|
|
|
p
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-06-01 15:00:57 +03:00
|
|
|
Err(..) => {
|
2018-04-29 02:03:31 +03:00
|
|
|
*$found = false;
|
|
|
|
return $default;
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-04-29 02:03:31 +03:00
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
}};
|
2018-04-29 02:03:31 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 19:53:48 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_Property_IsShorthand(
|
2019-11-27 23:57:51 +03:00
|
|
|
prop_name: &nsACString,
|
2018-11-20 07:37:53 +03:00
|
|
|
found: *mut bool,
|
2018-03-19 19:53:48 +03:00
|
|
|
) -> bool {
|
2018-04-29 02:03:31 +03:00
|
|
|
let prop_id = parse_enabled_property_name!(prop_name, found, false);
|
2018-03-19 19:53:48 +03:00
|
|
|
prop_id.is_shorthand()
|
|
|
|
}
|
|
|
|
|
2018-04-09 12:19:48 +03:00
|
|
|
#[no_mangle]
|
2019-11-27 23:57:51 +03:00
|
|
|
pub unsafe extern "C" fn Servo_Property_IsInherited(prop_name: &nsACString) -> bool {
|
|
|
|
let prop_name = prop_name.as_str_unchecked();
|
2018-06-01 15:00:57 +03:00
|
|
|
let prop_id = match PropertyId::parse_enabled_for_all_content(prop_name) {
|
2018-04-09 12:19:48 +03:00
|
|
|
Ok(id) => id,
|
|
|
|
Err(_) => return false,
|
|
|
|
};
|
|
|
|
let longhand_id = match prop_id {
|
|
|
|
PropertyId::Custom(_) => return true,
|
2018-11-20 07:37:53 +03:00
|
|
|
PropertyId::Longhand(id) | PropertyId::LonghandAlias(id, _) => id,
|
|
|
|
PropertyId::Shorthand(id) | PropertyId::ShorthandAlias(id, _) => {
|
|
|
|
id.longhands().next().unwrap()
|
|
|
|
},
|
2018-04-09 12:19:48 +03:00
|
|
|
};
|
|
|
|
longhand_id.inherited()
|
|
|
|
}
|
|
|
|
|
2018-04-26 02:01:02 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_Property_SupportsType(
|
2019-11-27 23:57:51 +03:00
|
|
|
prop_name: &nsACString,
|
2019-03-18 19:38:48 +03:00
|
|
|
ty: u8,
|
2018-04-26 02:01:02 +03:00
|
|
|
found: *mut bool,
|
|
|
|
) -> bool {
|
2018-04-29 02:03:31 +03:00
|
|
|
let prop_id = parse_enabled_property_name!(prop_name, found, false);
|
2018-04-26 02:01:02 +03:00
|
|
|
prop_id.supports_type(ty)
|
|
|
|
}
|
|
|
|
|
2019-11-27 23:57:51 +03:00
|
|
|
// TODO(emilio): We could use ThinVec instead of nsTArray.
|
2018-04-29 02:03:31 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_Property_GetCSSValuesForProperty(
|
2019-11-27 23:57:51 +03:00
|
|
|
prop_name: &nsACString,
|
2018-04-29 02:03:31 +03:00
|
|
|
found: *mut bool,
|
2019-11-27 23:57:51 +03:00
|
|
|
result: &mut nsTArray<nsString>,
|
2018-04-29 02:03:31 +03:00
|
|
|
) {
|
|
|
|
let prop_id = parse_enabled_property_name!(prop_name, found, ());
|
|
|
|
// Use B-tree set for unique and sorted result.
|
|
|
|
let mut values = BTreeSet::<&'static str>::new();
|
|
|
|
prop_id.collect_property_completion_keywords(&mut |list| values.extend(list.iter()));
|
|
|
|
|
2018-04-29 02:03:31 +03:00
|
|
|
let mut extras = vec![];
|
|
|
|
if values.contains("transparent") {
|
|
|
|
// This is a special value devtools use to avoid inserting the
|
|
|
|
// long list of color keywords. We need to prepend it to values.
|
|
|
|
extras.push("COLOR");
|
|
|
|
}
|
|
|
|
|
|
|
|
let len = extras.len() + values.len();
|
2019-06-19 01:29:58 +03:00
|
|
|
bindings::Gecko_ResizeTArrayForStrings(result, len as u32);
|
2018-04-29 02:03:31 +03:00
|
|
|
|
|
|
|
for (src, dest) in extras.iter().chain(values.iter()).zip(result.iter_mut()) {
|
2018-04-29 02:03:31 +03:00
|
|
|
dest.write_str(src).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 15:00:20 +03:00
|
|
|
#[no_mangle]
|
2018-11-04 16:01:19 +03:00
|
|
|
pub extern "C" fn Servo_Property_IsAnimatable(prop: nsCSSPropertyID) -> bool {
|
2018-11-20 07:37:53 +03:00
|
|
|
NonCustomPropertyId::from_nscsspropertyid(prop)
|
|
|
|
.ok()
|
|
|
|
.map_or(false, |p| p.is_animatable())
|
2017-04-12 15:00:20 +03:00
|
|
|
}
|
|
|
|
|
2017-06-15 06:17:47 +03:00
|
|
|
#[no_mangle]
|
2018-11-04 16:01:19 +03:00
|
|
|
pub extern "C" fn Servo_Property_IsTransitionable(prop: nsCSSPropertyID) -> bool {
|
2018-11-20 07:37:53 +03:00
|
|
|
NonCustomPropertyId::from_nscsspropertyid(prop)
|
|
|
|
.ok()
|
|
|
|
.map_or(false, |p| p.is_transitionable())
|
2017-06-15 06:17:47 +03:00
|
|
|
}
|
|
|
|
|
2017-04-12 15:00:20 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_Property_IsDiscreteAnimatable(property: nsCSSPropertyID) -> bool {
|
2017-09-29 18:01:52 +03:00
|
|
|
match LonghandId::from_nscsspropertyid(property) {
|
|
|
|
Ok(longhand) => longhand.is_discrete_animatable(),
|
|
|
|
Err(()) => return false,
|
2017-06-15 06:17:47 +03:00
|
|
|
}
|
2017-04-12 15:00:20 +03:00
|
|
|
}
|
|
|
|
|
2016-01-19 11:49:10 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_Element_ClearData(element: &RawGeckoElement) {
|
2017-07-15 17:44:08 +03:00
|
|
|
unsafe { GeckoElement(element).clear_data() };
|
2016-01-19 11:49:10 +03:00
|
|
|
}
|
2016-02-04 20:55:09 +03:00
|
|
|
|
2017-08-03 03:39:15 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_Element_SizeOfExcludingThisAndCVs(
|
|
|
|
malloc_size_of: GeckoMallocSizeOf,
|
|
|
|
malloc_enclosing_size_of: GeckoMallocSizeOf,
|
|
|
|
seen_ptrs: *mut SeenPtrs,
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
2018-02-13 18:25:30 +03:00
|
|
|
) -> usize {
|
2017-08-03 03:39:15 +03:00
|
|
|
let element = GeckoElement(element);
|
|
|
|
let borrow = element.borrow_data();
|
|
|
|
if let Some(data) = borrow {
|
2018-11-20 07:37:53 +03:00
|
|
|
let have_seen_ptr = move |ptr| unsafe { Gecko_HaveSeenPtr(seen_ptrs, ptr) };
|
2018-02-13 18:25:30 +03:00
|
|
|
let mut ops = MallocSizeOfOps::new(
|
|
|
|
malloc_size_of.unwrap(),
|
|
|
|
Some(malloc_enclosing_size_of.unwrap()),
|
|
|
|
Some(Box::new(have_seen_ptr)),
|
|
|
|
);
|
servo: Merge #18452 - Overhaul MallocSizeOf and related things (from nnethercote:bug-1398737); r=jdm
This patch makes the MallocSizeOf stuff in Stylo work more like the HeapSizeOf
stuff already in Servo, except better. In particular, it adds deriving support
for MallocSizeOf, which will make it easier to improve coverage.
The patch does the following.
- Combines servo/components/style/stylesheets/memory.rs and the heapsize crate
into a new crate, malloc_size_of.
- Forks the heapsize_derive crate, calling it malloc_size_of, so that
MallocSizeOf can be derived.
- Both the new crates have MIT/Apache licenses, like heapsize, in case they are
incorporated into heapsize in the future.
- Renames the methods within MallocSizeOf and the related traits so they are
more concise.
- Removes MallocSizeOfWithGuard.
- Adds `derive(MallocSizeOf)` to a lot of types, in some cases replacing an
equivalent or almost-equivalent hand-written implementation.
- Adds stuff so that Rc/Arc can be handled properly.
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because tested on Gecko side.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 7f4cb1861b172423781a369b2decca6c65d60546
--HG--
rename : servo/components/hashglobe/LICENSE-APACHE => servo/components/malloc_size_of/LICENSE-APACHE
rename : servo/components/hashglobe/LICENSE-MIT => servo/components/malloc_size_of/LICENSE-MIT
rename : servo/components/jstraceable_derive/Cargo.toml => servo/components/malloc_size_of_derive/Cargo.toml
rename : servo/components/hashglobe/LICENSE-APACHE => servo/components/malloc_size_of_derive/LICENSE-APACHE
rename : servo/components/hashglobe/LICENSE-MIT => servo/components/malloc_size_of_derive/LICENSE-MIT
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : a8254c4ae15901b764d918355e900a1e74d6eb03
2017-09-12 06:11:25 +03:00
|
|
|
(*data).size_of_excluding_cvs(&mut ops)
|
2017-08-03 03:39:15 +03:00
|
|
|
} else {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-14 05:07:01 +03:00
|
|
|
#[no_mangle]
|
2019-08-16 08:59:03 +03:00
|
|
|
pub extern "C" fn Servo_Element_GetMaybeOutOfDateStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
2019-08-16 08:59:03 +03:00
|
|
|
) -> *const ComputedValues {
|
2017-08-14 05:07:01 +03:00
|
|
|
let element = GeckoElement(element);
|
2019-08-16 08:59:03 +03:00
|
|
|
let data = match element.borrow_data() {
|
|
|
|
Some(d) => d,
|
|
|
|
None => return ptr::null(),
|
|
|
|
};
|
|
|
|
&**data.styles.primary() as *const _
|
2017-08-14 05:07:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-16 08:59:03 +03:00
|
|
|
pub extern "C" fn Servo_Element_GetMaybeOutOfDatePseudoStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
2018-02-13 18:25:30 +03:00
|
|
|
index: usize,
|
2019-08-16 08:59:03 +03:00
|
|
|
) -> *const ComputedValues {
|
2017-08-14 05:07:01 +03:00
|
|
|
let element = GeckoElement(element);
|
2019-08-16 08:59:03 +03:00
|
|
|
let data = match element.borrow_data() {
|
|
|
|
Some(d) => d,
|
|
|
|
None => return ptr::null(),
|
|
|
|
};
|
|
|
|
match data.styles.pseudos.as_array()[index].as_ref() {
|
|
|
|
Some(style) => &**style as *const _,
|
|
|
|
None => ptr::null(),
|
|
|
|
}
|
2017-08-14 05:07:01 +03:00
|
|
|
}
|
|
|
|
|
2017-08-23 06:04:34 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_Element_IsDisplayNone(element: &RawGeckoElement) -> bool {
|
2017-08-23 06:04:34 +03:00
|
|
|
let element = GeckoElement(element);
|
2018-11-20 07:37:53 +03:00
|
|
|
let data = element
|
|
|
|
.get_data()
|
2018-04-07 14:54:41 +03:00
|
|
|
.expect("Invoking Servo_Element_IsDisplayNone on unstyled element");
|
|
|
|
|
|
|
|
// This function is hot, so we bypass the AtomicRefCell.
|
|
|
|
//
|
|
|
|
// It would be nice to also assert that we're not in the servo traversal,
|
|
|
|
// but this function is called at various intermediate checkpoints when
|
|
|
|
// managing the traversal on the Gecko side.
|
2018-01-12 21:22:10 +03:00
|
|
|
debug_assert!(is_main_thread());
|
|
|
|
unsafe { &*data.as_ptr() }.styles.is_display_none()
|
2017-08-23 06:04:34 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 14:54:41 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_Element_IsDisplayContents(element: &RawGeckoElement) -> bool {
|
2018-04-07 14:54:41 +03:00
|
|
|
let element = GeckoElement(element);
|
2018-11-20 07:37:53 +03:00
|
|
|
let data = element
|
|
|
|
.get_data()
|
2018-04-07 14:54:41 +03:00
|
|
|
.expect("Invoking Servo_Element_IsDisplayContents on unstyled element");
|
|
|
|
|
|
|
|
debug_assert!(is_main_thread());
|
2018-11-20 07:37:53 +03:00
|
|
|
unsafe { &*data.as_ptr() }
|
|
|
|
.styles
|
|
|
|
.primary()
|
|
|
|
.get_box()
|
|
|
|
.clone_display()
|
|
|
|
.is_contents()
|
2018-04-07 14:54:41 +03:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:05:57 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_Element_IsPrimaryStyleReusedViaRuleNode(element: &RawGeckoElement) -> bool {
|
2017-09-20 10:05:57 +03:00
|
|
|
let element = GeckoElement(element);
|
2018-11-20 07:37:53 +03:00
|
|
|
let data = element
|
|
|
|
.borrow_data()
|
|
|
|
.expect("Invoking Servo_Element_IsPrimaryStyleReusedViaRuleNode on unstyled element");
|
|
|
|
data.flags
|
|
|
|
.contains(data::ElementDataFlags::PRIMARY_STYLE_REUSED_VIA_RULE_NODE)
|
2017-09-20 10:05:57 +03:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:08:37 +03:00
|
|
|
fn mode_to_origin(mode: SheetParsingMode) -> Origin {
|
|
|
|
match mode {
|
2016-11-10 21:56:48 +03:00
|
|
|
SheetParsingMode::eAuthorSheetFeatures => Origin::Author,
|
|
|
|
SheetParsingMode::eUserSheetFeatures => Origin::User,
|
|
|
|
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
|
2018-06-14 20:08:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_Empty(
|
|
|
|
mode: SheetParsingMode,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoStyleSheetContents> {
|
2018-06-14 20:08:37 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let origin = mode_to_origin(mode);
|
2017-07-02 17:00:39 +03:00
|
|
|
let shared_lock = &global_style_data.shared_lock;
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(StylesheetContents::from_str(
|
|
|
|
"",
|
|
|
|
unsafe { dummy_url_data() }.clone(),
|
|
|
|
origin,
|
|
|
|
shared_lock,
|
|
|
|
/* loader = */ None,
|
|
|
|
None,
|
|
|
|
QuirksMode::NoQuirks,
|
|
|
|
0,
|
|
|
|
/* use_counters = */ None,
|
2019-12-12 16:57:54 +03:00
|
|
|
/* sanitization_data = */ None,
|
2018-11-20 07:37:53 +03:00
|
|
|
))
|
|
|
|
.into_strong()
|
2016-11-10 21:56:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-28 19:32:00 +03:00
|
|
|
/// Note: The load_data corresponds to this sheet, and is passed as the parent
|
|
|
|
/// load data for child sheet loads. It may be null for certain cases where we
|
|
|
|
/// know we won't have child loads.
|
2016-02-04 20:55:09 +03:00
|
|
|
#[no_mangle]
|
2019-12-12 16:57:54 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSheet_FromUTF8Bytes(
|
2017-07-07 00:57:36 +03:00
|
|
|
loader: *mut Loader,
|
2018-04-30 20:23:14 +03:00
|
|
|
stylesheet: *mut DomStyleSheet,
|
2018-02-28 19:32:00 +03:00
|
|
|
load_data: *mut SheetLoadData,
|
2019-11-27 23:57:51 +03:00
|
|
|
bytes: &nsACString,
|
2017-07-02 17:00:39 +03:00
|
|
|
mode: SheetParsingMode,
|
|
|
|
extra_data: *mut URLExtraData,
|
|
|
|
line_number_offset: u32,
|
2017-08-24 22:58:49 +03:00
|
|
|
quirks_mode: nsCompatibility,
|
2018-02-13 18:25:30 +03:00
|
|
|
reusable_sheets: *mut LoaderReusableStyleSheets,
|
2019-03-21 20:00:27 +03:00
|
|
|
use_counters: Option<&UseCounters>,
|
2019-12-12 16:57:54 +03:00
|
|
|
sanitization_kind: SanitizationKind,
|
|
|
|
sanitized_output: Option<&mut nsAString>,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoStyleSheetContents> {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2019-12-12 16:57:54 +03:00
|
|
|
let input = bytes.as_str_unchecked();
|
2016-02-04 20:55:09 +03:00
|
|
|
|
2017-07-11 04:13:44 +03:00
|
|
|
let reporter = ErrorReporter::new(stylesheet, loader, extra_data);
|
2019-12-12 16:57:54 +03:00
|
|
|
let url_data = UrlExtraData::from_ptr_ref(&extra_data);
|
2017-07-07 00:57:36 +03:00
|
|
|
let loader = if loader.is_null() {
|
2016-12-31 06:12:55 +03:00
|
|
|
None
|
|
|
|
} else {
|
2019-12-12 16:57:54 +03:00
|
|
|
debug_assert!(
|
|
|
|
sanitized_output.is_none(),
|
|
|
|
"Shouldn't trigger @import loads for sanitization",
|
|
|
|
);
|
2018-11-20 07:37:53 +03:00
|
|
|
Some(StylesheetLoader::new(
|
|
|
|
loader,
|
|
|
|
stylesheet,
|
|
|
|
load_data,
|
|
|
|
reusable_sheets,
|
|
|
|
))
|
2016-12-31 06:12:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// FIXME(emilio): loader.as_ref() doesn't typecheck for some reason?
|
2019-06-19 00:32:16 +03:00
|
|
|
let loader: Option<&dyn StyleStylesheetLoader> = match loader {
|
2016-12-31 06:12:55 +03:00
|
|
|
None => None,
|
|
|
|
Some(ref s) => Some(s),
|
|
|
|
};
|
|
|
|
|
2019-12-12 16:57:54 +03:00
|
|
|
let mut sanitization_data = SanitizationData::new(sanitization_kind);
|
|
|
|
|
|
|
|
let contents = Arc::new(StylesheetContents::from_str(
|
2018-06-20 22:07:45 +03:00
|
|
|
input,
|
|
|
|
url_data.clone(),
|
|
|
|
mode_to_origin(mode),
|
|
|
|
&global_style_data.shared_lock,
|
|
|
|
loader,
|
2019-06-19 00:32:16 +03:00
|
|
|
reporter.as_ref().map(|r| r as &dyn ParseErrorReporter),
|
2018-06-20 22:07:45 +03:00
|
|
|
quirks_mode.into(),
|
|
|
|
line_number_offset,
|
2019-03-21 20:00:27 +03:00
|
|
|
use_counters,
|
2019-12-12 16:57:54 +03:00
|
|
|
sanitization_data.as_mut(),
|
|
|
|
));
|
|
|
|
|
|
|
|
if let Some(data) = sanitization_data {
|
|
|
|
sanitized_output.unwrap().assign_utf8(data.take().as_bytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
contents.into_strong()
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2018-02-15 03:39:35 +03:00
|
|
|
#[no_mangle]
|
2018-06-21 14:09:35 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSheet_FromUTF8BytesAsync(
|
2018-02-15 03:39:35 +03:00
|
|
|
load_data: *mut SheetLoadDataHolder,
|
|
|
|
extra_data: *mut URLExtraData,
|
2019-11-27 23:57:51 +03:00
|
|
|
bytes: &nsACString,
|
2018-02-15 03:39:35 +03:00
|
|
|
mode: SheetParsingMode,
|
|
|
|
line_number_offset: u32,
|
|
|
|
quirks_mode: nsCompatibility,
|
2018-08-21 13:31:11 +03:00
|
|
|
should_record_use_counters: bool,
|
2018-02-15 03:39:35 +03:00
|
|
|
) {
|
2018-06-21 14:09:35 +03:00
|
|
|
let load_data = RefPtr::new(load_data);
|
2019-03-30 03:15:43 +03:00
|
|
|
let extra_data = UrlExtraData::new(extra_data);
|
2018-06-21 14:09:35 +03:00
|
|
|
|
|
|
|
let mut sheet_bytes = nsCString::new();
|
2019-11-27 23:57:51 +03:00
|
|
|
sheet_bytes.assign(bytes);
|
2018-08-20 20:03:11 +03:00
|
|
|
|
2018-02-15 03:39:35 +03:00
|
|
|
let async_parser = AsyncStylesheetParser::new(
|
|
|
|
load_data,
|
|
|
|
extra_data,
|
2018-06-21 14:09:35 +03:00
|
|
|
sheet_bytes,
|
2018-02-15 03:39:35 +03:00
|
|
|
mode_to_origin(mode),
|
|
|
|
quirks_mode.into(),
|
2018-08-20 20:03:11 +03:00
|
|
|
line_number_offset,
|
2018-08-21 13:31:11 +03:00
|
|
|
should_record_use_counters,
|
2018-02-15 03:39:35 +03:00
|
|
|
);
|
|
|
|
|
2019-09-10 01:39:46 +03:00
|
|
|
if let Some(thread_pool) = STYLE_THREAD_POOL.pool().as_ref() {
|
2018-02-15 03:39:35 +03:00
|
|
|
thread_pool.spawn(|| {
|
2019-05-14 08:00:45 +03:00
|
|
|
profiler_label!(Parse);
|
2018-02-15 03:39:35 +03:00
|
|
|
async_parser.parse();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
async_parser.parse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 01:39:46 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_ShutdownThreadPool() {
|
|
|
|
debug_assert!(is_main_thread() && !is_in_servo_traversal());
|
|
|
|
StyleThreadPool::shutdown();
|
|
|
|
}
|
|
|
|
|
2019-03-30 03:16:29 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_StyleSheet_FromSharedData(
|
|
|
|
extra_data: *mut URLExtraData,
|
|
|
|
shared_rules: &ServoCssRules,
|
|
|
|
) -> Strong<RawServoStyleSheetContents> {
|
|
|
|
let shared_rules = Locked::<CssRules>::as_arc(&shared_rules);
|
|
|
|
Arc::new(StylesheetContents::from_shared_data(
|
|
|
|
shared_rules.clone_arc(),
|
|
|
|
Origin::UserAgent,
|
|
|
|
UrlExtraData::new(extra_data),
|
|
|
|
QuirksMode::NoQuirks,
|
|
|
|
))
|
|
|
|
.into_strong()
|
|
|
|
}
|
|
|
|
|
2016-12-31 06:12:55 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_AppendStyleSheet(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2018-04-30 20:23:14 +03:00
|
|
|
sheet: *const DomStyleSheet,
|
2017-07-02 17:00:39 +03:00
|
|
|
) {
|
2017-05-29 22:19:16 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2017-08-17 19:05:32 +03:00
|
|
|
let data = &mut *data;
|
2017-05-29 22:19:16 +03:00
|
|
|
let guard = global_style_data.shared_lock.read();
|
2017-08-13 14:39:40 +03:00
|
|
|
let sheet = unsafe { GeckoStyleSheet::new(sheet) };
|
2017-08-22 19:45:42 +03:00
|
|
|
data.stylist.append_stylesheet(sheet, &guard);
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2018-02-16 17:54:06 +03:00
|
|
|
#[no_mangle]
|
2019-03-26 21:15:59 +03:00
|
|
|
pub extern "C" fn Servo_AuthorStyles_Create() -> Owned<RawServoAuthorStyles> {
|
|
|
|
Box::new(AuthorStyles::<GeckoStyleSheet>::new()).into_ffi()
|
2018-02-16 17:54:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-30 23:18:33 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AuthorStyles_Drop(styles: *mut RawServoAuthorStyles) {
|
|
|
|
AuthorStyles::drop_ffi(styles)
|
2018-02-16 17:54:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AuthorStyles_AppendStyleSheet(
|
2019-03-21 20:00:27 +03:00
|
|
|
styles: &mut RawServoAuthorStyles,
|
2018-04-30 20:23:14 +03:00
|
|
|
sheet: *const DomStyleSheet,
|
2018-02-16 17:54:06 +03:00
|
|
|
) {
|
|
|
|
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(styles);
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let sheet = GeckoStyleSheet::new(sheet);
|
|
|
|
styles.stylesheets.append_stylesheet(None, sheet, &guard);
|
|
|
|
}
|
|
|
|
|
2018-02-27 13:47:29 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AuthorStyles_InsertStyleSheetBefore(
|
2019-03-21 20:00:27 +03:00
|
|
|
styles: &mut RawServoAuthorStyles,
|
2018-04-30 20:23:14 +03:00
|
|
|
sheet: *const DomStyleSheet,
|
|
|
|
before_sheet: *const DomStyleSheet,
|
2018-02-27 13:47:29 +03:00
|
|
|
) {
|
|
|
|
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(styles);
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
styles.stylesheets.insert_stylesheet_before(
|
|
|
|
None,
|
|
|
|
GeckoStyleSheet::new(sheet),
|
|
|
|
GeckoStyleSheet::new(before_sheet),
|
|
|
|
&guard,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AuthorStyles_RemoveStyleSheet(
|
2019-03-21 20:00:27 +03:00
|
|
|
styles: &mut RawServoAuthorStyles,
|
2018-04-30 20:23:14 +03:00
|
|
|
sheet: *const DomStyleSheet,
|
2018-02-27 13:47:29 +03:00
|
|
|
) {
|
|
|
|
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(styles);
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2018-11-20 07:37:53 +03:00
|
|
|
styles
|
|
|
|
.stylesheets
|
|
|
|
.remove_stylesheet(None, GeckoStyleSheet::new(sheet), &guard);
|
2018-02-27 13:47:29 +03:00
|
|
|
}
|
|
|
|
|
2018-02-16 17:54:06 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub unsafe extern "C" fn Servo_AuthorStyles_ForceDirty(styles: &mut RawServoAuthorStyles) {
|
2018-02-16 17:54:06 +03:00
|
|
|
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(styles);
|
|
|
|
styles.stylesheets.force_dirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AuthorStyles_Flush(
|
2019-03-21 20:00:27 +03:00
|
|
|
styles: &mut RawServoAuthorStyles,
|
|
|
|
document_set: &RawServoStyleSet,
|
2018-02-16 17:54:06 +03:00
|
|
|
) {
|
|
|
|
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(styles);
|
|
|
|
// Try to avoid the atomic borrow below if possible.
|
|
|
|
if !styles.stylesheets.dirty() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let document_data = PerDocumentStyleData::from_ffi(document_set).borrow();
|
2018-02-16 17:54:06 +03:00
|
|
|
|
|
|
|
let stylist = &document_data.stylist;
|
|
|
|
|
|
|
|
// TODO(emilio): This is going to need an element or something to do proper
|
|
|
|
// invalidation in Shadow roots.
|
2018-11-20 07:37:53 +03:00
|
|
|
styles.flush::<GeckoElement>(stylist.device(), stylist.quirks_mode(), &guard);
|
2018-02-16 17:54:06 +03:00
|
|
|
}
|
|
|
|
|
2019-06-08 21:58:57 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_SizeOfIncludingThis(
|
|
|
|
malloc_size_of: GeckoMallocSizeOf,
|
|
|
|
malloc_enclosing_size_of: GeckoMallocSizeOf,
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
|
|
|
) -> usize {
|
|
|
|
use malloc_size_of::MallocSizeOf;
|
|
|
|
use malloc_size_of::MallocUnconditionalShallowSizeOf;
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
|
|
|
|
let mut ops = MallocSizeOfOps::new(
|
|
|
|
malloc_size_of.unwrap(),
|
|
|
|
Some(malloc_enclosing_size_of.unwrap()),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
|
|
|
|
Locked::<PropertyDeclarationBlock>::as_arc(&declarations).with_arc(|declarations| {
|
|
|
|
let mut n = 0;
|
|
|
|
n += declarations.unconditional_shallow_size_of(&mut ops);
|
|
|
|
n += declarations.read_with(&guard).size_of(&mut ops);
|
|
|
|
n
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-02-19 07:13:10 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_AuthorStyles_SizeOfIncludingThis(
|
|
|
|
malloc_size_of: GeckoMallocSizeOf,
|
|
|
|
malloc_enclosing_size_of: GeckoMallocSizeOf,
|
2019-03-21 20:00:27 +03:00
|
|
|
styles: &RawServoAuthorStyles,
|
2018-02-19 07:13:10 +03:00
|
|
|
) -> usize {
|
|
|
|
// We cannot `use` MallocSizeOf at the top level, otherwise the compiler
|
|
|
|
// would complain in `Servo_StyleSheet_SizeOfIncludingThis` for `size_of`
|
|
|
|
// there.
|
|
|
|
use malloc_size_of::MallocSizeOf;
|
|
|
|
let malloc_size_of = malloc_size_of.unwrap();
|
2018-11-20 07:37:53 +03:00
|
|
|
let malloc_size_of_this =
|
|
|
|
malloc_size_of(styles as *const RawServoAuthorStyles as *const c_void);
|
2018-02-19 07:13:10 +03:00
|
|
|
|
|
|
|
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi(styles);
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut ops = MallocSizeOfOps::new(
|
|
|
|
malloc_size_of,
|
|
|
|
Some(malloc_enclosing_size_of.unwrap()),
|
|
|
|
None,
|
|
|
|
);
|
2018-02-19 07:13:10 +03:00
|
|
|
malloc_size_of_this + styles.size_of(&mut ops)
|
|
|
|
}
|
|
|
|
|
2017-06-03 18:11:23 +03:00
|
|
|
#[no_mangle]
|
2018-02-07 16:02:34 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
|
2019-03-21 20:00:27 +03:00
|
|
|
document_set: &RawServoStyleSet,
|
2019-11-27 23:57:51 +03:00
|
|
|
non_document_styles: &mut nsTArray<&mut RawServoAuthorStyles>,
|
2018-02-07 16:02:34 +03:00
|
|
|
may_affect_default_style: bool,
|
|
|
|
) -> structs::MediumFeaturesChangedResult {
|
2017-06-03 18:11:23 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
|
|
|
|
// NOTE(emilio): We don't actually need to flush the stylist here and ensure
|
|
|
|
// it's up to date.
|
|
|
|
//
|
|
|
|
// In case it isn't we would trigger a rebuild + restyle as needed too.
|
|
|
|
//
|
|
|
|
// We need to ensure the default computed values are up to date though,
|
|
|
|
// because those can influence the result of media query evaluation.
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut document_data = PerDocumentStyleData::from_ffi(document_set).borrow_mut();
|
2017-06-03 18:11:23 +03:00
|
|
|
|
2018-02-07 16:02:34 +03:00
|
|
|
if may_affect_default_style {
|
|
|
|
document_data.stylist.device_mut().reset_computed_values();
|
2017-08-03 17:36:21 +03:00
|
|
|
}
|
2017-09-14 23:55:21 +03:00
|
|
|
let guards = StylesheetGuards::same(&guard);
|
2018-02-07 16:02:34 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let origins_in_which_rules_changed = document_data
|
|
|
|
.stylist
|
|
|
|
.media_features_change_changed_style(&guards, document_data.stylist.device());
|
2017-08-03 17:36:21 +03:00
|
|
|
|
2018-02-07 16:02:34 +03:00
|
|
|
let affects_document_rules = !origins_in_which_rules_changed.is_empty();
|
|
|
|
if affects_document_rules {
|
2018-11-20 07:37:53 +03:00
|
|
|
document_data
|
|
|
|
.stylist
|
|
|
|
.force_stylesheet_origins_dirty(origins_in_which_rules_changed);
|
2018-02-07 16:02:34 +03:00
|
|
|
}
|
2017-09-04 23:19:06 +03:00
|
|
|
|
2018-02-07 16:02:34 +03:00
|
|
|
let mut affects_non_document_rules = false;
|
2018-02-16 17:54:06 +03:00
|
|
|
for author_styles in &mut **non_document_styles {
|
2018-11-20 07:37:53 +03:00
|
|
|
let author_styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(&mut *author_styles);
|
2018-02-16 17:54:06 +03:00
|
|
|
let affected_style = author_styles.stylesheets.iter().any(|sheet| {
|
|
|
|
!author_styles.data.media_feature_affected_matches(
|
|
|
|
sheet,
|
|
|
|
&guards.author,
|
2018-02-07 16:02:34 +03:00
|
|
|
document_data.stylist.device(),
|
2018-02-16 17:54:06 +03:00
|
|
|
document_data.stylist.quirks_mode(),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
if affected_style {
|
2018-02-07 16:02:34 +03:00
|
|
|
affects_non_document_rules = true;
|
2018-02-16 17:54:06 +03:00
|
|
|
author_styles.stylesheets.force_dirty();
|
2018-02-07 16:02:34 +03:00
|
|
|
}
|
|
|
|
}
|
2017-09-04 23:19:06 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let uses_viewport_units = document_data.stylist.device().used_viewport_size();
|
2017-09-04 23:19:06 +03:00
|
|
|
|
2018-02-07 16:02:34 +03:00
|
|
|
structs::MediumFeaturesChangedResult {
|
|
|
|
mAffectsDocumentRules: affects_document_rules,
|
|
|
|
mAffectsNonDocumentRules: affects_non_document_rules,
|
|
|
|
mUsesViewportUnits: uses_viewport_units,
|
|
|
|
}
|
2017-06-03 18:11:23 +03:00
|
|
|
}
|
|
|
|
|
2016-04-29 08:37:40 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2018-04-30 20:23:14 +03:00
|
|
|
sheet: *const DomStyleSheet,
|
2018-11-20 07:37:53 +03:00
|
|
|
before_sheet: *const DomStyleSheet,
|
2017-07-02 17:00:39 +03:00
|
|
|
) {
|
2017-05-29 22:19:16 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2017-08-17 19:05:32 +03:00
|
|
|
let data = &mut *data;
|
2017-05-29 22:19:16 +03:00
|
|
|
let guard = global_style_data.shared_lock.read();
|
2017-08-13 14:39:40 +03:00
|
|
|
let sheet = unsafe { GeckoStyleSheet::new(sheet) };
|
2017-08-22 19:45:42 +03:00
|
|
|
data.stylist.insert_stylesheet_before(
|
2017-08-13 14:39:40 +03:00
|
|
|
sheet,
|
2017-07-02 17:00:39 +03:00
|
|
|
unsafe { GeckoStyleSheet::new(before_sheet) },
|
2017-07-09 15:18:36 +03:00
|
|
|
&guard,
|
|
|
|
);
|
2016-04-29 08:37:40 +03:00
|
|
|
}
|
|
|
|
|
2017-06-21 14:36:52 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_RemoveStyleSheet(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2018-11-20 07:37:53 +03:00
|
|
|
sheet: *const DomStyleSheet,
|
2017-07-02 17:00:39 +03:00
|
|
|
) {
|
2017-07-09 15:18:36 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2016-10-11 20:03:29 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2017-08-17 19:05:32 +03:00
|
|
|
let data = &mut *data;
|
2017-07-09 15:18:36 +03:00
|
|
|
let guard = global_style_data.shared_lock.read();
|
2017-08-13 14:39:40 +03:00
|
|
|
let sheet = unsafe { GeckoStyleSheet::new(sheet) };
|
2017-08-22 19:45:42 +03:00
|
|
|
data.stylist.remove_stylesheet(sheet, &guard);
|
2016-12-26 05:13:30 +03:00
|
|
|
}
|
|
|
|
|
2019-04-19 07:20:31 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_GetSheetAt(
|
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
origin: Origin,
|
|
|
|
index: usize,
|
|
|
|
) -> *const DomStyleSheet {
|
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2019-08-26 12:58:53 +03:00
|
|
|
data.stylist
|
|
|
|
.sheet_at(origin, index)
|
|
|
|
.map_or(ptr::null(), |s| s.raw())
|
2019-04-19 07:20:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_GetSheetCount(
|
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
origin: Origin,
|
|
|
|
) -> usize {
|
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
data.stylist.sheet_count(origin)
|
|
|
|
}
|
|
|
|
|
2016-12-26 05:13:30 +03:00
|
|
|
#[no_mangle]
|
2018-01-27 05:18:48 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_FlushStyleSheets(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
doc_element: Option<&RawGeckoElement>,
|
2018-01-27 05:18:48 +03:00
|
|
|
snapshots: *const ServoElementSnapshotTable,
|
2017-07-02 17:00:39 +03:00
|
|
|
) {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2016-12-26 05:13:30 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2017-05-29 22:19:16 +03:00
|
|
|
let doc_element = doc_element.map(GeckoElement);
|
2018-01-27 05:18:48 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let have_invalidations = data.flush_stylesheets(&guard, doc_element, snapshots.as_ref());
|
2018-01-27 05:18:48 +03:00
|
|
|
|
2017-08-23 06:04:34 +03:00
|
|
|
if have_invalidations && doc_element.is_some() {
|
2018-01-27 05:18:48 +03:00
|
|
|
// The invalidation machinery propagates the bits up, but we still need
|
|
|
|
// to tell the Gecko restyle root machinery about it.
|
|
|
|
bindings::Gecko_NoteDirtySubtreeForInvalidation(doc_element.unwrap().0);
|
2017-08-23 06:04:34 +03:00
|
|
|
}
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 08:49:28 +03:00
|
|
|
#[no_mangle]
|
2017-05-29 22:19:16 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_NoteStyleSheetsChanged(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2017-08-13 14:39:40 +03:00
|
|
|
changed_origins: OriginFlags,
|
2017-07-02 17:00:39 +03:00
|
|
|
) {
|
2016-12-19 08:49:28 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2018-11-20 07:37:53 +03:00
|
|
|
data.stylist
|
|
|
|
.force_stylesheet_origins_dirty(OriginSet::from(changed_origins));
|
2018-02-10 01:18:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSet_SetAuthorStyleDisabled(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2018-02-10 01:18:08 +03:00
|
|
|
author_style_disabled: bool,
|
|
|
|
) {
|
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2018-11-20 07:37:53 +03:00
|
|
|
let enabled = if author_style_disabled {
|
|
|
|
AuthorStylesEnabled::No
|
|
|
|
} else {
|
|
|
|
AuthorStylesEnabled::Yes
|
|
|
|
};
|
2018-02-10 01:18:08 +03:00
|
|
|
data.stylist.set_author_styles_enabled(enabled);
|
2016-12-19 08:49:28 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 20:55:09 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_HasRules(raw_contents: &RawServoStyleSheetContents) -> bool {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2017-07-02 17:00:39 +03:00
|
|
|
!StylesheetContents::as_arc(&raw_contents)
|
2018-11-20 07:37:53 +03:00
|
|
|
.rules
|
|
|
|
.read_with(&guard)
|
|
|
|
.0
|
|
|
|
.is_empty()
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2020-01-15 01:34:40 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSheet_HasImportRules(raw_contents: &RawServoStyleSheetContents) -> bool {
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let rules = StylesheetContents::as_arc(&raw_contents).rules(&guard);
|
|
|
|
|
|
|
|
let first_is_import = rules.iter().next().map_or(false, |r| r.rule_type() == CssRuleType::Import);
|
|
|
|
debug_assert_eq!(
|
|
|
|
first_is_import,
|
|
|
|
rules.iter().any(|r| r.rule_type() == CssRuleType::Import),
|
|
|
|
"@import must come before every other rule",
|
|
|
|
);
|
|
|
|
|
|
|
|
first_is_import
|
|
|
|
}
|
|
|
|
|
2016-11-24 02:47:18 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_GetRules(
|
2019-03-21 20:00:27 +03:00
|
|
|
sheet: &RawServoStyleSheetContents,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ServoCssRules> {
|
2018-11-20 07:37:53 +03:00
|
|
|
StylesheetContents::as_arc(&sheet)
|
|
|
|
.rules
|
|
|
|
.clone()
|
|
|
|
.into_strong()
|
2016-11-24 02:47:18 +03:00
|
|
|
}
|
|
|
|
|
2017-05-25 07:26:23 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_Clone(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_sheet: &RawServoStyleSheetContents,
|
2018-04-30 20:23:14 +03:00
|
|
|
reference_sheet: *const DomStyleSheet,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoStyleSheetContents> {
|
2017-07-02 17:00:39 +03:00
|
|
|
use style::shared_lock::{DeepCloneParams, DeepCloneWithLock};
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let contents = StylesheetContents::as_arc(&raw_sheet);
|
|
|
|
let params = DeepCloneParams { reference_sheet };
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(contents.deep_clone_with_lock(&global_style_data.shared_lock, &guard, ¶ms))
|
|
|
|
.into_strong()
|
2017-05-25 07:26:23 +03:00
|
|
|
}
|
|
|
|
|
servo: Merge #17044 - Introduce and start using the MallocSizeOf trait (from nnethercote:MallocSizeOf); r=emilio
MallocSizeOf is similar to the existing HeapSizeOf trait from the
heapsize crate. The only difference is that MallocSizeOf's
malloc_size_of_children() function takes an additional MallocSizeOfFn
argument, which is used to measure heap blocks. This extra argument
makes MallocSizeOf match how Gecko's memory measurements work, and is
required for Stylo to integrate with DMD.
The patch also introduces a second trait, MallocSizeOfWithGuard, which
is much the same as MallocSizeOf, but with a |guard| argument for the
global style lock.
Finally, the patch uses the new traits to measure a small amount of
Stylo's memory usage.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because code is only for Gecko integration.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: aca09436b71e6defe007e1d17a9d79214d094a7b
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 1d5dc4e7ab75e8e0332922396b5b55ed67c4572e
2017-05-29 05:10:25 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_SizeOfIncludingThis(
|
2017-08-31 08:31:31 +03:00
|
|
|
malloc_size_of: GeckoMallocSizeOf,
|
2017-09-18 07:19:54 +03:00
|
|
|
malloc_enclosing_size_of: GeckoMallocSizeOf,
|
2019-03-21 20:00:27 +03:00
|
|
|
sheet: &RawServoStyleSheetContents,
|
2017-07-02 17:00:39 +03:00
|
|
|
) -> usize {
|
servo: Merge #17044 - Introduce and start using the MallocSizeOf trait (from nnethercote:MallocSizeOf); r=emilio
MallocSizeOf is similar to the existing HeapSizeOf trait from the
heapsize crate. The only difference is that MallocSizeOf's
malloc_size_of_children() function takes an additional MallocSizeOfFn
argument, which is used to measure heap blocks. This extra argument
makes MallocSizeOf match how Gecko's memory measurements work, and is
required for Stylo to integrate with DMD.
The patch also introduces a second trait, MallocSizeOfWithGuard, which
is much the same as MallocSizeOf, but with a |guard| argument for the
global style lock.
Finally, the patch uses the new traits to measure a small amount of
Stylo's memory usage.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because code is only for Gecko integration.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: aca09436b71e6defe007e1d17a9d79214d094a7b
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 1d5dc4e7ab75e8e0332922396b5b55ed67c4572e
2017-05-29 05:10:25 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut ops = MallocSizeOfOps::new(
|
|
|
|
malloc_size_of.unwrap(),
|
|
|
|
Some(malloc_enclosing_size_of.unwrap()),
|
|
|
|
None,
|
|
|
|
);
|
2019-11-07 14:19:23 +03:00
|
|
|
// TODO(emilio): We're not measuring the size of the Arc<StyleSheetContents>
|
|
|
|
// allocation itself here.
|
2019-11-06 20:41:34 +03:00
|
|
|
StylesheetContents::as_arc(&sheet).size_of(&guard, &mut ops)
|
servo: Merge #17044 - Introduce and start using the MallocSizeOf trait (from nnethercote:MallocSizeOf); r=emilio
MallocSizeOf is similar to the existing HeapSizeOf trait from the
heapsize crate. The only difference is that MallocSizeOf's
malloc_size_of_children() function takes an additional MallocSizeOfFn
argument, which is used to measure heap blocks. This extra argument
makes MallocSizeOf match how Gecko's memory measurements work, and is
required for Stylo to integrate with DMD.
The patch also introduces a second trait, MallocSizeOfWithGuard, which
is much the same as MallocSizeOf, but with a |guard| argument for the
global style lock.
Finally, the patch uses the new traits to measure a small amount of
Stylo's memory usage.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because code is only for Gecko integration.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: aca09436b71e6defe007e1d17a9d79214d094a7b
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 1d5dc4e7ab75e8e0332922396b5b55ed67c4572e
2017-05-29 05:10:25 +03:00
|
|
|
}
|
|
|
|
|
2017-08-13 14:39:40 +03:00
|
|
|
#[no_mangle]
|
2019-04-19 07:20:31 +03:00
|
|
|
pub extern "C" fn Servo_StyleSheet_GetOrigin(sheet: &RawServoStyleSheetContents) -> Origin {
|
|
|
|
StylesheetContents::as_arc(&sheet).origin
|
2017-08-13 14:39:40 +03:00
|
|
|
}
|
|
|
|
|
2017-08-17 16:08:16 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSheet_GetSourceMapURL(
|
2019-03-21 20:00:27 +03:00
|
|
|
sheet: &RawServoStyleSheetContents,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2017-08-17 16:08:16 +03:00
|
|
|
) {
|
|
|
|
let contents = StylesheetContents::as_arc(&sheet);
|
|
|
|
let url_opt = contents.source_map_url.read();
|
|
|
|
if let Some(ref url) = *url_opt {
|
2020-01-05 17:42:23 +03:00
|
|
|
write!(result, "{}", url).unwrap();
|
2017-08-17 16:08:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 22:44:03 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSheet_GetSourceURL(
|
2019-03-21 20:00:27 +03:00
|
|
|
sheet: &RawServoStyleSheetContents,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2017-09-15 22:44:03 +03:00
|
|
|
) {
|
|
|
|
let contents = StylesheetContents::as_arc(&sheet);
|
|
|
|
let url_opt = contents.source_url.read();
|
|
|
|
if let Some(ref url) = *url_opt {
|
2020-01-05 17:42:23 +03:00
|
|
|
write!(result, "{}", url).unwrap();
|
2017-09-15 22:44:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-22 14:17:09 +03:00
|
|
|
fn read_locked_arc<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
2018-06-18 13:30:24 +03:00
|
|
|
where
|
|
|
|
Locked<T>: HasArcFFI,
|
|
|
|
F: FnOnce(&T) -> R,
|
2017-03-22 14:17:09 +03:00
|
|
|
{
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
func(Locked::<T>::as_arc(&raw).read_with(&guard))
|
|
|
|
}
|
|
|
|
|
2017-09-06 07:20:55 +03:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
unsafe fn read_locked_arc_unchecked<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
2018-11-20 07:37:53 +03:00
|
|
|
where
|
|
|
|
Locked<T>: HasArcFFI,
|
|
|
|
F: FnOnce(&T) -> R,
|
2017-09-06 07:20:55 +03:00
|
|
|
{
|
2018-01-12 21:22:10 +03:00
|
|
|
debug_assert!(is_main_thread() && !is_in_servo_traversal());
|
2017-09-06 07:20:55 +03:00
|
|
|
read_locked_arc(raw, func)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
|
|
unsafe fn read_locked_arc_unchecked<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
2018-11-20 07:37:53 +03:00
|
|
|
where
|
|
|
|
Locked<T>: HasArcFFI,
|
|
|
|
F: FnOnce(&T) -> R,
|
2017-09-06 07:20:55 +03:00
|
|
|
{
|
|
|
|
func(Locked::<T>::as_arc(&raw).read_unchecked())
|
|
|
|
}
|
|
|
|
|
2017-03-22 14:17:09 +03:00
|
|
|
fn write_locked_arc<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
2018-11-20 07:37:53 +03:00
|
|
|
where
|
|
|
|
Locked<T>: HasArcFFI,
|
|
|
|
F: FnOnce(&mut T) -> R,
|
2017-03-22 14:17:09 +03:00
|
|
|
{
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let mut guard = global_style_data.shared_lock.write();
|
|
|
|
func(Locked::<T>::as_arc(&raw).write_with(&mut guard))
|
|
|
|
}
|
|
|
|
|
2016-11-24 02:47:18 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_CssRules_ListTypes(rules: &ServoCssRules, result: &mut nsTArray<usize>) {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(rules, |rules: &CssRules| {
|
2018-11-20 07:37:53 +03:00
|
|
|
result.assign_from_iter_pod(rules.0.iter().map(|rule| rule.rule_type() as usize));
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2016-11-24 02:47:18 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 08:54:46 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_CssRules_InsertRule(
|
2019-03-21 20:00:27 +03:00
|
|
|
rules: &ServoCssRules,
|
|
|
|
contents: &RawServoStyleSheetContents,
|
2019-11-27 23:57:51 +03:00
|
|
|
rule: &nsACString,
|
2017-07-02 17:00:39 +03:00
|
|
|
index: u32,
|
|
|
|
nested: bool,
|
|
|
|
loader: *mut Loader,
|
2018-04-30 20:23:14 +03:00
|
|
|
gecko_stylesheet: *mut DomStyleSheet,
|
2017-07-02 17:00:39 +03:00
|
|
|
rule_type: *mut u16,
|
|
|
|
) -> nsresult {
|
2017-04-03 15:05:42 +03:00
|
|
|
let loader = if loader.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2018-11-20 07:37:53 +03:00
|
|
|
Some(StylesheetLoader::new(
|
|
|
|
loader,
|
|
|
|
gecko_stylesheet,
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
))
|
2017-04-03 15:05:42 +03:00
|
|
|
};
|
2018-11-20 07:37:53 +03:00
|
|
|
let loader = loader
|
|
|
|
.as_ref()
|
2019-06-19 00:32:16 +03:00
|
|
|
.map(|loader| loader as &dyn StyleStylesheetLoader);
|
2019-11-27 23:57:51 +03:00
|
|
|
let rule = unsafe { rule.as_str_unchecked() };
|
2017-04-12 18:00:26 +03:00
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2017-07-02 17:00:39 +03:00
|
|
|
let contents = StylesheetContents::as_arc(&contents);
|
|
|
|
let result = Locked::<CssRules>::as_arc(&rules).insert_rule(
|
|
|
|
&global_style_data.shared_lock,
|
|
|
|
rule,
|
|
|
|
contents,
|
|
|
|
index as usize,
|
|
|
|
nested,
|
2018-11-20 07:37:53 +03:00
|
|
|
loader,
|
2017-07-02 17:00:39 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
match result {
|
2017-04-12 18:00:26 +03:00
|
|
|
Ok(new_rule) => {
|
|
|
|
*unsafe { rule_type.as_mut().unwrap() } = new_rule.rule_type() as u16;
|
|
|
|
nsresult::NS_OK
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-04-12 18:00:26 +03:00
|
|
|
Err(err) => err.into(),
|
|
|
|
}
|
2016-12-01 08:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_CssRules_DeleteRule(rules: &ServoCssRules, index: u32) -> nsresult {
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(rules, |rules: &mut CssRules| {
|
|
|
|
match rules.remove_rule(index as usize) {
|
|
|
|
Ok(_) => nsresult::NS_OK,
|
2018-11-20 07:37:53 +03:00
|
|
|
Err(err) => err.into(),
|
2017-03-22 14:17:09 +03:00
|
|
|
}
|
|
|
|
})
|
2016-12-01 08:54:46 +03:00
|
|
|
}
|
|
|
|
|
2017-05-19 07:49:30 +03:00
|
|
|
macro_rules! impl_basic_rule_funcs_without_getter {
|
|
|
|
{ ($rule_type:ty, $raw_type:ty),
|
|
|
|
debug: $debug:ident,
|
|
|
|
to_css: $to_css:ident,
|
|
|
|
} => {
|
2018-01-16 04:24:59 +03:00
|
|
|
#[cfg(debug_assertions)]
|
2017-05-19 07:49:30 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn $debug(rule: &$raw_type, result: *mut nsACString) {
|
|
|
|
read_locked_arc(rule, |rule: &$rule_type| {
|
|
|
|
write!(unsafe { result.as_mut().unwrap() }, "{:?}", *rule).unwrap();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-01-16 04:24:59 +03:00
|
|
|
#[cfg(not(debug_assertions))]
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn $debug(_: &$raw_type, _: *mut nsACString) {
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
|
2017-05-19 07:49:30 +03:00
|
|
|
#[no_mangle]
|
2020-01-05 17:42:23 +03:00
|
|
|
pub extern "C" fn $to_css(rule: &$raw_type, result: &mut nsAString) {
|
2017-05-19 07:49:30 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let rule = Locked::<$rule_type>::as_arc(&rule);
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.read_with(&guard).to_css(&guard, result).unwrap();
|
2017-05-19 07:49:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 13:58:06 +03:00
|
|
|
macro_rules! impl_basic_rule_funcs {
|
|
|
|
{ ($name:ident, $rule_type:ty, $raw_type:ty),
|
|
|
|
getter: $getter:ident,
|
|
|
|
debug: $debug:ident,
|
|
|
|
to_css: $to_css:ident,
|
|
|
|
} => {
|
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn $getter(
|
2019-03-21 20:00:27 +03:00
|
|
|
rules: &ServoCssRules,
|
2018-02-13 18:25:30 +03:00
|
|
|
index: u32,
|
|
|
|
line: *mut u32,
|
|
|
|
column: *mut u32,
|
|
|
|
) -> Strong<$raw_type> {
|
2017-05-15 13:28:50 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let rules = Locked::<CssRules>::as_arc(&rules).read_with(&guard);
|
2017-07-02 17:00:39 +03:00
|
|
|
let index = index as usize;
|
|
|
|
|
|
|
|
if index >= rules.0.len() {
|
|
|
|
return Strong::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
match rules.0[index] {
|
2017-05-15 13:28:50 +03:00
|
|
|
CssRule::$name(ref rule) => {
|
|
|
|
let location = rule.read_with(&guard).source_location;
|
|
|
|
*unsafe { line.as_mut().unwrap() } = location.line as u32;
|
|
|
|
*unsafe { column.as_mut().unwrap() } = location.column as u32;
|
|
|
|
rule.clone().into_strong()
|
|
|
|
},
|
|
|
|
_ => {
|
2017-07-02 17:00:39 +03:00
|
|
|
Strong::null()
|
2017-03-15 13:58:06 +03:00
|
|
|
}
|
2017-05-15 13:28:50 +03:00
|
|
|
}
|
2017-03-15 13:58:06 +03:00
|
|
|
}
|
|
|
|
|
2017-05-19 07:49:30 +03:00
|
|
|
impl_basic_rule_funcs_without_getter! { ($rule_type, $raw_type),
|
|
|
|
debug: $debug,
|
|
|
|
to_css: $to_css,
|
2017-03-15 13:58:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:11:04 +03:00
|
|
|
macro_rules! impl_group_rule_funcs {
|
|
|
|
{ ($name:ident, $rule_type:ty, $raw_type:ty),
|
|
|
|
get_rules: $get_rules:ident,
|
|
|
|
$($basic:tt)+
|
|
|
|
} => {
|
|
|
|
impl_basic_rule_funcs! { ($name, $rule_type, $raw_type), $($basic)+ }
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-26 21:16:01 +03:00
|
|
|
pub extern "C" fn $get_rules(rule: &$raw_type) -> Strong<ServoCssRules> {
|
2017-04-28 13:11:04 +03:00
|
|
|
read_locked_arc(rule, |rule: &$rule_type| {
|
|
|
|
rule.rules.clone().into_strong()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 13:58:06 +03:00
|
|
|
impl_basic_rule_funcs! { (Style, StyleRule, RawServoStyleRule),
|
|
|
|
getter: Servo_CssRules_GetStyleRuleAt,
|
|
|
|
debug: Servo_StyleRule_Debug,
|
|
|
|
to_css: Servo_StyleRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
2017-05-30 02:51:45 +03:00
|
|
|
impl_basic_rule_funcs! { (Import, ImportRule, RawServoImportRule),
|
|
|
|
getter: Servo_CssRules_GetImportRuleAt,
|
|
|
|
debug: Servo_ImportRule_Debug,
|
|
|
|
to_css: Servo_ImportRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
2017-05-19 07:49:30 +03:00
|
|
|
impl_basic_rule_funcs_without_getter! { (Keyframe, RawServoKeyframe),
|
|
|
|
debug: Servo_Keyframe_Debug,
|
|
|
|
to_css: Servo_Keyframe_GetCssText,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_basic_rule_funcs! { (Keyframes, KeyframesRule, RawServoKeyframesRule),
|
|
|
|
getter: Servo_CssRules_GetKeyframesRuleAt,
|
|
|
|
debug: Servo_KeyframesRule_Debug,
|
|
|
|
to_css: Servo_KeyframesRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:11:04 +03:00
|
|
|
impl_group_rule_funcs! { (Media, MediaRule, RawServoMediaRule),
|
|
|
|
get_rules: Servo_MediaRule_GetRules,
|
2017-03-15 13:58:06 +03:00
|
|
|
getter: Servo_CssRules_GetMediaRuleAt,
|
|
|
|
debug: Servo_MediaRule_Debug,
|
|
|
|
to_css: Servo_MediaRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_basic_rule_funcs! { (Namespace, NamespaceRule, RawServoNamespaceRule),
|
|
|
|
getter: Servo_CssRules_GetNamespaceRuleAt,
|
|
|
|
debug: Servo_NamespaceRule_Debug,
|
|
|
|
to_css: Servo_NamespaceRule_GetCssText,
|
2016-11-24 02:47:18 +03:00
|
|
|
}
|
|
|
|
|
2017-04-10 05:47:59 +03:00
|
|
|
impl_basic_rule_funcs! { (Page, PageRule, RawServoPageRule),
|
|
|
|
getter: Servo_CssRules_GetPageRuleAt,
|
|
|
|
debug: Servo_PageRule_Debug,
|
|
|
|
to_css: Servo_PageRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:11:04 +03:00
|
|
|
impl_group_rule_funcs! { (Supports, SupportsRule, RawServoSupportsRule),
|
|
|
|
get_rules: Servo_SupportsRule_GetRules,
|
|
|
|
getter: Servo_CssRules_GetSupportsRuleAt,
|
|
|
|
debug: Servo_SupportsRule_Debug,
|
|
|
|
to_css: Servo_SupportsRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
2018-06-05 18:16:51 +03:00
|
|
|
impl_group_rule_funcs! { (Document, DocumentRule, RawServoMozDocumentRule),
|
|
|
|
get_rules: Servo_MozDocumentRule_GetRules,
|
|
|
|
getter: Servo_CssRules_GetMozDocumentRuleAt,
|
|
|
|
debug: Servo_MozDocumentRule_Debug,
|
|
|
|
to_css: Servo_MozDocumentRule_GetCssText,
|
2017-05-11 14:27:42 +03:00
|
|
|
}
|
|
|
|
|
2017-07-28 00:15:02 +03:00
|
|
|
impl_basic_rule_funcs! { (FontFeatureValues, FontFeatureValuesRule, RawServoFontFeatureValuesRule),
|
|
|
|
getter: Servo_CssRules_GetFontFeatureValuesRuleAt,
|
|
|
|
debug: Servo_FontFeatureValuesRule_Debug,
|
|
|
|
to_css: Servo_FontFeatureValuesRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:33:59 +03:00
|
|
|
impl_basic_rule_funcs! { (FontFace, FontFaceRule, RawServoFontFaceRule),
|
|
|
|
getter: Servo_CssRules_GetFontFaceRuleAt,
|
|
|
|
debug: Servo_FontFaceRule_Debug,
|
|
|
|
to_css: Servo_FontFaceRule_GetCssText,
|
|
|
|
}
|
|
|
|
|
2018-04-05 02:34:06 +03:00
|
|
|
impl_basic_rule_funcs! { (CounterStyle, CounterStyleRule, RawServoCounterStyleRule),
|
|
|
|
getter: Servo_CssRules_GetCounterStyleRuleAt,
|
|
|
|
debug: Servo_CounterStyleRule_Debug,
|
|
|
|
to_css: Servo_CounterStyleRule_GetCssText,
|
2017-03-30 04:50:47 +03:00
|
|
|
}
|
|
|
|
|
2016-11-24 02:47:18 +03:00
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_GetStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoStyleRule,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoDeclarationBlock> {
|
2018-11-20 07:37:53 +03:00
|
|
|
read_locked_arc(rule, |rule: &StyleRule| rule.block.clone().into_strong())
|
2016-11-24 02:47:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_SetStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoStyleRule,
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
2018-11-20 07:37:53 +03:00
|
|
|
) {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(rule, |rule: &mut StyleRule| {
|
2017-07-18 05:44:25 +03:00
|
|
|
rule.block = declarations.clone_arc();
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2016-11-24 02:47:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_GetSelectorText(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoStyleRule,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-11-20 07:37:53 +03:00
|
|
|
) {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(rule, |rule: &StyleRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.selectors.to_css(result).unwrap();
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2016-11-24 02:47:18 +03:00
|
|
|
}
|
|
|
|
|
2017-06-07 19:54:47 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_GetSelectorTextAtIndex(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoStyleRule,
|
2018-02-13 18:25:30 +03:00
|
|
|
index: u32,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-06-07 19:54:47 +03:00
|
|
|
read_locked_arc(rule, |rule: &StyleRule| {
|
2017-06-12 15:46:11 +03:00
|
|
|
let index = index as usize;
|
|
|
|
if index >= rule.selectors.0.len() {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.selectors.0[index].to_css(result).unwrap();
|
2017-06-07 19:54:47 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_GetSelectorCount(rule: &RawServoStyleRule, count: *mut u32) {
|
2017-06-07 19:54:47 +03:00
|
|
|
read_locked_arc(rule, |rule: &StyleRule| {
|
|
|
|
*unsafe { count.as_mut().unwrap() } = rule.selectors.0.len() as u32;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-12 15:46:11 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_GetSpecificityAtIndex(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoStyleRule,
|
2017-07-02 17:00:39 +03:00
|
|
|
index: u32,
|
2018-11-20 07:37:53 +03:00
|
|
|
specificity: *mut u64,
|
2017-07-02 17:00:39 +03:00
|
|
|
) {
|
2017-06-12 15:46:11 +03:00
|
|
|
read_locked_arc(rule, |rule: &StyleRule| {
|
2018-11-20 07:37:53 +03:00
|
|
|
let specificity = unsafe { specificity.as_mut().unwrap() };
|
2017-06-12 15:46:11 +03:00
|
|
|
let index = index as usize;
|
|
|
|
if index >= rule.selectors.0.len() {
|
|
|
|
*specificity = 0;
|
|
|
|
return;
|
|
|
|
}
|
2017-07-13 14:15:15 +03:00
|
|
|
*specificity = rule.selectors.0[index].specificity() as u64;
|
2017-06-12 15:46:11 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-04 15:08:03 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_SelectorMatchesElement(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoStyleRule,
|
|
|
|
element: &RawGeckoElement,
|
2018-02-13 18:25:30 +03:00
|
|
|
index: u32,
|
2019-02-19 16:44:33 +03:00
|
|
|
pseudo_type: PseudoStyleType,
|
2019-09-14 01:12:12 +03:00
|
|
|
relevant_link_visited: bool,
|
2018-02-13 18:25:30 +03:00
|
|
|
) -> bool {
|
2017-07-04 15:08:03 +03:00
|
|
|
read_locked_arc(rule, |rule: &StyleRule| {
|
|
|
|
let index = index as usize;
|
|
|
|
if index >= rule.selectors.0.len() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-13 14:15:15 +03:00
|
|
|
let selector = &rule.selectors.0[index];
|
2017-07-04 15:08:03 +03:00
|
|
|
let mut matching_mode = MatchingMode::Normal;
|
|
|
|
|
|
|
|
match PseudoElement::from_pseudo_type(pseudo_type) {
|
|
|
|
Some(pseudo) => {
|
|
|
|
// We need to make sure that the requested pseudo element type
|
|
|
|
// matches the selector pseudo element type before proceeding.
|
2017-07-13 14:15:15 +03:00
|
|
|
match selector.pseudo_element() {
|
2017-07-04 15:08:03 +03:00
|
|
|
Some(selector_pseudo) if *selector_pseudo == pseudo => {
|
|
|
|
matching_mode = MatchingMode::ForStatelessPseudoElement
|
|
|
|
},
|
|
|
|
_ => return false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
// Do not attempt to match if a pseudo element is requested and
|
|
|
|
// this is not a pseudo element selector, or vice versa.
|
2017-07-13 14:15:15 +03:00
|
|
|
if selector.has_pseudo_element() {
|
2017-07-04 15:08:03 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let element = GeckoElement(element);
|
2017-10-26 15:51:21 +03:00
|
|
|
let quirks_mode = element.as_node().owner_doc().quirks_mode();
|
2019-09-14 01:12:12 +03:00
|
|
|
let visited_mode =
|
|
|
|
if relevant_link_visited {
|
|
|
|
VisitedHandlingMode::RelevantLinkVisited
|
|
|
|
} else {
|
|
|
|
VisitedHandlingMode::AllLinksUnvisited
|
|
|
|
};
|
|
|
|
let mut ctx =
|
|
|
|
MatchingContext::new_for_visited(matching_mode, None, None, visited_mode, quirks_mode);
|
2017-07-13 14:15:15 +03:00
|
|
|
matches_selector(selector, 0, None, &element, &mut ctx, &mut |_, _| {})
|
2017-07-04 15:08:03 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-14 19:05:44 +03:00
|
|
|
#[no_mangle]
|
2020-01-07 12:47:20 +03:00
|
|
|
pub extern "C" fn Servo_StyleRule_SetSelectorText(
|
2019-03-21 20:00:27 +03:00
|
|
|
sheet: &RawServoStyleSheetContents,
|
|
|
|
rule: &RawServoStyleRule,
|
2020-01-07 12:47:20 +03:00
|
|
|
text: &nsAString,
|
2018-04-14 19:05:44 +03:00
|
|
|
) -> bool {
|
2020-01-07 12:47:20 +03:00
|
|
|
let value_str = text.to_string();
|
2018-04-14 19:05:44 +03:00
|
|
|
|
|
|
|
write_locked_arc(rule, |rule: &mut StyleRule| {
|
|
|
|
use style::selector_parser::SelectorParser;
|
|
|
|
|
|
|
|
let contents = StylesheetContents::as_arc(&sheet);
|
|
|
|
let namespaces = contents.namespaces.read();
|
|
|
|
let url_data = contents.url_data.read();
|
|
|
|
let parser = SelectorParser {
|
|
|
|
stylesheet_origin: contents.origin,
|
|
|
|
namespaces: &namespaces,
|
|
|
|
url_data: Some(&url_data),
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut parser_input = ParserInput::new(&value_str);
|
|
|
|
match SelectorList::parse(&parser, &mut Parser::new(&mut parser_input)) {
|
|
|
|
Ok(selectors) => {
|
|
|
|
rule.selectors = selectors;
|
|
|
|
true
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-04-14 19:05:44 +03:00
|
|
|
Err(_) => false,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-13 15:22:43 +03:00
|
|
|
#[no_mangle]
|
2017-10-14 16:13:59 +03:00
|
|
|
pub unsafe extern "C" fn Servo_SelectorList_Closest(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
|
|
|
selectors: &RawServoSelectorList,
|
|
|
|
) -> *const RawGeckoElement {
|
2017-10-13 15:22:43 +03:00
|
|
|
use std::borrow::Borrow;
|
2017-10-13 18:48:57 +03:00
|
|
|
use style::dom_apis;
|
2017-10-13 15:22:43 +03:00
|
|
|
|
|
|
|
let element = GeckoElement(element);
|
2017-10-26 15:51:21 +03:00
|
|
|
let quirks_mode = element.as_node().owner_doc().quirks_mode();
|
2017-10-13 15:22:43 +03:00
|
|
|
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
dom_apis::element_closest(element, &selectors, quirks_mode).map_or(ptr::null(), |e| e.0)
|
2017-10-13 15:22:43 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 16:05:07 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SelectorList_Matches(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
|
|
|
selectors: &RawServoSelectorList,
|
2017-10-03 16:05:07 +03:00
|
|
|
) -> bool {
|
2017-10-10 09:20:38 +03:00
|
|
|
use std::borrow::Borrow;
|
2017-10-13 18:48:57 +03:00
|
|
|
use style::dom_apis;
|
2017-10-10 09:20:38 +03:00
|
|
|
|
2017-10-03 16:05:07 +03:00
|
|
|
let element = GeckoElement(element);
|
2017-10-26 15:51:21 +03:00
|
|
|
let quirks_mode = element.as_node().owner_doc().quirks_mode();
|
2017-10-10 09:20:38 +03:00
|
|
|
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
|
2018-11-20 07:37:53 +03:00
|
|
|
dom_apis::element_matches(&element, &selectors, quirks_mode)
|
2017-10-03 16:05:07 +03:00
|
|
|
}
|
|
|
|
|
2017-10-23 16:14:35 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SelectorList_QueryFirst(
|
2019-03-21 20:00:27 +03:00
|
|
|
node: &RawGeckoNode,
|
|
|
|
selectors: &RawServoSelectorList,
|
2017-11-04 13:36:17 +03:00
|
|
|
may_use_invalidation: bool,
|
2019-03-21 20:00:27 +03:00
|
|
|
) -> *const RawGeckoElement {
|
2017-10-23 16:14:35 +03:00
|
|
|
use std::borrow::Borrow;
|
2017-11-04 13:36:17 +03:00
|
|
|
use style::dom_apis::{self, MayUseInvalidation, QueryFirst};
|
2017-10-23 16:14:35 +03:00
|
|
|
|
|
|
|
let node = GeckoNode(node);
|
|
|
|
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
|
|
|
|
let mut result = None;
|
2017-11-04 13:36:17 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let may_use_invalidation = if may_use_invalidation {
|
|
|
|
MayUseInvalidation::Yes
|
|
|
|
} else {
|
|
|
|
MayUseInvalidation::No
|
|
|
|
};
|
2017-11-04 13:36:17 +03:00
|
|
|
|
2017-10-23 16:14:35 +03:00
|
|
|
dom_apis::query_selector::<GeckoElement, QueryFirst>(
|
|
|
|
node,
|
|
|
|
&selectors,
|
|
|
|
&mut result,
|
2017-11-04 13:36:17 +03:00
|
|
|
may_use_invalidation,
|
2017-10-23 16:14:35 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
result.map_or(ptr::null(), |e| e.0)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SelectorList_QueryAll(
|
2019-03-21 20:00:27 +03:00
|
|
|
node: &RawGeckoNode,
|
|
|
|
selectors: &RawServoSelectorList,
|
2017-10-23 16:14:35 +03:00
|
|
|
content_list: *mut structs::nsSimpleContentList,
|
2017-11-04 13:36:17 +03:00
|
|
|
may_use_invalidation: bool,
|
2017-10-23 16:14:35 +03:00
|
|
|
) {
|
|
|
|
use std::borrow::Borrow;
|
2017-11-04 13:36:17 +03:00
|
|
|
use style::dom_apis::{self, MayUseInvalidation, QueryAll};
|
2017-10-23 16:14:35 +03:00
|
|
|
|
|
|
|
let node = GeckoNode(node);
|
|
|
|
let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
|
|
|
|
let mut result = SmallVec::new();
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let may_use_invalidation = if may_use_invalidation {
|
|
|
|
MayUseInvalidation::Yes
|
|
|
|
} else {
|
|
|
|
MayUseInvalidation::No
|
|
|
|
};
|
2017-11-04 13:36:17 +03:00
|
|
|
|
2017-10-23 16:14:35 +03:00
|
|
|
dom_apis::query_selector::<GeckoElement, QueryAll>(
|
|
|
|
node,
|
|
|
|
&selectors,
|
|
|
|
&mut result,
|
2017-11-04 13:36:17 +03:00
|
|
|
may_use_invalidation,
|
2017-10-23 16:14:35 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
if !result.is_empty() {
|
|
|
|
// NOTE(emilio): This relies on a slice of GeckoElement having the same
|
|
|
|
// memory representation than a slice of element pointers.
|
|
|
|
bindings::Gecko_ContentList_AppendAll(
|
|
|
|
content_list,
|
|
|
|
result.as_ptr() as *mut *const _,
|
|
|
|
result.len(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 02:51:45 +03:00
|
|
|
#[no_mangle]
|
2020-01-05 17:42:23 +03:00
|
|
|
pub extern "C" fn Servo_ImportRule_GetHref(rule: &RawServoImportRule, result: &mut nsAString) {
|
2017-05-30 02:51:45 +03:00
|
|
|
read_locked_arc(rule, |rule: &ImportRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
write!(result, "{}", rule.url.as_str()).unwrap();
|
2017-05-30 02:51:45 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_ImportRule_GetSheet(rule: &RawServoImportRule) -> *const DomStyleSheet {
|
2017-05-30 02:51:45 +03:00
|
|
|
read_locked_arc(rule, |rule: &ImportRule| {
|
2018-04-30 20:23:14 +03:00
|
|
|
rule.stylesheet.as_sheet().unwrap().raw() as *const DomStyleSheet
|
2017-05-30 02:51:45 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-02-15 03:39:35 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_ImportRule_SetSheet(rule: &RawServoImportRule, sheet: *mut DomStyleSheet) {
|
2018-02-15 03:39:35 +03:00
|
|
|
write_locked_arc(rule, |rule: &mut ImportRule| {
|
|
|
|
let sheet = unsafe { GeckoStyleSheet::new(sheet) };
|
|
|
|
rule.stylesheet = ImportSheet::new(sheet);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-19 07:49:30 +03:00
|
|
|
#[no_mangle]
|
2020-01-05 17:42:23 +03:00
|
|
|
pub extern "C" fn Servo_Keyframe_GetKeyText(keyframe: &RawServoKeyframe, result: &mut nsAString) {
|
2017-05-19 07:49:30 +03:00
|
|
|
read_locked_arc(keyframe, |keyframe: &Keyframe| {
|
2020-01-05 17:42:23 +03:00
|
|
|
keyframe.selector.to_css(&mut CssWriter::new(result)).unwrap()
|
2017-05-19 07:49:30 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_Keyframe_SetKeyText(
|
2019-03-21 20:00:27 +03:00
|
|
|
keyframe: &RawServoKeyframe,
|
2019-11-27 23:57:51 +03:00
|
|
|
text: &nsACString,
|
2018-11-20 07:37:53 +03:00
|
|
|
) -> bool {
|
2019-11-27 23:57:51 +03:00
|
|
|
let text = unsafe { text.as_str_unchecked() };
|
2017-06-10 00:31:48 +03:00
|
|
|
let mut input = ParserInput::new(&text);
|
|
|
|
if let Ok(selector) = Parser::new(&mut input).parse_entirely(KeyframeSelector::parse) {
|
2017-05-19 07:49:30 +03:00
|
|
|
write_locked_arc(keyframe, |keyframe: &mut Keyframe| {
|
|
|
|
keyframe.selector = selector;
|
|
|
|
});
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_Keyframe_GetStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
keyframe: &RawServoKeyframe,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoDeclarationBlock> {
|
2018-11-20 07:37:53 +03:00
|
|
|
read_locked_arc(keyframe, |keyframe: &Keyframe| {
|
|
|
|
keyframe.block.clone().into_strong()
|
|
|
|
})
|
2017-05-19 07:49:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_Keyframe_SetStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
keyframe: &RawServoKeyframe,
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
2018-11-20 07:37:53 +03:00
|
|
|
) {
|
2017-05-19 07:49:30 +03:00
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
write_locked_arc(keyframe, |keyframe: &mut Keyframe| {
|
2017-07-18 05:44:25 +03:00
|
|
|
keyframe.block = declarations.clone_arc();
|
2017-05-19 07:49:30 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_KeyframesRule_GetName(rule: &RawServoKeyframesRule) -> *mut nsAtom {
|
2017-05-19 07:49:30 +03:00
|
|
|
read_locked_arc(rule, |rule: &KeyframesRule| rule.name.as_atom().as_ptr())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_KeyframesRule_SetName(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoKeyframesRule,
|
2018-11-20 07:37:53 +03:00
|
|
|
name: *mut nsAtom,
|
|
|
|
) {
|
2017-05-19 07:49:30 +03:00
|
|
|
write_locked_arc(rule, |rule: &mut KeyframesRule| {
|
2018-03-19 13:11:14 +03:00
|
|
|
rule.name = KeyframesName::Ident(CustomIdent(Atom::from_addrefed(name)));
|
2017-05-19 07:49:30 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_KeyframesRule_GetCount(rule: &RawServoKeyframesRule) -> u32 {
|
2017-05-19 07:49:30 +03:00
|
|
|
read_locked_arc(rule, |rule: &KeyframesRule| rule.keyframes.len() as u32)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_KeyframesRule_GetKeyframeAt(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoKeyframesRule,
|
2018-02-13 18:25:30 +03:00
|
|
|
index: u32,
|
|
|
|
line: *mut u32,
|
|
|
|
column: *mut u32,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoKeyframe> {
|
2017-09-05 19:22:20 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2018-11-20 07:37:53 +03:00
|
|
|
let key = Locked::<KeyframesRule>::as_arc(&rule)
|
|
|
|
.read_with(&guard)
|
|
|
|
.keyframes[index as usize]
|
|
|
|
.clone();
|
2017-09-05 19:22:20 +03:00
|
|
|
let location = key.read_with(&guard).source_location;
|
|
|
|
*unsafe { line.as_mut().unwrap() } = location.line as u32;
|
|
|
|
*unsafe { column.as_mut().unwrap() } = location.column as u32;
|
|
|
|
key.into_strong()
|
2017-05-19 07:49:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_KeyframesRule_FindRule(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoKeyframesRule,
|
2019-11-27 23:57:51 +03:00
|
|
|
key: &nsACString,
|
2018-02-13 18:25:30 +03:00
|
|
|
) -> u32 {
|
2019-11-27 23:57:51 +03:00
|
|
|
let key = unsafe { key.as_str_unchecked() };
|
2017-05-19 07:49:30 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2018-11-20 07:37:53 +03:00
|
|
|
Locked::<KeyframesRule>::as_arc(&rule)
|
|
|
|
.read_with(&guard)
|
|
|
|
.find_rule(&guard, key)
|
|
|
|
.map(|index| index as u32)
|
2017-05-19 07:49:30 +03:00
|
|
|
.unwrap_or(u32::max_value())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_KeyframesRule_AppendRule(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoKeyframesRule,
|
|
|
|
contents: &RawServoStyleSheetContents,
|
2019-11-27 23:57:51 +03:00
|
|
|
css: &nsACString,
|
2017-07-02 17:00:39 +03:00
|
|
|
) -> bool {
|
2019-11-27 23:57:51 +03:00
|
|
|
let css = unsafe { css.as_str_unchecked() };
|
2017-07-02 17:00:39 +03:00
|
|
|
let contents = StylesheetContents::as_arc(&contents);
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2017-08-18 20:58:46 +03:00
|
|
|
|
2017-07-02 17:00:39 +03:00
|
|
|
match Keyframe::parse(css, &contents, &global_style_data.shared_lock) {
|
|
|
|
Ok(keyframe) => {
|
|
|
|
write_locked_arc(rule, |rule: &mut KeyframesRule| {
|
|
|
|
rule.keyframes.push(keyframe);
|
|
|
|
});
|
|
|
|
true
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-07-02 17:00:39 +03:00
|
|
|
Err(..) => false,
|
2017-05-19 07:49:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_KeyframesRule_DeleteRule(rule: &RawServoKeyframesRule, index: u32) {
|
2017-05-19 07:49:30 +03:00
|
|
|
write_locked_arc(rule, |rule: &mut KeyframesRule| {
|
|
|
|
rule.keyframes.remove(index as usize);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-13 09:55:46 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_MediaRule_GetMedia(rule: &RawServoMediaRule) -> Strong<RawServoMediaList> {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(rule, |rule: &MediaRule| {
|
|
|
|
rule.media_queries.clone().into_strong()
|
|
|
|
})
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_NamespaceRule_GetPrefix(rule: &RawServoNamespaceRule) -> *mut nsAtom {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(rule, |rule: &NamespaceRule| {
|
|
|
|
rule.prefix.as_ref().unwrap_or(&atom!("")).as_ptr()
|
|
|
|
})
|
2017-03-15 13:58:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_NamespaceRule_GetURI(rule: &RawServoNamespaceRule) -> *mut nsAtom {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(rule, |rule: &NamespaceRule| rule.url.0.as_ptr())
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
2017-04-10 05:47:59 +03:00
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_PageRule_GetStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoPageRule,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoDeclarationBlock> {
|
2018-11-20 07:37:53 +03:00
|
|
|
read_locked_arc(rule, |rule: &PageRule| rule.block.clone().into_strong())
|
2017-04-10 05:47:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_PageRule_SetStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoPageRule,
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-04-10 05:47:59 +03:00
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
write_locked_arc(rule, |rule: &mut PageRule| {
|
2017-07-18 05:44:25 +03:00
|
|
|
rule.block = declarations.clone_arc();
|
2017-04-10 05:47:59 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:11:04 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_SupportsRule_GetConditionText(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoSupportsRule,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-04-28 13:11:04 +03:00
|
|
|
read_locked_arc(rule, |rule: &SupportsRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.condition.to_css(&mut CssWriter::new(result)).unwrap();
|
2017-04-28 13:11:04 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-11 14:27:42 +03:00
|
|
|
#[no_mangle]
|
2018-06-05 18:16:51 +03:00
|
|
|
pub extern "C" fn Servo_MozDocumentRule_GetConditionText(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoMozDocumentRule,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-05-11 14:27:42 +03:00
|
|
|
read_locked_arc(rule, |rule: &DocumentRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.condition.to_css(&mut CssWriter::new(result)).unwrap();
|
2017-05-11 14:27:42 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-28 00:15:02 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_FontFeatureValuesRule_GetFontFamily(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFeatureValuesRule,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-07-28 00:15:02 +03:00
|
|
|
read_locked_arc(rule, |rule: &FontFeatureValuesRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.font_family_to_css(&mut CssWriter::new(result)).unwrap()
|
2017-07-28 00:15:02 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_FontFeatureValuesRule_GetValueText(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFeatureValuesRule,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-07-28 00:15:02 +03:00
|
|
|
read_locked_arc(rule, |rule: &FontFeatureValuesRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.value_to_css(&mut CssWriter::new(result)).unwrap();
|
2017-07-28 00:15:02 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:33:59 +03:00
|
|
|
#[no_mangle]
|
2019-03-26 21:16:01 +03:00
|
|
|
pub extern "C" fn Servo_FontFaceRule_CreateEmpty() -> Strong<RawServoFontFaceRule> {
|
2018-04-04 02:33:59 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
// XXX This is not great. We should split FontFace descriptor data
|
|
|
|
// from the rule, so that we don't need to create the rule like this
|
|
|
|
// and the descriptor data itself can be hold in UniquePtr from the
|
|
|
|
// Gecko side. See bug 1450904.
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(
|
|
|
|
global_style_data
|
|
|
|
.shared_lock
|
|
|
|
.wrap(FontFaceRule::empty(SourceLocation { line: 0, column: 0 })),
|
|
|
|
)
|
|
|
|
.into_strong()
|
2018-04-04 02:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_Clone(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoFontFaceRule> {
|
2018-04-04 02:33:59 +03:00
|
|
|
let clone = read_locked_arc(rule, |rule: &FontFaceRule| rule.clone());
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
Arc::new(global_style_data.shared_lock.wrap(clone)).into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetSourceLocation(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-04-04 02:33:59 +03:00
|
|
|
line: *mut u32,
|
|
|
|
column: *mut u32,
|
|
|
|
) {
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
|
|
|
let location = rule.source_location;
|
|
|
|
*line.as_mut().unwrap() = location.line as u32;
|
|
|
|
*column.as_mut().unwrap() = location.column as u32;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! apply_font_desc_list {
|
|
|
|
($apply_macro:ident) => {
|
|
|
|
$apply_macro! {
|
|
|
|
valid: [
|
|
|
|
eCSSFontDesc_Family => family,
|
|
|
|
eCSSFontDesc_Style => style,
|
|
|
|
eCSSFontDesc_Weight => weight,
|
|
|
|
eCSSFontDesc_Stretch => stretch,
|
|
|
|
eCSSFontDesc_Src => sources,
|
|
|
|
eCSSFontDesc_UnicodeRange => unicode_range,
|
|
|
|
eCSSFontDesc_FontFeatureSettings => feature_settings,
|
|
|
|
eCSSFontDesc_FontVariationSettings => variation_settings,
|
|
|
|
eCSSFontDesc_FontLanguageOverride => language_override,
|
|
|
|
eCSSFontDesc_Display => display,
|
|
|
|
]
|
|
|
|
invalid: [
|
|
|
|
eCSSFontDesc_UNKNOWN,
|
|
|
|
eCSSFontDesc_COUNT,
|
|
|
|
]
|
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
};
|
2018-04-04 02:33:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_Length(rule: &RawServoFontFaceRule) -> u32 {
|
2018-04-04 02:33:59 +03:00
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
|
|
|
let mut result = 0;
|
|
|
|
macro_rules! count_values {
|
|
|
|
(
|
|
|
|
valid: [$($v_enum_name:ident => $field:ident,)*]
|
|
|
|
invalid: [$($i_enum_name:ident,)*]
|
|
|
|
) => {
|
|
|
|
$(if rule.$field.is_some() {
|
|
|
|
result += 1;
|
|
|
|
})*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
apply_font_desc_list!(count_values);
|
|
|
|
result
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_IndexGetter(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-04-04 02:33:59 +03:00
|
|
|
index: u32,
|
|
|
|
) -> nsCSSFontDesc {
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
|
|
|
let mut count = 0;
|
|
|
|
macro_rules! lookup_index {
|
|
|
|
(
|
|
|
|
valid: [$($v_enum_name:ident => $field:ident,)*]
|
|
|
|
invalid: [$($i_enum_name:ident,)*]
|
|
|
|
) => {
|
|
|
|
$(if rule.$field.is_some() {
|
|
|
|
count += 1;
|
|
|
|
if count - 1 == index {
|
|
|
|
return nsCSSFontDesc::$v_enum_name;
|
|
|
|
}
|
|
|
|
})*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
apply_font_desc_list!(lookup_index);
|
|
|
|
return nsCSSFontDesc::eCSSFontDesc_UNKNOWN;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetDeclCssText(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-04-04 02:33:59 +03:00
|
|
|
) {
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
rule.decl_to_css(result).unwrap();
|
2018-04-04 02:33:59 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-30 23:18:33 +03:00
|
|
|
macro_rules! simple_font_descriptor_getter_impl {
|
|
|
|
($rule:ident, $out:ident, $field:ident, $compute:ident) => {
|
|
|
|
read_locked_arc($rule, |rule: &FontFaceRule| {
|
|
|
|
match rule.$field {
|
|
|
|
None => return false,
|
|
|
|
Some(ref f) => *$out = f.$compute(),
|
|
|
|
}
|
|
|
|
true
|
|
|
|
})
|
2018-11-20 07:37:53 +03:00
|
|
|
};
|
2018-10-04 00:50:21 +03:00
|
|
|
}
|
|
|
|
|
2019-03-30 23:18:33 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetFontWeight(
|
|
|
|
rule: &RawServoFontFaceRule,
|
|
|
|
out: &mut font_face::ComputedFontWeightRange,
|
|
|
|
) -> bool {
|
|
|
|
simple_font_descriptor_getter_impl!(rule, out, weight, compute)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetFontStretch(
|
|
|
|
rule: &RawServoFontFaceRule,
|
|
|
|
out: &mut font_face::ComputedFontStretchRange,
|
|
|
|
) -> bool {
|
|
|
|
simple_font_descriptor_getter_impl!(rule, out, stretch, compute)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetFontStyle(
|
|
|
|
rule: &RawServoFontFaceRule,
|
|
|
|
out: &mut font_face::ComputedFontStyleDescriptor,
|
|
|
|
) -> bool {
|
|
|
|
simple_font_descriptor_getter_impl!(rule, out, style, compute)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetFontDisplay(
|
|
|
|
rule: &RawServoFontFaceRule,
|
|
|
|
out: &mut font_face::FontDisplay,
|
|
|
|
) -> bool {
|
|
|
|
simple_font_descriptor_getter_impl!(rule, out, display, clone)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetFontLanguageOverride(
|
|
|
|
rule: &RawServoFontFaceRule,
|
|
|
|
out: &mut computed::FontLanguageOverride,
|
|
|
|
) -> bool {
|
|
|
|
simple_font_descriptor_getter_impl!(rule, out, language_override, compute_non_system)
|
|
|
|
}
|
2018-10-04 00:50:21 +03:00
|
|
|
|
2018-04-04 02:33:59 +03:00
|
|
|
#[no_mangle]
|
2018-10-04 00:50:21 +03:00
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetFamilyName(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-10-04 00:50:21 +03:00
|
|
|
) -> *mut nsAtom {
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
|
|
|
// TODO(emilio): font-family is a mandatory descriptor, can't we unwrap
|
|
|
|
// here, and remove the null-checks in Gecko?
|
2018-11-20 07:37:53 +03:00
|
|
|
rule.family
|
|
|
|
.as_ref()
|
|
|
|
.map_or(ptr::null_mut(), |f| f.name.as_ptr())
|
2018-10-04 00:50:21 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetUnicodeRanges(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-10-04 00:50:21 +03:00
|
|
|
out_len: *mut usize,
|
2019-03-30 23:18:33 +03:00
|
|
|
) -> *const UnicodeRange {
|
2018-10-04 00:50:21 +03:00
|
|
|
*out_len = 0;
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
|
|
|
let ranges = match rule.unicode_range {
|
|
|
|
Some(ref ranges) => ranges,
|
|
|
|
None => return ptr::null(),
|
|
|
|
};
|
|
|
|
*out_len = ranges.len();
|
|
|
|
ranges.as_ptr() as *const _
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetSources(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2019-03-30 23:18:33 +03:00
|
|
|
out: *mut nsTArray<FontFaceSourceListComponent>,
|
2018-04-04 02:33:59 +03:00
|
|
|
) {
|
2018-10-04 00:50:21 +03:00
|
|
|
let out = &mut *out;
|
2018-04-04 02:33:59 +03:00
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
2018-10-04 00:50:21 +03:00
|
|
|
let sources = match rule.sources {
|
|
|
|
Some(ref s) => s,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
let len = sources.iter().fold(0, |acc, src| {
|
|
|
|
acc + match *src {
|
|
|
|
// Each format hint takes one position in the array of mSrc.
|
|
|
|
Source::Url(ref url) => url.format_hints.len() + 1,
|
|
|
|
Source::Local(_) => 1,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
out.set_len(len as u32);
|
|
|
|
|
|
|
|
let mut iter = out.iter_mut();
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut set_next = |component: FontFaceSourceListComponent| {
|
2018-10-31 09:20:15 +03:00
|
|
|
*iter.next().expect("miscalculated length") = component;
|
2018-10-04 00:50:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
for source in sources.iter() {
|
|
|
|
match *source {
|
|
|
|
Source::Url(ref url) => {
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
set_next(FontFaceSourceListComponent::Url(&url.url));
|
2018-10-04 00:50:21 +03:00
|
|
|
for hint in url.format_hints.iter() {
|
|
|
|
set_next(FontFaceSourceListComponent::FormatHint {
|
|
|
|
length: hint.len(),
|
|
|
|
utf8_bytes: hint.as_ptr(),
|
|
|
|
});
|
2018-10-09 19:44:51 +03:00
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-10-04 00:50:21 +03:00
|
|
|
Source::Local(ref name) => {
|
|
|
|
set_next(FontFaceSourceListComponent::Local(name.name.as_ptr()));
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-04-04 02:33:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-04 00:50:21 +03:00
|
|
|
|
|
|
|
assert!(iter.next().is_none(), "miscalculated");
|
2018-04-04 02:33:59 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-04 00:50:21 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetVariationSettings(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-10-04 00:50:21 +03:00
|
|
|
variations: *mut nsTArray<structs::gfxFontVariation>,
|
|
|
|
) {
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
|
|
|
let source_variations = match rule.variation_settings {
|
|
|
|
Some(ref v) => v,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
(*variations).set_len(source_variations.0.len() as u32);
|
|
|
|
for (target, source) in (*variations).iter_mut().zip(source_variations.0.iter()) {
|
|
|
|
*target = structs::gfxFontVariation {
|
|
|
|
mTag: source.tag.0,
|
|
|
|
mValue: source.value.get(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetFeatureSettings(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-10-04 00:50:21 +03:00
|
|
|
features: *mut nsTArray<structs::gfxFontFeature>,
|
|
|
|
) {
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
|
|
|
let source_features = match rule.feature_settings {
|
|
|
|
Some(ref v) => v,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
(*features).set_len(source_features.0.len() as u32);
|
|
|
|
for (target, source) in (*features).iter_mut().zip(source_features.0.iter()) {
|
|
|
|
*target = structs::gfxFontFeature {
|
|
|
|
mTag: source.tag.0,
|
|
|
|
mValue: source.value.value() as u32,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:33:59 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_GetDescriptorCssText(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-04-04 02:33:59 +03:00
|
|
|
desc: nsCSSFontDesc,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-04-04 02:33:59 +03:00
|
|
|
) {
|
|
|
|
read_locked_arc(rule, |rule: &FontFaceRule| {
|
2020-01-05 17:42:23 +03:00
|
|
|
let mut writer = CssWriter::new(result);
|
2018-04-04 02:33:59 +03:00
|
|
|
macro_rules! to_css_text {
|
|
|
|
(
|
|
|
|
valid: [$($v_enum_name:ident => $field:ident,)*]
|
|
|
|
invalid: [$($i_enum_name:ident,)*]
|
|
|
|
) => {
|
|
|
|
match desc {
|
|
|
|
$(
|
|
|
|
nsCSSFontDesc::$v_enum_name => {
|
|
|
|
if let Some(ref value) = rule.$field {
|
|
|
|
value.to_css(&mut writer).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
$(
|
|
|
|
nsCSSFontDesc::$i_enum_name => {
|
|
|
|
debug_assert!(false, "not a valid font descriptor");
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
apply_font_desc_list!(to_css_text)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_SetDescriptor(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-04-04 02:33:59 +03:00
|
|
|
desc: nsCSSFontDesc,
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2018-04-04 02:33:59 +03:00
|
|
|
data: *mut URLExtraData,
|
2019-05-09 12:43:42 +03:00
|
|
|
out_changed: *mut bool,
|
2018-04-04 02:33:59 +03:00
|
|
|
) -> bool {
|
2019-11-27 23:57:51 +03:00
|
|
|
let value = value.as_str_unchecked();
|
2018-04-04 02:33:59 +03:00
|
|
|
let mut input = ParserInput::new(&value);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
2018-06-21 14:09:35 +03:00
|
|
|
let url_data = UrlExtraData::from_ptr_ref(&data);
|
2018-04-04 02:33:59 +03:00
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::FontFace),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2018-04-04 02:33:59 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
write_locked_arc(rule, |rule: &mut FontFaceRule| {
|
|
|
|
macro_rules! to_css_text {
|
|
|
|
(
|
|
|
|
valid: [$($v_enum_name:ident => $field:ident,)*]
|
|
|
|
invalid: [$($i_enum_name:ident,)*]
|
|
|
|
) => {
|
|
|
|
match desc {
|
|
|
|
$(
|
|
|
|
nsCSSFontDesc::$v_enum_name => {
|
|
|
|
if let Ok(value) = parser.parse_entirely(|i| Parse::parse(&context, i)) {
|
2019-05-09 12:43:42 +03:00
|
|
|
let result = Some(value);
|
|
|
|
*out_changed = result != rule.$field;
|
|
|
|
rule.$field = result;
|
2018-04-04 02:33:59 +03:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
$(
|
|
|
|
nsCSSFontDesc::$i_enum_name => {
|
|
|
|
debug_assert!(false, "not a valid font descriptor");
|
|
|
|
false
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
apply_font_desc_list!(to_css_text)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_FontFaceRule_ResetDescriptor(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoFontFaceRule,
|
2018-04-04 02:33:59 +03:00
|
|
|
desc: nsCSSFontDesc,
|
|
|
|
) {
|
|
|
|
write_locked_arc(rule, |rule: &mut FontFaceRule| {
|
|
|
|
macro_rules! reset_desc {
|
|
|
|
(
|
|
|
|
valid: [$($v_enum_name:ident => $field:ident,)*]
|
|
|
|
invalid: [$($i_enum_name:ident,)*]
|
|
|
|
) => {
|
|
|
|
match desc {
|
|
|
|
$(nsCSSFontDesc::$v_enum_name => rule.$field = None,)*
|
|
|
|
$(nsCSSFontDesc::$i_enum_name => debug_assert!(false, "not a valid font descriptor"),)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
apply_font_desc_list!(reset_desc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-05 02:34:06 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetName(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> *mut nsAtom {
|
2018-11-20 07:37:53 +03:00
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| rule.name().0.as_ptr())
|
2018-04-05 02:34:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_SetName(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> bool {
|
2019-11-27 23:57:51 +03:00
|
|
|
let value = value.as_str_unchecked();
|
2018-04-05 02:34:06 +03:00
|
|
|
let mut input = ParserInput::new(&value);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
|
|
|
match parser.parse_entirely(counter_style::parse_counter_style_name_definition) {
|
|
|
|
Ok(name) => {
|
|
|
|
write_locked_arc(rule, |rule: &mut CounterStyleRule| rule.set_name(name));
|
|
|
|
true
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-04-05 02:34:06 +03:00
|
|
|
Err(_) => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetGeneration(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> u32 {
|
2018-11-20 07:37:53 +03:00
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| rule.generation())
|
2018-04-05 02:34:06 +03:00
|
|
|
}
|
|
|
|
|
2019-05-17 02:05:10 +03:00
|
|
|
fn symbol_to_string(s: &counter_style::Symbol) -> nsString {
|
|
|
|
match *s {
|
|
|
|
counter_style::Symbol::String(ref s) => nsString::from(&**s),
|
2019-08-26 12:58:53 +03:00
|
|
|
counter_style::Symbol::Ident(ref i) => nsString::from(i.0.as_slice()),
|
2019-05-17 02:05:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:05:54 +03:00
|
|
|
// TODO(emilio): Cbindgen could be used to simplify a bunch of code here.
|
2019-05-17 02:05:10 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetPad(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
|
|
|
width: &mut i32,
|
|
|
|
symbol: &mut nsString,
|
|
|
|
) -> bool {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
let pad = match rule.pad() {
|
|
|
|
Some(pad) => pad,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
*width = pad.0.value();
|
|
|
|
*symbol = symbol_to_string(&pad.1);
|
|
|
|
true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:05:25 +03:00
|
|
|
fn get_symbol(s: Option<&counter_style::Symbol>, out: &mut nsString) -> bool {
|
|
|
|
let s = match s {
|
|
|
|
Some(s) => s,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
*out = symbol_to_string(s);
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetPrefix(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
|
|
|
out: &mut nsString,
|
|
|
|
) -> bool {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
get_symbol(rule.prefix(), out)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetSuffix(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
|
|
|
out: &mut nsString,
|
|
|
|
) -> bool {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
get_symbol(rule.suffix(), out)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetNegative(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
|
|
|
prefix: &mut nsString,
|
|
|
|
suffix: &mut nsString,
|
|
|
|
) -> bool {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
let negative = match rule.negative() {
|
|
|
|
Some(n) => n,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
*prefix = symbol_to_string(&negative.0);
|
|
|
|
*suffix = match negative.1 {
|
|
|
|
Some(ref s) => symbol_to_string(s),
|
|
|
|
None => nsString::new(),
|
|
|
|
};
|
|
|
|
true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:05:38 +03:00
|
|
|
#[repr(u8)]
|
|
|
|
pub enum IsOrdinalInRange {
|
|
|
|
Auto,
|
|
|
|
InRange,
|
|
|
|
NotInRange,
|
|
|
|
NoOrdinalSpecified,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_IsInRange(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
|
|
|
ordinal: i32,
|
|
|
|
) -> IsOrdinalInRange {
|
|
|
|
use style::counter_style::CounterBound;
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
let range = match rule.range() {
|
|
|
|
Some(r) => r,
|
|
|
|
None => return IsOrdinalInRange::NoOrdinalSpecified,
|
|
|
|
};
|
|
|
|
|
|
|
|
if range.0.is_empty() {
|
|
|
|
return IsOrdinalInRange::Auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
let in_range = range.0.iter().any(|r| {
|
|
|
|
if let CounterBound::Integer(start) = r.start {
|
|
|
|
if start.value() > ordinal {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let CounterBound::Integer(end) = r.end {
|
|
|
|
if end.value() < ordinal {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
});
|
|
|
|
|
|
|
|
if in_range {
|
|
|
|
IsOrdinalInRange::InRange
|
|
|
|
} else {
|
|
|
|
IsOrdinalInRange::NotInRange
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:05:54 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetSymbols(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
|
|
|
symbols: &mut style::OwnedSlice<nsString>,
|
|
|
|
) {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
*symbols = match rule.symbols() {
|
|
|
|
Some(s) => s.0.iter().map(symbol_to_string).collect(),
|
|
|
|
None => style::OwnedSlice::default(),
|
|
|
|
};
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct AdditiveSymbol {
|
|
|
|
pub weight: i32,
|
|
|
|
pub symbol: nsString,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetAdditiveSymbols(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
|
|
|
symbols: &mut style::OwnedSlice<AdditiveSymbol>,
|
|
|
|
) {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
*symbols = match rule.additive_symbols() {
|
2019-08-26 12:58:53 +03:00
|
|
|
Some(s) => {
|
|
|
|
s.0.iter()
|
|
|
|
.map(|s| AdditiveSymbol {
|
|
|
|
weight: s.weight.value(),
|
|
|
|
symbol: symbol_to_string(&s.symbol),
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
},
|
2019-05-17 02:05:54 +03:00
|
|
|
None => style::OwnedSlice::default(),
|
|
|
|
};
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:06:06 +03:00
|
|
|
#[repr(C, u8)]
|
|
|
|
pub enum CounterSpeakAs {
|
|
|
|
None,
|
|
|
|
Auto,
|
|
|
|
Bullets,
|
|
|
|
Numbers,
|
|
|
|
Words,
|
|
|
|
Ident(*mut nsAtom),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetSpeakAs(
|
|
|
|
rule: &RawServoCounterStyleRule,
|
2019-05-17 07:43:39 +03:00
|
|
|
out: &mut CounterSpeakAs,
|
|
|
|
) {
|
2019-05-17 02:06:06 +03:00
|
|
|
use style::counter_style::SpeakAs;
|
2019-05-17 07:43:39 +03:00
|
|
|
*out = read_locked_arc(rule, |rule: &CounterStyleRule| {
|
2019-05-17 02:06:06 +03:00
|
|
|
let speak_as = match rule.speak_as() {
|
|
|
|
Some(s) => s,
|
|
|
|
None => return CounterSpeakAs::None,
|
|
|
|
};
|
|
|
|
match *speak_as {
|
|
|
|
SpeakAs::Auto => CounterSpeakAs::Auto,
|
|
|
|
SpeakAs::Bullets => CounterSpeakAs::Bullets,
|
|
|
|
SpeakAs::Numbers => CounterSpeakAs::Numbers,
|
|
|
|
SpeakAs::Words => CounterSpeakAs::Words,
|
|
|
|
SpeakAs::Other(ref other) => CounterSpeakAs::Ident(other.0.as_ptr()),
|
|
|
|
}
|
2019-05-17 07:43:39 +03:00
|
|
|
});
|
2019-05-17 02:06:06 +03:00
|
|
|
}
|
|
|
|
|
2018-04-05 02:34:06 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetSystem(rule: &RawServoCounterStyleRule) -> u8 {
|
2018-04-05 02:34:06 +03:00
|
|
|
use style::counter_style::System;
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
match *rule.resolved_system() {
|
|
|
|
System::Cyclic => structs::NS_STYLE_COUNTER_SYSTEM_CYCLIC,
|
|
|
|
System::Numeric => structs::NS_STYLE_COUNTER_SYSTEM_NUMERIC,
|
|
|
|
System::Alphabetic => structs::NS_STYLE_COUNTER_SYSTEM_ALPHABETIC,
|
|
|
|
System::Symbolic => structs::NS_STYLE_COUNTER_SYSTEM_SYMBOLIC,
|
|
|
|
System::Additive => structs::NS_STYLE_COUNTER_SYSTEM_ADDITIVE,
|
|
|
|
System::Fixed { .. } => structs::NS_STYLE_COUNTER_SYSTEM_FIXED,
|
|
|
|
System::Extends(_) => structs::NS_STYLE_COUNTER_SYSTEM_EXTENDS,
|
|
|
|
}
|
|
|
|
}) as u8
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetExtended(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> *mut nsAtom {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
match *rule.resolved_system() {
|
|
|
|
counter_style::System::Extends(ref name) => name.0.as_ptr(),
|
|
|
|
_ => {
|
|
|
|
debug_assert!(false, "Not extends system");
|
|
|
|
ptr::null_mut()
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-04-05 02:34:06 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetFixedFirstValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> i32 {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
match *rule.resolved_system() {
|
|
|
|
counter_style::System::Fixed { first_symbol_value } => {
|
|
|
|
first_symbol_value.map_or(1, |v| v.value())
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-04-05 02:34:06 +03:00
|
|
|
_ => {
|
|
|
|
debug_assert!(false, "Not fixed system");
|
|
|
|
0
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2018-04-05 02:34:06 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetFallback(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> *mut nsAtom {
|
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
rule.fallback().map_or(ptr::null_mut(), |i| i.0 .0.as_ptr())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! counter_style_descriptors {
|
|
|
|
{
|
|
|
|
valid: [
|
|
|
|
$($desc:ident => $getter:ident / $setter:ident,)+
|
|
|
|
]
|
|
|
|
invalid: [
|
|
|
|
$($i_desc:ident,)+
|
|
|
|
]
|
|
|
|
} => {
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_GetDescriptorCssText(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2018-04-05 02:34:06 +03:00
|
|
|
desc: nsCSSCounterDesc,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-04-05 02:34:06 +03:00
|
|
|
) {
|
2020-01-05 17:42:23 +03:00
|
|
|
let mut writer = CssWriter::new(result);
|
2018-04-05 02:34:06 +03:00
|
|
|
read_locked_arc(rule, |rule: &CounterStyleRule| {
|
|
|
|
match desc {
|
|
|
|
$(nsCSSCounterDesc::$desc => {
|
|
|
|
if let Some(value) = rule.$getter() {
|
|
|
|
value.to_css(&mut writer).unwrap();
|
|
|
|
}
|
|
|
|
})+
|
|
|
|
$(nsCSSCounterDesc::$i_desc => unreachable!(),)+
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_CounterStyleRule_SetDescriptor(
|
2019-03-21 20:00:27 +03:00
|
|
|
rule: &RawServoCounterStyleRule,
|
2018-04-05 02:34:06 +03:00
|
|
|
desc: nsCSSCounterDesc,
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> bool {
|
2019-11-27 23:57:51 +03:00
|
|
|
let value = value.as_str_unchecked();
|
2018-04-05 02:34:06 +03:00
|
|
|
let mut input = ParserInput::new(&value);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
|
|
|
let url_data = dummy_url_data();
|
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::CounterStyle),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2018-04-05 02:34:06 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
write_locked_arc(rule, |rule: &mut CounterStyleRule| {
|
|
|
|
match desc {
|
|
|
|
$(nsCSSCounterDesc::$desc => {
|
|
|
|
match parser.parse_entirely(|i| Parse::parse(&context, i)) {
|
|
|
|
Ok(value) => rule.$setter(value),
|
|
|
|
Err(_) => false,
|
|
|
|
}
|
|
|
|
})+
|
|
|
|
$(nsCSSCounterDesc::$i_desc => unreachable!(),)+
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
counter_style_descriptors! {
|
|
|
|
valid: [
|
|
|
|
eCSSCounterDesc_System => system / set_system,
|
|
|
|
eCSSCounterDesc_Symbols => symbols / set_symbols,
|
|
|
|
eCSSCounterDesc_AdditiveSymbols => additive_symbols / set_additive_symbols,
|
|
|
|
eCSSCounterDesc_Negative => negative / set_negative,
|
|
|
|
eCSSCounterDesc_Prefix => prefix / set_prefix,
|
|
|
|
eCSSCounterDesc_Suffix => suffix / set_suffix,
|
|
|
|
eCSSCounterDesc_Range => range / set_range,
|
|
|
|
eCSSCounterDesc_Pad => pad / set_pad,
|
|
|
|
eCSSCounterDesc_Fallback => fallback / set_fallback,
|
|
|
|
eCSSCounterDesc_SpeakAs => speak_as / set_speak_as,
|
|
|
|
]
|
|
|
|
invalid: [
|
|
|
|
eCSSCounterDesc_UNKNOWN,
|
|
|
|
eCSSCounterDesc_COUNT,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2016-03-25 00:57:33 +03:00
|
|
|
#[no_mangle]
|
2018-03-19 13:11:14 +03:00
|
|
|
pub unsafe extern "C" fn Servo_ComputedValues_GetForAnonymousBox(
|
2019-03-21 20:00:27 +03:00
|
|
|
parent_style_or_null: Option<&ComputedValues>,
|
2019-02-19 16:44:33 +03:00
|
|
|
pseudo: PseudoStyleType,
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let guards = StylesheetGuards::same(&guard);
|
2016-12-26 05:13:30 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2019-02-19 16:44:33 +03:00
|
|
|
let pseudo = PseudoElement::from_pseudo_type(pseudo).unwrap();
|
|
|
|
debug_assert!(pseudo.is_anon_box());
|
2016-04-30 00:27:16 +03:00
|
|
|
|
2017-04-09 14:15:51 +03:00
|
|
|
let metrics = get_metrics_provider_for_product();
|
2017-09-07 00:40:33 +03:00
|
|
|
|
|
|
|
// If the pseudo element is PageContent, we should append the precomputed
|
|
|
|
// pseudo element declerations with specified page rules.
|
|
|
|
let page_decls = match pseudo {
|
|
|
|
PseudoElement::PageContent => {
|
|
|
|
let mut declarations = vec![];
|
2017-09-14 01:44:21 +03:00
|
|
|
let iter = data.stylist.iter_extra_data_origins_rev();
|
2017-09-07 00:40:33 +03:00
|
|
|
for (data, origin) in iter {
|
|
|
|
let level = match origin {
|
|
|
|
Origin::UserAgent => CascadeLevel::UANormal,
|
|
|
|
Origin::User => CascadeLevel::UserNormal,
|
2019-11-14 05:49:54 +03:00
|
|
|
Origin::Author => CascadeLevel::same_tree_author_normal(),
|
2017-09-07 00:40:33 +03:00
|
|
|
};
|
|
|
|
for rule in data.pages.iter() {
|
|
|
|
declarations.push(ApplicableDeclarationBlock::from_declarations(
|
|
|
|
rule.read_with(level.guard(&guards)).block.clone(),
|
2018-11-20 07:37:53 +03:00
|
|
|
level,
|
2017-09-07 00:40:33 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(declarations)
|
|
|
|
},
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let rule_node = data
|
|
|
|
.stylist
|
|
|
|
.rule_node_for_precomputed_pseudo(&guards, &pseudo, page_decls);
|
2017-09-07 00:40:33 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
data.stylist
|
|
|
|
.precomputed_values_for_pseudo_with_rule_node::<GeckoElement>(
|
|
|
|
&guards,
|
|
|
|
&pseudo,
|
|
|
|
parent_style_or_null.map(|x| &*x),
|
|
|
|
&metrics,
|
|
|
|
rule_node,
|
|
|
|
)
|
|
|
|
.into()
|
2016-03-25 00:57:33 +03:00
|
|
|
}
|
|
|
|
|
2016-05-04 13:42:23 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_ResolvePseudoStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
pseudo_type: PseudoStyleType,
|
2018-02-13 18:25:30 +03:00
|
|
|
is_probe: bool,
|
2019-03-21 20:00:27 +03:00
|
|
|
inherited_style: Option<&ComputedValues>,
|
|
|
|
raw_data: &RawServoStyleSet,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2016-12-26 05:13:30 +03:00
|
|
|
let element = GeckoElement(element);
|
2017-06-24 09:58:16 +03:00
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2016-05-04 13:42:23 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
debug!(
|
|
|
|
"Servo_ResolvePseudoStyle: {:?} {:?}, is_probe: {}",
|
|
|
|
element,
|
|
|
|
PseudoElement::from_pseudo_type(pseudo_type),
|
|
|
|
is_probe
|
|
|
|
);
|
2017-06-23 03:46:55 +03:00
|
|
|
|
2017-09-28 23:17:21 +03:00
|
|
|
let data = element.borrow_data();
|
|
|
|
|
|
|
|
let data = match data.as_ref() {
|
|
|
|
Some(data) if data.has_styles() => data,
|
|
|
|
_ => {
|
|
|
|
// FIXME(bholley, emilio): Assert against this.
|
|
|
|
//
|
|
|
|
// Known offender is nsMathMLmoFrame::MarkIntrinsicISizesDirty,
|
|
|
|
// which goes and does a bunch of work involving style resolution.
|
|
|
|
//
|
|
|
|
// Bug 1403865 tracks fixing it, and potentially adding an assert
|
|
|
|
// here instead.
|
|
|
|
warn!("Calling Servo_ResolvePseudoStyle on unstyled element");
|
|
|
|
return if is_probe {
|
|
|
|
Strong::null()
|
|
|
|
} else {
|
|
|
|
doc_data.default_computed_values().clone().into()
|
|
|
|
};
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-09-28 23:17:21 +03:00
|
|
|
};
|
2016-05-04 13:42:23 +03:00
|
|
|
|
2017-05-16 04:46:42 +03:00
|
|
|
let pseudo = PseudoElement::from_pseudo_type(pseudo_type)
|
2018-11-20 07:37:53 +03:00
|
|
|
.expect("ResolvePseudoStyle with a non-pseudo?");
|
2017-05-16 04:46:42 +03:00
|
|
|
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2017-06-24 09:58:16 +03:00
|
|
|
let style = get_pseudo_style(
|
|
|
|
&guard,
|
|
|
|
element,
|
|
|
|
&pseudo,
|
|
|
|
RuleInclusion::All,
|
|
|
|
&data.styles,
|
2017-07-18 05:44:25 +03:00
|
|
|
inherited_style,
|
2017-06-24 09:58:16 +03:00
|
|
|
&*doc_data,
|
2017-07-18 05:44:25 +03:00
|
|
|
is_probe,
|
2017-10-20 12:18:53 +03:00
|
|
|
/* matching_func = */ None,
|
2017-06-24 09:58:16 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
match style {
|
2017-07-21 21:05:13 +03:00
|
|
|
Some(s) => s.into(),
|
2017-06-24 09:58:16 +03:00
|
|
|
None => {
|
|
|
|
debug_assert!(is_probe);
|
|
|
|
Strong::null()
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2016-12-26 05:13:30 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-04 13:42:23 +03:00
|
|
|
|
2017-10-20 12:18:53 +03:00
|
|
|
fn debug_atom_array(atoms: &AtomArray) -> String {
|
|
|
|
let mut result = String::from("[");
|
|
|
|
for atom in atoms.iter() {
|
|
|
|
if atom.mRawPtr.is_null() {
|
|
|
|
result += "(null), ";
|
|
|
|
} else {
|
|
|
|
let atom = unsafe { WeakAtom::new(atom.mRawPtr) };
|
|
|
|
write!(result, "{}, ", atom).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.push(']');
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_ComputedValues_ResolveXULTreePseudoStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
2017-10-20 12:18:53 +03:00
|
|
|
pseudo_tag: *mut nsAtom,
|
2019-03-21 20:00:27 +03:00
|
|
|
inherited_style: &ComputedValues,
|
2019-11-27 23:57:51 +03:00
|
|
|
input_word: &AtomArray,
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2017-10-20 12:18:53 +03:00
|
|
|
let element = GeckoElement(element);
|
2018-11-20 07:37:53 +03:00
|
|
|
let data = element
|
|
|
|
.borrow_data()
|
2017-10-20 12:18:53 +03:00
|
|
|
.expect("Calling ResolveXULTreePseudoStyle on unstyled element?");
|
|
|
|
|
|
|
|
let pseudo = unsafe {
|
|
|
|
Atom::with(pseudo_tag, |atom| {
|
|
|
|
PseudoElement::from_tree_pseudo_atom(atom, Box::new([]))
|
2018-11-20 07:37:53 +03:00
|
|
|
})
|
|
|
|
.expect("ResolveXULTreePseudoStyle with a non-tree pseudo?")
|
2017-10-20 12:18:53 +03:00
|
|
|
};
|
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
debug!(
|
|
|
|
"ResolveXULTreePseudoStyle: {:?} {:?} {}",
|
|
|
|
element,
|
|
|
|
pseudo,
|
|
|
|
debug_atom_array(input_word)
|
|
|
|
);
|
2017-10-20 12:18:53 +03:00
|
|
|
|
|
|
|
let matching_fn = |pseudo: &PseudoElement| {
|
2018-11-20 07:37:53 +03:00
|
|
|
let args = pseudo
|
|
|
|
.tree_pseudo_args()
|
|
|
|
.expect("Not a tree pseudo-element?");
|
|
|
|
args.iter()
|
|
|
|
.all(|atom| input_word.iter().any(|item| atom.as_ptr() == item.mRawPtr))
|
2017-10-20 12:18:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
get_pseudo_style(
|
|
|
|
&guard,
|
|
|
|
element,
|
|
|
|
&pseudo,
|
|
|
|
RuleInclusion::All,
|
|
|
|
&data.styles,
|
|
|
|
Some(inherited_style),
|
|
|
|
&*doc_data,
|
|
|
|
/* is_probe = */ false,
|
|
|
|
Some(&matching_fn),
|
2018-11-20 07:37:53 +03:00
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.into()
|
2017-10-20 12:18:53 +03:00
|
|
|
}
|
|
|
|
|
2017-06-27 20:27:49 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_SetExplicitStyle(element: &RawGeckoElement, style: &ComputedValues) {
|
2017-06-27 20:27:49 +03:00
|
|
|
let element = GeckoElement(element);
|
|
|
|
debug!("Servo_SetExplicitStyle: {:?}", element);
|
|
|
|
// We only support this API for initial styling. There's no reason it couldn't
|
|
|
|
// work for other things, we just haven't had a reason to do so.
|
|
|
|
debug_assert!(element.get_data().is_none());
|
2017-07-15 17:44:08 +03:00
|
|
|
let mut data = unsafe { element.ensure_data() };
|
2017-07-21 21:05:13 +03:00
|
|
|
data.styles.primary = Some(unsafe { ArcBorrow::from_ref(style) }.clone_arc());
|
2017-06-27 20:27:49 +03:00
|
|
|
}
|
|
|
|
|
2017-05-09 21:21:29 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_HasAuthorSpecifiedRules(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
style: &ComputedValues,
|
|
|
|
element: &RawGeckoElement,
|
2018-02-13 18:25:30 +03:00
|
|
|
rule_type_mask: u32,
|
|
|
|
) -> bool {
|
2019-03-07 00:36:12 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2017-05-09 21:21:29 +03:00
|
|
|
let element = GeckoElement(element);
|
2017-05-16 04:46:42 +03:00
|
|
|
|
2017-05-09 21:21:29 +03:00
|
|
|
let guard = (*GLOBAL_STYLE_DATA).shared_lock.read();
|
|
|
|
let guards = StylesheetGuards::same(&guard);
|
|
|
|
|
2019-03-07 00:36:12 +03:00
|
|
|
let pseudo = style.pseudo();
|
|
|
|
let author_colors_allowed = data.stylist.device().use_document_colors();
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
style.rules().has_author_specified_rules(
|
|
|
|
element,
|
|
|
|
pseudo,
|
|
|
|
&guards,
|
|
|
|
rule_type_mask,
|
|
|
|
author_colors_allowed,
|
|
|
|
)
|
2017-05-09 21:21:29 +03:00
|
|
|
}
|
|
|
|
|
2017-06-24 09:58:16 +03:00
|
|
|
fn get_pseudo_style(
|
|
|
|
guard: &SharedRwLockReadGuard,
|
|
|
|
element: GeckoElement,
|
|
|
|
pseudo: &PseudoElement,
|
|
|
|
rule_inclusion: RuleInclusion,
|
|
|
|
styles: &ElementStyles,
|
2017-07-18 19:23:03 +03:00
|
|
|
inherited_styles: Option<&ComputedValues>,
|
2017-06-24 09:58:16 +03:00
|
|
|
doc_data: &PerDocumentStyleDataImpl,
|
|
|
|
is_probe: bool,
|
2019-06-19 00:32:16 +03:00
|
|
|
matching_func: Option<&dyn Fn(&PseudoElement) -> bool>,
|
2017-06-24 09:58:16 +03:00
|
|
|
) -> Option<Arc<ComputedValues>> {
|
|
|
|
let style = match pseudo.cascade_type() {
|
2017-06-27 09:46:13 +03:00
|
|
|
PseudoElementCascadeType::Eager => {
|
|
|
|
match *pseudo {
|
|
|
|
PseudoElement::FirstLetter => {
|
servo: Merge #19842 - style: Cleanup a bit the cascade (from emilio:cascade-cleanup); r=nox,jryans
This makes an element available in StyleAdjuster, and uses it to replace some of our CascadeFlags (the ones that don't represent restrictions on what's actually cascaded, actually).
That fixes handwaviness in the handling of those flags from style reparenting,
and code duplication to handle tricky stuff like :visited.
There are a number of other changes that are worth noticing:
* skip_root_and_item_based_display_fixup is renamed to skip_item_display_fixup:
TElement::is_root() already implies being the document element, which by
definition is not native anonymous and not a pseudo-element.
Thus, you never get fixed-up if your NAC or a pseudo, which is what the code
tried to avoid, so the only fixup with a point is the item one, which is
necessary.
* The pseudo-element probing code was refactored to return early a
Option::<CascadeInputs>::None, which is nicer than what it was doing.
* The visited_links_enabled check has moved to selector-matching time. The rest
of the checks aren't based on whether the element is a link, or are properly
guarded by parent_style.visited_style().is_some() or visited_rules.is_some().
Thus you can transitively infer that no element will end up with a :visited
style, not even from style reparenting.
Anyway, the underlying reason why I want the element in StyleAdjuster is because
we're going to implement an adjustment in there depending on the tag of the
element (converting display: contents to display: none depending on the tag), so
computing that information eagerly, including a hash lookup, wouldn't be nice.
See each commit for details.
Source-Repo: https://github.com/servo/servo
Source-Revision: 02331617b9bd7a379b05f7daa7ad09a44c27504c
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : dceeca4961762c9f7414007c83ceed03e00c720b
2018-01-23 15:30:51 +03:00
|
|
|
styles.pseudos.get(&pseudo).map(|pseudo_styles| {
|
2017-07-08 02:11:50 +03:00
|
|
|
// inherited_styles can be None when doing lazy resolution
|
|
|
|
// (e.g. for computed style) or when probing. In that case
|
|
|
|
// we just inherit from our element, which is what Gecko
|
|
|
|
// does in that situation. What should actually happen in
|
|
|
|
// the computed style case is a bit unclear.
|
2018-11-20 07:37:53 +03:00
|
|
|
let inherited_styles = inherited_styles.unwrap_or(styles.primary());
|
2017-07-08 02:11:50 +03:00
|
|
|
let guards = StylesheetGuards::same(guard);
|
|
|
|
let metrics = get_metrics_provider_for_product();
|
|
|
|
let inputs = CascadeInputs::new_from_style(pseudo_styles);
|
servo: Merge #19842 - style: Cleanup a bit the cascade (from emilio:cascade-cleanup); r=nox,jryans
This makes an element available in StyleAdjuster, and uses it to replace some of our CascadeFlags (the ones that don't represent restrictions on what's actually cascaded, actually).
That fixes handwaviness in the handling of those flags from style reparenting,
and code duplication to handle tricky stuff like :visited.
There are a number of other changes that are worth noticing:
* skip_root_and_item_based_display_fixup is renamed to skip_item_display_fixup:
TElement::is_root() already implies being the document element, which by
definition is not native anonymous and not a pseudo-element.
Thus, you never get fixed-up if your NAC or a pseudo, which is what the code
tried to avoid, so the only fixup with a point is the item one, which is
necessary.
* The pseudo-element probing code was refactored to return early a
Option::<CascadeInputs>::None, which is nicer than what it was doing.
* The visited_links_enabled check has moved to selector-matching time. The rest
of the checks aren't based on whether the element is a link, or are properly
guarded by parent_style.visited_style().is_some() or visited_rules.is_some().
Thus you can transitively infer that no element will end up with a :visited
style, not even from style reparenting.
Anyway, the underlying reason why I want the element in StyleAdjuster is because
we're going to implement an adjustment in there depending on the tag of the
element (converting display: contents to display: none depending on the tag), so
computing that information eagerly, including a hash lookup, wouldn't be nice.
See each commit for details.
Source-Repo: https://github.com/servo/servo
Source-Revision: 02331617b9bd7a379b05f7daa7ad09a44c27504c
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : dceeca4961762c9f7414007c83ceed03e00c720b
2018-01-23 15:30:51 +03:00
|
|
|
doc_data.stylist.compute_pseudo_element_style_with_inputs(
|
|
|
|
inputs,
|
|
|
|
pseudo,
|
|
|
|
&guards,
|
|
|
|
Some(inherited_styles),
|
|
|
|
&metrics,
|
|
|
|
Some(element),
|
|
|
|
)
|
2017-07-08 02:11:50 +03:00
|
|
|
})
|
2017-06-27 09:46:13 +03:00
|
|
|
},
|
|
|
|
_ => {
|
2017-07-29 06:51:20 +03:00
|
|
|
// Unfortunately, we can't assert that inherited_styles, if
|
|
|
|
// present, is pointer-equal to styles.primary(), or even
|
|
|
|
// equal in any meaningful way. The way it can fail is as
|
|
|
|
// follows. Say we append an element with a ::before,
|
|
|
|
// ::after, or ::first-line to a parent with a ::first-line,
|
|
|
|
// such that the element ends up on the first line of the
|
|
|
|
// parent (e.g. it's an inline-block in the case it has a
|
|
|
|
// ::first-line, or any container in the ::before/::after
|
|
|
|
// cases). Then gecko will update its frame's style to
|
|
|
|
// inherit from the parent's ::first-line. The next time we
|
|
|
|
// try to get the ::before/::after/::first-line style for
|
|
|
|
// the kid, we'll likely pass in the frame's style as
|
|
|
|
// inherited_styles, but that's not pointer-identical to
|
|
|
|
// styles.primary(), because it got reparented.
|
|
|
|
//
|
|
|
|
// Now in practice this turns out to be OK, because all the
|
|
|
|
// cases in which there's a mismatch go ahead and reparent
|
|
|
|
// styles again as needed to make sure the ::first-line
|
|
|
|
// affects all the things it should affect. But it makes it
|
|
|
|
// impossible to assert anything about the two styles
|
|
|
|
// matching here, unfortunately.
|
2017-06-27 09:46:13 +03:00
|
|
|
styles.pseudos.get(&pseudo).cloned()
|
|
|
|
},
|
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2016-12-26 05:13:30 +03:00
|
|
|
PseudoElementCascadeType::Precomputed => unreachable!("No anonymous boxes"),
|
2016-05-04 13:42:23 +03:00
|
|
|
PseudoElementCascadeType::Lazy => {
|
2018-11-20 07:37:53 +03:00
|
|
|
debug_assert!(
|
|
|
|
inherited_styles.is_none() ||
|
|
|
|
ptr::eq(inherited_styles.unwrap(), &**styles.primary())
|
|
|
|
);
|
2017-05-23 10:25:07 +03:00
|
|
|
let base = if pseudo.inherits_from_default_values() {
|
2017-06-14 12:00:07 +03:00
|
|
|
doc_data.default_computed_values()
|
2017-05-23 10:25:07 +03:00
|
|
|
} else {
|
2017-06-23 03:46:55 +03:00
|
|
|
styles.primary()
|
2017-05-23 10:25:07 +03:00
|
|
|
};
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let guards = StylesheetGuards::same(guard);
|
2017-04-09 14:15:51 +03:00
|
|
|
let metrics = get_metrics_provider_for_product();
|
2018-01-10 08:34:15 +03:00
|
|
|
doc_data.stylist.lazily_compute_pseudo_element_style(
|
|
|
|
&guards,
|
|
|
|
element,
|
|
|
|
&pseudo,
|
|
|
|
rule_inclusion,
|
|
|
|
base,
|
|
|
|
is_probe,
|
|
|
|
&metrics,
|
|
|
|
matching_func,
|
|
|
|
)
|
2016-12-26 05:13:30 +03:00
|
|
|
},
|
2017-06-24 09:58:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if is_probe {
|
|
|
|
return style;
|
2016-05-04 13:42:23 +03:00
|
|
|
}
|
2017-06-24 09:58:16 +03:00
|
|
|
|
|
|
|
Some(style.unwrap_or_else(|| {
|
2017-07-18 05:44:25 +03:00
|
|
|
StyleBuilder::for_inheritance(
|
2017-07-18 19:23:03 +03:00
|
|
|
doc_data.stylist.device(),
|
2018-02-03 20:24:23 +03:00
|
|
|
Some(styles.primary()),
|
2017-07-18 19:23:03 +03:00
|
|
|
Some(pseudo),
|
2018-11-20 07:37:53 +03:00
|
|
|
)
|
|
|
|
.build()
|
2017-06-24 09:58:16 +03:00
|
|
|
}))
|
2016-05-04 13:42:23 +03:00
|
|
|
}
|
|
|
|
|
2016-05-06 14:30:47 +03:00
|
|
|
#[no_mangle]
|
2018-03-19 13:11:14 +03:00
|
|
|
pub unsafe extern "C" fn Servo_ComputedValues_Inherit(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2019-02-19 16:44:33 +03:00
|
|
|
pseudo: PseudoStyleType,
|
2019-03-21 20:00:27 +03:00
|
|
|
parent_style_context: Option<&ComputedValues>,
|
2018-11-20 07:37:53 +03:00
|
|
|
target: structs::InheritTarget,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2017-01-05 08:01:38 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2017-04-28 18:25:21 +03:00
|
|
|
|
|
|
|
let for_text = target == structs::InheritTarget::Text;
|
2019-02-19 16:44:33 +03:00
|
|
|
let pseudo = PseudoElement::from_pseudo_type(pseudo).unwrap();
|
|
|
|
debug_assert!(pseudo.is_anon_box());
|
2017-07-18 19:23:03 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut style =
|
|
|
|
StyleBuilder::for_inheritance(data.stylist.device(), parent_style_context, Some(&pseudo));
|
2017-04-28 18:25:21 +03:00
|
|
|
|
2018-02-03 20:24:23 +03:00
|
|
|
if for_text {
|
|
|
|
StyleAdjuster::new(&mut style).adjust_for_text();
|
|
|
|
}
|
2017-07-18 05:44:25 +03:00
|
|
|
|
2018-02-03 20:24:23 +03:00
|
|
|
style.build().into()
|
2017-05-25 03:53:48 +03:00
|
|
|
}
|
|
|
|
|
2017-06-27 20:27:49 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_SpecifiesAnimationsOrTransitions(
|
2019-03-21 20:00:27 +03:00
|
|
|
values: &ComputedValues,
|
2018-02-13 18:25:30 +03:00
|
|
|
) -> bool {
|
2017-06-27 20:27:49 +03:00
|
|
|
let b = values.get_box();
|
|
|
|
b.specifies_animations() || b.specifies_transitions()
|
|
|
|
}
|
|
|
|
|
2017-07-10 06:07:41 +03:00
|
|
|
#[no_mangle]
|
2018-01-17 22:55:03 +03:00
|
|
|
pub extern "C" fn Servo_ComputedValues_GetStyleRuleList(
|
2019-03-21 20:00:27 +03:00
|
|
|
values: &ComputedValues,
|
|
|
|
rules: &mut nsTArray<*const RawServoStyleRule>,
|
2018-01-17 22:55:03 +03:00
|
|
|
) {
|
2017-08-08 11:21:54 +03:00
|
|
|
let rule_node = match values.rules {
|
|
|
|
Some(ref r) => r,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
2017-09-29 18:01:52 +03:00
|
|
|
let mut result = SmallVec::<[_; 10]>::new();
|
2017-08-08 11:21:54 +03:00
|
|
|
for node in rule_node.self_and_ancestors() {
|
2018-04-21 02:28:33 +03:00
|
|
|
let style_rule = match node.style_source().and_then(|x| x.as_rule()) {
|
|
|
|
Some(rule) => rule,
|
2017-08-08 11:21:54 +03:00
|
|
|
_ => continue,
|
|
|
|
};
|
|
|
|
|
2017-09-01 12:15:21 +03:00
|
|
|
// For the rules with any important declaration, we insert them into
|
|
|
|
// rule tree twice, one for normal level and another for important
|
|
|
|
// level. So, we skip the important one to keep the specificity order of
|
|
|
|
// rules.
|
2017-08-08 11:21:54 +03:00
|
|
|
if node.importance().important() {
|
2017-09-01 12:15:21 +03:00
|
|
|
continue;
|
2017-07-10 06:07:41 +03:00
|
|
|
}
|
2017-08-08 11:21:54 +03:00
|
|
|
|
|
|
|
result.push(style_rule);
|
|
|
|
}
|
|
|
|
|
2018-10-09 11:49:51 +03:00
|
|
|
rules.assign_from_iter_pod(result.into_iter().map(|src| {
|
2018-04-21 02:28:33 +03:00
|
|
|
src.with_arc(|a| {
|
2018-11-20 07:37:53 +03:00
|
|
|
a.with_raw_offset_arc(|arc| *Locked::<StyleRule>::arc_as_borrowed(arc) as *const _)
|
2018-10-09 11:49:51 +03:00
|
|
|
})
|
|
|
|
}))
|
2017-07-10 06:07:41 +03:00
|
|
|
}
|
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
/// println_stderr!() calls Gecko's printf_stderr(), which, unlike eprintln!(),
|
|
|
|
/// will funnel output to Android logcat.
|
|
|
|
#[cfg(feature = "gecko_debug")]
|
|
|
|
macro_rules! println_stderr {
|
|
|
|
($($e:expr),+) => {
|
|
|
|
{
|
|
|
|
let mut s = nsCString::new();
|
|
|
|
write!(s, $($e),+).unwrap();
|
|
|
|
s.write_char('\n').unwrap();
|
|
|
|
unsafe { bindings::Gecko_PrintfStderr(&s); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "gecko_debug")]
|
|
|
|
fn dump_properties_and_rules(cv: &ComputedValues, properties: &LonghandIdSet) {
|
|
|
|
println_stderr!(" Properties:");
|
|
|
|
for p in properties.iter() {
|
|
|
|
let mut v = String::new();
|
2019-08-26 12:58:53 +03:00
|
|
|
cv.get_longhand_property_value(p, &mut CssWriter::new(&mut v))
|
|
|
|
.unwrap();
|
2019-06-27 10:22:22 +03:00
|
|
|
println_stderr!(" {:?}: {}", p, v);
|
|
|
|
}
|
|
|
|
println_stderr!(" Rules:");
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
for rn in cv.rules().self_and_ancestors() {
|
|
|
|
if rn.importance().important() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if let Some(d) = rn.style_source().and_then(|s| s.as_declarations()) {
|
|
|
|
println_stderr!(" [DeclarationBlock: {:?}]", d);
|
|
|
|
}
|
|
|
|
if let Some(r) = rn.style_source().and_then(|s| s.as_rule()) {
|
|
|
|
let mut s = nsString::new();
|
|
|
|
r.read_with(&guard).to_css(&guard, &mut s).unwrap();
|
|
|
|
println_stderr!(" {}", s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "gecko_debug")]
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_ComputedValues_EqualForCachedAnonymousContentStyle(
|
|
|
|
a: &ComputedValues,
|
|
|
|
b: &ComputedValues,
|
|
|
|
) -> bool {
|
|
|
|
let mut differing_properties = a.differing_properties(b);
|
|
|
|
|
|
|
|
// Ignore any difference in -x-lang, which we can't override in the
|
|
|
|
// rules in minimal-xul.css, but which makes no difference for the
|
|
|
|
// anonymous content subtrees we cache style for.
|
|
|
|
differing_properties.remove(LonghandId::XLang);
|
|
|
|
|
2019-07-11 01:43:24 +03:00
|
|
|
// Ignore any difference in pref-controlled, inherited properties. These
|
|
|
|
// properties may or may not be set by the 'all' declaration in the
|
|
|
|
// minimal-xul.css rule, depending on whether the pref was enabled at the
|
|
|
|
// time the UA sheets were parsed.
|
|
|
|
//
|
|
|
|
// If you add a new pref-controlled, inherited property, it must be defined
|
|
|
|
// with `has_effect_on_gecko_scrollbars=False` to declare that
|
|
|
|
// different values of this property on a <scrollbar> element or its
|
|
|
|
// descendant scrollbar part elements should have no effect on their
|
|
|
|
// rendering and behavior.
|
|
|
|
//
|
|
|
|
// If you do need a pref-controlled, inherited property to have an effect
|
|
|
|
// on these elements, then you will need to add some checks to the
|
|
|
|
// nsIAnonymousContentCreator::CreateAnonymousContent implementations of
|
|
|
|
// ScrollFrameHelper and nsScrollbarFrame to clear the AnonymousContentKey
|
|
|
|
// if a non-initial value is used.
|
|
|
|
differing_properties.remove_all(&LonghandIdSet::has_no_effect_on_gecko_scrollbars());
|
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
if !differing_properties.is_empty() {
|
|
|
|
println_stderr!("Actual style:");
|
|
|
|
dump_properties_and_rules(a, &differing_properties);
|
|
|
|
println_stderr!("Expected style:");
|
|
|
|
dump_properties_and_rules(b, &differing_properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
differing_properties.is_empty()
|
|
|
|
}
|
|
|
|
|
2019-04-03 10:02:00 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSet_Init(doc: &structs::Document) -> *mut RawServoStyleSet {
|
2019-03-07 00:36:12 +03:00
|
|
|
let data = Box::new(PerDocumentStyleData::new(doc));
|
2017-08-16 06:11:50 +03:00
|
|
|
Box::into_raw(data) as *mut RawServoStyleSet
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
|
|
|
|
2017-01-05 08:01:38 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_RebuildCachedData(raw_data: &RawServoStyleSet) {
|
2017-01-05 08:01:38 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2017-08-03 17:36:21 +03:00
|
|
|
data.stylist.device_mut().rebuild_cached_data();
|
2017-01-05 08:01:38 +03:00
|
|
|
}
|
|
|
|
|
2016-02-04 20:55:09 +03:00
|
|
|
#[no_mangle]
|
2019-03-30 23:18:33 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_Drop(data: *mut RawServoStyleSet) {
|
|
|
|
PerDocumentStyleData::drop_ffi(data);
|
2016-02-04 20:55:09 +03:00
|
|
|
}
|
2016-06-24 05:46:25 +03:00
|
|
|
|
2017-06-10 22:25:59 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_CompatModeChanged(raw_data: &RawServoStyleSet) {
|
2017-06-10 22:25:59 +03:00
|
|
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2019-03-07 00:36:12 +03:00
|
|
|
let quirks_mode = data.stylist.device().document().mCompatMode;
|
|
|
|
data.stylist.set_quirks_mode(quirks_mode.into());
|
2017-06-10 22:25:59 +03:00
|
|
|
}
|
|
|
|
|
2018-06-20 22:07:45 +03:00
|
|
|
fn parse_property_into(
|
2017-10-13 22:11:02 +03:00
|
|
|
declarations: &mut SourcePropertyDeclaration,
|
|
|
|
property_id: PropertyId,
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2017-10-13 22:11:02 +03:00
|
|
|
data: *mut URLExtraData,
|
|
|
|
parsing_mode: structs::ParsingMode,
|
|
|
|
quirks_mode: QuirksMode,
|
2019-06-19 00:32:16 +03:00
|
|
|
reporter: Option<&dyn ParseErrorReporter>,
|
2018-06-20 22:07:45 +03:00
|
|
|
) -> Result<(), ()> {
|
2019-11-27 23:57:51 +03:00
|
|
|
let value = unsafe { value.as_str_unchecked() };
|
2018-06-21 14:09:35 +03:00
|
|
|
let url_data = unsafe { UrlExtraData::from_ptr_ref(&data) };
|
2017-05-14 02:53:07 +03:00
|
|
|
let parsing_mode = ParsingMode::from_bits_truncate(parsing_mode);
|
2017-05-11 05:25:47 +03:00
|
|
|
|
2017-05-20 02:37:14 +03:00
|
|
|
parse_one_declaration_into(
|
|
|
|
declarations,
|
|
|
|
property_id,
|
|
|
|
value,
|
|
|
|
url_data,
|
2017-07-11 04:13:44 +03:00
|
|
|
reporter,
|
2017-05-20 02:37:14 +03:00
|
|
|
parsing_mode,
|
2017-11-21 16:47:52 +03:00
|
|
|
quirks_mode,
|
|
|
|
)
|
2017-05-11 05:25:47 +03:00
|
|
|
}
|
|
|
|
|
2016-10-09 16:53:28 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_ParseProperty(
|
2018-11-20 07:37:53 +03:00
|
|
|
property: nsCSSPropertyID,
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2017-10-13 22:11:02 +03:00
|
|
|
data: *mut URLExtraData,
|
|
|
|
parsing_mode: structs::ParsingMode,
|
|
|
|
quirks_mode: nsCompatibility,
|
|
|
|
loader: *mut Loader,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoDeclarationBlock> {
|
2019-08-26 12:58:53 +03:00
|
|
|
let id = get_property_id_from_nscsspropertyid!(property, Strong::null());
|
2017-05-20 02:37:14 +03:00
|
|
|
let mut declarations = SourcePropertyDeclaration::new();
|
2017-07-11 04:13:44 +03:00
|
|
|
let reporter = ErrorReporter::new(ptr::null_mut(), loader, data);
|
2018-06-20 22:07:45 +03:00
|
|
|
let result = parse_property_into(
|
|
|
|
&mut declarations,
|
|
|
|
id,
|
|
|
|
value,
|
|
|
|
data,
|
|
|
|
parsing_mode,
|
|
|
|
quirks_mode.into(),
|
2019-06-19 00:32:16 +03:00
|
|
|
reporter.as_ref().map(|r| r as &dyn ParseErrorReporter),
|
2018-06-20 22:07:45 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
match result {
|
2017-05-20 02:37:14 +03:00
|
|
|
Ok(()) => {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2017-03-08 14:07:04 +03:00
|
|
|
let mut block = PropertyDeclarationBlock::new();
|
2018-11-20 07:37:53 +03:00
|
|
|
block.extend(declarations.drain(), Importance::Normal);
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
Arc::new(global_style_data.shared_lock.wrap(block)).into_strong()
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2019-03-21 20:00:27 +03:00
|
|
|
Err(_) => Strong::null(),
|
2016-10-09 16:53:28 +03:00
|
|
|
}
|
|
|
|
}
|
2016-10-18 08:51:14 +03:00
|
|
|
|
2017-03-21 11:36:49 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_ParseEasing(
|
2020-01-07 12:47:20 +03:00
|
|
|
easing: &nsAString,
|
2017-10-13 22:11:02 +03:00
|
|
|
data: *mut URLExtraData,
|
2019-03-21 20:00:27 +03:00
|
|
|
output: &mut nsTimingFunction,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2017-03-21 11:36:49 +03:00
|
|
|
use style::properties::longhands::transition_timing_function;
|
|
|
|
|
2017-10-17 09:11:39 +03:00
|
|
|
// FIXME Dummy URL data would work fine here.
|
2018-06-21 14:09:35 +03:00
|
|
|
let url_data = unsafe { UrlExtraData::from_ptr_ref(&data) };
|
2017-11-27 17:41:46 +03:00
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Style),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-11-27 17:41:46 +03:00
|
|
|
);
|
2020-01-07 12:47:20 +03:00
|
|
|
let easing = easing.to_string();
|
2017-06-10 00:31:48 +03:00
|
|
|
let mut input = ParserInput::new(&easing);
|
2017-06-16 16:09:52 +03:00
|
|
|
let mut parser = Parser::new(&mut input);
|
2017-08-11 03:48:34 +03:00
|
|
|
let result =
|
|
|
|
parser.parse_entirely(|p| transition_timing_function::single_value::parse(&context, p));
|
2017-06-16 16:09:52 +03:00
|
|
|
match result {
|
2017-03-21 11:36:49 +03:00
|
|
|
Ok(parsed_easing) => {
|
2018-10-26 21:03:35 +03:00
|
|
|
// We store as computed value in nsTimingFunction.
|
|
|
|
(*output).mTiming = parsed_easing.to_computed_value_without_context();
|
2017-03-21 11:36:49 +03:00
|
|
|
true
|
|
|
|
},
|
2018-11-20 07:37:53 +03:00
|
|
|
Err(_) => false,
|
2017-03-21 11:36:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 00:33:56 +03:00
|
|
|
#[no_mangle]
|
2020-01-05 17:42:23 +03:00
|
|
|
pub extern "C" fn Servo_SerializeEasing(easing: &nsTimingFunction, output: &mut nsAString) {
|
|
|
|
easing.mTiming.to_css(&mut CssWriter::new(output)).unwrap();
|
2019-02-24 21:47:53 +03:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:24:21 +03:00
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_GetProperties_Overriding_Animation(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
|
|
|
list: &nsTArray<nsCSSPropertyID>,
|
|
|
|
set: &mut structs::nsCSSPropertyIDSet,
|
2018-02-13 18:25:30 +03:00
|
|
|
) {
|
2017-05-20 15:24:21 +03:00
|
|
|
let element = GeckoElement(element);
|
|
|
|
let element_data = match element.borrow_data() {
|
|
|
|
Some(data) => data,
|
2018-11-20 07:37:53 +03:00
|
|
|
None => return,
|
2017-05-20 15:24:21 +03:00
|
|
|
};
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let guards = StylesheetGuards::same(&guard);
|
2018-11-20 07:37:53 +03:00
|
|
|
let (overridden, custom) = element_data
|
|
|
|
.styles
|
|
|
|
.primary()
|
|
|
|
.rules()
|
|
|
|
.get_properties_overriding_animations(&guards);
|
2017-05-20 15:24:21 +03:00
|
|
|
for p in list.iter() {
|
|
|
|
match PropertyId::from_nscsspropertyid(*p) {
|
|
|
|
Ok(property) => {
|
|
|
|
if let PropertyId::Longhand(id) = property {
|
|
|
|
if overridden.contains(id) {
|
|
|
|
unsafe { Gecko_AddPropertyToSet(set, *p) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(_) => {
|
|
|
|
if *p == nsCSSPropertyID::eCSSPropertyExtra_variable && custom {
|
|
|
|
unsafe { Gecko_AddPropertyToSet(set, *p) };
|
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-05-20 15:24:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 09:54:41 +03:00
|
|
|
#[no_mangle]
|
2018-11-20 07:37:53 +03:00
|
|
|
pub extern "C" fn Servo_MatrixTransform_Operate(
|
|
|
|
matrix_operator: MatrixTransformOperator,
|
2019-03-21 20:00:27 +03:00
|
|
|
from: *const structs::Matrix4x4Components,
|
|
|
|
to: *const structs::Matrix4x4Components,
|
2018-11-20 07:37:53 +03:00
|
|
|
progress: f64,
|
2019-03-21 20:00:27 +03:00
|
|
|
output: *mut structs::Matrix4x4Components,
|
2018-11-20 07:37:53 +03:00
|
|
|
) {
|
2017-06-07 09:54:41 +03:00
|
|
|
use self::MatrixTransformOperator::{Accumulate, Interpolate};
|
2017-11-03 01:02:07 +03:00
|
|
|
use style::values::computed::transform::Matrix3D;
|
2017-06-07 09:54:41 +03:00
|
|
|
|
2017-11-03 01:02:07 +03:00
|
|
|
let from = Matrix3D::from(unsafe { from.as_ref() }.expect("not a valid 'from' matrix"));
|
|
|
|
let to = Matrix3D::from(unsafe { to.as_ref() }.expect("not a valid 'to' matrix"));
|
2017-06-07 09:54:41 +03:00
|
|
|
let result = match matrix_operator {
|
2017-08-22 15:22:10 +03:00
|
|
|
Interpolate => from.animate(&to, Procedure::Interpolate { progress }),
|
2018-11-20 07:37:53 +03:00
|
|
|
Accumulate => from.animate(
|
|
|
|
&to,
|
|
|
|
Procedure::Accumulate {
|
|
|
|
count: progress as u64,
|
|
|
|
},
|
|
|
|
),
|
2017-06-07 09:54:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let output = unsafe { output.as_mut() }.expect("not a valid 'output' matrix");
|
servo: Merge #18591 - stylo: do not handle the fallback discrete animation inside the Animate trait (from chenpighead:stylo-singular-matrix-animation); r=BorisChiou
At present, we do the fallback discrete animation for non-invertible matrices in
ComputedMatrix.animate(). However, according to the spec, we should fallback to
discrete animation for cases like:
1. animation between transform with single non-invertible matrix
2. animation between transform with matched transform functions that have at least
one non-invertible matrix
2. animation between transform with mismatched transform functions that have at
least one non-invertible matrix.
The current implementation only handles the first case.
Moreover, we already have fallback discrete animation procedures in CSS Animation
and Web Animation, so we should be able to not doing any fallback inside the
Animate trait.
In this patch, we let the animation between non-invertible matrices to return Err().
So, we can propagate the Err() to the callers, and let the fallback discrete
animation procedure stay at the Servo_MatrixTransform_Operate, which is ouside
the Animate trait.
Gecko bug: [Bug 1394284](https://bugzilla.mozilla.org/show_bug.cgi?id=1394284)
---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix [Bug 1394284](https://bugzilla.mozilla.org/show_bug.cgi?id=1394284)
- [X] There are wpt tests for these changes, and thet will be landed in [Bug 1394284](https://bugzilla.mozilla.org/show_bug.cgi?id=1394284)
Source-Repo: https://github.com/servo/servo
Source-Revision: ce7cee75e4c0c8357b489be42589d96348870627
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 830ee041c599c8dee799d36732e16f7e8b2fcd34
2017-09-21 11:16:58 +03:00
|
|
|
if let Ok(result) = result {
|
2017-06-07 09:54:41 +03:00
|
|
|
*output = result.into();
|
servo: Merge #18591 - stylo: do not handle the fallback discrete animation inside the Animate trait (from chenpighead:stylo-singular-matrix-animation); r=BorisChiou
At present, we do the fallback discrete animation for non-invertible matrices in
ComputedMatrix.animate(). However, according to the spec, we should fallback to
discrete animation for cases like:
1. animation between transform with single non-invertible matrix
2. animation between transform with matched transform functions that have at least
one non-invertible matrix
2. animation between transform with mismatched transform functions that have at
least one non-invertible matrix.
The current implementation only handles the first case.
Moreover, we already have fallback discrete animation procedures in CSS Animation
and Web Animation, so we should be able to not doing any fallback inside the
Animate trait.
In this patch, we let the animation between non-invertible matrices to return Err().
So, we can propagate the Err() to the callers, and let the fallback discrete
animation procedure stay at the Servo_MatrixTransform_Operate, which is ouside
the Animate trait.
Gecko bug: [Bug 1394284](https://bugzilla.mozilla.org/show_bug.cgi?id=1394284)
---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix [Bug 1394284](https://bugzilla.mozilla.org/show_bug.cgi?id=1394284)
- [X] There are wpt tests for these changes, and thet will be landed in [Bug 1394284](https://bugzilla.mozilla.org/show_bug.cgi?id=1394284)
Source-Repo: https://github.com/servo/servo
Source-Revision: ce7cee75e4c0c8357b489be42589d96348870627
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 830ee041c599c8dee799d36732e16f7e8b2fcd34
2017-09-21 11:16:58 +03:00
|
|
|
} else if progress < 0.5 {
|
|
|
|
*output = from.clone().into();
|
|
|
|
} else {
|
|
|
|
*output = to.clone().into();
|
|
|
|
}
|
2017-06-07 09:54:41 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:46:25 +03:00
|
|
|
#[no_mangle]
|
2018-08-20 20:03:11 +03:00
|
|
|
pub unsafe extern "C" fn Servo_ParseStyleAttribute(
|
2019-11-27 23:57:51 +03:00
|
|
|
data: &nsACString,
|
2017-10-13 22:11:02 +03:00
|
|
|
raw_extra_data: *mut URLExtraData,
|
|
|
|
quirks_mode: nsCompatibility,
|
|
|
|
loader: *mut Loader,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoDeclarationBlock> {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2019-11-27 23:57:51 +03:00
|
|
|
let value = data.as_str_unchecked();
|
2017-07-11 04:13:44 +03:00
|
|
|
let reporter = ErrorReporter::new(ptr::null_mut(), loader, raw_extra_data);
|
2018-08-20 20:03:11 +03:00
|
|
|
let url_data = UrlExtraData::from_ptr_ref(&raw_extra_data);
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(global_style_data.shared_lock.wrap(parse_style_attribute(
|
|
|
|
value,
|
|
|
|
url_data,
|
2019-06-19 00:32:16 +03:00
|
|
|
reporter.as_ref().map(|r| r as &dyn ParseErrorReporter),
|
2018-11-20 07:37:53 +03:00
|
|
|
quirks_mode.into(),
|
|
|
|
)))
|
|
|
|
.into_strong()
|
2016-06-24 05:46:25 +03:00
|
|
|
}
|
|
|
|
|
2016-11-04 07:42:06 +03:00
|
|
|
#[no_mangle]
|
2019-03-26 21:16:01 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_CreateEmpty() -> Strong<RawServoDeclarationBlock> {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(
|
|
|
|
global_style_data
|
|
|
|
.shared_lock
|
|
|
|
.wrap(PropertyDeclarationBlock::new()),
|
|
|
|
)
|
|
|
|
.into_strong()
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_Clone(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoDeclarationBlock> {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(
|
|
|
|
global_style_data
|
|
|
|
.shared_lock
|
|
|
|
.wrap(declarations.read_with(&guard).clone()),
|
|
|
|
)
|
|
|
|
.into_strong()
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
2016-10-09 16:53:28 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_Equals(
|
2019-03-21 20:00:27 +03:00
|
|
|
a: &RawServoDeclarationBlock,
|
|
|
|
b: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2018-11-20 07:37:53 +03:00
|
|
|
*Locked::<PropertyDeclarationBlock>::as_arc(&a)
|
|
|
|
.read_with(&guard)
|
|
|
|
.declarations() ==
|
|
|
|
*Locked::<PropertyDeclarationBlock>::as_arc(&b)
|
|
|
|
.read_with(&guard)
|
|
|
|
.declarations()
|
2016-06-24 05:46:25 +03:00
|
|
|
}
|
2016-07-19 07:25:31 +03:00
|
|
|
|
2016-11-04 07:42:06 +03:00
|
|
|
#[no_mangle]
|
2020-01-05 17:42:23 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_GetCssText(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2018-06-06 01:04:39 +03:00
|
|
|
) {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
2020-01-05 17:42:23 +03:00
|
|
|
decls.to_css(result).unwrap()
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
2016-10-09 16:53:28 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2018-11-20 07:37:53 +03:00
|
|
|
property_id: nsCSSPropertyID,
|
2020-01-05 17:42:23 +03:00
|
|
|
buffer: &mut nsAString,
|
2019-03-21 20:00:27 +03:00
|
|
|
computed_values: Option<&ComputedValues>,
|
|
|
|
custom_properties: Option<&RawServoDeclarationBlock>,
|
2020-01-08 14:55:28 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2016-12-18 05:22:10 +03:00
|
|
|
let property_id = get_property_id_from_nscsspropertyid!(property_id, ());
|
2016-10-18 08:51:14 +03:00
|
|
|
|
2017-09-27 12:35:00 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let decls = Locked::<PropertyDeclarationBlock>::as_arc(&declarations).read_with(&guard);
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let custom_properties =
|
|
|
|
Locked::<PropertyDeclarationBlock>::arc_from_borrowed(&custom_properties);
|
2017-09-27 12:35:00 +03:00
|
|
|
let custom_properties = custom_properties.map(|block| block.read_with(&guard));
|
2020-01-08 14:55:28 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2020-01-08 14:56:25 +03:00
|
|
|
let rv = decls.single_value_to_css(&property_id, buffer, computed_values, custom_properties, &data.stylist.device());
|
2018-01-23 01:58:30 +03:00
|
|
|
debug_assert!(rv.is_ok());
|
2016-10-09 16:53:28 +03:00
|
|
|
}
|
|
|
|
|
2017-05-22 07:22:35 +03:00
|
|
|
#[no_mangle]
|
2018-02-07 00:42:23 +03:00
|
|
|
pub unsafe extern "C" fn Servo_SerializeFontValueForCanvas(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2020-01-05 17:42:23 +03:00
|
|
|
buffer: &mut nsAString,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-05-22 07:22:35 +03:00
|
|
|
use style::properties::shorthands::font;
|
|
|
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
2017-09-11 16:57:07 +03:00
|
|
|
let longhands = match font::LonghandsToSerialize::from_iter(decls.declarations().iter()) {
|
2017-05-22 07:22:35 +03:00
|
|
|
Ok(l) => l,
|
|
|
|
Err(()) => {
|
|
|
|
warn!("Unexpected property!");
|
|
|
|
return;
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-05-22 07:22:35 +03:00
|
|
|
};
|
|
|
|
|
2020-01-05 17:42:23 +03:00
|
|
|
let rv = longhands.to_css(&mut CssWriter::new(buffer));
|
2017-05-22 07:22:35 +03:00
|
|
|
debug_assert!(rv.is_ok());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-04 07:42:06 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_Count(declarations: &RawServoDeclarationBlock) -> u32 {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
|
|
|
decls.declarations().len() as u32
|
|
|
|
})
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
index: u32,
|
2020-01-04 13:36:49 +03:00
|
|
|
result: &mut nsACString,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
2017-09-11 16:57:07 +03:00
|
|
|
if let Some(decl) = decls.declarations().get(index as usize) {
|
2020-01-04 13:36:49 +03:00
|
|
|
result.assign(&decl.id().name());
|
2017-03-22 14:17:09 +03:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
})
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
2016-12-18 05:22:10 +03:00
|
|
|
macro_rules! get_property_id_from_property {
|
|
|
|
($property: ident, $ret: expr) => {{
|
2019-11-27 23:57:51 +03:00
|
|
|
let property = $property.as_str_unchecked();
|
2018-06-01 15:00:57 +03:00
|
|
|
match PropertyId::parse_enabled_for_all_content(property) {
|
2016-12-18 05:22:10 +03:00
|
|
|
Ok(property_id) => property_id,
|
2018-06-01 15:00:57 +03:00
|
|
|
Err(_) => return $ret,
|
2016-12-18 05:22:10 +03:00
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
}};
|
2016-12-18 05:22:10 +03:00
|
|
|
}
|
|
|
|
|
2017-09-07 14:55:02 +03:00
|
|
|
unsafe fn get_property_value(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-09-07 14:55:02 +03:00
|
|
|
property_id: PropertyId,
|
2020-01-05 17:42:23 +03:00
|
|
|
value: &mut nsAString,
|
2017-09-07 14:55:02 +03:00
|
|
|
) {
|
2017-09-06 07:20:55 +03:00
|
|
|
// This callsite is hot enough that the lock acquisition shows up in profiles.
|
|
|
|
// Using an unchecked read here improves our performance by ~10% on the
|
|
|
|
// microbenchmark in bug 1355599.
|
2017-09-07 14:55:02 +03:00
|
|
|
read_locked_arc_unchecked(declarations, |decls: &PropertyDeclarationBlock| {
|
2020-01-05 17:42:23 +03:00
|
|
|
decls.property_value_to_css(&property_id, value).unwrap();
|
2017-09-07 14:55:02 +03:00
|
|
|
})
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-09-07 14:55:02 +03:00
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2019-11-27 23:57:51 +03:00
|
|
|
property: &nsACString,
|
2020-01-05 17:42:23 +03:00
|
|
|
value: &mut nsAString,
|
2017-09-07 14:55:02 +03:00
|
|
|
) {
|
|
|
|
get_property_value(
|
|
|
|
declarations,
|
|
|
|
get_property_id_from_property!(property, ()),
|
|
|
|
value,
|
|
|
|
)
|
2016-12-18 05:22:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-09-07 14:55:02 +03:00
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyValueById(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-09-07 14:55:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
2020-01-05 17:42:23 +03:00
|
|
|
value: &mut nsAString,
|
2017-09-07 14:55:02 +03:00
|
|
|
) {
|
2018-11-20 07:37:53 +03:00
|
|
|
get_property_value(
|
|
|
|
declarations,
|
|
|
|
get_property_id_from_nscsspropertyid!(property, ()),
|
|
|
|
value,
|
|
|
|
)
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-09-07 14:55:02 +03:00
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2019-11-27 23:57:51 +03:00
|
|
|
property: &nsACString,
|
2017-09-07 14:55:02 +03:00
|
|
|
) -> bool {
|
2016-12-18 05:22:10 +03:00
|
|
|
let property_id = get_property_id_from_property!(property, false);
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
|
|
|
decls.property_priority(&property_id).important()
|
|
|
|
})
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
2019-05-20 08:22:39 +03:00
|
|
|
#[inline(always)]
|
|
|
|
fn set_property_to_declarations(
|
|
|
|
block: &RawServoDeclarationBlock,
|
|
|
|
parsed_declarations: &mut SourcePropertyDeclaration,
|
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
|
|
|
importance: Importance,
|
|
|
|
) -> bool {
|
|
|
|
let mut updates = Default::default();
|
|
|
|
let will_change = read_locked_arc(block, |decls: &PropertyDeclarationBlock| {
|
|
|
|
decls.prepare_for_update(&parsed_declarations, importance, &mut updates)
|
|
|
|
});
|
|
|
|
if !will_change {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
before_change_closure.invoke();
|
|
|
|
write_locked_arc(block, |decls: &mut PropertyDeclarationBlock| {
|
|
|
|
decls.update(parsed_declarations.drain(), importance, &mut updates)
|
|
|
|
});
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2017-10-13 22:11:02 +03:00
|
|
|
fn set_property(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property_id: PropertyId,
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2017-10-13 22:11:02 +03:00
|
|
|
is_important: bool,
|
|
|
|
data: *mut URLExtraData,
|
|
|
|
parsing_mode: structs::ParsingMode,
|
|
|
|
quirks_mode: QuirksMode,
|
2018-06-06 01:04:39 +03:00
|
|
|
loader: *mut Loader,
|
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2017-05-20 02:37:14 +03:00
|
|
|
let mut source_declarations = SourcePropertyDeclaration::new();
|
2017-07-11 04:13:44 +03:00
|
|
|
let reporter = ErrorReporter::new(ptr::null_mut(), loader, data);
|
2018-06-06 01:04:39 +03:00
|
|
|
let result = parse_property_into(
|
|
|
|
&mut source_declarations,
|
|
|
|
property_id,
|
|
|
|
value,
|
|
|
|
data,
|
|
|
|
parsing_mode,
|
|
|
|
quirks_mode,
|
2019-06-19 00:32:16 +03:00
|
|
|
reporter.as_ref().map(|r| r as &dyn ParseErrorReporter),
|
2018-06-06 01:04:39 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
if result.is_err() {
|
|
|
|
return false;
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
2018-06-06 01:04:39 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let importance = if is_important {
|
|
|
|
Importance::Important
|
|
|
|
} else {
|
|
|
|
Importance::Normal
|
|
|
|
};
|
2018-07-11 03:54:47 +03:00
|
|
|
|
2019-05-20 08:22:39 +03:00
|
|
|
set_property_to_declarations(
|
|
|
|
declarations,
|
|
|
|
&mut source_declarations,
|
|
|
|
before_change_closure,
|
|
|
|
importance,
|
|
|
|
)
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-09-07 14:55:02 +03:00
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_SetProperty(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2019-11-27 23:57:51 +03:00
|
|
|
property: &nsACString,
|
|
|
|
value: &nsACString,
|
2017-09-07 14:55:02 +03:00
|
|
|
is_important: bool,
|
|
|
|
data: *mut URLExtraData,
|
|
|
|
parsing_mode: structs::ParsingMode,
|
|
|
|
quirks_mode: nsCompatibility,
|
|
|
|
loader: *mut Loader,
|
2018-06-06 01:04:39 +03:00
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
2017-09-07 14:55:02 +03:00
|
|
|
) -> bool {
|
|
|
|
set_property(
|
|
|
|
declarations,
|
|
|
|
get_property_id_from_property!(property, false),
|
|
|
|
value,
|
|
|
|
is_important,
|
|
|
|
data,
|
|
|
|
parsing_mode,
|
|
|
|
quirks_mode.into(),
|
|
|
|
loader,
|
2018-06-06 01:04:39 +03:00
|
|
|
before_change_closure,
|
2017-09-07 14:55:02 +03:00
|
|
|
)
|
2016-12-18 05:22:10 +03:00
|
|
|
}
|
|
|
|
|
2018-05-03 19:27:44 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_SetPropertyToAnimationValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
|
|
|
animation_value: &RawServoAnimationValue,
|
2019-05-20 08:22:39 +03:00
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
2018-05-03 19:27:44 +03:00
|
|
|
) -> bool {
|
2019-05-20 08:22:39 +03:00
|
|
|
let mut source_declarations =
|
|
|
|
SourcePropertyDeclaration::with_one(AnimationValue::as_arc(&animation_value).uncompute());
|
|
|
|
|
|
|
|
set_property_to_declarations(
|
|
|
|
declarations,
|
|
|
|
&mut source_declarations,
|
|
|
|
before_change_closure,
|
|
|
|
Importance::Normal,
|
|
|
|
)
|
2018-05-03 19:27:44 +03:00
|
|
|
}
|
|
|
|
|
2016-12-18 05:22:10 +03:00
|
|
|
#[no_mangle]
|
2017-09-07 14:55:02 +03:00
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_SetPropertyById(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-09-07 14:55:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2017-09-07 14:55:02 +03:00
|
|
|
is_important: bool,
|
|
|
|
data: *mut URLExtraData,
|
|
|
|
parsing_mode: structs::ParsingMode,
|
|
|
|
quirks_mode: nsCompatibility,
|
|
|
|
loader: *mut Loader,
|
2018-06-06 01:04:39 +03:00
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
2017-09-07 14:55:02 +03:00
|
|
|
) -> bool {
|
|
|
|
set_property(
|
|
|
|
declarations,
|
|
|
|
get_property_id_from_nscsspropertyid!(property, false),
|
|
|
|
value,
|
|
|
|
is_important,
|
|
|
|
data,
|
|
|
|
parsing_mode,
|
|
|
|
quirks_mode.into(),
|
|
|
|
loader,
|
2018-06-06 01:04:39 +03:00
|
|
|
before_change_closure,
|
2017-09-07 14:55:02 +03:00
|
|
|
)
|
2016-12-18 05:22:10 +03:00
|
|
|
}
|
|
|
|
|
2017-10-20 13:26:18 +03:00
|
|
|
fn remove_property(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2018-06-06 01:04:39 +03:00
|
|
|
property_id: PropertyId,
|
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
2017-10-20 13:26:18 +03:00
|
|
|
) -> bool {
|
2018-11-20 07:37:53 +03:00
|
|
|
let first_declaration = read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
|
|
|
decls.first_declaration_to_remove(&property_id)
|
|
|
|
});
|
2018-06-18 13:30:24 +03:00
|
|
|
|
|
|
|
let first_declaration = match first_declaration {
|
|
|
|
Some(i) => i,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
|
|
|
|
before_change_closure.invoke();
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-06-18 13:30:24 +03:00
|
|
|
decls.remove_property(&property_id, first_declaration)
|
|
|
|
});
|
|
|
|
|
|
|
|
true
|
2016-12-18 05:22:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-09-07 14:55:02 +03:00
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_RemoveProperty(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2019-11-27 23:57:51 +03:00
|
|
|
property: &nsACString,
|
2018-06-06 01:04:39 +03:00
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
2018-02-10 11:59:43 +03:00
|
|
|
) -> bool {
|
2018-06-06 01:04:39 +03:00
|
|
|
remove_property(
|
|
|
|
declarations,
|
|
|
|
get_property_id_from_property!(property, false),
|
|
|
|
before_change_closure,
|
|
|
|
)
|
2016-12-18 05:22:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-20 13:26:18 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_RemovePropertyById(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2018-06-06 01:04:39 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
before_change_closure: DeclarationBlockMutationClosure,
|
2017-10-20 13:26:18 +03:00
|
|
|
) -> bool {
|
2018-06-06 01:04:39 +03:00
|
|
|
remove_property(
|
|
|
|
declarations,
|
|
|
|
get_property_id_from_nscsspropertyid!(property, false),
|
|
|
|
before_change_closure,
|
|
|
|
)
|
2016-11-04 07:42:06 +03:00
|
|
|
}
|
|
|
|
|
2017-04-12 18:00:26 +03:00
|
|
|
#[no_mangle]
|
2019-03-26 21:16:01 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_Create() -> Strong<RawServoMediaList> {
|
2017-04-12 18:00:26 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
Arc::new(global_style_data.shared_lock.wrap(MediaList::empty())).into_strong()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_DeepClone(list: &RawServoMediaList) -> Strong<RawServoMediaList> {
|
2017-04-12 18:00:26 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
read_locked_arc(list, |list: &MediaList| {
|
2018-11-20 07:37:53 +03:00
|
|
|
Arc::new(global_style_data.shared_lock.wrap(list.clone())).into_strong()
|
2017-04-12 18:00:26 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_Matches(
|
2019-03-21 20:00:27 +03:00
|
|
|
list: &RawServoMediaList,
|
|
|
|
raw_data: &RawServoStyleSet,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2017-04-12 18:00:26 +03:00
|
|
|
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
read_locked_arc(list, |list: &MediaList| {
|
2018-11-20 07:37:53 +03:00
|
|
|
list.evaluate(
|
|
|
|
per_doc_data.stylist.device(),
|
|
|
|
per_doc_data.stylist.quirks_mode(),
|
|
|
|
)
|
2017-04-12 18:00:26 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:20:52 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_HasCSSWideKeyword(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
) -> bool {
|
2017-04-15 14:20:52 +03:00
|
|
|
let property_id = get_property_id_from_nscsspropertyid!(property, false);
|
|
|
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
|
|
|
decls.has_css_wide_keyword(&property_id)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-13 09:55:46 +03:00
|
|
|
#[no_mangle]
|
2020-01-05 17:42:23 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_GetText(list: &RawServoMediaList, result: &mut nsAString) {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(list, |list: &MediaList| {
|
2020-01-05 17:42:23 +03:00
|
|
|
list.to_css(&mut CssWriter::new(result)).unwrap();
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-25 15:50:46 +03:00
|
|
|
pub unsafe extern "C" fn Servo_MediaList_SetText(
|
2019-03-21 20:00:27 +03:00
|
|
|
list: &RawServoMediaList,
|
2019-11-27 23:57:51 +03:00
|
|
|
text: &nsACString,
|
2017-10-25 15:50:46 +03:00
|
|
|
caller_type: CallerType,
|
|
|
|
) {
|
2019-11-27 23:57:51 +03:00
|
|
|
let text = text.as_str_unchecked();
|
2017-10-25 15:50:46 +03:00
|
|
|
|
2017-06-10 00:31:48 +03:00
|
|
|
let mut input = ParserInput::new(&text);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
2017-10-25 15:50:46 +03:00
|
|
|
let url_data = dummy_url_data();
|
|
|
|
|
|
|
|
// TODO(emilio): If the need for `CallerType` appears in more places,
|
|
|
|
// consider adding an explicit member in `ParserContext` instead of doing
|
|
|
|
// this (or adding a dummy "chrome://" url data).
|
|
|
|
//
|
|
|
|
// For media query parsing it's effectively the same, so for now...
|
|
|
|
let origin = match caller_type {
|
|
|
|
CallerType::System => Origin::UserAgent,
|
|
|
|
CallerType::NonSystem => Origin::Author,
|
|
|
|
};
|
|
|
|
|
|
|
|
let context = ParserContext::new(
|
|
|
|
origin,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Media),
|
2017-10-31 02:25:45 +03:00
|
|
|
ParsingMode::DEFAULT,
|
2017-10-25 15:50:46 +03:00
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
// TODO(emilio): Looks like error reporting could be useful here?
|
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-10-25 15:50:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
write_locked_arc(list, |list: &mut MediaList| {
|
2018-06-20 22:07:45 +03:00
|
|
|
*list = MediaList::parse(&context, &mut parser);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_GetLength(list: &RawServoMediaList) -> u32 {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(list, |list: &MediaList| list.media_queries.len() as u32)
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_GetMediumAt(
|
2019-03-21 20:00:27 +03:00
|
|
|
list: &RawServoMediaList,
|
2017-10-13 22:11:02 +03:00
|
|
|
index: u32,
|
2020-01-05 17:42:23 +03:00
|
|
|
result: &mut nsAString,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(list, |list: &MediaList| {
|
2020-01-05 17:42:23 +03:00
|
|
|
let media_query = match list.media_queries.get(index as usize) {
|
|
|
|
Some(mq) => mq,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
media_query.to_css(&mut CssWriter::new(result)).unwrap();
|
|
|
|
true
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_AppendMedium(
|
2019-03-21 20:00:27 +03:00
|
|
|
list: &RawServoMediaList,
|
2019-11-27 23:57:51 +03:00
|
|
|
new_medium: &nsACString,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2019-11-27 23:57:51 +03:00
|
|
|
let new_medium = unsafe { new_medium.as_str_unchecked() };
|
2017-04-12 13:38:50 +03:00
|
|
|
let url_data = unsafe { dummy_url_data() };
|
2017-11-27 17:41:46 +03:00
|
|
|
let context = ParserContext::new_for_cssom(
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Media),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-11-27 17:41:46 +03:00
|
|
|
);
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(list, |list: &mut MediaList| {
|
2017-04-12 13:38:50 +03:00
|
|
|
list.append_medium(&context, new_medium);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_MediaList_DeleteMedium(
|
2019-03-21 20:00:27 +03:00
|
|
|
list: &RawServoMediaList,
|
2019-11-27 23:57:51 +03:00
|
|
|
old_medium: &nsACString,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2019-11-27 23:57:51 +03:00
|
|
|
let old_medium = unsafe { old_medium.as_str_unchecked() };
|
2017-04-12 13:38:50 +03:00
|
|
|
let url_data = unsafe { dummy_url_data() };
|
2017-11-27 17:41:46 +03:00
|
|
|
let context = ParserContext::new_for_cssom(
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Media),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-11-27 17:41:46 +03:00
|
|
|
);
|
2018-11-20 07:37:53 +03:00
|
|
|
write_locked_arc(list, |list: &mut MediaList| {
|
|
|
|
list.delete_medium(&context, old_medium)
|
|
|
|
})
|
2017-03-13 09:55:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-06 04:09:12 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_MediaList_SizeOfIncludingThis(
|
|
|
|
malloc_size_of: GeckoMallocSizeOf,
|
|
|
|
malloc_enclosing_size_of: GeckoMallocSizeOf,
|
2019-03-21 20:00:27 +03:00
|
|
|
list: &RawServoMediaList,
|
2018-07-06 04:09:12 +03:00
|
|
|
) -> usize {
|
|
|
|
use malloc_size_of::MallocSizeOf;
|
|
|
|
use malloc_size_of::MallocUnconditionalShallowSizeOf;
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
|
|
|
|
let mut ops = MallocSizeOfOps::new(
|
|
|
|
malloc_size_of.unwrap(),
|
|
|
|
Some(malloc_enclosing_size_of.unwrap()),
|
2018-11-20 07:37:53 +03:00
|
|
|
None,
|
2018-07-06 04:09:12 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
Locked::<MediaList>::as_arc(&list).with_arc(|list| {
|
|
|
|
let mut n = 0;
|
|
|
|
n += list.unconditional_shallow_size_of(&mut ops);
|
|
|
|
n += list.read_with(&guard).size_of(&mut ops);
|
|
|
|
n
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-19 07:43:33 +03:00
|
|
|
macro_rules! get_longhand_from_id {
|
2017-05-11 03:05:21 +03:00
|
|
|
($id:expr) => {
|
2017-02-19 07:43:33 +03:00
|
|
|
match PropertyId::from_nscsspropertyid($id) {
|
|
|
|
Ok(PropertyId::Longhand(long)) => long,
|
|
|
|
_ => {
|
2018-01-13 20:52:15 +03:00
|
|
|
panic!("stylo: unknown presentation property with id");
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-02-04 04:36:04 +03:00
|
|
|
}
|
|
|
|
};
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! match_wrap_declared {
|
|
|
|
($longhand:ident, $($property:ident => $inner:expr,)*) => (
|
|
|
|
match $longhand {
|
|
|
|
$(
|
2017-03-17 00:48:53 +03:00
|
|
|
LonghandId::$property => PropertyDeclaration::$property($inner),
|
2017-02-19 07:43:33 +03:00
|
|
|
)*
|
|
|
|
_ => {
|
2018-01-13 20:52:15 +03:00
|
|
|
panic!("stylo: Don't know how to handle presentation property");
|
2017-02-04 04:36:04 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-19 07:43:33 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-02-13 18:25:30 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_PropertyIsSet(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2018-02-13 18:25:30 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
) -> bool {
|
2017-03-22 14:17:09 +03:00
|
|
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
2017-09-12 02:50:19 +03:00
|
|
|
decls.contains(get_longhand_from_id!(property))
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-03-19 13:11:14 +03:00
|
|
|
pub unsafe extern "C" fn Servo_DeclarationBlock_SetIdentStringValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
value: *mut nsAtom,
|
|
|
|
) {
|
2017-02-19 07:43:33 +03:00
|
|
|
use style::properties::longhands::_x_lang::computed_value::T as Lang;
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
let prop = match_wrap_declared! { long,
|
2018-03-19 13:11:14 +03:00
|
|
|
XLang => Lang(Atom::from_raw(value)),
|
2017-02-19 07:43:33 +03:00
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
#[allow(unreachable_code)]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
2018-11-20 07:37:53 +03:00
|
|
|
value: i32,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2018-08-21 18:34:21 +03:00
|
|
|
use num_traits::FromPrimitive;
|
2017-02-19 07:43:33 +03:00
|
|
|
use style::properties::longhands;
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-05-01 16:08:34 +03:00
|
|
|
use style::values::generics::box_::{VerticalAlign, VerticalAlignKeyword};
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::values::generics::font::FontStyle;
|
2017-03-20 10:28:46 +03:00
|
|
|
use style::values::specified::BorderStyle;
|
2018-08-21 18:34:21 +03:00
|
|
|
use style::values::specified::Display;
|
2018-07-16 20:01:24 +03:00
|
|
|
use style::values::specified::{Clear, Float};
|
2017-02-19 07:43:33 +03:00
|
|
|
|
2019-01-28 03:04:06 +03:00
|
|
|
fn get_from_computed<T>(value: u32) -> T
|
|
|
|
where
|
|
|
|
T: ToComputedValue,
|
|
|
|
T::ComputedValue: FromPrimitive,
|
|
|
|
{
|
|
|
|
T::from_computed_value(&T::ComputedValue::from_u32(value).unwrap())
|
|
|
|
}
|
|
|
|
|
2017-02-19 07:43:33 +03:00
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
let value = value as u32;
|
|
|
|
|
|
|
|
let prop = match_wrap_declared! { long,
|
|
|
|
MozUserModify => longhands::_moz_user_modify::SpecifiedValue::from_gecko_keyword(value),
|
2017-04-12 17:16:55 +03:00
|
|
|
Direction => longhands::direction::SpecifiedValue::from_gecko_keyword(value),
|
2019-01-28 03:04:06 +03:00
|
|
|
Display => get_from_computed::<Display>(value),
|
|
|
|
Float => get_from_computed::<Float>(value),
|
|
|
|
Clear => get_from_computed::<Clear>(value),
|
2019-05-01 16:08:34 +03:00
|
|
|
VerticalAlign => VerticalAlign::Keyword(VerticalAlignKeyword::from_u32(value).unwrap()),
|
2017-02-19 07:43:33 +03:00
|
|
|
TextAlign => longhands::text_align::SpecifiedValue::from_gecko_keyword(value),
|
2017-03-31 14:01:06 +03:00
|
|
|
TextEmphasisPosition => longhands::text_emphasis_position::SpecifiedValue::from_gecko_keyword(value),
|
2017-02-19 07:43:33 +03:00
|
|
|
FontSize => {
|
|
|
|
// We rely on Gecko passing in font-size values (0...7) here.
|
2017-03-20 10:28:46 +03:00
|
|
|
longhands::font_size::SpecifiedValue::from_html_size(value as u8)
|
2017-02-19 07:43:33 +03:00
|
|
|
},
|
2017-09-17 23:12:46 +03:00
|
|
|
FontStyle => {
|
2018-04-23 17:52:20 +03:00
|
|
|
let val = if value == structs::NS_FONT_STYLE_ITALIC {
|
|
|
|
FontStyle::Italic
|
|
|
|
} else {
|
|
|
|
debug_assert_eq!(value, structs::NS_FONT_STYLE_NORMAL);
|
|
|
|
FontStyle::Normal
|
|
|
|
};
|
|
|
|
|
|
|
|
ToComputedValue::from_computed_value(&val)
|
2017-09-17 23:12:46 +03:00
|
|
|
},
|
2017-04-12 17:16:55 +03:00
|
|
|
FontWeight => longhands::font_weight::SpecifiedValue::from_gecko_keyword(value),
|
2017-05-27 15:09:30 +03:00
|
|
|
ListStyleType => Box::new(longhands::list_style_type::SpecifiedValue::from_gecko_keyword(value)),
|
2017-04-12 17:16:55 +03:00
|
|
|
MozMathVariant => longhands::_moz_math_variant::SpecifiedValue::from_gecko_keyword(value),
|
2017-02-19 07:43:33 +03:00
|
|
|
WhiteSpace => longhands::white_space::SpecifiedValue::from_gecko_keyword(value),
|
|
|
|
CaptionSide => longhands::caption_side::SpecifiedValue::from_gecko_keyword(value),
|
2019-01-28 03:04:06 +03:00
|
|
|
BorderTopStyle => get_from_computed::<BorderStyle>(value),
|
|
|
|
BorderRightStyle => get_from_computed::<BorderStyle>(value),
|
|
|
|
BorderBottomStyle => get_from_computed::<BorderStyle>(value),
|
|
|
|
BorderLeftStyle => get_from_computed::<BorderStyle>(value),
|
2017-02-19 07:43:33 +03:00
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetIntValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
2018-11-20 07:37:53 +03:00
|
|
|
value: i32,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-04-12 17:16:55 +03:00
|
|
|
use style::properties::longhands::_moz_script_level::SpecifiedValue as MozScriptLevel;
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-08-21 23:02:13 +03:00
|
|
|
use style::values::specified::Integer;
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
let prop = match_wrap_declared! { long,
|
2019-08-21 23:02:13 +03:00
|
|
|
XSpan => Integer::new(value),
|
2017-04-12 17:16:55 +03:00
|
|
|
// Gecko uses Integer values to signal that it is relative
|
|
|
|
MozScriptLevel => MozScriptLevel::Relative(value),
|
2017-02-19 07:43:33 +03:00
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
2019-03-25 01:13:52 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetCounterResetListItem(
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
|
|
|
counter_value: i32,
|
|
|
|
) {
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-03-25 01:13:52 +03:00
|
|
|
use style::values::generics::counters::{CounterPair, CounterSetOrReset};
|
|
|
|
|
|
|
|
let prop = PropertyDeclaration::CounterReset(CounterSetOrReset::new(vec![CounterPair {
|
|
|
|
name: CustomIdent(atom!("list-item")),
|
|
|
|
value: style::values::specified::Integer::new(counter_value),
|
|
|
|
}]));
|
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
|
|
|
decls.push(prop, Importance::Normal);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetCounterSetListItem(
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
|
|
|
counter_value: i32,
|
|
|
|
) {
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-03-25 01:13:52 +03:00
|
|
|
use style::values::generics::counters::{CounterPair, CounterSetOrReset};
|
|
|
|
|
|
|
|
let prop = PropertyDeclaration::CounterSet(CounterSetOrReset::new(vec![CounterPair {
|
|
|
|
name: CustomIdent(atom!("list-item")),
|
|
|
|
value: style::values::specified::Integer::new(counter_value),
|
|
|
|
}]));
|
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
|
|
|
decls.push(prop, Importance::Normal);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-19 07:43:33 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
2018-11-20 07:37:53 +03:00
|
|
|
value: f32,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-02-19 07:43:33 +03:00
|
|
|
use style::properties::longhands::border_spacing::SpecifiedValue as BorderSpacing;
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::values::generics::length::LengthPercentageOrAuto;
|
2019-02-11 13:59:49 +03:00
|
|
|
use style::values::generics::length::Size;
|
2019-01-22 04:59:21 +03:00
|
|
|
use style::values::generics::NonNegative;
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::values::specified::length::LengthPercentage;
|
2019-01-22 04:59:21 +03:00
|
|
|
use style::values::specified::length::NonNegativeLengthPercentage;
|
|
|
|
use style::values::specified::length::{NoCalcLength, NonNegativeLength};
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::values::specified::{BorderCornerRadius, BorderSideWidth};
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
let nocalc = NoCalcLength::from_px(value);
|
2019-01-07 15:42:40 +03:00
|
|
|
let lp = LengthPercentage::Length(nocalc);
|
|
|
|
let lp_or_auto = LengthPercentageOrAuto::LengthPercentage(lp.clone());
|
2017-02-19 07:43:33 +03:00
|
|
|
let prop = match_wrap_declared! { long,
|
2019-02-11 13:59:49 +03:00
|
|
|
Height => Size::LengthPercentage(NonNegative(lp)),
|
|
|
|
Width => Size::LengthPercentage(NonNegative(lp)),
|
2017-06-02 11:53:55 +03:00
|
|
|
BorderTopWidth => BorderSideWidth::Length(nocalc.into()),
|
|
|
|
BorderRightWidth => BorderSideWidth::Length(nocalc.into()),
|
|
|
|
BorderBottomWidth => BorderSideWidth::Length(nocalc.into()),
|
|
|
|
BorderLeftWidth => BorderSideWidth::Length(nocalc.into()),
|
2019-01-07 15:42:40 +03:00
|
|
|
MarginTop => lp_or_auto,
|
|
|
|
MarginRight => lp_or_auto,
|
|
|
|
MarginBottom => lp_or_auto,
|
|
|
|
MarginLeft => lp_or_auto,
|
|
|
|
PaddingTop => NonNegative(lp),
|
|
|
|
PaddingRight => NonNegative(lp),
|
|
|
|
PaddingBottom => NonNegative(lp),
|
|
|
|
PaddingLeft => NonNegative(lp),
|
2017-09-17 23:12:46 +03:00
|
|
|
BorderSpacing => {
|
|
|
|
let v = NonNegativeLength::from(nocalc);
|
|
|
|
Box::new(BorderSpacing::new(v.clone(), v))
|
|
|
|
},
|
|
|
|
BorderTopLeftRadius => {
|
2019-01-07 15:42:42 +03:00
|
|
|
let length = NonNegativeLengthPercentage::from(nocalc);
|
2017-09-17 23:12:46 +03:00
|
|
|
Box::new(BorderCornerRadius::new(length.clone(), length))
|
|
|
|
},
|
|
|
|
BorderTopRightRadius => {
|
2019-01-07 15:42:42 +03:00
|
|
|
let length = NonNegativeLengthPercentage::from(nocalc);
|
2017-09-17 23:12:46 +03:00
|
|
|
Box::new(BorderCornerRadius::new(length.clone(), length))
|
|
|
|
},
|
|
|
|
BorderBottomLeftRadius => {
|
2019-01-07 15:42:42 +03:00
|
|
|
let length = NonNegativeLengthPercentage::from(nocalc);
|
2017-09-17 23:12:46 +03:00
|
|
|
Box::new(BorderCornerRadius::new(length.clone(), length))
|
|
|
|
},
|
|
|
|
BorderBottomRightRadius => {
|
2019-01-07 15:42:42 +03:00
|
|
|
let length = NonNegativeLengthPercentage::from(nocalc);
|
2017-09-17 23:12:46 +03:00
|
|
|
Box::new(BorderCornerRadius::new(length.clone(), length))
|
|
|
|
},
|
2017-02-19 07:43:33 +03:00
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:16:55 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
value: f32,
|
|
|
|
unit: structs::nsCSSUnit,
|
|
|
|
) {
|
2017-04-25 21:06:23 +03:00
|
|
|
use style::properties::longhands::_moz_script_min_size::SpecifiedValue as MozScriptMinSize;
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::values::generics::length::{LengthPercentageOrAuto, Size};
|
2019-01-27 03:03:44 +03:00
|
|
|
use style::values::generics::NonNegative;
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::values::specified::length::LengthPercentage;
|
2019-01-22 04:59:21 +03:00
|
|
|
use style::values::specified::length::NoCalcLength;
|
2017-11-14 16:27:28 +03:00
|
|
|
use style::values::specified::length::{AbsoluteLength, FontRelativeLength};
|
2017-04-12 17:16:55 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
let nocalc = match unit {
|
2018-11-20 07:37:53 +03:00
|
|
|
structs::nsCSSUnit::eCSSUnit_EM => {
|
|
|
|
NoCalcLength::FontRelative(FontRelativeLength::Em(value))
|
|
|
|
},
|
|
|
|
structs::nsCSSUnit::eCSSUnit_XHeight => {
|
|
|
|
NoCalcLength::FontRelative(FontRelativeLength::Ex(value))
|
|
|
|
},
|
2017-04-12 17:16:55 +03:00
|
|
|
structs::nsCSSUnit::eCSSUnit_Pixel => NoCalcLength::Absolute(AbsoluteLength::Px(value)),
|
|
|
|
structs::nsCSSUnit::eCSSUnit_Inch => NoCalcLength::Absolute(AbsoluteLength::In(value)),
|
2018-11-20 07:37:53 +03:00
|
|
|
structs::nsCSSUnit::eCSSUnit_Centimeter => {
|
|
|
|
NoCalcLength::Absolute(AbsoluteLength::Cm(value))
|
|
|
|
},
|
|
|
|
structs::nsCSSUnit::eCSSUnit_Millimeter => {
|
|
|
|
NoCalcLength::Absolute(AbsoluteLength::Mm(value))
|
|
|
|
},
|
2017-04-12 17:16:55 +03:00
|
|
|
structs::nsCSSUnit::eCSSUnit_Point => NoCalcLength::Absolute(AbsoluteLength::Pt(value)),
|
|
|
|
structs::nsCSSUnit::eCSSUnit_Pica => NoCalcLength::Absolute(AbsoluteLength::Pc(value)),
|
|
|
|
structs::nsCSSUnit::eCSSUnit_Quarter => NoCalcLength::Absolute(AbsoluteLength::Q(value)),
|
2018-11-20 07:37:53 +03:00
|
|
|
_ => unreachable!("Unknown unit passed to SetLengthValue"),
|
2017-04-12 17:16:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let prop = match_wrap_declared! { long,
|
2019-02-11 13:59:49 +03:00
|
|
|
Width => Size::LengthPercentage(NonNegative(LengthPercentage::Length(nocalc))),
|
2019-05-16 16:21:21 +03:00
|
|
|
Height => Size::LengthPercentage(NonNegative(LengthPercentage::Length(nocalc))),
|
|
|
|
X => LengthPercentage::Length(nocalc),
|
|
|
|
Y => LengthPercentage::Length(nocalc),
|
|
|
|
Cx => LengthPercentage::Length(nocalc),
|
|
|
|
Cy => LengthPercentage::Length(nocalc),
|
|
|
|
R => NonNegative(LengthPercentage::Length(nocalc)),
|
|
|
|
Rx => LengthPercentageOrAuto::LengthPercentage(NonNegative(LengthPercentage::Length(nocalc))),
|
|
|
|
Ry => LengthPercentageOrAuto::LengthPercentage(NonNegative(LengthPercentage::Length(nocalc))),
|
2019-01-07 15:42:42 +03:00
|
|
|
FontSize => LengthPercentage::from(nocalc).into(),
|
2017-04-25 21:06:23 +03:00
|
|
|
MozScriptMinSize => MozScriptMinSize(nocalc),
|
2017-04-12 17:16:55 +03:00
|
|
|
};
|
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-04-12 17:16:55 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetNumberValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
value: f32,
|
|
|
|
) {
|
2017-04-12 17:16:55 +03:00
|
|
|
use style::properties::longhands::_moz_script_level::SpecifiedValue as MozScriptLevel;
|
2017-11-23 13:28:18 +03:00
|
|
|
use style::properties::longhands::_moz_script_size_multiplier::SpecifiedValue as MozScriptSizeMultiplier;
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-06-27 01:10:04 +03:00
|
|
|
use style::values::specified::Number;
|
2017-04-12 17:16:55 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
|
|
|
|
let prop = match_wrap_declared! { long,
|
2017-11-23 13:28:18 +03:00
|
|
|
MozScriptSizeMultiplier => MozScriptSizeMultiplier(value),
|
2017-04-12 17:16:55 +03:00
|
|
|
// Gecko uses Number values to signal that it is absolute
|
2017-11-12 18:41:04 +03:00
|
|
|
MozScriptLevel => MozScriptLevel::MozAbsolute(value as i32),
|
2019-06-27 01:10:04 +03:00
|
|
|
AspectRatio => Number::new(value),
|
2017-04-12 17:16:55 +03:00
|
|
|
};
|
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-04-12 17:16:55 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-19 07:43:33 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
value: f32,
|
|
|
|
) {
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2017-07-17 11:29:11 +03:00
|
|
|
use style::values::computed::Percentage;
|
2019-08-26 12:58:53 +03:00
|
|
|
use style::values::generics::length::{LengthPercentageOrAuto, Size};
|
2019-01-27 03:03:44 +03:00
|
|
|
use style::values::generics::NonNegative;
|
|
|
|
use style::values::specified::length::LengthPercentage;
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
let pc = Percentage(value);
|
2019-01-27 03:03:44 +03:00
|
|
|
let lp = LengthPercentage::Percentage(pc);
|
|
|
|
let lp_or_auto = LengthPercentageOrAuto::LengthPercentage(lp.clone());
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let prop = match_wrap_declared! { long,
|
2019-02-11 13:59:49 +03:00
|
|
|
Height => Size::LengthPercentage(NonNegative(lp)),
|
|
|
|
Width => Size::LengthPercentage(NonNegative(lp)),
|
2019-05-16 16:21:21 +03:00
|
|
|
X => lp,
|
|
|
|
Y => lp,
|
|
|
|
Cx => lp,
|
|
|
|
Cy => lp,
|
|
|
|
R => NonNegative(lp),
|
|
|
|
Rx => LengthPercentageOrAuto::LengthPercentage(NonNegative(lp)),
|
|
|
|
Ry => LengthPercentageOrAuto::LengthPercentage(NonNegative(lp)),
|
2019-01-07 15:42:40 +03:00
|
|
|
MarginTop => lp_or_auto,
|
|
|
|
MarginRight => lp_or_auto,
|
|
|
|
MarginBottom => lp_or_auto,
|
|
|
|
MarginLeft => lp_or_auto,
|
2019-01-07 15:42:42 +03:00
|
|
|
FontSize => LengthPercentage::from(pc).into(),
|
2017-02-19 07:43:33 +03:00
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
) {
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-02-11 13:59:49 +03:00
|
|
|
use style::values::generics::length::{LengthPercentageOrAuto, Size};
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
2019-01-07 15:42:42 +03:00
|
|
|
let auto = LengthPercentageOrAuto::Auto;
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let prop = match_wrap_declared! { long,
|
2019-02-11 13:59:49 +03:00
|
|
|
Height => Size::auto(),
|
|
|
|
Width => Size::auto(),
|
2017-02-19 07:43:33 +03:00
|
|
|
MarginTop => auto,
|
|
|
|
MarginRight => auto,
|
|
|
|
MarginBottom => auto,
|
|
|
|
MarginLeft => auto,
|
2017-02-04 04:36:04 +03:00
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetCurrentColor(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
) {
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2017-06-08 07:03:52 +03:00
|
|
|
use style::values::specified::Color;
|
2017-02-04 04:36:04 +03:00
|
|
|
|
2017-02-19 07:43:33 +03:00
|
|
|
let long = get_longhand_from_id!(property);
|
2017-06-08 07:03:52 +03:00
|
|
|
let cc = Color::currentcolor();
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let prop = match_wrap_declared! { long,
|
|
|
|
BorderTopColor => cc,
|
|
|
|
BorderRightColor => cc,
|
|
|
|
BorderBottomColor => cc,
|
|
|
|
BorderLeftColor => cc,
|
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetColorValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
property: nsCSSPropertyID,
|
|
|
|
value: structs::nscolor,
|
|
|
|
) {
|
2017-02-19 07:43:33 +03:00
|
|
|
use style::gecko::values::convert_nscolor_to_rgba;
|
2017-02-28 10:08:33 +03:00
|
|
|
use style::properties::longhands;
|
2019-04-03 13:00:44 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2017-06-08 07:03:52 +03:00
|
|
|
use style::values::specified::Color;
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let long = get_longhand_from_id!(property);
|
|
|
|
let rgba = convert_nscolor_to_rgba(value);
|
2017-06-08 07:03:52 +03:00
|
|
|
let color = Color::rgba(rgba);
|
2017-02-19 07:43:33 +03:00
|
|
|
|
|
|
|
let prop = match_wrap_declared! { long,
|
|
|
|
BorderTopColor => color,
|
|
|
|
BorderRightColor => color,
|
|
|
|
BorderBottomColor => color,
|
|
|
|
BorderLeftColor => color,
|
2017-02-28 10:08:33 +03:00
|
|
|
Color => longhands::color::SpecifiedValue(color),
|
2017-02-19 07:43:33 +03:00
|
|
|
BackgroundColor => color,
|
|
|
|
};
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(prop, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2020-01-05 17:42:23 +03:00
|
|
|
value: &nsAString,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-02-19 07:43:33 +03:00
|
|
|
use style::properties::longhands::font_family::SpecifiedValue as FontFamily;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2017-02-19 07:43:33 +03:00
|
|
|
|
2020-01-05 17:42:23 +03:00
|
|
|
let string = value.to_string();
|
2017-06-10 00:31:48 +03:00
|
|
|
let mut input = ParserInput::new(&string);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
2017-11-25 22:06:31 +03:00
|
|
|
let result = FontFamily::parse_specified(&mut parser);
|
2017-06-16 16:09:52 +03:00
|
|
|
if let Ok(family) = result {
|
2017-02-19 07:43:33 +03:00
|
|
|
if parser.is_exhausted() {
|
2017-10-04 13:01:45 +03:00
|
|
|
let decl = PropertyDeclaration::FontFamily(family);
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(decl, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-19 07:43:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:16:55 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2020-01-05 17:42:23 +03:00
|
|
|
value: &nsAString,
|
2017-10-13 22:11:02 +03:00
|
|
|
raw_extra_data: *mut URLExtraData,
|
|
|
|
) {
|
2017-04-12 17:16:55 +03:00
|
|
|
use style::properties::longhands::background_image::SpecifiedValue as BackgroundImage;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2019-06-03 15:22:30 +03:00
|
|
|
use style::stylesheets::CorsMode;
|
2019-06-07 17:13:17 +03:00
|
|
|
use style::values::generics::image::{Image, ImageLayer};
|
2018-03-08 16:06:35 +03:00
|
|
|
use style::values::specified::url::SpecifiedImageUrl;
|
2017-04-12 17:16:55 +03:00
|
|
|
|
2018-06-21 14:09:35 +03:00
|
|
|
let url_data = unsafe { UrlExtraData::from_ptr_ref(&raw_extra_data) };
|
2020-01-05 17:42:23 +03:00
|
|
|
let string = value.to_string();
|
2017-11-27 17:41:46 +03:00
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Style),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-11-27 17:41:46 +03:00
|
|
|
);
|
2019-06-03 15:22:30 +03:00
|
|
|
let url = SpecifiedImageUrl::parse_from_string(string.into(), &context, CorsMode::None);
|
2019-08-26 12:58:53 +03:00
|
|
|
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
|
|
|
|
vec![ImageLayer::Image(Image::Url(url))].into(),
|
|
|
|
));
|
2018-05-16 05:19:31 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(decl, Importance::Normal);
|
2018-05-16 05:19:31 +03:00
|
|
|
});
|
2017-04-12 17:16:55 +03:00
|
|
|
}
|
|
|
|
|
2017-02-19 07:43:33 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_DeclarationBlock_SetTextDecorationColorOverride(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-03-17 00:48:53 +03:00
|
|
|
use style::properties::PropertyDeclaration;
|
2017-11-15 00:34:10 +03:00
|
|
|
use style::values::specified::text::TextDecorationLine;
|
2017-02-19 07:43:33 +03:00
|
|
|
|
2019-03-18 20:58:16 +03:00
|
|
|
let decoration = TextDecorationLine::COLOR_OVERRIDE;
|
2017-03-17 00:48:53 +03:00
|
|
|
let decl = PropertyDeclaration::TextDecorationLine(decoration);
|
2017-03-22 14:17:09 +03:00
|
|
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
2018-07-19 03:11:04 +03:00
|
|
|
decls.push(decl, Importance::Normal);
|
2017-03-22 14:17:09 +03:00
|
|
|
})
|
2017-02-04 04:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 07:25:31 +03:00
|
|
|
#[no_mangle]
|
2017-09-07 14:55:02 +03:00
|
|
|
pub unsafe extern "C" fn Servo_CSSSupports2(
|
2019-11-27 23:57:51 +03:00
|
|
|
property: &nsACString,
|
|
|
|
value: &nsACString,
|
2017-09-07 14:55:02 +03:00
|
|
|
) -> bool {
|
2017-05-11 05:25:47 +03:00
|
|
|
let id = get_property_id_from_property!(property, false);
|
2016-07-19 07:25:31 +03:00
|
|
|
|
2017-05-20 02:37:14 +03:00
|
|
|
let mut declarations = SourcePropertyDeclaration::new();
|
|
|
|
parse_property_into(
|
|
|
|
&mut declarations,
|
|
|
|
id,
|
|
|
|
value,
|
2017-09-07 14:55:02 +03:00
|
|
|
DUMMY_URL_DATA,
|
2017-05-20 02:37:14 +03:00
|
|
|
structs::ParsingMode_Default,
|
2017-07-11 04:13:44 +03:00
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-11-20 07:37:53 +03:00
|
|
|
)
|
|
|
|
.is_ok()
|
2016-07-19 07:25:31 +03:00
|
|
|
}
|
2016-07-22 00:54:34 +03:00
|
|
|
|
2017-01-17 00:56:51 +03:00
|
|
|
#[no_mangle]
|
2019-11-27 23:57:51 +03:00
|
|
|
pub extern "C" fn Servo_CSSSupports(cond: &nsACString) -> bool {
|
|
|
|
let condition = unsafe { cond.as_str_unchecked() };
|
2017-06-10 00:31:48 +03:00
|
|
|
let mut input = ParserInput::new(&condition);
|
|
|
|
let mut input = Parser::new(&mut input);
|
2018-10-17 15:08:14 +03:00
|
|
|
let cond = match input.parse_entirely(parse_condition_or_declaration) {
|
|
|
|
Ok(c) => c,
|
|
|
|
Err(..) => return false,
|
|
|
|
};
|
2017-11-27 17:41:46 +03:00
|
|
|
|
2018-10-17 15:08:14 +03:00
|
|
|
let url_data = unsafe { dummy_url_data() };
|
|
|
|
|
|
|
|
// NOTE(emilio): The supports API is not associated to any stylesheet,
|
|
|
|
// so the fact that there is no namespace map here is fine.
|
|
|
|
let context = ParserContext::new_for_cssom(
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Style),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
|
|
|
|
let namespaces = Default::default();
|
|
|
|
cond.eval(&context, &namespaces)
|
2017-01-17 00:56:51 +03:00
|
|
|
}
|
|
|
|
|
2016-11-25 20:00:44 +03:00
|
|
|
#[no_mangle]
|
2018-02-16 23:33:48 +03:00
|
|
|
pub unsafe extern "C" fn Servo_NoteExplicitHints(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
2019-03-14 14:47:50 +03:00
|
|
|
restyle_hint: RestyleHint,
|
2017-10-13 22:11:02 +03:00
|
|
|
change_hint: nsChangeHint,
|
|
|
|
) {
|
2017-08-03 00:27:58 +03:00
|
|
|
GeckoElement(element).note_explicit_hints(restyle_hint, change_hint);
|
2016-11-25 20:00:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_TakeChangeHint(element: &RawGeckoElement, was_restyled: *mut bool) -> u32 {
|
2018-11-20 07:37:53 +03:00
|
|
|
let was_restyled = unsafe { was_restyled.as_mut().unwrap() };
|
2016-11-25 20:00:44 +03:00
|
|
|
let element = GeckoElement(element);
|
2017-07-15 07:07:38 +03:00
|
|
|
|
2017-06-16 06:28:56 +03:00
|
|
|
let damage = match element.mutate_data() {
|
|
|
|
Some(mut data) => {
|
2017-09-12 21:16:26 +03:00
|
|
|
*was_restyled = data.is_restyle();
|
2017-07-15 07:07:38 +03:00
|
|
|
|
2017-09-12 21:16:26 +03:00
|
|
|
let damage = data.damage;
|
2017-08-12 05:15:12 +03:00
|
|
|
data.clear_restyle_state();
|
2017-06-16 06:28:56 +03:00
|
|
|
damage
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-06-16 06:28:56 +03:00
|
|
|
None => {
|
|
|
|
warn!("Trying to get change hint from unstyled element");
|
2017-07-15 07:07:38 +03:00
|
|
|
*was_restyled = false;
|
2017-06-16 06:28:56 +03:00
|
|
|
GeckoRestyleDamage::empty()
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-01-10 04:26:50 +03:00
|
|
|
};
|
2016-11-25 20:00:44 +03:00
|
|
|
|
2017-01-10 04:26:50 +03:00
|
|
|
debug!("Servo_TakeChangeHint: {:?}, damage={:?}", element, damage);
|
2017-08-16 06:11:50 +03:00
|
|
|
// We'd like to return `nsChangeHint` here, but bindgen bitfield enums don't
|
|
|
|
// work as return values with the Linux 32-bit ABI at the moment because
|
|
|
|
// they wrap the value in a struct, so for now just unwrap it.
|
|
|
|
damage.as_change_hint().0
|
2016-11-25 20:00:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_ResolveStyle(element: &RawGeckoElement) -> Strong<ComputedValues> {
|
2016-11-25 20:00:44 +03:00
|
|
|
let element = GeckoElement(element);
|
2017-01-10 04:26:50 +03:00
|
|
|
debug!("Servo_ResolveStyle: {:?}", element);
|
2018-11-20 07:37:53 +03:00
|
|
|
let data = element
|
|
|
|
.borrow_data()
|
|
|
|
.expect("Resolving style on unstyled element");
|
2016-12-10 04:01:05 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
debug_assert!(
|
|
|
|
element.has_current_styles(&*data),
|
|
|
|
"Resolving style on {:?} without current styles: {:?}",
|
|
|
|
element,
|
|
|
|
data
|
|
|
|
);
|
2017-07-21 21:05:13 +03:00
|
|
|
data.styles.primary().clone().into()
|
2016-11-25 20:00:44 +03:00
|
|
|
}
|
2016-07-22 00:54:34 +03:00
|
|
|
|
2017-07-28 02:29:29 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_ResolveStyleLazily(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
pseudo_type: PseudoStyleType,
|
2017-10-13 22:11:02 +03:00
|
|
|
rule_inclusion: StyleRuleInclusion,
|
|
|
|
snapshots: *const ServoElementSnapshotTable,
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2017-05-10 23:08:59 +03:00
|
|
|
debug_assert!(!snapshots.is_null());
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2016-12-28 06:55:01 +03:00
|
|
|
let element = GeckoElement(element);
|
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_data);
|
2017-06-14 12:00:07 +03:00
|
|
|
let data = doc_data.borrow();
|
2017-05-25 13:50:52 +03:00
|
|
|
let rule_inclusion = RuleInclusion::from(rule_inclusion);
|
2017-08-25 10:30:50 +03:00
|
|
|
let pseudo = PseudoElement::from_pseudo_type(pseudo_type);
|
|
|
|
let finish = |styles: &ElementStyles, is_probe: bool| -> Option<Arc<ComputedValues>> {
|
|
|
|
match pseudo {
|
2017-06-24 09:58:16 +03:00
|
|
|
Some(ref pseudo) => {
|
|
|
|
get_pseudo_style(
|
|
|
|
&guard,
|
|
|
|
element,
|
|
|
|
pseudo,
|
|
|
|
rule_inclusion,
|
|
|
|
styles,
|
2017-06-27 09:46:13 +03:00
|
|
|
/* inherited_styles = */ None,
|
2017-06-24 09:58:16 +03:00
|
|
|
&*data,
|
2017-08-25 10:30:50 +03:00
|
|
|
is_probe,
|
2017-10-20 12:18:53 +03:00
|
|
|
/* matching_func = */ None,
|
2017-08-25 10:30:50 +03:00
|
|
|
)
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-08-25 10:30:50 +03:00
|
|
|
None => Some(styles.primary().clone()),
|
2017-06-24 09:58:16 +03:00
|
|
|
}
|
2016-12-28 06:55:01 +03:00
|
|
|
};
|
|
|
|
|
2017-08-25 10:30:50 +03:00
|
|
|
let is_before_or_after = pseudo.as_ref().map_or(false, |p| p.is_before_or_after());
|
|
|
|
|
2016-12-28 06:55:01 +03:00
|
|
|
// In the common case we already have the style. Check that before setting
|
2018-02-21 14:09:15 +03:00
|
|
|
// up all the computation machinery.
|
2017-08-25 10:30:50 +03:00
|
|
|
//
|
|
|
|
// Also, only probe in the ::before or ::after case, since their styles may
|
|
|
|
// not be in the `ElementData`, given they may exist but not be applicable
|
|
|
|
// to generate an actual pseudo-element (like, having a `content: none`).
|
2018-02-21 14:09:15 +03:00
|
|
|
if rule_inclusion == RuleInclusion::All {
|
2017-06-23 03:46:55 +03:00
|
|
|
let styles = element.mutate_data().and_then(|d| {
|
|
|
|
if d.has_styles() {
|
2017-08-25 10:30:50 +03:00
|
|
|
finish(&d.styles, is_before_or_after)
|
2017-06-23 03:46:55 +03:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if let Some(result) = styles {
|
2017-07-21 21:05:13 +03:00
|
|
|
return result.into();
|
2017-05-25 13:50:52 +03:00
|
|
|
}
|
2016-12-28 06:55:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We don't have the style ready. Go ahead and compute it as necessary.
|
2018-11-20 07:37:53 +03:00
|
|
|
let shared = create_shared_context(
|
|
|
|
&global_style_data,
|
|
|
|
&guard,
|
|
|
|
&data,
|
|
|
|
TraversalFlags::empty(),
|
|
|
|
unsafe { &*snapshots },
|
|
|
|
);
|
2016-12-28 06:55:01 +03:00
|
|
|
let mut tlc = ThreadLocalStyleContext::new(&shared);
|
|
|
|
let mut context = StyleContext {
|
|
|
|
shared: &shared,
|
|
|
|
thread_local: &mut tlc,
|
|
|
|
};
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let styles = resolve_style(&mut context, element, rule_inclusion, pseudo.as_ref());
|
2017-08-25 10:30:50 +03:00
|
|
|
|
|
|
|
finish(&styles, /* is_probe = */ false)
|
|
|
|
.expect("We're not probing, so we should always get a style back")
|
|
|
|
.into()
|
2016-12-28 06:55:01 +03:00
|
|
|
}
|
|
|
|
|
2017-07-29 06:51:20 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_ReparentStyle(
|
2019-03-21 20:00:27 +03:00
|
|
|
style_to_reparent: &ComputedValues,
|
|
|
|
parent_style: &ComputedValues,
|
|
|
|
parent_style_ignoring_first_line: &ComputedValues,
|
|
|
|
layout_parent_style: &ComputedValues,
|
|
|
|
element: Option<&RawGeckoElement>,
|
|
|
|
raw_data: &RawServoStyleSet,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2017-07-29 06:51:20 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
let inputs = CascadeInputs::new_from_style(style_to_reparent);
|
|
|
|
let metrics = get_metrics_provider_for_product();
|
|
|
|
let pseudo = style_to_reparent.pseudo();
|
|
|
|
let element = element.map(GeckoElement);
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
doc_data
|
|
|
|
.stylist
|
|
|
|
.cascade_style_and_visited(
|
|
|
|
element,
|
|
|
|
pseudo.as_ref(),
|
|
|
|
inputs,
|
|
|
|
&StylesheetGuards::same(&guard),
|
|
|
|
Some(parent_style),
|
|
|
|
Some(parent_style_ignoring_first_line),
|
|
|
|
Some(layout_parent_style),
|
|
|
|
&metrics,
|
|
|
|
/* rule_cache = */ None,
|
|
|
|
&mut RuleCacheConditions::default(),
|
|
|
|
)
|
|
|
|
.into()
|
2017-07-29 06:51:20 +03:00
|
|
|
}
|
|
|
|
|
2017-05-31 20:03:50 +03:00
|
|
|
#[cfg(feature = "gecko_debug")]
|
|
|
|
fn simulate_compute_values_failure(property: &PropertyValuePair) -> bool {
|
|
|
|
let p = property.mProperty;
|
|
|
|
let id = get_property_id_from_nscsspropertyid!(p, false);
|
|
|
|
id.as_shorthand().is_ok() && property.mSimulateComputeValuesFailure
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "gecko_debug"))]
|
|
|
|
fn simulate_compute_values_failure(_: &PropertyValuePair) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2018-02-03 20:24:23 +03:00
|
|
|
fn create_context_for_animation<'a>(
|
2017-07-20 12:36:15 +03:00
|
|
|
per_doc_data: &'a PerDocumentStyleDataImpl,
|
2019-06-19 00:32:16 +03:00
|
|
|
font_metrics_provider: &'a dyn FontMetricsProvider,
|
2017-07-20 12:36:15 +03:00
|
|
|
style: &'a ComputedValues,
|
|
|
|
parent_style: Option<&'a ComputedValues>,
|
2017-07-25 05:13:08 +03:00
|
|
|
for_smil_animation: bool,
|
2017-09-14 12:28:50 +03:00
|
|
|
rule_cache_conditions: &'a mut RuleCacheConditions,
|
2017-07-20 12:36:15 +03:00
|
|
|
) -> Context<'a> {
|
2017-06-02 06:56:48 +03:00
|
|
|
Context {
|
|
|
|
is_root_element: false,
|
2018-11-20 07:37:53 +03:00
|
|
|
builder: StyleBuilder::for_animation(per_doc_data.stylist.device(), style, parent_style),
|
2017-06-02 06:56:48 +03:00
|
|
|
font_metrics_provider: font_metrics_provider,
|
|
|
|
cached_system_font: None,
|
|
|
|
in_media_query: false,
|
|
|
|
quirks_mode: per_doc_data.stylist.quirks_mode(),
|
2017-07-25 05:13:08 +03:00
|
|
|
for_smil_animation,
|
2017-09-14 12:28:50 +03:00
|
|
|
for_non_inherited_property: None,
|
|
|
|
rule_cache_conditions: RefCell::new(rule_cache_conditions),
|
2017-06-02 06:56:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:54:12 +03:00
|
|
|
struct PropertyAndIndex {
|
|
|
|
property: PropertyId,
|
|
|
|
index: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PrioritizedPropertyIter<'a> {
|
2018-02-21 07:49:19 +03:00
|
|
|
properties: &'a [PropertyValuePair],
|
2017-07-24 07:54:12 +03:00
|
|
|
sorted_property_indices: Vec<PropertyAndIndex>,
|
|
|
|
curr: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> PrioritizedPropertyIter<'a> {
|
2018-02-21 07:49:19 +03:00
|
|
|
fn new(properties: &'a [PropertyValuePair]) -> PrioritizedPropertyIter {
|
2018-11-05 02:12:24 +03:00
|
|
|
use style::values::animated::compare_property_priority;
|
|
|
|
|
2018-02-21 07:49:19 +03:00
|
|
|
// If we fail to convert a nsCSSPropertyID into a PropertyId we
|
|
|
|
// shouldn't fail outright but instead by treating that property as the
|
|
|
|
// 'all' property we make it sort last.
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut sorted_property_indices: Vec<PropertyAndIndex> = properties
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(index, pair)| {
|
|
|
|
let property = PropertyId::from_nscsspropertyid(pair.mProperty)
|
|
|
|
.unwrap_or(PropertyId::Shorthand(ShorthandId::All));
|
2018-02-21 07:49:19 +03:00
|
|
|
|
|
|
|
PropertyAndIndex { property, index }
|
2018-11-20 07:37:53 +03:00
|
|
|
})
|
|
|
|
.collect();
|
2017-07-24 07:54:12 +03:00
|
|
|
sorted_property_indices.sort_by(|a, b| compare_property_priority(&a.property, &b.property));
|
|
|
|
|
|
|
|
PrioritizedPropertyIter {
|
|
|
|
properties,
|
|
|
|
sorted_property_indices,
|
|
|
|
curr: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Iterator for PrioritizedPropertyIter<'a> {
|
|
|
|
type Item = &'a PropertyValuePair;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<&'a PropertyValuePair> {
|
|
|
|
if self.curr >= self.sorted_property_indices.len() {
|
2018-11-20 07:37:53 +03:00
|
|
|
return None;
|
2017-07-24 07:54:12 +03:00
|
|
|
}
|
|
|
|
self.curr += 1;
|
|
|
|
Some(&self.properties[self.sorted_property_indices[self.curr - 1].index])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 15:09:33 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_GetComputedKeyframeValues(
|
2019-03-21 20:00:27 +03:00
|
|
|
keyframes: &nsTArray<structs::Keyframe>,
|
|
|
|
element: &RawGeckoElement,
|
|
|
|
style: &ComputedValues,
|
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
computed_keyframes: &mut nsTArray<structs::ComputedKeyframeValues>,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-03-11 15:40:31 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2017-06-02 06:56:48 +03:00
|
|
|
let metrics = get_metrics_provider_for_product();
|
2017-03-11 15:40:31 +03:00
|
|
|
|
2017-06-02 06:56:48 +03:00
|
|
|
let element = GeckoElement(element);
|
|
|
|
let parent_element = element.inheritance_parent();
|
|
|
|
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
|
2018-11-20 07:37:53 +03:00
|
|
|
let parent_style = parent_data
|
|
|
|
.as_ref()
|
|
|
|
.map(|d| d.styles.primary())
|
|
|
|
.map(|x| &**x);
|
2017-02-24 15:09:33 +03:00
|
|
|
|
2017-09-14 12:28:50 +03:00
|
|
|
let mut conditions = Default::default();
|
2018-02-03 20:24:23 +03:00
|
|
|
let mut context = create_context_for_animation(
|
2017-07-25 05:13:08 +03:00
|
|
|
&data,
|
|
|
|
&metrics,
|
|
|
|
&style,
|
|
|
|
parent_style,
|
|
|
|
/* for_smil_animation = */ false,
|
2017-09-14 12:28:50 +03:00
|
|
|
&mut conditions,
|
2017-07-25 05:13:08 +03:00
|
|
|
);
|
2017-06-02 06:56:48 +03:00
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let default_values = data.default_computed_values();
|
2017-02-24 15:09:33 +03:00
|
|
|
|
2017-09-27 12:35:00 +03:00
|
|
|
let mut raw_custom_properties_block; // To make the raw block alive in the scope.
|
2017-02-24 15:09:33 +03:00
|
|
|
for (index, keyframe) in keyframes.iter().enumerate() {
|
2017-09-27 12:35:00 +03:00
|
|
|
let mut custom_properties = None;
|
|
|
|
for property in keyframe.mPropertyValues.iter() {
|
|
|
|
// Find the block for custom properties first.
|
|
|
|
if property.mProperty == nsCSSPropertyID::eCSSPropertyExtra_variable {
|
2018-11-20 07:37:53 +03:00
|
|
|
raw_custom_properties_block =
|
|
|
|
unsafe { &*property.mServoDeclarationBlock.mRawPtr.clone() };
|
|
|
|
let guard =
|
|
|
|
Locked::<PropertyDeclarationBlock>::as_arc(&raw_custom_properties_block)
|
|
|
|
.read_with(&guard);
|
2017-09-27 12:35:00 +03:00
|
|
|
custom_properties = guard.cascade_custom_properties_with_context(&context);
|
|
|
|
// There should be one PropertyDeclarationBlock for custom properties.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 15:09:33 +03:00
|
|
|
let ref mut animation_values = computed_keyframes[index];
|
|
|
|
|
2017-02-27 01:09:44 +03:00
|
|
|
let mut seen = LonghandIdSet::new();
|
2017-02-24 15:09:33 +03:00
|
|
|
|
2017-05-02 14:03:40 +03:00
|
|
|
let mut property_index = 0;
|
2017-07-24 07:54:12 +03:00
|
|
|
for property in PrioritizedPropertyIter::new(&keyframe.mPropertyValues) {
|
2017-05-31 20:03:50 +03:00
|
|
|
if simulate_compute_values_failure(property) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut maybe_append_animation_value =
|
|
|
|
|property: LonghandId, value: Option<AnimationValue>| {
|
|
|
|
debug_assert!(!property.is_logical());
|
2019-04-26 03:47:40 +03:00
|
|
|
debug_assert!(property.is_animatable());
|
|
|
|
|
|
|
|
// 'display' is only animatable from SMIL
|
|
|
|
if property == LonghandId::Display {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
if seen.contains(property) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seen.insert(property);
|
|
|
|
|
|
|
|
// This is safe since we immediately write to the uninitialized values.
|
|
|
|
unsafe { animation_values.set_len((property_index + 1) as u32) };
|
|
|
|
animation_values[property_index].mProperty = property.to_nscsspropertyid();
|
|
|
|
match value {
|
|
|
|
Some(v) => {
|
|
|
|
animation_values[property_index]
|
|
|
|
.mValue
|
|
|
|
.mServo
|
|
|
|
.set_arc_leaky(Arc::new(v));
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
animation_values[property_index].mValue.mServo.mRawPtr =
|
|
|
|
ptr::null_mut();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
property_index += 1;
|
|
|
|
};
|
2017-07-10 12:31:35 +03:00
|
|
|
|
|
|
|
if property.mServoDeclarationBlock.mRawPtr.is_null() {
|
2018-11-20 07:37:53 +03:00
|
|
|
let property = LonghandId::from_nscsspropertyid(property.mProperty);
|
2017-09-29 18:01:52 +03:00
|
|
|
if let Ok(prop) = property {
|
|
|
|
maybe_append_animation_value(prop, None);
|
2017-07-10 12:31:35 +03:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-02-24 15:09:33 +03:00
|
|
|
let declarations = unsafe { &*property.mServoDeclarationBlock.mRawPtr.clone() };
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
let guard = declarations.read_with(&guard);
|
2017-09-27 12:35:00 +03:00
|
|
|
let iter = guard.to_animation_value_iter(
|
|
|
|
&mut context,
|
|
|
|
&default_values,
|
2017-10-01 21:30:18 +03:00
|
|
|
custom_properties.as_ref(),
|
2017-09-27 12:35:00 +03:00
|
|
|
);
|
2017-02-24 15:09:33 +03:00
|
|
|
|
2017-09-29 18:01:52 +03:00
|
|
|
for value in iter {
|
|
|
|
let id = value.id();
|
|
|
|
maybe_append_animation_value(id, Some(value));
|
2017-02-24 15:09:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-09 02:23:56 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_GetAnimationValues(
|
2019-03-21 20:00:27 +03:00
|
|
|
declarations: &RawServoDeclarationBlock,
|
|
|
|
element: &RawGeckoElement,
|
|
|
|
style: &ComputedValues,
|
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
animation_values: &mut nsTArray<structs::RefPtr<structs::RawServoAnimationValue>>,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-06-09 02:23:56 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
let metrics = get_metrics_provider_for_product();
|
|
|
|
|
|
|
|
let element = GeckoElement(element);
|
|
|
|
let parent_element = element.inheritance_parent();
|
|
|
|
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
|
2018-11-20 07:37:53 +03:00
|
|
|
let parent_style = parent_data
|
|
|
|
.as_ref()
|
|
|
|
.map(|d| d.styles.primary())
|
|
|
|
.map(|x| &**x);
|
2017-06-09 02:23:56 +03:00
|
|
|
|
2017-09-14 12:28:50 +03:00
|
|
|
let mut conditions = Default::default();
|
2018-02-03 20:24:23 +03:00
|
|
|
let mut context = create_context_for_animation(
|
2017-07-25 05:13:08 +03:00
|
|
|
&data,
|
|
|
|
&metrics,
|
|
|
|
&style,
|
|
|
|
parent_style,
|
2017-09-14 12:28:50 +03:00
|
|
|
/* for_smil_animation = */ true,
|
|
|
|
&mut conditions,
|
2017-07-25 05:13:08 +03:00
|
|
|
);
|
2017-06-09 02:23:56 +03:00
|
|
|
|
|
|
|
let default_values = data.default_computed_values();
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
|
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
let guard = declarations.read_with(&guard);
|
2017-09-27 12:35:00 +03:00
|
|
|
let iter = guard.to_animation_value_iter(
|
|
|
|
&mut context,
|
|
|
|
&default_values,
|
2017-10-01 21:30:18 +03:00
|
|
|
None, // SMIL has no extra custom properties.
|
2017-09-27 12:35:00 +03:00
|
|
|
);
|
|
|
|
for (index, anim) in iter.enumerate() {
|
2017-06-09 02:23:56 +03:00
|
|
|
unsafe { animation_values.set_len((index + 1) as u32) };
|
2017-09-29 18:01:52 +03:00
|
|
|
animation_values[index].set_arc_leaky(Arc::new(anim));
|
2017-06-09 02:23:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 02:25:10 +03:00
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValue_GetPropertyId(
|
|
|
|
value: &RawServoAnimationValue,
|
|
|
|
) -> nsCSSPropertyID {
|
2019-05-17 02:25:10 +03:00
|
|
|
let value = AnimationValue::as_arc(&value);
|
|
|
|
value.id().to_nscsspropertyid()
|
|
|
|
}
|
|
|
|
|
2017-05-03 07:46:15 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_AnimationValue_Compute(
|
2019-03-21 20:00:27 +03:00
|
|
|
element: &RawGeckoElement,
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
|
|
|
style: &ComputedValues,
|
|
|
|
raw_data: &RawServoStyleSet,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<RawServoAnimationValue> {
|
2017-05-03 07:46:15 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
let metrics = get_metrics_provider_for_product();
|
|
|
|
|
2017-06-02 06:56:48 +03:00
|
|
|
let element = GeckoElement(element);
|
|
|
|
let parent_element = element.inheritance_parent();
|
|
|
|
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
|
2018-11-20 07:37:53 +03:00
|
|
|
let parent_style = parent_data
|
|
|
|
.as_ref()
|
|
|
|
.map(|d| d.styles.primary())
|
|
|
|
.map(|x| &**x);
|
2017-06-02 06:56:48 +03:00
|
|
|
|
2017-09-14 12:28:50 +03:00
|
|
|
let mut conditions = Default::default();
|
2018-02-03 20:24:23 +03:00
|
|
|
let mut context = create_context_for_animation(
|
2017-07-25 05:13:08 +03:00
|
|
|
&data,
|
|
|
|
&metrics,
|
|
|
|
style,
|
|
|
|
parent_style,
|
2017-09-14 12:28:50 +03:00
|
|
|
/* for_smil_animation = */ false,
|
|
|
|
&mut conditions,
|
2017-07-25 05:13:08 +03:00
|
|
|
);
|
2017-06-02 06:56:48 +03:00
|
|
|
|
|
|
|
let default_values = data.default_computed_values();
|
2017-05-03 07:46:15 +03:00
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
// We only compute the first element in declarations.
|
2018-11-20 07:37:53 +03:00
|
|
|
match declarations
|
|
|
|
.read_with(&guard)
|
|
|
|
.declaration_importance_iter()
|
|
|
|
.next()
|
|
|
|
{
|
2017-09-11 16:57:07 +03:00
|
|
|
Some((decl, imp)) if imp == Importance::Normal => {
|
2017-09-27 12:35:00 +03:00
|
|
|
let animation = AnimationValue::from_declaration(
|
|
|
|
decl,
|
|
|
|
&mut context,
|
2017-10-01 21:30:18 +03:00
|
|
|
None, // No extra custom properties for devtools.
|
2017-09-27 12:35:00 +03:00
|
|
|
default_values,
|
|
|
|
);
|
2019-08-26 12:58:53 +03:00
|
|
|
animation.map_or(Strong::null(), |value| Arc::new(value).into_strong())
|
2017-05-03 07:46:15 +03:00
|
|
|
},
|
2019-03-21 20:00:27 +03:00
|
|
|
_ => Strong::null(),
|
2017-05-03 07:46:15 +03:00
|
|
|
}
|
|
|
|
}
|
2016-12-28 06:55:01 +03:00
|
|
|
|
2016-11-25 20:00:44 +03:00
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_AssertTreeIsClean(root: &RawGeckoElement) {
|
2017-04-23 02:40:47 +03:00
|
|
|
if !cfg!(feature = "gecko_debug") {
|
2016-11-25 20:00:44 +03:00
|
|
|
panic!("Calling Servo_AssertTreeIsClean in release build");
|
|
|
|
}
|
|
|
|
|
|
|
|
let root = GeckoElement(root);
|
2017-08-27 02:13:40 +03:00
|
|
|
debug!("Servo_AssertTreeIsClean: ");
|
|
|
|
debug!("{:?}", ShowSubtreeData(root.as_node()));
|
|
|
|
|
2016-11-25 20:00:44 +03:00
|
|
|
fn assert_subtree_is_clean<'le>(el: GeckoElement<'le>) {
|
2018-11-20 07:37:53 +03:00
|
|
|
debug_assert!(
|
|
|
|
!el.has_dirty_descendants() && !el.has_animation_only_dirty_descendants(),
|
|
|
|
"{:?} has still dirty bit {:?} or animation-only dirty bit {:?}",
|
|
|
|
el,
|
|
|
|
el.has_dirty_descendants(),
|
|
|
|
el.has_animation_only_dirty_descendants()
|
|
|
|
);
|
2017-10-17 13:18:29 +03:00
|
|
|
for child in el.traversal_children() {
|
2016-11-25 20:00:44 +03:00
|
|
|
if let Some(child) = child.as_element() {
|
|
|
|
assert_subtree_is_clean(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-22 00:54:34 +03:00
|
|
|
|
2016-11-25 20:00:44 +03:00
|
|
|
assert_subtree_is_clean(root);
|
2016-07-22 00:54:34 +03:00
|
|
|
}
|
2017-01-29 08:24:04 +03:00
|
|
|
|
2017-09-19 07:58:53 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_IsWorkerThread() -> bool {
|
|
|
|
thread_state::get().is_worker()
|
|
|
|
}
|
|
|
|
|
2017-05-24 12:26:19 +03:00
|
|
|
enum Offset {
|
|
|
|
Zero,
|
2018-11-20 07:37:53 +03:00
|
|
|
One,
|
2017-05-24 12:26:19 +03:00
|
|
|
}
|
|
|
|
|
2017-09-29 18:01:52 +03:00
|
|
|
fn fill_in_missing_keyframe_values(
|
|
|
|
all_properties: &LonghandIdSet,
|
2019-03-21 20:00:27 +03:00
|
|
|
timing_function: &nsTimingFunction,
|
2017-09-29 18:01:52 +03:00
|
|
|
longhands_at_offset: &LonghandIdSet,
|
|
|
|
offset: Offset,
|
2019-03-21 20:00:27 +03:00
|
|
|
keyframes: &mut nsTArray<structs::Keyframe>,
|
2017-09-29 18:01:52 +03:00
|
|
|
) {
|
|
|
|
// Return early if all animated properties are already set.
|
|
|
|
if longhands_at_offset.contains_all(all_properties) {
|
2017-05-13 22:05:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let keyframe = match offset {
|
2018-11-20 07:37:53 +03:00
|
|
|
Offset::Zero => unsafe { Gecko_GetOrCreateInitialKeyframe(keyframes, timing_function) },
|
|
|
|
Offset::One => unsafe { Gecko_GetOrCreateFinalKeyframe(keyframes, timing_function) },
|
2017-05-13 22:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Append properties that have not been set at this offset.
|
2017-09-29 18:01:52 +03:00
|
|
|
for property in all_properties.iter() {
|
|
|
|
if !longhands_at_offset.contains(property) {
|
|
|
|
unsafe {
|
|
|
|
Gecko_AppendPropertyValuePair(
|
|
|
|
&mut (*keyframe).mPropertyValues,
|
2018-11-20 07:37:53 +03:00
|
|
|
property.to_nscsspropertyid(),
|
2017-09-29 18:01:52 +03:00
|
|
|
);
|
|
|
|
}
|
2017-05-13 22:05:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2018-03-19 13:11:14 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_GetKeyframesForName(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
element: &RawGeckoElement,
|
|
|
|
style: &ComputedValues,
|
2017-10-13 22:11:02 +03:00
|
|
|
name: *mut nsAtom,
|
2019-03-21 20:00:27 +03:00
|
|
|
inherited_timing_function: &nsTimingFunction,
|
|
|
|
keyframes: &mut nsTArray<structs::Keyframe>,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2018-05-01 08:09:12 +03:00
|
|
|
debug_assert!(keyframes.len() == 0, "keyframes should be initially empty");
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
|
2018-05-01 08:09:12 +03:00
|
|
|
let element = GeckoElement(element);
|
2017-03-10 07:23:21 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2018-03-19 13:11:14 +03:00
|
|
|
let name = Atom::from_raw(name);
|
2017-05-13 22:05:40 +03:00
|
|
|
|
2018-05-01 08:09:12 +03:00
|
|
|
let animation = match data.stylist.get_animation(&name, element) {
|
2017-05-13 22:05:40 +03:00
|
|
|
Some(animation) => animation,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
2017-01-29 08:24:04 +03:00
|
|
|
|
2017-05-13 22:05:40 +03:00
|
|
|
let mut properties_set_at_current_offset = LonghandIdSet::new();
|
|
|
|
let mut properties_set_at_start = LonghandIdSet::new();
|
|
|
|
let mut properties_set_at_end = LonghandIdSet::new();
|
|
|
|
let mut has_complete_initial_keyframe = false;
|
|
|
|
let mut has_complete_final_keyframe = false;
|
|
|
|
let mut current_offset = -1.;
|
|
|
|
|
2018-07-06 06:19:10 +03:00
|
|
|
let writing_mode = style.writing_mode;
|
|
|
|
|
2017-05-13 22:05:40 +03:00
|
|
|
// Iterate over the keyframe rules backwards so we can drop overridden
|
|
|
|
// properties (since declarations in later rules override those in earlier
|
|
|
|
// ones).
|
|
|
|
for step in animation.steps.iter().rev() {
|
|
|
|
if step.start_percentage.0 != current_offset {
|
|
|
|
properties_set_at_current_offset.clear();
|
|
|
|
current_offset = step.start_percentage.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override timing_function if the keyframe has an animation-timing-function.
|
2018-10-26 21:03:35 +03:00
|
|
|
let timing_function = nsTimingFunction {
|
|
|
|
mTiming: match step.get_animation_timing_function(&guard) {
|
|
|
|
Some(val) => val.to_computed_value_without_context(),
|
|
|
|
None => (*inherited_timing_function).mTiming,
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-05-13 22:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Look for an existing keyframe with the same offset and timing
|
|
|
|
// function or else add a new keyframe at the beginning of the keyframe
|
|
|
|
// array.
|
2018-03-19 13:11:14 +03:00
|
|
|
let keyframe = Gecko_GetOrCreateKeyframeAtStart(
|
|
|
|
keyframes,
|
|
|
|
step.start_percentage.0 as f32,
|
|
|
|
&timing_function,
|
|
|
|
);
|
2017-05-13 22:05:40 +03:00
|
|
|
|
|
|
|
match step.value {
|
|
|
|
KeyframesStepValue::ComputedValues => {
|
|
|
|
// In KeyframesAnimation::from_keyframes if there is no 0% or
|
|
|
|
// 100% keyframe at all, we will create a 'ComputedValues' step
|
|
|
|
// to represent that all properties animated by the keyframes
|
|
|
|
// animation should be set to the underlying computed value for
|
|
|
|
// that keyframe.
|
2018-07-06 06:19:10 +03:00
|
|
|
let mut seen = LonghandIdSet::new();
|
2017-05-13 22:05:40 +03:00
|
|
|
for property in animation.properties_changed.iter() {
|
2018-07-06 06:19:10 +03:00
|
|
|
let property = property.to_physical(writing_mode);
|
|
|
|
if seen.contains(property) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
seen.insert(property);
|
|
|
|
|
2018-03-19 13:11:14 +03:00
|
|
|
Gecko_AppendPropertyValuePair(
|
|
|
|
&mut (*keyframe).mPropertyValues,
|
|
|
|
property.to_nscsspropertyid(),
|
|
|
|
);
|
2017-04-19 11:06:31 +03:00
|
|
|
}
|
2017-05-13 22:05:40 +03:00
|
|
|
if current_offset == 0.0 {
|
|
|
|
has_complete_initial_keyframe = true;
|
|
|
|
} else if current_offset == 1.0 {
|
|
|
|
has_complete_final_keyframe = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
KeyframesStepValue::Declarations { ref block } => {
|
|
|
|
let guard = block.read_with(&guard);
|
2017-09-29 18:01:52 +03:00
|
|
|
|
|
|
|
let mut custom_properties = PropertyDeclarationBlock::new();
|
|
|
|
|
|
|
|
// Filter out non-animatable properties and properties with
|
|
|
|
// !important.
|
2018-07-06 06:19:10 +03:00
|
|
|
//
|
|
|
|
// Also, iterate in reverse to respect the source order in case
|
|
|
|
// there are logical and physical longhands in the same block.
|
|
|
|
for declaration in guard.normal_declaration_iter().rev() {
|
2017-09-29 18:01:52 +03:00
|
|
|
let id = declaration.id();
|
|
|
|
|
|
|
|
let id = match id {
|
|
|
|
PropertyDeclarationId::Longhand(id) => {
|
|
|
|
// Skip the 'display' property because although it
|
|
|
|
// is animatable from SMIL, it should not be
|
|
|
|
// animatable from CSS Animations.
|
|
|
|
if id == LonghandId::Display {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if !id.is_animatable() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-06 06:19:10 +03:00
|
|
|
id.to_physical(writing_mode)
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-09-29 18:01:52 +03:00
|
|
|
PropertyDeclarationId::Custom(..) => {
|
2018-11-20 07:37:53 +03:00
|
|
|
custom_properties.push(declaration.clone(), Importance::Normal);
|
2017-09-29 18:01:52 +03:00
|
|
|
continue;
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-09-29 18:01:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if properties_set_at_current_offset.contains(id) {
|
|
|
|
continue;
|
2017-09-27 12:35:00 +03:00
|
|
|
}
|
2017-09-29 18:01:52 +03:00
|
|
|
|
2018-03-19 13:11:14 +03:00
|
|
|
let pair = Gecko_AppendPropertyValuePair(
|
|
|
|
&mut (*keyframe).mPropertyValues,
|
|
|
|
id.to_nscsspropertyid(),
|
|
|
|
);
|
2017-09-29 18:01:52 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
(*pair).mServoDeclarationBlock.set_arc_leaky(Arc::new(
|
|
|
|
global_style_data
|
|
|
|
.shared_lock
|
|
|
|
.wrap(PropertyDeclarationBlock::with_one(
|
2018-07-06 06:19:10 +03:00
|
|
|
declaration.to_physical(writing_mode),
|
2018-03-19 13:11:14 +03:00
|
|
|
Importance::Normal,
|
2018-11-20 07:37:53 +03:00
|
|
|
)),
|
|
|
|
));
|
2017-09-29 18:01:52 +03:00
|
|
|
|
|
|
|
if current_offset == 0.0 {
|
|
|
|
properties_set_at_start.insert(id);
|
|
|
|
} else if current_offset == 1.0 {
|
|
|
|
properties_set_at_end.insert(id);
|
2017-09-27 12:35:00 +03:00
|
|
|
}
|
2017-09-29 18:01:52 +03:00
|
|
|
properties_set_at_current_offset.insert(id);
|
2017-09-27 12:35:00 +03:00
|
|
|
}
|
|
|
|
|
2017-09-29 18:01:52 +03:00
|
|
|
if custom_properties.any_normal() {
|
2018-03-19 13:11:14 +03:00
|
|
|
let pair = Gecko_AppendPropertyValuePair(
|
|
|
|
&mut (*keyframe).mPropertyValues,
|
|
|
|
nsCSSPropertyID::eCSSPropertyExtra_variable,
|
|
|
|
);
|
2017-09-29 18:01:52 +03:00
|
|
|
|
2018-03-19 13:11:14 +03:00
|
|
|
(*pair).mServoDeclarationBlock.set_arc_leaky(Arc::new(
|
2018-11-20 07:37:53 +03:00
|
|
|
global_style_data.shared_lock.wrap(custom_properties),
|
2018-03-19 13:11:14 +03:00
|
|
|
));
|
2017-05-13 22:05:40 +03:00
|
|
|
}
|
|
|
|
},
|
2017-04-19 11:06:31 +03:00
|
|
|
}
|
2017-01-29 08:24:04 +03:00
|
|
|
}
|
2017-05-13 22:05:40 +03:00
|
|
|
|
2018-07-06 06:19:10 +03:00
|
|
|
let mut properties_changed = LonghandIdSet::new();
|
|
|
|
for property in animation.properties_changed.iter() {
|
|
|
|
properties_changed.insert(property.to_physical(writing_mode));
|
|
|
|
}
|
|
|
|
|
2017-05-13 22:05:40 +03:00
|
|
|
// Append property values that are missing in the initial or the final keyframes.
|
|
|
|
if !has_complete_initial_keyframe {
|
2017-09-29 18:01:52 +03:00
|
|
|
fill_in_missing_keyframe_values(
|
2018-07-06 06:19:10 +03:00
|
|
|
&properties_changed,
|
2017-09-29 18:01:52 +03:00
|
|
|
inherited_timing_function,
|
|
|
|
&properties_set_at_start,
|
|
|
|
Offset::Zero,
|
|
|
|
keyframes,
|
|
|
|
);
|
2017-05-13 22:05:40 +03:00
|
|
|
}
|
|
|
|
if !has_complete_final_keyframe {
|
2017-09-29 18:01:52 +03:00
|
|
|
fill_in_missing_keyframe_values(
|
2018-07-06 06:19:10 +03:00
|
|
|
&properties_changed,
|
2017-09-29 18:01:52 +03:00
|
|
|
inherited_timing_function,
|
|
|
|
&properties_set_at_end,
|
|
|
|
Offset::One,
|
|
|
|
keyframes,
|
|
|
|
);
|
2017-05-13 22:05:40 +03:00
|
|
|
}
|
|
|
|
true
|
2017-01-29 08:24:04 +03:00
|
|
|
}
|
|
|
|
|
2017-03-30 04:50:47 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_GetFontFaceRules(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
rules: &mut nsTArray<structs::nsFontFaceRuleContainer>,
|
2017-10-13 22:11:02 +03:00
|
|
|
) {
|
2017-03-30 04:50:47 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2018-02-07 14:20:36 +03:00
|
|
|
debug_assert_eq!(rules.len(), 0);
|
2017-03-30 04:50:47 +03:00
|
|
|
|
2017-09-14 01:44:21 +03:00
|
|
|
let len: u32 = data
|
|
|
|
.stylist
|
|
|
|
.iter_extra_data_origins()
|
2017-08-11 08:40:18 +03:00
|
|
|
.map(|(d, _)| d.font_faces.len() as u32)
|
|
|
|
.sum();
|
|
|
|
|
2017-08-14 12:19:34 +03:00
|
|
|
// Reversed iterator because Gecko expects rules to appear sorted
|
|
|
|
// UserAgent first, Author last.
|
2017-09-14 01:44:21 +03:00
|
|
|
let font_face_iter = data
|
|
|
|
.stylist
|
|
|
|
.iter_extra_data_origins_rev()
|
2017-08-11 08:40:18 +03:00
|
|
|
.flat_map(|(d, o)| d.font_faces.iter().zip(iter::repeat(o)));
|
|
|
|
|
|
|
|
unsafe { rules.set_len(len) };
|
2019-04-19 07:20:31 +03:00
|
|
|
for ((rule, origin), dest) in font_face_iter.zip(rules.iter_mut()) {
|
|
|
|
dest.mRule.set_arc_leaky(rule.clone());
|
|
|
|
dest.mOrigin = origin;
|
2017-03-30 04:50:47 +03:00
|
|
|
}
|
|
|
|
}
|
2017-04-15 14:20:52 +03:00
|
|
|
|
2019-03-21 20:00:27 +03:00
|
|
|
// XXX Ideally this should return a Option<&RawServoCounterStyleRule>,
|
2018-04-05 02:34:06 +03:00
|
|
|
// but we cannot, because the value from AtomicRefCell::borrow() can only
|
|
|
|
// live in this function, and thus anything derived from it cannot get the
|
|
|
|
// same lifetime as raw_data in parameter. See bug 1451543.
|
2017-05-16 09:17:07 +03:00
|
|
|
#[no_mangle]
|
2018-04-05 02:34:06 +03:00
|
|
|
pub unsafe extern "C" fn Servo_StyleSet_GetCounterStyleRule(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2017-10-13 22:11:02 +03:00
|
|
|
name: *mut nsAtom,
|
2018-04-05 02:34:06 +03:00
|
|
|
) -> *const RawServoCounterStyleRule {
|
2017-05-16 09:17:07 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2018-04-05 02:34:06 +03:00
|
|
|
Atom::with(name, |name| {
|
|
|
|
data.stylist
|
|
|
|
.iter_extra_data_origins()
|
|
|
|
.filter_map(|(d, _)| d.counter_styles.get(name))
|
|
|
|
.next()
|
|
|
|
.map_or(ptr::null(), |rule| rule.as_borrowed())
|
|
|
|
})
|
2017-05-16 09:17:07 +03:00
|
|
|
}
|
|
|
|
|
2017-08-25 23:45:03 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSet_BuildFontFeatureValueSet(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> *mut gfxFontFeatureValueSet {
|
2017-08-25 23:45:03 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let has_rule = data
|
|
|
|
.stylist
|
|
|
|
.iter_extra_data_origins()
|
|
|
|
.any(|(d, _)| !d.font_feature_values.is_empty());
|
2017-09-06 02:35:55 +03:00
|
|
|
|
|
|
|
if !has_rule {
|
2018-11-20 07:37:53 +03:00
|
|
|
return ptr::null_mut();
|
2017-09-06 02:35:55 +03:00
|
|
|
}
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let font_feature_values_iter = data
|
|
|
|
.stylist
|
|
|
|
.iter_extra_data_origins_rev()
|
|
|
|
.flat_map(|(d, _)| d.font_feature_values.iter());
|
2017-08-25 23:45:03 +03:00
|
|
|
|
2017-09-06 02:35:55 +03:00
|
|
|
let set = unsafe { Gecko_ConstructFontFeatureValueSet() };
|
2017-08-25 23:45:03 +03:00
|
|
|
for src in font_feature_values_iter {
|
|
|
|
let rule = src.read_with(&guard);
|
|
|
|
rule.set_at_rules(set);
|
|
|
|
}
|
2017-09-06 02:35:55 +03:00
|
|
|
set
|
2017-08-25 23:45:03 +03:00
|
|
|
}
|
|
|
|
|
2017-04-15 14:20:52 +03:00
|
|
|
#[no_mangle]
|
2017-07-02 17:00:39 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
parent_style_context: Option<&ComputedValues>,
|
|
|
|
declarations: &RawServoDeclarationBlock,
|
2019-03-26 21:16:01 +03:00
|
|
|
) -> Strong<ComputedValues> {
|
2017-04-15 14:20:52 +03:00
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let guards = StylesheetGuards::same(&guard);
|
|
|
|
|
2017-07-18 05:44:25 +03:00
|
|
|
let parent_style = match parent_style_context {
|
2017-07-18 19:23:03 +03:00
|
|
|
Some(parent) => &*parent,
|
2017-04-15 14:20:52 +03:00
|
|
|
None => doc_data.default_computed_values(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
doc_data
|
|
|
|
.stylist
|
|
|
|
.compute_for_declarations::<GeckoElement>(&guards, parent_style, declarations.clone_arc())
|
|
|
|
.into()
|
2017-04-15 14:20:52 +03:00
|
|
|
}
|
2017-05-12 13:41:35 +03:00
|
|
|
|
2017-08-31 08:31:31 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSet_AddSizeOfExcludingThis(
|
|
|
|
malloc_size_of: GeckoMallocSizeOf,
|
2017-09-05 20:51:17 +03:00
|
|
|
malloc_enclosing_size_of: GeckoMallocSizeOf,
|
2017-08-31 08:31:31 +03:00
|
|
|
sizes: *mut ServoStyleSetSizes,
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2017-08-31 08:31:31 +03:00
|
|
|
) {
|
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut ops = MallocSizeOfOps::new(
|
|
|
|
malloc_size_of.unwrap(),
|
|
|
|
Some(malloc_enclosing_size_of.unwrap()),
|
|
|
|
None,
|
|
|
|
);
|
2017-08-31 08:31:31 +03:00
|
|
|
let sizes = unsafe { sizes.as_mut() }.unwrap();
|
2017-09-26 13:52:34 +03:00
|
|
|
data.add_size_of(&mut ops, sizes);
|
2017-08-31 08:31:31 +03:00
|
|
|
}
|
|
|
|
|
2017-09-20 02:46:49 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_UACache_AddSizeOf(
|
|
|
|
malloc_size_of: GeckoMallocSizeOf,
|
|
|
|
malloc_enclosing_size_of: GeckoMallocSizeOf,
|
2018-11-20 07:37:53 +03:00
|
|
|
sizes: *mut ServoStyleSetSizes,
|
2017-09-20 02:46:49 +03:00
|
|
|
) {
|
2018-11-20 07:37:53 +03:00
|
|
|
let mut ops = MallocSizeOfOps::new(
|
|
|
|
malloc_size_of.unwrap(),
|
|
|
|
Some(malloc_enclosing_size_of.unwrap()),
|
|
|
|
None,
|
|
|
|
);
|
2017-09-20 02:46:49 +03:00
|
|
|
let sizes = unsafe { sizes.as_mut() }.unwrap();
|
|
|
|
add_size_of_ua_cache(&mut ops, sizes);
|
|
|
|
}
|
|
|
|
|
2017-05-12 13:41:35 +03:00
|
|
|
#[no_mangle]
|
2017-06-29 03:02:17 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_MightHaveAttributeDependency(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
element: &RawGeckoElement,
|
2017-10-09 03:10:40 +03:00
|
|
|
local_name: *mut nsAtom,
|
2017-06-29 03:02:17 +03:00
|
|
|
) -> bool {
|
2017-05-12 13:41:35 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2017-06-29 03:02:17 +03:00
|
|
|
let element = GeckoElement(element);
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
Atom::with(local_name, |atom| {
|
servo: Merge #20597 - style: Implement the non-functional :host selector (from emilio:host); r=xidorn
Kinda tricky because :host only matches rules on the shadow root where the rules
come from. So we need to be careful during invalidation and style sharing.
I didn't use the non_ts_pseudo_class_list bits because as soon as we implement
the :host(..) bits we're going to need to special-case it anyway.
The general schema is the following:
* Rightmost featureless :host selectors are handled inserting them in the
host_rules hashmap. Note that we only insert featureless stuff there. We
could insert all of them and just filter during matching, but that's slightly
annoying.
* The other selectors, like non-featureless :host or what not, are added to the
normal cascade data. This is harmless, since the shadow host rules are never
matched against the host, so we know they'll just never match, and avoids
adding more special-cases.
* Featureless :host selectors to the left of a combinator are handled during
matching, in the special-case of next_element_for_combinator in selectors.
This prevents this from being more invasive, and keeps the usual fast path
slim, but it's a bit hard to match the spec and the implementation.
We could keep a copy of the SelectorIter instead in the matching context to
make the handling of featureless-ness explicit in match_non_ts_pseudo_class,
but we'd still need the special-case anyway, so I'm not fond of it.
* We take advantage of one thing that makes this sound. As you may have
noticed, if you had `root` element which is a ShadowRoot, and you matched
something like `div:host` against it, using a MatchingContext with
current_host == root, we'd incorrectly report a match. But this is impossible
due to the following constraints:
* Shadow root rules aren't matched against the host during styling (except
these featureless selectors).
* DOM APIs' current_host needs to be the _containing_ host, not the element
itself if you're a Shadow host.
Bug: 992245
Reviewed-by: xidorn
MozReview-Commit-ID: KayYNfTXb5h
Source-Repo: https://github.com/servo/servo
Source-Revision: cb754b262747e7cab794411df55588f0f0b30b5e
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 2ebbb2578ff9dbadfe905ae501cd52bd61a9fe9a
2018-04-09 13:41:59 +03:00
|
|
|
data.stylist.any_applicable_rule_data(element, |data| {
|
2018-01-09 16:26:28 +03:00
|
|
|
data.might_have_attribute_dependency(atom)
|
|
|
|
})
|
2017-06-29 03:02:17 +03:00
|
|
|
})
|
|
|
|
}
|
2017-05-12 13:41:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-06-29 03:02:17 +03:00
|
|
|
pub extern "C" fn Servo_StyleSet_HasStateDependency(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
element: &RawGeckoElement,
|
2017-06-29 03:02:17 +03:00
|
|
|
state: u64,
|
|
|
|
) -> bool {
|
|
|
|
let element = GeckoElement(element);
|
|
|
|
|
|
|
|
let state = ElementState::from_bits_truncate(state);
|
2017-05-12 13:41:35 +03:00
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
2017-06-29 03:02:17 +03:00
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
data.stylist
|
|
|
|
.any_applicable_rule_data(element, |data| data.has_state_dependency(state))
|
2017-05-12 13:41:35 +03:00
|
|
|
}
|
2017-06-23 04:49:38 +03:00
|
|
|
|
2017-10-20 10:56:47 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_StyleSet_HasDocumentStateDependency(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
2017-10-20 10:56:47 +03:00
|
|
|
state: u64,
|
|
|
|
) -> bool {
|
|
|
|
let state = DocumentState::from_bits_truncate(state);
|
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
|
|
|
|
data.stylist.has_document_state_dependency(state)
|
|
|
|
}
|
|
|
|
|
2018-06-07 21:27:57 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_GetPropertyValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
style: &ComputedValues,
|
2018-06-07 21:27:57 +03:00
|
|
|
prop: nsCSSPropertyID,
|
2020-01-05 17:42:23 +03:00
|
|
|
value: &mut nsAString,
|
2018-06-07 21:27:57 +03:00
|
|
|
) {
|
2018-11-15 11:25:13 +03:00
|
|
|
if let Ok(longhand) = LonghandId::from_nscsspropertyid(prop) {
|
2018-11-20 07:37:53 +03:00
|
|
|
style
|
2020-01-05 17:42:23 +03:00
|
|
|
.get_longhand_property_value(longhand, &mut CssWriter::new(value))
|
2018-11-20 07:37:53 +03:00
|
|
|
.unwrap();
|
2018-11-15 11:25:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let shorthand =
|
|
|
|
ShorthandId::from_nscsspropertyid(prop).expect("Not a shorthand nor a longhand?");
|
2018-11-15 11:25:13 +03:00
|
|
|
let mut block = PropertyDeclarationBlock::new();
|
|
|
|
// NOTE(emilio): We reuse the animation value machinery to avoid blowing up
|
|
|
|
// code size, but may need to come up with something different if ever care
|
|
|
|
// about supporting the cases that assert below. Fortunately we don't right
|
|
|
|
// now.
|
|
|
|
for longhand in shorthand.longhands() {
|
|
|
|
debug_assert!(
|
|
|
|
!longhand.is_logical(),
|
|
|
|
"This won't quite do the right thing if we want to serialize \
|
|
|
|
logical shorthands"
|
|
|
|
);
|
2018-11-20 07:37:53 +03:00
|
|
|
let animated = AnimationValue::from_computed_values(longhand, style).expect(
|
|
|
|
"Somebody tried to serialize a shorthand with \
|
|
|
|
non-animatable properties, would need more code \
|
|
|
|
to do this",
|
|
|
|
);
|
2018-11-15 11:25:13 +03:00
|
|
|
block.push(animated.uncompute(), Importance::Normal);
|
|
|
|
}
|
2020-01-05 17:42:23 +03:00
|
|
|
block.shorthand_to_css(shorthand, value).unwrap();
|
2018-06-07 21:27:57 +03:00
|
|
|
}
|
|
|
|
|
2017-06-23 04:49:38 +03:00
|
|
|
#[no_mangle]
|
2018-03-19 13:11:14 +03:00
|
|
|
pub unsafe extern "C" fn Servo_GetCustomPropertyValue(
|
2019-03-21 20:00:27 +03:00
|
|
|
computed_values: &ComputedValues,
|
2020-01-04 13:36:49 +03:00
|
|
|
name: &nsACString,
|
2020-01-05 17:42:23 +03:00
|
|
|
value: &mut nsAString,
|
2017-10-13 22:11:02 +03:00
|
|
|
) -> bool {
|
2017-07-18 05:44:25 +03:00
|
|
|
let custom_properties = match computed_values.custom_properties() {
|
2017-06-23 04:49:38 +03:00
|
|
|
Some(p) => p,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
|
2020-01-04 13:36:49 +03:00
|
|
|
let name = Atom::from(name.as_str_unchecked());
|
2017-08-08 16:29:14 +03:00
|
|
|
let computed_value = match custom_properties.get(&name) {
|
2017-06-23 04:49:38 +03:00
|
|
|
Some(v) => v,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
|
2020-01-05 17:42:23 +03:00
|
|
|
computed_value.to_css(&mut CssWriter::new(value)).unwrap();
|
2017-06-23 04:49:38 +03:00
|
|
|
true
|
|
|
|
}
|
2017-06-29 04:04:58 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-21 20:00:27 +03:00
|
|
|
pub extern "C" fn Servo_GetCustomPropertiesCount(computed_values: &ComputedValues) -> u32 {
|
2017-07-18 05:44:25 +03:00
|
|
|
match computed_values.custom_properties() {
|
2017-06-29 04:04:58 +03:00
|
|
|
Some(p) => p.len() as u32,
|
|
|
|
None => 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_GetCustomPropertyNameAt(
|
2019-03-21 20:00:27 +03:00
|
|
|
computed_values: &ComputedValues,
|
2017-10-13 22:11:02 +03:00
|
|
|
index: u32,
|
2020-01-04 13:36:49 +03:00
|
|
|
) -> *mut nsAtom {
|
2017-07-18 05:44:25 +03:00
|
|
|
let custom_properties = match computed_values.custom_properties() {
|
2017-06-29 04:04:58 +03:00
|
|
|
Some(p) => p,
|
2020-01-04 13:36:49 +03:00
|
|
|
None => return ptr::null_mut(),
|
2017-06-29 04:04:58 +03:00
|
|
|
};
|
|
|
|
|
2019-01-11 02:57:02 +03:00
|
|
|
let property_name = match custom_properties.get_index(index as usize) {
|
|
|
|
Some((key, _value)) => key,
|
2020-01-04 13:36:49 +03:00
|
|
|
None => return ptr::null_mut(),
|
2017-06-29 04:04:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-01-04 13:36:49 +03:00
|
|
|
property_name.as_ptr()
|
2017-06-29 04:04:58 +03:00
|
|
|
}
|
2017-08-25 11:36:34 +03:00
|
|
|
|
2017-09-15 22:43:30 +03:00
|
|
|
#[no_mangle]
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
pub extern "C" fn Servo_CssUrl_IsLocalRef(url: &url::CssUrl) -> bool {
|
|
|
|
url.is_fragment()
|
2018-10-17 12:43:45 +03:00
|
|
|
}
|
|
|
|
|
2017-08-25 11:36:34 +03:00
|
|
|
#[no_mangle]
|
2017-10-13 22:11:02 +03:00
|
|
|
pub extern "C" fn Servo_ProcessInvalidations(
|
2019-03-21 20:00:27 +03:00
|
|
|
set: &RawServoStyleSet,
|
|
|
|
element: &RawGeckoElement,
|
2017-10-13 22:11:02 +03:00
|
|
|
snapshots: *const ServoElementSnapshotTable,
|
|
|
|
) {
|
2017-08-25 11:36:34 +03:00
|
|
|
debug_assert!(!snapshots.is_null());
|
|
|
|
|
|
|
|
let element = GeckoElement(element);
|
|
|
|
debug_assert!(element.has_snapshot());
|
|
|
|
debug_assert!(!element.handled_snapshot());
|
|
|
|
|
|
|
|
let mut data = element.mutate_data();
|
|
|
|
debug_assert!(data.is_some());
|
|
|
|
|
|
|
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
|
|
|
let guard = global_style_data.shared_lock.read();
|
|
|
|
let per_doc_data = PerDocumentStyleData::from_ffi(set).borrow();
|
2018-11-20 07:37:53 +03:00
|
|
|
let shared_style_context = create_shared_context(
|
|
|
|
&global_style_data,
|
|
|
|
&guard,
|
|
|
|
&per_doc_data,
|
|
|
|
TraversalFlags::empty(),
|
|
|
|
unsafe { &*snapshots },
|
|
|
|
);
|
2017-08-25 11:36:34 +03:00
|
|
|
let mut data = data.as_mut().map(|d| &mut **d);
|
|
|
|
|
|
|
|
if let Some(ref mut data) = data {
|
2017-11-30 01:36:48 +03:00
|
|
|
// FIXME(emilio): Ideally we could share the nth-index-cache across all
|
|
|
|
// the elements?
|
2017-10-03 08:40:03 +03:00
|
|
|
let result = data.invalidate_style_if_needed(
|
|
|
|
element,
|
|
|
|
&shared_style_context,
|
|
|
|
None,
|
2017-11-30 01:36:48 +03:00
|
|
|
&mut NthIndexCache::default(),
|
2017-10-03 08:40:03 +03:00
|
|
|
);
|
|
|
|
|
2017-09-05 22:18:52 +03:00
|
|
|
if result.has_invalidated_siblings() {
|
2018-11-20 07:37:53 +03:00
|
|
|
let parent = element
|
|
|
|
.traversal_parent()
|
|
|
|
.expect("How could we invalidate siblings without a common parent?");
|
2017-09-05 22:18:52 +03:00
|
|
|
unsafe {
|
|
|
|
parent.set_dirty_descendants();
|
|
|
|
bindings::Gecko_NoteDirtySubtreeForInvalidation(parent.0);
|
|
|
|
}
|
|
|
|
} else if result.has_invalidated_descendants() {
|
|
|
|
unsafe { bindings::Gecko_NoteDirtySubtreeForInvalidation(element.0) };
|
|
|
|
} else if result.has_invalidated_self() {
|
|
|
|
unsafe { bindings::Gecko_NoteDirtyElement(element.0) };
|
|
|
|
}
|
2017-08-25 11:36:34 +03:00
|
|
|
}
|
|
|
|
}
|
2017-09-06 18:47:32 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2019-10-07 02:30:23 +03:00
|
|
|
pub extern "C" fn Servo_HasPendingRestyleAncestor(
|
|
|
|
element: &RawGeckoElement,
|
|
|
|
may_need_to_flush_layout: bool,
|
|
|
|
) -> bool {
|
2019-10-05 12:25:21 +03:00
|
|
|
let mut has_yet_to_be_styled = false;
|
2017-09-06 18:47:32 +03:00
|
|
|
let mut element = Some(GeckoElement(element));
|
|
|
|
while let Some(e) = element {
|
2017-10-25 18:28:18 +03:00
|
|
|
if e.has_animations() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the element needs a frame, it means that we haven't styled it yet
|
|
|
|
// after it got inserted in the document, and thus we may need to do
|
|
|
|
// that for transitions and animations to trigger.
|
2019-10-05 12:25:21 +03:00
|
|
|
//
|
|
|
|
// This is a fast path in the common case, but `has_yet_to_be_styled` is
|
|
|
|
// the real check for this.
|
2017-10-25 18:28:18 +03:00
|
|
|
if e.needs_frame() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-05 12:25:21 +03:00
|
|
|
let data = e.borrow_data();
|
|
|
|
if let Some(ref data) = data {
|
2017-09-12 21:16:26 +03:00
|
|
|
if !data.hint.is_empty() {
|
2017-09-06 18:47:32 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-10-05 12:25:21 +03:00
|
|
|
if has_yet_to_be_styled && !data.styles.is_display_none() {
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-07 02:30:23 +03:00
|
|
|
// Ideally, DOM mutations wouldn't affect layout trees of siblings.
|
|
|
|
//
|
|
|
|
// In practice, this can happen because Gecko deals pretty badly
|
|
|
|
// with some kinds of content insertion and removals.
|
|
|
|
//
|
|
|
|
// If we may need to flush layout, we need frames to accurately
|
|
|
|
// determine whether we'll actually flush, so if we have to
|
|
|
|
// reconstruct we need to flush style, which is what will take care
|
|
|
|
// of ensuring that frames are constructed, even if the style itself
|
|
|
|
// is up-to-date.
|
|
|
|
if may_need_to_flush_layout && data.damage.contains(GeckoRestyleDamage::reconstruct()) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-06 18:47:32 +03:00
|
|
|
}
|
2019-10-05 12:25:21 +03:00
|
|
|
has_yet_to_be_styled = data.is_none();
|
2017-10-25 18:28:18 +03:00
|
|
|
|
2017-09-06 18:47:32 +03:00
|
|
|
element = e.traversal_parent();
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
2017-09-29 03:10:46 +03:00
|
|
|
|
2017-10-03 16:05:07 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SelectorList_Parse(
|
2019-11-27 23:57:51 +03:00
|
|
|
selector_list: &nsACString,
|
2019-03-26 21:15:59 +03:00
|
|
|
) -> OwnedOrNull<RawServoSelectorList> {
|
2017-10-03 16:05:07 +03:00
|
|
|
use style::selector_parser::SelectorParser;
|
|
|
|
|
2019-11-27 23:57:51 +03:00
|
|
|
let input = selector_list.as_str_unchecked();
|
2017-10-03 16:05:07 +03:00
|
|
|
let selector_list = match SelectorParser::parse_author_origin_no_namespace(&input) {
|
|
|
|
Ok(selector_list) => selector_list,
|
2019-03-26 21:15:59 +03:00
|
|
|
Err(..) => return OwnedOrNull::null(),
|
2017-10-03 16:05:07 +03:00
|
|
|
};
|
|
|
|
|
2019-03-26 21:15:59 +03:00
|
|
|
Box::new(selector_list).into_ffi().maybe()
|
2017-10-03 16:05:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-30 23:18:33 +03:00
|
|
|
pub unsafe extern "C" fn Servo_SelectorList_Drop(list: *mut RawServoSelectorList) {
|
|
|
|
SelectorList::drop_ffi(list)
|
2017-10-03 16:05:07 +03:00
|
|
|
}
|
2017-10-16 12:49:33 +03:00
|
|
|
|
2017-12-05 08:32:15 +03:00
|
|
|
fn parse_color(
|
|
|
|
value: &str,
|
2019-06-19 00:32:16 +03:00
|
|
|
error_reporter: Option<&dyn ParseErrorReporter>,
|
2017-12-05 08:32:15 +03:00
|
|
|
) -> Result<specified::Color, ()> {
|
2017-10-16 12:49:33 +03:00
|
|
|
let mut input = ParserInput::new(value);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
2017-12-05 12:37:18 +03:00
|
|
|
let url_data = unsafe { dummy_url_data() };
|
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Style),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
error_reporter,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-12-05 12:37:18 +03:00
|
|
|
);
|
|
|
|
|
2017-12-05 08:32:15 +03:00
|
|
|
let start_position = parser.position();
|
2018-11-20 07:37:53 +03:00
|
|
|
parser
|
|
|
|
.parse_entirely(|i| specified::Color::parse(&context, i))
|
|
|
|
.map_err(|err| {
|
|
|
|
if error_reporter.is_some() {
|
|
|
|
match err.kind {
|
|
|
|
ParseErrorKind::Custom(StyleParseErrorKind::ValueError(..)) => {
|
|
|
|
let location = err.location.clone();
|
|
|
|
let error = ContextualParseError::UnsupportedValue(
|
|
|
|
parser.slice_from(start_position),
|
|
|
|
err,
|
|
|
|
);
|
|
|
|
context.log_css_error(location, error);
|
|
|
|
},
|
|
|
|
// Ignore other kinds of errors that might be reported, such as
|
|
|
|
// ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken),
|
|
|
|
// since Gecko doesn't report those to the error console.
|
|
|
|
_ => {},
|
2017-12-05 08:32:15 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-20 07:37:53 +03:00
|
|
|
})
|
2017-10-16 12:49:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2020-01-08 04:21:30 +03:00
|
|
|
pub unsafe extern "C" fn Servo_IsValidCSSColor(value: &nsACString) -> bool {
|
|
|
|
parse_color(value.as_str_unchecked(), None).is_ok()
|
2017-10-16 12:49:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2020-01-08 04:21:30 +03:00
|
|
|
pub unsafe extern "C" fn Servo_ComputeColor(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: Option<&RawServoStyleSet>,
|
2017-10-16 12:49:33 +03:00
|
|
|
current_color: structs::nscolor,
|
2020-01-08 04:21:30 +03:00
|
|
|
value: &nsACString,
|
|
|
|
result_color: &mut structs::nscolor,
|
2017-12-05 08:32:15 +03:00
|
|
|
was_current_color: *mut bool,
|
|
|
|
loader: *mut Loader,
|
2017-10-16 12:49:33 +03:00
|
|
|
) -> bool {
|
|
|
|
use style::gecko;
|
|
|
|
|
|
|
|
let current_color = gecko::values::convert_nscolor_to_rgba(current_color);
|
|
|
|
|
2020-01-08 04:21:30 +03:00
|
|
|
let reporter = loader.as_mut().and_then(|loader| {
|
2017-12-05 08:32:15 +03:00
|
|
|
// Make an ErrorReporter that will report errors as being "from DOM".
|
|
|
|
ErrorReporter::new(ptr::null_mut(), loader, ptr::null_mut())
|
|
|
|
});
|
|
|
|
|
2020-01-08 04:21:30 +03:00
|
|
|
let specified_color = match parse_color(
|
|
|
|
value.as_str_unchecked(),
|
2019-08-26 12:58:53 +03:00
|
|
|
reporter.as_ref().map(|r| r as &dyn ParseErrorReporter),
|
|
|
|
) {
|
2020-01-08 04:21:30 +03:00
|
|
|
Ok(c) => c,
|
|
|
|
Err(..) => return false,
|
|
|
|
};
|
2017-10-16 12:49:33 +03:00
|
|
|
|
2020-01-08 04:21:30 +03:00
|
|
|
let computed_color = match raw_data {
|
|
|
|
Some(raw_data) => {
|
|
|
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
let device = data.stylist.device();
|
|
|
|
let quirks_mode = data.stylist.quirks_mode();
|
|
|
|
Context::for_media_query_evaluation(device, quirks_mode, |context| {
|
|
|
|
specified_color.to_computed_color(Some(&context))
|
|
|
|
})
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2020-01-08 04:21:30 +03:00
|
|
|
None => specified_color.to_computed_color(None),
|
|
|
|
};
|
|
|
|
|
|
|
|
let computed_color = match computed_color {
|
|
|
|
Some(c) => c,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
|
|
|
|
let rgba = computed_color.to_rgba(current_color);
|
|
|
|
*result_color = gecko::values::convert_rgba_to_nscolor(&rgba);
|
|
|
|
|
|
|
|
if !was_current_color.is_null() {
|
|
|
|
*was_current_color = computed_color.is_currentcolor();
|
2017-10-16 12:49:33 +03:00
|
|
|
}
|
2020-01-08 04:21:30 +03:00
|
|
|
|
|
|
|
true
|
2017-10-16 12:49:33 +03:00
|
|
|
}
|
2017-10-17 09:11:39 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2018-04-05 12:37:39 +03:00
|
|
|
pub unsafe extern "C" fn Servo_IntersectionObserverRootMargin_Parse(
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsAString,
|
2019-01-26 13:00:44 +03:00
|
|
|
result: *mut IntersectionObserverRootMargin,
|
2017-10-17 09:11:39 +03:00
|
|
|
) -> bool {
|
2019-11-27 23:57:51 +03:00
|
|
|
let value = value.to_string();
|
2018-04-05 12:37:39 +03:00
|
|
|
let result = result.as_mut().unwrap();
|
2017-10-17 09:11:39 +03:00
|
|
|
|
|
|
|
let mut input = ParserInput::new(&value);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
|
|
|
|
2018-04-05 12:37:39 +03:00
|
|
|
let url_data = dummy_url_data();
|
2017-10-17 09:11:39 +03:00
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::Style),
|
2017-10-31 02:25:45 +03:00
|
|
|
ParsingMode::DEFAULT,
|
2017-10-17 09:11:39 +03:00
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-10-17 09:11:39 +03:00
|
|
|
);
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let margin = parser.parse_entirely(|p| IntersectionObserverRootMargin::parse(&context, p));
|
2017-10-17 09:11:39 +03:00
|
|
|
match margin {
|
|
|
|
Ok(margin) => {
|
2019-01-26 13:00:44 +03:00
|
|
|
*result = margin;
|
2017-10-17 09:11:39 +03:00
|
|
|
true
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2017-10-17 09:11:39 +03:00
|
|
|
Err(..) => false,
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 06:01:34 +03:00
|
|
|
|
2018-04-05 12:37:39 +03:00
|
|
|
#[no_mangle]
|
2020-01-05 17:42:23 +03:00
|
|
|
pub extern "C" fn Servo_IntersectionObserverRootMargin_ToString(
|
|
|
|
root_margin: &IntersectionObserverRootMargin,
|
|
|
|
result: &mut nsAString,
|
2018-04-05 12:37:39 +03:00
|
|
|
) {
|
2020-01-05 17:42:23 +03:00
|
|
|
let mut writer = CssWriter::new(result);
|
|
|
|
root_margin.to_css(&mut writer).unwrap();
|
2018-04-05 12:37:39 +03:00
|
|
|
}
|
|
|
|
|
2017-11-28 05:13:34 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn Servo_ParseTransformIntoMatrix(
|
2020-01-07 12:46:53 +03:00
|
|
|
value: &nsACString,
|
2020-01-07 12:47:20 +03:00
|
|
|
contain_3d: &mut bool,
|
|
|
|
result: &mut structs::Matrix4x4Components,
|
2017-11-28 05:13:34 +03:00
|
|
|
) -> bool {
|
|
|
|
use style::properties::longhands::transform;
|
|
|
|
|
2020-01-07 12:46:53 +03:00
|
|
|
let string = unsafe { value.as_str_unchecked() };
|
2017-11-28 05:13:34 +03:00
|
|
|
let mut input = ParserInput::new(&string);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
unsafe { dummy_url_data() },
|
|
|
|
Some(CssRuleType::Style),
|
|
|
|
ParsingMode::DEFAULT,
|
2018-06-20 22:07:45 +03:00
|
|
|
QuirksMode::NoQuirks,
|
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-11-28 05:13:34 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
let transform = match parser.parse_entirely(|t| transform::parse(&context, t)) {
|
|
|
|
Ok(t) => t,
|
|
|
|
Err(..) => return false,
|
|
|
|
};
|
|
|
|
|
|
|
|
let (m, is_3d) = match transform.to_transform_3d_matrix(None) {
|
|
|
|
Ok(result) => result,
|
|
|
|
Err(..) => return false,
|
|
|
|
};
|
|
|
|
|
|
|
|
*result = m.to_row_major_array();
|
|
|
|
*contain_3d = is_3d;
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2017-12-05 17:09:35 +03:00
|
|
|
#[no_mangle]
|
2018-10-04 00:50:21 +03:00
|
|
|
pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching(
|
2020-01-07 12:47:20 +03:00
|
|
|
value: &nsAString,
|
2017-12-05 17:09:35 +03:00
|
|
|
data: *mut URLExtraData,
|
2020-01-07 12:47:20 +03:00
|
|
|
family: &mut structs::RefPtr<structs::SharedFontList>,
|
|
|
|
style: &mut ComputedFontStyleDescriptor,
|
|
|
|
stretch: &mut f32,
|
|
|
|
weight: &mut f32,
|
2017-12-05 17:09:35 +03:00
|
|
|
) -> bool {
|
|
|
|
use style::properties::shorthands::font;
|
2019-03-30 03:15:51 +03:00
|
|
|
use style::values::computed::font::FontFamilyList;
|
2018-10-04 00:50:21 +03:00
|
|
|
use style::values::computed::font::FontWeight as ComputedFontWeight;
|
2018-11-20 07:37:53 +03:00
|
|
|
use style::values::generics::font::FontStyle as GenericFontStyle;
|
|
|
|
use style::values::specified::font::{
|
|
|
|
FontFamily, FontStretch, FontStyle, FontWeight, SpecifiedFontStyle,
|
|
|
|
};
|
2017-12-05 17:09:35 +03:00
|
|
|
|
2020-01-07 12:47:20 +03:00
|
|
|
let string = value.to_string();
|
2017-12-05 17:09:35 +03:00
|
|
|
let mut input = ParserInput::new(&string);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
2018-10-04 00:50:21 +03:00
|
|
|
let url_data = UrlExtraData::from_ptr_ref(&data);
|
2017-12-05 17:09:35 +03:00
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
url_data,
|
|
|
|
Some(CssRuleType::FontFace),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-12-05 17:09:35 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
let font = match parser.parse_entirely(|f| font::parse_value(&context, f)) {
|
|
|
|
Ok(f) => f,
|
|
|
|
Err(..) => return false,
|
|
|
|
};
|
|
|
|
|
|
|
|
// The system font is not acceptable, so we return false.
|
|
|
|
match font.font_family {
|
2019-03-30 03:15:51 +03:00
|
|
|
FontFamily::Values(FontFamilyList::SharedFontList(list)) => family.set_move(list),
|
|
|
|
FontFamily::Values(list) => family.set_move(list.shared_font_list().clone()),
|
2017-12-05 17:09:35 +03:00
|
|
|
FontFamily::System(_) => return false,
|
|
|
|
}
|
2018-04-23 17:52:20 +03:00
|
|
|
|
2018-04-19 22:23:31 +03:00
|
|
|
let specified_font_style = match font.font_style {
|
|
|
|
FontStyle::Specified(ref s) => s,
|
2018-04-19 21:38:08 +03:00
|
|
|
FontStyle::System(_) => return false,
|
|
|
|
};
|
2020-01-07 12:47:20 +03:00
|
|
|
|
|
|
|
*style = match *specified_font_style {
|
2018-10-04 00:50:21 +03:00
|
|
|
GenericFontStyle::Normal => ComputedFontStyleDescriptor::Normal,
|
|
|
|
GenericFontStyle::Italic => ComputedFontStyleDescriptor::Italic,
|
2018-04-19 22:23:31 +03:00
|
|
|
GenericFontStyle::Oblique(ref angle) => {
|
2018-10-04 00:50:21 +03:00
|
|
|
let angle = SpecifiedFontStyle::compute_angle_degrees(angle);
|
|
|
|
ComputedFontStyleDescriptor::Oblique(angle, angle)
|
2018-11-20 07:37:53 +03:00
|
|
|
},
|
2020-01-07 12:47:20 +03:00
|
|
|
};
|
2018-04-19 22:23:31 +03:00
|
|
|
|
2018-10-04 00:50:21 +03:00
|
|
|
*stretch = match font.font_stretch {
|
|
|
|
FontStretch::Keyword(ref k) => k.compute().0,
|
|
|
|
FontStretch::Stretch(ref p) => p.get(),
|
|
|
|
FontStretch::System(_) => return false,
|
|
|
|
};
|
2018-04-17 14:30:04 +03:00
|
|
|
|
2018-10-04 00:50:21 +03:00
|
|
|
*weight = match font.font_weight {
|
|
|
|
FontWeight::Absolute(w) => w.compute().0,
|
2017-12-05 17:09:35 +03:00
|
|
|
// Resolve relative font weights against the initial of font-weight
|
|
|
|
// (normal, which is equivalent to 400).
|
2018-10-04 00:50:21 +03:00
|
|
|
FontWeight::Bolder => ComputedFontWeight::normal().bolder().0,
|
|
|
|
FontWeight::Lighter => ComputedFontWeight::normal().lighter().0,
|
2017-12-05 17:09:35 +03:00
|
|
|
FontWeight::System(_) => return false,
|
2018-10-04 00:50:21 +03:00
|
|
|
};
|
2017-12-05 17:09:35 +03:00
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2017-11-13 06:01:34 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SourceSizeList_Parse(
|
2019-11-27 23:57:51 +03:00
|
|
|
value: &nsACString,
|
2019-03-26 21:15:59 +03:00
|
|
|
) -> Owned<RawServoSourceSizeList> {
|
2019-11-27 23:57:51 +03:00
|
|
|
let value = value.as_str_unchecked();
|
2017-11-13 06:01:34 +03:00
|
|
|
let mut input = ParserInput::new(value);
|
|
|
|
let mut parser = Parser::new(&mut input);
|
|
|
|
|
|
|
|
let context = ParserContext::new(
|
|
|
|
Origin::Author,
|
|
|
|
dummy_url_data(),
|
|
|
|
Some(CssRuleType::Style),
|
|
|
|
ParsingMode::DEFAULT,
|
|
|
|
QuirksMode::NoQuirks,
|
2018-06-20 22:07:45 +03:00
|
|
|
None,
|
2018-08-20 20:03:11 +03:00
|
|
|
None,
|
2017-11-13 06:01:34 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// NB: Intentionally not calling parse_entirely.
|
|
|
|
let list = SourceSizeList::parse(&context, &mut parser);
|
2019-03-26 21:15:59 +03:00
|
|
|
Box::new(list).into_ffi()
|
2017-11-13 06:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SourceSizeList_Evaluate(
|
2019-03-21 20:00:27 +03:00
|
|
|
raw_data: &RawServoStyleSet,
|
|
|
|
list: Option<&RawServoSourceSizeList>,
|
2017-11-13 06:01:34 +03:00
|
|
|
) -> i32 {
|
|
|
|
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
|
|
|
let device = doc_data.stylist.device();
|
|
|
|
let quirks_mode = doc_data.stylist.quirks_mode();
|
|
|
|
|
|
|
|
let result = match list {
|
2018-11-20 07:37:53 +03:00
|
|
|
Some(list) => SourceSizeList::from_ffi(list).evaluate(device, quirks_mode),
|
|
|
|
None => SourceSizeList::empty().evaluate(device, quirks_mode),
|
2017-11-13 06:01:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
result.0
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-30 23:18:33 +03:00
|
|
|
pub unsafe extern "C" fn Servo_SourceSizeList_Drop(list: *mut RawServoSourceSizeList) {
|
|
|
|
SourceSizeList::drop_ffi(list);
|
2017-11-13 06:01:34 +03:00
|
|
|
}
|
2017-12-05 06:22:50 +03:00
|
|
|
|
2018-01-17 22:55:03 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_InvalidateStyleForDocStateChanges(
|
2019-03-21 20:00:27 +03:00
|
|
|
root: &RawGeckoElement,
|
|
|
|
document_style: &RawServoStyleSet,
|
2019-11-27 23:57:51 +03:00
|
|
|
non_document_styles: &nsTArray<&RawServoAuthorStyles>,
|
2018-01-17 22:55:03 +03:00
|
|
|
states_changed: u64,
|
|
|
|
) {
|
|
|
|
use style::invalidation::element::document_state::DocumentStateInvalidationProcessor;
|
|
|
|
use style::invalidation::element::invalidator::TreeStyleInvalidator;
|
|
|
|
|
2018-02-16 17:54:06 +03:00
|
|
|
let document_data = PerDocumentStyleData::from_ffi(document_style).borrow();
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let iter = document_data
|
|
|
|
.stylist
|
|
|
|
.iter_origins()
|
|
|
|
.map(|(data, _origin)| data)
|
2019-11-27 23:57:51 +03:00
|
|
|
.chain(non_document_styles.iter().map(|author_styles| {
|
2018-02-16 17:54:06 +03:00
|
|
|
let styles: &_ = AuthorStyles::<GeckoStyleSheet>::from_ffi(author_styles);
|
|
|
|
&styles.data
|
|
|
|
}));
|
|
|
|
|
2018-01-17 22:55:03 +03:00
|
|
|
let root = GeckoElement(root);
|
|
|
|
let mut processor = DocumentStateInvalidationProcessor::new(
|
2018-02-16 17:54:06 +03:00
|
|
|
iter,
|
2018-01-17 22:55:03 +03:00
|
|
|
DocumentState::from_bits_truncate(states_changed),
|
|
|
|
root.as_node().owner_doc().quirks_mode(),
|
|
|
|
);
|
|
|
|
|
2018-11-20 07:37:53 +03:00
|
|
|
let result =
|
|
|
|
TreeStyleInvalidator::new(root, /* stack_limit_checker = */ None, &mut processor)
|
|
|
|
.invalidate();
|
2018-01-17 22:55:03 +03:00
|
|
|
|
|
|
|
debug_assert!(!result.has_invalidated_siblings(), "How in the world?");
|
|
|
|
if result.has_invalidated_descendants() {
|
|
|
|
bindings::Gecko_NoteDirtySubtreeForInvalidation(root.0);
|
|
|
|
} else if result.has_invalidated_self() {
|
|
|
|
bindings::Gecko_NoteDirtyElement(root.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 01:51:48 +03:00
|
|
|
#[no_mangle]
|
2019-11-27 23:57:51 +03:00
|
|
|
pub unsafe extern "C" fn Servo_PseudoClass_GetStates(name: &nsACString) -> u64 {
|
|
|
|
let name = name.as_str_unchecked();
|
2018-03-28 01:51:48 +03:00
|
|
|
match NonTSPseudoClass::parse_non_functional(name) {
|
|
|
|
None => 0,
|
|
|
|
// Ignore :any-link since it contains both visited and unvisited state.
|
|
|
|
Some(NonTSPseudoClass::AnyLink) => 0,
|
|
|
|
Some(pseudo_class) => pseudo_class.state_flag().bits(),
|
|
|
|
}
|
|
|
|
}
|
2018-08-20 20:03:11 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-26 21:15:59 +03:00
|
|
|
pub unsafe extern "C" fn Servo_UseCounters_Create() -> Owned<structs::StyleUseCounters> {
|
|
|
|
Box::<UseCounters>::default().into_ffi()
|
2018-08-21 13:31:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-03-30 23:18:33 +03:00
|
|
|
pub unsafe extern "C" fn Servo_UseCounters_Drop(c: *mut structs::StyleUseCounters) {
|
|
|
|
UseCounters::drop_ffi(c);
|
2018-08-21 13:31:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_UseCounters_Merge(
|
2019-03-21 20:00:27 +03:00
|
|
|
doc_counters: &UseCounters,
|
|
|
|
sheet_counters: &UseCounters,
|
2018-08-21 13:31:11 +03:00
|
|
|
) {
|
2019-03-21 20:00:27 +03:00
|
|
|
doc_counters.merge(sheet_counters)
|
2018-08-20 20:03:11 +03:00
|
|
|
}
|
2018-08-20 23:07:19 +03:00
|
|
|
|
2019-09-19 03:19:59 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_IsPropertyIdRecordedInUseCounter(
|
|
|
|
use_counters: &UseCounters,
|
|
|
|
id: nsCSSPropertyID,
|
|
|
|
) -> bool {
|
|
|
|
let id = NonCustomPropertyId::from_nscsspropertyid(id).unwrap();
|
|
|
|
use_counters.non_custom_properties.recorded(id)
|
|
|
|
}
|
|
|
|
|
2019-09-19 03:20:04 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_IsUnknownPropertyRecordedInUseCounter(
|
|
|
|
use_counters: &UseCounters,
|
|
|
|
p: CountedUnknownProperty,
|
|
|
|
) -> bool {
|
|
|
|
use_counters.counted_unknown_properties.recorded(p)
|
|
|
|
}
|
|
|
|
|
2018-08-20 23:07:19 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_IsCssPropertyRecordedInUseCounter(
|
2019-03-21 20:00:27 +03:00
|
|
|
use_counters: &UseCounters,
|
2019-11-27 23:51:20 +03:00
|
|
|
property: &nsACString,
|
2018-08-20 23:07:19 +03:00
|
|
|
known_prop: *mut bool,
|
|
|
|
) -> bool {
|
Bug 1575062 - Support css use counters for unimplemented properties. r=emilio
For developing properties, we will handle them in an other bug.
Besides, I use an iframe for the test because we create a use counter in
the constructor of Document, which use the prefs to decide what kind of
properties we want to record. So, in the test, we have to reload iframe
to make sure we re-create the document, so does the use counter, to make
sure the prefs work properly.
The two prefs affect the css use counters:
1. layout.css.use-counters.enabled: Allocate use counters, and record
non-custom properties.
2. layout.css.use-counters-unimplemented.enabled: Record all unimplmented
properties into the use counters.
If we disable layout.css.use-counters.enblaed, we don't create use counters
object, so layout.css.use-counters-unimplemented.enabled doesn't work,
either.
Differential Revision: https://phabricator.services.mozilla.com/D43860
--HG--
extra : moz-landing-system : lando
2019-08-30 02:40:13 +03:00
|
|
|
*known_prop = false;
|
2019-11-27 23:51:20 +03:00
|
|
|
|
|
|
|
let prop_name = property.as_str_unchecked();
|
|
|
|
if let Ok(p) = PropertyId::parse_unchecked_for_testing(prop_name) {
|
|
|
|
if let Some(id) = p.non_custom_id() {
|
Bug 1575062 - Support css use counters for unimplemented properties. r=emilio
For developing properties, we will handle them in an other bug.
Besides, I use an iframe for the test because we create a use counter in
the constructor of Document, which use the prefs to decide what kind of
properties we want to record. So, in the test, we have to reload iframe
to make sure we re-create the document, so does the use counter, to make
sure the prefs work properly.
The two prefs affect the css use counters:
1. layout.css.use-counters.enabled: Allocate use counters, and record
non-custom properties.
2. layout.css.use-counters-unimplemented.enabled: Record all unimplmented
properties into the use counters.
If we disable layout.css.use-counters.enblaed, we don't create use counters
object, so layout.css.use-counters-unimplemented.enabled doesn't work,
either.
Differential Revision: https://phabricator.services.mozilla.com/D43860
--HG--
extra : moz-landing-system : lando
2019-08-30 02:40:13 +03:00
|
|
|
*known_prop = true;
|
2019-11-27 23:51:20 +03:00
|
|
|
return use_counters.non_custom_properties.recorded(id);
|
Bug 1575062 - Support css use counters for unimplemented properties. r=emilio
For developing properties, we will handle them in an other bug.
Besides, I use an iframe for the test because we create a use counter in
the constructor of Document, which use the prefs to decide what kind of
properties we want to record. So, in the test, we have to reload iframe
to make sure we re-create the document, so does the use counter, to make
sure the prefs work properly.
The two prefs affect the css use counters:
1. layout.css.use-counters.enabled: Allocate use counters, and record
non-custom properties.
2. layout.css.use-counters-unimplemented.enabled: Record all unimplmented
properties into the use counters.
If we disable layout.css.use-counters.enblaed, we don't create use counters
object, so layout.css.use-counters-unimplemented.enabled doesn't work,
either.
Differential Revision: https://phabricator.services.mozilla.com/D43860
--HG--
extra : moz-landing-system : lando
2019-08-30 02:40:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 23:51:20 +03:00
|
|
|
if let Some(p) = CountedUnknownProperty::parse_for_testing(prop_name) {
|
Bug 1575062 - Support css use counters for unimplemented properties. r=emilio
For developing properties, we will handle them in an other bug.
Besides, I use an iframe for the test because we create a use counter in
the constructor of Document, which use the prefs to decide what kind of
properties we want to record. So, in the test, we have to reload iframe
to make sure we re-create the document, so does the use counter, to make
sure the prefs work properly.
The two prefs affect the css use counters:
1. layout.css.use-counters.enabled: Allocate use counters, and record
non-custom properties.
2. layout.css.use-counters-unimplemented.enabled: Record all unimplmented
properties into the use counters.
If we disable layout.css.use-counters.enblaed, we don't create use counters
object, so layout.css.use-counters-unimplemented.enabled doesn't work,
either.
Differential Revision: https://phabricator.services.mozilla.com/D43860
--HG--
extra : moz-landing-system : lando
2019-08-30 02:40:13 +03:00
|
|
|
*known_prop = true;
|
2019-11-27 23:51:20 +03:00
|
|
|
return use_counters.counted_unknown_properties.recorded(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
2018-08-20 23:07:19 +03:00
|
|
|
}
|
2018-11-07 02:03:24 +03:00
|
|
|
|
2019-03-30 03:16:27 +03:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_Create(
|
|
|
|
buffer: *mut u8,
|
|
|
|
len: usize,
|
|
|
|
) -> *mut RawServoSharedMemoryBuilder {
|
|
|
|
let mut builder = Box::new(SharedMemoryBuilder::new(buffer, len));
|
|
|
|
|
|
|
|
// We have Arc<UnparsedValue>s in style sheets due to CSS variables being
|
|
|
|
// used in shorthand property declarations. There aren't many, though,
|
|
|
|
// and they aren't big, so we just allow their duplication for now.
|
|
|
|
builder.add_allowed_duplication_type::<UnparsedValue>();
|
|
|
|
|
|
|
|
Box::into_raw(builder) as *mut _
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_AddStylesheet(
|
|
|
|
builder: &mut RawServoSharedMemoryBuilder,
|
|
|
|
raw_contents: &RawServoStyleSheetContents,
|
|
|
|
) -> *const ServoCssRules {
|
|
|
|
let builder = SharedMemoryBuilder::from_ffi_mut(builder);
|
|
|
|
let contents = StylesheetContents::as_arc(&raw_contents);
|
|
|
|
|
|
|
|
// Assert some things we assume when we create a style sheet from shared
|
|
|
|
// memory.
|
|
|
|
debug_assert_eq!(contents.origin, Origin::UserAgent);
|
|
|
|
debug_assert_eq!(contents.quirks_mode, QuirksMode::NoQuirks);
|
|
|
|
debug_assert!(contents.source_map_url.read().is_none());
|
|
|
|
debug_assert!(contents.source_url.read().is_none());
|
|
|
|
|
|
|
|
let rules = &contents.rules;
|
|
|
|
let shared_rules: &Arc<Locked<CssRules>> = &*builder.write(rules);
|
2019-08-26 12:58:53 +03:00
|
|
|
(&*shared_rules)
|
|
|
|
.with_raw_offset_arc(|arc| *Locked::<CssRules>::arc_as_borrowed(arc) as *const _)
|
2019-03-30 03:16:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_GetLength(
|
|
|
|
builder: &mut RawServoSharedMemoryBuilder,
|
|
|
|
) -> usize {
|
|
|
|
let builder = SharedMemoryBuilder::from_ffi_mut(builder);
|
|
|
|
builder.len()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_Drop(builder: *mut RawServoSharedMemoryBuilder) {
|
2019-03-30 23:18:33 +03:00
|
|
|
SharedMemoryBuilder::drop_ffi(builder)
|
2019-03-30 03:16:27 +03:00
|
|
|
}
|
2019-05-09 14:24:57 +03:00
|
|
|
|
|
|
|
/// Returns a unique pointer to a clone of the shape image.
|
|
|
|
///
|
|
|
|
/// Probably temporary, as we move more stuff to cbindgen.
|
|
|
|
#[no_mangle]
|
|
|
|
#[must_use]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_CloneBasicShape(
|
|
|
|
v: &computed::basic_shape::BasicShape,
|
|
|
|
) -> *mut computed::basic_shape::BasicShape {
|
2019-05-09 14:24:57 +03:00
|
|
|
Box::into_raw(Box::new(v.clone()))
|
|
|
|
}
|
2019-05-17 02:03:29 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn Servo_StyleArcSlice_EmptyPtr() -> *mut c_void {
|
|
|
|
style_traits::arc_slice::ArcSlice::<u64>::leaked_empty_ptr()
|
|
|
|
}
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
|
|
|
|
#[no_mangle]
|
2019-08-26 12:58:53 +03:00
|
|
|
pub unsafe extern "C" fn Servo_LoadData_GetLazy(
|
|
|
|
source: &url::LoadDataSource,
|
|
|
|
) -> *const url::LoadData {
|
Bug 1552708 - Use cbindgen for URIs. r=heycam
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:
* Filters
* Shapes and images, almost. Need to:
* Get rid of the complex -moz- gradient parsing (let
layout.css.simple-moz-gradient.enabled get to release).
* Counters, almost. Need to:
* Share the Attr representation with Gecko, by not using Option<>.
* Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
maybe).
Which in turn allows us to remove a whole lot of bindings in followups to this.
The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* UrlValueSource
* Arc<CssUrlData>
* load id
* resolved uri
* CORS mode.
* ...
```
The new one removes the double reference to the url data via URLValue, and looks
like:
```
SpecifiedUrl
* CssUrl
* Arc<CssUrlData>
* String
* UrlExtraData
* CorsMode
* LoadData
* load id
* resolved URI
```
The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.
I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).
The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.
One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).
Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-05-27 14:45:12 +03:00
|
|
|
source.get()
|
|
|
|
}
|