mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Pass a LayoutContext through box construction
This commit is contained in:
parent
9c5a595044
commit
4e6e31a76c
6 changed files with 34 additions and 31 deletions
|
@ -2,6 +2,7 @@
|
||||||
* 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 crate::context::LayoutContext;
|
||||||
use crate::element_data::{LayoutBox, LayoutDataForElement};
|
use crate::element_data::{LayoutBox, LayoutDataForElement};
|
||||||
use crate::geom::physical::Vec2;
|
use crate::geom::physical::Vec2;
|
||||||
use crate::replaced::ReplacedContent;
|
use crate::replaced::ReplacedContent;
|
||||||
|
@ -13,7 +14,6 @@ use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
|
||||||
use servo_arc::Arc as ServoArc;
|
use servo_arc::Arc as ServoArc;
|
||||||
use std::marker::PhantomData as marker;
|
use std::marker::PhantomData as marker;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::context::SharedStyleContext;
|
|
||||||
use style::dom::TNode;
|
use style::dom::TNode;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
use style::selector_parser::PseudoElement;
|
use style::selector_parser::PseudoElement;
|
||||||
|
@ -66,7 +66,7 @@ where
|
||||||
|
|
||||||
fn traverse_children_of<'dom, Node>(
|
fn traverse_children_of<'dom, Node>(
|
||||||
parent_element: Node,
|
parent_element: Node,
|
||||||
context: &SharedStyleContext,
|
context: &LayoutContext,
|
||||||
handler: &mut impl TraversalHandler<'dom, Node>,
|
handler: &mut impl TraversalHandler<'dom, Node>,
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
|
@ -88,7 +88,7 @@ fn traverse_children_of<'dom, Node>(
|
||||||
|
|
||||||
fn traverse_element<'dom, Node>(
|
fn traverse_element<'dom, Node>(
|
||||||
element: Node,
|
element: Node,
|
||||||
context: &SharedStyleContext,
|
context: &LayoutContext,
|
||||||
handler: &mut impl TraversalHandler<'dom, Node>,
|
handler: &mut impl TraversalHandler<'dom, Node>,
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
|
@ -121,7 +121,7 @@ fn traverse_element<'dom, Node>(
|
||||||
fn traverse_pseudo_element<'dom, Node>(
|
fn traverse_pseudo_element<'dom, Node>(
|
||||||
which: WhichPseudoElement,
|
which: WhichPseudoElement,
|
||||||
element: Node,
|
element: Node,
|
||||||
context: &SharedStyleContext,
|
context: &LayoutContext,
|
||||||
handler: &mut impl TraversalHandler<'dom, Node>,
|
handler: &mut impl TraversalHandler<'dom, Node>,
|
||||||
) where
|
) where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
|
@ -146,7 +146,7 @@ fn traverse_pseudo_element<'dom, Node>(
|
||||||
|
|
||||||
fn traverse_pseudo_element_contents<'dom, Node>(
|
fn traverse_pseudo_element_contents<'dom, Node>(
|
||||||
pseudo_element_style: &ServoArc<ComputedValues>,
|
pseudo_element_style: &ServoArc<ComputedValues>,
|
||||||
context: &SharedStyleContext,
|
context: &LayoutContext,
|
||||||
handler: &mut impl TraversalHandler<'dom, Node>,
|
handler: &mut impl TraversalHandler<'dom, Node>,
|
||||||
items: Vec<PseudoElementContentItem>,
|
items: Vec<PseudoElementContentItem>,
|
||||||
) where
|
) where
|
||||||
|
@ -159,9 +159,10 @@ fn traverse_pseudo_element_contents<'dom, Node>(
|
||||||
PseudoElementContentItem::Replaced(contents) => {
|
PseudoElementContentItem::Replaced(contents) => {
|
||||||
let item_style = anonymous_style.get_or_insert_with(|| {
|
let item_style = anonymous_style.get_or_insert_with(|| {
|
||||||
context
|
context
|
||||||
|
.shared_context()
|
||||||
.stylist
|
.stylist
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
.style_for_anonymous::<Node::ConcreteElement>(
|
||||||
&context.guards,
|
&context.shared_context().guards,
|
||||||
&PseudoElement::ServoText,
|
&PseudoElement::ServoText,
|
||||||
&pseudo_element_style,
|
&pseudo_element_style,
|
||||||
)
|
)
|
||||||
|
@ -215,7 +216,7 @@ where
|
||||||
pub(crate) fn traverse(
|
pub(crate) fn traverse(
|
||||||
self,
|
self,
|
||||||
inherited_style: &ServoArc<ComputedValues>,
|
inherited_style: &ServoArc<ComputedValues>,
|
||||||
context: &SharedStyleContext,
|
context: &LayoutContext,
|
||||||
handler: &mut impl TraversalHandler<'dom, Node>,
|
handler: &mut impl TraversalHandler<'dom, Node>,
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
|
@ -230,7 +231,7 @@ where
|
||||||
fn pseudo_element_style<'dom, Node>(
|
fn pseudo_element_style<'dom, Node>(
|
||||||
_which: WhichPseudoElement,
|
_which: WhichPseudoElement,
|
||||||
_element: Node,
|
_element: Node,
|
||||||
_context: &SharedStyleContext,
|
_context: &LayoutContext,
|
||||||
) -> Option<ServoArc<ComputedValues>>
|
) -> Option<ServoArc<ComputedValues>>
|
||||||
where
|
where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
|
@ -243,7 +244,7 @@ where
|
||||||
fn generate_pseudo_element_content<'dom, Node>(
|
fn generate_pseudo_element_content<'dom, Node>(
|
||||||
_pseudo_element_style: &ComputedValues,
|
_pseudo_element_style: &ComputedValues,
|
||||||
_element: Node,
|
_element: Node,
|
||||||
_context: &SharedStyleContext,
|
_context: &LayoutContext,
|
||||||
) -> Vec<PseudoElementContentItem>
|
) -> Vec<PseudoElementContentItem>
|
||||||
where
|
where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
|
@ -292,7 +293,7 @@ pub(crate) trait NodeExt<'dom>: 'dom + Copy + LayoutNode + Send + Sync {
|
||||||
fn first_child(self) -> Option<Self>;
|
fn first_child(self) -> Option<Self>;
|
||||||
fn next_sibling(self) -> Option<Self>;
|
fn next_sibling(self) -> Option<Self>;
|
||||||
fn parent_node(self) -> Option<Self>;
|
fn parent_node(self) -> Option<Self>;
|
||||||
fn style(self, context: &SharedStyleContext) -> ServoArc<ComputedValues>;
|
fn style(self, context: &LayoutContext) -> ServoArc<ComputedValues>;
|
||||||
|
|
||||||
fn layout_data_mut(&self) -> AtomicRefMut<LayoutDataForElement>;
|
fn layout_data_mut(&self) -> AtomicRefMut<LayoutDataForElement>;
|
||||||
fn element_box_slot(&self) -> BoxSlot<'dom>;
|
fn element_box_slot(&self) -> BoxSlot<'dom>;
|
||||||
|
@ -349,8 +350,8 @@ where
|
||||||
TNode::parent_node(&self)
|
TNode::parent_node(&self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn style(self, context: &SharedStyleContext) -> ServoArc<ComputedValues> {
|
fn style(self, context: &LayoutContext) -> ServoArc<ComputedValues> {
|
||||||
self.to_threadsafe().style(context)
|
self.to_threadsafe().style(context.shared_context())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_data_mut(&self) -> AtomicRefMut<LayoutDataForElement> {
|
fn layout_data_mut(&self) -> AtomicRefMut<LayoutDataForElement> {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* 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 crate::context::LayoutContext;
|
||||||
use crate::dom_traversal::{BoxSlot, Contents, NodeExt, NonReplacedContents, TraversalHandler};
|
use crate::dom_traversal::{BoxSlot, Contents, NodeExt, NonReplacedContents, TraversalHandler};
|
||||||
use crate::element_data::LayoutBox;
|
use crate::element_data::LayoutBox;
|
||||||
use crate::flow::float::FloatBox;
|
use crate::flow::float::FloatBox;
|
||||||
|
@ -14,13 +15,12 @@ use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
use rayon_croissant::ParallelIteratorExt;
|
use rayon_croissant::ParallelIteratorExt;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use style::context::SharedStyleContext;
|
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
use style::selector_parser::PseudoElement;
|
use style::selector_parser::PseudoElement;
|
||||||
|
|
||||||
impl BlockFormattingContext {
|
impl BlockFormattingContext {
|
||||||
pub fn construct<'dom>(
|
pub fn construct<'dom>(
|
||||||
context: &SharedStyleContext<'_>,
|
context: &LayoutContext,
|
||||||
style: &Arc<ComputedValues>,
|
style: &Arc<ComputedValues>,
|
||||||
contents: NonReplacedContents<impl NodeExt<'dom>>,
|
contents: NonReplacedContents<impl NodeExt<'dom>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -71,7 +71,7 @@ enum IntermediateBlockContainer<Node> {
|
||||||
/// This builder starts from the first child of a given DOM node
|
/// This builder starts from the first child of a given DOM node
|
||||||
/// and does a preorder traversal of all of its inclusive siblings.
|
/// and does a preorder traversal of all of its inclusive siblings.
|
||||||
struct BlockContainerBuilder<'dom, 'style, Node> {
|
struct BlockContainerBuilder<'dom, 'style, Node> {
|
||||||
context: &'style SharedStyleContext<'style>,
|
context: &'style LayoutContext<'style>,
|
||||||
|
|
||||||
block_container_style: &'style Arc<ComputedValues>,
|
block_container_style: &'style Arc<ComputedValues>,
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ struct BlockContainerBuilder<'dom, 'style, Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockContainer {
|
impl BlockContainer {
|
||||||
pub fn construct<'dom, 'style>(
|
pub fn construct<'dom>(
|
||||||
context: &SharedStyleContext<'style>,
|
context: &LayoutContext,
|
||||||
block_container_style: &Arc<ComputedValues>,
|
block_container_style: &Arc<ComputedValues>,
|
||||||
contents: NonReplacedContents<impl NodeExt<'dom>>,
|
contents: NonReplacedContents<impl NodeExt<'dom>>,
|
||||||
//intrinsic_sizes_requested: bool,
|
//intrinsic_sizes_requested: bool,
|
||||||
|
@ -510,9 +510,10 @@ where
|
||||||
let block_container_style = self.block_container_style;
|
let block_container_style = self.block_container_style;
|
||||||
let anonymous_style = self.anonymous_style.get_or_insert_with(|| {
|
let anonymous_style = self.anonymous_style.get_or_insert_with(|| {
|
||||||
context
|
context
|
||||||
|
.shared_context()
|
||||||
.stylist
|
.stylist
|
||||||
.style_for_anonymous::<Node::ConcreteElement>(
|
.style_for_anonymous::<Node::ConcreteElement>(
|
||||||
&context.guards,
|
&context.shared_context().guards,
|
||||||
&PseudoElement::ServoText,
|
&PseudoElement::ServoText,
|
||||||
&block_container_style,
|
&block_container_style,
|
||||||
)
|
)
|
||||||
|
@ -547,9 +548,9 @@ impl<'dom, Node> IntermediateBlockLevelBox<Node>
|
||||||
where
|
where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
fn finish<'style>(
|
fn finish(
|
||||||
self,
|
self,
|
||||||
context: &SharedStyleContext<'style>,
|
context: &LayoutContext,
|
||||||
) -> (Arc<BlockLevelBox>, ContainsFloats) {
|
) -> (Arc<BlockLevelBox>, ContainsFloats) {
|
||||||
match self {
|
match self {
|
||||||
IntermediateBlockLevelBox::SameFormattingContextBlock { style, contents } => {
|
IntermediateBlockLevelBox::SameFormattingContextBlock { style, contents } => {
|
||||||
|
@ -614,9 +615,9 @@ impl<'dom, Node> IntermediateBlockContainer<Node>
|
||||||
where
|
where
|
||||||
Node: NodeExt<'dom>,
|
Node: NodeExt<'dom>,
|
||||||
{
|
{
|
||||||
fn finish<'style>(
|
fn finish(
|
||||||
self,
|
self,
|
||||||
context: &SharedStyleContext<'style>,
|
context: &LayoutContext,
|
||||||
style: &Arc<ComputedValues>,
|
style: &Arc<ComputedValues>,
|
||||||
) -> (BlockContainer, ContainsFloats) {
|
) -> (BlockContainer, ContainsFloats) {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -19,7 +19,6 @@ use crate::{ContainingBlock, DefiniteContainingBlock};
|
||||||
use rayon::iter::{IntoParallelRefIterator, ParallelExtend, ParallelIterator};
|
use rayon::iter::{IntoParallelRefIterator, ParallelExtend, ParallelIterator};
|
||||||
use script_layout_interface::wrapper_traits::LayoutNode;
|
use script_layout_interface::wrapper_traits::LayoutNode;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use style::context::SharedStyleContext;
|
|
||||||
use style::values::computed::{Length, LengthOrAuto};
|
use style::values::computed::{Length, LengthOrAuto};
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
use style_traits::CSSPixel;
|
use style_traits::CSSPixel;
|
||||||
|
@ -28,7 +27,7 @@ pub struct BoxTreeRoot(BlockFormattingContext);
|
||||||
pub struct FragmentTreeRoot(Vec<Fragment>);
|
pub struct FragmentTreeRoot(Vec<Fragment>);
|
||||||
|
|
||||||
impl BoxTreeRoot {
|
impl BoxTreeRoot {
|
||||||
pub fn construct<'dom, Node>(context: &SharedStyleContext<'_>, root_element: Node) -> Self
|
pub fn construct<'dom, Node>(context: &LayoutContext, root_element: Node) -> Self
|
||||||
where
|
where
|
||||||
Node: 'dom + Copy + LayoutNode + Send + Sync,
|
Node: 'dom + Copy + LayoutNode + Send + Sync,
|
||||||
{
|
{
|
||||||
|
@ -41,7 +40,7 @@ impl BoxTreeRoot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_for_root_element<'dom>(
|
fn construct_for_root_element<'dom>(
|
||||||
context: &SharedStyleContext<'_>,
|
context: &LayoutContext,
|
||||||
root_element: impl NodeExt<'dom>,
|
root_element: impl NodeExt<'dom>,
|
||||||
) -> (ContainsFloats, Vec<Arc<BlockLevelBox>>) {
|
) -> (ContainsFloats, Vec<Arc<BlockLevelBox>>) {
|
||||||
let style = root_element.style(context);
|
let style = root_element.style(context);
|
||||||
|
|
|
@ -12,7 +12,6 @@ use crate::style_ext::DisplayInside;
|
||||||
use crate::ContainingBlock;
|
use crate::ContainingBlock;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use style::context::SharedStyleContext;
|
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
use style::values::computed::Length;
|
use style::values::computed::Length;
|
||||||
|
|
||||||
|
@ -46,8 +45,8 @@ enum NonReplacedIFCKind<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndependentFormattingContext {
|
impl IndependentFormattingContext {
|
||||||
pub fn construct<'dom, 'style>(
|
pub fn construct<'dom>(
|
||||||
context: &SharedStyleContext<'style>,
|
context: &LayoutContext,
|
||||||
style: Arc<ComputedValues>,
|
style: Arc<ComputedValues>,
|
||||||
display_inside: DisplayInside,
|
display_inside: DisplayInside,
|
||||||
contents: Contents<impl NodeExt<'dom>>,
|
contents: Contents<impl NodeExt<'dom>>,
|
||||||
|
|
|
@ -20,6 +20,10 @@ impl<'a> RecalcStyle<'a> {
|
||||||
RecalcStyle { context: context }
|
RecalcStyle { context: context }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn context(&self) -> &LayoutContext<'a> {
|
||||||
|
&self.context
|
||||||
|
}
|
||||||
|
|
||||||
pub fn destroy(self) -> LayoutContext<'a> {
|
pub fn destroy(self) -> LayoutContext<'a> {
|
||||||
self.context
|
self.context
|
||||||
}
|
}
|
||||||
|
|
|
@ -1081,9 +1081,8 @@ impl LayoutThread {
|
||||||
let box_tree = if token.should_traverse() {
|
let box_tree = if token.should_traverse() {
|
||||||
driver::traverse_dom(&traversal, token, Some(rayon_pool));
|
driver::traverse_dom(&traversal, token, Some(rayon_pool));
|
||||||
|
|
||||||
let shared = DomTraversal::<ServoLayoutElement>::shared_context(&traversal);
|
|
||||||
let root_node = document.root_element().unwrap().as_node();
|
let root_node = document.root_element().unwrap().as_node();
|
||||||
let box_tree = rayon_pool.install(|| BoxTreeRoot::construct(shared, root_node));
|
let box_tree = rayon_pool.install(|| BoxTreeRoot::construct(traversal.context(), root_node));
|
||||||
Some(box_tree)
|
Some(box_tree)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue