Return the result from DisplayItem::hit_test().

This commit is contained in:
Ms2ger 2016-06-28 16:58:36 +02:00
parent ae064dc7c1
commit 4e8ff4f9bc

View file

@ -636,13 +636,17 @@ impl StackingContext {
for child in self.children.iter() { for child in self.children.iter() {
while let Some(item) = traversal.advance(self) { while let Some(item) = traversal.advance(self) {
item.hit_test(point, result); if let Some(meta) = item.hit_test(point) {
result.push(meta);
}
} }
child.hit_test(traversal, &point, scroll_offsets, result); child.hit_test(traversal, &point, scroll_offsets, result);
} }
while let Some(item) = traversal.advance(self) { while let Some(item) = traversal.advance(self) {
item.hit_test(point, result); if let Some(meta) = item.hit_test(point) {
result.push(meta);
}
} }
} }
@ -1331,21 +1335,21 @@ impl DisplayItem {
println!("{}+ {:?}", indent, self); println!("{}+ {:?}", indent, self);
} }
fn hit_test(&self, point: Point2D<Au>, result: &mut Vec<DisplayItemMetadata>) { fn hit_test(&self, point: Point2D<Au>) -> Option<DisplayItemMetadata> {
// TODO(pcwalton): Use a precise algorithm here. This will allow us to properly hit // TODO(pcwalton): Use a precise algorithm here. This will allow us to properly hit
// test elements with `border-radius`, for example. // test elements with `border-radius`, for example.
let base_item = self.base(); let base_item = self.base();
if !base_item.clip.might_intersect_point(&point) { if !base_item.clip.might_intersect_point(&point) {
// Clipped out. // Clipped out.
return; return None;
} }
if !self.bounds().contains(&point) { if !self.bounds().contains(&point) {
// Can't possibly hit. // Can't possibly hit.
return; return None;
} }
if base_item.metadata.pointing.is_none() { if base_item.metadata.pointing.is_none() {
// `pointer-events` is `none`. Ignore this item. // `pointer-events` is `none`. Ignore this item.
return; return None;
} }
match *self { match *self {
@ -1364,18 +1368,17 @@ impl DisplayItem {
(border.border_widths.top + (border.border_widths.top +
border.border_widths.bottom))); border.border_widths.bottom)));
if interior_rect.contains(&point) { if interior_rect.contains(&point) {
return; return None;
} }
} }
DisplayItem::BoxShadowClass(_) => { DisplayItem::BoxShadowClass(_) => {
// Box shadows can never be hit. // Box shadows can never be hit.
return return None;
} }
_ => {} _ => {}
} }
// We found a hit! Some(base_item.metadata)
result.push(base_item.metadata);
} }
} }