servo: Merge #12841 - Fix hit testing to take into account nested stacking contexts #12777 (from emilio:hit-test); r=pcwalton

<!-- Please describe your changes on the following line: -->

Fixes #12833.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #12833 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 9b4713f5366aa43ac0db6a8f1d96f33b2f527978
This commit is contained in:
Emilio Cobos Álvarez 2016-08-25 13:44:27 -05:00
parent f910293bda
commit 4b5727104d

View File

@ -719,28 +719,32 @@ impl StackingContext {
geometry::f32_rect_to_au_rect(overflow) geometry::f32_rect_to_au_rect(overflow)
} }
pub fn hit_test<'a>(&self, fn hit_test<'a>(&self,
traversal: &mut DisplayListTraversal<'a>, traversal: &mut DisplayListTraversal<'a>,
translated_point: &Point2D<Au>, translated_point: &Point2D<Au>,
client_point: &Point2D<Au>, client_point: &Point2D<Au>,
scroll_offsets: &ScrollOffsetMap, scroll_offsets: &ScrollOffsetMap,
result: &mut Vec<DisplayItemMetadata>) { result: &mut Vec<DisplayItemMetadata>) {
let is_fixed = match self.layer_info { let is_fixed = match self.layer_info {
Some(ref layer_info) => layer_info.scroll_policy == ScrollPolicy::FixedPosition, Some(ref layer_info) => layer_info.scroll_policy == ScrollPolicy::FixedPosition,
None => false, None => false,
}; };
let effective_point = if is_fixed { client_point } else { translated_point }; // Convert the parent translated point into stacking context local
// transform space if the stacking context isn't fixed.
// Convert the point into stacking context local transform space. //
let mut point = if self.context_type == StackingContextType::Real { // If it's fixed, we need to use the client point anyway, and if it's a
let point = *effective_point - self.bounds.origin; // pseudo-stacking context, our parent's is enough.
let mut translated_point = if is_fixed {
*client_point
} else if self.context_type == StackingContextType::Real {
let point = *translated_point - self.bounds.origin;
let inv_transform = self.transform.inverse().unwrap(); let inv_transform = self.transform.inverse().unwrap();
let frac_point = inv_transform.transform_point(&Point2D::new(point.x.to_f32_px(), let frac_point = inv_transform.transform_point(&Point2D::new(point.x.to_f32_px(),
point.y.to_f32_px())); point.y.to_f32_px()));
Point2D::new(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y)) Point2D::new(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y))
} else { } else {
*effective_point *translated_point
}; };
// Adjust the translated point to account for the scroll offset if // Adjust the translated point to account for the scroll offset if
@ -751,22 +755,23 @@ impl StackingContext {
// `Window::hit_test_query()`) by now. // `Window::hit_test_query()`) by now.
if !is_fixed && self.id != StackingContextId::root() { if !is_fixed && self.id != StackingContextId::root() {
if let Some(scroll_offset) = scroll_offsets.get(&self.id) { if let Some(scroll_offset) = scroll_offsets.get(&self.id) {
point.x -= Au::from_f32_px(scroll_offset.x); translated_point.x -= Au::from_f32_px(scroll_offset.x);
point.y -= Au::from_f32_px(scroll_offset.y); translated_point.y -= Au::from_f32_px(scroll_offset.y);
} }
} }
for child in self.children() { for child in self.children() {
while let Some(item) = traversal.advance(self) { while let Some(item) = traversal.advance(self) {
if let Some(meta) = item.hit_test(point) { if let Some(meta) = item.hit_test(translated_point) {
result.push(meta); result.push(meta);
} }
} }
child.hit_test(traversal, translated_point, client_point, scroll_offsets, result); child.hit_test(traversal, &translated_point, client_point,
scroll_offsets, result);
} }
while let Some(item) = traversal.advance(self) { while let Some(item) = traversal.advance(self) {
if let Some(meta) = item.hit_test(point) { if let Some(meta) = item.hit_test(translated_point) {
result.push(meta); result.push(meta);
} }
} }