From e38cc1a5491b536239d38aef98341e2f807b964c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 7 Oct 2019 15:32:43 +0200 Subject: [PATCH 1/7] 2020: run layout after box construction --- components/layout_2020/flow/mod.rs | 2 +- components/layout_2020/flow/root.rs | 5 +++-- components/layout_2020/lib.rs | 2 +- components/layout_thread_2020/lib.rs | 13 +++++++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index 189a5aeb436..2395380c5eb 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -27,7 +27,7 @@ mod float; pub mod inline; mod root; -pub use root::BoxTreeRoot; +pub use root::{BoxTreeRoot, FragmentTreeRoot}; #[derive(Debug)] pub(crate) struct BlockFormattingContext { diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index 994ce29bb16..6e344e1cdc8 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -23,6 +23,7 @@ use style::values::computed::{Length, LengthOrAuto}; use style_traits::CSSPixel; pub struct BoxTreeRoot(BlockFormattingContext); +pub struct FragmentTreeRoot(Vec); impl BoxTreeRoot { pub fn construct<'dom>( @@ -95,7 +96,7 @@ fn construct_for_root_element<'dom>( } impl BoxTreeRoot { - fn layout(&self, viewport: geom::Size) -> Vec { + pub fn layout(&self, viewport: geom::Size) -> FragmentTreeRoot { let initial_containing_block_size = Vec2 { inline: Length::new(viewport.width), block: Length::new(viewport.height), @@ -125,6 +126,6 @@ impl BoxTreeRoot { .par_iter() .map(|a| a.layout(&initial_containing_block)), ); - flow_children.fragments + FragmentTreeRoot(flow_children.fragments) } } diff --git a/components/layout_2020/lib.rs b/components/layout_2020/lib.rs index f491411eb3c..b7578713f5d 100644 --- a/components/layout_2020/lib.rs +++ b/components/layout_2020/lib.rs @@ -30,7 +30,7 @@ mod style_ext; pub mod traversal; pub mod wrapper; -pub use flow::BoxTreeRoot; +pub use flow::{BoxTreeRoot, FragmentTreeRoot}; use crate::dom_traversal::{Contents, NodeExt}; use crate::flow::{BlockFormattingContext, FlowChildren}; diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index 13f6fc79dce..c33449d478a 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -167,8 +167,11 @@ pub struct LayoutThread { /// The number of Web fonts that have been requested but not yet loaded. outstanding_web_fonts: Arc, - /// The root box tree. - box_tree_root: RefCell>, + /// The root of the box tree. + box_tree_root: RefCell>, + + /// The root of the fragment tree. + fragment_tree_root: RefCell>, /// The document-specific shared lock used for author-origin stylesheets document_shared_lock: Option, @@ -497,6 +500,7 @@ impl LayoutThread { _new_animations_receiver: new_animations_receiver, outstanding_web_fonts: Arc::new(AtomicUsize::new(0)), box_tree_root: Default::default(), + fragment_tree_root: Default::default(), document_shared_lock: None, epoch: Cell::new(Epoch(0)), viewport_size: Size2D::new(Au(0), Au(0)), @@ -1084,7 +1088,12 @@ impl LayoutThread { let shared = DomTraversal::::shared_context(&traversal); let box_tree = BoxTreeRoot::construct(shared, document.root_element().unwrap().as_node()); + let fragment_tree = box_tree.layout(Size2D::new( + self.viewport_size.width.to_f32_px(), + self.viewport_size.height.to_f32_px(), + )); *self.box_tree_root.borrow_mut() = Some(box_tree); + *self.fragment_tree_root.borrow_mut() = Some(fragment_tree); } for element in elements_with_snapshot { From 4e8eeda976f1475b11b1630854a01046d51e3c44 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 7 Oct 2019 16:37:53 +0200 Subject: [PATCH 2/7] 2020: add and call Fragment::build_display_list --- components/layout_2020/flow/root.rs | 13 ++++++++++++- components/layout_2020/fragments.rs | 16 ++++++++++++++++ components/layout_thread_2020/lib.rs | 25 ++++++++++++++----------- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index 6e344e1cdc8..ba473abc410 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -6,7 +6,7 @@ use crate::dom_traversal::{Contents, NodeExt}; use crate::flow::construct::ContainsFloats; use crate::flow::float::FloatBox; use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox}; -use crate::fragments::Fragment; +use crate::fragments::{Fragment, IsContentful}; use crate::geom; use crate::geom::flow_relative::Vec2; use crate::positioned::AbsolutelyPositionedBox; @@ -21,6 +21,7 @@ use style::context::SharedStyleContext; use style::properties::ComputedValues; use style::values::computed::{Length, LengthOrAuto}; use style_traits::CSSPixel; +use webrender_api::DisplayListBuilder; pub struct BoxTreeRoot(BlockFormattingContext); pub struct FragmentTreeRoot(Vec); @@ -129,3 +130,13 @@ impl BoxTreeRoot { FragmentTreeRoot(flow_children.fragments) } } + +impl FragmentTreeRoot { + pub fn build_display_list(&self, builder: &mut DisplayListBuilder) -> IsContentful { + let mut is_contentful = IsContentful(false); + for fragment in &self.0 { + fragment.build_display_list(builder, &mut is_contentful) + } + is_contentful + } +} diff --git a/components/layout_2020/fragments.rs b/components/layout_2020/fragments.rs index ceb2fdf7971..ad1ebd41359 100644 --- a/components/layout_2020/fragments.rs +++ b/components/layout_2020/fragments.rs @@ -9,6 +9,7 @@ use servo_arc::Arc; use style::properties::ComputedValues; use style::values::computed::Length; use style::Zero; +use webrender_api::DisplayListBuilder; pub(crate) enum Fragment { Box(BoxFragment), @@ -123,3 +124,18 @@ impl CollapsedMargin { self.max_positive + self.min_negative } } + +/// Contentful paint, for the purpose of +/// https://w3c.github.io/paint-timing/#first-contentful-paint +/// (i.e. the display list contains items of type text, +/// image, non-white canvas or SVG). Used by metrics. +pub struct IsContentful(pub bool); + +impl Fragment { + pub(crate) fn build_display_list( + &self, + builder: &mut DisplayListBuilder, + is_contentful: &mut IsContentful, + ) { + } +} diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index c33449d478a..1c0ee67a268 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -1108,7 +1108,9 @@ impl LayoutThread { } // Perform post-style recalculation layout passes. - self.perform_post_style_recalc_layout_passes(&data.reflow_goal, Some(&document)); + if let Some(root) = &*self.fragment_tree_root.borrow() { + self.perform_post_style_recalc_layout_passes(root, &data.reflow_goal, Some(&document)); + } self.first_reflow.set(false); self.respond_to_query_if_necessary(&data.reflow_goal, &mut *rw_data, &mut layout_context); @@ -1230,7 +1232,10 @@ impl LayoutThread { ); } - if let Some(author_shared_lock) = self.document_shared_lock.clone() { + if let Some(root) = &*self.fragment_tree_root.borrow() { + // Unwrap here should not panic since self.fragment_tree_root is only ever set to Some(_) + // in handle_reflow() where self.document_shared_lock is as well. + let author_shared_lock = self.document_shared_lock.clone().unwrap(); let author_guard = author_shared_lock.read(); let ua_or_user_guard = UA_STYLESHEETS.shared_lock.read(); let _guards = StylesheetGuards { @@ -1238,12 +1243,13 @@ impl LayoutThread { ua_or_user: &ua_or_user_guard, }; - self.perform_post_style_recalc_layout_passes(&ReflowGoal::TickAnimations, None); + self.perform_post_style_recalc_layout_passes(root, &ReflowGoal::TickAnimations, None); } } fn perform_post_style_recalc_layout_passes( &self, + fragment_tree: &layout::FragmentTreeRoot, reflow_goal: &ReflowGoal, document: Option<&ServoLayoutDocument>, ) { @@ -1261,16 +1267,13 @@ impl LayoutThread { document.will_paint(); } - let viewport_size = Size2D::new( + let viewport_size = webrender_api::units::LayoutSize::from_untyped(Size2D::new( self.viewport_size.width.to_f32_px(), self.viewport_size.height.to_f32_px(), - ); - - let viewport_size = webrender_api::units::LayoutSize::from_untyped(viewport_size); - - let display_list = + )); + let mut display_list = webrender_api::DisplayListBuilder::new(self.id.to_webrender(), viewport_size); - let is_contentful = false; + let is_contentful = fragment_tree.build_display_list(&mut display_list); debug!("Layout done!"); @@ -1282,7 +1285,7 @@ impl LayoutThread { // sending the display list to WebRender in order to set time related // Progressive Web Metrics. self.paint_time_metrics - .maybe_observe_paint_time(self, epoch, is_contentful); + .maybe_observe_paint_time(self, epoch, is_contentful.0); let mut txn = webrender_api::Transaction::new(); txn.set_display_list( From cfc3ffcd545a18806674cf3bb1e3ddcffff3d89e Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 15 Oct 2019 17:52:51 +0200 Subject: [PATCH 3/7] 2020: paint background-color --- Cargo.lock | 1 + components/layout_2020/Cargo.toml | 1 + components/layout_2020/display_list.rs | 106 +++++++++++++++++++++++++ components/layout_2020/flow/root.rs | 24 +++++- components/layout_2020/fragments.rs | 16 ---- components/layout_2020/geom.rs | 9 +++ components/layout_2020/lib.rs | 1 + components/layout_thread_2020/lib.rs | 9 ++- 8 files changed, 143 insertions(+), 24 deletions(-) create mode 100644 components/layout_2020/display_list.rs diff --git a/Cargo.lock b/Cargo.lock index f6c6c03ddf0..da1e5f81bb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2477,6 +2477,7 @@ version = "0.0.1" dependencies = [ "app_units", "atomic_refcell", + "cssparser", "euclid", "gfx", "ipc-channel", diff --git a/components/layout_2020/Cargo.toml b/components/layout_2020/Cargo.toml index cacece15eb5..69b0bea014e 100644 --- a/components/layout_2020/Cargo.toml +++ b/components/layout_2020/Cargo.toml @@ -15,6 +15,7 @@ doctest = false [dependencies] app_units = "0.7" atomic_refcell = "0.1" +cssparser = "0.27" euclid = "0.20" gfx = {path = "../gfx"} ipc-channel = "0.12" diff --git a/components/layout_2020/display_list.rs b/components/layout_2020/display_list.rs new file mode 100644 index 00000000000..cd3d3b103db --- /dev/null +++ b/components/layout_2020/display_list.rs @@ -0,0 +1,106 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +use crate::fragments::{BoxFragment, Fragment}; +use crate::geom::physical::{Rect, Vec2}; +use crate::style_ext::ComputedValuesExt; +use app_units::Au; +use style::values::computed::Length; +use webrender_api::CommonItemProperties; + +pub struct DisplayListBuilder { + pipeline_id: webrender_api::PipelineId, + pub wr: webrender_api::DisplayListBuilder, + pub is_contentful: bool, +} + +impl DisplayListBuilder { + pub fn new( + pipeline_id: webrender_api::PipelineId, + viewport_size: webrender_api::units::LayoutSize, + ) -> Self { + Self { + pipeline_id, + is_contentful: false, + wr: webrender_api::DisplayListBuilder::new(pipeline_id, viewport_size), + } + } +} + +/// Contentful paint, for the purpose of +/// https://w3c.github.io/paint-timing/#first-contentful-paint +/// (i.e. the display list contains items of type text, +/// image, non-white canvas or SVG). Used by metrics. +pub struct IsContentful(pub bool); + +impl Fragment { + pub(crate) fn build_display_list( + &self, + builder: &mut DisplayListBuilder, + is_contentful: &mut IsContentful, + containing_block: &Rect, + ) { + match self { + Fragment::Box(b) => b.build_display_list(builder, is_contentful, containing_block), + Fragment::Anonymous(a) => { + let rect = a + .rect + .to_physical(a.mode, containing_block) + .translate(&containing_block.top_left); + for child in &a.children { + child.build_display_list(builder, is_contentful, &rect) + } + }, + Fragment::Text(_) => { + is_contentful.0 = true; + // FIXME + }, + } + } +} + +impl BoxFragment { + fn build_display_list( + &self, + builder: &mut DisplayListBuilder, + is_contentful: &mut IsContentful, + containing_block: &Rect, + ) { + let background_color = self + .style + .resolve_color(self.style.clone_background_color()); + if background_color.alpha > 0 { + let clip_rect = self + .border_rect() + .to_physical(self.style.writing_mode(), containing_block) + .translate(&containing_block.top_left) + .into(); + let common = CommonItemProperties { + clip_rect, + clip_id: webrender_api::ClipId::root(builder.pipeline_id), + spatial_id: webrender_api::SpatialId::root_scroll_node(builder.pipeline_id), + hit_info: None, + // TODO(gw): Make use of the WR backface visibility functionality. + is_backface_visible: true, + }; + builder.wr.push_rect(&common, rgba(background_color)) + } + let content_rect = self + .content_rect + .to_physical(self.style.writing_mode(), containing_block) + .translate(&containing_block.top_left); + for child in &self.children { + child.build_display_list(builder, is_contentful, &content_rect) + } + } +} + +fn rgba(rgba: cssparser::RGBA) -> webrender_api::ColorF { + webrender_api::ColorF::new( + rgba.red_f32(), + rgba.green_f32(), + rgba.blue_f32(), + rgba.alpha_f32(), + ) +} diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index ba473abc410..54cc1eef07f 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -2,11 +2,12 @@ * 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/. */ +use crate::display_list::IsContentful; use crate::dom_traversal::{Contents, NodeExt}; use crate::flow::construct::ContainsFloats; use crate::flow::float::FloatBox; use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox}; -use crate::fragments::{Fragment, IsContentful}; +use crate::fragments::Fragment; use crate::geom; use crate::geom::flow_relative::Vec2; use crate::positioned::AbsolutelyPositionedBox; @@ -20,8 +21,8 @@ use servo_arc::Arc; use style::context::SharedStyleContext; use style::properties::ComputedValues; use style::values::computed::{Length, LengthOrAuto}; +use style::Zero; use style_traits::CSSPixel; -use webrender_api::DisplayListBuilder; pub struct BoxTreeRoot(BlockFormattingContext); pub struct FragmentTreeRoot(Vec); @@ -132,10 +133,25 @@ impl BoxTreeRoot { } impl FragmentTreeRoot { - pub fn build_display_list(&self, builder: &mut DisplayListBuilder) -> IsContentful { + pub fn build_display_list( + &self, + builder: &mut crate::display_list::DisplayListBuilder, + pipeline_id: msg::constellation_msg::PipelineId, + viewport_size: webrender_api::units::LayoutSize, + ) -> IsContentful { + let containing_block = geom::physical::Rect { + top_left: geom::physical::Vec2 { + x: Length::zero(), + y: Length::zero(), + }, + size: geom::physical::Vec2 { + x: Length::new(viewport_size.width), + y: Length::new(viewport_size.height), + }, + }; let mut is_contentful = IsContentful(false); for fragment in &self.0 { - fragment.build_display_list(builder, &mut is_contentful) + fragment.build_display_list(builder, &mut is_contentful, &containing_block) } is_contentful } diff --git a/components/layout_2020/fragments.rs b/components/layout_2020/fragments.rs index ad1ebd41359..ceb2fdf7971 100644 --- a/components/layout_2020/fragments.rs +++ b/components/layout_2020/fragments.rs @@ -9,7 +9,6 @@ use servo_arc::Arc; use style::properties::ComputedValues; use style::values::computed::Length; use style::Zero; -use webrender_api::DisplayListBuilder; pub(crate) enum Fragment { Box(BoxFragment), @@ -124,18 +123,3 @@ impl CollapsedMargin { self.max_positive + self.min_negative } } - -/// Contentful paint, for the purpose of -/// https://w3c.github.io/paint-timing/#first-contentful-paint -/// (i.e. the display list contains items of type text, -/// image, non-white canvas or SVG). Used by metrics. -pub struct IsContentful(pub bool); - -impl Fragment { - pub(crate) fn build_display_list( - &self, - builder: &mut DisplayListBuilder, - is_contentful: &mut IsContentful, - ) { - } -} diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index af8d37393b5..a56ee5c7613 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -332,3 +332,12 @@ impl From> for Rect { } } } + +impl From> for webrender_api::units::LayoutRect { + fn from(r: physical::Rect) -> Self { + Rect { + origin: Point::new(r.top_left.x.px(), r.top_left.y.px()), + size: Size::new(r.size.x.px(), r.size.y.px()), + } + } +} diff --git a/components/layout_2020/lib.rs b/components/layout_2020/lib.rs index b7578713f5d..5c046feecd7 100644 --- a/components/layout_2020/lib.rs +++ b/components/layout_2020/lib.rs @@ -17,6 +17,7 @@ use style::Zero; pub mod context; pub mod data; +pub mod display_list; mod dom_traversal; mod element_data; mod flow; diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index 1c0ee67a268..13cf35975ee 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -35,6 +35,7 @@ use gfx_traits::{node_id_from_scroll_id, Epoch}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use ipc_channel::router::ROUTER; use layout::context::LayoutContext; +use layout::display_list::DisplayListBuilder; use layout::query::{ process_content_box_request, process_content_boxes_request, LayoutRPCImpl, LayoutThreadData, }; @@ -1271,9 +1272,9 @@ impl LayoutThread { self.viewport_size.width.to_f32_px(), self.viewport_size.height.to_f32_px(), )); - let mut display_list = - webrender_api::DisplayListBuilder::new(self.id.to_webrender(), viewport_size); - let is_contentful = fragment_tree.build_display_list(&mut display_list); + let mut display_list = DisplayListBuilder::new(self.id.to_webrender(), viewport_size); + let is_contentful = + fragment_tree.build_display_list(&mut display_list, self.id, viewport_size); debug!("Layout done!"); @@ -1292,7 +1293,7 @@ impl LayoutThread { webrender_api::Epoch(epoch.0), None, viewport_size, - display_list.finalize(), + display_list.wr.finalize(), true, ); txn.generate_frame(); From 13e494d74f6ae4f6e41eaa96a89dec392bd33d93 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 15 Oct 2019 17:55:57 +0200 Subject: [PATCH 4/7] More compact debug output for CSS values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` Rect { start_corner: Vec2 { i: 0.0 px, b: 0.0 px }, size: Vec2 { i: 1024.0 px, b: 20.0 px }, } ``` … instead of: ``` Rect { start_corner: Vec2 { inline: CSSPixelLength( 0.0, ), block: CSSPixelLength( 0.0, ), }, size: Vec2 { inline: CSSPixelLength( 1024.0, ), block: CSSPixelLength( 0.0, ), }, } ``` --- components/layout_2020/geom.rs | 27 ++++++++++++++++++++-- components/style/values/computed/length.rs | 8 ++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index a56ee5c7613..f37685821a3 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -3,6 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::style_ext::{Direction, WritingMode}; +use std::fmt; use std::ops::{Add, AddAssign, Sub}; use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto}; use style::Zero; @@ -13,7 +14,7 @@ pub type Size = euclid::Size2D; pub type Rect = euclid::Rect; pub(crate) mod physical { - #[derive(Clone, Debug)] + #[derive(Clone)] pub(crate) struct Vec2 { pub x: T, pub y: T, @@ -35,7 +36,7 @@ pub(crate) mod physical { } pub(crate) mod flow_relative { - #[derive(Clone, Debug)] + #[derive(Clone)] pub(crate) struct Vec2 { pub inline: T, pub block: T, @@ -56,6 +57,28 @@ pub(crate) mod flow_relative { } } +impl fmt::Debug for physical::Vec2 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + // Not using f.debug_struct on purpose here, to keep {:?} output somewhat compact + f.write_str("Vec2 { x: ")?; + self.x.fmt(f)?; + f.write_str(", y: ")?; + self.y.fmt(f)?; + f.write_str(" }") + } +} + +impl fmt::Debug for flow_relative::Vec2 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + // Not using f.debug_struct on purpose here, to keep {:?} output somewhat compact + f.write_str("Vec2 { i: ")?; + self.inline.fmt(f)?; + f.write_str(", b: ")?; + self.block.fmt(f)?; + f.write_str(" }") + } +} + impl Add<&'_ physical::Vec2> for &'_ physical::Vec2 where T: Add + Copy, diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 9bfad708a64..6d61198d364 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -611,7 +611,6 @@ impl Size { Clone, ComputeSquaredDistance, Copy, - Debug, MallocSizeOf, PartialEq, PartialOrd, @@ -623,6 +622,13 @@ impl Size { #[repr(C)] pub struct CSSPixelLength(CSSFloat); +impl fmt::Debug for CSSPixelLength { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f)?; + f.write_str(" px") + } +} + impl CSSPixelLength { /// Return a new CSSPixelLength. #[inline] From 8f89f59329563f0bae6fb7e38bf4ba8bb574087c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 23 Oct 2019 17:28:03 +0200 Subject: [PATCH 5/7] 2020: parse `display: contents` --- components/style/values/specified/box.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index b66b03b47b8..58d51f8c006 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -619,7 +619,7 @@ impl Parse for Display { // Now parse the single-keyword `display` values. Ok(try_match_ident_ignore_ascii_case! { input, "none" => Display::None, - #[cfg(feature = "gecko")] + #[cfg(any(feature = "servo-layout-2020", feature = "gecko"))] "contents" => Display::Contents, "inline-block" => Display::InlineBlock, #[cfg(any(feature = "servo-layout-2013", feature = "gecko"))] From 22f5e077657e79b5f66b8444384ce22514aa4eaf Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 23 Oct 2019 17:59:06 +0200 Subject: [PATCH 6/7] 2020: define DisplayInside and DisplayOutside enums separately from Stylo --- components/layout_2020/flow/construct.rs | 2 - components/layout_2020/flow/inline.rs | 1 - components/layout_2020/lib.rs | 4 +- components/layout_2020/style_ext.rs | 51 ++++++++++++++++-------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs index a7056f23ca9..f3afabf15fc 100644 --- a/components/layout_2020/flow/construct.rs +++ b/components/layout_2020/flow/construct.rs @@ -210,7 +210,6 @@ where self.handle_block_level_element(style.clone(), inside, contents, box_slot) } }, - DisplayOutside::None => panic!(":("), }, } } @@ -352,7 +351,6 @@ where inline_box.last_fragment = true; Arc::new(InlineLevelBox::InlineBox(inline_box)) }, - DisplayInside::None | DisplayInside::Contents => panic!(":("), }, }; self.current_inline_level_boxes().push(box_.clone()); diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs index 59b822976ca..133654f32b7 100644 --- a/components/layout_2020/flow/inline.rs +++ b/components/layout_2020/flow/inline.rs @@ -122,7 +122,6 @@ impl InlineFormattingContext { inline: match outside { DisplayOutside::Inline => ifc.inline_position, DisplayOutside::Block => Length::zero(), - DisplayOutside::None => unreachable!(":("), }, block: ifc.line_boxes.next_line_block_position, }, diff --git a/components/layout_2020/lib.rs b/components/layout_2020/lib.rs index 5c046feecd7..052cb4b0540 100644 --- a/components/layout_2020/lib.rs +++ b/components/layout_2020/lib.rs @@ -38,11 +38,10 @@ 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 crate::style_ext::{ComputedValuesExt, Direction, DisplayInside, 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 #[derive(Debug)] @@ -74,7 +73,6 @@ impl IndependentFormattingContext { non_replaced, )) }, - DisplayInside::None | DisplayInside::Contents => panic!(":("), }, Err(replaced) => IndependentFormattingContext::Replaced(replaced), } diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index bb0b0411dec..e6d4537f47c 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -4,14 +4,12 @@ use crate::geom::{flow_relative, physical}; use style::properties::ComputedValues; -use style::values::computed::{ - Display as PackedDisplay, Length, LengthPercentage, LengthPercentageOrAuto, Size, -}; +use style::values::computed::{Length, LengthPercentage, LengthPercentageOrAuto, Size}; +use style::values::specified::box_ as stylo; pub use style::computed_values::direction::T as Direction; pub use style::computed_values::position::T as Position; pub use style::computed_values::writing_mode::T as WritingMode; -pub use style::values::specified::box_::{DisplayInside, DisplayOutside}; #[derive(Clone, Copy, Eq, PartialEq)] pub(crate) enum Display { @@ -31,6 +29,18 @@ pub(crate) enum DisplayGeneratingBox { // https://drafts.csswg.org/css-display-3/#layout-specific-display } +#[derive(Clone, Copy, Eq, PartialEq)] +pub(crate) enum DisplayOutside { + Block, + Inline, +} + +#[derive(Clone, Copy, Eq, PartialEq)] +pub(crate) enum DisplayInside { + Flow, + FlowRoot, +} + pub(crate) trait ComputedValuesExt { fn writing_mode(&self) -> (WritingMode, Direction); fn box_offsets(&self) -> flow_relative::Sides; @@ -105,18 +115,27 @@ impl ComputedValuesExt for ComputedValues { } } -impl From for Display { - fn from(packed_display: PackedDisplay) -> Self { - if packed_display == PackedDisplay::None { - return Self::None; - } - if packed_display == PackedDisplay::Contents { - return Self::Contents; - } - Self::GeneratingBox(DisplayGeneratingBox::OutsideInside { - outside: packed_display.outside(), - inside: packed_display.inside(), - // list_item: packed_display.is_list_item(), +impl From for Display { + fn from(packed: stylo::Display) -> Self { + let inside = match packed.inside() { + stylo::DisplayInside::Flow => DisplayInside::Flow, + stylo::DisplayInside::FlowRoot => DisplayInside::FlowRoot, + + // These should not be values of DisplayInside, but oh well + stylo::DisplayInside::None => return Display::None, + stylo::DisplayInside::Contents => return Display::Contents, + }; + let outside = match packed.outside() { + stylo::DisplayOutside::Block => DisplayOutside::Block, + stylo::DisplayOutside::Inline => DisplayOutside::Inline, + + // This should not be a value of DisplayInside, but oh well + stylo::DisplayOutside::None => return Display::None, + }; + Display::GeneratingBox(DisplayGeneratingBox::OutsideInside { + outside, + inside, + // list_item: packed.is_list_item(), }) } } From 59f68525c4f2ad199861a3db7444929dd4dbe795 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 23 Oct 2019 18:38:30 +0200 Subject: [PATCH 7/7] 2020: enable CSS parsing of properties that are (somewhat) implemented --- components/style/properties/longhands/border.mako.rs | 2 -- components/style/properties/longhands/box.mako.rs | 1 - components/style/properties/longhands/inherited_box.mako.rs | 2 ++ components/style/properties/longhands/margin.mako.rs | 1 - components/style/properties/longhands/padding.mako.rs | 1 - components/style/properties/longhands/position.mako.rs | 3 --- components/style/properties/shorthands/border.mako.rs | 6 +++--- components/style/properties/shorthands/margin.mako.rs | 6 +++--- components/style/properties/shorthands/padding.mako.rs | 6 +++--- 9 files changed, 11 insertions(+), 17 deletions(-) diff --git a/components/style/properties/longhands/border.mako.rs b/components/style/properties/longhands/border.mako.rs index 80e95ae84b3..a77fe4cb5b3 100644 --- a/components/style/properties/longhands/border.mako.rs +++ b/components/style/properties/longhands/border.mako.rs @@ -24,7 +24,6 @@ "border-%s-color" % side_name, "Color", "computed_value::T::currentcolor()", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", alias=maybe_moz_logical_alias(engine, side, "-moz-border-%s-color"), spec=maybe_logical_spec(side, "color"), animation_value_type="AnimatedColor", @@ -51,7 +50,6 @@ "BorderSideWidth", "crate::values::computed::NonNegativeLength::new(3.)", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", computed_type="crate::values::computed::NonNegativeLength", alias=maybe_moz_logical_alias(engine, side, "-moz-border-%s-width"), spec=maybe_logical_spec(side, "width"), diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs index a75504be193..815dcab313e 100644 --- a/components/style/properties/longhands/box.mako.rs +++ b/components/style/properties/longhands/box.mako.rs @@ -63,7 +63,6 @@ ${helpers.predefined_type( "Float", "computed::Float::None", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", initial_specified_value="specified::Float::None", spec="https://drafts.csswg.org/css-box/#propdef-float", animation_value_type="discrete", diff --git a/components/style/properties/longhands/inherited_box.mako.rs b/components/style/properties/longhands/inherited_box.mako.rs index 77ee11bdd4c..8db62bf56d6 100644 --- a/components/style/properties/longhands/inherited_box.mako.rs +++ b/components/style/properties/longhands/inherited_box.mako.rs @@ -29,6 +29,7 @@ ${helpers.single_keyword( rl=horizontal-tb rl-tb=horizontal-tb \ tb=vertical-rl tb-rl=vertical-rl", servo_2013_pref="layout.writing-mode.enabled", + servo_2020_pref="layout.writing-mode.enabled", animation_value_type="none", spec="https://drafts.csswg.org/css-writing-modes/#propdef-writing-mode", servo_restyle_damage="rebuild_and_reflow", @@ -38,6 +39,7 @@ ${helpers.single_keyword( "direction", "ltr rtl", engines="gecko servo-2013 servo-2020", + servo_2020_pref="layout.2020.unimplemented", animation_value_type="none", spec="https://drafts.csswg.org/css-writing-modes/#propdef-direction", needs_conversion=True, diff --git a/components/style/properties/longhands/margin.mako.rs b/components/style/properties/longhands/margin.mako.rs index 9ec1e97504c..4ad056f05b2 100644 --- a/components/style/properties/longhands/margin.mako.rs +++ b/components/style/properties/longhands/margin.mako.rs @@ -17,7 +17,6 @@ "LengthPercentageOrAuto", "computed::LengthPercentageOrAuto::zero()", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", alias=maybe_moz_logical_alias(engine, side, "-moz-margin-%s"), allow_quirks="No" if side[1] else "Yes", animation_value_type="ComputedValue", diff --git a/components/style/properties/longhands/padding.mako.rs b/components/style/properties/longhands/padding.mako.rs index a91f1238979..3089c0acb92 100644 --- a/components/style/properties/longhands/padding.mako.rs +++ b/components/style/properties/longhands/padding.mako.rs @@ -17,7 +17,6 @@ "NonNegativeLengthPercentage", "computed::NonNegativeLengthPercentage::zero()", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", alias=maybe_moz_logical_alias(engine, side, "-moz-padding-%s"), animation_value_type="NonNegativeLengthPercentage", logical=side[1], diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index 680b6117c42..1c2f5cc2e4a 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -15,7 +15,6 @@ "LengthPercentageOrAuto", "computed::LengthPercentageOrAuto::auto()", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side, animation_value_type="ComputedValue", allow_quirks="Yes", @@ -30,7 +29,6 @@ "LengthPercentageOrAuto", "computed::LengthPercentageOrAuto::auto()", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", spec="https://drafts.csswg.org/css-logical-props/#propdef-inset-%s" % side, alias="offset-%s:layout.css.offset-logical-properties.enabled" % side, animation_value_type="ComputedValue", @@ -278,7 +276,6 @@ ${helpers.predefined_type( "Size", "computed::Size::auto()", engines="gecko servo-2013 servo-2020", - servo_2020_pref="layout.2020.unimplemented", logical=logical, logical_group="size", allow_quirks="No" if logical else "Yes", diff --git a/components/style/properties/shorthands/border.mako.rs b/components/style/properties/shorthands/border.mako.rs index 564244a9acc..4f1c381c732 100644 --- a/components/style/properties/shorthands/border.mako.rs +++ b/components/style/properties/shorthands/border.mako.rs @@ -9,7 +9,7 @@ ${helpers.four_sides_shorthand( "border-color", "border-%s-color", "specified::Color::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", spec="https://drafts.csswg.org/css-backgrounds/#border-color", allow_quirks="Yes", )} @@ -18,14 +18,14 @@ ${helpers.four_sides_shorthand( "border-style", "border-%s-style", "specified::BorderStyle::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", needs_context=False, spec="https://drafts.csswg.org/css-backgrounds/#border-style", )} <%helpers:shorthand name="border-width" - engines="gecko servo-2013" + engines="gecko servo-2013 servo-2020" sub_properties="${ ' '.join('border-%s-width' % side for side in PHYSICAL_SIDES)}" diff --git a/components/style/properties/shorthands/margin.mako.rs b/components/style/properties/shorthands/margin.mako.rs index a767ad604fb..5d5f2101563 100644 --- a/components/style/properties/shorthands/margin.mako.rs +++ b/components/style/properties/shorthands/margin.mako.rs @@ -8,7 +8,7 @@ ${helpers.four_sides_shorthand( "margin", "margin-%s", "specified::LengthPercentageOrAuto::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", spec="https://drafts.csswg.org/css-box/#propdef-margin", allowed_in_page_rule=True, allow_quirks="Yes", @@ -19,7 +19,7 @@ ${helpers.two_properties_shorthand( "margin-block-start", "margin-block-end", "specified::LengthPercentageOrAuto::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", spec="https://drafts.csswg.org/css-logical/#propdef-margin-block" )} @@ -28,7 +28,7 @@ ${helpers.two_properties_shorthand( "margin-inline-start", "margin-inline-end", "specified::LengthPercentageOrAuto::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", spec="https://drafts.csswg.org/css-logical/#propdef-margin-inline" )} diff --git a/components/style/properties/shorthands/padding.mako.rs b/components/style/properties/shorthands/padding.mako.rs index 6499d494d15..02db51a88d6 100644 --- a/components/style/properties/shorthands/padding.mako.rs +++ b/components/style/properties/shorthands/padding.mako.rs @@ -8,7 +8,7 @@ ${helpers.four_sides_shorthand( "padding", "padding-%s", "specified::NonNegativeLengthPercentage::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", spec="https://drafts.csswg.org/css-box-3/#propdef-padding", allow_quirks="Yes", )} @@ -18,7 +18,7 @@ ${helpers.two_properties_shorthand( "padding-block-start", "padding-block-end", "specified::NonNegativeLengthPercentage::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", spec="https://drafts.csswg.org/css-logical/#propdef-padding-block" )} @@ -27,7 +27,7 @@ ${helpers.two_properties_shorthand( "padding-inline-start", "padding-inline-end", "specified::NonNegativeLengthPercentage::parse", - engines="gecko servo-2013", + engines="gecko servo-2013 servo-2020", spec="https://drafts.csswg.org/css-logical/#propdef-padding-inline" )}