mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #17632 - omakk:master, r=jdm
Clean up HTMLImageElement::handle_event Reflects desired changes in #15832 <!-- Please describe your changes on the following line: --> Cleans up `HTMLImageElement::handle_event` located in `components/script/dom/htmlimageelement.rs` --- <!-- 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 #15832 - [X] These changes do not require tests because this change maintains the same logic <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17632) <!-- Reviewable:end -->
This commit is contained in:
commit
6e2e7151d8
3 changed files with 37 additions and 39 deletions
|
@ -167,7 +167,7 @@ impl Area {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn hit_test(&self, p: Point2D<f32>) -> bool {
|
||||
pub fn hit_test(&self, p: &Point2D<f32>) -> bool {
|
||||
match *self {
|
||||
Area::Circle { left, top, radius } => {
|
||||
(p.x - left) * (p.x - left) +
|
||||
|
|
|
@ -954,39 +954,37 @@ impl VirtualMethods for HTMLImageElement {
|
|||
}
|
||||
|
||||
fn handle_event(&self, event: &Event) {
|
||||
if event.type_() == atom!("click") {
|
||||
let area_elements = self.areas();
|
||||
let elements = if let Some(x) = area_elements {
|
||||
x
|
||||
} else {
|
||||
if event.type_() != atom!("click") {
|
||||
return
|
||||
}
|
||||
|
||||
let area_elements = self.areas();
|
||||
let elements = match area_elements {
|
||||
Some(x) => x,
|
||||
None => return,
|
||||
};
|
||||
|
||||
// Fetch click coordinates
|
||||
let mouse_event = match event.downcast::<MouseEvent>() {
|
||||
Some(x) => x,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let point = Point2D::new(mouse_event.ClientX().to_f32().unwrap(),
|
||||
mouse_event.ClientY().to_f32().unwrap());
|
||||
let bcr = self.upcast::<Element>().GetBoundingClientRect();
|
||||
let bcr_p = Point2D::new(bcr.X() as f32, bcr.Y() as f32);
|
||||
|
||||
// Walk HTMLAreaElements
|
||||
for element in elements {
|
||||
let shape = element.get_shape_from_coords();
|
||||
let shp = match shape {
|
||||
Some(x) => x.absolute_coords(bcr_p),
|
||||
None => return,
|
||||
};
|
||||
if shp.hit_test(&point) {
|
||||
element.activation_behavior(event, self.upcast());
|
||||
return
|
||||
};
|
||||
|
||||
// Fetch click coordinates
|
||||
let mouse_event = if let Some(x) = event.downcast::<MouseEvent>() {
|
||||
x
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let point = Point2D::new(mouse_event.ClientX().to_f32().unwrap(),
|
||||
mouse_event.ClientY().to_f32().unwrap());
|
||||
|
||||
// Walk HTMLAreaElements
|
||||
for element in elements {
|
||||
let shape = element.get_shape_from_coords();
|
||||
let p = Point2D::new(self.upcast::<Element>().GetBoundingClientRect().X() as f32,
|
||||
self.upcast::<Element>().GetBoundingClientRect().Y() as f32);
|
||||
|
||||
let shp = if let Some(x) = shape {
|
||||
x.absolute_coords(p)
|
||||
} else {
|
||||
return
|
||||
};
|
||||
if shp.hit_test(point) {
|
||||
element.activation_behavior(event, self.upcast());
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue