diff --git a/components/layout/construct.rs b/components/layout/construct.rs index cc34642466a..873be2b2743 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -47,6 +47,7 @@ use style::computed_values::content::ContentItem; use style::computed_values::{caption_side, display, empty_cells, float, list_style_position}; use style::computed_values::{position}; use style::properties::{self, ComputedValues, ServoComputedValues}; +use style::servo::SharedStyleContext; use table::TableFlow; use table_caption::TableCaptionFlow; use table_cell::TableCellFlow; @@ -210,15 +211,15 @@ impl InlineFragmentsAccumulator { } } - fn from_inline_node(node: &N) -> InlineFragmentsAccumulator + fn from_inline_node(node: &N, style_context: &SharedStyleContext) -> InlineFragmentsAccumulator where N: ThreadSafeLayoutNode { InlineFragmentsAccumulator { fragments: IntermediateInlineFragments::new(), enclosing_node: Some(InlineFragmentNodeInfo { address: node.opaque(), pseudo: node.get_pseudo_element_type().strip(), - style: node.style().clone(), - selected_style: node.selected_style().clone(), + style: node.style(style_context).clone(), + selected_style: node.selected_style(style_context).clone(), flags: InlineFragmentNodeFlags::empty(), }), bidi_control_chars: None, @@ -287,6 +288,11 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } } + #[inline] + fn style_context(&self) -> &SharedStyleContext { + self.layout_context.style_context() + } + #[inline] fn set_flow_construction_result(&self, node: &ConcreteThreadSafeLayoutNode, @@ -336,7 +342,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> Some(NodeTypeId::Element(ElementTypeId::HTMLElement( HTMLElementTypeId::HTMLCanvasElement))) => { let data = node.canvas_data().unwrap(); - SpecificFragmentInfo::Canvas(box CanvasFragmentInfo::new(node, data)) + SpecificFragmentInfo::Canvas(box CanvasFragmentInfo::new(node, data, self.layout_context)) } _ => { // This includes pseudo-elements. @@ -344,7 +350,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } }; - Fragment::new(node, specific_fragment_info) + Fragment::new(node, specific_fragment_info, self.layout_context) } /// Generates anonymous table objects per CSS 2.1 § 17.2.1. @@ -356,13 +362,14 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> return } + let style_context = self.style_context(); if child.is_table_cell() { - let mut style = child_node.style().clone(); + let mut style = child_node.style(style_context).clone(); properties::modify_style_for_anonymous_table_object(&mut style, display::T::table_row); let fragment = Fragment::from_opaque_node_and_style(child_node.opaque(), PseudoElementType::Normal, style, - child_node.selected_style().clone(), + child_node.selected_style(style_context).clone(), child_node.restyle_damage(), SpecificFragmentInfo::TableRow); let mut new_child: FlowRef = Arc::new(TableRowFlow::from_fragment(fragment)); @@ -371,12 +378,12 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> *child = new_child } if child.is_table_row() || child.is_table_rowgroup() { - let mut style = child_node.style().clone(); + let mut style = child_node.style(style_context).clone(); properties::modify_style_for_anonymous_table_object(&mut style, display::T::table); let fragment = Fragment::from_opaque_node_and_style(child_node.opaque(), PseudoElementType::Normal, style, - child_node.selected_style().clone(), + child_node.selected_style(style_context).clone(), child_node.restyle_damage(), SpecificFragmentInfo::Table); let mut new_child: FlowRef = Arc::new(TableFlow::from_fragment(fragment)); @@ -385,13 +392,13 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> *child = new_child } if child.is_table() { - let mut style = child_node.style().clone(); + let mut style = child_node.style(style_context).clone(); properties::modify_style_for_anonymous_table_object(&mut style, display::T::table); let fragment = Fragment::from_opaque_node_and_style(child_node.opaque(), PseudoElementType::Normal, style, - child_node.selected_style().clone(), + child_node.selected_style(style_context).clone(), child_node.restyle_damage(), SpecificFragmentInfo::TableWrapper); let mut new_child: FlowRef = Arc::new(TableWrapperFlow::from_fragment(fragment, None)); @@ -449,7 +456,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> TextRunScanner::new().scan_for_runs(&mut self.layout_context.font_context(), fragments.fragments); let mut inline_flow_ref: FlowRef = Arc::new( - InlineFlow::from_fragments(scanned_fragments, node.style().writing_mode)); + InlineFlow::from_fragments(scanned_fragments, node.style(self.style_context()).writing_mode)); // Add all the inline-block fragments as children of the inline flow. for inline_block_flow in &inline_block_flows { @@ -479,7 +486,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> let (ascent, descent) = inline_flow.compute_minimum_ascent_and_descent(&mut self.layout_context .font_context(), - &**node.style()); + &**node.style(self.style_context())); inline_flow.minimum_block_size_above_baseline = ascent; inline_flow.minimum_depth_below_baseline = descent; } @@ -587,10 +594,11 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> box UnscannedTextFragmentInfo::new(" ".to_owned(), None)); properties::modify_style_for_replaced_content(&mut whitespace_style); properties::modify_style_for_text(&mut whitespace_style); + let style_context = self.style_context(); let fragment = Fragment::from_opaque_node_and_style(whitespace_node, whitespace_pseudo, whitespace_style, - node.selected_style().clone(), + node.selected_style(style_context).clone(), whitespace_damage, fragment_info); inline_fragment_accumulator.fragments.fragments.push_back(fragment); @@ -696,7 +704,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } } - let mut style = node.style().clone(); + let mut style = node.style(self.style_context()).clone(); if node_is_input_or_text_area { properties::modify_style_for_input_text(&mut style); } @@ -722,7 +730,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> let mut style = (*style).clone(); properties::modify_style_for_text(&mut style); - let selected_style = node.selected_style(); + let selected_style = node.selected_style(self.style_context()); match text_content { TextContent::Text(string) => { @@ -765,7 +773,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> /// to happen. fn build_flow_for_block(&mut self, node: &ConcreteThreadSafeLayoutNode, float_kind: Option) -> ConstructionResult { - if node.style().is_multicol() { + if node.style(self.style_context()).is_multicol() { return self.build_flow_for_multicol(node, float_kind) } @@ -791,7 +799,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> predecessors: mem::replace( fragment_accumulator, InlineFragmentsAccumulator::from_inline_node( - node)).to_intermediate_inline_fragments(), + node, self.style_context())).to_intermediate_inline_fragments(), flow: kid_flow, }; opt_inline_block_splits.push_back(split) @@ -805,8 +813,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> fn build_fragments_for_nonreplaced_inline_content(&mut self, node: &ConcreteThreadSafeLayoutNode) -> ConstructionResult { let mut opt_inline_block_splits: LinkedList = LinkedList::new(); - let mut fragment_accumulator = InlineFragmentsAccumulator::from_inline_node(node); - fragment_accumulator.bidi_control_chars = bidi_control_chars(&*node.style()); + let mut fragment_accumulator = InlineFragmentsAccumulator::from_inline_node(node, self.style_context()); + fragment_accumulator.bidi_control_chars = bidi_control_chars(&*node.style(self.style_context())); let mut abs_descendants = AbsoluteDescendants::new(); @@ -828,7 +836,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> mem::replace( &mut fragment_accumulator, InlineFragmentsAccumulator::from_inline_node( - node)).to_intermediate_inline_fragments(), + node, self.style_context())).to_intermediate_inline_fragments(), flow: flow, }; opt_inline_block_splits.push_back(split); @@ -879,12 +887,13 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> box UnscannedTextFragmentInfo::new(" ".to_owned(), None)); properties::modify_style_for_replaced_content(&mut whitespace_style); properties::modify_style_for_text(&mut whitespace_style); - let fragment = Fragment::from_opaque_node_and_style(whitespace_node, - whitespace_pseudo, - whitespace_style, - node.selected_style().clone(), - whitespace_damage, - fragment_info); + let fragment = + Fragment::from_opaque_node_and_style(whitespace_node, + whitespace_pseudo, + whitespace_style, + node.selected_style(self.style_context()).clone(), + whitespace_damage, + fragment_info); fragment_accumulator.fragments.fragments.push_back(fragment) } ConstructionResult::ConstructionItem(ConstructionItem::TableColumnFragment(_)) => { @@ -894,17 +903,18 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } } - if is_empty && node.style().has_padding_or_border() { + let node_style = node.style(self.style_context()); + if is_empty && node_style.has_padding_or_border() { // An empty inline box needs at least one fragment to draw its background and borders. let info = SpecificFragmentInfo::UnscannedText( box UnscannedTextFragmentInfo::new(String::new(), None)); - let mut modified_style = node.style().clone(); + let mut modified_style = node_style.clone(); properties::modify_style_for_replaced_content(&mut modified_style); properties::modify_style_for_text(&mut modified_style); let fragment = Fragment::from_opaque_node_and_style(node.opaque(), node.get_pseudo_element_type().strip(), modified_style, - node.selected_style().clone(), + node.selected_style(self.style_context()).clone(), node.restyle_damage(), info); fragment_accumulator.fragments.fragments.push_back(fragment) @@ -917,7 +927,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> // If the node is positioned, then it's the containing block for all absolutely- // positioned descendants. - if node.style().get_box().position != position::T::static_ { + if node_style.get_box().position != position::T::static_ { fragment_accumulator.fragments .absolute_descendants .mark_as_having_reached_containing_block(); @@ -944,17 +954,17 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } // If this node is ignorable whitespace, bail out now. - if node.is_ignorable_whitespace() { + if node.is_ignorable_whitespace(self.style_context()) { return ConstructionResult::ConstructionItem(ConstructionItem::Whitespace( node.opaque(), node.get_pseudo_element_type().strip(), - node.style().clone(), + node.style(self.style_context()).clone(), node.restyle_damage())) } // Modify the style as necessary. (See the comment in // `properties::modify_style_for_replaced_content()`.) - let mut style = (*node.style()).clone(); + let mut style = (*node.style(self.style_context())).clone(); properties::modify_style_for_replaced_content(&mut style); // If this is generated content, then we need to initialize the accumulator with the @@ -987,14 +997,15 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> _ => unreachable!() }; - let mut modified_style = (*node.style()).clone(); + let style_context = self.style_context(); + let mut modified_style = (*node.style(self.style_context())).clone(); properties::modify_style_for_outer_inline_block_fragment(&mut modified_style); let fragment_info = SpecificFragmentInfo::InlineBlock(InlineBlockFragmentInfo::new( block_flow)); let fragment = Fragment::from_opaque_node_and_style(node.opaque(), node.get_pseudo_element_type().strip(), modified_style, - node.selected_style().clone(), + node.selected_style(style_context).clone(), node.restyle_damage(), fragment_info); @@ -1022,16 +1033,17 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> let fragment_info = SpecificFragmentInfo::InlineAbsoluteHypothetical( InlineAbsoluteHypotheticalFragmentInfo::new(block_flow)); - let mut style = node.style().clone(); + let style_context = self.style_context(); + let mut style = node.style(style_context).clone(); properties::modify_style_for_inline_absolute_hypothetical_fragment(&mut style); let fragment = Fragment::from_opaque_node_and_style(node.opaque(), PseudoElementType::Normal, style, - node.selected_style().clone(), + node.selected_style(style_context).clone(), node.restyle_damage(), fragment_info); - let mut fragment_accumulator = InlineFragmentsAccumulator::from_inline_node(node); + let mut fragment_accumulator = InlineFragmentsAccumulator::from_inline_node(node, self.style_context()); fragment_accumulator.fragments.fragments.push_back(fragment); fragment_accumulator.fragments.absolute_descendants.push_descendants(abs_descendants); @@ -1087,7 +1099,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> child_flows: Vec, flow: &mut FlowRef, node: &ConcreteThreadSafeLayoutNode) { - let mut anonymous_flow = flow.generate_missing_child_flow(node); + let mut anonymous_flow = flow.generate_missing_child_flow(node, self.layout_context); let mut consecutive_siblings = vec!(); for kid_flow in child_flows { if anonymous_flow.need_anonymous_flow(&*kid_flow) { @@ -1115,10 +1127,10 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> fn build_flow_for_multicol(&mut self, node: &ConcreteThreadSafeLayoutNode, float_kind: Option) -> ConstructionResult { - let fragment = Fragment::new(node, SpecificFragmentInfo::Multicol); + let fragment = Fragment::new(node, SpecificFragmentInfo::Multicol, self.layout_context); let mut flow: FlowRef = Arc::new(MulticolFlow::from_fragment(fragment, float_kind)); - let column_fragment = Fragment::new(node, SpecificFragmentInfo::MulticolColumn); + let column_fragment = Fragment::new(node, SpecificFragmentInfo::MulticolColumn, self.layout_context); let column_flow = Arc::new(MulticolColumnFlow::from_fragment(column_fragment)); // First populate the column flow with its children. @@ -1156,11 +1168,11 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> /// possibly other `TableCaptionFlow`s or `TableFlow`s underneath it. fn build_flow_for_table_wrapper(&mut self, node: &ConcreteThreadSafeLayoutNode, float_value: float::T) -> ConstructionResult { - let fragment = Fragment::new(node, SpecificFragmentInfo::TableWrapper); + let fragment = Fragment::new(node, SpecificFragmentInfo::TableWrapper, self.layout_context); let mut wrapper_flow: FlowRef = Arc::new( TableWrapperFlow::from_fragment(fragment, FloatKind::from_property(float_value))); - let table_fragment = Fragment::new(node, SpecificFragmentInfo::Table); + let table_fragment = Fragment::new(node, SpecificFragmentInfo::Table, self.layout_context); let table_flow = Arc::new(TableFlow::from_fragment(table_fragment)); // First populate the table flow with its children. @@ -1218,7 +1230,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> /// with possibly other `TableRowFlow`s underneath it. fn build_flow_for_table_rowgroup(&mut self, node: &ConcreteThreadSafeLayoutNode) -> ConstructionResult { - let fragment = Fragment::new(node, SpecificFragmentInfo::TableRow); + let fragment = Fragment::new(node, SpecificFragmentInfo::TableRow, self.layout_context); let flow = Arc::new(TableRowGroupFlow::from_fragment(fragment)); self.build_flow_for_block_like(flow, node) } @@ -1226,7 +1238,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> /// Builds a flow for a node with `display: table-row`. This yields a `TableRowFlow` with /// possibly other `TableCellFlow`s underneath it. fn build_flow_for_table_row(&mut self, node: &ConcreteThreadSafeLayoutNode) -> ConstructionResult { - let fragment = Fragment::new(node, SpecificFragmentInfo::TableRow); + let fragment = Fragment::new(node, SpecificFragmentInfo::TableRow, self.layout_context); let flow = Arc::new(TableRowFlow::from_fragment(fragment)); self.build_flow_for_block_like(flow, node) } @@ -1234,14 +1246,14 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> /// Builds a flow for a node with `display: table-cell`. This yields a `TableCellFlow` with /// possibly other `BlockFlow`s or `InlineFlow`s underneath it. fn build_flow_for_table_cell(&mut self, node: &ConcreteThreadSafeLayoutNode) -> ConstructionResult { - let fragment = Fragment::new(node, SpecificFragmentInfo::TableCell); + let fragment = Fragment::new(node, SpecificFragmentInfo::TableCell, self.layout_context); // 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().get_inheritedtable().empty_cells == empty_cells::T::hide && + let hide = node.style(self.style_context()).get_inheritedtable().empty_cells == empty_cells::T::hide && node.children().all(|kid| { - let position = kid.style().get_box().position; + let position = kid.style(self.style_context()).get_box().position; !kid.is_content() || position == position::T::absolute || position == position::T::fixed @@ -1257,15 +1269,15 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> fn build_flow_for_list_item(&mut self, node: &ConcreteThreadSafeLayoutNode, flotation: float::T) -> ConstructionResult { let flotation = FloatKind::from_property(flotation); - let marker_fragments = match node.style().get_list().list_style_image.0 { + let marker_fragments = match node.style(self.style_context()).get_list().list_style_image.0 { Some(ref url) => { let image_info = box ImageFragmentInfo::new(node, Some((*url).clone()), &self.layout_context); - vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info))] + vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info), self.layout_context)] } None => { - match ListStyleTypeContent::from_list_style_type(node.style() + match ListStyleTypeContent::from_list_style_type(node.style(self.style_context()) .get_list() .list_style_type) { ListStyleTypeContent::None => Vec::new(), @@ -1275,14 +1287,15 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> unscanned_marker_fragments.push_back(Fragment::new( node, SpecificFragmentInfo::UnscannedText( - box UnscannedTextFragmentInfo::new(text, None)))); + box UnscannedTextFragmentInfo::new(text, None)), + self.layout_context)); let marker_fragments = TextRunScanner::new().scan_for_runs( &mut self.layout_context.font_context(), unscanned_marker_fragments); marker_fragments.fragments } ListStyleTypeContent::GeneratedContent(info) => { - vec![Fragment::new(node, SpecificFragmentInfo::GeneratedContent(info))] + vec![Fragment::new(node, SpecificFragmentInfo::GeneratedContent(info), self.layout_context)] } } } @@ -1295,7 +1308,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> // there. let mut initial_fragments = IntermediateInlineFragments::new(); let main_fragment = self.build_fragment_for_block(node); - let flow = match node.style().get_list().list_style_position { + let flow = match node.style(self.style_context()).get_list().list_style_position { list_style_position::T::outside => { Arc::new(ListItemFlow::from_fragments_and_flotation( main_fragment, marker_fragments, flotation)) @@ -1322,7 +1335,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> let specific = SpecificFragmentInfo::TableColumn(TableColumnFragmentInfo::new(node)); let construction_item = ConstructionItem::TableColumnFragment(Fragment::new(node, - specific)); + specific, + self.layout_context)); ConstructionResult::ConstructionItem(construction_item) } @@ -1332,7 +1346,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> -> ConstructionResult { let fragment = Fragment::new(node, - SpecificFragmentInfo::TableColumn(TableColumnFragmentInfo::new(node))); + SpecificFragmentInfo::TableColumn(TableColumnFragmentInfo::new(node)), + self.layout_context); let mut col_fragments = vec!(); for kid in node.children() { // CSS 2.1 § 17.2.1. Treat all non-column child fragments of `table-column-group` @@ -1345,7 +1360,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> if col_fragments.is_empty() { debug!("add SpecificFragmentInfo::TableColumn for empty colgroup"); let specific = SpecificFragmentInfo::TableColumn(TableColumnFragmentInfo::new(node)); - col_fragments.push(Fragment::new(node, specific)); + col_fragments.push(Fragment::new(node, specific, self.layout_context)); } let mut flow: FlowRef = Arc::new(TableColGroupFlow::from_fragments(fragment, col_fragments)); flow.finish(); @@ -1387,11 +1402,11 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> return false } - if node.can_be_fragmented() || node.style().is_multicol() { + if node.can_be_fragmented() || node.style(self.style_context()).is_multicol() { return false } - let mut style = node.style().clone(); + let mut style = node.style(self.style_context()).clone(); let mut data = node.mutate_layout_data().unwrap(); let damage = data.restyle_damage; match *node.construction_result_mut(&mut *data) { @@ -1490,18 +1505,20 @@ impl<'a, ConcreteThreadSafeLayoutNode> PostorderNodeMutTraversal { // Pseudo-element. - let style = node.style(); + let style = node.style(self.style_context()); let display = match node.get_pseudo_element_type() { - PseudoElementType::Normal => display::T::inline, - PseudoElementType::Before(display) => display, - PseudoElementType::After(display) => display, - PseudoElementType::DetailsContent(display) => display, - PseudoElementType::DetailsSummary(display) => display, + PseudoElementType::Normal + => display::T::inline, + PseudoElementType::Before(maybe_display) | + PseudoElementType::After(maybe_display) | + PseudoElementType::DetailsContent(maybe_display) | + PseudoElementType::DetailsSummary(maybe_display) + => maybe_display.unwrap_or(style.get_box().display), }; (display, style.get_box().float, style.get_box().position) } Some(NodeTypeId::Element(_)) => { - let style = node.style(); + let style = node.style(self.style_context()); let munged_display = if style.get_box()._servo_display_for_hypothetical_box == display::T::inline { display::T::inline diff --git a/components/layout/context.rs b/components/layout/context.rs index 169c2f38082..9c752645513 100644 --- a/components/layout/context.rs +++ b/components/layout/context.rs @@ -108,7 +108,7 @@ pub struct LayoutContext<'a> { cached_local_layout_context: Rc, } -impl<'a> StyleContext<'a, ServoSelectorImpl, ServoComputedValues> for LayoutContext<'a> { +impl<'a> StyleContext<'a, ServoSelectorImpl> for LayoutContext<'a> { fn shared_context(&self) -> &'a SharedStyleContext { &self.shared.style_context } @@ -129,6 +129,11 @@ impl<'a> LayoutContext<'a> { } } + #[inline(always)] + pub fn style_context(&self) -> &SharedStyleContext { + &self.shared.style_context + } + #[inline(always)] pub fn font_context(&self) -> RefMut { self.cached_local_layout_context.font_context.borrow_mut() diff --git a/components/layout/data.rs b/components/layout/data.rs index f582ec71ffb..4e5c8339157 100644 --- a/components/layout/data.rs +++ b/components/layout/data.rs @@ -17,8 +17,9 @@ pub struct PrivateLayoutData { /// Description of how to account for recent style changes. pub restyle_damage: RestyleDamage, - /// The current results of flow construction for this node. This is either a flow or a - /// `ConstructionItem`. See comments in `construct.rs` for more details. + /// The current results of flow construction for this node. This is either a + /// flow or a `ConstructionItem`. See comments in `construct.rs` for more + /// details. pub flow_construction_result: ConstructionResult, pub before_flow_construction_result: ConstructionResult, diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 2dfcc05ab06..79ab2fc2c07 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -483,7 +483,7 @@ pub trait ImmutableFlowUtils { fn need_anonymous_flow(self, child: &Flow) -> bool; /// Generates missing child flow of this flow. - fn generate_missing_child_flow(self, node: &N) -> FlowRef; + fn generate_missing_child_flow(self, node: &N, ctx: &LayoutContext) -> FlowRef; /// Returns true if this flow contains fragments that are roots of an absolute flow tree. fn contains_roots_of_absolute_flow_tree(&self) -> bool; @@ -1275,8 +1275,9 @@ impl<'a> ImmutableFlowUtils for &'a Flow { /// FIXME(pcwalton): This duplicates some logic in /// `generate_anonymous_table_flows_if_necessary()`. We should remove this function eventually, /// as it's harder to understand. - fn generate_missing_child_flow(self, node: &N) -> FlowRef { - let mut style = node.style().clone(); + fn generate_missing_child_flow(self, node: &N, ctx: &LayoutContext) -> FlowRef { + let style_context = ctx.style_context(); + let mut style = node.style(style_context).clone(); match self.class() { FlowClass::Table | FlowClass::TableRowGroup => { properties::modify_style_for_anonymous_table_object( @@ -1286,7 +1287,7 @@ impl<'a> ImmutableFlowUtils for &'a Flow { node.opaque(), PseudoElementType::Normal, style, - node.selected_style().clone(), + node.selected_style(style_context).clone(), node.restyle_damage(), SpecificFragmentInfo::TableRow); Arc::new(TableRowFlow::from_fragment(fragment)) @@ -1299,10 +1300,10 @@ impl<'a> ImmutableFlowUtils for &'a Flow { node.opaque(), PseudoElementType::Normal, style, - node.selected_style().clone(), + node.selected_style(style_context).clone(), node.restyle_damage(), SpecificFragmentInfo::TableCell); - let hide = node.style().get_inheritedtable().empty_cells == empty_cells::T::hide; + let hide = node.style(style_context).get_inheritedtable().empty_cells == empty_cells::T::hide; Arc::new(TableCellFlow::from_node_fragment_and_visibility_flag(node, fragment, !hide)) }, FlowClass::Flex => { @@ -1310,7 +1311,7 @@ impl<'a> ImmutableFlowUtils for &'a Flow { Fragment::from_opaque_node_and_style(node.opaque(), PseudoElementType::Normal, style, - node.selected_style().clone(), + node.selected_style(style_context).clone(), node.restyle_damage(), SpecificFragmentInfo::Generic); Arc::new(BlockFlow::from_fragment(fragment, None)) diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index ce9e55496c7..9523159de41 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -319,9 +319,9 @@ pub struct CanvasFragmentInfo { } impl CanvasFragmentInfo { - pub fn new(node: &N, data: HTMLCanvasData) -> CanvasFragmentInfo { + pub fn new(node: &N, data: HTMLCanvasData, ctx: &LayoutContext) -> CanvasFragmentInfo { CanvasFragmentInfo { - replaced_image_fragment_info: ReplacedImageFragmentInfo::new(node), + replaced_image_fragment_info: ReplacedImageFragmentInfo::new(node, ctx), ipc_renderer: data.ipc_renderer .map(|renderer| Arc::new(Mutex::new(renderer))), dom_width: Au::from_px(data.width as i32), @@ -382,7 +382,7 @@ impl ImageFragmentInfo { }; ImageFragmentInfo { - replaced_image_fragment_info: ReplacedImageFragmentInfo::new(node), + replaced_image_fragment_info: ReplacedImageFragmentInfo::new(node, layout_context), image: image, metadata: metadata, } @@ -441,9 +441,9 @@ pub struct ReplacedImageFragmentInfo { } impl ReplacedImageFragmentInfo { - pub fn new(node: &N) -> ReplacedImageFragmentInfo + pub fn new(node: &N, ctx: &LayoutContext) -> ReplacedImageFragmentInfo where N: ThreadSafeLayoutNode { - let is_vertical = node.style().writing_mode.is_vertical(); + let is_vertical = node.style(ctx.style_context()).writing_mode.is_vertical(); ReplacedImageFragmentInfo { computed_inline_size: None, computed_block_size: None, @@ -789,8 +789,9 @@ impl TableColumnFragmentInfo { impl Fragment { /// Constructs a new `Fragment` instance. - pub fn new(node: &N, specific: SpecificFragmentInfo) -> Fragment { - let style = node.style().clone(); + pub fn new(node: &N, specific: SpecificFragmentInfo, ctx: &LayoutContext) -> Fragment { + let style_context = ctx.style_context(); + let style = node.style(style_context).clone(); let writing_mode = style.writing_mode; let mut restyle_damage = node.restyle_damage(); @@ -799,7 +800,7 @@ impl Fragment { Fragment { node: node.opaque(), style: style, - selected_style: node.selected_style().clone(), + selected_style: node.selected_style(style_context).clone(), restyle_damage: restyle_damage, border_box: LogicalRect::zero(writing_mode), border_padding: LogicalMargin::zero(writing_mode), diff --git a/components/layout/layout_thread.rs b/components/layout/layout_thread.rs index 64779f8e031..bf325b8dbdd 100644 --- a/components/layout/layout_thread.rs +++ b/components/layout/layout_thread.rs @@ -67,14 +67,13 @@ use std::sync::mpsc::{channel, Sender, Receiver}; use std::sync::{Arc, Mutex, MutexGuard, RwLock}; use style::animation::Animation; use style::computed_values::{filter, mix_blend_mode}; -use style::context::{ReflowGoal, StylistWrapper}; +use style::context::{ReflowGoal}; use style::dom::{TDocument, TElement, TNode}; use style::error_reporting::ParseErrorReporter; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaType}; use style::parallel::WorkQueueData; use style::properties::ComputedValues; -use style::selector_impl::ServoSelectorImpl; use style::selector_matching::USER_OR_USER_AGENT_STYLESHEETS; use style::servo::{SharedStyleContext, Stylesheet, Stylist}; use style::stylesheets::CSSRuleIteratorExt; @@ -107,7 +106,7 @@ pub struct LayoutThreadData { pub display_list: Option>, /// Performs CSS selector matching and style resolution. - pub stylist: Box, + pub stylist: Arc, /// A queued response for the union of the content boxes of a node. pub content_box_response: Rect, @@ -421,7 +420,7 @@ impl LayoutThread { let font_cache_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_font_cache_receiver); - let stylist = box Stylist::new(device); + let stylist = Arc::new(Stylist::new(device)); let outstanding_web_fonts_counter = Arc::new(AtomicUsize::new(0)); for stylesheet in &*USER_OR_USER_AGENT_STYLESHEETS { add_font_face_rules(stylesheet, @@ -510,7 +509,7 @@ impl LayoutThread { style_context: SharedStyleContext { viewport_size: self.viewport_size.clone(), screen_size_changed: screen_size_changed, - stylist: StylistWrapper::(&*rw_data.stylist), + stylist: rw_data.stylist.clone(), generation: self.generation, goal: goal, new_animations_sender: Mutex::new(self.new_animations_sender.clone()), @@ -809,7 +808,7 @@ impl LayoutThread { /// Sets quirks mode for the document, causing the quirks mode stylesheet to be used. fn handle_set_quirks_mode<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) { let mut rw_data = possibly_locked_rw_data.lock(); - rw_data.stylist.set_quirks_mode(true); + Arc::get_mut(&mut rw_data.stylist).unwrap().set_quirks_mode(true); possibly_locked_rw_data.block(rw_data); } @@ -1060,7 +1059,7 @@ impl LayoutThread { // Calculate the actual viewport as per DEVICE-ADAPT § 6 let device = Device::new(MediaType::Screen, initial_viewport); - rw_data.stylist.set_device(device, &data.document_stylesheets); + Arc::get_mut(&mut rw_data.stylist).unwrap().set_device(device, &data.document_stylesheets); let constraints = rw_data.stylist.viewport_constraints().clone(); self.viewport_size = match constraints { @@ -1092,8 +1091,8 @@ impl LayoutThread { } // If the entire flow tree is invalid, then it will be reflowed anyhow. - needs_dirtying |= rw_data.stylist.update(&data.document_stylesheets, - data.stylesheets_changed); + needs_dirtying |= Arc::get_mut(&mut rw_data.stylist).unwrap().update(&data.document_stylesheets, + data.stylesheets_changed); let needs_reflow = viewport_size_changed && !needs_dirtying; unsafe { if needs_dirtying { diff --git a/components/layout/lib.rs b/components/layout/lib.rs index f4978023d76..22dc6546629 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -103,3 +103,4 @@ mod wrapper; // For unit tests: pub use fragment::Fragment; +pub use wrapper::ServoThreadSafeLayoutNode; diff --git a/components/layout/query.rs b/components/layout/query.rs index 5b28acfa462..df94ed0024e 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -574,8 +574,8 @@ pub fn process_resolved_style_request( let layout_node = match *pseudo { Some(PseudoElement::Before) => layout_node.get_before_pseudo(), Some(PseudoElement::After) => layout_node.get_after_pseudo(), - Some(PseudoElement::DetailsSummary) => layout_node.get_details_summary_pseudo(), - Some(PseudoElement::DetailsContent) => layout_node.get_details_content_pseudo(), + Some(PseudoElement::DetailsSummary) | + Some(PseudoElement::DetailsContent) | Some(PseudoElement::Selection) => None, _ => Some(layout_node) }; @@ -590,7 +590,7 @@ pub fn process_resolved_style_request( Some(layout_node) => layout_node }; - let style = &*layout_node.style(); + let style = &*layout_node.resolved_style(); let positioned = match style.get_box().position { position::computed_value::T::relative | @@ -711,7 +711,7 @@ pub fn process_offset_parent_query(requested_node: N, layout_root pub fn process_node_overflow_request(requested_node: N) -> NodeOverflowResponse { let layout_node = requested_node.to_threadsafe(); - let style = &*layout_node.style(); + let style = &*layout_node.resolved_style(); let style_box = style.get_box(); NodeOverflowResponse(Some((Point2D::new(style_box.overflow_x, style_box.overflow_y.0)))) @@ -720,7 +720,7 @@ pub fn process_node_overflow_request(requested_node: N) -> NodeOv pub fn process_margin_style_query(requested_node: N) -> MarginStyleResponse { let layout_node = requested_node.to_threadsafe(); - let style = &*layout_node.style(); + let style = &*layout_node.resolved_style(); let margin = style.get_margin(); MarginStyleResponse { diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index a94203cbf21..e9215f8717f 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -72,7 +72,7 @@ use style::properties::{ComputedValues, ServoComputedValues}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::restyle_hints::ElementSnapshot; use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl}; -use style::servo::PrivateStyleData; +use style::servo::{PrivateStyleData, SharedStyleContext}; use url::Url; use util::str::is_whitespace; @@ -428,14 +428,14 @@ impl<'le> TElement for ServoLayoutElement<'le> { } #[inline] - fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> { + fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str> { unsafe { (*self.element.unsafe_get()).get_attr_val_for_layout(namespace, name) } } #[inline] - fn get_attrs<'a>(&'a self, name: &Atom) -> Vec<&'a str> { + fn get_attrs(&self, name: &Atom) -> Vec<&str> { unsafe { (*self.element.unsafe_get()).get_attr_vals_for_layout(name) } @@ -650,6 +650,16 @@ impl PseudoElementType { PseudoElementType::DetailsContent(_) => PseudoElementType::DetailsContent(()), } } + + pub fn style_pseudo_element(&self) -> PseudoElement { + match *self { + PseudoElementType::Normal => unreachable!("style_pseudo_element called with PseudoElementType::Normal"), + PseudoElementType::Before(_) => PseudoElement::Before, + PseudoElementType::After(_) => PseudoElement::After, + PseudoElementType::DetailsSummary(_) => PseudoElement::DetailsSummary, + PseudoElementType::DetailsContent(_) => PseudoElement::DetailsContent, + } + } } /// A thread-safe version of `LayoutNode`, used during flow construction. This type of layout @@ -661,7 +671,7 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq { /// Creates a new `ThreadSafeLayoutNode` for the same `LayoutNode` /// with a different pseudo-element type. - fn with_pseudo(&self, pseudo: PseudoElementType) -> Self; + fn with_pseudo(&self, pseudo: PseudoElementType>) -> Self; /// Converts self into an `OpaqueNode`. fn opaque(&self) -> OpaqueNode; @@ -685,42 +695,36 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq { fn as_element(&self) -> Self::ConcreteThreadSafeLayoutElement; #[inline] - fn get_pseudo_element_type(&self) -> PseudoElementType; + fn get_pseudo_element_type(&self) -> PseudoElementType>; #[inline] fn get_before_pseudo(&self) -> Option { - self.borrow_layout_data().unwrap() - .style_data.per_pseudo - .get(&PseudoElement::Before) - .map(|style| { - self.with_pseudo(PseudoElementType::Before(style.get_box().display)) - }) + if self.borrow_layout_data().unwrap() + .style_data.per_pseudo + .contains_key(&PseudoElement::Before) { + Some(self.with_pseudo(PseudoElementType::Before(None))) + } else { + None + } } #[inline] fn get_after_pseudo(&self) -> Option { - self.borrow_layout_data().unwrap() - .style_data.per_pseudo - .get(&PseudoElement::After) - .map(|style| { - self.with_pseudo(PseudoElementType::After(style.get_box().display)) - }) + if self.borrow_layout_data().unwrap() + .style_data.per_pseudo + .contains_key(&PseudoElement::After) { + Some(self.with_pseudo(PseudoElementType::After(None))) + } else { + None + } } - // TODO(emilio): Since the ::-details-* pseudos are internal, just affecting one element, and - // only changing `display` property when the element `open` attribute changes, this should be - // eligible for not being cascaded eagerly, reading the display property from layout instead. #[inline] fn get_details_summary_pseudo(&self) -> Option { if self.is_element() && self.as_element().get_local_name() == &atom!("details") && self.as_element().get_namespace() == &ns!(html) { - self.borrow_layout_data().unwrap() - .style_data.per_pseudo - .get(&PseudoElement::DetailsSummary) - .map(|style| { - self.with_pseudo(PseudoElementType::DetailsSummary(style.get_box().display)) - }) + Some(self.with_pseudo(PseudoElementType::DetailsSummary(None))) } else { None } @@ -731,12 +735,12 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq { if self.is_element() && self.as_element().get_local_name() == &atom!("details") && self.as_element().get_namespace() == &ns!(html) { - self.borrow_layout_data().unwrap() - .style_data.per_pseudo - .get(&PseudoElement::DetailsContent) - .map(|style| { - self.with_pseudo(PseudoElementType::DetailsContent(style.get_box().display)) - }) + let display = if self.as_element().get_attr(&ns!(), &atom!("open")).is_some() { + None // Specified by the stylesheet + } else { + Some(display::T::none) + }; + Some(self.with_pseudo(PseudoElementType::DetailsContent(display))) } else { None } @@ -759,23 +763,58 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq { /// /// Unlike the version on TNode, this handles pseudo-elements. #[inline] - fn style(&self) -> Ref> { + fn style(&self, context: &SharedStyleContext) -> Ref> { + match self.get_pseudo_element_type() { + PseudoElementType::Normal => { + Ref::map(self.borrow_layout_data().unwrap(), |data| { + data.style_data.style.as_ref().unwrap() + }) + }, + other => { + // Precompute non-eagerly-cascaded pseudo-element styles if not + // cached before. + let style_pseudo = other.style_pseudo_element(); + if !style_pseudo.is_eagerly_cascaded() && + !self.borrow_layout_data().unwrap().style_data.per_pseudo.contains_key(&style_pseudo) { + let mut data = self.mutate_layout_data().unwrap(); + let new_style = context.stylist + .computed_values_for_pseudo(&style_pseudo, + data.style_data.style.as_ref()); + data.style_data.per_pseudo.insert(style_pseudo.clone(), new_style.unwrap()); + } + + Ref::map(self.borrow_layout_data().unwrap(), |data| { + data.style_data.per_pseudo.get(&style_pseudo).unwrap() + }) + } + } + } + + /// Returns the already resolved style of the node. + /// + /// This differs from `style(ctx)` in that if the pseudo-element has not yet + /// been computed it would panic. + /// + /// This should be used just for querying layout, or when we know the + /// element style is precomputed, not from general layout itself. + #[inline] + fn resolved_style(&self) -> Ref> { Ref::map(self.borrow_layout_data().unwrap(), |data| { - let style = match self.get_pseudo_element_type() { - PseudoElementType::Before(_) => data.style_data.per_pseudo.get(&PseudoElement::Before), - PseudoElementType::After(_) => data.style_data.per_pseudo.get(&PseudoElement::After), - PseudoElementType::DetailsSummary(_) => data.style_data.per_pseudo.get(&PseudoElement::DetailsSummary), - PseudoElementType::DetailsContent(_) => data.style_data.per_pseudo.get(&PseudoElement::DetailsContent), - PseudoElementType::Normal => data.style_data.style.as_ref(), - }; - style.unwrap() + match self.get_pseudo_element_type() { + PseudoElementType::Normal + => data.style_data.style.as_ref().unwrap(), + other + => data.style_data.per_pseudo.get(&other.style_pseudo_element()).unwrap(), + } }) } #[inline] - fn selected_style(&self) -> Ref> { + fn selected_style(&self, _context: &SharedStyleContext) -> Ref> { Ref::map(self.borrow_layout_data().unwrap(), |data| { - data.style_data.per_pseudo.get(&PseudoElement::Selection).unwrap_or(data.style_data.style.as_ref().unwrap()) + data.style_data.per_pseudo + .get(&PseudoElement::Selection) + .unwrap_or(data.style_data.style.as_ref().unwrap()) }) } @@ -786,26 +825,16 @@ pub trait ThreadSafeLayoutNode : Clone + Copy + Sized + PartialEq { let mut data = self.mutate_layout_data().unwrap(); match self.get_pseudo_element_type() { - PseudoElementType::Before(_) => { - data.style_data.per_pseudo.remove(&PseudoElement::Before); - } - PseudoElementType::After(_) => { - data.style_data.per_pseudo.remove(&PseudoElement::After); - } - PseudoElementType::DetailsSummary(_) => { - data.style_data.per_pseudo.remove(&PseudoElement::DetailsSummary); - } - PseudoElementType::DetailsContent(_) => { - data.style_data.per_pseudo.remove(&PseudoElement::DetailsContent); - } - PseudoElementType::Normal => { data.style_data.style = None; } + other => { + data.style_data.per_pseudo.remove(&other.style_pseudo_element()); + } }; } - fn is_ignorable_whitespace(&self) -> bool; + fn is_ignorable_whitespace(&self, context: &SharedStyleContext) -> bool; fn restyle_damage(self) -> RestyleDamage; @@ -884,7 +913,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized { type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode; #[inline] - fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str>; + fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str>; #[inline] fn get_local_name(&self) -> &Atom; @@ -898,7 +927,9 @@ pub struct ServoThreadSafeLayoutNode<'ln> { /// The wrapped node. node: ServoLayoutNode<'ln>, - pseudo: PseudoElementType, + /// The pseudo-element type, with (optionally), + /// an specified display value to override the stylesheet. + pseudo: PseudoElementType>, } impl<'a> PartialEq for ServoThreadSafeLayoutNode<'a> { @@ -948,7 +979,8 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> { type ConcreteThreadSafeLayoutElement = ServoThreadSafeLayoutElement<'ln>; type ChildrenIterator = ThreadSafeLayoutNodeChildrenIterator; - fn with_pseudo(&self, pseudo: PseudoElementType) -> ServoThreadSafeLayoutNode<'ln> { + fn with_pseudo(&self, + pseudo: PseudoElementType>) -> ServoThreadSafeLayoutNode<'ln> { ServoThreadSafeLayoutNode { node: self.node.clone(), pseudo: pseudo, @@ -993,7 +1025,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> { } } - fn get_pseudo_element_type(&self) -> PseudoElementType { + fn get_pseudo_element_type(&self) -> PseudoElementType> { self.pseudo } @@ -1005,7 +1037,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> { self.node.mutate_layout_data() } - fn is_ignorable_whitespace(&self) -> bool { + fn is_ignorable_whitespace(&self, context: &SharedStyleContext) -> bool { unsafe { let text: LayoutJS = match self.get_jsmanaged().downcast() { Some(text) => text, @@ -1022,7 +1054,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().get_inheritedtext().white_space.preserve_newlines() + !self.style(context).get_inheritedtext().white_space.preserve_newlines() } } @@ -1046,13 +1078,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> { fn text_content(&self) -> TextContent { if self.pseudo.is_replaced_content() { - let data = &self.borrow_layout_data().unwrap().style_data; - - let style = if self.pseudo.is_before() { - data.per_pseudo.get(&PseudoElement::Before).unwrap() - } else { - data.per_pseudo.get(&PseudoElement::After).unwrap() - }; + let style = self.resolved_style(); return match style.as_ref().get_counters().content { content::T::Content(ref value) if !value.is_empty() => { @@ -1078,7 +1104,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> { return TextContent::Text(data); } - panic!("not text!") + unreachable!("not text!") } fn selection(&self) -> Option> { @@ -1164,8 +1190,8 @@ impl Iterator for ThreadSafeLayoutNodeChildrenIterator(pub *const Stylist); - -// FIXME(#6569) This implementation is unsound. -#[allow(unsafe_code)] -unsafe impl Sync for StylistWrapper {} - pub struct SharedStyleContext { /// The current viewport size. pub viewport_size: Size2D, @@ -30,9 +24,7 @@ pub struct SharedStyleContext { pub screen_size_changed: bool, /// The CSS selector stylist. - /// - /// FIXME(#2604): Make this no longer an unsafe pointer once we have fast `RWArc`s. - pub stylist: StylistWrapper, + pub stylist: Arc>, /// Starts at zero, and increased by one every time a layout completes. /// This can be used to easily check for invalid stale data. @@ -60,10 +52,9 @@ pub struct LocalStyleContext { pub style_sharing_candidate_cache: RefCell>, } -pub trait StyleContext<'a, Impl: SelectorImplExt, C: ComputedValues> { - +pub trait StyleContext<'a, Impl: SelectorImplExt> { fn shared_context(&self) -> &'a SharedStyleContext; - fn local_context(&self) -> &LocalStyleContext; + fn local_context(&self) -> &LocalStyleContext; } /// Why we're doing reflow. @@ -74,4 +65,3 @@ pub enum ReflowGoal { /// We're reflowing in order to satisfy a script query. No display list will be created. ForScriptQuery, } - diff --git a/components/style/dom.rs b/components/style/dom.rs index d0ba545798c..fed1597c627 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -4,11 +4,12 @@ #![allow(unsafe_code)] +use context::SharedStyleContext; use data::PrivateStyleData; use element_state::ElementState; use properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint}; -use selector_impl::ElementExt; +use selector_impl::{ElementExt, SelectorImplExt}; use selectors::Element; use selectors::matching::DeclarationBlock; use smallvec::VecLike; @@ -137,19 +138,19 @@ pub trait TNode : Sized + Copy + Clone { #[inline(always)] unsafe fn borrow_data_unchecked(&self) -> Option<*const PrivateStyleData<::Impl, - Self::ConcreteComputedValues>>; + Self::ConcreteComputedValues>>; /// Borrows the PrivateStyleData immutably. Fails on a conflicting borrow. #[inline(always)] fn borrow_data(&self) -> Option::Impl, - Self::ConcreteComputedValues>>>; + Self::ConcreteComputedValues>>>; /// Borrows the PrivateStyleData mutably. Fails on a conflicting borrow. #[inline(always)] fn mutate_data(&self) -> Option::Impl, - Self::ConcreteComputedValues>>>; + Self::ConcreteComputedValues>>>; /// Get the description of how to account for recent style changes. fn restyle_damage(self) -> Self::ConcreteRestyleDamage; @@ -170,7 +171,10 @@ pub trait TNode : Sized + Copy + Clone { /// Returns the style results for the given node. If CSS selector matching /// has not yet been performed, fails. - fn style(&self) -> Ref> { + fn style(&self, + _context: &SharedStyleContext<::Impl>) + -> Ref> + where ::Impl: SelectorImplExt { Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap()) } diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs index b5dbdc37a3f..e116594b02f 100644 --- a/components/style/restyle_hints.rs +++ b/components/style/restyle_hints.rs @@ -136,7 +136,7 @@ impl<'a, E> Element for ElementWrapper<'a, E> fn get_local_name(&self) -> &Atom { self.element.get_local_name() } - fn get_namespace<'b>(&self) -> &Namespace { + fn get_namespace(&self) -> &Namespace { self.element.get_namespace() } fn get_id(&self) -> Option { diff --git a/components/style/selector_impl.rs b/components/style/selector_impl.rs index d70287f9ddf..b7faff4c028 100644 --- a/components/style/selector_impl.rs +++ b/components/style/selector_impl.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use element_state::ElementState; +use properties::{self, ServoComputedValues}; use selector_matching::{USER_OR_USER_AGENT_STYLESHEETS, QUIRKS_MODE_STYLESHEET}; use selectors::Element; use selectors::parser::{ParserContext, SelectorImpl}; @@ -12,9 +13,51 @@ pub trait ElementExt: Element { } pub trait SelectorImplExt : SelectorImpl + Sized { - fn each_eagerly_cascaded_pseudo_element(mut fun: F) + type ComputedValues: properties::ComputedValues; + + fn each_pseudo_element(mut fun: F) where F: FnMut(::PseudoElement); + /// This function determines if a pseudo-element is eagerly cascaded or not. + /// + /// Eagerly cascaded pseudo-elements are "normal" pseudo-elements (i.e. + /// `::before` and `::after`). They inherit styles normally as another + /// selector would do. + /// + /// Non-eagerly cascaded ones skip the cascade process entirely, mostly as + /// an optimisation since they are private pseudo-elements (like + /// `::-servo-details-content`). This pseudo-elements are resolved on the + /// fly using global rules (rules of the form `*|*`), and applying them to + /// the parent style. + /// + /// If you're implementing a public selector that the end-user might + /// customize, then you probably need doing the whole cascading process and + /// return true in this function for that pseudo. + /// + /// But if you are implementing a private pseudo-element, please consider if + /// it might be possible to skip the cascade for it. + fn is_eagerly_cascaded_pseudo_element(pseudo: &::PseudoElement) -> bool; + + #[inline] + fn each_eagerly_cascaded_pseudo_element(mut fun: F) + where F: FnMut(::PseudoElement) { + Self::each_pseudo_element(|pseudo| { + if Self::is_eagerly_cascaded_pseudo_element(&pseudo) { + fun(pseudo) + } + }) + } + + #[inline] + fn each_non_eagerly_cascaded_pseudo_element(mut fun: F) + where F: FnMut(::PseudoElement) { + Self::each_pseudo_element(|pseudo| { + if !Self::is_eagerly_cascaded_pseudo_element(&pseudo) { + fun(pseudo) + } + }) + } + fn pseudo_class_state_flag(pc: &Self::NonTSPseudoClass) -> ElementState; fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet]; @@ -31,6 +74,19 @@ pub enum PseudoElement { DetailsContent, } +impl PseudoElement { + #[inline] + pub fn is_eagerly_cascaded(&self) -> bool { + match *self { + PseudoElement::Before | + PseudoElement::After | + PseudoElement::Selection | + PseudoElement::DetailsSummary => true, + PseudoElement::DetailsContent => false, + } + } +} + #[derive(Clone, Debug, PartialEq, Eq, HeapSizeOf, Hash)] pub enum NonTSPseudoClass { AnyLink, @@ -112,15 +168,17 @@ impl SelectorImpl for ServoSelectorImpl { "before" => Before, "after" => After, "selection" => Selection, - "-servo-details-summary" => if context.in_user_agent_stylesheet { + "-servo-details-summary" => { + if !context.in_user_agent_stylesheet { + return Err(()) + } DetailsSummary - } else { - return Err(()) }, - "-servo-details-content" => if context.in_user_agent_stylesheet { + "-servo-details-content" => { + if !context.in_user_agent_stylesheet { + return Err(()) + } DetailsContent - } else { - return Err(()) }, _ => return Err(()) }; @@ -129,15 +187,16 @@ impl SelectorImpl for ServoSelectorImpl { } } -impl> ElementExt for E { - fn is_link(&self) -> bool { - self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink) - } -} - impl SelectorImplExt for ServoSelectorImpl { + type ComputedValues = ServoComputedValues; + #[inline] - fn each_eagerly_cascaded_pseudo_element(mut fun: F) + fn is_eagerly_cascaded_pseudo_element(pseudo: &PseudoElement) -> bool { + pseudo.is_eagerly_cascaded() + } + + #[inline] + fn each_pseudo_element(mut fun: F) where F: FnMut(PseudoElement) { fun(PseudoElement::Before); fun(PseudoElement::After); @@ -161,3 +220,9 @@ impl SelectorImplExt for ServoSelectorImpl { Some(&*QUIRKS_MODE_STYLESHEET) } } + +impl> ElementExt for E { + fn is_link(&self) -> bool { + self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink) + } +} diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 167d3277c42..72fdec38e43 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -8,8 +8,9 @@ use dom::TElement; use element_state::*; use error_reporting::{ParseErrorReporter, StdoutErrorReporter}; +use euclid::Size2D; use media_queries::{Device, MediaType}; -use properties::{PropertyDeclaration, PropertyDeclarationBlock}; +use properties::{self, ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; use restyle_hints::{ElementSnapshot, RestyleHint, DependencySet}; use selector_impl::{SelectorImplExt, ServoSelectorImpl}; use selectors::Element; @@ -116,11 +117,20 @@ pub struct Stylist { /// The current selector maps, after evaluating media /// rules against the current device. element_map: PerPseudoElementSelectorMap, + /// The selector maps corresponding to a given pseudo-element /// (depending on the implementation) pseudos_map: HashMap, BuildHasherDefault<::fnv::FnvHasher>>, + + /// Applicable declarations for a given non-eagerly cascaded pseudo-element. + /// These are eagerly computed once, and then used to resolve the new + /// computed values on the fly on layout. + non_eagerly_cascaded_pseudo_element_decls: HashMap, + BuildHasherDefault<::fnv::FnvHasher>>, + rules_source_order: usize, /// Selector dependencies used to compute restyle hints. @@ -138,6 +148,7 @@ impl Stylist { element_map: PerPseudoElementSelectorMap::new(), pseudos_map: HashMap::with_hasher(Default::default()), + non_eagerly_cascaded_pseudo_element_decls: HashMap::with_hasher(Default::default()), rules_source_order: 0, state_deps: DependencySet::new(), }; @@ -160,6 +171,11 @@ impl Stylist { self.element_map = PerPseudoElementSelectorMap::new(); self.pseudos_map = HashMap::with_hasher(Default::default()); + Impl::each_eagerly_cascaded_pseudo_element(|pseudo| { + self.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new()); + }); + + self.non_eagerly_cascaded_pseudo_element_decls = HashMap::with_hasher(Default::default()); self.rules_source_order = 0; self.state_deps.clear(); @@ -182,8 +198,7 @@ impl Stylist { } fn add_stylesheet(&mut self, stylesheet: &Stylesheet) { - let device = &self.device; - if !stylesheet.is_effective_for_device(device) { + if !stylesheet.is_effective_for_device(&self.device) { return; } let mut rules_source_order = self.rules_source_order; @@ -195,20 +210,21 @@ impl Stylist { if !$style_rule.declarations.$priority.is_empty() { for selector in &$style_rule.selectors { let map = if let Some(ref pseudo) = selector.pseudo_element { - self.pseudos_map.entry(pseudo.clone()) - .or_insert_with(PerPseudoElementSelectorMap::new) - .borrow_for_origin(&stylesheet.origin) + self.pseudos_map + .entry(pseudo.clone()) + .or_insert_with(PerPseudoElementSelectorMap::new) + .borrow_for_origin(&stylesheet.origin) } else { self.element_map.borrow_for_origin(&stylesheet.origin) }; map.$priority.insert(Rule { - selector: selector.compound_selectors.clone(), - declarations: DeclarationBlock { - specificity: selector.specificity, - declarations: $style_rule.declarations.$priority.clone(), - source_order: rules_source_order, - }, + selector: selector.compound_selectors.clone(), + declarations: DeclarationBlock { + specificity: selector.specificity, + declarations: $style_rule.declarations.$priority.clone(), + source_order: rules_source_order, + }, }); } } @@ -223,7 +239,40 @@ impl Stylist { self.state_deps.note_selector(selector.compound_selectors.clone()); } } + self.rules_source_order = rules_source_order; + + Impl::each_non_eagerly_cascaded_pseudo_element(|pseudo| { + // TODO: Don't precompute this, compute it on demand instead and + // cache it. + // + // This is actually kind of hard, because the stylist is shared + // between threads. + if let Some(map) = self.pseudos_map.remove(&pseudo) { + let mut declarations = vec![]; + + map.user_agent.normal.get_universal_rules(&mut declarations); + map.user_agent.important.get_universal_rules(&mut declarations); + + self.non_eagerly_cascaded_pseudo_element_decls.insert(pseudo, declarations); + } + }) + } + + pub fn computed_values_for_pseudo(&self, + pseudo: &Impl::PseudoElement, + parent: Option<&Arc>) -> Option> { + debug_assert!(!Impl::is_eagerly_cascaded_pseudo_element(pseudo)); + if let Some(declarations) = self.non_eagerly_cascaded_pseudo_element_decls.get(pseudo) { + let (computed, _) = + properties::cascade::(Size2D::zero(), + &declarations, false, + parent.map(|p| &**p), None, + box StdoutErrorReporter); + Some(Arc::new(computed)) + } else { + parent.map(|p| p.clone()) + } } pub fn compute_restyle_hint(&self, element: &E, @@ -284,20 +333,16 @@ impl Stylist { assert!(!self.is_device_dirty); assert!(style_attribute.is_none() || pseudo_element.is_none(), "Style attributes do not apply to pseudo-elements"); + debug_assert!(pseudo_element.is_none() || + Impl::is_eagerly_cascaded_pseudo_element(pseudo_element.as_ref().unwrap())); let map = match pseudo_element { - Some(ref pseudo) => match self.pseudos_map.get(pseudo) { - Some(map) => map, - // TODO(emilio): get non eagerly-cascaded pseudo-element rules here. - // Actually assume there are no rules applicable. - None => return true, - }, + Some(ref pseudo) => self.pseudos_map.get(pseudo).unwrap(), None => &self.element_map, }; let mut shareable = true; - // Step 1: Normal user-agent rules. map.user_agent.normal.get_all_matching_rules(element, parent_bf, diff --git a/components/style/servo.rs b/components/style/servo.rs index ec7044ad4a5..f5ce9d608b0 100644 --- a/components/style/servo.rs +++ b/components/style/servo.rs @@ -12,5 +12,4 @@ use stylesheets; pub type Stylesheet = stylesheets::Stylesheet; pub type PrivateStyleData = data::PrivateStyleData; pub type Stylist = selector_matching::Stylist; -pub type StylistWrapper = context::StylistWrapper; pub type SharedStyleContext = context::SharedStyleContext; diff --git a/components/style/traversal.rs b/components/style/traversal.rs index f39347e83ab..c7ba825acbd 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -123,8 +123,8 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C, root: OpaqueNode, node: N) where N: TNode, - C: StyleContext<'a, ::Impl, N::ConcreteComputedValues>, - ::Impl: SelectorImplExt + 'a { + C: StyleContext<'a, ::Impl>, + ::Impl: SelectorImplExt + 'a { // Initialize layout data. // // FIXME(pcwalton): Stop allocating here. Ideally this should just be done by the HTML @@ -167,8 +167,9 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C, let shareable_element = match node.as_element() { Some(element) => { // Perform the CSS selector matching. - let stylist = unsafe { &*context.shared_context().stylist.0 }; - if element.match_element(stylist, + let stylist = &context.shared_context().stylist; + + if element.match_element(&**stylist, Some(&*bf), &mut applicable_declarations) { Some(element) diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index dd47a33ba88..8832485efbf 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -143,6 +143,11 @@ name = "bitflags" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bitflags" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "block" version = "0.1.5" @@ -656,7 +661,7 @@ dependencies = [ "servo-skia 0.20130412.6 (registry+https://github.com/rust-lang/crates.io-index)", "simd 0.1.0 (git+https://github.com/huonw/simd)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "style_traits 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", @@ -821,7 +826,7 @@ dependencies = [ "phf 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "tendril 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1012,11 +1017,11 @@ dependencies = [ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "style_traits 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1695,10 +1700,10 @@ dependencies = [ "regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "script_traits 0.0.1", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1738,10 +1743,10 @@ dependencies = [ [[package]] name = "selectors" -version = "0.5.2" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1749,7 +1754,7 @@ dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1947,7 +1952,7 @@ dependencies = [ [[package]] name = "string_cache" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "debug_unreachable 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1977,11 +1982,11 @@ dependencies = [ "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style_traits 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2000,7 +2005,7 @@ dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2183,7 +2188,7 @@ dependencies = [ "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2399,7 +2404,7 @@ dependencies = [ "phf 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "tendril 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock index aca096bd784..3b716c53ae3 100644 --- a/ports/geckolib/Cargo.lock +++ b/ports/geckolib/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "util 0.0.1", @@ -81,6 +81,11 @@ name = "bitflags" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bitflags" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "0.5.1" @@ -422,10 +427,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "selectors" -version = "0.5.2" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -433,7 +438,7 @@ dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -466,7 +471,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "string_cache" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "debug_unreachable 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -496,11 +501,11 @@ dependencies = [ "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style_traits 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -519,7 +524,7 @@ dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -600,7 +605,7 @@ dependencies = [ "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs index a3640f775bd..16724678a80 100644 --- a/ports/geckolib/bindings.rs +++ b/ports/geckolib/bindings.rs @@ -1,5 +1,6 @@ /* automatically generated by rust-bindgen */ +use gecko_style_structs::SheetParsingMode; use gecko_style_structs::nsStyleFont; use gecko_style_structs::nsStyleColor; use gecko_style_structs::nsStyleList; @@ -68,7 +69,8 @@ extern "C" { pub fn Gecko_SetNodeData(node: *mut RawGeckoNode, data: *mut ServoNodeData); pub fn Servo_DropNodeData(data: *mut ServoNodeData); - pub fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, length: u32) + pub fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, length: u32, + parsing_mode: SheetParsingMode) -> *mut RawServoStyleSheet; pub fn Servo_AddRefStyleSheet(sheet: *mut RawServoStyleSheet); pub fn Servo_ReleaseStyleSheet(sheet: *mut RawServoStyleSheet); @@ -96,6 +98,8 @@ extern "C" { pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, ns: *const u8, name: *const u8, length: *mut u32) -> *const ::std::os::raw::c_char; + pub fn Gecko_GetAtomAsUTF16(atom: *mut nsIAtom, length: *mut u32) + -> *const u16; pub fn Gecko_LocalName(element: *mut RawGeckoElement, length: *mut u32) -> *const u16; pub fn Gecko_Namespace(element: *mut RawGeckoElement, length: *mut u32) @@ -106,23 +110,33 @@ extern "C" { pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont, other: *const nsStyleFont); pub fn Gecko_Destroy_nsStyleFont(ptr: *mut nsStyleFont); + pub fn Servo_GetStyleFont(computedValues: *mut ServoComputedValues) + -> *const nsStyleFont; pub fn Gecko_Construct_nsStyleColor(ptr: *mut nsStyleColor); pub fn Gecko_CopyConstruct_nsStyleColor(ptr: *mut nsStyleColor, other: *const nsStyleColor); pub fn Gecko_Destroy_nsStyleColor(ptr: *mut nsStyleColor); + pub fn Servo_GetStyleColor(computedValues: *mut ServoComputedValues) + -> *const nsStyleColor; pub fn Gecko_Construct_nsStyleList(ptr: *mut nsStyleList); pub fn Gecko_CopyConstruct_nsStyleList(ptr: *mut nsStyleList, other: *const nsStyleList); pub fn Gecko_Destroy_nsStyleList(ptr: *mut nsStyleList); + pub fn Servo_GetStyleList(computedValues: *mut ServoComputedValues) + -> *const nsStyleList; pub fn Gecko_Construct_nsStyleText(ptr: *mut nsStyleText); pub fn Gecko_CopyConstruct_nsStyleText(ptr: *mut nsStyleText, other: *const nsStyleText); pub fn Gecko_Destroy_nsStyleText(ptr: *mut nsStyleText); + pub fn Servo_GetStyleText(computedValues: *mut ServoComputedValues) + -> *const nsStyleText; pub fn Gecko_Construct_nsStyleVisibility(ptr: *mut nsStyleVisibility); pub fn Gecko_CopyConstruct_nsStyleVisibility(ptr: *mut nsStyleVisibility, other: *const nsStyleVisibility); pub fn Gecko_Destroy_nsStyleVisibility(ptr: *mut nsStyleVisibility); + pub fn Servo_GetStyleVisibility(computedValues: *mut ServoComputedValues) + -> *const nsStyleVisibility; pub fn Gecko_Construct_nsStyleUserInterface(ptr: *mut nsStyleUserInterface); pub fn Gecko_CopyConstruct_nsStyleUserInterface(ptr: @@ -130,81 +144,120 @@ extern "C" { other: *const nsStyleUserInterface); pub fn Gecko_Destroy_nsStyleUserInterface(ptr: *mut nsStyleUserInterface); + pub fn Servo_GetStyleUserInterface(computedValues: + *mut ServoComputedValues) + -> *const nsStyleUserInterface; pub fn Gecko_Construct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); pub fn Gecko_CopyConstruct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder, other: *const nsStyleTableBorder); pub fn Gecko_Destroy_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); + pub fn Servo_GetStyleTableBorder(computedValues: *mut ServoComputedValues) + -> *const nsStyleTableBorder; pub fn Gecko_Construct_nsStyleSVG(ptr: *mut nsStyleSVG); pub fn Gecko_CopyConstruct_nsStyleSVG(ptr: *mut nsStyleSVG, other: *const nsStyleSVG); pub fn Gecko_Destroy_nsStyleSVG(ptr: *mut nsStyleSVG); + pub fn Servo_GetStyleSVG(computedValues: *mut ServoComputedValues) + -> *const nsStyleSVG; pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables); pub fn Gecko_CopyConstruct_nsStyleVariables(ptr: *mut nsStyleVariables, other: *const nsStyleVariables); pub fn Gecko_Destroy_nsStyleVariables(ptr: *mut nsStyleVariables); + pub fn Servo_GetStyleVariables(computedValues: *mut ServoComputedValues) + -> *const nsStyleVariables; pub fn Gecko_Construct_nsStyleBackground(ptr: *mut nsStyleBackground); pub fn Gecko_CopyConstruct_nsStyleBackground(ptr: *mut nsStyleBackground, other: *const nsStyleBackground); pub fn Gecko_Destroy_nsStyleBackground(ptr: *mut nsStyleBackground); + pub fn Servo_GetStyleBackground(computedValues: *mut ServoComputedValues) + -> *const nsStyleBackground; pub fn Gecko_Construct_nsStylePosition(ptr: *mut nsStylePosition); pub fn Gecko_CopyConstruct_nsStylePosition(ptr: *mut nsStylePosition, other: *const nsStylePosition); pub fn Gecko_Destroy_nsStylePosition(ptr: *mut nsStylePosition); + pub fn Servo_GetStylePosition(computedValues: *mut ServoComputedValues) + -> *const nsStylePosition; pub fn Gecko_Construct_nsStyleTextReset(ptr: *mut nsStyleTextReset); pub fn Gecko_CopyConstruct_nsStyleTextReset(ptr: *mut nsStyleTextReset, other: *const nsStyleTextReset); pub fn Gecko_Destroy_nsStyleTextReset(ptr: *mut nsStyleTextReset); + pub fn Servo_GetStyleTextReset(computedValues: *mut ServoComputedValues) + -> *const nsStyleTextReset; pub fn Gecko_Construct_nsStyleDisplay(ptr: *mut nsStyleDisplay); pub fn Gecko_CopyConstruct_nsStyleDisplay(ptr: *mut nsStyleDisplay, other: *const nsStyleDisplay); pub fn Gecko_Destroy_nsStyleDisplay(ptr: *mut nsStyleDisplay); + pub fn Servo_GetStyleDisplay(computedValues: *mut ServoComputedValues) + -> *const nsStyleDisplay; pub fn Gecko_Construct_nsStyleContent(ptr: *mut nsStyleContent); pub fn Gecko_CopyConstruct_nsStyleContent(ptr: *mut nsStyleContent, other: *const nsStyleContent); pub fn Gecko_Destroy_nsStyleContent(ptr: *mut nsStyleContent); + pub fn Servo_GetStyleContent(computedValues: *mut ServoComputedValues) + -> *const nsStyleContent; pub fn Gecko_Construct_nsStyleUIReset(ptr: *mut nsStyleUIReset); pub fn Gecko_CopyConstruct_nsStyleUIReset(ptr: *mut nsStyleUIReset, other: *const nsStyleUIReset); pub fn Gecko_Destroy_nsStyleUIReset(ptr: *mut nsStyleUIReset); + pub fn Servo_GetStyleUIReset(computedValues: *mut ServoComputedValues) + -> *const nsStyleUIReset; pub fn Gecko_Construct_nsStyleTable(ptr: *mut nsStyleTable); pub fn Gecko_CopyConstruct_nsStyleTable(ptr: *mut nsStyleTable, other: *const nsStyleTable); pub fn Gecko_Destroy_nsStyleTable(ptr: *mut nsStyleTable); + pub fn Servo_GetStyleTable(computedValues: *mut ServoComputedValues) + -> *const nsStyleTable; pub fn Gecko_Construct_nsStyleMargin(ptr: *mut nsStyleMargin); pub fn Gecko_CopyConstruct_nsStyleMargin(ptr: *mut nsStyleMargin, other: *const nsStyleMargin); pub fn Gecko_Destroy_nsStyleMargin(ptr: *mut nsStyleMargin); + pub fn Servo_GetStyleMargin(computedValues: *mut ServoComputedValues) + -> *const nsStyleMargin; pub fn Gecko_Construct_nsStylePadding(ptr: *mut nsStylePadding); pub fn Gecko_CopyConstruct_nsStylePadding(ptr: *mut nsStylePadding, other: *const nsStylePadding); pub fn Gecko_Destroy_nsStylePadding(ptr: *mut nsStylePadding); + pub fn Servo_GetStylePadding(computedValues: *mut ServoComputedValues) + -> *const nsStylePadding; pub fn Gecko_Construct_nsStyleBorder(ptr: *mut nsStyleBorder); pub fn Gecko_CopyConstruct_nsStyleBorder(ptr: *mut nsStyleBorder, other: *const nsStyleBorder); pub fn Gecko_Destroy_nsStyleBorder(ptr: *mut nsStyleBorder); + pub fn Servo_GetStyleBorder(computedValues: *mut ServoComputedValues) + -> *const nsStyleBorder; pub fn Gecko_Construct_nsStyleOutline(ptr: *mut nsStyleOutline); pub fn Gecko_CopyConstruct_nsStyleOutline(ptr: *mut nsStyleOutline, other: *const nsStyleOutline); pub fn Gecko_Destroy_nsStyleOutline(ptr: *mut nsStyleOutline); + pub fn Servo_GetStyleOutline(computedValues: *mut ServoComputedValues) + -> *const nsStyleOutline; pub fn Gecko_Construct_nsStyleXUL(ptr: *mut nsStyleXUL); pub fn Gecko_CopyConstruct_nsStyleXUL(ptr: *mut nsStyleXUL, other: *const nsStyleXUL); pub fn Gecko_Destroy_nsStyleXUL(ptr: *mut nsStyleXUL); + pub fn Servo_GetStyleXUL(computedValues: *mut ServoComputedValues) + -> *const nsStyleXUL; pub fn Gecko_Construct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); pub fn Gecko_CopyConstruct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset, other: *const nsStyleSVGReset); pub fn Gecko_Destroy_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); + pub fn Servo_GetStyleSVGReset(computedValues: *mut ServoComputedValues) + -> *const nsStyleSVGReset; pub fn Gecko_Construct_nsStyleColumn(ptr: *mut nsStyleColumn); pub fn Gecko_CopyConstruct_nsStyleColumn(ptr: *mut nsStyleColumn, other: *const nsStyleColumn); pub fn Gecko_Destroy_nsStyleColumn(ptr: *mut nsStyleColumn); + pub fn Servo_GetStyleColumn(computedValues: *mut ServoComputedValues) + -> *const nsStyleColumn; pub fn Gecko_Construct_nsStyleEffects(ptr: *mut nsStyleEffects); pub fn Gecko_CopyConstruct_nsStyleEffects(ptr: *mut nsStyleEffects, other: *const nsStyleEffects); pub fn Gecko_Destroy_nsStyleEffects(ptr: *mut nsStyleEffects); + pub fn Servo_GetStyleEffects(computedValues: *mut ServoComputedValues) + -> *const nsStyleEffects; } diff --git a/ports/geckolib/data.rs b/ports/geckolib/data.rs index bc1c398e6c0..733d5e4f83f 100644 --- a/ports/geckolib/data.rs +++ b/ports/geckolib/data.rs @@ -22,7 +22,7 @@ use util::workqueue::WorkQueue; pub struct PerDocumentStyleData { /// Rule processor. - pub stylist: Stylist, + pub stylist: Arc, /// List of stylesheets, mirrored from Gecko. pub stylesheets: Vec>, @@ -50,8 +50,8 @@ impl PerDocumentStyleData { let num_threads = cmp::max(num_cpus::get() * 3 / 4, 1); PerDocumentStyleData { - stylist: Stylist::new(device), - stylesheets: Vec::new(), + stylist: Arc::new(Stylist::new(device)), + stylesheets: vec![], stylesheets_changed: true, new_animations_sender: new_anims_sender, new_animations_receiver: new_anims_receiver, diff --git a/ports/geckolib/gecko_style_structs.rs b/ports/geckolib/gecko_style_structs.rs index 114fe03b2b6..f5807afd5e9 100644 --- a/ports/geckolib/gecko_style_structs.rs +++ b/ports/geckolib/gecko_style_structs.rs @@ -3986,6 +3986,34 @@ fn bindgen_test_layout_CounterStyleManager() { assert_eq!(::std::mem::size_of::() , 72usize); assert_eq!(::std::mem::align_of::() , 8usize); } +/** + * Enum defining the mode in which a sheet is to be parsed. This is + * usually, but not always, the same as the cascade level at which the + * sheet will apply (see nsStyleSet.h). Most of the Loader APIs only + * support loading of author sheets. + * + * Author sheets are the normal case: styles embedded in or linked + * from HTML pages. They are also the most restricted. + * + * User sheets can do anything author sheets can do, and also get + * access to a few CSS extensions that are not yet suitable for + * exposure on the public Web, but are very useful for expressing + * user style overrides, such as @-moz-document rules. + * + * Agent sheets have access to all author- and user-sheet features + * plus more extensions that are necessary for internal use but, + * again, not yet suitable for exposure on the public Web. Some of + * these are outright unsafe to expose; in particular, incorrect + * styling of anonymous box pseudo-elements can violate layout + * invariants. + */ +#[repr(u32)] +#[derive(Debug, Copy, Clone)] +pub enum SheetParsingMode { + eAuthorSheetFeatures = 0, + eUserSheetFeatures = 1, + eAgentSheetFeatures = 2, +} pub type nsLoadFlags = u32; #[repr(C)] #[derive(Debug, Copy)] diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d4bfc62b9d6..27edf4ed357 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -10,16 +10,17 @@ use bindings::{RawServoStyleSet, RawServoStyleSheet, ServoComputedValues, ServoN use bindings::{nsIAtom}; use data::PerDocumentStyleData; use euclid::Size2D; +use gecko_style_structs::SheetParsingMode; use properties::GeckoComputedValues; -use selector_impl::{SharedStyleContext, Stylesheet}; +use selector_impl::{GeckoSelectorImpl, PseudoElement, SharedStyleContext, Stylesheet}; use std::marker::PhantomData; use std::mem::{forget, transmute}; use std::ptr; use std::slice; use std::str::from_utf8_unchecked; use std::sync::{Arc, Mutex}; -use style::context::{ReflowGoal, StylistWrapper}; -use style::dom::{TDocument, TElement, TNode}; +use style::context::{ReflowGoal}; +use style::dom::{TDocument, TNode}; use style::error_reporting::StdoutErrorReporter; use style::parallel; use style::properties::ComputedValues; @@ -27,7 +28,30 @@ use style::stylesheets::Origin; use traversal::RecalcStyleOnly; use url::Url; use util::arc_ptr_eq; -use wrapper::{GeckoDocument, GeckoElement, GeckoNode, NonOpaqueStyleData}; +use wrapper::{GeckoDocument, GeckoNode, NonOpaqueStyleData}; + +// TODO: This is ugly and should go away once we get an atom back-end. +pub fn pseudo_element_from_atom(pseudo: *mut nsIAtom, + in_ua_stylesheet: bool) -> Result { + use bindings::Gecko_GetAtomAsUTF16; + use selectors::parser::{ParserContext, SelectorImpl}; + + let pseudo_string = unsafe { + let mut length = 0; + let mut buff = Gecko_GetAtomAsUTF16(pseudo, &mut length); + + // Handle the annoying preceding colon in front of everything in nsCSSAnonBoxList.h. + debug_assert!(length >= 2 && *buff == ':' as u16 && *buff.offset(1) != ':' as u16); + buff = buff.offset(1); + length -= 1; + + String::from_utf16(slice::from_raw_parts(buff, length as usize)).unwrap() + }; + + let mut context = ParserContext::new(); + context.in_user_agent_stylesheet = in_ua_stylesheet; + GeckoSelectorImpl::parse_pseudo_element(&context, &pseudo_string).map_err(|_| pseudo_string) +} /* * For Gecko->Servo function calls, we need to redeclare the same signature that was declared in @@ -51,7 +75,8 @@ pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *m // into a runtime-wide init hook at some point. GeckoComputedValues::initial_values(); - let _needs_dirtying = data.stylist.update(&data.stylesheets, data.stylesheets_changed); + let _needs_dirtying = Arc::get_mut(&mut data.stylist).unwrap() + .update(&data.stylesheets, data.stylesheets_changed); data.stylesheets_changed = false; let shared_style_context = SharedStyleContext { @@ -59,7 +84,7 @@ pub extern "C" fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, raw_data: *m screen_size_changed: false, generation: 0, goal: ReflowGoal::ForScriptQuery, - stylist: StylistWrapper(&data.stylist), + stylist: data.stylist.clone(), new_animations_sender: Mutex::new(data.new_animations_sender.clone()), running_animations: data.running_animations.clone(), expired_animations: data.expired_animations.clone(), @@ -80,13 +105,20 @@ pub extern "C" fn Servo_DropNodeData(data: *mut ServoNodeData) -> () { #[no_mangle] pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, - length: u32) -> *mut RawServoStyleSheet { + length: u32, + mode: SheetParsingMode) -> *mut RawServoStyleSheet { let input = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) }; - // FIXME(heycam): Pass in the real base URL and sheet origin to use. + let origin = match mode { + SheetParsingMode::eAuthorSheetFeatures => Origin::Author, + SheetParsingMode::eUserSheetFeatures => Origin::User, + SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent, + }; + + // FIXME(heycam): Pass in the real base URL. let url = Url::parse("about:none").unwrap(); - let sheet = Arc::new(Stylesheet::from_str(input, url, Origin::Author, Box::new(StdoutErrorReporter))); + let sheet = Arc::new(Stylesheet::from_str(input, url, origin, Box::new(StdoutErrorReporter))); unsafe { transmute(sheet) } @@ -97,19 +129,40 @@ pub struct ArcHelpers { phantom2: PhantomData, } + impl ArcHelpers { pub fn with(raw: *mut GeckoType, cb: F) -> Output where F: FnOnce(&Arc) -> Output { + debug_assert!(!raw.is_null()); + let owned = unsafe { Self::into(raw) }; let result = cb(&owned); forget(owned); result } + pub fn maybe_with(maybe_raw: *mut GeckoType, cb: F) -> Output + where F: FnOnce(Option<&Arc>) -> Output { + let owned = if maybe_raw.is_null() { + None + } else { + Some(unsafe { Self::into(maybe_raw) }) + }; + + let result = cb(owned.as_ref()); + forget(owned); + + result + } + pub unsafe fn into(ptr: *mut GeckoType) -> Arc { transmute(ptr) } + pub fn from(owned: Arc) -> *mut GeckoType { + unsafe { transmute(owned) } + } + pub unsafe fn addref(ptr: *mut GeckoType) { Self::with(ptr, |arc| forget(arc.clone())); } @@ -197,12 +250,26 @@ pub extern "C" fn Servo_GetComputedValues(node: *mut RawGeckoNode) } #[no_mangle] -pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(_parentStyleOrNull: *mut ServoComputedValues, - _pseudoTag: *mut nsIAtom, +pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: *mut ServoComputedValues, + pseudo_tag: *mut nsIAtom, raw_data: *mut RawServoStyleSet) -> *mut ServoComputedValues { - let _data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); - unimplemented!(); + let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); + + let pseudo = match pseudo_element_from_atom(pseudo_tag, true) { + Ok(pseudo) => pseudo, + Err(pseudo) => { + warn!("stylo: Unable to parse anonymous-box pseudo-element: {}", pseudo); + return ptr::null_mut(); + } + }; + + type Helpers = ArcHelpers; + + Helpers::maybe_with(parent_style_or_null, |maybe_parent| { + let new_computed = data.stylist.computed_values_for_pseudo(&pseudo, maybe_parent); + new_computed.map_or(ptr::null_mut(), |c| Helpers::from(c)) + }) } #[no_mangle] diff --git a/ports/geckolib/selector_impl.rs b/ports/geckolib/selector_impl.rs index d892b68ca31..03803563443 100644 --- a/ports/geckolib/selector_impl.rs +++ b/ports/geckolib/selector_impl.rs @@ -151,14 +151,24 @@ impl SelectorImpl for GeckoSelectorImpl { Ok(pseudo_class) } - fn parse_pseudo_element(_context: &ParserContext, + fn parse_pseudo_element(context: &ParserContext, name: &str) -> Result { use self::PseudoElement::*; - let pseudo_element = match_ignore_ascii_case! { name, - "before" => Before, - "after" => After, - "first-line" => FirstLine, + // The braces here are unfortunate, but they're needed for + // match_ignore_ascii_case! to work as expected. + match_ignore_ascii_case! { name, + "before" => { return Ok(Before) }, + "after" => { return Ok(After) }, + "first-line" => { return Ok(FirstLine) }, + _ => {} + } + + if !context.in_user_agent_stylesheet { + return Err(()) + } + + Ok(match_ignore_ascii_case! { name, "-moz-non-element" => MozNonElement, "-moz-anonymous-block" => MozAnonymousBlock, @@ -225,19 +235,94 @@ impl SelectorImpl for GeckoSelectorImpl { "-moz-svg-text" => MozSVGText, _ => return Err(()) - }; - - Ok(pseudo_element) + }) } } impl SelectorImplExt for GeckoSelectorImpl { + type ComputedValues = GeckoComputedValues; + #[inline] - fn each_eagerly_cascaded_pseudo_element(mut fun: F) + fn is_eagerly_cascaded_pseudo_element(pseudo: &PseudoElement) -> bool { + match *pseudo { + PseudoElement::Before | + PseudoElement::After | + PseudoElement::FirstLine => true, + _ => false, + } + } + + #[inline] + fn each_pseudo_element(mut fun: F) where F: FnMut(PseudoElement) { fun(PseudoElement::Before); fun(PseudoElement::After); - // TODO: probably a lot more are missing here + fun(PseudoElement::FirstLine); + + fun(PseudoElement::MozNonElement); + fun(PseudoElement::MozAnonymousBlock); + fun(PseudoElement::MozAnonymousPositionedBlock); + fun(PseudoElement::MozMathMLAnonymousBlock); + fun(PseudoElement::MozXULAnonymousBlock); + + fun(PseudoElement::MozHorizontalFramesetBorder); + fun(PseudoElement::MozVerticalFramesetBorder); + fun(PseudoElement::MozLineFrame); + fun(PseudoElement::MozButtonContent); + fun(PseudoElement::MozButtonLabel); + fun(PseudoElement::MozCellContent); + fun(PseudoElement::MozDropdownList); + fun(PseudoElement::MozFieldsetContent); + fun(PseudoElement::MozFramesetBlank); + fun(PseudoElement::MozDisplayComboboxControlFrame); + + fun(PseudoElement::MozHTMLCanvasContent); + fun(PseudoElement::MozInlineTable); + fun(PseudoElement::MozTable); + fun(PseudoElement::MozTableCell); + fun(PseudoElement::MozTableColumnGroup); + fun(PseudoElement::MozTableColumn); + fun(PseudoElement::MozTableOuter); + fun(PseudoElement::MozTableRowGroup); + fun(PseudoElement::MozTableRow); + + fun(PseudoElement::MozCanvas); + fun(PseudoElement::MozPageBreak); + fun(PseudoElement::MozPage); + fun(PseudoElement::MozPageContent); + fun(PseudoElement::MozPageSequence); + fun(PseudoElement::MozScrolledContent); + fun(PseudoElement::MozScrolledCanvas); + fun(PseudoElement::MozScrolledPageSequence); + fun(PseudoElement::MozColumnContent); + fun(PseudoElement::MozViewport); + fun(PseudoElement::MozViewportScroll); + fun(PseudoElement::MozAnonymousFlexItem); + fun(PseudoElement::MozAnonymousGridItem); + + fun(PseudoElement::MozRuby); + fun(PseudoElement::MozRubyBase); + fun(PseudoElement::MozRubyBaseContainer); + fun(PseudoElement::MozRubyText); + fun(PseudoElement::MozRubyTextContainer); + + fun(PseudoElement::MozTreeColumn); + fun(PseudoElement::MozTreeRow); + fun(PseudoElement::MozTreeSeparator); + fun(PseudoElement::MozTreeCell); + fun(PseudoElement::MozTreeIndentation); + fun(PseudoElement::MozTreeLine); + fun(PseudoElement::MozTreeTwisty); + fun(PseudoElement::MozTreeImage); + fun(PseudoElement::MozTreeCellText); + fun(PseudoElement::MozTreeCheckbox); + fun(PseudoElement::MozTreeProgressMeter); + fun(PseudoElement::MozTreeDropFeedback); + + fun(PseudoElement::MozSVGMarkerAnonChild); + fun(PseudoElement::MozSVGOuterSVGAnonChild); + fun(PseudoElement::MozSVGForeignContent); + fun(PseudoElement::MozSVGText); } #[inline] diff --git a/ports/geckolib/tools/regen_bindings.sh b/ports/geckolib/tools/regen_bindings.sh index 5529dd95234..cff58117d91 100755 --- a/ports/geckolib/tools/regen_bindings.sh +++ b/ports/geckolib/tools/regen_bindings.sh @@ -28,17 +28,17 @@ else LIBCLANG_PATH=`brew --prefix llvm38`/lib/llvm-3.8/lib; fi -# Prevent bindgen from generating opaque types for the gecko style structs. -export MAP_GECKO_STRUCTS="" -for STRUCT in nsStyleFont nsStyleColor nsStyleList nsStyleText \ +# Prevent bindgen from generating opaque types for common gecko types +export MAP_GECKO_TYPES="" +for STRUCT in SheetParsingMode nsStyleFont nsStyleColor nsStyleList nsStyleText \ nsStyleVisibility nsStyleUserInterface nsStyleTableBorder \ nsStyleSVG nsStyleVariables nsStyleBackground nsStylePosition \ nsStyleTextReset nsStyleDisplay nsStyleContent nsStyleUIReset \ nsStyleTable nsStyleMargin nsStylePadding nsStyleBorder \ nsStyleOutline nsStyleXUL nsStyleSVGReset nsStyleColumn nsStyleEffects do - MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-blacklist-type $STRUCT " - MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-raw-line 'use gecko_style_structs::$STRUCT;' " + MAP_GECKO_TYPES=$MAP_GECKO_TYPES"-blacklist-type $STRUCT " + MAP_GECKO_TYPES=$MAP_GECKO_TYPES"-raw-line 'use gecko_style_structs::$STRUCT;' " done # Check for the include directory. @@ -50,7 +50,7 @@ fi export RUST_BACKTRACE=1 -# We need to use 'eval' here to make MAP_GECKO_STRUCTS evaluate properly as +# We need to use 'eval' here to make MAP_GECKO_TYPES evaluate properly as # multiple arguments. eval ./rust-bindgen/target/debug/bindgen \ -x c++ -std=gnu++0x \ @@ -61,4 +61,4 @@ eval ./rust-bindgen/target/debug/bindgen \ "$DIST_INCLUDE/mozilla/ServoBindings.h" \ -match "ServoBindings.h" \ -match "nsStyleStructList.h" \ - $MAP_GECKO_STRUCTS + $MAP_GECKO_TYPES diff --git a/ports/geckolib/tools/regen_style_structs.sh b/ports/geckolib/tools/regen_style_structs.sh index dc4690fc188..95833f88a16 100755 --- a/ports/geckolib/tools/regen_style_structs.sh +++ b/ports/geckolib/tools/regen_style_structs.sh @@ -95,6 +95,7 @@ export RUST_BACKTRACE=1 -match "nsDataHashtable.h" \ -match "nsCSSScanner.h" \ -match "Types.h" \ + -match "SheetParsingMode.h" \ -blacklist-type "IsDestructibleFallbackImpl" \ -blacklist-type "IsDestructibleFallback" \ -opaque-type "nsIntMargin" \ diff --git a/ports/geckolib/traversal.rs b/ports/geckolib/traversal.rs index 33fc1fd322e..4e10d8c8fc8 100644 --- a/ports/geckolib/traversal.rs +++ b/ports/geckolib/traversal.rs @@ -52,7 +52,7 @@ impl<'a> StandaloneStyleContext<'a> { } } -impl<'a> StyleContext<'a, GeckoSelectorImpl, GeckoComputedValues> for StandaloneStyleContext<'a> { +impl<'a> StyleContext<'a, GeckoSelectorImpl> for StandaloneStyleContext<'a> { fn shared_context(&self) -> &'a SharedStyleContext { &self.shared } diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 450791ad071..68cb39fd0f4 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -136,6 +136,11 @@ name = "bitflags" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bitflags" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "block" version = "0.1.5" @@ -659,7 +664,7 @@ dependencies = [ "servo-skia 0.20130412.6 (registry+https://github.com/rust-lang/crates.io-index)", "simd 0.1.0 (git+https://github.com/huonw/simd)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "style_traits 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", @@ -804,7 +809,7 @@ dependencies = [ "phf 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "tendril 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -995,11 +1000,11 @@ dependencies = [ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "style_traits 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1678,10 +1683,10 @@ dependencies = [ "regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "script_traits 0.0.1", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1721,10 +1726,10 @@ dependencies = [ [[package]] name = "selectors" -version = "0.5.2" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1732,7 +1737,7 @@ dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1928,7 +1933,7 @@ dependencies = [ [[package]] name = "string_cache" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "debug_unreachable 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1958,11 +1963,11 @@ dependencies = [ "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "style_traits 0.0.1", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1981,7 +1986,7 @@ dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2164,7 +2169,7 @@ dependencies = [ "serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2350,7 +2355,7 @@ dependencies = [ "phf 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "string_cache 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "tendril 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/resources/servo.css b/resources/servo.css index 5fe1b27bf46..0ef23b8f86d 100644 --- a/resources/servo.css +++ b/resources/servo.css @@ -51,15 +51,11 @@ details::-servo-details-summary { details[open]::-servo-details-summary { list-style: disclosure-open; } -details::-servo-details-content { +*|*::-servo-details-content { margin-left: 40px; overflow: hidden; - display: none; -} -details[open]::-servo-details-content { display: block; } - /* * Until servo supports svg properly, make sure to at least prevent svg * children from being layed out and rendered like usual html. diff --git a/tests/unit/layout/size_of.rs b/tests/unit/layout/size_of.rs index f79e352cdc9..87f1dcb3d44 100644 --- a/tests/unit/layout/size_of.rs +++ b/tests/unit/layout/size_of.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use layout::Fragment; +use layout::ServoThreadSafeLayoutNode; use std::mem::size_of; #[test] @@ -12,7 +13,7 @@ fn test_size_of_fragment() { if actual < expected { panic!("Your changes have decreased the stack size of layout::fragment::Fragment \ - from {} to {}. Good work! Please update the size in tests/layout/size_of.rs", + from {} to {}. Good work! Please update the size in tests/unit/layout/size_of.rs", expected, actual); } @@ -20,7 +21,27 @@ fn test_size_of_fragment() { panic!("Your changes have increased the stack size of layout::fragment::Fragment \ from {} to {}. Please consider choosing a design which avoids this increase. \ If you feel that the increase is necessary, update the size in \ - tests/layout/size_of.rs.", + tests/unit/layout/size_of.rs.", + expected, actual); + } +} + +#[test] +fn test_size_of_layout_node() { + let expected = 16; + let actual = size_of::(); + + if actual < expected { + panic!("Your changes have decreased the stack size of layout::wrapper::ServoThreadSafeLayoutNode \ + from {} to {}. Good work! Please update the size in tests/layout/unit/size_of.rs", + expected, actual); + } + + if actual > expected { + panic!("Your changes have increased the stack size of layout::wrapper::ServoThreadSafeLayoutNode \ + from {} to {}. Please consider choosing a design which avoids this increase. \ + If you feel that the increase is necessary, update the size in \ + tests/unit/layout/size_of.rs.", expected, actual); } } diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml index f4e635cf076..91c3d5d4f64 100644 --- a/tests/unit/style/Cargo.toml +++ b/tests/unit/style/Cargo.toml @@ -18,6 +18,6 @@ app_units = {version = "0.2.3", features = ["plugins"]} cssparser = {version = "0.5.4", features = ["heap_size"]} euclid = {version = "0.6.4", features = ["plugins"]} selectors = {version = "0.5", features = ["heap_size"]} -string_cache = {version = "0.2.12", features = ["heap_size"]} +string_cache = {version = "0.2", features = ["heap_size"]} url = {version = "1.0.0", features = ["heap_size"]} rustc-serialize = "0.3" diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index 53e891f5dd1..91822093ea2 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -8,7 +8,7 @@ use selectors::parser::*; use std::borrow::ToOwned; use std::sync::Arc; use std::sync::Mutex; -use string_cache::Atom; +use string_cache::{Atom, Namespace}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands}; use style::stylesheets::{CSSRule, StyleRule, Origin}; use style::error_reporting::ParseErrorReporter; @@ -32,13 +32,13 @@ fn test_parse_stylesheet() { media: None, dirty_on_viewport_size_change: false, rules: vec![ - CSSRule::Namespace(None, ns!(html)), + CSSRule::Namespace(None, Namespace(Atom::from("http://www.w3.org/1999/xhtml"))), CSSRule::Style(StyleRule { selectors: vec![ Selector { compound_selectors: Arc::new(CompoundSelector { simple_selectors: vec![ - SimpleSelector::Namespace(ns!(html)), + SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))), SimpleSelector::LocalName(LocalName { name: atom!("input"), lower_name: atom!("input"), @@ -68,7 +68,7 @@ fn test_parse_stylesheet() { Selector { compound_selectors: Arc::new(CompoundSelector { simple_selectors: vec![ - SimpleSelector::Namespace(ns!(html)), + SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))), SimpleSelector::LocalName(LocalName { name: atom!("html"), lower_name: atom!("html"), @@ -82,7 +82,7 @@ fn test_parse_stylesheet() { Selector { compound_selectors: Arc::new(CompoundSelector { simple_selectors: vec![ - SimpleSelector::Namespace(ns!(html)), + SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))), SimpleSelector::LocalName(LocalName { name: atom!("body"), lower_name: atom!("body"), @@ -107,10 +107,12 @@ fn test_parse_stylesheet() { Selector { compound_selectors: Arc::new(CompoundSelector { simple_selectors: vec![ + SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))), SimpleSelector::Class(Atom::from("ok")), ], next: Some((Arc::new(CompoundSelector { simple_selectors: vec![ + SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))), SimpleSelector::ID(Atom::from("d1")), ], next: None, @@ -145,7 +147,6 @@ fn test_parse_stylesheet() { }); } - struct CSSError { pub line: usize, pub column: usize, diff --git a/tests/wpt/mozilla/tests/mozilla/details_ui_opened.html b/tests/wpt/mozilla/tests/mozilla/details_ui_opened.html index 10e65e98d81..2d9b13aad0a 100644 --- a/tests/wpt/mozilla/tests/mozilla/details_ui_opened.html +++ b/tests/wpt/mozilla/tests/mozilla/details_ui_opened.html @@ -6,4 +6,3 @@ Test Contents -