Skip to content

Comments

making image element areas good at finding areas#15904

Merged
bors-servo merged 1 commit intoservo:masterfrom
sendilkumarn:image-area
Apr 5, 2017
Merged

making image element areas good at finding areas#15904
bors-servo merged 1 commit intoservo:masterfrom
sendilkumarn:image-area

Conversation

@sendilkumarn
Copy link
Contributor

@sendilkumarn sendilkumarn commented Mar 10, 2017



This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmlimageelement.rs
  • @KiChjang: components/script/dom/htmlimageelement.rs

@highfive
Copy link

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 10, 2017

let map = self.upcast::<Node>()
.following_siblings()
.GetRootNode()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the document instead.

document_from_node(self).traverse_preorder()

Some(elements)
Some(elements)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be shorter as map.map(|elem| { ... }), probably with a different name for map, for clarity.

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 14, 2017
@nox
Copy link
Contributor

nox commented Mar 14, 2017

#15914 partly covers the same changes.

@nox nox assigned nox and unassigned asajeffrey Mar 14, 2017

let elements: Vec<Root<HTMLAreaElement>> = map.unwrap().upcast::<Node>()
.children()
match map {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map.and_then(|map_elem| {
    // elements ...
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not and_then, map.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, got confused by Some returning another Some

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 14, 2017
Copy link
Contributor

@nox nox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, one fix, and one refactor.

let map = self.upcast::<Node>()
.following_siblings()
let useMapElements = self.upcast::<Node>()
.GetRootNode()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the document here as I mentioned in my previous comment, also the indentation is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to replace node by document ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously nox had mentioned this,

document_from_node(self).traverse_preorder()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we have to cast the doc into node to traverse?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do.

document_from_node(self).upcast::<Node>().traverse_preorder()

Still better than using GetRootNode.


let map = self.upcast::<Node>()
.following_siblings()
let useMapElements = self.upcast::<Node>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: double space.

mapElem.upcast::<Node>()
.traverse_preorder()
.filter_map(Root::downcast::<HTMLAreaElement>).collect()
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I just realised that you should rather add a method on HTMLMapElement itself that returns the Vec<Root<HTMLAreaElement>>, and call it here.

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 15, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 15, 2017
@nox
Copy link
Contributor

nox commented Mar 15, 2017

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit 7a3644a with merge b32bef8...

bors-servo pushed a commit that referenced this pull request Mar 15, 2017
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 -->
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Mar 16, 2017
@jdm
Copy link
Member

jdm commented Mar 16, 2017

The only test that failed that wasn't recognized in that run was an instance of #14323.

@nox
Copy link
Contributor

nox commented Mar 16, 2017

@sendilkumarn The code is correct, but it needs a test.

@nox nox added S-needs-tests New tests have been requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 16, 2017
@sendilkumarn
Copy link
Contributor Author

I am on it.

@sendilkumarn
Copy link
Contributor Author

sendilkumarn commented Mar 17, 2017

@nox where / what you want to add in tests?

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 22, 2017
@sendilkumarn
Copy link
Contributor Author

@nox sorry for the delay. Here it is 👍

@ghost
Copy link

ghost commented Mar 25, 2017

Tidy fails.

./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:17: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:18: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:19: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:26: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:27: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:32: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:33: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:34: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:41: trailing whitespace
./tests/wpt/mozilla/tests/mozilla/img-find-areas.html:42: trailing whitespace

Also, the WPT manifest needs to be updated. Please read tests/wpt/README.md

@nox
Copy link
Contributor

nox commented Mar 28, 2017

@jdm Does the test look good to you?

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is a good start, but we can write it without timeouts and separate the cases that it is testing.

return true;
};
document.addEventListener("DOMContentLoaded", function() {
test.step(function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document.addEventListener("DOMContentLoaded", test.step_func(function() {
    img.click();
});

img.onclick = function(e) {
img_clicked = true;
return true;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

img.onclick = test.step_func_done();


<img usemap="#img_no_map" src="2x2.png" id="img_no"/>
<script>
var test = async_test("ImageShouldFindTheMapEvenWhenItIsNotItsSibiling");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_test("Image should find a non-sibling map")

</map>
<img usemap="#img_map" src="2x2.png" id="img"/>

<img usemap="#img_no_map" src="2x2.png" id="img_no"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

img and area elements are self-closing; we don't need the / at all.

});
test.step_timeout(function() {
assert_true(img_clicked, "Image click expected"); test.done();
}, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this with the earlier changes.


var img_no = document.getElementById('img_no');
var img_no_map_clicked = false;
img_no.onclick = function(e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

img_no.onclick = test2.unreached_func("click event should not be fired for image without map");

assert_true(img_clicked, "Image click expected"); test.done();
}, 500);

var img_no = document.getElementById('img_no');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should declare a separate async_test for the case with no map.

});
test.step_timeout(function() {
assert_false(img_no_map_clicked, "Image no map click expected"); test.done();
}, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document.addEventListener("DOMContentLoaded", test2.step(function() {
    img_no.click();
});
window.addEventListener("load", test2.step_func_done(function() {
    assert_false(img_no_map_clicked, "Image no map click expected");
});

@sendilkumarn sendilkumarn force-pushed the image-area branch 4 times, most recently from e76ad45 to d578772 Compare March 29, 2017 03:08
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
@sendilkumarn
Copy link
Contributor Author

Thanks @jdm for the awesome help 👍

@sendilkumarn
Copy link
Contributor Author

added tests and the builds are green.

@jdm
Copy link
Member

jdm commented Apr 5, 2017

@bors-servo: r+
Thanks!

@bors-servo
Copy link
Contributor

📌 Commit 31dafcc has been approved by jdm

@highfive highfive assigned jdm and unassigned nox Apr 5, 2017
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 5, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 31dafcc with merge c12b17d...

bors-servo pushed a commit that referenced this pull request Apr 5, 2017
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 -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-msvc-dev
Approved by: jdm
Pushing c12b17d to master...

@bors-servo bors-servo merged commit 31dafcc into servo:master Apr 5, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-needs-tests New tests have been requested by a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTMLImageElement::areas() doesn't seem very good at finding areas

6 participants