mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Defined new trait ParseErrorReporter and added error_reporter member to ParserContext
This commit is contained in:
parent
8efc954531
commit
996e9e06b2
24 changed files with 194 additions and 69 deletions
|
@ -22,7 +22,7 @@ use euclid::SideOffsets2D;
|
|||
use euclid::size::Size2D;
|
||||
use fnv::FnvHasher;
|
||||
use string_cache::Atom;
|
||||
|
||||
use style_traits::ParseErrorReporter;
|
||||
use computed_values;
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use selectors::matching::DeclarationBlock;
|
||||
|
@ -135,6 +135,7 @@ pub mod longhands {
|
|||
use properties::{ComputedValues, PropertyDeclaration};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use style_traits::ParseErrorReporter;
|
||||
use values::computed::ToComputedValue;
|
||||
use values::{computed, specified};
|
||||
use string_cache::Atom;
|
||||
|
@ -145,7 +146,8 @@ pub mod longhands {
|
|||
inherited_style: &ComputedValues,
|
||||
context: &computed::Context,
|
||||
seen: &mut PropertyBitField,
|
||||
cacheable: &mut bool) {
|
||||
cacheable: &mut bool,
|
||||
error_reporter: Box<ParseErrorReporter + Send>) {
|
||||
let declared_value = match *declaration {
|
||||
PropertyDeclaration::${property.camel_case}(ref declared_value) => {
|
||||
declared_value
|
||||
|
@ -174,7 +176,7 @@ pub mod longhands {
|
|||
.${property.ident}
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
}, error_reporter.clone()
|
||||
);
|
||||
Arc::make_mut(&mut style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
||||
computed_value;
|
||||
|
@ -186,7 +188,8 @@ pub mod longhands {
|
|||
inherited_style,
|
||||
context,
|
||||
seen,
|
||||
cacheable);
|
||||
cacheable,
|
||||
error_reporter);
|
||||
% endif
|
||||
% else:
|
||||
// Do not allow stylesheets to set derived properties.
|
||||
|
@ -533,7 +536,8 @@ pub mod longhands {
|
|||
_inherited_style: &ComputedValues,
|
||||
context: &computed::Context,
|
||||
_seen: &mut PropertyBitField,
|
||||
_cacheable: &mut bool) {
|
||||
_cacheable: &mut bool,
|
||||
_error_reporter: Box<ParseErrorReporter + Send>) {
|
||||
Arc::make_mut(&mut style.box_)._servo_display_for_hypothetical_box =
|
||||
longhands::_servo_display_for_hypothetical_box::derive_from_display(
|
||||
*computed_value,
|
||||
|
@ -2234,7 +2238,8 @@ pub mod longhands {
|
|||
_inherited_style: &ComputedValues,
|
||||
context: &computed::Context,
|
||||
_seen: &mut PropertyBitField,
|
||||
_cacheable: &mut bool) {
|
||||
_cacheable: &mut bool,
|
||||
_error_reporter: Box<ParseErrorReporter + Send>) {
|
||||
Arc::make_mut(&mut style.inheritedtext)._servo_text_decorations_in_effect =
|
||||
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(
|
||||
*computed_value,
|
||||
|
@ -5613,7 +5618,7 @@ mod property_bit_field {
|
|||
fn substitute_variables_${property.ident}<F, R>(
|
||||
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
|
||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
f: F)
|
||||
f: F, error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> R
|
||||
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R
|
||||
{
|
||||
|
@ -5625,7 +5630,7 @@ mod property_bit_field {
|
|||
.and_then(|css| {
|
||||
// As of this writing, only the base URL is used for property values:
|
||||
let context = ParserContext::new(
|
||||
::stylesheets::Origin::Author, base_url);
|
||||
::stylesheets::Origin::Author, base_url, error_reporter);
|
||||
Parser::new(&css).parse_entirely(|input| {
|
||||
match from_shorthand {
|
||||
None => {
|
||||
|
@ -5668,15 +5673,15 @@ pub struct PropertyDeclarationBlock {
|
|||
pub normal: Arc<Vec<PropertyDeclaration>>,
|
||||
}
|
||||
|
||||
|
||||
pub fn parse_style_attribute(input: &str, base_url: &Url) -> PropertyDeclarationBlock {
|
||||
let context = ParserContext::new(Origin::Author, base_url);
|
||||
pub fn parse_style_attribute(input: &str, base_url: &Url, error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> PropertyDeclarationBlock {
|
||||
let context = ParserContext::new(Origin::Author, base_url, error_reporter);
|
||||
parse_property_declaration_list(&context, &mut Parser::new(input))
|
||||
}
|
||||
|
||||
pub fn parse_one_declaration(name: &str, input: &str, base_url: &Url)
|
||||
pub fn parse_one_declaration(name: &str, input: &str, base_url: &Url, error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> Result<Vec<PropertyDeclaration>, ()> {
|
||||
let context = ParserContext::new(Origin::Author, base_url);
|
||||
let context = ParserContext::new(Origin::Author, base_url, error_reporter);
|
||||
let mut results = vec![];
|
||||
match PropertyDeclaration::parse(name, &context, &mut Parser::new(input), &mut results) {
|
||||
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => Ok(results),
|
||||
|
@ -6389,7 +6394,8 @@ fn cascade_with_cached_declarations(
|
|||
parent_style: &ComputedValues,
|
||||
cached_style: &ComputedValues,
|
||||
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
context: &computed::Context)
|
||||
context: &computed::Context,
|
||||
error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> ComputedValues {
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% if style_struct.inherited:
|
||||
|
@ -6433,7 +6439,7 @@ fn cascade_with_cached_declarations(
|
|||
.clone()
|
||||
}
|
||||
DeclaredValue::WithVariables { .. } => unreachable!()
|
||||
}
|
||||
}, error_reporter.clone()
|
||||
);
|
||||
Arc::make_mut(&mut style_${style_struct.ident})
|
||||
.${property.ident} = computed_value;
|
||||
|
@ -6488,7 +6494,8 @@ type CascadePropertyFn = extern "Rust" fn(declaration: &PropertyDeclaration,
|
|||
inherited_style: &ComputedValues,
|
||||
context: &computed::Context,
|
||||
seen: &mut PropertyBitField,
|
||||
cacheable: &mut bool);
|
||||
cacheable: &mut bool,
|
||||
error_reporter: Box<ParseErrorReporter + Send>);
|
||||
|
||||
// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
|
||||
// properties.
|
||||
|
@ -6533,7 +6540,8 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
applicable_declarations: &[DeclarationBlock<Vec<PropertyDeclaration>>],
|
||||
shareable: bool,
|
||||
parent_style: Option< &ComputedValues >,
|
||||
cached_style: Option< &ComputedValues >)
|
||||
cached_style: Option< &ComputedValues >,
|
||||
error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> (ComputedValues, bool) {
|
||||
let initial_values = &*INITIAL_VALUES;
|
||||
let (is_root_element, inherited_style) = match parent_style {
|
||||
|
@ -6588,7 +6596,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
|
||||
// This assumes that the computed and specified values have the same Rust type.
|
||||
macro_rules! get_specified(
|
||||
($style_struct_getter: ident, $property: ident, $declared_value: expr) => {
|
||||
($style_struct_getter: ident, $property: ident, $declared_value: expr, $error_reporter: expr) => {
|
||||
concat_idents!(substitute_variables_, $property)(
|
||||
$declared_value, &custom_properties, |value| match *value {
|
||||
DeclaredValue::Value(specified_value) => specified_value,
|
||||
|
@ -6597,7 +6605,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
inherited_style.$style_struct_getter().$property.clone()
|
||||
}
|
||||
DeclaredValue::WithVariables { .. } => unreachable!()
|
||||
}
|
||||
}, $error_reporter.clone()
|
||||
)
|
||||
};
|
||||
);
|
||||
|
@ -6636,7 +6644,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
DeclaredValue::Initial => longhands::font_size::get_initial_value(),
|
||||
DeclaredValue::Inherit => context.inherited_font_size,
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
}
|
||||
}, error_reporter.clone()
|
||||
);
|
||||
}
|
||||
PropertyDeclaration::Color(ref value) => {
|
||||
|
@ -6648,35 +6656,35 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
DeclaredValue::Initial => longhands::color::get_initial_value(),
|
||||
DeclaredValue::Inherit => inherited_style.get_color().color.clone(),
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
}
|
||||
}, error_reporter.clone()
|
||||
);
|
||||
}
|
||||
PropertyDeclaration::Display(ref value) => {
|
||||
context.display = get_specified!(get_box, display, value);
|
||||
context.display = get_specified!(get_box, display, value, error_reporter.clone());
|
||||
}
|
||||
PropertyDeclaration::Position(ref value) => {
|
||||
context.positioned = match get_specified!(get_box, position, value) {
|
||||
context.positioned = match get_specified!(get_box, position, value, error_reporter.clone()) {
|
||||
longhands::position::SpecifiedValue::absolute |
|
||||
longhands::position::SpecifiedValue::fixed => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
PropertyDeclaration::OverflowX(ref value) => {
|
||||
context.overflow_x = get_specified!(get_box, overflow_x, value);
|
||||
context.overflow_x = get_specified!(get_box, overflow_x, value, error_reporter.clone());
|
||||
}
|
||||
PropertyDeclaration::OverflowY(ref value) => {
|
||||
context.overflow_y = get_specified!(get_box, overflow_y, value);
|
||||
context.overflow_y = get_specified!(get_box, overflow_y, value, error_reporter.clone());
|
||||
}
|
||||
PropertyDeclaration::Float(ref value) => {
|
||||
context.floated = get_specified!(get_box, float, value)
|
||||
context.floated = get_specified!(get_box, float, value, error_reporter.clone())
|
||||
!= longhands::float::SpecifiedValue::none;
|
||||
}
|
||||
PropertyDeclaration::TextDecoration(ref value) => {
|
||||
context.text_decoration = get_specified!(get_text, text_decoration, value);
|
||||
context.text_decoration = get_specified!(get_text, text_decoration, value, error_reporter.clone());
|
||||
}
|
||||
PropertyDeclaration::OutlineStyle(ref value) => {
|
||||
context.outline_style_present =
|
||||
match get_specified!(get_outline, outline_style, value) {
|
||||
match get_specified!(get_outline, outline_style, value, error_reporter.clone()) {
|
||||
BorderStyle::none => false,
|
||||
_ => true,
|
||||
};
|
||||
|
@ -6684,7 +6692,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
% for side in ["top", "right", "bottom", "left"]:
|
||||
PropertyDeclaration::Border${side.capitalize()}Style(ref value) => {
|
||||
context.border_${side}_present =
|
||||
match get_specified!(get_border, border_${side}_style, value) {
|
||||
match get_specified!(get_border, border_${side}_style, value, error_reporter.clone()) {
|
||||
BorderStyle::none | BorderStyle::hidden => false,
|
||||
_ => true,
|
||||
};
|
||||
|
@ -6702,7 +6710,8 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
parent_style,
|
||||
cached_style,
|
||||
custom_properties,
|
||||
&context), false)
|
||||
&context,
|
||||
error_reporter), false)
|
||||
}
|
||||
(_, _) => {}
|
||||
}
|
||||
|
@ -6746,7 +6755,8 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
inherited_style,
|
||||
&context,
|
||||
&mut seen,
|
||||
&mut cacheable);
|
||||
&mut cacheable,
|
||||
error_reporter.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue