mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Call BoxTreeRoot::construct from layout_thread_2020
This commit is contained in:
parent
9706cd497d
commit
ec74204fa0
12 changed files with 51 additions and 42 deletions
|
@ -17,7 +17,7 @@ use style::properties::ComputedValues;
|
||||||
use style::selector_parser::PseudoElement;
|
use style::selector_parser::PseudoElement;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub(super) enum WhichPseudoElement {
|
pub enum WhichPseudoElement {
|
||||||
Before,
|
Before,
|
||||||
After,
|
After,
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ pub(super) enum Contents<Node> {
|
||||||
OfPseudoElement(Vec<PseudoElementContentItem>),
|
OfPseudoElement(Vec<PseudoElementContentItem>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) enum NonReplacedContents<Node> {
|
pub enum NonReplacedContents<Node> {
|
||||||
OfElement(Node),
|
OfElement(Node),
|
||||||
OfPseudoElement(Vec<PseudoElementContentItem>),
|
OfPseudoElement(Vec<PseudoElementContentItem>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) enum PseudoElementContentItem {
|
pub enum PseudoElementContentItem {
|
||||||
Text(String),
|
Text(String),
|
||||||
Replaced(ReplacedContent),
|
Replaced(ReplacedContent),
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ where
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct BoxSlot<'dom> {
|
pub struct BoxSlot<'dom> {
|
||||||
slot: Option<Arc<AtomicRefCell<Option<LayoutBox>>>>,
|
slot: Option<Arc<AtomicRefCell<Option<LayoutBox>>>>,
|
||||||
marker: marker<&'dom ()>,
|
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 is_element(self) -> bool;
|
||||||
fn as_text(self) -> Option<String>;
|
fn as_text(self) -> Option<String>;
|
||||||
fn first_child(self) -> Option<Self>;
|
fn first_child(self) -> Option<Self>;
|
||||||
|
|
|
@ -8,7 +8,7 @@ use atomic_refcell::AtomicRefCell;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(crate) struct LayoutDataForElement {
|
pub struct LayoutDataForElement {
|
||||||
pub(super) self_box: Arc<AtomicRefCell<Option<LayoutBox>>>,
|
pub(super) self_box: Arc<AtomicRefCell<Option<LayoutBox>>>,
|
||||||
pub(super) pseudo_elements: Option<Box<PseudoElementBoxes>>,
|
pub(super) pseudo_elements: Option<Box<PseudoElementBoxes>>,
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ pub(super) struct PseudoElementBoxes {
|
||||||
pub after: Arc<AtomicRefCell<Option<LayoutBox>>>,
|
pub after: Arc<AtomicRefCell<Option<LayoutBox>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) enum LayoutBox {
|
pub enum LayoutBox {
|
||||||
DisplayContents,
|
DisplayContents,
|
||||||
BlockLevel(Arc<BlockLevelBox>),
|
BlockLevel(Arc<BlockLevelBox>),
|
||||||
InlineLevel(Arc<InlineLevelBox>),
|
InlineLevel(Arc<InlineLevelBox>),
|
||||||
|
|
|
@ -123,7 +123,7 @@ struct BlockContainerBuilder<'dom, 'style, Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockContainer {
|
impl BlockContainer {
|
||||||
pub fn construct<'dom, 'style>(
|
pub(crate) fn construct<'dom, 'style>(
|
||||||
context: &SharedStyleContext<'style>,
|
context: &SharedStyleContext<'style>,
|
||||||
block_container_style: &Arc<ComputedValues>,
|
block_container_style: &Arc<ComputedValues>,
|
||||||
contents: NonReplacedContents<impl NodeExt<'dom>>,
|
contents: NonReplacedContents<impl NodeExt<'dom>>,
|
||||||
|
@ -646,7 +646,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub(crate) enum ContainsFloats {
|
pub enum ContainsFloats {
|
||||||
No,
|
No,
|
||||||
Yes,
|
Yes,
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use servo_arc::Arc;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct FloatBox {
|
pub struct FloatBox {
|
||||||
pub style: Arc<ComputedValues>,
|
pub style: Arc<ComputedValues>,
|
||||||
pub contents: IndependentFormattingContext,
|
pub contents: IndependentFormattingContext,
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@ use style::values::computed::Length;
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub(crate) struct InlineFormattingContext {
|
pub struct InlineFormattingContext {
|
||||||
pub(super) inline_level_boxes: Vec<Arc<InlineLevelBox>>,
|
pub(super) inline_level_boxes: Vec<Arc<InlineLevelBox>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum InlineLevelBox {
|
pub enum InlineLevelBox {
|
||||||
InlineBox(InlineBox),
|
InlineBox(InlineBox),
|
||||||
TextRun(TextRun),
|
TextRun(TextRun),
|
||||||
OutOfFlowAbsolutelyPositionedBox(AbsolutelyPositionedBox),
|
OutOfFlowAbsolutelyPositionedBox(AbsolutelyPositionedBox),
|
||||||
|
@ -34,7 +34,7 @@ pub(crate) enum InlineLevelBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct InlineBox {
|
pub struct InlineBox {
|
||||||
pub style: Arc<ComputedValues>,
|
pub style: Arc<ComputedValues>,
|
||||||
pub first_fragment: bool,
|
pub first_fragment: bool,
|
||||||
pub last_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
|
/// https://www.w3.org/TR/css-display-3/#css-text-run
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct TextRun {
|
pub struct TextRun {
|
||||||
pub parent_style: Arc<ComputedValues>,
|
pub parent_style: Arc<ComputedValues>,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,22 +25,22 @@ use style::Zero;
|
||||||
mod construct;
|
mod construct;
|
||||||
mod float;
|
mod float;
|
||||||
pub mod inline;
|
pub mod inline;
|
||||||
mod root;
|
pub mod root;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct BlockFormattingContext {
|
pub struct BlockFormattingContext {
|
||||||
pub contents: BlockContainer,
|
pub contents: BlockContainer,
|
||||||
pub contains_floats: bool,
|
pub contains_floats: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum BlockContainer {
|
pub enum BlockContainer {
|
||||||
BlockLevelBoxes(Vec<Arc<BlockLevelBox>>),
|
BlockLevelBoxes(Vec<Arc<BlockLevelBox>>),
|
||||||
InlineFormattingContext(InlineFormattingContext),
|
InlineFormattingContext(InlineFormattingContext),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum BlockLevelBox {
|
pub enum BlockLevelBox {
|
||||||
SameFormattingContextBlock {
|
SameFormattingContextBlock {
|
||||||
style: Arc<ComputedValues>,
|
style: Arc<ComputedValues>,
|
||||||
contents: BlockContainer,
|
contents: BlockContainer,
|
||||||
|
|
|
@ -22,17 +22,8 @@ use style::properties::ComputedValues;
|
||||||
use style::values::computed::{Length, LengthOrAuto};
|
use style::values::computed::{Length, LengthOrAuto};
|
||||||
use style_traits::CSSPixel;
|
use style_traits::CSSPixel;
|
||||||
|
|
||||||
// FIXME
|
#[derive(Debug)]
|
||||||
// impl crate::dom::Document {
|
pub struct BoxTreeRoot(BlockFormattingContext);
|
||||||
// pub(crate) fn layout(
|
|
||||||
// &self,
|
|
||||||
// viewport: crate::geom::Size<crate::geom::CssPx>,
|
|
||||||
// ) -> Vec<Fragment> {
|
|
||||||
// BoxTreeRoot::construct(self).layout(viewport)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
struct BoxTreeRoot(BlockFormattingContext);
|
|
||||||
|
|
||||||
impl BoxTreeRoot {
|
impl BoxTreeRoot {
|
||||||
pub fn construct<'dom>(
|
pub fn construct<'dom>(
|
||||||
|
|
|
@ -11,8 +11,18 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
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::properties::ComputedValues;
|
||||||
use style::values::computed::{Length, LengthOrAuto};
|
use style::values::computed::{Length, LengthOrAuto};
|
||||||
|
use style::values::specified::box_::DisplayInside;
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
|
|
||||||
pub mod context;
|
pub mod context;
|
||||||
|
@ -30,20 +40,11 @@ pub mod style_ext;
|
||||||
pub mod traversal;
|
pub mod traversal;
|
||||||
pub mod wrapper;
|
pub mod wrapper;
|
||||||
|
|
||||||
use crate::dom_traversal::{Contents, NodeExt};
|
pub use crate::flow::root::BoxTreeRoot;
|
||||||
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;
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-display/#independent-formatting-context
|
/// https://drafts.csswg.org/css-display/#independent-formatting-context
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum IndependentFormattingContext {
|
pub enum IndependentFormattingContext {
|
||||||
Flow(BlockFormattingContext),
|
Flow(BlockFormattingContext),
|
||||||
|
|
||||||
// Not called FC in specs, but behaves close enough
|
// Not called FC in specs, but behaves close enough
|
||||||
|
|
|
@ -13,7 +13,7 @@ use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPerc
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct AbsolutelyPositionedBox {
|
pub struct AbsolutelyPositionedBox {
|
||||||
pub style: Arc<ComputedValues>,
|
pub style: Arc<ComputedValues>,
|
||||||
pub contents: IndependentFormattingContext,
|
pub contents: IndependentFormattingContext,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::dom_traversal::NodeExt;
|
||||||
use style::context::SharedStyleContext;
|
use style::context::SharedStyleContext;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) enum ReplacedContent {
|
pub enum ReplacedContent {
|
||||||
// Not implemented yet
|
// Not implemented yet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,13 @@ pub struct ServoLayoutNode<'a> {
|
||||||
chain: PhantomData<&'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> {
|
impl<'ln> Debug for ServoLayoutNode<'ln> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
if let Some(el) = self.as_element() {
|
if let Some(el) = self.as_element() {
|
||||||
|
|
|
@ -45,6 +45,7 @@ use layout::query::{
|
||||||
process_text_index_request,
|
process_text_index_request,
|
||||||
};
|
};
|
||||||
use layout::traversal::RecalcStyle;
|
use layout::traversal::RecalcStyle;
|
||||||
|
use layout::BoxTreeRoot;
|
||||||
use layout_traits::LayoutThreadFactory;
|
use layout_traits::LayoutThreadFactory;
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
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.
|
/// The number of Web fonts that have been requested but not yet loaded.
|
||||||
outstanding_web_fonts: Arc<AtomicUsize>,
|
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
|
/// The document-specific shared lock used for author-origin stylesheets
|
||||||
document_shared_lock: Option<SharedRwLock>,
|
document_shared_lock: Option<SharedRwLock>,
|
||||||
|
|
||||||
|
@ -492,6 +496,7 @@ impl LayoutThread {
|
||||||
new_animations_sender: new_animations_sender,
|
new_animations_sender: new_animations_sender,
|
||||||
_new_animations_receiver: new_animations_receiver,
|
_new_animations_receiver: new_animations_receiver,
|
||||||
outstanding_web_fonts: Arc::new(AtomicUsize::new(0)),
|
outstanding_web_fonts: Arc::new(AtomicUsize::new(0)),
|
||||||
|
box_tree_root: Default::default(),
|
||||||
document_shared_lock: None,
|
document_shared_lock: None,
|
||||||
epoch: Cell::new(Epoch(0)),
|
epoch: Cell::new(Epoch(0)),
|
||||||
viewport_size: Size2D::new(Au(0), Au(0)),
|
viewport_size: Size2D::new(Au(0), Au(0)),
|
||||||
|
@ -1075,6 +1080,11 @@ impl LayoutThread {
|
||||||
|
|
||||||
if token.should_traverse() {
|
if token.should_traverse() {
|
||||||
driver::traverse_dom(&traversal, token, None);
|
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 {
|
for element in elements_with_snapshot {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue