diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index dd647070d7a..454177c789e 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -10,7 +10,7 @@ use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox}; use crate::formatting_contexts::IndependentFormattingContext; use crate::fragments::Fragment; use crate::geom::flow_relative::Vec2; -use crate::geom::PhysicalRect; +use crate::geom::{PhysicalPoint, PhysicalRect, PhysicalSize}; use crate::positioned::AbsolutelyPositionedBox; use crate::positioned::PositioningContext; use crate::replaced::ReplacedContent; @@ -22,6 +22,7 @@ use euclid::default::{Point2D, Rect, Size2D}; use gfx_traits::print_tree::PrintTree; use script_layout_interface::wrapper_traits::LayoutNode; use servo_arc::Arc; +use style::dom::OpaqueNode; use style::properties::ComputedValues; use style::values::computed::Length; use style_traits::CSSPixel; @@ -35,8 +36,8 @@ pub struct FragmentTreeRoot { /// The scrollable overflow of the root of the fragment tree. scrollable_overflow: PhysicalRect, - /// The axis-aligned bounding box of the border box of all child fragments - bounding_box_of_border_boxes: PhysicalRect, + /// The containing block used in the layout of this fragment tree. + initial_containing_block: PhysicalRect, } impl BoxTreeRoot { @@ -117,13 +118,18 @@ impl BoxTreeRoot { viewport: euclid::Size2D, ) -> FragmentTreeRoot { let style = ComputedValues::initial_values(); + + // FIXME: use the document’s mode: + // https://drafts.csswg.org/css-writing-modes/#principal-flow + let physical_containing_block = PhysicalRect::new( + PhysicalPoint::zero(), + PhysicalSize::new(Length::new(viewport.width), Length::new(viewport.height)), + ); let initial_containing_block = DefiniteContainingBlock { size: Vec2 { - inline: Length::new(viewport.width), - block: Length::new(viewport.height), + inline: physical_containing_block.size.width, + block: physical_containing_block.size.height, }, - // FIXME: use the document’s mode: - // https://drafts.csswg.org/css-writing-modes/#principal-flow style, }; @@ -142,8 +148,6 @@ impl BoxTreeRoot { &mut independent_layout.fragments, ); - // FIXME(mrobinson, bug 25564): We should be using the containing block - // here to properly convert scrollable overflow to physical geometry. let scrollable_overflow = independent_layout .fragments @@ -167,51 +171,18 @@ impl BoxTreeRoot { acc.union(&child_overflow) }); - let containing_block = PhysicalRect::zero(); - let bounding_box_of_border_boxes = - independent_layout - .fragments - .iter() - .fold(PhysicalRect::zero(), |acc, child| { - acc.union(&match child { - Fragment::Box(fragment) => fragment - .border_rect() - .to_physical(fragment.style.writing_mode, &containing_block), - Fragment::Anonymous(fragment) => { - fragment.rect.to_physical(fragment.mode, &containing_block) - }, - Fragment::Text(fragment) => fragment - .rect - .to_physical(fragment.parent_style.writing_mode, &containing_block), - Fragment::Image(fragment) => fragment - .rect - .to_physical(fragment.style.writing_mode, &containing_block), - }) - }); - FragmentTreeRoot { children: independent_layout.fragments, scrollable_overflow, - bounding_box_of_border_boxes, + initial_containing_block: physical_containing_block, } } } impl FragmentTreeRoot { - pub fn build_display_list( - &self, - builder: &mut crate::display_list::DisplayListBuilder, - viewport_size: webrender_api::units::LayoutSize, - ) { - let containing_block = PhysicalRect::new( - euclid::Point2D::zero(), - euclid::Size2D::new( - Length::new(viewport_size.width), - Length::new(viewport_size.height), - ), - ); + pub fn build_display_list(&self, builder: &mut crate::display_list::DisplayListBuilder) { for fragment in &self.children { - fragment.build_display_list(builder, &containing_block) + fragment.build_display_list(builder, &self.initial_containing_block) } } @@ -229,15 +200,126 @@ impl FragmentTreeRoot { )) } - pub fn bounding_box_of_border_boxes(&self) -> Rect { - let origin = Point2D::new( - Au::from_f32_px(self.bounding_box_of_border_boxes.origin.x.px()), - Au::from_f32_px(self.bounding_box_of_border_boxes.origin.y.px()), - ); - let size = Size2D::new( - Au::from_f32_px(self.bounding_box_of_border_boxes.size.width.px()), - Au::from_f32_px(self.bounding_box_of_border_boxes.size.height.px()), - ); - Rect::new(origin, size) + fn find( + &self, + mut process_func: impl FnMut(&Fragment, &PhysicalRect) -> Option, + ) -> Option { + fn recur( + fragments: &[Fragment], + containing_block: &PhysicalRect, + process_func: &mut impl FnMut(&Fragment, &PhysicalRect) -> Option, + ) -> Option { + for fragment in fragments { + if let Some(result) = process_func(fragment, containing_block) { + return Some(result); + } + + match fragment { + Fragment::Box(fragment) => { + let new_containing_block = fragment + .content_rect + .to_physical(fragment.style.writing_mode, containing_block) + .translate(containing_block.origin.to_vector()); + if let Some(result) = + recur(&fragment.children, &new_containing_block, process_func) + { + return Some(result); + } + }, + Fragment::Anonymous(fragment) => { + let new_containing_block = fragment + .rect + .to_physical(fragment.mode, containing_block) + .translate(containing_block.origin.to_vector()); + if let Some(result) = + recur(&fragment.children, &new_containing_block, process_func) + { + return Some(result); + } + }, + _ => {}, + } + } + None + } + recur( + &self.children, + &self.initial_containing_block, + &mut process_func, + ) + } + + pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Rect { + let mut bounding_box = PhysicalRect::zero(); + self.find(|fragment, containing_block| { + let fragment_relative_rect = match fragment { + Fragment::Box(fragment) if fragment.tag == requested_node => fragment + .border_rect() + .to_physical(fragment.style.writing_mode, &containing_block), + Fragment::Text(fragment) if fragment.tag == requested_node => fragment + .rect + .to_physical(fragment.parent_style.writing_mode, &containing_block), + Fragment::Box(_) | + Fragment::Text(_) | + Fragment::Image(_) | + Fragment::Anonymous(_) => return None, + }; + + bounding_box = fragment_relative_rect + .translate(containing_block.origin.to_vector()) + .union(&bounding_box); + None::<()> + }); + + Rect::new( + Point2D::new( + Au::from_f32_px(bounding_box.origin.x.px()), + Au::from_f32_px(bounding_box.origin.y.px()), + ), + Size2D::new( + Au::from_f32_px(bounding_box.size.width.px()), + Au::from_f32_px(bounding_box.size.height.px()), + ), + ) + } + + pub fn get_border_dimensions_for_node(&self, requested_node: OpaqueNode) -> Rect { + self.find(|fragment, containing_block| { + let (style, padding_rect) = match fragment { + Fragment::Box(fragment) if fragment.tag == requested_node => { + (&fragment.style, fragment.padding_rect()) + }, + Fragment::Box(_) | + Fragment::Text(_) | + Fragment::Image(_) | + Fragment::Anonymous(_) => return None, + }; + + // https://drafts.csswg.org/cssom-view/#dom-element-clienttop + // " If the element has no associated CSS layout box or if the + // CSS layout box is inline, return zero." For this check we + // also explicitly ignore the list item portion of the display + // style. + let display = &style.get_box().display; + if display.inside() == style::values::specified::box_::DisplayInside::Flow && + display.outside() == style::values::specified::box_::DisplayOutside::Inline + { + return Some(Rect::zero()); + } + + let padding_rect = padding_rect.to_physical(style.writing_mode, &containing_block); + let border = style.get_border(); + Some(Rect::new( + Point2D::new( + border.border_left_width.px() as i32, + border.border_top_width.px() as i32, + ), + Size2D::new( + padding_rect.size.width.px() as i32, + padding_rect.size.height.px() as i32, + ), + )) + }) + .unwrap_or_else(Rect::zero) } } diff --git a/components/layout_2020/query.rs b/components/layout_2020/query.rs index 0a7225c3b3c..d281bb57a91 100644 --- a/components/layout_2020/query.rs +++ b/components/layout_2020/query.rs @@ -165,22 +165,31 @@ impl LayoutRPC for LayoutRPCImpl { } pub fn process_content_box_request( - _requested_node: OpaqueNode, + requested_node: OpaqueNode, fragment_tree_root: Option<&FragmentTreeRoot>, ) -> Option> { let fragment_tree_root = match fragment_tree_root { Some(fragment_tree_root) => fragment_tree_root, None => return None, }; - Some(fragment_tree_root.bounding_box_of_border_boxes()) + + Some(fragment_tree_root.get_content_box_for_node(requested_node)) } pub fn process_content_boxes_request(_requested_node: OpaqueNode) -> Vec> { vec![] } -pub fn process_node_geometry_request(_requested_node: OpaqueNode) -> Rect { - Rect::zero() +pub fn process_node_geometry_request( + requested_node: OpaqueNode, + fragment_tree_root: Option<&FragmentTreeRoot>, +) -> Rect { + let fragment_tree_root = match fragment_tree_root { + Some(fragment_tree_root) => fragment_tree_root, + None => return Rect::zero(), + }; + + fragment_tree_root.get_border_dimensions_for_node(requested_node) } pub fn process_node_scroll_id_request( diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index 0cc910d9c71..97d19762528 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -1234,7 +1234,10 @@ impl LayoutThread { rw_data.text_index_response = process_text_index_request(node, point_in_node); }, &QueryMsg::ClientRectQuery(node) => { - rw_data.client_rect_response = process_node_geometry_request(node); + rw_data.client_rect_response = process_node_geometry_request( + node, + (&*self.fragment_tree_root.borrow()).as_ref(), + ); }, &QueryMsg::NodeScrollGeometryQuery(node) => { rw_data.scroll_area_response = process_node_scroll_area_request(node); @@ -1383,11 +1386,7 @@ impl LayoutThread { fragment_tree.scrollable_overflow(), ); - 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(), - )); - fragment_tree.build_display_list(&mut display_list, viewport_size); + fragment_tree.build_display_list(&mut display_list); if self.dump_flow_tree { fragment_tree.print(); @@ -1408,6 +1407,10 @@ impl LayoutThread { self.paint_time_metrics .maybe_observe_paint_time(self, epoch, display_list.is_contentful); + 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(), + )); self.webrender_api.send_display_list( self.webrender_document, epoch, diff --git a/tests/wpt/include-layout-2020.ini b/tests/wpt/include-layout-2020.ini index f689dde483b..eb6b04d3080 100644 --- a/tests/wpt/include-layout-2020.ini +++ b/tests/wpt/include-layout-2020.ini @@ -3,6 +3,8 @@ skip: true skip: true [css] skip: false + [mozilla] + skip: false [css] skip: true [CSS2] @@ -13,3 +15,5 @@ skip: true skip: false [css-backgrounds] skip: false + [cssom-view] + skip: false diff --git a/tests/wpt/metadata-layout-2020/css/cssom-view/CaretPosition-001.html.ini b/tests/wpt/metadata-layout-2020/css/cssom-view/CaretPosition-001.html.ini new file mode 100644 index 00000000000..4c79907309b --- /dev/null +++ b/tests/wpt/metadata-layout-2020/css/cssom-view/CaretPosition-001.html.ini @@ -0,0 +1,4 @@ +[CaretPosition-001.html] + [Element at (400, 100)] + expected: FAIL + diff --git a/tests/wpt/metadata-layout-2020/css/cssom-view/DOMRectList.html.ini b/tests/wpt/metadata-layout-2020/css/cssom-view/DOMRectList.html.ini new file mode 100644 index 00000000000..ddbb141c3f7 --- /dev/null +++ b/tests/wpt/metadata-layout-2020/css/cssom-view/DOMRectList.html.ini @@ -0,0 +1,7 @@ +[DOMRectList.html] + [Range getClientRects()] + expected: FAIL + + [Element getClientRects()] + expected: FAIL + diff --git a/tests/wpt/metadata-layout-2020/css/cssom-view/GetBoundingRect.html.ini b/tests/wpt/metadata-layout-2020/css/cssom-view/GetBoundingRect.html.ini new file mode 100644 index 00000000000..668456deca0 --- /dev/null +++ b/tests/wpt/metadata-layout-2020/css/cssom-view/GetBoundingRect.html.ini @@ -0,0 +1,4 @@ +[GetBoundingRect.html] + [getBoundingClientRect] + expected: FAIL + diff --git a/tests/wpt/metadata-layout-2020/css/cssom-view/HTMLBody-ScrollArea_quirksmode.html.ini b/tests/wpt/metadata-layout-2020/css/cssom-view/HTMLBody-ScrollArea_quirksmode.html.ini new file mode 100644 index 00000000000..4a680249460 --- /dev/null +++ b/tests/wpt/metadata-layout-2020/css/cssom-view/HTMLBody-ScrollArea_quirksmode.html.ini @@ -0,0 +1,13 @@ +[HTMLBody-ScrollArea_quirksmode.html] + [document.scrollingElement should be body element in quirks.] + expected: FAIL + + [scrollingElement in quirks should be null when body is potentially scrollable.] + expected: FAIL + + [scrollingElement in quirks should be body if any of document and body has a visible overflow.] + expected: FAIL + + [When body potentially scrollable, document.body.scrollHeight changes when changing the height of the body content in quirks.] + expected: FAIL + diff --git a/tests/wpt/metadata-layout-2020/css/cssom-view/MediaQueryList-addListener-handleEvent.html.ini b/tests/wpt/metadata-layout-2020/css/cssom-view/MediaQueryList-addListener-handleEvent.html.ini new file mode 100644 index 00000000000..434378ac0a7 --- /dev/null +++ b/tests/wpt/metadata-layout-2020/css/cssom-view/MediaQueryList-addListener-handleEvent.html.ini @@ -0,0 +1,19 @@ +[MediaQueryList-addListener-handleEvent.html] + [throws if handleEvent is falsy and not callable] + expected: FAIL + + [looks up handleEvent method on every event dispatch] + expected: FAIL + + [calls handleEvent method of event listener] + expected: FAIL + + [rethrows errors when getting handleEvent] + expected: FAIL + + [doesn't look up handleEvent method on callable event listeners] + expected: FAIL + + [throws if handleEvent is thruthy and not callable] + expected: FAIL + diff --git a/tests/wpt/metadata-layout-2020/css/cssom-view/MediaQueryList-addListener-removeListener.html.ini b/tests/wpt/metadata-layout-2020/css/cssom-view/MediaQueryList-addListener-removeListener.html.ini new file mode 100644 index 00000000000..f4b1d458a7f --- /dev/null +++ b/tests/wpt/metadata-layout-2020/css/cssom-view/MediaQueryList-addListener-removeListener.html.ini @@ -0,0 +1,19 @@ +[MediaQueryList-addListener-removeListener.html] + [removing listener from one MQL doesn't remove it from all MQLs] + expected: FAIL + + [listeners are called when