Skip to content

Implement Document#elementsFromPoint - #10034

Merged
bors-servo merged 1 commit into
servo:masterfrom
luthfianto:implement-elementsfrompoint
Apr 4, 2016
Merged

bors-servo merged 1 commit into
servo:masterfrom
luthfianto:implement-elementsfrompoint

Conversation

@luthfianto

Copy link
Copy Markdown
Contributor

Fixes #9859.

I'm trying to implement Document#elementsFromPoint, which I need to reuse the get_nodes_under_mouse and mouse_over function which have been removed a days ago in #9715. So I added it back while I'm not sure if my implementation is correct. Any advice will be greatly appreciated.


This change is Reviewable

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify layout and 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 16, 2016
@emilio

emilio commented Mar 16, 2016

Copy link
Copy Markdown
Member

Good job! I've left a few comments :)

Let's see if there's any test for that,

@bors-servo: try

-S-awaiting-review +S-needs-code-changes


Review status: 0 of 4 files reviewed at latest revision, 4 unresolved discussions.


components/layout/query.rs, line 101 [r1] (raw file):
This conditional can be removed, since using .iter().map(..)will return an empty vector in this case regardless.


components/script/dom/document.rs, line 1498 [r1] (raw file):
I think this name is misleading, and should be called nodes_from_point, or return just the elements.


components/script/dom/document.rs, line 2610 [r1] (raw file):
Doing something like:

self.elements_from_point().iter().flat_map(|addr| {
    let node = node::from_untrusted_node_address(js_runtime, addr);
    node.downcast::<Element>()
}).collect();

Should be enough, the parent of a node that is not an element should already be in the list after it.

Your code might unexpectedly panic depending on which point are you using as input.


components/script/dom/document.rs, line 2624 [r1] (raw file):
Why do we need the clone and the unwrap here?

Can't we do:

if elements.last() != Some(root_element) {
    elements.push(root_element);
}

Or Some(&root_element) since last() returns a reference.


Comments from the review on Reviewable.io

@emilio emilio 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 16, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 0e639cc with merge d77aa2d...

bors-servo pushed a commit that referenced this pull request Mar 16, 2016
Implement Document#elementsFromPoint

Fixes #9859.

I'm trying to implement Document#elementsFromPoint, which I need to reuse the `get_nodes_under_mouse` and `mouse_over` function which have been removed a days ago in #9715. So I added it back while I'm not sure if my implementation is correct. Any advice will be greatly appreciated.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10034)
<!-- Reviewable:end -->
@emilio emilio assigned emilio and unassigned nox Mar 16, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - status-appveyor

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

jdm commented Mar 16, 2016

Copy link
Copy Markdown
Member

Looks like the non-windows platforms had no unexpected test results.

@jdm

jdm commented Mar 16, 2016

Copy link
Copy Markdown
Member

We are apparently ignoring the tests in tests/wpt/web-platform-tests/cssom-view/. Could you add that directory to tests/wpt/include.ini?

@luthfianto

Copy link
Copy Markdown
Contributor Author

Review status: 0 of 4 files reviewed at latest revision, 4 unresolved discussions.


components/script/dom/document.rs, line 1498 [r1] (raw file):
But nodes_from_point is already used. Should we rename the other function? To what name?


Comments from the review on Reviewable.io

@emilio

emilio commented Mar 16, 2016

Copy link
Copy Markdown
Member

Review status: 0 of 4 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


components/script/dom/document.rs, line 1498 [r1] (raw file):
Is it? I don't see any nodes_from_point in the impl Document... There shouldn't be any name conflict.


Comments from the review on Reviewable.io

@luthfianto

Copy link
Copy Markdown
Contributor Author

Review status: 0 of 4 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


components/script/dom/document.rs, line 1498 [r1] (raw file):
Oh right, there wouldn't be any name conflict


Comments from the review on Reviewable.io

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 17, 2016
@emilio

emilio commented Mar 17, 2016

Copy link
Copy Markdown
Member

Left a few more comments, let's see how the cssom tests go!

@bors-servo: try

-S-awaiting-review +S-needs-code-changes


Reviewed 2 of 4 files at r1, 3 of 3 files at r2.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/document.rs, line 2612 [r2] (raw file):
I think this is still not quite correct, you're asuming every node address returned here is an element. I think that might not be always true, that's why I suggested the flat_map (which "removes" the None values) instead of the unwrap().

I don't know if we include text nodes in the nodes_from_point traversal, but that'd be just one of the possible examples that could cause a crash.


