mirror of
https://github.com/servo/servo.git
synced 2025-09-27 23:30:08 +01:00
layout: Use ServoThreadSafeLayoutNode
in more places (#38626)
Use `ServoThreadSafeLayoutNode` in more places in layout rather than `ServoLayoutNode`. The former is meant to be used during layout, but layout 2020 was written against the latter. In general, this reduces the amount of conversion to the thread-safe version in many places in layout. In addition, an unused iterator from the `script` crate `ServoThreadSafeLayoutNodeChildrenIterator` is replaced with the child iterator from `layout`. The `layout` version must be directly in `script` now as it uses the dangerous variants of `next_sibling` and `first_child`, which allow encapsulating the unsafe bits into one module. This will ultimately be useful for storing the layout data of pseudo-element children of pseudo-elements properly. Testing: This should not change any behavior and thus is covered by existing tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
20ad1ce84e
commit
ee7c1d9109
20 changed files with 258 additions and 321 deletions
|
@ -12,7 +12,7 @@ use euclid::{SideOffsets2D, Size2D};
|
|||
use itertools::Itertools;
|
||||
use layout_api::wrapper_traits::{LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
|
||||
use layout_api::{LayoutElementType, LayoutNodeType, OffsetParentResponse};
|
||||
use script::layout_dom::ServoLayoutNode;
|
||||
use script::layout_dom::{ServoLayoutNode, ServoThreadSafeLayoutNode};
|
||||
use servo_arc::Arc as ServoArc;
|
||||
use servo_geometry::{FastLayoutTransform, au_rect_to_f32_rect, f32_rect_to_au_rect};
|
||||
use servo_url::ServoUrl;
|
||||
|
@ -53,7 +53,7 @@ use crate::taffy::SpecificTaffyGridInfo;
|
|||
/// calculate its cumlative transform from its root scroll node to the scroll node.
|
||||
fn root_transform_for_layout_node(
|
||||
scroll_tree: &ScrollTree,
|
||||
node: ServoLayoutNode<'_>,
|
||||
node: ServoThreadSafeLayoutNode<'_>,
|
||||
) -> Option<FastLayoutTransform> {
|
||||
let fragments = node.fragments_for_pseudo(None);
|
||||
let box_fragment = fragments
|
||||
|
@ -69,7 +69,7 @@ fn root_transform_for_layout_node(
|
|||
|
||||
pub(crate) fn process_content_box_request(
|
||||
stacking_context_tree: &StackingContextTree,
|
||||
node: ServoLayoutNode<'_>,
|
||||
node: ServoThreadSafeLayoutNode<'_>,
|
||||
) -> Option<Rect<Au>> {
|
||||
let rects: Vec<_> = node
|
||||
.fragments_for_pseudo(None)
|
||||
|
@ -94,7 +94,7 @@ pub(crate) fn process_content_box_request(
|
|||
|
||||
pub(crate) fn process_content_boxes_request(
|
||||
stacking_context_tree: &StackingContextTree,
|
||||
node: ServoLayoutNode<'_>,
|
||||
node: ServoThreadSafeLayoutNode<'_>,
|
||||
) -> Vec<Rect<Au>> {
|
||||
let fragments = node.fragments_for_pseudo(None);
|
||||
let content_boxes = fragments
|
||||
|
@ -113,7 +113,7 @@ pub(crate) fn process_content_boxes_request(
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn process_client_rect_request(node: ServoLayoutNode<'_>) -> Rect<i32> {
|
||||
pub fn process_client_rect_request(node: ServoThreadSafeLayoutNode<'_>) -> Rect<i32> {
|
||||
node.fragments_for_pseudo(None)
|
||||
.first()
|
||||
.map(Fragment::client_rect)
|
||||
|
@ -122,7 +122,7 @@ pub fn process_client_rect_request(node: ServoLayoutNode<'_>) -> Rect<i32> {
|
|||
|
||||
/// <https://drafts.csswg.org/cssom-view/#scrolling-area>
|
||||
pub fn process_node_scroll_area_request(
|
||||
requested_node: Option<ServoLayoutNode<'_>>,
|
||||
requested_node: Option<ServoThreadSafeLayoutNode<'_>>,
|
||||
fragment_tree: Option<Rc<FragmentTree>>,
|
||||
) -> Rect<i32> {
|
||||
let Some(tree) = fragment_tree else {
|
||||
|
@ -311,7 +311,8 @@ pub fn process_resolved_style_request(
|
|||
.to_css_string()
|
||||
};
|
||||
|
||||
node.fragments_for_pseudo(*pseudo)
|
||||
node.to_threadsafe()
|
||||
.fragments_for_pseudo(*pseudo)
|
||||
.first()
|
||||
.map(resolve_for_fragment)
|
||||
.unwrap_or_else(|| computed_style(None))
|
||||
|
@ -484,7 +485,11 @@ fn offset_parent_fragments(node: ServoLayoutNode<'_>) -> Option<OffsetParentFrag
|
|||
// * The element is the root element.
|
||||
// * The element is the HTML body element.
|
||||
// * The element’s computed value of the position property is fixed.
|
||||
let fragment = node.fragments_for_pseudo(None).first().cloned()?;
|
||||
let fragment = node
|
||||
.to_threadsafe()
|
||||
.fragments_for_pseudo(None)
|
||||
.first()
|
||||
.cloned()?;
|
||||
let flags = fragment.base()?.flags;
|
||||
if flags.intersects(
|
||||
FragmentFlags::IS_ROOT_ELEMENT | FragmentFlags::IS_BODY_ELEMENT_OF_HTML_ELEMENT_ROOT,
|
||||
|
@ -507,14 +512,22 @@ fn offset_parent_fragments(node: ServoLayoutNode<'_>) -> Option<OffsetParentFrag
|
|||
while let Some(parent_node) = maybe_parent_node {
|
||||
maybe_parent_node = parent_node.parent_node();
|
||||
|
||||
if let Some(parent_fragment) = parent_node.fragments_for_pseudo(None).first() {
|
||||
if let Some(parent_fragment) = parent_node
|
||||
.to_threadsafe()
|
||||
.fragments_for_pseudo(None)
|
||||
.first()
|
||||
{
|
||||
let parent_fragment = match parent_fragment {
|
||||
Fragment::Box(box_fragment) | Fragment::Float(box_fragment) => box_fragment,
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
let grandparent_fragment =
|
||||
maybe_parent_node.and_then(|node| node.fragments_for_pseudo(None).first().cloned());
|
||||
let grandparent_fragment = maybe_parent_node.and_then(|node| {
|
||||
node.to_threadsafe()
|
||||
.fragments_for_pseudo(None)
|
||||
.first()
|
||||
.cloned()
|
||||
});
|
||||
|
||||
if parent_fragment.borrow().style.get_box().position != Position::Static {
|
||||
return Some(OffsetParentFragments {
|
||||
|
@ -557,7 +570,11 @@ pub fn process_offset_parent_query(node: ServoLayoutNode<'_>) -> Option<OffsetPa
|
|||
// [1]: https://github.com/w3c/csswg-drafts/issues/4541
|
||||
// > 1. If the element is the HTML body element or does not have any associated CSS
|
||||
// layout box return zero and terminate this algorithm.
|
||||
let fragment = node.fragments_for_pseudo(None).first().cloned()?;
|
||||
let fragment = node
|
||||
.to_threadsafe()
|
||||
.fragments_for_pseudo(None)
|
||||
.first()
|
||||
.cloned()?;
|
||||
let mut border_box = fragment.cumulative_border_box_rect()?;
|
||||
|
||||
// 2. If the offsetParent of the element is null return the x-coordinate of the left
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue