making image element areas good at finding areas

linting errors

replaced with map

fixes comments

moving to document

added test cases

linting and updating manifest

changing test cases

linting fixes

manifest update

linting fixes

splitting the test cases into two
This commit is contained in:
SendilKumar N 2017-03-10 13:55:24 +08:00
parent 5421d833de
commit 31dafcc5f3
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()
.filter_map(Root::downcast::<HTMLMapElement>)
.find(|n| n.upcast::<Element>().get_string_attribute(&LocalName::from("name")) == last);
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>