diff --git a/components/layout/block.rs b/components/layout/block.rs index 003f1fb2e02..351b0dba9d9 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1417,7 +1417,7 @@ impl BlockFlow { // Per CSS 2.1 § 16.3.1, text alignment propagates to all children in flow. // // TODO(#2265, pcwalton): Do this in the cascade instead. - let containing_block_text_align = self.fragment.style().get_inheritedtext().text_align; + let containing_block_text_align = self.fragment.style().get_inherited_text().text_align; kid.mut_base().flags.set_text_align(containing_block_text_align); // Handle `text-indent` on behalf of any inline children that we have. This is @@ -1425,7 +1425,7 @@ impl BlockFlow { // we know. if kid.is_inline_flow() { kid.as_mut_inline().first_line_indentation = - self.fragment.style().get_inheritedtext().text_indent + self.fragment.style().get_inherited_text().text_indent .to_used_value(containing_block_size); } } @@ -2340,7 +2340,7 @@ pub trait ISizeAndMarginsComputer { containing_block_inline_size), MaybeAuto::from_style(position.inline_end, containing_block_inline_size), - style.get_inheritedtext().text_align, + style.get_inherited_text().text_align, available_inline_size) } diff --git a/components/layout/construct.rs b/components/layout/construct.rs index efa3ccd176a..063b1ee710f 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -1095,7 +1095,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> kid_flow.as_block() .fragment .style() - .get_inheritedtable() + .get_inherited_table() .caption_side == side { table_wrapper_flow.add_new_child(kid_flow); } @@ -1256,7 +1256,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> // Determine if the table cell should be hidden. Per CSS 2.1 § 17.6.1.1, this will be true // if the cell has any in-flow elements (even empty ones!) and has `empty-cells` set to // `hide`. - let hide = node.style(self.style_context()).get_inheritedtable().empty_cells == EmptyCells::Hide && + let hide = node.style(self.style_context()).get_inherited_table().empty_cells == EmptyCells::Hide && node.children().all(|kid| { let position = kid.style(self.style_context()).get_box().position; !kid.is_content() || @@ -1871,7 +1871,7 @@ fn bidi_control_chars(style: &ServoArc) -> Option<(&'static str, use style::computed_values::unicode_bidi::T::*; let unicode_bidi = style.get_text().unicode_bidi; - let direction = style.get_inheritedbox().direction; + let direction = style.get_inherited_box().direction; // See the table in http://dev.w3.org/csswg/css-writing-modes/#unicode-bidi match (unicode_bidi, direction) { diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 16a1fc85770..d8467958038 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -1013,7 +1013,7 @@ impl FragmentDisplayListBuilding for Fragment { id: webrender_image.key.unwrap(), stretch_size: placement.tile_size.to_layout(), tile_spacing: placement.tile_spacing.to_layout(), - image_rendering: style.get_inheritedbox().image_rendering.to_layout(), + image_rendering: style.get_inherited_box().image_rendering.to_layout(), }))); }); } @@ -1581,7 +1581,7 @@ impl FragmentDisplayListBuilding for Fragment { display_list_section: DisplayListSection, clip: Rect, ) { - if self.style().get_inheritedbox().visibility != Visibility::Visible { + if self.style().get_inherited_box().visibility != Visibility::Visible { return; } @@ -1744,7 +1744,7 @@ impl FragmentDisplayListBuilding for Fragment { state, &text_fragment, stacking_relative_content_box, - &self.style.get_inheritedtext().text_shadow.0, + &self.style.get_inherited_text().text_shadow.0, clip, ); @@ -1765,7 +1765,7 @@ impl FragmentDisplayListBuilding for Fragment { state, &text_fragment, stacking_relative_content_box, - &self.style.get_inheritedtext().text_shadow.0, + &self.style.get_inherited_text().text_shadow.0, clip, ); @@ -1837,7 +1837,7 @@ impl FragmentDisplayListBuilding for Fragment { stretch_size: stacking_relative_content_box.size.to_layout(), tile_spacing: LayoutSize::zero(), image_rendering: self.style - .get_inheritedbox() + .get_inherited_box() .image_rendering .to_layout(), }))); @@ -2005,7 +2005,7 @@ impl FragmentDisplayListBuilding for Fragment { } // Create display items for text decorations. - let text_decorations = self.style().get_inheritedtext().text_decorations_in_effect; + let text_decorations = self.style().get_inherited_text().text_decorations_in_effect; let logical_stacking_relative_content_box = LogicalRect::from_physical( self.style.writing_mode, @@ -3048,8 +3048,8 @@ impl ComputedValuesCursorUtility for ComputedValues { #[inline] fn get_cursor(&self, default_cursor: CursorKind) -> Option { match ( - self.get_inheritedui().pointer_events, - &self.get_inheritedui().cursor, + self.get_inherited_ui().pointer_events, + &self.get_inherited_ui().cursor, ) { (PointerEvents::None, _) => None, ( diff --git a/components/layout/flex.rs b/components/layout/flex.rs index 42ed7910b8d..2864c922874 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -561,7 +561,7 @@ impl FlexFlow { .explicit_block_size(parent_container_size) .map(|x| max(x - box_border, Au(0))); let containing_block_text_align = - self.block_flow.fragment.style().get_inheritedtext().text_align; + self.block_flow.fragment.style().get_inherited_text().text_align; while let Some(mut line) = self.get_flex_line(inline_size) { let items = &mut self.items[line.range.clone()]; diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 38ea9d03b93..b7b3ac07d64 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -818,7 +818,7 @@ impl Fragment { SpecificFragmentInfo::TableCell => { let base_quantities = QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_PADDING | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; - if self.style.get_inheritedtable().border_collapse == + if self.style.get_inherited_table().border_collapse == BorderCollapse::Separate { base_quantities | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER } else { @@ -828,7 +828,7 @@ impl Fragment { SpecificFragmentInfo::TableWrapper => { let base_quantities = QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_MARGINS | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; - if self.style.get_inheritedtable().border_collapse == + if self.style.get_inherited_table().border_collapse == BorderCollapse::Separate { base_quantities | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER } else { @@ -838,7 +838,7 @@ impl Fragment { SpecificFragmentInfo::TableRow => { let base_quantities = QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; - if self.style.get_inheritedtable().border_collapse == + if self.style.get_inherited_table().border_collapse == BorderCollapse::Separate { base_quantities | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER } else { @@ -1272,7 +1272,7 @@ impl Fragment { pub fn compute_border_and_padding(&mut self, containing_block_inline_size: Au) { // Compute border. - let border = match self.style.get_inheritedtable().border_collapse { + let border = match self.style.get_inherited_table().border_collapse { BorderCollapse::Separate => self.border_width(), BorderCollapse::Collapse => LogicalMargin::zero(self.style.writing_mode), }; @@ -1377,7 +1377,7 @@ impl Fragment { } pub fn white_space(&self) -> WhiteSpace { - self.style().get_inheritedtext().white_space + self.style().get_inherited_text().white_space } pub fn color(&self) -> Color { @@ -1625,12 +1625,12 @@ impl Fragment { let mut flags = SplitOptions::empty(); if starts_line { flags.insert(SplitOptions::STARTS_LINE); - if self.style().get_inheritedtext().overflow_wrap == OverflowWrap::BreakWord { + if self.style().get_inherited_text().overflow_wrap == OverflowWrap::BreakWord { flags.insert(SplitOptions::RETRY_AT_CHARACTER_BOUNDARIES) } } - match self.style().get_inheritedtext().word_break { + match self.style().get_inherited_text().word_break { WordBreak::Normal | WordBreak::KeepAll => { // Break at normal word boundaries. keep-all forbids soft wrap opportunities. let natural_word_breaking_strategy = diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 83961219e37..58d6a498457 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -934,7 +934,7 @@ impl InlineFlow { if fragments.fragments.is_empty() { return } - let text_justify = fragments.fragments[0].style().get_inheritedtext().text_justify; + let text_justify = fragments.fragments[0].style().get_inherited_text().text_justify; // Translate `left` and `right` to logical directions. let is_ltr = fragments.fragments[0].style().writing_mode.is_bidi_ltr(); @@ -1341,7 +1341,7 @@ impl Flow for InlineFlow { let mut intrinsic_sizes_for_nonbroken_run = IntrinsicISizesContribution::new(); for fragment in &mut self.fragments.fragments { let intrinsic_sizes_for_fragment = fragment.compute_intrinsic_inline_sizes().finish(); - match fragment.style.get_inheritedtext().white_space { + match fragment.style.get_inherited_text().white_space { WhiteSpace::Nowrap => { intrinsic_sizes_for_nonbroken_run.union_nonbreaking_inline( &intrinsic_sizes_for_fragment) diff --git a/components/layout/query.rs b/components/layout/query.rs index b52d415939f..408e220dfe4 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -959,7 +959,7 @@ fn inner_text_collection_steps(node: N, }; // Step 2. - if style.get_inheritedbox().visibility != Visibility::Visible { + if style.get_inherited_box().visibility != Visibility::Visible { continue; } diff --git a/components/layout/table.rs b/components/layout/table.rs index a258a570692..658a39d8e21 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -191,8 +191,8 @@ impl TableFlow { /// Returns the effective spacing per cell, taking the value of `border-collapse` into account. pub fn spacing(&self) -> border_spacing::T { let style = self.block_flow.fragment.style(); - match style.get_inheritedtable().border_collapse { - border_collapse::T::Separate => style.get_inheritedtable().border_spacing, + match style.get_inherited_table().border_collapse { + border_collapse::T::Separate => style.get_inherited_table().border_spacing, border_collapse::T::Collapse => border_spacing::T::zero(), } } @@ -298,7 +298,7 @@ impl Flow for TableFlow { let collapsing_borders = self.block_flow .fragment .style - .get_inheritedtable() + .get_inherited_table() .border_collapse == border_collapse::T::Collapse; let table_inline_collapsed_borders = if collapsing_borders { Some(TableInlineCollapsedBorders { @@ -522,7 +522,7 @@ impl Flow for TableFlow { let border_painting_mode = match self.block_flow .fragment .style - .get_inheritedtable() + .get_inherited_table() .border_collapse { border_collapse::T::Separate => BorderPaintingMode::Separate, border_collapse::T::Collapse => BorderPaintingMode::Hidden, @@ -771,12 +771,12 @@ pub trait TableLikeFlow { impl TableLikeFlow for BlockFlow { fn assign_block_size_for_table_like_flow(&mut self, block_direction_spacing: Au, layout_context: &LayoutContext) { - debug_assert!(self.fragment.style.get_inheritedtable().border_collapse == + debug_assert!(self.fragment.style.get_inherited_table().border_collapse == border_collapse::T::Separate || block_direction_spacing == Au(0)); fn border_spacing_for_row(fragment: &Fragment, row: &TableRowFlow, block_direction_spacing: Au) -> Au { - match fragment.style.get_inheritedtable().border_collapse { + match fragment.style.get_inherited_table().border_collapse { border_collapse::T::Separate => block_direction_spacing, border_collapse::T::Collapse => { row.collapsed_border_spacing.block_start @@ -1204,13 +1204,13 @@ impl<'table> TableCellStyleInfo<'table> { use style::computed_values::visibility::T as Visibility; if !self.cell.visible || self.cell.block_flow.fragment.style() - .get_inheritedbox().visibility != Visibility::Visible { + .get_inherited_box().visibility != Visibility::Visible { return } let border_painting_mode = match self.cell.block_flow .fragment .style - .get_inheritedtable() + .get_inherited_table() .border_collapse { border_collapse::T::Separate => BorderPaintingMode::Separate, border_collapse::T::Collapse => BorderPaintingMode::Collapse(&self.cell.collapsed_borders), diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 933d3be632e..ffecce5d6c7 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -353,7 +353,7 @@ impl Flow for TableRowFlow { let collapsing_borders = self.block_flow .fragment .style() - .get_inheritedtable() + .get_inherited_table() .border_collapse == BorderCollapse::Collapse; let row_style = &*self.block_flow.fragment.style; self.preliminary_collapsed_borders.reset( @@ -500,7 +500,7 @@ impl Flow for TableRowFlow { // Set up border collapse info. let border_collapse_info = - match self.block_flow.fragment.style().get_inheritedtable().border_collapse { + match self.block_flow.fragment.style().get_inherited_table().border_collapse { BorderCollapse::Collapse => { Some(BorderCollapseInfoForChildTableCell { collapsed_borders_for_row: &self.final_collapsed_borders, diff --git a/components/layout/table_rowgroup.rs b/components/layout/table_rowgroup.rs index 85bccb18ade..cac1657bd43 100644 --- a/components/layout/table_rowgroup.rs +++ b/components/layout/table_rowgroup.rs @@ -130,7 +130,7 @@ impl Flow for TableRowGroupFlow { let (inline_start_content_edge, inline_end_content_edge) = (Au(0), Au(0)); let content_inline_size = containing_block_inline_size; - let border_collapse = self.block_flow.fragment.style.get_inheritedtable().border_collapse; + let border_collapse = self.block_flow.fragment.style.get_inherited_table().border_collapse; let inline_size_computer = InternalTable; inline_size_computer.compute_used_inline_size(&mut self.block_flow, shared_context, diff --git a/components/layout/text.rs b/components/layout/text.rs index 15fecd3f7d1..ac93eaed03f 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -170,7 +170,7 @@ impl TextRunScanner { { let in_fragment = self.clump.front().unwrap(); let font_style = in_fragment.style().clone_font(); - let inherited_text_style = in_fragment.style().get_inheritedtext(); + let inherited_text_style = in_fragment.style().get_inherited_text(); font_group = font_context.font_group(font_style); compression = match in_fragment.white_space() { WhiteSpace::Normal | @@ -477,7 +477,7 @@ pub fn font_metrics_for_style(mut font_context: &mut LayoutFontContext, style: : /// Returns the line block-size needed by the given computed style and font size. pub fn line_height_from_style(style: &ComputedValues, metrics: &FontMetrics) -> Au { let font_size = style.get_font().font_size.size(); - match style.get_inheritedtext().line_height { + match style.get_inherited_text().line_height { LineHeight::Normal => Au::from(metrics.line_gap), LineHeight::Number(l) => font_size.scale_by(l.0), LineHeight::Length(l) => Au::from(l) diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 309ddaf7e93..89a21ec64d5 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -979,7 +979,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> { // // If you implement other values for this property, you will almost certainly // want to update this check. - !self.style(context).get_inheritedtext().white_space.preserve_newlines() + !self.style(context).get_inherited_text().white_space.preserve_newlines() } } diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index f0383e871fa..3c39b95a28b 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -128,7 +128,7 @@ use style::context::{QuirksMode, RegisteredSpeculativePainter, RegisteredSpecula use style::context::{SharedStyleContext, StyleSystemOptions, ThreadLocalStyleContextCreationInfo}; use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode}; use style::driver; -use style::error_reporting::{NullReporter, RustLogReporter}; +use style::error_reporting::RustLogReporter; use style::invalidation::element::restyle_hints::RestyleHint; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaList, MediaType}; @@ -1754,7 +1754,7 @@ fn get_ua_stylesheets() -> Result { MediaList::empty(), shared_lock.clone(), None, - &NullReporter, + None, QuirksMode::NoQuirks, )))) } @@ -1782,7 +1782,7 @@ fn get_ua_stylesheets() -> Result { MediaList::empty(), shared_lock.clone(), None, - &RustLogReporter, + Some(&RustLogReporter), QuirksMode::NoQuirks, ))) ); diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs index 4b67f516e83..d642b44a19f 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -42,7 +42,8 @@ impl CSS { &url, Some(CssRuleType::Style), ParsingMode::DEFAULT, - QuirksMode::NoQuirks + QuirksMode::NoQuirks, + None, ); decl.eval(&context) } @@ -58,7 +59,8 @@ impl CSS { &url, Some(CssRuleType::Style), ParsingMode::DEFAULT, - QuirksMode::NoQuirks + QuirksMode::NoQuirks, + None, ); cond.eval(&context) } else { diff --git a/components/script/dom/cssmediarule.rs b/components/script/dom/cssmediarule.rs index 0ecdf71a314..23f3c46a251 100644 --- a/components/script/dom/cssmediarule.rs +++ b/components/script/dom/cssmediarule.rs @@ -75,15 +75,15 @@ impl CSSMediaRule { let window = global.as_window(); let url = window.get_url(); let quirks_mode = window.Document().quirks_mode(); - let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - ParsingMode::DEFAULT, - quirks_mode); - - let new_medialist = StyleMediaList::parse( - &context, - &mut input, + let context = ParserContext::new_for_cssom( + &url, + Some(CssRuleType::Media), + ParsingMode::DEFAULT, + quirks_mode, window.css_error_reporter(), ); + + let new_medialist = StyleMediaList::parse(&context, &mut input); let mut guard = self.cssconditionrule.shared_lock().write(); // Clone an Arc because we can’t borrow `guard` twice at the same time. diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index e3a4a20d380..9f6c97dbc7d 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -181,6 +181,19 @@ macro_rules! css_properties( ); ); +fn remove_property( + decls: &mut PropertyDeclarationBlock, + id: &PropertyId, +) -> bool { + let first_declaration = decls.first_declaration_to_remove(id); + let first_declaration = match first_declaration { + Some(i) => i, + None => return false, + }; + decls.remove_property(id, first_declaration); + true +} + impl CSSStyleDeclaration { #[allow(unrooted_must_root)] pub fn new_inherited(owner: CSSStyleOwner, @@ -253,7 +266,7 @@ impl CSSStyleDeclaration { self.owner.mutate_associated_block(|pdb, changed| { if value.is_empty() { // Step 3 - *changed = pdb.remove_property(&id, |_| {}); + *changed = remove_property(pdb, &id); return Ok(()); } @@ -365,7 +378,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { let mut string = String::new(); self.owner.mutate_associated_block(|pdb, changed| { pdb.property_value_to_css(&id, &mut string).unwrap(); - *changed = pdb.remove_property(&id, |_| {}); + *changed = remove_property(pdb, &id); }); // Step 6 diff --git a/components/script/dom/csssupportsrule.rs b/components/script/dom/csssupportsrule.rs index 68d02aa241a..a96cd706b86 100644 --- a/components/script/dom/csssupportsrule.rs +++ b/components/script/dom/csssupportsrule.rs @@ -63,9 +63,13 @@ impl CSSSupportsRule { let win = global.as_window(); let url = win.Document().url(); let quirks_mode = win.Document().quirks_mode(); - let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Supports), - ParsingMode::DEFAULT, - quirks_mode); + let context = ParserContext::new_for_cssom( + &url, + Some(CssRuleType::Supports), + ParsingMode::DEFAULT, + quirks_mode, + None, + ); let enabled = cond.eval(&context); let mut guard = self.cssconditionrule.shared_lock().write(); let rule = self.supportsrule.write_with(&mut guard); diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 9e048161633..26c59bdb8ec 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -127,6 +127,7 @@ use std::cell::{Cell, Ref, RefMut}; use std::collections::{HashMap, HashSet, VecDeque}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::default::Default; +use std::fmt; use std::mem; use std::ptr::NonNull; use std::rc::Rc; @@ -213,6 +214,12 @@ struct StyleSheetInDocument { owner: Dom, } +impl fmt::Debug for StyleSheetInDocument { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + self.sheet.fmt(formatter) + } +} + impl PartialEq for StyleSheetInDocument { fn eq(&self, other: &Self) -> bool { Arc::ptr_eq(&self.sheet, &other.sheet) diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 8206af23e3e..61acecda71d 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -770,10 +770,13 @@ pub fn parse_a_sizes_attribute(input: DOMString, width: Option) -> Vec &CSSErrorReporter { - &self.error_reporter + pub fn css_error_reporter(&self) -> Option<&ParseErrorReporter> { + Some(&self.error_reporter) } /// Sets a new list of scroll offsets. @@ -1017,14 +1018,15 @@ impl WindowMethods for Window { let mut parser = Parser::new(&mut input); let url = self.get_url(); let quirks_mode = self.Document().quirks_mode(); - let context = CssParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - ParsingMode::DEFAULT, - quirks_mode); - let media_query_list = media_queries::MediaList::parse( - &context, - &mut parser, + let context = CssParserContext::new_for_cssom( + &url, + Some(CssRuleType::Media), + ParsingMode::DEFAULT, + quirks_mode, self.css_error_reporter(), ); + let media_query_list = + media_queries::MediaList::parse(&context, &mut parser); let document = self.Document(); let mql = MediaQueryList::new(&document, media_query_list); self.media_query_lists.push(&*mql); diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 94b10aa0d33..2542dee3625 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -9,8 +9,8 @@ use Atom; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser}; use cssparser::{CowRcStr, Parser, SourceLocation, Token}; -use error_reporting::{ContextualParseError, ParseErrorReporter}; -use parser::{Parse, ParserContext, ParserErrorContext}; +use error_reporting::ContextualParseError; +use parser::{Parse, ParserContext}; use selectors::parser::SelectorParseErrorKind; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; @@ -73,16 +73,12 @@ pub fn parse_counter_style_name_definition<'i, 't>( } /// Parse the body (inside `{}`) of an @counter-style rule -pub fn parse_counter_style_body<'i, 't, R>( +pub fn parse_counter_style_body<'i, 't>( name: CustomIdent, context: &ParserContext, - error_context: &ParserErrorContext, input: &mut Parser<'i, 't>, location: SourceLocation, -) -> Result> -where - R: ParseErrorReporter, -{ +) -> Result> { let start = input.current_source_location(); let mut rule = CounterStyleRuleData::empty(name, location); { @@ -98,7 +94,7 @@ where slice, error, ); - context.log_css_error(error_context, location, error) + context.log_css_error(location, error) } } } @@ -134,7 +130,7 @@ where _ => None, }; if let Some(error) = error { - context.log_css_error(error_context, start, error); + context.log_css_error(start, error); Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } else { Ok(rule) diff --git a/components/style/encoding_support.rs b/components/style/encoding_support.rs index eadcfa4c159..7aec18bee2c 100644 --- a/components/style/encoding_support.rs +++ b/components/style/encoding_support.rs @@ -55,7 +55,7 @@ impl Stylesheet { /// /// Takes care of decoding the network bytes and forwards the resulting /// string to `Stylesheet::from_str`. - pub fn from_bytes( + pub fn from_bytes( bytes: &[u8], url_data: UrlExtraData, protocol_encoding_label: Option<&str>, @@ -64,12 +64,9 @@ impl Stylesheet { media: MediaList, shared_lock: SharedRwLock, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: &R, + error_reporter: Option<&ParseErrorReporter>, quirks_mode: QuirksMode, - ) -> Stylesheet - where - R: ParseErrorReporter, - { + ) -> Stylesheet { let string = decode_stylesheet_bytes(bytes, protocol_encoding_label, environment_encoding); Stylesheet::from_str( &string, @@ -86,17 +83,15 @@ impl Stylesheet { /// Updates an empty stylesheet with a set of bytes that reached over the /// network. - pub fn update_from_bytes( + pub fn update_from_bytes( existing: &Stylesheet, bytes: &[u8], protocol_encoding_label: Option<&str>, environment_encoding: Option<&'static encoding_rs::Encoding>, url_data: UrlExtraData, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: &R, - ) where - R: ParseErrorReporter, - { + error_reporter: Option<&ParseErrorReporter>, + ) { let string = decode_stylesheet_bytes(bytes, protocol_encoding_label, environment_encoding); Self::update_from_str( existing, diff --git a/components/style/error_reporting.rs b/components/style/error_reporting.rs index 2af76be87b9..b5d5ba17ef8 100644 --- a/components/style/error_reporting.rs +++ b/components/style/error_reporting.rs @@ -7,7 +7,6 @@ #![deny(missing_docs)] use cssparser::{BasicParseErrorKind, ParseErrorKind, SourceLocation, Token}; -use log; use std::fmt; use style_traits::ParseError; use stylesheets::UrlExtraData; @@ -229,8 +228,10 @@ pub trait ParseErrorReporter { /// This logging is silent by default, and can be enabled with a `RUST_LOG=style=info` /// environment variable. /// (See [`env_logger`](https://rust-lang-nursery.github.io/log/env_logger/).) +#[cfg(feature = "servo")] pub struct RustLogReporter; +#[cfg(feature = "servo")] impl ParseErrorReporter for RustLogReporter { fn report_error( &self, @@ -238,6 +239,7 @@ impl ParseErrorReporter for RustLogReporter { location: SourceLocation, error: ContextualParseError, ) { + use log; if log_enabled!(log::Level::Info) { info!( "Url:\t{}\n{}:{} {}", @@ -249,17 +251,3 @@ impl ParseErrorReporter for RustLogReporter { } } } - -/// Error reporter which silently forgets errors -pub struct NullReporter; - -impl ParseErrorReporter for NullReporter { - fn report_error( - &self, - _url: &UrlExtraData, - _location: SourceLocation, - _error: ContextualParseError, - ) { - // do nothing - } -} diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 57c0f3b0b77..d7501c1cca7 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -10,8 +10,8 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use cssparser::{CowRcStr, SourceLocation}; #[cfg(feature = "gecko")] use cssparser::UnicodeRange; -use error_reporting::{ContextualParseError, ParseErrorReporter}; -use parser::{Parse, ParserContext, ParserErrorContext}; +use error_reporting::ContextualParseError; +use parser::{Parse, ParserContext}; #[cfg(feature = "gecko")] use properties::longhands::font_language_override; use selectors::parser::SelectorParseErrorKind; @@ -186,15 +186,11 @@ impl ToCss for FontStyle { /// Parse the block inside a `@font-face` rule. /// /// Note that the prelude parsing code lives in the `stylesheets` module. -pub fn parse_font_face_block( +pub fn parse_font_face_block( context: &ParserContext, - error_context: &ParserErrorContext, input: &mut Parser, location: SourceLocation, -) -> FontFaceRuleData -where - R: ParseErrorReporter, -{ +) -> FontFaceRuleData { let mut rule = FontFaceRuleData::empty(location); { let parser = FontFaceRuleParser { @@ -206,7 +202,7 @@ where if let Err((error, slice)) = declaration { let location = error.location; let error = ContextualParseError::UnsupportedFontFaceDescriptor(slice, error); - context.log_css_error(error_context, location, error) + context.log_css_error(location, error) } } } diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index a4ed8294ac2..6b9005c7560 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -18,13 +18,24 @@ use properties::ComputedValues; use selector_parser::SnapshotMap; use servo_arc::Arc; use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards}; +use std::fmt; use stylesheets::{CssRule, Origin, StylesheetContents, StylesheetInDocument}; use stylist::Stylist; /// Little wrapper to a Gecko style sheet. -#[derive(Debug, Eq, PartialEq)] +#[derive(Eq, PartialEq)] pub struct GeckoStyleSheet(*const DomStyleSheet); +impl fmt::Debug for GeckoStyleSheet { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + let contents = self.contents(); + formatter.debug_struct("GeckoStyleSheet") + .field("origin", &contents.origin) + .field("url_data", &*contents.url_data.read()) + .finish() + } +} + impl ToMediaListKey for ::gecko::data::GeckoStyleSheet { fn to_media_list_key(&self) -> MediaListKey { use std::mem; diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 1c34762f286..771f4570b47 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -64,6 +64,27 @@ pub struct Device { used_viewport_size: AtomicBool, } +impl fmt::Debug for Device { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use nsstring::nsCString; + + let mut doc_uri = nsCString::new(); + unsafe { + let doc = + &*self.pres_context().mDocument.raw::(); + + bindings::Gecko_nsIURI_Debug( + doc.mDocumentURI.raw::(), + &mut doc_uri, + ) + }; + + f.debug_struct("Device") + .field("document_url", &doc_uri) + .finish() + } +} + unsafe impl Sync for Device {} unsafe impl Send for Device {} diff --git a/components/style/gecko/url.rs b/components/style/gecko/url.rs index cb503f4720a..b94d2139764 100644 --- a/components/style/gecko/url.rs +++ b/components/style/gecko/url.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use gecko_bindings::bindings; -use gecko_bindings::structs::{ServoBundledURI, URLExtraData}; +use gecko_bindings::structs::ServoBundledURI; use gecko_bindings::structs::mozilla::css::URLValueData; use gecko_bindings::structs::root::{RustString, nsStyleImageRequest}; use gecko_bindings::structs::root::mozilla::css::{ImageValue, URLValue}; @@ -18,6 +18,7 @@ use servo_arc::{Arc, RawOffsetArc}; use std::fmt::{self, Write}; use std::mem; use style_traits::{CssWriter, ParseError, ToCss}; +use stylesheets::UrlExtraData; use values::computed::{Context, ToComputedValue}; /// A CSS url() value for gecko. @@ -32,7 +33,7 @@ pub struct CssUrl { /// The URL extra data. #[css(skip)] - pub extra_data: RefPtr, + pub extra_data: UrlExtraData, } impl CssUrl { @@ -58,7 +59,7 @@ impl CssUrl { &url.mString as *const _ as *const RawOffsetArc; CssUrl { serialization: Arc::from_raw_offset((*arc_type).clone()), - extra_data: url.mExtraData.to_safe(), + extra_data: UrlExtraData(url.mExtraData.to_safe()), } } @@ -88,7 +89,7 @@ impl CssUrl { let arc_offset = Arc::into_raw_offset(self.serialization.clone()); ServoBundledURI { mURLString: unsafe { mem::transmute::<_, RawOffsetArc>(arc_offset) }, - mExtraData: self.extra_data.get(), + mExtraData: self.extra_data.0.get(), } } } diff --git a/components/style/gecko_bindings/sugar/refptr.rs b/components/style/gecko_bindings/sugar/refptr.rs index 10c9e627699..6a32b81430e 100644 --- a/components/style/gecko_bindings/sugar/refptr.rs +++ b/components/style/gecko_bindings/sugar/refptr.rs @@ -78,15 +78,6 @@ impl RefPtr { ret } - /// Create a reference to RefPtr from a reference to pointer. - /// - /// The pointer must be valid and non null. - /// - /// This method doesn't touch refcount. - pub unsafe fn from_ptr_ref(ptr: &*mut T) -> &Self { - mem::transmute(ptr) - } - /// Produces an FFI-compatible RefPtr that can be stored in style structs. /// /// structs::RefPtr does not have a destructor, so this may leak diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index 297599e2080..b0c8750265b 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -122,7 +122,8 @@ impl WeakAtom { unsafe { u8_ptr.offset(string_offset) as *const u16 } } else { let atom_ptr = self.as_ptr() as *const nsDynamicAtom; - unsafe { (*(atom_ptr)).mString } + // Dynamic atom chars are stored at the end of the object. + unsafe { atom_ptr.offset(1) as *const u16 } }; unsafe { slice::from_raw_parts(string, self.len() as usize) } } diff --git a/components/style/media_queries/media_list.rs b/components/style/media_queries/media_list.rs index 5243174e07f..a5604b6dc19 100644 --- a/components/style/media_queries/media_list.rs +++ b/components/style/media_queries/media_list.rs @@ -9,13 +9,13 @@ use context::QuirksMode; use cssparser::{Delimiter, Parser}; use cssparser::{ParserInput, Token}; -use error_reporting::{ContextualParseError, ParseErrorReporter}; -use parser::{ParserContext, ParserErrorContext}; +use error_reporting::ContextualParseError; +use parser::ParserContext; use super::{Device, MediaQuery, Qualifier}; /// A type that encapsulates a media query list. -#[css(comma)] -#[derive(Clone, Debug, MallocSizeOf, ToCss)] +#[css(comma, derive_debug)] +#[derive(Clone, MallocSizeOf, ToCss)] pub struct MediaList { /// The list of media queries. #[css(iterable)] @@ -30,14 +30,10 @@ impl MediaList { /// "not all", see: /// /// - pub fn parse( + pub fn parse( context: &ParserContext, input: &mut Parser, - error_reporter: &R, - ) -> MediaList - where - R: ParseErrorReporter, - { + ) -> Self { if input.is_exhausted() { return Self::empty(); } @@ -54,8 +50,7 @@ impl MediaList { let location = err.location; let error = ContextualParseError::InvalidMediaRule(input.slice_from(start_position), err); - let error_context = ParserErrorContext { error_reporter }; - context.log_css_error(&error_context, location, error); + context.log_css_error(location, error); }, } diff --git a/components/style/parser.rs b/components/style/parser.rs index 6dbfe1cfa01..a4b7d816203 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -36,12 +36,6 @@ pub fn assert_parsing_mode_match() { } } -/// The context required to report a parse error. -pub struct ParserErrorContext<'a, R: 'a> { - /// An error reporter to report syntax errors. - pub error_reporter: &'a R, -} - /// The data that the parser needs from outside in order to parse a stylesheet. pub struct ParserContext<'a> { /// The `Origin` of the stylesheet, whether it's a user, author or @@ -55,6 +49,8 @@ pub struct ParserContext<'a> { pub parsing_mode: ParsingMode, /// The quirks mode of this stylesheet. pub quirks_mode: QuirksMode, + /// The active error reporter, or none if error reporting is disabled. + error_reporter: Option<&'a ParseErrorReporter>, /// The currently active namespaces. pub namespaces: Option<&'a Namespaces>, } @@ -68,6 +64,7 @@ impl<'a> ParserContext<'a> { rule_type: Option, parsing_mode: ParsingMode, quirks_mode: QuirksMode, + error_reporter: Option<&'a ParseErrorReporter>, ) -> Self { ParserContext { stylesheet_origin, @@ -75,6 +72,7 @@ impl<'a> ParserContext<'a> { rule_type, parsing_mode, quirks_mode, + error_reporter, namespaces: None, } } @@ -86,6 +84,7 @@ impl<'a> ParserContext<'a> { rule_type: Option, parsing_mode: ParsingMode, quirks_mode: QuirksMode, + error_reporter: Option<&'a ParseErrorReporter>, ) -> Self { Self::new( Origin::Author, @@ -93,6 +92,7 @@ impl<'a> ParserContext<'a> { rule_type, parsing_mode, quirks_mode, + error_reporter, ) } @@ -110,6 +110,7 @@ impl<'a> ParserContext<'a> { parsing_mode: context.parsing_mode, quirks_mode: context.quirks_mode, namespaces: Some(namespaces), + error_reporter: context.error_reporter, } } @@ -127,21 +128,17 @@ impl<'a> ParserContext<'a> { } /// Record a CSS parse error with this context’s error reporting. - pub fn log_css_error( + pub fn log_css_error( &self, - context: &ParserErrorContext, location: SourceLocation, error: ContextualParseError, - ) where - R: ParseErrorReporter, - { - let location = SourceLocation { - line: location.line, - column: location.column, + ) { + let error_reporter = match self.error_reporter { + Some(r) => r, + None => return, }; - context - .error_reporter - .report_error(self.url_data, location, error) + + error_reporter.report_error(self.url_data, location, error) } /// Returns whether chrome-only rules should be parsed. diff --git a/components/style/properties/build.py b/components/style/properties/build.py index 04418723ee4..4f5da29246b 100644 --- a/components/style/properties/build.py +++ b/components/style/properties/build.py @@ -19,6 +19,34 @@ import data RE_PYTHON_ADDR = re.compile(r'<.+? object at 0x[0-9a-fA-F]+>') +OUT_DIR = os.environ.get("OUT_DIR", "") + +STYLE_STRUCT_LIST = [ + "background", + "border", + "box", + "color", + "column", + "counters", + "effects", + "font", + "inherited_box", + "inherited_table", + "inherited_text", + "inherited_ui", + "inherited_svg", + "list", + "margin", + "outline", + "padding", + "position", + "table", + "text", + "ui", + "svg", + "xul", +] + def main(): usage = "Usage: %s [ servo | gecko ] [ style-crate | geckolib