Skip to content

Commit

Permalink
Answer content box queries for layout_2020 for the root element
Browse files Browse the repository at this point in the history
This isn't correct yet, but it is necessary to give a value in order for
scrolling from script to work. Later this should give an accurate
content box response as well as work for non-root elements.
  • Loading branch information
mrobinson committed Jan 21, 2020
1 parent 27e0400 commit 1cd772f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
41 changes: 40 additions & 1 deletion components/layout_2020/flow/root.rs
Expand Up @@ -18,7 +18,8 @@ use crate::replaced::ReplacedContent;
use crate::sizing::ContentSizesRequest;
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside};
use crate::DefiniteContainingBlock;
use euclid::Size2D;
use app_units::Au;
use euclid::default::{Point2D, Rect, Size2D};
use gfx_traits::print_tree::PrintTree;
use script_layout_interface::wrapper_traits::LayoutNode;
use servo_arc::Arc;
Expand All @@ -35,6 +36,9 @@ pub struct FragmentTreeRoot {

/// The scrollable overflow of the root of the fragment tree.
scrollable_overflow: physical::Rect<Length>,

/// The axis-aligned bounding box of the border box of all child fragments
bounding_box_of_border_boxes: physical::Rect<Length>,
}

impl BoxTreeRoot {
Expand Down Expand Up @@ -165,9 +169,32 @@ impl BoxTreeRoot {
acc.axis_aligned_bounding_box(&child_overflow)
});

let containing_block = physical::Rect::zero();
let bounding_box_of_border_boxes =
independent_layout
.fragments
.iter()
.fold(physical::Rect::zero(), |acc, child| {
acc.axis_aligned_bounding_box(&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,
}
}
}
Expand Down Expand Up @@ -206,4 +233,16 @@ impl FragmentTreeRoot {
self.scrollable_overflow.size.y.px(),
))
}

pub fn bounding_box_of_border_boxes(&self) -> Rect<Au> {
let origin = Point2D::new(
Au::from_f32_px(self.bounding_box_of_border_boxes.top_left.x.px()),
Au::from_f32_px(self.bounding_box_of_border_boxes.top_left.y.px()),
);
let size = Size2D::new(
Au::from_f32_px(self.bounding_box_of_border_boxes.size.x.px()),
Au::from_f32_px(self.bounding_box_of_border_boxes.size.y.px()),
);
Rect::new(origin, size)
}
}
12 changes: 10 additions & 2 deletions components/layout_2020/query.rs
Expand Up @@ -5,6 +5,7 @@
//! Utilities for querying the layout, as needed by the layout thread.

use crate::context::LayoutContext;
use crate::flow::FragmentTreeRoot;
use app_units::Au;
use euclid::default::{Point2D, Rect};
use euclid::Size2D;
Expand Down Expand Up @@ -163,8 +164,15 @@ impl LayoutRPC for LayoutRPCImpl {
}
}

pub fn process_content_box_request(_requested_node: OpaqueNode) -> Option<Rect<Au>> {
None
pub fn process_content_box_request(
_requested_node: OpaqueNode,
fragment_tree_root: Option<&FragmentTreeRoot>,
) -> Option<Rect<Au>> {
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())
}

pub fn process_content_boxes_request(_requested_node: OpaqueNode) -> Vec<Rect<Au>> {
Expand Down
13 changes: 8 additions & 5 deletions components/layout_thread_2020/lib.rs
Expand Up @@ -46,7 +46,7 @@ use layout::query::{
process_text_index_request,
};
use layout::traversal::RecalcStyle;
use layout::BoxTreeRoot;
use layout::{BoxTreeRoot, FragmentTreeRoot};
use layout_traits::LayoutThreadFactory;
use libc::c_void;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
Expand Down Expand Up @@ -172,10 +172,10 @@ pub struct LayoutThread {
outstanding_web_fonts: Arc<AtomicUsize>,

/// The root of the box tree.
box_tree_root: RefCell<Option<layout::BoxTreeRoot>>,
box_tree_root: RefCell<Option<BoxTreeRoot>>,

/// The root of the fragment tree.
fragment_tree_root: RefCell<Option<layout::FragmentTreeRoot>>,
fragment_tree_root: RefCell<Option<FragmentTreeRoot>>,

/// The document-specific shared lock used for author-origin stylesheets
document_shared_lock: Option<SharedRwLock>,
Expand Down Expand Up @@ -1218,7 +1218,10 @@ impl LayoutThread {
match *reflow_goal {
ReflowGoal::LayoutQuery(ref querymsg, _) => match querymsg {
&QueryMsg::ContentBoxQuery(node) => {
rw_data.content_box_response = process_content_box_request(node);
rw_data.content_box_response = process_content_box_request(
node,
(&*self.fragment_tree_root.borrow()).as_ref(),
);
},
&QueryMsg::ContentBoxesQuery(node) => {
rw_data.content_boxes_response = process_content_boxes_request(node);
Expand Down Expand Up @@ -1355,7 +1358,7 @@ impl LayoutThread {

fn perform_post_style_recalc_layout_passes(
&self,
fragment_tree: &layout::FragmentTreeRoot,
fragment_tree: &FragmentTreeRoot,
reflow_goal: &ReflowGoal,
document: Option<&ServoLayoutDocument>,
context: &mut LayoutContext,
Expand Down

0 comments on commit 1cd772f

Please sign in to comment.