Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Less messy namespace handling. #18142

Merged
merged 4 commits into from Aug 18, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -36,9 +36,13 @@ impl CSS {
decl.push_str(&value);
let decl = Declaration(decl);
let url = win.Document().url();
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports),
PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks);
let context = ParserContext::new_for_cssom(
&url,
win.css_error_reporter(),
Some(CssRuleType::Style),
PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks
);
decl.eval(&context)
}

@@ -49,9 +53,13 @@ impl CSS {
let cond = parse_condition_or_declaration(&mut input);
if let Ok(cond) = cond {
let url = win.Document().url();
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports),
PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks);
let context = ParserContext::new_for_cssom(
&url,
win.css_error_reporter(),
Some(CssRuleType::Style),
PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks
);
cond.eval(&context)
} else {
false
@@ -61,13 +61,14 @@ pub struct ParserContext<'a> {

impl<'a> ParserContext<'a> {
/// Create a parser context.
pub fn new(stylesheet_origin: Origin,
url_data: &'a UrlExtraData,
error_reporter: &'a ParseErrorReporter,
rule_type: Option<CssRuleType>,
parsing_mode: ParsingMode,
quirks_mode: QuirksMode)
-> ParserContext<'a> {
pub fn new(
stylesheet_origin: Origin,
url_data: &'a UrlExtraData,
error_reporter: &'a ParseErrorReporter,
rule_type: Option<CssRuleType>,
parsing_mode: ParsingMode,
quirks_mode: QuirksMode,
) -> ParserContext<'a> {
ParserContext {
stylesheet_origin: stylesheet_origin,
url_data: url_data,
@@ -88,23 +89,31 @@ impl<'a> ParserContext<'a> {
parsing_mode: ParsingMode,
quirks_mode: QuirksMode
) -> ParserContext<'a> {
Self::new(Origin::Author, url_data, error_reporter, rule_type, parsing_mode, quirks_mode)
Self::new(
Origin::Author,
url_data,
error_reporter,
rule_type,
parsing_mode,
quirks_mode,
)
}

/// Create a parser context based on a previous context, but with a modified rule type.
pub fn new_with_rule_type(
context: &'a ParserContext,
rule_type: Option<CssRuleType>
rule_type: CssRuleType,
namespaces: &'a Namespaces,
) -> ParserContext<'a> {
ParserContext {
stylesheet_origin: context.stylesheet_origin,
url_data: context.url_data,
error_reporter: context.error_reporter,
rule_type: rule_type,
rule_type: Some(rule_type),
line_number_offset: context.line_number_offset,
parsing_mode: context.parsing_mode,
quirks_mode: context.quirks_mode,
namespaces: context.namespaces,
namespaces: Some(namespaces),
}
}

@@ -115,7 +124,7 @@ impl<'a> ParserContext<'a> {
error_reporter: &'a ParseErrorReporter,
line_number_offset: u64,
parsing_mode: ParsingMode,
quirks_mode: QuirksMode
quirks_mode: QuirksMode,
) -> ParserContext<'a> {
ParserContext {
stylesheet_origin: stylesheet_origin,
@@ -322,14 +322,17 @@ macro_rules! font_feature_values_blocks {
}
}

fn parse_block<'t>(&mut self, prelude: Self::Prelude, input: &mut Parser<'i, 't>)
-> Result<Self::AtRule, ParseError<'i>> {
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::FontFeatureValues));
fn parse_block<'t>(
&mut self,
prelude: Self::Prelude,
input: &mut Parser<'i, 't>
) -> Result<Self::AtRule, ParseError<'i>> {
debug_assert_eq!(self.context.rule_type(), CssRuleType::FontFeatureValues);
match prelude {
$(
BlockType::$ident_camel => {
let parser = FFVDeclarationsParser {
context: &context,
context: &self.context,
declarations: &mut self.rule.$ident,
};

@@ -338,7 +341,7 @@ macro_rules! font_feature_values_blocks {
if let Err(err) = declaration {
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
err.slice, err.error);
context.log_css_error(err.location, error);
self.context.log_css_error(err.location, error);
}
}
},
@@ -214,12 +214,16 @@ impl Keyframe {
) -> Result<Arc<Locked<Self>>, ParseError<'i>> {
let url_data = parent_stylesheet_contents.url_data.read();
let error_reporter = NullReporter;
let context = ParserContext::new(parent_stylesheet_contents.origin,
&url_data,
&error_reporter,
Some(CssRuleType::Keyframe),
PARSING_MODE_DEFAULT,
parent_stylesheet_contents.quirks_mode);
let namespaces = parent_stylesheet_contents.namespaces.read();
let mut context = ParserContext::new(
parent_stylesheet_contents.origin,
&url_data,
&error_reporter,
Some(CssRuleType::Keyframe),
PARSING_MODE_DEFAULT,
parent_stylesheet_contents.quirks_mode
);
context.namespaces = Some(&*namespaces);
let mut input = ParserInput::new(css);
let mut input = Parser::new(&mut input);

@@ -450,8 +454,14 @@ struct KeyframeListParser<'a> {
}

/// Parses a keyframe list from CSS input.
pub fn parse_keyframe_list(context: &ParserContext, input: &mut Parser, shared_lock: &SharedRwLock)
-> Vec<Arc<Locked<Keyframe>>> {
pub fn parse_keyframe_list(
context: &ParserContext,
input: &mut Parser,
shared_lock: &SharedRwLock
) -> Vec<Arc<Locked<Keyframe>>> {
debug_assert!(context.namespaces.is_some(),
"Parsing a keyframe list from a context without namespaces?");

let mut declarations = SourcePropertyDeclaration::new();
RuleListParser::new_for_nested_rule(input, KeyframeListParser {
context: context,
@@ -487,7 +497,13 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {

fn parse_block<'t>(&mut self, prelude: Self::Prelude, input: &mut Parser<'i, 't>)
-> Result<Self::QualifiedRule, ParseError<'i>> {
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Keyframe));
let context =
ParserContext::new_with_rule_type(
self.context,
CssRuleType::Keyframe,
self.context.namespaces.unwrap(),
);

let parser = KeyframeDeclarationParser {
context: &context,
declarations: self.declarations,
@@ -134,7 +134,7 @@ impl MallocSizeOfWithGuard for CssRule {
}

#[allow(missing_docs)]
#[derive(PartialEq, Eq, Copy, Clone)]
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum CssRuleType {
// https://drafts.csswg.org/cssom/#the-cssrule-interface
Style = 1,
@@ -249,7 +249,7 @@ impl CssRule {
loader: loader,
state: state,
had_hierarchy_error: false,
namespaces: Some(&mut *guard),
namespaces: &mut *guard,
};

parse_one_rule(&mut input, &mut rule_parser)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.