mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
layout: Simplify and generalize the usage of pseudo-elements (#36202)
- Remove the last remaining Servo-specific PseudoElement enum from layout. This was made to select `::before` and `::after` (both eager pseudo-elements), but now `traverse_pseudo_element` is called `traverse_eager_pseudo_element` and should work on any eager pseudo element. - Expose a single way of getting psuedo-element variants of ThreadSafeLayoutElement in the Layout DOM, which returns `None` when the pseudo-element doesn't apply (not defined for eager pseudo-elements or when trying to get `<details>` related pseudo-elements on elements that they don't apply to). - Ensure that NodeAndStyleInfo always refers to a node. This is done by making sure that anonymous boxes are all associated with their originating node. These changes are prepatory work for implementation of the `::marker` pseudo-element as well as ensuring that all anonymous boxes can be cached into the box tree eventually. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
c30ad5a30e
commit
b5c8164e99
15 changed files with 278 additions and 354 deletions
|
@ -5,8 +5,10 @@
|
||||||
//! Layout construction code that is shared between modern layout modes (Flexbox and CSS Grid)
|
//! Layout construction code that is shared between modern layout modes (Flexbox and CSS Grid)
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
|
use style::selector_parser::PseudoElement;
|
||||||
|
|
||||||
use crate::PropagatedBoxTreeData;
|
use crate::PropagatedBoxTreeData;
|
||||||
use crate::context::LayoutContext;
|
use crate::context::LayoutContext;
|
||||||
|
@ -136,21 +138,11 @@ where
|
||||||
pub(crate) fn finish(mut self) -> Vec<ModernItem<'dom>> {
|
pub(crate) fn finish(mut self) -> Vec<ModernItem<'dom>> {
|
||||||
self.wrap_any_text_in_anonymous_block_container();
|
self.wrap_any_text_in_anonymous_block_container();
|
||||||
|
|
||||||
let anonymous_style = if self.has_text_runs {
|
let anonymous_info = LazyLock::new(|| {
|
||||||
Some(
|
self.info
|
||||||
self.context
|
.pseudo(self.context, PseudoElement::ServoAnonymousBox)
|
||||||
.shared_context()
|
.expect("Should always be able to construct info for anonymous boxes.")
|
||||||
.stylist
|
});
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
|
||||||
&self.context.shared_context().guards,
|
|
||||||
&style::selector_parser::PseudoElement::ServoAnonymousBox,
|
|
||||||
&self.info.style,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut children: Vec<ModernItem> = std::mem::take(&mut self.jobs)
|
let mut children: Vec<ModernItem> = std::mem::take(&mut self.jobs)
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.filter_map(|job| match job {
|
.filter_map(|job| match job {
|
||||||
|
@ -173,7 +165,7 @@ where
|
||||||
let block_formatting_context = BlockFormattingContext::from_block_container(
|
let block_formatting_context = BlockFormattingContext::from_block_container(
|
||||||
BlockContainer::InlineFormattingContext(inline_formatting_context),
|
BlockContainer::InlineFormattingContext(inline_formatting_context),
|
||||||
);
|
);
|
||||||
let info = &self.info.new_anonymous(anonymous_style.clone().unwrap());
|
let info: &NodeAndStyleInfo<_> = &*anonymous_info;
|
||||||
let formatting_context = IndependentFormattingContext {
|
let formatting_context = IndependentFormattingContext {
|
||||||
base: LayoutBoxBase::new(info.into(), info.style.clone()),
|
base: LayoutBoxBase::new(info.into(), info.style.clone()),
|
||||||
contents: IndependentFormattingContextContents::NonReplaced(
|
contents: IndependentFormattingContextContents::NonReplaced(
|
||||||
|
|
|
@ -17,10 +17,10 @@ use script_layout_interface::{
|
||||||
};
|
};
|
||||||
use servo_arc::Arc as ServoArc;
|
use servo_arc::Arc as ServoArc;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
|
use style::selector_parser::PseudoElement;
|
||||||
|
|
||||||
use crate::cell::ArcRefCell;
|
use crate::cell::ArcRefCell;
|
||||||
use crate::context::LayoutContext;
|
use crate::context::LayoutContext;
|
||||||
use crate::dom_traversal::WhichPseudoElement;
|
|
||||||
use crate::flexbox::FlexLevelBox;
|
use crate::flexbox::FlexLevelBox;
|
||||||
use crate::flow::BlockLevelBox;
|
use crate::flow::BlockLevelBox;
|
||||||
use crate::flow::inline::InlineItem;
|
use crate::flow::inline::InlineItem;
|
||||||
|
@ -108,8 +108,8 @@ pub(crate) trait NodeExt<'dom>: 'dom + LayoutNode<'dom> {
|
||||||
fn layout_data_mut(self) -> AtomicRefMut<'dom, InnerDOMLayoutData>;
|
fn layout_data_mut(self) -> AtomicRefMut<'dom, InnerDOMLayoutData>;
|
||||||
fn layout_data(self) -> Option<AtomicRef<'dom, InnerDOMLayoutData>>;
|
fn layout_data(self) -> Option<AtomicRef<'dom, InnerDOMLayoutData>>;
|
||||||
fn element_box_slot(&self) -> BoxSlot<'dom>;
|
fn element_box_slot(&self) -> BoxSlot<'dom>;
|
||||||
fn pseudo_element_box_slot(&self, which: WhichPseudoElement) -> BoxSlot<'dom>;
|
fn pseudo_element_box_slot(&self, which: PseudoElement) -> BoxSlot<'dom>;
|
||||||
fn unset_pseudo_element_box(self, which: WhichPseudoElement);
|
fn unset_pseudo_element_box(self, which: PseudoElement);
|
||||||
|
|
||||||
/// Remove boxes for the element itself, and its `:before` and `:after` if any.
|
/// Remove boxes for the element itself, and its `:before` and `:after` if any.
|
||||||
fn unset_all_boxes(self);
|
fn unset_all_boxes(self);
|
||||||
|
@ -217,20 +217,28 @@ where
|
||||||
BoxSlot::new(self.layout_data_mut().self_box.clone())
|
BoxSlot::new(self.layout_data_mut().self_box.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pseudo_element_box_slot(&self, which: WhichPseudoElement) -> BoxSlot<'dom> {
|
fn pseudo_element_box_slot(&self, pseudo_element_type: PseudoElement) -> BoxSlot<'dom> {
|
||||||
let data = self.layout_data_mut();
|
let data = self.layout_data_mut();
|
||||||
let cell = match which {
|
let cell = match pseudo_element_type {
|
||||||
WhichPseudoElement::Before => &data.pseudo_before_box,
|
PseudoElement::Before => &data.pseudo_before_box,
|
||||||
WhichPseudoElement::After => &data.pseudo_after_box,
|
PseudoElement::After => &data.pseudo_after_box,
|
||||||
|
_ => unreachable!(
|
||||||
|
"Asked for box slot for unsupported pseudo-element: {:?}",
|
||||||
|
pseudo_element_type
|
||||||
|
),
|
||||||
};
|
};
|
||||||
BoxSlot::new(cell.clone())
|
BoxSlot::new(cell.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unset_pseudo_element_box(self, which: WhichPseudoElement) {
|
fn unset_pseudo_element_box(self, pseudo_element_type: PseudoElement) {
|
||||||
let data = self.layout_data_mut();
|
let data = self.layout_data_mut();
|
||||||
let cell = match which {
|
let cell = match pseudo_element_type {
|
||||||
WhichPseudoElement::Before => &data.pseudo_before_box,
|
PseudoElement::Before => &data.pseudo_before_box,
|
||||||
WhichPseudoElement::After => &data.pseudo_after_box,
|
PseudoElement::After => &data.pseudo_after_box,
|
||||||
|
_ => unreachable!(
|
||||||
|
"Asked for box slot for unsupported pseudo-element: {:?}",
|
||||||
|
pseudo_element_type
|
||||||
|
),
|
||||||
};
|
};
|
||||||
*cell.borrow_mut() = None;
|
*cell.borrow_mut() = None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ use std::borrow::Cow;
|
||||||
use std::iter::FusedIterator;
|
use std::iter::FusedIterator;
|
||||||
|
|
||||||
use html5ever::{LocalName, local_name};
|
use html5ever::{LocalName, local_name};
|
||||||
use log::warn;
|
|
||||||
use script_layout_interface::wrapper_traits::{ThreadSafeLayoutElement, ThreadSafeLayoutNode};
|
use script_layout_interface::wrapper_traits::{ThreadSafeLayoutElement, ThreadSafeLayoutNode};
|
||||||
use script_layout_interface::{LayoutElementType, LayoutNodeType};
|
use script_layout_interface::{LayoutElementType, LayoutNodeType};
|
||||||
use selectors::Element as SelectorsElement;
|
use selectors::Element as SelectorsElement;
|
||||||
|
@ -24,29 +23,23 @@ use crate::quotes::quotes_for_lang;
|
||||||
use crate::replaced::ReplacedContents;
|
use crate::replaced::ReplacedContents;
|
||||||
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside, DisplayOutside};
|
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside, DisplayOutside};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub(crate) enum WhichPseudoElement {
|
|
||||||
Before,
|
|
||||||
After,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A data structure used to pass and store related layout information together to
|
/// A data structure used to pass and store related layout information together to
|
||||||
/// avoid having to repeat the same arguments in argument lists.
|
/// avoid having to repeat the same arguments in argument lists.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct NodeAndStyleInfo<Node> {
|
pub(crate) struct NodeAndStyleInfo<Node> {
|
||||||
pub node: Option<Node>,
|
pub node: Node,
|
||||||
pub pseudo_element_type: Option<WhichPseudoElement>,
|
pub pseudo_element_type: Option<PseudoElement>,
|
||||||
pub style: ServoArc<ComputedValues>,
|
pub style: ServoArc<ComputedValues>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'dom, Node: NodeExt<'dom>> NodeAndStyleInfo<Node> {
|
impl<'dom, Node: NodeExt<'dom>> NodeAndStyleInfo<Node> {
|
||||||
fn new_with_pseudo(
|
fn new_with_pseudo(
|
||||||
node: Node,
|
node: Node,
|
||||||
pseudo_element_type: WhichPseudoElement,
|
pseudo_element_type: PseudoElement,
|
||||||
style: ServoArc<ComputedValues>,
|
style: ServoArc<ComputedValues>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
node: Some(node),
|
node,
|
||||||
pseudo_element_type: Some(pseudo_element_type),
|
pseudo_element_type: Some(pseudo_element_type),
|
||||||
style,
|
style,
|
||||||
}
|
}
|
||||||
|
@ -54,55 +47,60 @@ impl<'dom, Node: NodeExt<'dom>> NodeAndStyleInfo<Node> {
|
||||||
|
|
||||||
pub(crate) fn new(node: Node, style: ServoArc<ComputedValues>) -> Self {
|
pub(crate) fn new(node: Node, style: ServoArc<ComputedValues>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
node: Some(node),
|
node,
|
||||||
pseudo_element_type: None,
|
pseudo_element_type: None,
|
||||||
style,
|
style,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_single_line_text_input(&self) -> bool {
|
pub(crate) fn is_single_line_text_input(&self) -> bool {
|
||||||
self.node.is_some_and(|node| {
|
self.node.type_id() == LayoutNodeType::Element(LayoutElementType::HTMLInputElement)
|
||||||
node.type_id() == LayoutNodeType::Element(LayoutElementType::HTMLInputElement)
|
}
|
||||||
|
|
||||||
|
pub(crate) fn pseudo(
|
||||||
|
&self,
|
||||||
|
context: &LayoutContext,
|
||||||
|
pseudo_element_type: PseudoElement,
|
||||||
|
) -> Option<Self> {
|
||||||
|
let style = self
|
||||||
|
.node
|
||||||
|
.to_threadsafe()
|
||||||
|
.as_element()?
|
||||||
|
.with_pseudo(pseudo_element_type)?
|
||||||
|
.style(context.shared_context());
|
||||||
|
Some(NodeAndStyleInfo {
|
||||||
|
node: self.node,
|
||||||
|
pseudo_element_type: Some(pseudo_element_type),
|
||||||
|
style,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Node: Clone> NodeAndStyleInfo<Node> {
|
|
||||||
pub(crate) fn new_anonymous(&self, style: ServoArc<ComputedValues>) -> Self {
|
|
||||||
Self {
|
|
||||||
node: None,
|
|
||||||
pseudo_element_type: self.pseudo_element_type,
|
|
||||||
style,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn new_replacing_style(&self, style: ServoArc<ComputedValues>) -> Self {
|
|
||||||
Self {
|
|
||||||
node: self.node.clone(),
|
|
||||||
pseudo_element_type: self.pseudo_element_type,
|
|
||||||
style,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'dom, Node> From<&NodeAndStyleInfo<Node>> for BaseFragmentInfo
|
impl<'dom, Node> From<&NodeAndStyleInfo<Node>> for BaseFragmentInfo
|
||||||
where
|
where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
fn from(info: &NodeAndStyleInfo<Node>) -> Self {
|
fn from(info: &NodeAndStyleInfo<Node>) -> Self {
|
||||||
let node = match info.node {
|
let node = info.node;
|
||||||
Some(node) => node,
|
let pseudo = info.pseudo_element_type;
|
||||||
None => return Self::anonymous(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let pseudo = info.pseudo_element_type.map(|pseudo| match pseudo {
|
|
||||||
WhichPseudoElement::Before => PseudoElement::Before,
|
|
||||||
WhichPseudoElement::After => PseudoElement::After,
|
|
||||||
});
|
|
||||||
|
|
||||||
let threadsafe_node = node.to_threadsafe();
|
let threadsafe_node = node.to_threadsafe();
|
||||||
let mut flags = FragmentFlags::empty();
|
let mut flags = FragmentFlags::empty();
|
||||||
|
|
||||||
|
// Anonymous boxes should not have a tag, because they should not take part in hit testing.
|
||||||
|
//
|
||||||
|
// TODO(mrobinson): It seems that anonymous boxes should take part in hit testing in some
|
||||||
|
// cases, but currently this means that the order of hit test results isn't as expected for
|
||||||
|
// some WPT tests. This needs more investigation.
|
||||||
|
if matches!(
|
||||||
|
pseudo,
|
||||||
|
Some(PseudoElement::ServoAnonymousBox) |
|
||||||
|
Some(PseudoElement::ServoAnonymousTable) |
|
||||||
|
Some(PseudoElement::ServoAnonymousTableCell) |
|
||||||
|
Some(PseudoElement::ServoAnonymousTableRow)
|
||||||
|
) {
|
||||||
|
return Self::anonymous();
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(element) = threadsafe_node.as_html_element() {
|
if let Some(element) = threadsafe_node.as_html_element() {
|
||||||
if element.is_body_element_of_html_element_root() {
|
if element.is_body_element_of_html_element_root() {
|
||||||
flags.insert(FragmentFlags::IS_BODY_ELEMENT_OF_HTML_ELEMENT_ROOT);
|
flags.insert(FragmentFlags::IS_BODY_ELEMENT_OF_HTML_ELEMENT_ROOT);
|
||||||
|
@ -184,7 +182,7 @@ fn traverse_children_of<'dom, Node>(
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
traverse_pseudo_element(WhichPseudoElement::Before, parent_element, context, handler);
|
traverse_eager_pseudo_element(PseudoElement::Before, parent_element, context, handler);
|
||||||
|
|
||||||
let is_text_input_element = matches!(
|
let is_text_input_element = matches!(
|
||||||
parent_element.type_id(),
|
parent_element.type_id(),
|
||||||
|
@ -223,7 +221,7 @@ fn traverse_children_of<'dom, Node>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
traverse_pseudo_element(WhichPseudoElement::After, parent_element, context, handler);
|
traverse_eager_pseudo_element(PseudoElement::After, parent_element, context, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traverse_element<'dom, Node>(
|
fn traverse_element<'dom, Node>(
|
||||||
|
@ -268,33 +266,46 @@ fn traverse_element<'dom, Node>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traverse_pseudo_element<'dom, Node>(
|
fn traverse_eager_pseudo_element<'dom, Node>(
|
||||||
which: WhichPseudoElement,
|
pseudo_element_type: PseudoElement,
|
||||||
element: Node,
|
node: Node,
|
||||||
context: &LayoutContext,
|
context: &LayoutContext,
|
||||||
handler: &mut impl TraversalHandler<'dom, Node>,
|
handler: &mut impl TraversalHandler<'dom, Node>,
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
if let Some(style) = pseudo_element_style(which, element, context) {
|
assert!(pseudo_element_type.is_eager());
|
||||||
let info = NodeAndStyleInfo::new_with_pseudo(element, which, style);
|
|
||||||
match Display::from(info.style.get_box().display) {
|
// First clear any old contents from the node.
|
||||||
Display::None => element.unset_pseudo_element_box(which),
|
node.unset_pseudo_element_box(pseudo_element_type);
|
||||||
Display::Contents => {
|
|
||||||
let items = generate_pseudo_element_content(&info.style, element, context);
|
let Some(element) = node.to_threadsafe().as_element() else {
|
||||||
let box_slot = element.pseudo_element_box_slot(which);
|
return;
|
||||||
box_slot.set(LayoutBox::DisplayContents);
|
};
|
||||||
traverse_pseudo_element_contents(&info, context, handler, items);
|
let Some(pseudo_element) = element.with_pseudo(pseudo_element_type) else {
|
||||||
},
|
return;
|
||||||
Display::GeneratingBox(display) => {
|
};
|
||||||
let items = generate_pseudo_element_content(&info.style, element, context);
|
|
||||||
let box_slot = element.pseudo_element_box_slot(which);
|
let style = pseudo_element.style(context.shared_context());
|
||||||
let contents = NonReplacedContents::OfPseudoElement(items).into();
|
if style.ineffective_content_property() {
|
||||||
handler.handle_element(&info, display, contents, box_slot);
|
return;
|
||||||
},
|
}
|
||||||
}
|
|
||||||
} else {
|
let info = NodeAndStyleInfo::new_with_pseudo(node, pseudo_element_type, style);
|
||||||
element.unset_pseudo_element_box(which)
|
match Display::from(info.style.get_box().display) {
|
||||||
|
Display::None => {},
|
||||||
|
Display::Contents => {
|
||||||
|
let items = generate_pseudo_element_content(&info.style, node, context);
|
||||||
|
let box_slot = node.pseudo_element_box_slot(pseudo_element_type);
|
||||||
|
box_slot.set(LayoutBox::DisplayContents);
|
||||||
|
traverse_pseudo_element_contents(&info, context, handler, items);
|
||||||
|
},
|
||||||
|
Display::GeneratingBox(display) => {
|
||||||
|
let items = generate_pseudo_element_content(&info.style, node, context);
|
||||||
|
let box_slot = node.pseudo_element_box_slot(pseudo_element_type);
|
||||||
|
let contents = NonReplacedContents::OfPseudoElement(items).into();
|
||||||
|
handler.handle_element(&info, display, contents, box_slot);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,20 +317,14 @@ fn traverse_pseudo_element_contents<'dom, Node>(
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
let mut anonymous_style = None;
|
let mut anonymous_info = None;
|
||||||
for item in items {
|
for item in items {
|
||||||
match item {
|
match item {
|
||||||
PseudoElementContentItem::Text(text) => handler.handle_text(info, text.into()),
|
PseudoElementContentItem::Text(text) => handler.handle_text(info, text.into()),
|
||||||
PseudoElementContentItem::Replaced(contents) => {
|
PseudoElementContentItem::Replaced(contents) => {
|
||||||
let item_style = anonymous_style.get_or_insert_with(|| {
|
let anonymous_info = anonymous_info.get_or_insert_with(|| {
|
||||||
context
|
info.pseudo(context, PseudoElement::ServoAnonymousBox)
|
||||||
.shared_context()
|
.unwrap_or_else(|| info.clone())
|
||||||
.stylist
|
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
|
||||||
&context.shared_context().guards,
|
|
||||||
&PseudoElement::ServoAnonymousBox,
|
|
||||||
&info.style,
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
let display_inline = DisplayGeneratingBox::OutsideInside {
|
let display_inline = DisplayGeneratingBox::OutsideInside {
|
||||||
outside: DisplayOutside::Inline,
|
outside: DisplayOutside::Inline,
|
||||||
|
@ -329,12 +334,11 @@ fn traverse_pseudo_element_contents<'dom, Node>(
|
||||||
};
|
};
|
||||||
// `display` is not inherited, so we get the initial value
|
// `display` is not inherited, so we get the initial value
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
Display::from(item_style.get_box().display) ==
|
Display::from(anonymous_info.style.get_box().display) ==
|
||||||
Display::GeneratingBox(display_inline)
|
Display::GeneratingBox(display_inline)
|
||||||
);
|
);
|
||||||
let info = info.new_replacing_style(item_style.clone());
|
|
||||||
handler.handle_element(
|
handler.handle_element(
|
||||||
&info,
|
anonymous_info,
|
||||||
display_inline,
|
display_inline,
|
||||||
Contents::Replaced(contents),
|
Contents::Replaced(contents),
|
||||||
// We don’t keep pointers to boxes generated by contents of pseudo-elements
|
// We don’t keep pointers to boxes generated by contents of pseudo-elements
|
||||||
|
@ -380,16 +384,9 @@ impl NonReplacedContents {
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
let node = match info.node {
|
|
||||||
Some(node) => node,
|
|
||||||
None => {
|
|
||||||
warn!("Tried to traverse an anonymous node!");
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
match self {
|
match self {
|
||||||
NonReplacedContents::OfElement | NonReplacedContents::OfTextControl => {
|
NonReplacedContents::OfElement | NonReplacedContents::OfTextControl => {
|
||||||
traverse_children_of(node, context, handler)
|
traverse_children_of(info.node, context, handler)
|
||||||
},
|
},
|
||||||
NonReplacedContents::OfPseudoElement(items) => {
|
NonReplacedContents::OfPseudoElement(items) => {
|
||||||
traverse_pseudo_element_contents(info, context, handler, items)
|
traverse_pseudo_element_contents(info, context, handler, items)
|
||||||
|
@ -398,28 +395,6 @@ impl NonReplacedContents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pseudo_element_style<'dom, Node>(
|
|
||||||
which: WhichPseudoElement,
|
|
||||||
element: Node,
|
|
||||||
context: &LayoutContext,
|
|
||||||
) -> Option<ServoArc<ComputedValues>>
|
|
||||||
where
|
|
||||||
Node: NodeExt<'dom>,
|
|
||||||
{
|
|
||||||
match which {
|
|
||||||
WhichPseudoElement::After => element.to_threadsafe().get_pseudo(PseudoElement::After),
|
|
||||||
WhichPseudoElement::Before => element.to_threadsafe().get_pseudo(PseudoElement::Before),
|
|
||||||
}
|
|
||||||
.and_then(|pseudo_element| {
|
|
||||||
let style = pseudo_element.style(context.shared_context());
|
|
||||||
if style.ineffective_content_property() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(style)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_quote_from_pair<I, S>(item: &ContentItem<I>, opening: &S, closing: &S) -> String
|
fn get_quote_from_pair<I, S>(item: &ContentItem<I>, opening: &S, closing: &S) -> String
|
||||||
where
|
where
|
||||||
S: ToString + ?Sized,
|
S: ToString + ?Sized,
|
||||||
|
|
|
@ -83,6 +83,7 @@ enum BlockLevelCreator {
|
||||||
contents: Contents,
|
contents: Contents,
|
||||||
},
|
},
|
||||||
OutsideMarker {
|
OutsideMarker {
|
||||||
|
list_item_style: Arc<ComputedValues>,
|
||||||
contents: Vec<PseudoElementContentItem>,
|
contents: Vec<PseudoElementContentItem>,
|
||||||
},
|
},
|
||||||
AnonymousTable {
|
AnonymousTable {
|
||||||
|
@ -141,9 +142,9 @@ pub(crate) struct BlockContainerBuilder<'dom, 'style, Node> {
|
||||||
|
|
||||||
inline_formatting_context_builder: InlineFormattingContextBuilder,
|
inline_formatting_context_builder: InlineFormattingContextBuilder,
|
||||||
|
|
||||||
/// The style of the anonymous block boxes pushed to the list of block-level
|
/// The [`NodeAndStyleInfo`] to use for anonymous block boxes pushed to the list of
|
||||||
/// boxes, if any (see `end_ongoing_inline_formatting_context`).
|
/// block-level boxes, lazily initialized (see `end_ongoing_inline_formatting_context`).
|
||||||
anonymous_style: Option<Arc<ComputedValues>>,
|
anonymous_box_info: Option<NodeAndStyleInfo<Node>>,
|
||||||
|
|
||||||
/// A collection of content that is being added to an anonymous table. This is
|
/// A collection of content that is being added to an anonymous table. This is
|
||||||
/// composed of any sequence of internal table elements or table captions that
|
/// composed of any sequence of internal table elements or table captions that
|
||||||
|
@ -165,14 +166,16 @@ impl BlockContainer {
|
||||||
let mut builder = BlockContainerBuilder::new(context, info, propagated_data);
|
let mut builder = BlockContainerBuilder::new(context, info, propagated_data);
|
||||||
|
|
||||||
if is_list_item {
|
if is_list_item {
|
||||||
if let Some(marker_contents) = crate::lists::make_marker(context, info) {
|
if let Some((marker_info, marker_contents)) = crate::lists::make_marker(context, info) {
|
||||||
match info.style.clone_list_style_position() {
|
match marker_info.style.clone_list_style_position() {
|
||||||
ListStylePosition::Inside => {
|
ListStylePosition::Inside => {
|
||||||
builder.handle_list_item_marker_inside(info, marker_contents)
|
builder.handle_list_item_marker_inside(&marker_info, marker_contents)
|
||||||
},
|
|
||||||
ListStylePosition::Outside => {
|
|
||||||
builder.handle_list_item_marker_outside(info, marker_contents)
|
|
||||||
},
|
},
|
||||||
|
ListStylePosition::Outside => builder.handle_list_item_marker_outside(
|
||||||
|
&marker_info,
|
||||||
|
marker_contents,
|
||||||
|
info.style.clone(),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +200,7 @@ where
|
||||||
block_level_boxes: Vec::new(),
|
block_level_boxes: Vec::new(),
|
||||||
propagated_data: propagated_data.union(&info.style),
|
propagated_data: propagated_data.union(&info.style),
|
||||||
have_already_seen_first_line_for_text_indent: false,
|
have_already_seen_first_line_for_text_indent: false,
|
||||||
anonymous_style: None,
|
anonymous_box_info: None,
|
||||||
anonymous_table_content: Vec::new(),
|
anonymous_table_content: Vec::new(),
|
||||||
inline_formatting_context_builder: InlineFormattingContextBuilder::new(),
|
inline_formatting_context_builder: InlineFormattingContextBuilder::new(),
|
||||||
}
|
}
|
||||||
|
@ -277,16 +280,16 @@ where
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let ifc = Table::construct_anonymous(self.context, self.info, contents, propagated_data);
|
let (table_info, ifc) =
|
||||||
|
Table::construct_anonymous(self.context, self.info, contents, propagated_data);
|
||||||
|
|
||||||
if inline_table {
|
if inline_table {
|
||||||
self.inline_formatting_context_builder.push_atomic(ifc);
|
self.inline_formatting_context_builder.push_atomic(ifc);
|
||||||
} else {
|
} else {
|
||||||
let anonymous_info = self.info.new_anonymous(ifc.style().clone());
|
|
||||||
let table_block = ArcRefCell::new(BlockLevelBox::Independent(ifc));
|
let table_block = ArcRefCell::new(BlockLevelBox::Independent(ifc));
|
||||||
self.end_ongoing_inline_formatting_context();
|
self.end_ongoing_inline_formatting_context();
|
||||||
self.block_level_boxes.push(BlockLevelJob {
|
self.block_level_boxes.push(BlockLevelJob {
|
||||||
info: anonymous_info,
|
info: table_info,
|
||||||
box_slot: BoxSlot::dummy(),
|
box_slot: BoxSlot::dummy(),
|
||||||
kind: BlockLevelCreator::AnonymousTable { table_block },
|
kind: BlockLevelCreator::AnonymousTable { table_block },
|
||||||
propagated_data,
|
propagated_data,
|
||||||
|
@ -384,17 +387,8 @@ where
|
||||||
info: &NodeAndStyleInfo<Node>,
|
info: &NodeAndStyleInfo<Node>,
|
||||||
contents: Vec<crate::dom_traversal::PseudoElementContentItem>,
|
contents: Vec<crate::dom_traversal::PseudoElementContentItem>,
|
||||||
) {
|
) {
|
||||||
let marker_style = self
|
|
||||||
.context
|
|
||||||
.shared_context()
|
|
||||||
.stylist
|
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
|
||||||
&self.context.shared_context().guards,
|
|
||||||
&PseudoElement::ServoLegacyText, // FIMXE: use `PseudoElement::Marker` when we add it
|
|
||||||
&info.style,
|
|
||||||
);
|
|
||||||
self.handle_inline_level_element(
|
self.handle_inline_level_element(
|
||||||
&info.new_replacing_style(marker_style),
|
info,
|
||||||
DisplayInside::Flow {
|
DisplayInside::Flow {
|
||||||
is_list_item: false,
|
is_list_item: false,
|
||||||
},
|
},
|
||||||
|
@ -407,11 +401,15 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
info: &NodeAndStyleInfo<Node>,
|
info: &NodeAndStyleInfo<Node>,
|
||||||
contents: Vec<crate::dom_traversal::PseudoElementContentItem>,
|
contents: Vec<crate::dom_traversal::PseudoElementContentItem>,
|
||||||
|
list_item_style: Arc<ComputedValues>,
|
||||||
) {
|
) {
|
||||||
self.block_level_boxes.push(BlockLevelJob {
|
self.block_level_boxes.push(BlockLevelJob {
|
||||||
info: info.clone(),
|
info: info.clone(),
|
||||||
box_slot: BoxSlot::dummy(),
|
box_slot: BoxSlot::dummy(),
|
||||||
kind: BlockLevelCreator::OutsideMarker { contents },
|
kind: BlockLevelCreator::OutsideMarker {
|
||||||
|
contents,
|
||||||
|
list_item_style,
|
||||||
|
},
|
||||||
propagated_data: self.propagated_data.without_text_decorations(),
|
propagated_data: self.propagated_data.without_text_decorations(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -448,11 +446,13 @@ where
|
||||||
.start_inline_box(InlineBox::new(info));
|
.start_inline_box(InlineBox::new(info));
|
||||||
|
|
||||||
if is_list_item {
|
if is_list_item {
|
||||||
if let Some(marker_contents) = crate::lists::make_marker(self.context, info) {
|
if let Some((marker_info, marker_contents)) =
|
||||||
|
crate::lists::make_marker(self.context, info)
|
||||||
|
{
|
||||||
// Ignore `list-style-position` here:
|
// Ignore `list-style-position` here:
|
||||||
// “If the list item is an inline box: this value is equivalent to `inside`.”
|
// “If the list item is an inline box: this value is equivalent to `inside`.”
|
||||||
// https://drafts.csswg.org/css-lists/#list-style-position-outside
|
// https://drafts.csswg.org/css-lists/#list-style-position-outside
|
||||||
self.handle_list_item_marker_inside(info, marker_contents)
|
self.handle_list_item_marker_inside(&marker_info, marker_contents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,20 +616,16 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
inline_formatting_context: InlineFormattingContext,
|
inline_formatting_context: InlineFormattingContext,
|
||||||
) {
|
) {
|
||||||
let block_container_style = &self.info.style;
|
|
||||||
let layout_context = self.context;
|
let layout_context = self.context;
|
||||||
let anonymous_style = self.anonymous_style.get_or_insert_with(|| {
|
let info = self
|
||||||
layout_context
|
.anonymous_box_info
|
||||||
.shared_context()
|
.get_or_insert_with(|| {
|
||||||
.stylist
|
self.info
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
.pseudo(layout_context, PseudoElement::ServoAnonymousBox)
|
||||||
&layout_context.shared_context().guards,
|
.expect("Should never fail to create anonymous box")
|
||||||
&PseudoElement::ServoAnonymousBox,
|
})
|
||||||
block_container_style,
|
.clone();
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let info = self.info.new_anonymous(anonymous_style.clone());
|
|
||||||
self.block_level_boxes.push(BlockLevelJob {
|
self.block_level_boxes.push(BlockLevelJob {
|
||||||
info,
|
info,
|
||||||
// FIXME(nox): We should be storing this somewhere.
|
// FIXME(nox): We should be storing this somewhere.
|
||||||
|
@ -696,27 +692,23 @@ where
|
||||||
contents,
|
contents,
|
||||||
self.propagated_data,
|
self.propagated_data,
|
||||||
))),
|
))),
|
||||||
BlockLevelCreator::OutsideMarker { contents } => {
|
BlockLevelCreator::OutsideMarker {
|
||||||
let marker_style = context
|
contents,
|
||||||
.shared_context()
|
list_item_style,
|
||||||
.stylist
|
} => {
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
|
||||||
&context.shared_context().guards,
|
|
||||||
&PseudoElement::ServoLegacyText, // FIMXE: use `PseudoElement::Marker` when we add it
|
|
||||||
&info.style,
|
|
||||||
);
|
|
||||||
let contents = NonReplacedContents::OfPseudoElement(contents);
|
let contents = NonReplacedContents::OfPseudoElement(contents);
|
||||||
let block_container = BlockContainer::construct(
|
let block_container = BlockContainer::construct(
|
||||||
context,
|
context,
|
||||||
&info.new_replacing_style(marker_style.clone()),
|
info,
|
||||||
contents,
|
contents,
|
||||||
self.propagated_data.without_text_decorations(),
|
self.propagated_data.without_text_decorations(),
|
||||||
false, /* is_list_item */
|
false, /* is_list_item */
|
||||||
);
|
);
|
||||||
ArcRefCell::new(BlockLevelBox::OutsideMarker(OutsideMarker {
|
ArcRefCell::new(BlockLevelBox::OutsideMarker(OutsideMarker {
|
||||||
marker_style,
|
marker_style: info.style.clone(),
|
||||||
base: LayoutBoxBase::new(info.into(), info.style.clone()),
|
base: LayoutBoxBase::new(info.into(), info.style.clone()),
|
||||||
block_container,
|
block_container,
|
||||||
|
list_item_style,
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
BlockLevelCreator::AnonymousTable { table_block } => table_block,
|
BlockLevelCreator::AnonymousTable { table_block } => table_block,
|
||||||
|
|
|
@ -227,15 +227,12 @@ pub(crate) struct CollapsibleWithParentStartMargin(bool);
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct OutsideMarker {
|
pub(crate) struct OutsideMarker {
|
||||||
pub marker_style: Arc<ComputedValues>,
|
pub marker_style: Arc<ComputedValues>,
|
||||||
|
pub list_item_style: Arc<ComputedValues>,
|
||||||
pub base: LayoutBoxBase,
|
pub base: LayoutBoxBase,
|
||||||
pub block_container: BlockContainer,
|
pub block_container: BlockContainer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OutsideMarker {
|
impl OutsideMarker {
|
||||||
fn list_item_style(&self) -> &ComputedValues {
|
|
||||||
&self.base.style
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inline_content_sizes(
|
fn inline_content_sizes(
|
||||||
&self,
|
&self,
|
||||||
layout_context: &LayoutContext,
|
layout_context: &LayoutContext,
|
||||||
|
@ -313,7 +310,7 @@ impl OutsideMarker {
|
||||||
// TODO: This should use the LayoutStyle of the list item, not the default one. Currently
|
// TODO: This should use the LayoutStyle of the list item, not the default one. Currently
|
||||||
// they are the same, but this could change in the future.
|
// they are the same, but this could change in the future.
|
||||||
let pbm_of_list_item =
|
let pbm_of_list_item =
|
||||||
LayoutStyle::Default(self.list_item_style()).padding_border_margin(containing_block);
|
LayoutStyle::Default(&self.list_item_style).padding_border_margin(containing_block);
|
||||||
let content_rect = LogicalRect {
|
let content_rect = LogicalRect {
|
||||||
start_corner: LogicalVec2 {
|
start_corner: LogicalVec2 {
|
||||||
inline: -max_inline_size -
|
inline: -max_inline_size -
|
||||||
|
|
|
@ -13,8 +13,8 @@ use style::selector_parser::PseudoElement;
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct BaseFragment {
|
pub(crate) struct BaseFragment {
|
||||||
/// A tag which identifies the DOM node and pseudo element of this
|
/// A tag which identifies the DOM node and pseudo element of this
|
||||||
/// Fragment's content. If this fragment isn't related to any DOM
|
/// Fragment's content. If this fragment is for an anonymous box,
|
||||||
/// node at all, the tag will be None.
|
/// the tag will be None.
|
||||||
pub tag: Option<Tag>,
|
pub tag: Option<Tag>,
|
||||||
|
|
||||||
/// Flags which various information about this fragment used during
|
/// Flags which various information about this fragment used during
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use log::warn;
|
|
||||||
use style::properties::longhands::list_style_type::computed_value::T as ListStyleType;
|
use style::properties::longhands::list_style_type::computed_value::T as ListStyleType;
|
||||||
use style::properties::style_structs;
|
use style::properties::style_structs;
|
||||||
use style::values::computed::Image;
|
use style::values::computed::Image;
|
||||||
|
@ -16,24 +15,25 @@ use crate::replaced::ReplacedContents;
|
||||||
pub(crate) fn make_marker<'dom, Node>(
|
pub(crate) fn make_marker<'dom, Node>(
|
||||||
context: &LayoutContext,
|
context: &LayoutContext,
|
||||||
info: &NodeAndStyleInfo<Node>,
|
info: &NodeAndStyleInfo<Node>,
|
||||||
) -> Option<Vec<PseudoElementContentItem>>
|
) -> Option<(NodeAndStyleInfo<Node>, Vec<PseudoElementContentItem>)>
|
||||||
where
|
where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
let style = info.style.get_list();
|
// TODO: use `PseudoElement::Marker` when we add it.
|
||||||
let node = match info.node {
|
let marker_info = info.pseudo(
|
||||||
Some(node) => node,
|
context,
|
||||||
None => {
|
style::selector_parser::PseudoElement::ServoLegacyText,
|
||||||
warn!("Tried to make a marker for an anonymous node!");
|
)?;
|
||||||
return None;
|
let style = &marker_info.style;
|
||||||
},
|
let list_style = style.get_list();
|
||||||
};
|
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-lists/#marker-image
|
// https://drafts.csswg.org/css-lists/#marker-image
|
||||||
let marker_image = || match &style.list_style_image {
|
let marker_image = || match &list_style.list_style_image {
|
||||||
Image::Url(url) => Some(vec![
|
Image::Url(url) => Some(vec![
|
||||||
PseudoElementContentItem::Replaced(ReplacedContents::from_image_url(
|
PseudoElementContentItem::Replaced(ReplacedContents::from_image_url(
|
||||||
node, context, url,
|
marker_info.node,
|
||||||
|
context,
|
||||||
|
url,
|
||||||
)?),
|
)?),
|
||||||
PseudoElementContentItem::Text(" ".into()),
|
PseudoElementContentItem::Text(" ".into()),
|
||||||
]),
|
]),
|
||||||
|
@ -44,11 +44,13 @@ where
|
||||||
Image::PaintWorklet(..) |
|
Image::PaintWorklet(..) |
|
||||||
Image::None => None,
|
Image::None => None,
|
||||||
};
|
};
|
||||||
marker_image().or_else(|| {
|
let content = marker_image().or_else(|| {
|
||||||
Some(vec![PseudoElementContentItem::Text(
|
Some(vec![PseudoElementContentItem::Text(
|
||||||
marker_string(style)?.into(),
|
marker_string(list_style)?.into(),
|
||||||
)])
|
)])
|
||||||
})
|
})?;
|
||||||
|
|
||||||
|
Some((marker_info, content))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-lists/#marker-string>
|
/// <https://drafts.csswg.org/css-lists/#marker-string>
|
||||||
|
|
|
@ -116,19 +116,19 @@ pub fn process_resolved_style_request<'dom>(
|
||||||
// We call process_resolved_style_request after performing a whole-document
|
// We call process_resolved_style_request after performing a whole-document
|
||||||
// traversal, so in the common case, the element is styled.
|
// traversal, so in the common case, the element is styled.
|
||||||
let layout_element = node.to_threadsafe().as_element().unwrap();
|
let layout_element = node.to_threadsafe().as_element().unwrap();
|
||||||
let layout_element = pseudo.map_or_else(
|
let layout_element = match pseudo {
|
||||||
|| Some(layout_element),
|
Some(pseudo_element_type) => {
|
||||||
|pseudo_element| layout_element.get_pseudo(pseudo_element),
|
match layout_element.with_pseudo(*pseudo_element_type) {
|
||||||
);
|
Some(layout_element) => layout_element,
|
||||||
|
None => {
|
||||||
let layout_element = match layout_element {
|
// The pseudo doesn't exist, return nothing. Chrome seems to query
|
||||||
None => {
|
// the element itself in this case, Firefox uses the resolved value.
|
||||||
// The pseudo doesn't exist, return nothing. Chrome seems to query
|
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=29006
|
||||||
// the element itself in this case, Firefox uses the resolved value.
|
return String::new();
|
||||||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=29006
|
},
|
||||||
return String::new();
|
}
|
||||||
},
|
},
|
||||||
Some(layout_element) => layout_element,
|
None => layout_element,
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = &*layout_element.resolved_style();
|
let style = &*layout_element.resolved_style();
|
||||||
|
|
|
@ -95,26 +95,16 @@ impl Table {
|
||||||
parent_info: &NodeAndStyleInfo<Node>,
|
parent_info: &NodeAndStyleInfo<Node>,
|
||||||
contents: Vec<AnonymousTableContent<'dom, Node>>,
|
contents: Vec<AnonymousTableContent<'dom, Node>>,
|
||||||
propagated_data: PropagatedBoxTreeData,
|
propagated_data: PropagatedBoxTreeData,
|
||||||
) -> IndependentFormattingContext
|
) -> (NodeAndStyleInfo<Node>, IndependentFormattingContext)
|
||||||
where
|
where
|
||||||
Node: crate::dom::NodeExt<'dom>,
|
Node: crate::dom::NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
let grid_and_wrapper_style = context
|
let table_info = parent_info
|
||||||
.shared_context()
|
.pseudo(context, PseudoElement::ServoAnonymousTable)
|
||||||
.stylist
|
.expect("Should never fail to create anonymous table info.");
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
let table_style = table_info.style.clone();
|
||||||
&context.shared_context().guards,
|
let mut table_builder =
|
||||||
&PseudoElement::ServoAnonymousTable,
|
TableBuilderTraversal::new(context, &table_info, table_style.clone(), propagated_data);
|
||||||
&parent_info.style,
|
|
||||||
);
|
|
||||||
let anonymous_info = parent_info.new_anonymous(grid_and_wrapper_style.clone());
|
|
||||||
|
|
||||||
let mut table_builder = TableBuilderTraversal::new(
|
|
||||||
context,
|
|
||||||
&anonymous_info,
|
|
||||||
grid_and_wrapper_style.clone(),
|
|
||||||
propagated_data,
|
|
||||||
);
|
|
||||||
|
|
||||||
for content in contents {
|
for content in contents {
|
||||||
match content {
|
match content {
|
||||||
|
@ -137,12 +127,14 @@ impl Table {
|
||||||
let mut table = table_builder.finish();
|
let mut table = table_builder.finish();
|
||||||
table.anonymous = true;
|
table.anonymous = true;
|
||||||
|
|
||||||
IndependentFormattingContext {
|
let ifc = IndependentFormattingContext {
|
||||||
base: LayoutBoxBase::new((&anonymous_info).into(), grid_and_wrapper_style),
|
base: LayoutBoxBase::new((&table_info).into(), table_style),
|
||||||
contents: IndependentFormattingContextContents::NonReplaced(
|
contents: IndependentFormattingContextContents::NonReplaced(
|
||||||
IndependentNonReplacedContents::Table(table),
|
IndependentNonReplacedContents::Table(table),
|
||||||
),
|
),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
(table_info, ifc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Push a new slot into the last row of this table.
|
/// Push a new slot into the last row of this table.
|
||||||
|
@ -686,17 +678,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
let row_content = std::mem::take(&mut self.current_anonymous_row_content);
|
let row_content = std::mem::take(&mut self.current_anonymous_row_content);
|
||||||
let context = self.context;
|
let anonymous_info = self
|
||||||
let anonymous_style = self
|
.info
|
||||||
.context
|
.pseudo(self.context, PseudoElement::ServoAnonymousTableRow)
|
||||||
.shared_context()
|
.expect("Should never fail to create anonymous row info.");
|
||||||
.stylist
|
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
|
||||||
&context.shared_context().guards,
|
|
||||||
&PseudoElement::ServoAnonymousTableRow,
|
|
||||||
&self.info.style,
|
|
||||||
);
|
|
||||||
let anonymous_info = self.info.new_anonymous(anonymous_style.clone());
|
|
||||||
let mut row_builder =
|
let mut row_builder =
|
||||||
TableRowBuilder::new(self, &anonymous_info, self.current_propagated_data);
|
TableRowBuilder::new(self, &anonymous_info, self.current_propagated_data);
|
||||||
|
|
||||||
|
@ -718,9 +703,10 @@ where
|
||||||
|
|
||||||
row_builder.finish();
|
row_builder.finish();
|
||||||
|
|
||||||
|
let style = anonymous_info.style.clone();
|
||||||
self.push_table_row(TableTrack {
|
self.push_table_row(TableTrack {
|
||||||
base_fragment_info: (&anonymous_info).into(),
|
base_fragment_info: (&anonymous_info).into(),
|
||||||
style: anonymous_style,
|
style,
|
||||||
group_index: self.current_row_group_index,
|
group_index: self.current_row_group_index,
|
||||||
is_anonymous: true,
|
is_anonymous: true,
|
||||||
});
|
});
|
||||||
|
@ -958,16 +944,10 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
let context = self.table_traversal.context;
|
let context = self.table_traversal.context;
|
||||||
let anonymous_style = context
|
let anonymous_info = self
|
||||||
.shared_context()
|
.info
|
||||||
.stylist
|
.pseudo(context, PseudoElement::ServoAnonymousTableCell)
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
.expect("Should never fail to create anonymous table cell info");
|
||||||
&context.shared_context().guards,
|
|
||||||
&PseudoElement::ServoAnonymousTableCell,
|
|
||||||
&self.info.style,
|
|
||||||
);
|
|
||||||
let anonymous_info = self.info.new_anonymous(anonymous_style);
|
|
||||||
|
|
||||||
let propagated_data = self.propagated_data.disallowing_percentage_table_columns();
|
let propagated_data = self.propagated_data.disallowing_percentage_table_columns();
|
||||||
let mut builder = BlockContainerBuilder::new(context, &anonymous_info, propagated_data);
|
let mut builder = BlockContainerBuilder::new(context, &anonymous_info, propagated_data);
|
||||||
|
|
||||||
|
@ -1025,12 +1005,14 @@ where
|
||||||
// 65534 and `colspan` to 1000, so we also enforce the same limits
|
// 65534 and `colspan` to 1000, so we also enforce the same limits
|
||||||
// when dealing with arbitrary DOM elements (perhaps created via
|
// when dealing with arbitrary DOM elements (perhaps created via
|
||||||
// script).
|
// script).
|
||||||
let (rowspan, colspan) = info.node.map_or((1, 1), |node| {
|
let (rowspan, colspan) = if info.pseudo_element_type.is_none() {
|
||||||
let node = node.to_threadsafe();
|
let node = info.node.to_threadsafe();
|
||||||
let rowspan = node.get_rowspan().unwrap_or(1).min(65534) as usize;
|
let rowspan = node.get_rowspan().unwrap_or(1).min(65534) as usize;
|
||||||
let colspan = node.get_colspan().unwrap_or(1).min(1000) as usize;
|
let colspan = node.get_colspan().unwrap_or(1).min(1000) as usize;
|
||||||
(rowspan, colspan)
|
(rowspan, colspan)
|
||||||
});
|
} else {
|
||||||
|
(1, 1)
|
||||||
|
};
|
||||||
|
|
||||||
let propagated_data =
|
let propagated_data =
|
||||||
self.propagated_data.disallowing_percentage_table_columns();
|
self.propagated_data.disallowing_percentage_table_columns();
|
||||||
|
@ -1139,10 +1121,16 @@ fn add_column<'dom, Node>(
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
let span = column_info
|
let span = if column_info.pseudo_element_type.is_none() {
|
||||||
.node
|
column_info
|
||||||
.and_then(|node| node.to_threadsafe().get_span())
|
.node
|
||||||
.map_or(1, |span| span.min(1000) as usize);
|
.to_threadsafe()
|
||||||
|
.get_span()
|
||||||
|
.unwrap_or(1)
|
||||||
|
.min(1000) as usize
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
};
|
||||||
|
|
||||||
collection.extend(
|
collection.extend(
|
||||||
repeat(TableTrack {
|
repeat(TableTrack {
|
||||||
|
|
|
@ -14,6 +14,7 @@ use script_layout_interface::wrapper_traits::{
|
||||||
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
|
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
|
||||||
};
|
};
|
||||||
use script_layout_interface::{LayoutNodeType, StyleData};
|
use script_layout_interface::{LayoutNodeType, StyleData};
|
||||||
|
use selectors::Element as _;
|
||||||
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
||||||
use selectors::bloom::{BLOOM_HASH_MASK, BloomFilter};
|
use selectors::bloom::{BLOOM_HASH_MASK, BloomFilter};
|
||||||
use selectors::matching::{ElementSelectorFlags, MatchingContext, VisitedHandlingMode};
|
use selectors::matching::{ElementSelectorFlags, MatchingContext, VisitedHandlingMode};
|
||||||
|
@ -805,11 +806,35 @@ impl<'dom> ThreadSafeLayoutElement<'dom> for ServoThreadSafeLayoutElement<'dom>
|
||||||
self.pseudo
|
self.pseudo
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_pseudo(&self, pseudo: PseudoElement) -> Self {
|
fn with_pseudo(&self, pseudo_element_type: PseudoElement) -> Option<Self> {
|
||||||
ServoThreadSafeLayoutElement {
|
if pseudo_element_type.is_eager() &&
|
||||||
element: self.element,
|
self.style_data()
|
||||||
pseudo: Some(pseudo),
|
.styles
|
||||||
|
.pseudos
|
||||||
|
.get(&pseudo_element_type)
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pseudo_element_type == PseudoElement::DetailsSummary &&
|
||||||
|
(!self.has_local_name(&local_name!("details")) || !self.has_namespace(&ns!(html)))
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if pseudo_element_type == PseudoElement::DetailsContent &&
|
||||||
|
(!self.has_local_name(&local_name!("details")) ||
|
||||||
|
!self.has_namespace(&ns!(html)) ||
|
||||||
|
self.get_attr(&ns!(), &local_name!("open")).is_none())
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(ServoThreadSafeLayoutElement {
|
||||||
|
element: self.element,
|
||||||
|
pseudo: Some(pseudo_element_type),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_id(&self) -> Option<LayoutNodeType> {
|
fn type_id(&self) -> Option<LayoutNodeType> {
|
||||||
|
|
|
@ -436,8 +436,8 @@ impl<'dom> ServoThreadSafeLayoutNodeChildrenIterator<'dom> {
|
||||||
pub fn new(parent: ServoThreadSafeLayoutNode<'dom>) -> Self {
|
pub fn new(parent: ServoThreadSafeLayoutNode<'dom>) -> Self {
|
||||||
let first_child = match parent.pseudo_element() {
|
let first_child = match parent.pseudo_element() {
|
||||||
None => parent
|
None => parent
|
||||||
.get_pseudo(PseudoElement::Before)
|
.with_pseudo(PseudoElement::Before)
|
||||||
.or_else(|| parent.get_details_summary_pseudo())
|
.or_else(|| parent.with_pseudo(PseudoElement::DetailsSummary))
|
||||||
.or_else(|| unsafe { parent.dangerous_first_child() }),
|
.or_else(|| unsafe { parent.dangerous_first_child() }),
|
||||||
Some(PseudoElement::DetailsContent) | Some(PseudoElement::DetailsSummary) => unsafe {
|
Some(PseudoElement::DetailsContent) | Some(PseudoElement::DetailsSummary) => unsafe {
|
||||||
parent.dangerous_first_child()
|
parent.dangerous_first_child()
|
||||||
|
@ -503,18 +503,18 @@ impl<'dom> Iterator for ServoThreadSafeLayoutNodeChildrenIterator<'dom> {
|
||||||
self.current_node = match node.pseudo_element() {
|
self.current_node = match node.pseudo_element() {
|
||||||
Some(PseudoElement::Before) => self
|
Some(PseudoElement::Before) => self
|
||||||
.parent_node
|
.parent_node
|
||||||
.get_details_summary_pseudo()
|
.with_pseudo(PseudoElement::DetailsSummary)
|
||||||
.or_else(|| unsafe { self.parent_node.dangerous_first_child() })
|
.or_else(|| unsafe { self.parent_node.dangerous_first_child() })
|
||||||
.or_else(|| self.parent_node.get_pseudo(PseudoElement::After)),
|
.or_else(|| self.parent_node.with_pseudo(PseudoElement::After)),
|
||||||
Some(PseudoElement::DetailsSummary) => {
|
Some(PseudoElement::DetailsSummary) => {
|
||||||
self.parent_node.get_details_content_pseudo()
|
self.parent_node.with_pseudo(PseudoElement::DetailsContent)
|
||||||
},
|
},
|
||||||
Some(PseudoElement::DetailsContent) => {
|
Some(PseudoElement::DetailsContent) => {
|
||||||
self.parent_node.get_pseudo(PseudoElement::After)
|
self.parent_node.with_pseudo(PseudoElement::After)
|
||||||
},
|
},
|
||||||
Some(PseudoElement::After) => None,
|
Some(PseudoElement::After) => None,
|
||||||
None | Some(_) => unsafe { node.dangerous_next_sibling() }
|
None | Some(_) => unsafe { node.dangerous_next_sibling() }
|
||||||
.or_else(|| self.parent_node.get_pseudo(PseudoElement::After)),
|
.or_else(|| self.parent_node.with_pseudo(PseudoElement::After)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
node
|
node
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::sync::Arc as StdArc;
|
||||||
use atomic_refcell::AtomicRef;
|
use atomic_refcell::AtomicRef;
|
||||||
use base::id::{BrowsingContextId, PipelineId};
|
use base::id::{BrowsingContextId, PipelineId};
|
||||||
use fonts_traits::ByteIndex;
|
use fonts_traits::ByteIndex;
|
||||||
use html5ever::{LocalName, Namespace, local_name, namespace_url, ns};
|
use html5ever::{LocalName, Namespace};
|
||||||
use pixels::{Image, ImageMetadata};
|
use pixels::{Image, ImageMetadata};
|
||||||
use range::Range;
|
use range::Range;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
|
@ -157,25 +157,6 @@ pub trait ThreadSafeLayoutNode<'dom>: Clone + Copy + Debug + NodeInfo + PartialE
|
||||||
/// the parent until all the children have been processed.
|
/// the parent until all the children have been processed.
|
||||||
fn parent_style(&self) -> Arc<ComputedValues>;
|
fn parent_style(&self) -> Arc<ComputedValues>;
|
||||||
|
|
||||||
fn get_pseudo(&self, pseudo_element: PseudoElement) -> Option<Self> {
|
|
||||||
self.as_element()
|
|
||||||
.and_then(|element| element.get_pseudo(pseudo_element))
|
|
||||||
.as_ref()
|
|
||||||
.map(ThreadSafeLayoutElement::as_node)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_details_summary_pseudo(&self) -> Option<Self> {
|
|
||||||
self.as_element()
|
|
||||||
.and_then(|el| el.get_details_summary_pseudo())
|
|
||||||
.map(|el| el.as_node())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_details_content_pseudo(&self) -> Option<Self> {
|
|
||||||
self.as_element()
|
|
||||||
.and_then(|el| el.get_details_content_pseudo())
|
|
||||||
.map(|el| el.as_node())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug_id(self) -> usize;
|
fn debug_id(self) -> usize;
|
||||||
|
|
||||||
/// Returns an iterator over this node's children.
|
/// Returns an iterator over this node's children.
|
||||||
|
@ -266,6 +247,13 @@ pub trait ThreadSafeLayoutNode<'dom>: Clone + Copy + Debug + NodeInfo + PartialE
|
||||||
fn fragment_type(&self) -> FragmentType {
|
fn fragment_type(&self) -> FragmentType {
|
||||||
self.pseudo_element().into()
|
self.pseudo_element().into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn with_pseudo(&self, pseudo_element_type: PseudoElement) -> Option<Self> {
|
||||||
|
self.as_element()
|
||||||
|
.and_then(|element| element.with_pseudo(pseudo_element_type))
|
||||||
|
.as_ref()
|
||||||
|
.map(ThreadSafeLayoutElement::as_node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ThreadSafeLayoutElement<'dom>:
|
pub trait ThreadSafeLayoutElement<'dom>:
|
||||||
|
@ -283,7 +271,16 @@ pub trait ThreadSafeLayoutElement<'dom>:
|
||||||
|
|
||||||
/// Creates a new `ThreadSafeLayoutElement` for the same `LayoutElement`
|
/// Creates a new `ThreadSafeLayoutElement` for the same `LayoutElement`
|
||||||
/// with a different pseudo-element type.
|
/// with a different pseudo-element type.
|
||||||
fn with_pseudo(&self, pseudo: PseudoElement) -> Self;
|
///
|
||||||
|
/// Returns `None` if this pseudo doesn't apply to the given element for one of
|
||||||
|
/// the following reasons:
|
||||||
|
///
|
||||||
|
/// 1. `pseudo` is eager and is not defined in the stylesheet. In this case, there
|
||||||
|
/// is not reason to process the pseudo element at all.
|
||||||
|
/// 2. `pseudo` is for `::servo-details-summary` or `::servo-details-content` and
|
||||||
|
/// it doesn't apply to this element, either because it isn't a details or is
|
||||||
|
/// in the wrong state.
|
||||||
|
fn with_pseudo(&self, pseudo: PseudoElement) -> Option<Self>;
|
||||||
|
|
||||||
/// Returns the type ID of this node.
|
/// Returns the type ID of this node.
|
||||||
/// Returns `None` if this is a pseudo-element; otherwise, returns `Some`.
|
/// Returns `None` if this is a pseudo-element; otherwise, returns `Some`.
|
||||||
|
@ -309,42 +306,6 @@ pub trait ThreadSafeLayoutElement<'dom>:
|
||||||
|
|
||||||
fn pseudo_element(&self) -> Option<PseudoElement>;
|
fn pseudo_element(&self) -> Option<PseudoElement>;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn get_pseudo(&self, pseudo_element: PseudoElement) -> Option<Self> {
|
|
||||||
if self
|
|
||||||
.style_data()
|
|
||||||
.styles
|
|
||||||
.pseudos
|
|
||||||
.get(&pseudo_element)
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
Some(self.with_pseudo(pseudo_element))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn get_details_summary_pseudo(&self) -> Option<Self> {
|
|
||||||
if self.has_local_name(&local_name!("details")) && self.has_namespace(&ns!(html)) {
|
|
||||||
Some(self.with_pseudo(PseudoElement::DetailsSummary))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn get_details_content_pseudo(&self) -> Option<Self> {
|
|
||||||
if self.has_local_name(&local_name!("details")) &&
|
|
||||||
self.has_namespace(&ns!(html)) &&
|
|
||||||
self.get_attr(&ns!(), &local_name!("open")).is_some()
|
|
||||||
{
|
|
||||||
Some(self.with_pseudo(PseudoElement::DetailsContent))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the style results for the given node. If CSS selector matching
|
/// Returns the style results for the given node. If CSS selector matching
|
||||||
/// has not yet been performed, fails.
|
/// has not yet been performed, fails.
|
||||||
///
|
///
|
||||||
|
|
|
@ -202,6 +202,8 @@ svg > * {
|
||||||
*|*::-servo-legacy-text {
|
*|*::-servo-legacy-text {
|
||||||
text-overflow: inherit;
|
text-overflow: inherit;
|
||||||
overflow: inherit;
|
overflow: inherit;
|
||||||
|
padding: unset;
|
||||||
|
margin: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
*|*::-servo-legacy-table-wrapper {
|
*|*::-servo-legacy-table-wrapper {
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
[elementFromPoint-list-001.html]
|
|
||||||
[<li>Image Outside 2</li>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[<li>Outside 2</li>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[<li>Image Outside 1</li>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[<li>Outside 3</li>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[<li>Outside 1</li>]
|
|
||||||
expected: FAIL
|
|
|
@ -1,3 +0,0 @@
|
||||||
[intersection-ratio-with-fractional-bounds-2.html]
|
|
||||||
[IntersectionObserver ratio with fractional bounds]
|
|
||||||
expected: FAIL
|
|
Loading…
Add table
Add a link
Reference in a new issue