tests/wpt/include.ini, line 58 [r2] (raw file):
Thanks for doing this! I don't think we pass every test in here so the expectations should be updated... I'll make a try run now :)


Comments from the review on Reviewable.io

@emilio emilio 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 17, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 2c8b247 with merge a53c40a...

bors-servo pushed a commit that referenced this pull request Mar 17, 2016
Implement Document#elementsFromPoint

Fixes #9859.

I'm trying to implement Document#elementsFromPoint, which I need to reuse the `get_nodes_under_mouse` and `mouse_over` function which have been removed a days ago in #9715. So I added it back while I'm not sure if my implementation is correct. Any advice will be greatly appreciated.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10034)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Mar 17, 2016
@emilio

emilio commented Mar 18, 2016

Copy link
Copy Markdown
Member
CRASH [expected OK] /cssom-view/elementsFromPoint.html

Heh, that's it, we can't assume every node returned by nodes_from_point is an element.

@luthfianto

Copy link
Copy Markdown
Contributor Author

Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


components/script/dom/document.rs, line 2612 [r2] (raw file):
Right, but I couldn't use flat_map because the trait core::iter::Iterator is not implemented for the type dom::bindings::js::Root<dom::element::Element>


Comments from the review on Reviewable.io

@luthfianto

Copy link
Copy Markdown
Contributor Author

components/script/dom/document.rs, line 2612 [r2] (raw file):
Never mind. Suppose

let mut elements: Vec<_> = self.nodes_from_point(point).iter()
    .flat_map(|&untrusted_node_address| {
        let node = node::from_untrusted_node_address(js_runtime, untrusted_node_address);
        let element=node.downcast::<Element>();
        element
}).collect();

How do I make node live long enough? clone?


Comments from the review on Reviewable.io

@jdm

jdm commented Apr 3, 2016

Copy link
Copy Markdown
Member

I think the problem is the unanswered question.

@luthfianto

Copy link
Copy Markdown
Contributor Author

@nox thanks, not really. It's what @jdm said

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Apr 3, 2016
@KiChjang KiChjang removed the S-needs-rebase There are merge conflict errors. label Apr 3, 2016
@KiChjang

KiChjang commented Apr 3, 2016

Copy link
Copy Markdown
Contributor

@bors-servo r=emilio

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 07584b9 has been approved by emilio

@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 3, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 07584b9 with merge d7f4327...

bors-servo pushed a commit that referenced this pull request Apr 3, 2016
Implement Document#elementsFromPoint

Fixes #9859.

I'm trying to implement Document#elementsFromPoint, which I need to reuse the `get_nodes_under_mouse` and `mouse_over` function which have been removed a days ago in #9715. So I added it back while I'm not sure if my implementation is correct. Any advice will be greatly appreciated.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10034)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - status-appveyor

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Apr 3, 2016
@KiChjang

KiChjang commented Apr 3, 2016

Copy link
Copy Markdown
Contributor

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 07584b9 with merge c363817...

bors-servo pushed a commit that referenced this pull request Apr 4, 2016
Implement Document#elementsFromPoint

Fixes #9859.

I'm trying to implement Document#elementsFromPoint, which I need to reuse the `get_nodes_under_mouse` and `mouse_over` function which have been removed a days ago in #9715. So I added it back while I'm not sure if my implementation is correct. Any advice will be greatly appreciated.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10034)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Apr 4, 2016
@Ms2ger

Ms2ger commented Apr 4, 2016

Copy link
Copy Markdown
Contributor

@bors-servo retry

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 07584b9 with merge 241518a...

bors-servo pushed a commit that referenced this pull request Apr 4, 2016
Implement Document#elementsFromPoint

Fixes #9859.

I'm trying to implement Document#elementsFromPoint, which I need to reuse the `get_nodes_under_mouse` and `mouse_over` function which have been removed a days ago in #9715. So I added it back while I'm not sure if my implementation is correct. Any advice will be greatly appreciated.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10034)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, status-appveyor

@bors-servo
bors-servo merged commit 07584b9 into servo:master Apr 4, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 4, 2016
@luthfianto

Copy link
Copy Markdown
Contributor Author

Thanks, Servo team 🎉.

I'll proceed with #.10093

bors-servo pushed a commit that referenced this pull request Apr 15, 2016
…ble-test, r=nox

Fix Document#elementsFromPoint no viewport available test

Fixes #10093 and improves #10034.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10426)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants