Auto merge of #15904 - sendilkumarn:image-area, r=jdm

making image element areas good at finding areas

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

---
<!-- 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 #15884

<!-- 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/15904)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-05 08:49:22 -05:00 committed by GitHub
commit c12b17d276
5 changed files with 74 additions and 9 deletions

View file

@ -429,16 +429,12 @@ impl HTMLImageElement {
return None
}
let map = self.upcast::<Node>()
.following_siblings()
let useMapElements = document_from_node(self).upcast::<Node>()
.traverse_preorder()
.filter_map(Root::downcast::<HTMLMapElement>)
.find(|n| n.upcast::<Element>().get_string_attribute(&LocalName::from("name")) == last);
let elements: Vec<Root<HTMLAreaElement>> = map.unwrap().upcast::<Node>()
.children()
.filter_map(Root::downcast::<HTMLAreaElement>)
.collect();
Some(elements)
useMapElements.map(|mapElem| mapElem.get_area_elements())
}
}

View file

@ -3,9 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::HTMLMapElementBinding;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::htmlareaelement::HTMLAreaElement;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom_struct::dom_struct;
@ -33,4 +35,11 @@ impl HTMLMapElement {
document,
HTMLMapElementBinding::Wrap)
}
pub fn get_area_elements(&self) -> Vec<Root<HTMLAreaElement>> {
self.upcast::<Node>()
.traverse_preorder()
.filter_map(Root::downcast::<HTMLAreaElement>).collect()
}
}

View file

@ -12960,12 +12960,24 @@
{}
]
],
"mozilla/img_find_non_sibling_map.html": [
[
"/_mozilla/mozilla/img_find_non_sibling_map.html",
{}
]
],
"mozilla/img_multiple_request.html": [
[
"/_mozilla/mozilla/img_multiple_request.html",
{}
]
],
"mozilla/img_no_panic_on_no_map.html": [
[
"/_mozilla/mozilla/img_no_panic_on_no_map.html",
{}
]
],
"mozilla/img_width_height.html": [
[
"/_mozilla/mozilla/img_width_height.html",
@ -25489,10 +25501,18 @@
"3c4f36abed83367c851d943b1f25b8394de6fe75",
"testharness"
],
"mozilla/img_find_non_sibling_map.html": [
"d34100c4cc22adcaa1014095ba4b7b929b8e079d",
"testharness"
],
"mozilla/img_multiple_request.html": [
"0a6263ad87c9b3307f2dc694747b094a0517b79b",
"testharness"
],
"mozilla/img_no_panic_on_no_map.html": [
"be2ae22f4664b4577224ba6c7f3c4df8589c160a",
"testharness"
],
"mozilla/img_width_height.html": [
"37a04735261a6d2b36c3d529ce81eda46ed6967e",
"testharness"

View file

@ -0,0 +1,22 @@
<!doctype html>
<meta charset="utf-8">
<title>Test for issue #15884</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<map name="img_map" id="img_map">
<area shape="rect" coords="0,0,100,100">
</map>
<img usemap="#img_map" src="2x2.png" id="img">
<img usemap="#img_no_map" src="2x2.png" id="img_no">
<script>
var siblingTest = async_test("Image should find a non-sibling map");
var img = document.getElementById('img');
var img_clicked = false;
img.onclick = siblingTest.step_func_done();
document.addEventListener("DOMContentLoaded", siblingTest.step_func(function() {
img.click();
}));
</script>
</body>

View file

@ -0,0 +1,18 @@
<!doctype html>
<meta charset="utf-8">
<title>Test for issue #15884</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<img usemap="#img_no_map" src="2x2.png" id="img_no">
<script>
var noMapTest = async_test("Image should not panic when no map is found");
var img_no = document.getElementById('img_no');
var img_no_map_clicked = false;
img_no.onclick = noMapTest.step_func_done();
document.addEventListener("DOMContentLoaded", noMapTest.step(function() {
img_no.click();
}));
</script>
</body>
</html>