mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Fix indentation of multiple CssParserContext construction.
This commit is contained in:
parent
92e9f12bd0
commit
7a5a35f5e0
6 changed files with 132 additions and 103 deletions
|
@ -61,6 +61,7 @@ pub struct ParserContext<'a> {
|
||||||
|
|
||||||
impl<'a> ParserContext<'a> {
|
impl<'a> ParserContext<'a> {
|
||||||
/// Create a parser context.
|
/// Create a parser context.
|
||||||
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
stylesheet_origin: Origin,
|
stylesheet_origin: Origin,
|
||||||
url_data: &'a UrlExtraData,
|
url_data: &'a UrlExtraData,
|
||||||
|
@ -79,6 +80,7 @@ impl<'a> ParserContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a parser context for on-the-fly parsing in CSSOM
|
/// Create a parser context for on-the-fly parsing in CSSOM
|
||||||
|
#[inline]
|
||||||
pub fn new_for_cssom(
|
pub fn new_for_cssom(
|
||||||
url_data: &'a UrlExtraData,
|
url_data: &'a UrlExtraData,
|
||||||
rule_type: Option<CssRuleType>,
|
rule_type: Option<CssRuleType>,
|
||||||
|
@ -95,6 +97,7 @@ impl<'a> ParserContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a parser context based on a previous context, but with a modified rule type.
|
/// Create a parser context based on a previous context, but with a modified rule type.
|
||||||
|
#[inline]
|
||||||
pub fn new_with_rule_type(
|
pub fn new_with_rule_type(
|
||||||
context: &'a ParserContext,
|
context: &'a ParserContext,
|
||||||
rule_type: CssRuleType,
|
rule_type: CssRuleType,
|
||||||
|
|
|
@ -1016,18 +1016,23 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
|
||||||
|
|
||||||
/// A helper to parse the style attribute of an element, in order for this to be
|
/// A helper to parse the style attribute of an element, in order for this to be
|
||||||
/// shared between Servo and Gecko.
|
/// shared between Servo and Gecko.
|
||||||
pub fn parse_style_attribute<R>(input: &str,
|
pub fn parse_style_attribute<R>(
|
||||||
url_data: &UrlExtraData,
|
input: &str,
|
||||||
error_reporter: &R,
|
url_data: &UrlExtraData,
|
||||||
quirks_mode: QuirksMode)
|
error_reporter: &R,
|
||||||
-> PropertyDeclarationBlock
|
quirks_mode: QuirksMode,
|
||||||
where R: ParseErrorReporter
|
) -> PropertyDeclarationBlock
|
||||||
|
where
|
||||||
|
R: ParseErrorReporter
|
||||||
{
|
{
|
||||||
let context = ParserContext::new(Origin::Author,
|
let context = ParserContext::new(
|
||||||
url_data,
|
Origin::Author,
|
||||||
Some(CssRuleType::Style),
|
url_data,
|
||||||
ParsingMode::DEFAULT,
|
Some(CssRuleType::Style),
|
||||||
quirks_mode);
|
ParsingMode::DEFAULT,
|
||||||
|
quirks_mode,
|
||||||
|
);
|
||||||
|
|
||||||
let error_context = ParserErrorContext { error_reporter: error_reporter };
|
let error_context = ParserErrorContext { error_reporter: error_reporter };
|
||||||
let mut input = ParserInput::new(input);
|
let mut input = ParserInput::new(input);
|
||||||
parse_property_declaration_list(&context, &error_context, &mut Parser::new(&mut input))
|
parse_property_declaration_list(&context, &error_context, &mut Parser::new(&mut input))
|
||||||
|
@ -1049,11 +1054,14 @@ pub fn parse_one_declaration_into<R>(
|
||||||
where
|
where
|
||||||
R: ParseErrorReporter
|
R: ParseErrorReporter
|
||||||
{
|
{
|
||||||
let context = ParserContext::new(Origin::Author,
|
let context = ParserContext::new(
|
||||||
url_data,
|
Origin::Author,
|
||||||
Some(CssRuleType::Style),
|
url_data,
|
||||||
parsing_mode,
|
Some(CssRuleType::Style),
|
||||||
quirks_mode);
|
parsing_mode,
|
||||||
|
quirks_mode,
|
||||||
|
);
|
||||||
|
|
||||||
let mut input = ParserInput::new(input);
|
let mut input = ParserInput::new(input);
|
||||||
let mut parser = Parser::new(&mut input);
|
let mut parser = Parser::new(&mut input);
|
||||||
let start_position = parser.position();
|
let start_position = parser.position();
|
||||||
|
|
|
@ -954,7 +954,8 @@ impl UnparsedValue {
|
||||||
::custom_properties::substitute(&self.css, self.first_token_type, custom_properties)
|
::custom_properties::substitute(&self.css, self.first_token_type, custom_properties)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|css| {
|
.and_then(|css| {
|
||||||
// As of this writing, only the base URL is used for property values:
|
// As of this writing, only the base URL is used for property
|
||||||
|
// values.
|
||||||
let context = ParserContext::new(
|
let context = ParserContext::new(
|
||||||
Origin::Author,
|
Origin::Author,
|
||||||
&self.url_data,
|
&self.url_data,
|
||||||
|
@ -962,6 +963,7 @@ impl UnparsedValue {
|
||||||
ParsingMode::DEFAULT,
|
ParsingMode::DEFAULT,
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut input = ParserInput::new(&css);
|
let mut input = ParserInput::new(&css);
|
||||||
Parser::new(&mut input).parse_entirely(|input| {
|
Parser::new(&mut input).parse_entirely(|input| {
|
||||||
match self.from_shorthand {
|
match self.from_shorthand {
|
||||||
|
|
|
@ -313,8 +313,11 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> {
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
rule_type: CssRuleType
|
rule_type: CssRuleType
|
||||||
) -> Arc<Locked<CssRules>> {
|
) -> Arc<Locked<CssRules>> {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(self.context, rule_type, self.namespaces);
|
self.context,
|
||||||
|
rule_type,
|
||||||
|
self.namespaces,
|
||||||
|
);
|
||||||
|
|
||||||
let nested_parser = NestedRuleParser {
|
let nested_parser = NestedRuleParser {
|
||||||
stylesheet_origin: self.stylesheet_origin,
|
stylesheet_origin: self.stylesheet_origin,
|
||||||
|
@ -439,33 +442,32 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
) -> Result<CssRule, ParseError<'i>> {
|
) -> Result<CssRule, ParseError<'i>> {
|
||||||
match prelude {
|
match prelude {
|
||||||
AtRuleBlockPrelude::FontFace(location) => {
|
AtRuleBlockPrelude::FontFace(location) => {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::FontFace,
|
||||||
CssRuleType::FontFace,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
|
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
|
||||||
parse_font_face_block(&context, self.error_context, input, location).into()))))
|
parse_font_face_block(&context, self.error_context, input, location).into()))))
|
||||||
}
|
}
|
||||||
AtRuleBlockPrelude::FontFeatureValues(family_names, location) => {
|
AtRuleBlockPrelude::FontFeatureValues(family_names, location) => {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::FontFeatureValues,
|
||||||
CssRuleType::FontFeatureValues,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
|
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
|
||||||
FontFeatureValuesRule::parse(&context, self.error_context, input, family_names, location)))))
|
FontFeatureValuesRule::parse(&context, self.error_context, input, family_names, location)))))
|
||||||
}
|
}
|
||||||
AtRuleBlockPrelude::CounterStyle(name) => {
|
AtRuleBlockPrelude::CounterStyle(name) => {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::CounterStyle,
|
||||||
CssRuleType::CounterStyle,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap(
|
Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap(
|
||||||
parse_counter_style_body(name, &context, self.error_context, input)?.into()))))
|
parse_counter_style_body(name, &context, self.error_context, input)?.into()))))
|
||||||
}
|
}
|
||||||
|
@ -477,12 +479,12 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
}))))
|
}))))
|
||||||
}
|
}
|
||||||
AtRuleBlockPrelude::Supports(cond, location) => {
|
AtRuleBlockPrelude::Supports(cond, location) => {
|
||||||
let eval_context =
|
let eval_context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::Style,
|
||||||
CssRuleType::Style,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
let enabled = cond.eval(&eval_context);
|
let enabled = cond.eval(&eval_context);
|
||||||
Ok(CssRule::Supports(Arc::new(self.shared_lock.wrap(SupportsRule {
|
Ok(CssRule::Supports(Arc::new(self.shared_lock.wrap(SupportsRule {
|
||||||
condition: cond,
|
condition: cond,
|
||||||
|
@ -492,22 +494,21 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
}))))
|
}))))
|
||||||
}
|
}
|
||||||
AtRuleBlockPrelude::Viewport => {
|
AtRuleBlockPrelude::Viewport => {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::Viewport,
|
||||||
CssRuleType::Viewport,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
|
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
|
||||||
ViewportRule::parse(&context, self.error_context, input)?))))
|
ViewportRule::parse(&context, self.error_context, input)?))))
|
||||||
}
|
}
|
||||||
AtRuleBlockPrelude::Keyframes(name, prefix, location) => {
|
AtRuleBlockPrelude::Keyframes(name, prefix, location) => {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::Keyframes,
|
||||||
CssRuleType::Keyframes,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule {
|
Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule {
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -517,12 +518,12 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
||||||
}))))
|
}))))
|
||||||
}
|
}
|
||||||
AtRuleBlockPrelude::Page(location) => {
|
AtRuleBlockPrelude::Page(location) => {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::Page,
|
||||||
CssRuleType::Page,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
let declarations = parse_property_declaration_list(&context, self.error_context, input);
|
let declarations = parse_property_declaration_list(&context, self.error_context, input);
|
||||||
Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule {
|
Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule {
|
||||||
block: Arc::new(self.shared_lock.wrap(declarations)),
|
block: Arc::new(self.shared_lock.wrap(declarations)),
|
||||||
|
@ -573,12 +574,12 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRulePa
|
||||||
prelude: QualifiedRuleParserPrelude,
|
prelude: QualifiedRuleParserPrelude,
|
||||||
input: &mut Parser<'i, 't>
|
input: &mut Parser<'i, 't>
|
||||||
) -> Result<CssRule, ParseError<'i>> {
|
) -> Result<CssRule, ParseError<'i>> {
|
||||||
let context =
|
let context = ParserContext::new_with_rule_type(
|
||||||
ParserContext::new_with_rule_type(
|
self.context,
|
||||||
self.context,
|
CssRuleType::Style,
|
||||||
CssRuleType::Style,
|
self.namespaces,
|
||||||
self.namespaces,
|
);
|
||||||
);
|
|
||||||
let declarations = parse_property_declaration_list(&context, self.error_context, input);
|
let declarations = parse_property_declaration_list(&context, self.error_context, input);
|
||||||
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
|
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
|
||||||
selectors: prelude.selectors,
|
selectors: prelude.selectors,
|
||||||
|
|
|
@ -309,13 +309,16 @@ impl StylesheetInDocument for DocumentStyleSheet {
|
||||||
|
|
||||||
impl Stylesheet {
|
impl Stylesheet {
|
||||||
/// Updates an empty stylesheet from a given string of text.
|
/// Updates an empty stylesheet from a given string of text.
|
||||||
pub fn update_from_str<R>(existing: &Stylesheet,
|
pub fn update_from_str<R>(
|
||||||
css: &str,
|
existing: &Stylesheet,
|
||||||
url_data: UrlExtraData,
|
css: &str,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
url_data: UrlExtraData,
|
||||||
error_reporter: &R,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
line_number_offset: u32)
|
error_reporter: &R,
|
||||||
where R: ParseErrorReporter
|
line_number_offset: u32,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
R: ParseErrorReporter,
|
||||||
{
|
{
|
||||||
let namespaces = RwLock::new(Namespaces::default());
|
let namespaces = RwLock::new(Namespaces::default());
|
||||||
let (rules, source_map_url, source_url) =
|
let (rules, source_map_url, source_url) =
|
||||||
|
@ -359,14 +362,14 @@ impl Stylesheet {
|
||||||
let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset);
|
let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset);
|
||||||
let mut input = Parser::new(&mut input);
|
let mut input = Parser::new(&mut input);
|
||||||
|
|
||||||
let context =
|
let context = ParserContext::new(
|
||||||
ParserContext::new(
|
origin,
|
||||||
origin,
|
url_data,
|
||||||
url_data,
|
None,
|
||||||
None,
|
ParsingMode::DEFAULT,
|
||||||
ParsingMode::DEFAULT,
|
quirks_mode
|
||||||
quirks_mode
|
);
|
||||||
);
|
|
||||||
let error_context = ParserErrorContext { error_reporter };
|
let error_context = ParserErrorContext { error_reporter };
|
||||||
|
|
||||||
let rule_parser = TopLevelRuleParser {
|
let rule_parser = TopLevelRuleParser {
|
||||||
|
|
|
@ -2492,11 +2492,13 @@ pub extern "C" fn Servo_ParseEasing(
|
||||||
|
|
||||||
// FIXME Dummy URL data would work fine here.
|
// FIXME Dummy URL data would work fine here.
|
||||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||||
let context = ParserContext::new(Origin::Author,
|
let context = ParserContext::new(
|
||||||
url_data,
|
Origin::Author,
|
||||||
Some(CssRuleType::Style),
|
url_data,
|
||||||
ParsingMode::DEFAULT,
|
Some(CssRuleType::Style),
|
||||||
QuirksMode::NoQuirks);
|
ParsingMode::DEFAULT,
|
||||||
|
QuirksMode::NoQuirks,
|
||||||
|
);
|
||||||
let easing = unsafe { (*easing).to_string() };
|
let easing = unsafe { (*easing).to_string() };
|
||||||
let mut input = ParserInput::new(&easing);
|
let mut input = ParserInput::new(&easing);
|
||||||
let mut parser = Parser::new(&mut input);
|
let mut parser = Parser::new(&mut input);
|
||||||
|
@ -2961,9 +2963,12 @@ pub extern "C" fn Servo_MediaList_AppendMedium(
|
||||||
) {
|
) {
|
||||||
let new_medium = unsafe { new_medium.as_ref().unwrap().as_str_unchecked() };
|
let new_medium = unsafe { new_medium.as_ref().unwrap().as_str_unchecked() };
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media),
|
let context = ParserContext::new_for_cssom(
|
||||||
ParsingMode::DEFAULT,
|
url_data,
|
||||||
QuirksMode::NoQuirks);
|
Some(CssRuleType::Media),
|
||||||
|
ParsingMode::DEFAULT,
|
||||||
|
QuirksMode::NoQuirks,
|
||||||
|
);
|
||||||
write_locked_arc(list, |list: &mut MediaList| {
|
write_locked_arc(list, |list: &mut MediaList| {
|
||||||
list.append_medium(&context, new_medium);
|
list.append_medium(&context, new_medium);
|
||||||
})
|
})
|
||||||
|
@ -2976,9 +2981,12 @@ pub extern "C" fn Servo_MediaList_DeleteMedium(
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let old_medium = unsafe { old_medium.as_ref().unwrap().as_str_unchecked() };
|
let old_medium = unsafe { old_medium.as_ref().unwrap().as_str_unchecked() };
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media),
|
let context = ParserContext::new_for_cssom(
|
||||||
ParsingMode::DEFAULT,
|
url_data,
|
||||||
QuirksMode::NoQuirks);
|
Some(CssRuleType::Media),
|
||||||
|
ParsingMode::DEFAULT,
|
||||||
|
QuirksMode::NoQuirks,
|
||||||
|
);
|
||||||
write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium))
|
write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3362,9 +3370,13 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(
|
||||||
|
|
||||||
let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) };
|
let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) };
|
||||||
let string = unsafe { (*value).to_string() };
|
let string = unsafe { (*value).to_string() };
|
||||||
let context = ParserContext::new(Origin::Author, url_data,
|
let context = ParserContext::new(
|
||||||
Some(CssRuleType::Style), ParsingMode::DEFAULT,
|
Origin::Author,
|
||||||
QuirksMode::NoQuirks);
|
url_data,
|
||||||
|
Some(CssRuleType::Style),
|
||||||
|
ParsingMode::DEFAULT,
|
||||||
|
QuirksMode::NoQuirks,
|
||||||
|
);
|
||||||
if let Ok(mut url) = SpecifiedUrl::parse_from_string(string.into(), &context) {
|
if let Ok(mut url) = SpecifiedUrl::parse_from_string(string.into(), &context) {
|
||||||
url.build_image_value();
|
url.build_image_value();
|
||||||
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
|
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
|
||||||
|
@ -3420,13 +3432,13 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = unsafe { dummy_url_data() };
|
||||||
// NOTE(emilio): The supports API is not associated to any stylesheet,
|
// NOTE(emilio): The supports API is not associated to any stylesheet,
|
||||||
// so the fact that there are no namespace map here is fine.
|
// so the fact that there are no namespace map here is fine.
|
||||||
let context =
|
let context = ParserContext::new_for_cssom(
|
||||||
ParserContext::new_for_cssom(
|
url_data,
|
||||||
url_data,
|
Some(CssRuleType::Style),
|
||||||
Some(CssRuleType::Style),
|
ParsingMode::DEFAULT,
|
||||||
ParsingMode::DEFAULT,
|
QuirksMode::NoQuirks,
|
||||||
QuirksMode::NoQuirks,
|
);
|
||||||
);
|
|
||||||
cond.eval(&context)
|
cond.eval(&context)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue