mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
style: Hook the use counters into StyleSheet parsing.
Still not hooked into telemetry, I talked with :janerik and :gfritzsche about that, but test incoming! This intentionally doesn't handle CSSOM and such for now, will file followups for those, though should be trivial. I want to unify / clean up how we do the use counters and the error reporting stuff for CSSOM, since the current function call still shows up in profiles, but that should be a follow-up. Differential Revision: https://phabricator.services.mozilla.com/D3828
This commit is contained in:
parent
c8e5b7f1b0
commit
89b8f30737
8 changed files with 25 additions and 1 deletions
|
@ -21,6 +21,7 @@ use gecko_bindings::bindings::RawServoRuleNode;
|
|||
use gecko_bindings::bindings::RawServoRuleNodeStrong;
|
||||
use gecko_bindings::bindings::RawServoSupportsRule;
|
||||
use gecko_bindings::bindings::ServoCssRules;
|
||||
use gecko_bindings::bindings::StyleUseCounters;
|
||||
use gecko_bindings::structs::RawServoAnimationValue;
|
||||
use gecko_bindings::structs::RawServoDeclarationBlock;
|
||||
use gecko_bindings::structs::RawServoFontFaceRule;
|
||||
|
@ -39,6 +40,7 @@ use stylesheets::{CounterStyleRule, CssRules, FontFaceRule, FontFeatureValuesRul
|
|||
use stylesheets::{DocumentRule, ImportRule, KeyframesRule, MediaRule, NamespaceRule, PageRule};
|
||||
use stylesheets::{StyleRule, StylesheetContents, SupportsRule};
|
||||
use stylesheets::keyframes_rule::Keyframe;
|
||||
use use_counters::UseCounters;
|
||||
|
||||
macro_rules! impl_arc_ffi {
|
||||
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => {
|
||||
|
@ -59,6 +61,9 @@ macro_rules! impl_arc_ffi {
|
|||
};
|
||||
}
|
||||
|
||||
impl_arc_ffi!(UseCounters => StyleUseCounters
|
||||
[Servo_UseCounters_AddRef, Servo_UseCounters_Release]);
|
||||
|
||||
impl_arc_ffi!(Locked<CssRules> => ServoCssRules
|
||||
[Servo_CssRules_AddRef, Servo_CssRules_Release]);
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ impl<'a> ParserContext<'a> {
|
|||
parsing_mode: ParsingMode,
|
||||
quirks_mode: QuirksMode,
|
||||
error_reporter: Option<&'a ParseErrorReporter>,
|
||||
use_counters: Option<&'a UseCounters>,
|
||||
) -> Self {
|
||||
Self {
|
||||
stylesheet_origin,
|
||||
|
@ -77,7 +78,7 @@ impl<'a> ParserContext<'a> {
|
|||
quirks_mode,
|
||||
error_reporter,
|
||||
namespaces: None,
|
||||
use_counters: None,
|
||||
use_counters,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +90,7 @@ impl<'a> ParserContext<'a> {
|
|||
parsing_mode: ParsingMode,
|
||||
quirks_mode: QuirksMode,
|
||||
error_reporter: Option<&'a ParseErrorReporter>,
|
||||
use_counters: Option<&'a UseCounters>,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
Origin::Author,
|
||||
|
@ -97,6 +99,7 @@ impl<'a> ParserContext<'a> {
|
|||
parsing_mode,
|
||||
quirks_mode,
|
||||
error_reporter,
|
||||
use_counters,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1203,6 +1203,7 @@ pub fn parse_style_attribute(
|
|||
ParsingMode::DEFAULT,
|
||||
quirks_mode,
|
||||
error_reporter,
|
||||
None,
|
||||
);
|
||||
|
||||
let mut input = ParserInput::new(input);
|
||||
|
@ -1230,6 +1231,7 @@ pub fn parse_one_declaration_into(
|
|||
parsing_mode,
|
||||
quirks_mode,
|
||||
error_reporter,
|
||||
None,
|
||||
);
|
||||
|
||||
let mut input = ParserInput::new(input);
|
||||
|
|
|
@ -1563,6 +1563,7 @@ impl UnparsedValue {
|
|||
ParsingMode::DEFAULT,
|
||||
quirks_mode,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
let mut input = ParserInput::new(&css);
|
||||
|
|
|
@ -219,6 +219,7 @@ impl Keyframe {
|
|||
ParsingMode::DEFAULT,
|
||||
parent_stylesheet_contents.quirks_mode,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
context.namespaces = Some(&*namespaces);
|
||||
let mut input = ParserInput::new(css);
|
||||
|
|
|
@ -264,6 +264,7 @@ impl CssRule {
|
|||
ParsingMode::DEFAULT,
|
||||
parent_stylesheet_contents.quirks_mode,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
let mut input = ParserInput::new(css);
|
||||
|
|
|
@ -24,6 +24,7 @@ use stylesheets::loader::StylesheetLoader;
|
|||
use stylesheets::rule_parser::{State, TopLevelRuleParser};
|
||||
use stylesheets::rules_iterator::{EffectiveRules, EffectiveRulesIterator};
|
||||
use stylesheets::rules_iterator::{NestedRuleIterationCondition, RulesIterator};
|
||||
use use_counters::UseCounters;
|
||||
|
||||
/// This structure holds the user-agent and user stylesheets.
|
||||
pub struct UserAgentStylesheets {
|
||||
|
@ -78,6 +79,7 @@ impl StylesheetContents {
|
|||
error_reporter: Option<&ParseErrorReporter>,
|
||||
quirks_mode: QuirksMode,
|
||||
line_number_offset: u32,
|
||||
use_counters: Option<&UseCounters>,
|
||||
) -> Self {
|
||||
let namespaces = RwLock::new(Namespaces::default());
|
||||
let (rules, source_map_url, source_url) = Stylesheet::parse_rules(
|
||||
|
@ -90,6 +92,7 @@ impl StylesheetContents {
|
|||
error_reporter,
|
||||
quirks_mode,
|
||||
line_number_offset,
|
||||
use_counters,
|
||||
);
|
||||
|
||||
Self {
|
||||
|
@ -315,6 +318,8 @@ impl Stylesheet {
|
|||
line_number_offset: u32,
|
||||
) {
|
||||
let namespaces = RwLock::new(Namespaces::default());
|
||||
|
||||
// FIXME: Consider adding use counters to Servo?
|
||||
let (rules, source_map_url, source_url) = Self::parse_rules(
|
||||
css,
|
||||
&url_data,
|
||||
|
@ -325,6 +330,7 @@ impl Stylesheet {
|
|||
error_reporter,
|
||||
existing.contents.quirks_mode,
|
||||
line_number_offset,
|
||||
/* use_counters = */ None,
|
||||
);
|
||||
|
||||
*existing.contents.url_data.write() = url_data;
|
||||
|
@ -350,6 +356,7 @@ impl Stylesheet {
|
|||
error_reporter: Option<&ParseErrorReporter>,
|
||||
quirks_mode: QuirksMode,
|
||||
line_number_offset: u32,
|
||||
use_counters: Option<&UseCounters>,
|
||||
) -> (Vec<CssRule>, Option<String>, Option<String>) {
|
||||
let mut rules = Vec::new();
|
||||
let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset);
|
||||
|
@ -362,6 +369,7 @@ impl Stylesheet {
|
|||
ParsingMode::DEFAULT,
|
||||
quirks_mode,
|
||||
error_reporter,
|
||||
use_counters,
|
||||
);
|
||||
|
||||
let rule_parser = TopLevelRuleParser {
|
||||
|
@ -421,6 +429,7 @@ impl Stylesheet {
|
|||
quirks_mode: QuirksMode,
|
||||
line_number_offset: u32,
|
||||
) -> Self {
|
||||
// FIXME: Consider adding use counters to Servo?
|
||||
let contents = StylesheetContents::from_str(
|
||||
css,
|
||||
url_data,
|
||||
|
@ -430,6 +439,7 @@ impl Stylesheet {
|
|||
error_reporter,
|
||||
quirks_mode,
|
||||
line_number_offset,
|
||||
/* use_counters = */ None,
|
||||
);
|
||||
|
||||
Stylesheet {
|
||||
|
|
|
@ -33,6 +33,7 @@ impl NonCustomPropertyUseCounters {
|
|||
}
|
||||
|
||||
/// The use-counter data related to a given document we want to store.
|
||||
#[derive(Default)]
|
||||
pub struct UseCounters {
|
||||
/// The counters for non-custom properties that have been parsed in the
|
||||
/// document's stylesheets.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue