aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-07-07 11:21:16 -0700
committerGitHub <noreply@github.com>2017-07-07 11:21:16 -0700
commit6e2e7151d84804d4d630cecb1bf0a5ea2fe70e2b (patch)
treee11fcedfce323aaba281da52c5c20d26dd7aa22d /components/script
parent327e72aa149cdad347196f37bdb64c3afc5ae5e0 (diff)
parent420a7878b9c036830cffcd4dc8dbbf5e8d83e78e (diff)
downloadservo-6e2e7151d84804d4d630cecb1bf0a5ea2fe70e2b.tar.gz
servo-6e2e7151d84804d4d630cecb1bf0a5ea2fe70e2b.zip
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 -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/htmlareaelement.rs2
-rw-r--r--components/script/dom/htmlimageelement.rs60
2 files changed, 30 insertions, 32 deletions
diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs
index 9535fb060c2..0e3c26155fe 100644
--- a/components/script/dom/htmlareaelement.rs
+++ b/components/script/dom/htmlareaelement.rs
@@ -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) +
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index 6a4b67a6a92..1fc4f6249e0 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -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 {
- return
- };
+ if event.type_() != atom!("click") {
+ return
+ }
- // Fetch click coordinates
- let mouse_event = if let Some(x) = event.downcast::<MouseEvent>() {
- x
- } else {
- 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,
};
-
- 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
- }
+ if shp.hit_test(&point) {
+ element.activation_behavior(event, self.upcast());
+ return
}
}
}