diff options
author | Anthony Ramine <nox@nox.paris> | 2019-10-03 18:08:16 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2019-10-04 10:03:42 +0200 |
commit | ec74204fa0719856069770ac05c5aa7ac90cc4b2 (patch) | |
tree | 281eb4320a84c78b5d0aba3dc1a50cabfd0c73d5 | |
parent | 9706cd497da0fcc30c9af04b7d3dc0d4e9d7c8fb (diff) | |
download | servo-ec74204fa0719856069770ac05c5aa7ac90cc4b2.tar.gz servo-ec74204fa0719856069770ac05c5aa7ac90cc4b2.zip |
Call BoxTreeRoot::construct from layout_thread_2020
-rw-r--r-- | components/layout_2020/dom_traversal.rs | 10 | ||||
-rw-r--r-- | components/layout_2020/element_data.rs | 4 | ||||
-rw-r--r-- | components/layout_2020/flow/construct.rs | 4 | ||||
-rw-r--r-- | components/layout_2020/flow/float.rs | 2 | ||||
-rw-r--r-- | components/layout_2020/flow/inline.rs | 8 | ||||
-rw-r--r-- | components/layout_2020/flow/mod.rs | 8 | ||||
-rw-r--r-- | components/layout_2020/flow/root.rs | 13 | ||||
-rw-r--r-- | components/layout_2020/lib.rs | 23 | ||||
-rw-r--r-- | components/layout_2020/positioned.rs | 2 | ||||
-rw-r--r-- | components/layout_2020/replaced.rs | 2 | ||||
-rw-r--r-- | components/layout_thread_2020/dom_wrapper.rs | 7 | ||||
-rw-r--r-- | components/layout_thread_2020/lib.rs | 10 |
12 files changed, 51 insertions, 42 deletions
diff --git a/components/layout_2020/dom_traversal.rs b/components/layout_2020/dom_traversal.rs index c1ac55c2bfb..528c2b49271 100644 --- a/components/layout_2020/dom_traversal.rs +++ b/components/layout_2020/dom_traversal.rs @@ -17,7 +17,7 @@ use style::properties::ComputedValues; use style::selector_parser::PseudoElement; #[derive(Clone, Copy)] -pub(super) enum WhichPseudoElement { +pub enum WhichPseudoElement { Before, After, } @@ -35,12 +35,12 @@ pub(super) enum Contents<Node> { OfPseudoElement(Vec<PseudoElementContentItem>), } -pub(super) enum NonReplacedContents<Node> { +pub enum NonReplacedContents<Node> { OfElement(Node), OfPseudoElement(Vec<PseudoElementContentItem>), } -pub(super) enum PseudoElementContentItem { +pub enum PseudoElementContentItem { Text(String), Replaced(ReplacedContent), } @@ -252,7 +252,7 @@ where unimplemented!() } -pub(super) struct BoxSlot<'dom> { +pub struct BoxSlot<'dom> { slot: Option<Arc<AtomicRefCell<Option<LayoutBox>>>>, marker: marker<&'dom ()>, } @@ -284,7 +284,7 @@ impl Drop for BoxSlot<'_> { } } -pub(crate) trait NodeExt<'dom>: 'dom + Copy + LayoutNode + Send + Sync { +pub trait NodeExt<'dom>: 'dom + Copy + LayoutNode + Send + Sync { fn is_element(self) -> bool; fn as_text(self) -> Option<String>; fn first_child(self) -> Option<Self>; diff --git a/components/layout_2020/element_data.rs b/components/layout_2020/element_data.rs index fdf611a76c7..5cedbf65f1b 100644 --- a/components/layout_2020/element_data.rs +++ b/components/layout_2020/element_data.rs @@ -8,7 +8,7 @@ use atomic_refcell::AtomicRefCell; use servo_arc::Arc; #[derive(Default)] -pub(crate) struct LayoutDataForElement { +pub struct LayoutDataForElement { pub(super) self_box: Arc<AtomicRefCell<Option<LayoutBox>>>, pub(super) pseudo_elements: Option<Box<PseudoElementBoxes>>, } @@ -19,7 +19,7 @@ pub(super) struct PseudoElementBoxes { pub after: Arc<AtomicRefCell<Option<LayoutBox>>>, } -pub(super) enum LayoutBox { +pub enum LayoutBox { DisplayContents, BlockLevel(Arc<BlockLevelBox>), InlineLevel(Arc<InlineLevelBox>), diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs index 6b2027a8794..abdfae0bc84 100644 --- a/components/layout_2020/flow/construct.rs +++ b/components/layout_2020/flow/construct.rs @@ -123,7 +123,7 @@ struct BlockContainerBuilder<'dom, 'style, Node> { } impl BlockContainer { - pub fn construct<'dom, 'style>( + pub(crate) fn construct<'dom, 'style>( context: &SharedStyleContext<'style>, block_container_style: &Arc<ComputedValues>, contents: NonReplacedContents<impl NodeExt<'dom>>, @@ -646,7 +646,7 @@ where } #[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub(crate) enum ContainsFloats { +pub enum ContainsFloats { No, Yes, } diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs index 31fec0b79c0..4a7a4bb31c4 100644 --- a/components/layout_2020/flow/float.rs +++ b/components/layout_2020/flow/float.rs @@ -7,7 +7,7 @@ use servo_arc::Arc; use style::properties::ComputedValues; #[derive(Debug)] -pub(crate) struct FloatBox { +pub struct FloatBox { pub style: Arc<ComputedValues>, pub contents: IndependentFormattingContext, } diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs index 59b822976ca..1334560b337 100644 --- a/components/layout_2020/flow/inline.rs +++ b/components/layout_2020/flow/inline.rs @@ -16,12 +16,12 @@ use style::values::computed::Length; use style::Zero; #[derive(Debug, Default)] -pub(crate) struct InlineFormattingContext { +pub struct InlineFormattingContext { pub(super) inline_level_boxes: Vec<Arc<InlineLevelBox>>, } #[derive(Debug)] -pub(crate) enum InlineLevelBox { +pub enum InlineLevelBox { InlineBox(InlineBox), TextRun(TextRun), OutOfFlowAbsolutelyPositionedBox(AbsolutelyPositionedBox), @@ -34,7 +34,7 @@ pub(crate) enum InlineLevelBox { } #[derive(Debug)] -pub(crate) struct InlineBox { +pub struct InlineBox { pub style: Arc<ComputedValues>, pub first_fragment: bool, pub last_fragment: bool, @@ -43,7 +43,7 @@ pub(crate) struct InlineBox { /// https://www.w3.org/TR/css-display-3/#css-text-run #[derive(Debug)] -pub(crate) struct TextRun { +pub struct TextRun { pub parent_style: Arc<ComputedValues>, pub text: String, } diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index ae92f70822c..a68eaff563e 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -25,22 +25,22 @@ use style::Zero; mod construct; mod float; pub mod inline; -mod root; +pub mod root; #[derive(Debug)] -pub(crate) struct BlockFormattingContext { +pub struct BlockFormattingContext { pub contents: BlockContainer, pub contains_floats: bool, } #[derive(Debug)] -pub(crate) enum BlockContainer { +pub enum BlockContainer { BlockLevelBoxes(Vec<Arc<BlockLevelBox>>), InlineFormattingContext(InlineFormattingContext), } #[derive(Debug)] -pub(crate) enum BlockLevelBox { +pub enum BlockLevelBox { SameFormattingContextBlock { style: Arc<ComputedValues>, contents: BlockContainer, diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index b1a43ae28be..2a0d1f66be0 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -22,17 +22,8 @@ use style::properties::ComputedValues; use style::values::computed::{Length, LengthOrAuto}; use style_traits::CSSPixel; -// FIXME -// impl crate::dom::Document { -// pub(crate) fn layout( -// &self, -// viewport: crate::geom::Size<crate::geom::CssPx>, -// ) -> Vec<Fragment> { -// BoxTreeRoot::construct(self).layout(viewport) -// } -// } - -struct BoxTreeRoot(BlockFormattingContext); +#[derive(Debug)] +pub struct BoxTreeRoot(BlockFormattingContext); impl BoxTreeRoot { pub fn construct<'dom>( diff --git a/components/layout_2020/lib.rs b/components/layout_2020/lib.rs index 05a5caa9771..33d46f75fa1 100644 --- a/components/layout_2020/lib.rs +++ b/components/layout_2020/lib.rs @@ -11,8 +11,18 @@ #[macro_use] extern crate serde; +use crate::dom_traversal::{Contents, NodeExt}; +use crate::flow::{BlockFormattingContext, FlowChildren}; +use crate::geom::flow_relative::Vec2; +use crate::positioned::AbsolutelyPositionedFragment; +use crate::replaced::ReplacedContent; +use crate::style_ext::{ComputedValuesExt, Direction, Position, WritingMode}; +use servo_arc::Arc; +use std::convert::TryInto; +use style::context::SharedStyleContext; use style::properties::ComputedValues; use style::values::computed::{Length, LengthOrAuto}; +use style::values::specified::box_::DisplayInside; use style::Zero; pub mod context; @@ -30,20 +40,11 @@ pub mod style_ext; pub mod traversal; pub mod wrapper; -use crate::dom_traversal::{Contents, NodeExt}; -use crate::flow::{BlockFormattingContext, FlowChildren}; -use crate::geom::flow_relative::Vec2; -use crate::positioned::AbsolutelyPositionedFragment; -use crate::replaced::ReplacedContent; -use crate::style_ext::{ComputedValuesExt, Direction, Position, WritingMode}; -use servo_arc::Arc; -use std::convert::TryInto; -use style::context::SharedStyleContext; -use style::values::specified::box_::DisplayInside; +pub use crate::flow::root::BoxTreeRoot; /// https://drafts.csswg.org/css-display/#independent-formatting-context #[derive(Debug)] -enum IndependentFormattingContext { +pub enum IndependentFormattingContext { Flow(BlockFormattingContext), // Not called FC in specs, but behaves close enough diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index 55888fb8842..06da2a9fc0e 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -13,7 +13,7 @@ use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPerc use style::Zero; #[derive(Debug)] -pub(crate) struct AbsolutelyPositionedBox { +pub struct AbsolutelyPositionedBox { pub style: Arc<ComputedValues>, pub contents: IndependentFormattingContext, } diff --git a/components/layout_2020/replaced.rs b/components/layout_2020/replaced.rs index 04defc26b02..c67acd1b8ad 100644 --- a/components/layout_2020/replaced.rs +++ b/components/layout_2020/replaced.rs @@ -6,7 +6,7 @@ use crate::dom_traversal::NodeExt; use style::context::SharedStyleContext; #[derive(Debug)] -pub(super) enum ReplacedContent { +pub enum ReplacedContent { // Not implemented yet } diff --git a/components/layout_thread_2020/dom_wrapper.rs b/components/layout_thread_2020/dom_wrapper.rs index 5d815517532..a9f09e11073 100644 --- a/components/layout_thread_2020/dom_wrapper.rs +++ b/components/layout_thread_2020/dom_wrapper.rs @@ -109,6 +109,13 @@ pub struct ServoLayoutNode<'a> { chain: PhantomData<&'a ()>, } +// Those are supposed to be sound, but they aren't because the entire system +// between script and layout so far has been designed to work around their +// absence. Switching the entire thing to the inert crate infra will help. + +unsafe impl Send for ServoLayoutNode<'_> {} +unsafe impl Sync for ServoLayoutNode<'_> {} + impl<'ln> Debug for ServoLayoutNode<'ln> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(el) = self.as_element() { diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index 5855dea84cf..13f6fc79dce 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -45,6 +45,7 @@ use layout::query::{ process_text_index_request, }; use layout::traversal::RecalcStyle; +use layout::BoxTreeRoot; use layout_traits::LayoutThreadFactory; use libc::c_void; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; @@ -166,6 +167,9 @@ pub struct LayoutThread { /// The number of Web fonts that have been requested but not yet loaded. outstanding_web_fonts: Arc<AtomicUsize>, + /// The root box tree. + box_tree_root: RefCell<Option<BoxTreeRoot>>, + /// The document-specific shared lock used for author-origin stylesheets document_shared_lock: Option<SharedRwLock>, @@ -492,6 +496,7 @@ impl LayoutThread { new_animations_sender: new_animations_sender, _new_animations_receiver: new_animations_receiver, outstanding_web_fonts: Arc::new(AtomicUsize::new(0)), + box_tree_root: Default::default(), document_shared_lock: None, epoch: Cell::new(Epoch(0)), viewport_size: Size2D::new(Au(0), Au(0)), @@ -1075,6 +1080,11 @@ impl LayoutThread { if token.should_traverse() { driver::traverse_dom(&traversal, token, None); + + let shared = DomTraversal::<ServoLayoutElement>::shared_context(&traversal); + let box_tree = + BoxTreeRoot::construct(shared, document.root_element().unwrap().as_node()); + *self.box_tree_root.borrow_mut() = Some(box_tree); } for element in elements_with_snapshot { |