mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #10815 - emilio:anonbox-gcs, r=SimonSapin,bholley
style: Support anonymous box pseudo-elements This is a work-in-progress that: * Adds support for some pseudo-elements to skip the cascade entirely, in an analogous way to Gecko's anonymous box pseudo-elements. * Takes rid of `StylistWrapper`, and uses `Arc::get_mut` instead. * Uses the first bullet to precompute the `-servo-details-content` pseudo's style. I'd like @bholley to take a look before following, do you think that the aproach is the correct? Also, @SimonSapin could want to put some eyes on it. Depends on https://github.com/servo/rust-selectors/pull/81 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10815) <!-- Reviewable:end -->
This commit is contained in:
commit
407f991c8a
33 changed files with 762 additions and 336 deletions
|
@ -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<N>(node: &N) -> InlineFragmentsAccumulator
|
||||
fn from_inline_node<N>(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<FloatKind>)
|
||||
-> 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<InlineBlockSplit> = 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<FlowRef>,
|
||||
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<FloatKind>)
|
||||
-> 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<ConcreteThreadS
|
|||
let (display, float, positioning) = match node.type_id() {
|
||||
None => {
|
||||
// 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
|
||||
|
|
|
@ -108,7 +108,7 @@ pub struct LayoutContext<'a> {
|
|||
cached_local_layout_context: Rc<LocalLayoutContext>,
|
||||
}
|
||||
|
||||
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<FontContext> {
|
||||
self.cached_local_layout_context.font_context.borrow_mut()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<N: ThreadSafeLayoutNode>(self, node: &N) -> FlowRef;
|
||||
fn generate_missing_child_flow<N: ThreadSafeLayoutNode>(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<N: ThreadSafeLayoutNode>(self, node: &N) -> FlowRef {
|
||||
let mut style = node.style().clone();
|
||||
fn generate_missing_child_flow<N: ThreadSafeLayoutNode>(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))
|
||||
|
|
|
@ -319,9 +319,9 @@ pub struct CanvasFragmentInfo {
|
|||
}
|
||||
|
||||
impl CanvasFragmentInfo {
|
||||
pub fn new<N: ThreadSafeLayoutNode>(node: &N, data: HTMLCanvasData) -> CanvasFragmentInfo {
|
||||
pub fn new<N: ThreadSafeLayoutNode>(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<N>(node: &N) -> ReplacedImageFragmentInfo
|
||||
pub fn new<N>(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<N: ThreadSafeLayoutNode>(node: &N, specific: SpecificFragmentInfo) -> Fragment {
|
||||
let style = node.style().clone();
|
||||
pub fn new<N: ThreadSafeLayoutNode>(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),
|
||||
|
|
|
@ -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<Arc<DisplayList>>,
|
||||
|
||||
/// Performs CSS selector matching and style resolution.
|
||||
pub stylist: Box<Stylist>,
|
||||
pub stylist: Arc<Stylist>,
|
||||
|
||||
/// A queued response for the union of the content boxes of a node.
|
||||
pub content_box_response: Rect<Au>,
|
||||
|
@ -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::<ServoSelectorImpl>(&*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 {
|
||||
|
|
|
@ -103,3 +103,4 @@ mod wrapper;
|
|||
|
||||
// For unit tests:
|
||||
pub use fragment::Fragment;
|
||||
pub use wrapper::ServoThreadSafeLayoutNode;
|
||||
|
|
|
@ -574,8 +574,8 @@ pub fn process_resolved_style_request<N: LayoutNode>(
|
|||
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<N: LayoutNode>(
|
|||
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<N: LayoutNode>(requested_node: N, layout_root
|
|||
|
||||
pub fn process_node_overflow_request<N: LayoutNode>(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<N: LayoutNode>(requested_node: N) -> NodeOv
|
|||
pub fn process_margin_style_query<N: LayoutNode>(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 {
|
||||
|
|
|
@ -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<T> PseudoElementType<T> {
|
|||
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<display::T>) -> Self;
|
||||
fn with_pseudo(&self, pseudo: PseudoElementType<Option<display::T>>) -> 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<display::T>;
|
||||
fn get_pseudo_element_type(&self) -> PseudoElementType<Option<display::T>>;
|
||||
|
||||
#[inline]
|
||||
fn get_before_pseudo(&self) -> Option<Self> {
|
||||
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> {
|
||||
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<Self> {
|
||||
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<Arc<ServoComputedValues>> {
|
||||
fn style(&self, context: &SharedStyleContext) -> Ref<Arc<ServoComputedValues>> {
|
||||
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<Arc<ServoComputedValues>> {
|
||||
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<Arc<ServoComputedValues>> {
|
||||
fn selected_style(&self, _context: &SharedStyleContext) -> Ref<Arc<ServoComputedValues>> {
|
||||
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<ConcreteThreadSafeLayoutElement = Self>;
|
||||
|
||||
#[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<display::T>,
|
||||
/// The pseudo-element type, with (optionally),
|
||||
/// an specified display value to override the stylesheet.
|
||||
pseudo: PseudoElementType<Option<display::T>>,
|
||||
}
|
||||
|
||||
impl<'a> PartialEq for ServoThreadSafeLayoutNode<'a> {
|
||||
|
@ -948,7 +979,8 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
|||
type ConcreteThreadSafeLayoutElement = ServoThreadSafeLayoutElement<'ln>;
|
||||
type ChildrenIterator = ThreadSafeLayoutNodeChildrenIterator<Self>;
|
||||
|
||||
fn with_pseudo(&self, pseudo: PseudoElementType<display::T>) -> ServoThreadSafeLayoutNode<'ln> {
|
||||
fn with_pseudo(&self,
|
||||
pseudo: PseudoElementType<Option<display::T>>) -> 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<display::T> {
|
||||
fn get_pseudo_element_type(&self) -> PseudoElementType<Option<display::T>> {
|
||||
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<Text> = 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<Range<ByteIndex>> {
|
||||
|
@ -1164,8 +1190,8 @@ impl<ConcreteNode> Iterator for ThreadSafeLayoutNodeChildrenIterator<ConcreteNod
|
|||
loop {
|
||||
let next_node = if let Some(ref node) = current_node {
|
||||
if node.is_element() &&
|
||||
node.as_element().get_local_name() == &atom!("summary") &&
|
||||
node.as_element().get_namespace() == &ns!(html) {
|
||||
node.as_element().get_local_name() == &atom!("summary") &&
|
||||
node.as_element().get_namespace() == &ns!(html) {
|
||||
self.current_node = None;
|
||||
return Some(node.clone());
|
||||
}
|
||||
|
|
39
components/servo/Cargo.lock
generated
39
components/servo/Cargo.lock
generated
|
@ -158,6 +158,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"
|
||||
|
@ -727,7 +732,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)",
|
||||
|
@ -901,7 +906,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)",
|
||||
]
|
||||
|
@ -1092,11 +1097,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)",
|
||||
|
@ -1827,10 +1832,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)",
|
||||
|
@ -1881,10 +1886,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)",
|
||||
|
@ -1892,7 +1897,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]]
|
||||
|
@ -2053,7 +2058,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)",
|
||||
|
@ -2083,11 +2088,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)",
|
||||
|
@ -2104,8 +2109,8 @@ dependencies = [
|
|||
"msg 0.0.1",
|
||||
"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)",
|
||||
"string_cache 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"selectors 0.5.5 (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",
|
||||
"url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2124,7 +2129,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)",
|
||||
|
@ -2307,7 +2312,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)",
|
||||
]
|
||||
|
||||
|
@ -2534,7 +2539,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)",
|
||||
]
|
||||
|
|
|
@ -16,12 +16,6 @@ use std::collections::HashMap;
|
|||
use std::sync::mpsc::Sender;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
pub struct StylistWrapper<Impl: SelectorImplExt>(pub *const Stylist<Impl>);
|
||||
|
||||
// FIXME(#6569) This implementation is unsound.
|
||||
#[allow(unsafe_code)]
|
||||
unsafe impl<Impl: SelectorImplExt> Sync for StylistWrapper<Impl> {}
|
||||
|
||||
pub struct SharedStyleContext<Impl: SelectorImplExt> {
|
||||
/// The current viewport size.
|
||||
pub viewport_size: Size2D<Au>,
|
||||
|
@ -30,9 +24,7 @@ pub struct SharedStyleContext<Impl: SelectorImplExt> {
|
|||
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<Impl>,
|
||||
pub stylist: Arc<Stylist<Impl>>,
|
||||
|
||||
/// 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<C: ComputedValues> {
|
|||
pub style_sharing_candidate_cache: RefCell<StyleSharingCandidateCache<C>>,
|
||||
}
|
||||
|
||||
pub trait StyleContext<'a, Impl: SelectorImplExt, C: ComputedValues> {
|
||||
|
||||
pub trait StyleContext<'a, Impl: SelectorImplExt> {
|
||||
fn shared_context(&self) -> &'a SharedStyleContext<Impl>;
|
||||
fn local_context(&self) -> &LocalStyleContext<C>;
|
||||
fn local_context(&self) -> &LocalStyleContext<Impl::ComputedValues>;
|
||||
}
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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<<Self::ConcreteElement as Element>::Impl,
|
||||
Self::ConcreteComputedValues>>;
|
||||
Self::ConcreteComputedValues>>;
|
||||
|
||||
/// Borrows the PrivateStyleData immutably. Fails on a conflicting borrow.
|
||||
#[inline(always)]
|
||||
fn borrow_data(&self)
|
||||
-> Option<Ref<PrivateStyleData<<Self::ConcreteElement as Element>::Impl,
|
||||
Self::ConcreteComputedValues>>>;
|
||||
Self::ConcreteComputedValues>>>;
|
||||
|
||||
/// Borrows the PrivateStyleData mutably. Fails on a conflicting borrow.
|
||||
#[inline(always)]
|
||||
fn mutate_data(&self)
|
||||
-> Option<RefMut<PrivateStyleData<<Self::ConcreteElement as Element>::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<Arc<Self::ConcreteComputedValues>> {
|
||||
fn style(&self,
|
||||
_context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>)
|
||||
-> Ref<Arc<Self::ConcreteComputedValues>>
|
||||
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt<ComputedValues=Self::ConcreteComputedValues> {
|
||||
Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap())
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Atom> {
|
||||
|
|
|
@ -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<F>(mut fun: F)
|
||||
type ComputedValues: properties::ComputedValues;
|
||||
|
||||
fn each_pseudo_element<F>(mut fun: F)
|
||||
where F: FnMut(<Self as SelectorImpl>::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: &<Self as SelectorImpl>::PseudoElement) -> bool;
|
||||
|
||||
#[inline]
|
||||
fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F)
|
||||
where F: FnMut(<Self as SelectorImpl>::PseudoElement) {
|
||||
Self::each_pseudo_element(|pseudo| {
|
||||
if Self::is_eagerly_cascaded_pseudo_element(&pseudo) {
|
||||
fun(pseudo)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn each_non_eagerly_cascaded_pseudo_element<F>(mut fun: F)
|
||||
where F: FnMut(<Self as SelectorImpl>::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<Self>];
|
||||
|
@ -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<E: Element<Impl=ServoSelectorImpl>> 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<F>(mut fun: F)
|
||||
fn is_eagerly_cascaded_pseudo_element(pseudo: &PseudoElement) -> bool {
|
||||
pseudo.is_eagerly_cascaded()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn each_pseudo_element<F>(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<E: Element<Impl=ServoSelectorImpl>> ElementExt for E {
|
||||
fn is_link(&self) -> bool {
|
||||
self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Impl: SelectorImplExt> {
|
|||
/// The current selector maps, after evaluating media
|
||||
/// rules against the current device.
|
||||
element_map: PerPseudoElementSelectorMap<Impl>,
|
||||
|
||||
/// The selector maps corresponding to a given pseudo-element
|
||||
/// (depending on the implementation)
|
||||
pseudos_map: HashMap<Impl::PseudoElement,
|
||||
PerPseudoElementSelectorMap<Impl>,
|
||||
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<Impl::PseudoElement,
|
||||
Vec<DeclarationBlock>,
|
||||
BuildHasherDefault<::fnv::FnvHasher>>,
|
||||
|
||||
rules_source_order: usize,
|
||||
|
||||
/// Selector dependencies used to compute restyle hints.
|
||||
|
@ -138,6 +148,7 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
|
||||
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<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
|
||||
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<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
}
|
||||
|
||||
fn add_stylesheet(&mut self, stylesheet: &Stylesheet<Impl>) {
|
||||
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<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
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<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
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<Impl::ComputedValues>>) -> Option<Arc<Impl::ComputedValues>> {
|
||||
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::<Impl::ComputedValues>(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<E>(&self, element: &E,
|
||||
|
@ -284,20 +333,16 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
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,
|
||||
|
|
|
@ -12,5 +12,4 @@ use stylesheets;
|
|||
pub type Stylesheet = stylesheets::Stylesheet<ServoSelectorImpl>;
|
||||
pub type PrivateStyleData = data::PrivateStyleData<ServoSelectorImpl, ServoComputedValues>;
|
||||
pub type Stylist = selector_matching::Stylist<ServoSelectorImpl>;
|
||||
pub type StylistWrapper = context::StylistWrapper<ServoSelectorImpl>;
|
||||
pub type SharedStyleContext = context::SharedStyleContext<ServoSelectorImpl>;
|
||||
|
|
|
@ -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, <N::ConcreteElement as Element>::Impl, N::ConcreteComputedValues>,
|
||||
<N::ConcreteElement as Element>::Impl: SelectorImplExt + 'a {
|
||||
C: StyleContext<'a, <N::ConcreteElement as Element>::Impl>,
|
||||
<N::ConcreteElement as Element>::Impl: SelectorImplExt<ComputedValues=N::ConcreteComputedValues> + '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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue