Skip to content

Commit

Permalink
Don't crash when offset parent querying an element not in the document
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmabit committed Jan 13, 2017
1 parent 6623583 commit 18793af
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions components/layout/query.rs
Expand Up @@ -845,12 +845,11 @@ pub fn process_offset_parent_query<N: LayoutNode>(requested_node: N, layout_root
-> OffsetParentResponse {
let mut iterator = ParentOffsetBorderBoxIterator::new(requested_node.opaque());
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator);
// If we didn't find the node, something went wrong. Unwrap it.
let node_offset_box = iterator.node_offset_box.unwrap();

let node_offset_box = iterator.node_offset_box;
let parent_info_index = iterator.parent_nodes.iter().rposition(|info| info.is_some());
match parent_info_index {
Some(parent_info_index) => {
match (node_offset_box, parent_info_index) {
(Some(node_offset_box), Some(parent_info_index)) => {
let parent = iterator.parent_nodes[parent_info_index].as_ref().unwrap();
let origin = node_offset_box.offset - parent.border_box.origin;
let size = node_offset_box.rectangle.size;
Expand All @@ -859,7 +858,7 @@ pub fn process_offset_parent_query<N: LayoutNode>(requested_node: N, layout_root
rect: Rect::new(origin, size),
}
}
None => {
_ => {
OffsetParentResponse::empty()
}
}
Expand Down

0 comments on commit 18793af

Please sign in to comment.