Skip to content

Implement Document#elementFromPoint - #8932

Merged
bors-servo merged 1 commit into
servo:masterfrom
luthfianto:add-elementfrompoint
Feb 29, 2016
Merged

bors-servo merged 1 commit into
servo:masterfrom
luthfianto:add-elementfrompoint

Conversation

@luthfianto

Copy link
Copy Markdown
Contributor

Related to #8666. I haven't implemented elementsFromPoint, because from my past discussion with jdm, it's not good yet to implement elementsFromPoint because it may cause GC hazards.

By the way, I also have to include the test for this, right? I've found this [1]. So, is all I have to do is just to put this into tests/wpt/web-platform-tests/cssom-view/elementFromPoint.html?

[1] http://test.csswg.org/suites/cssom-view-1_dev/nightly-unstable/html/elementFromPosition.htm

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 11, 2015
@nox nox added the S-needs-code-changes Changes have not yet been made that were requested by a reviewer. label Dec 11, 2015
@nox

nox commented Dec 11, 2015

Copy link
Copy Markdown
Contributor
/home/travis/build/servo/servo/components/script/dom/document.rs:2443:26: 2443:56 error: call to unsafe function requires unsafe function or block [E0133]
/home/travis/build/servo/servo/components/script/dom/document.rs:2443         let js_runtime = JS_GetRuntime(window.get_cx());
                                                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/servo/servo/components/script/dom/document.rs:2443:26: 2443:56 help: run `rustc --explain E0133` to see a detailed explanation

@highfive highfive removed the S-needs-code-changes Changes have not yet been made that were requested by a reviewer. label Dec 11, 2015
@nox

nox commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

Thanks for the contribution!

Where is the step 3 handled?

If the document has a root element, return the root element and terminate these steps.

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


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


components/script/dom/document.rs, line 2436 [r1] (raw file):
This is the documentation link for elementsFromPoint.


components/script/dom/document.rs, line 2445 [r1] (raw file):
Please do this before defining point and js_runtime. Also or is || and you should put spaces around the actual comparison operators. The spaces are also redundant.


components/script/dom/document.rs, line 2449 [r2] (raw file):
The type annotation is useless.


components/script/dom/document.rs, line 2452 [r2] (raw file):
What if it isn't an Element?


components/script/dom/document.rs, line 2454 [r2] (raw file):
The spaces are superfluous.


Comments from the review on Reviewable.io

@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 Dec 13, 2015
@nox

nox commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

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


Comments from the review on Reviewable.io

@nox nox self-assigned this Dec 13, 2015
@luthfianto

Copy link
Copy Markdown
Contributor Author

@nox

nox commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

Review status: all files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/document.rs, line 2436 [r1] (raw file):
Never mind this one, you had fixed it before I published my comments.


components/script/dom/document.rs, line 2436 [r2] (raw file):
Nit: move this after the comment.


Comments from the review on Reviewable.io

@luthfianto

Copy link
Copy Markdown
Contributor Author

components/script/dom/document.rs, line 2452 [r2] (raw file):
Pardon, like what? From what I know, I'm downcasting Root to Root. You mean, could it be None?


Comments from the review on Reviewable.io

@luthfianto

Copy link
Copy Markdown
Contributor Author

components/script/dom/document.rs, line 2452 [r2] (raw file):
Root to Root *


Comments from the review on Reviewable.io

@luthfianto

Copy link
Copy Markdown
Contributor Author

Oh ok, looks like I haven't handled that


Comments from the review on Reviewable.io

@nox

nox commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

@rilut As a side note, one of the features of Reviewable is that you don't need to publish each comment separately. Just reply or handle all of them, and then publish all your replies at once with the green button on the top of their UI.

@luthfianto

Copy link
Copy Markdown
Contributor Author

@nox Yeah, I'm looking for that too haha. Sorry it's my first time

@nox

nox commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

No problem. :) We all had to learn that at some point.


Review status: all files reviewed at latest revision, 1 unresolved discussion.


components/script/dom/document.rs, line 2452 [r2] (raw file):
It can be None yeah. But my initial question was silly, because it can only be an Element and not a Text node, right?


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-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 13, 2015
@luthfianto

Copy link
Copy Markdown
Contributor Author

components/script/dom/document.rs, line 2436 [r2] (raw file):
Turns out it fails tidy. The spec comment should be right above the function name


Comments from the review on Reviewable.io

@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 Dec 13, 2015
@nox

nox commented Dec 13, 2015

Copy link
Copy Markdown
Contributor

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


Reviewed 1 of 1 files at r4.
Review status: all files reviewed at latest revision, 3 unresolved discussions.


components/script/dom/document.rs, line 2436 [r2] (raw file):
Sorry for this.


components/script/dom/document.rs, line 2445 [r4] (raw file):
Please remove the parentheses and put spaces around ||


components/script/dom/document.rs, line 2451 [r4] (raw file):
hit_test can return None, in which case we shouldn't unwrap. This is the place where the step 3 should be done.


Comments from the review on Reviewable.io

@luthfianto

Copy link
Copy Markdown
Contributor Author

Review status: all files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/document.rs, line 2445 [r4] (raw file):
Whoa I got it backward


components/script/dom/document.rs, line 2451 [r4] (raw file):
something like this?

match self.hit_test(point) {
    Some(untrusted_node_address) => {
        let rootnode =
            node::from_untrusted_node_address(js_runtime, untrusted_node_address);

        match rootnode.downcast::<Element>() {
            Some(element_ref) => Some(Root::from_ref(element_ref)),
            None => None,
        }
    },
    None => None,
}

Comments from the review on Reviewable.io

@luthfianto

Copy link
Copy Markdown
Contributor Author

components/script/dom/document.rs, line 2451 [r4] (raw file):
or should we use unwrap_or_else?


Comments from the review on Reviewable.io

@Ms2ger

Ms2ger commented Dec 13, 2015

Copy link
Copy Markdown
Contributor
        match rootnode.downcast::<Element>() {
            Some(element_ref) => Some(Root::from_ref(element_ref)),
            None => None,
        }

could be written as

        rootnode.downcast::<Element>().map(Root::from_ref)

@luthfianto

Copy link
Copy Markdown
Contributor Author
fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<Root<Element>> {
    let x = *x as f32;
    let y = *y as f32;
    let point = &Point2D { x: x, y: y };
    let window = window_from_node(self);
    let viewport = window.window_size().unwrap().visible_viewport;

    if x < 0.0 || y < 0.0 || x > viewport.width.get() || y > viewport.height.get() {
        return None;
    }

    let js_runtime = unsafe { JS_GetRuntime(window.get_cx()) };

    match self.hit_test(point) {
        Some(untrusted_node_address) => {
            let rootnode =
                node::from_untrusted_node_address(js_runtime, untrusted_node_address);

            rootnode.downcast::<Element>().map(Root::from_ref)
        },
        None => None,
    }
}

is this okay?


Comments from the review on Reviewable.io

@nox

nox commented Dec 14, 2015

Copy link
Copy Markdown
Contributor

Review status: all files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/document.rs, line 2451 [r4] (raw file):
As I said earlier, there are two issues here:

  • I don't know if hit_test can return a Node that is not an Element, if all it returns are Element instances, we can just unwrap downcast and unwrap.
  • In the case hit_test returns None, you need to do as stated in step 3, i.e. returning the document root: "If the document has a root element, return the root element and terminate these steps". This corresponds to the last None => None match clause in your snippet.

Comments from the review on Reviewable.io

@nox

nox commented Dec 14, 2015

Copy link
Copy Markdown
Contributor

For the first issue I mentioned, I just discussed it with @mbrubeck on the IRC channel:


23:38 <nox> jdm: Do you know if hit_test can return a Node that is not an Element?
23:39 <~jdm> I do not
23:39 <nox> jdm: Do you know who knows?
23:40 <~jdm> pcwalton or mbrubeck, perhaps
23:40 <nox> Thanks.
23:41 → ncthom91 and erickt joined  
23:44 <@mbrubeck> nox: I think it can return a non-Element node.
23:44 <nox> mbrubeck: What should elementFromPoint return then?
23:44 <@mbrubeck> nox: Some callers in script::dom::document look for the parent Element if necessary
23:44 <nox> The root? The closest Element parent?
23:44 <nox> Ok.
23:45 <@mbrubeck> nox: https://github.com/servo/servo/blob/master/components/script/dom/document.rs#L627-L644
23:45 <nox> (Stupid me saying closest, the parent must be one obviously.)

So you should do something along these lines:

match result_of_hit_test {
    Some(address) => {
        let node = …;
        node.downcast::<Element>().unwrap_or_else(|| {
            node.GetParentNode().downcast::<Element>().unwrap()
        })
    }
    None => { /* Get root element. */ }
}

@luthfianto

Copy link
Copy Markdown
Contributor Author

@nox (Haven't tested this. On Windows). Something like this?

match self.hit_test(point)  {
    Some(untrusted_node_address) => {
        let node = node::from_untrusted_node_address(js_runtime, untrusted_node_address);
        node.downcast::<Element>().unwrap_or_else(|| {
            node.GetParentNode().downcast::<Element>().unwrap()
        })
    }
    None => match self.GetBody() {
        Some(body) => Some(Root::upcast(body)),
        None =>None,
    }
}

bors-servo pushed a commit that referenced this pull request Feb 27, 2016
Implement Document#elementFromPoint

Related to #8666. I haven't implemented elementsFromPoint, because from my past discussion with jdm, [it's not good yet](https://github.com/rilut/servo/commit/dbfa25214b2888dda7527d62b5df1bb61f1ab047#commitcomment-14668959) to implement elementsFromPoint because it may cause GC hazards.

By the way, I also have to include the test for this, right? I've found this [1]. So, is all I have to do is just to put this into `tests/wpt/web-platform-tests/cssom-view/elementFromPoint.html`?

[1] http://test.csswg.org/suites/cssom-view-1_dev/nightly-unstable/html/elementFromPosition.htm

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8932)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-css

@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 Feb 27, 2016
@nox

nox commented Feb 27, 2016

Copy link
Copy Markdown
Contributor

@jdm Seems like it was a fluke. :(

@KiChjang

Copy link
Copy Markdown
Contributor

This looks like it would cause an intermittent, should we disable that test?

@luthfianto

Copy link
Copy Markdown
Contributor Author

@nox @KiChjang

[CaretPosition-001.htm]
  type: testharness
  [getBox]
    expected:
      PASS

Should this do the trick?

@nox

nox commented Feb 27, 2016

Copy link
Copy Markdown
Contributor

No, I think we should actually disable that test. What do you think @Ms2ger?

@nox nox added the S-awaiting-answer Someone asked a question that requires an answer. label Feb 27, 2016
@nox

nox commented Feb 29, 2016

Copy link
Copy Markdown
Contributor
18:00 <@Ms2ger> nox, file an issue to re-enable it and disable for now
18:00 <@Ms2ger> It has two test()s with the same name
18:00 <@Ms2ger> I imagine one fails and one passes

So:

[CaretPosition-001.htm]
  type: testharness
  [getBox]
    disabled: <URL of the issue that you have to file about the disabling>

r=me when that's done.

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-answer Someone asked a question that requires an answer. S-tests-failed The changes caused existing tests to fail. labels Feb 29, 2016
@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 Feb 29, 2016
@KiChjang

Copy link
Copy Markdown
Contributor

@bors-servo r=nox

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 76678bb has been approved by nox

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 76678bb with merge 4bcdbe6...

@highfive highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Feb 29, 2016
bors-servo pushed a commit that referenced this pull request Feb 29, 2016
Implement Document#elementFromPoint

Related to #8666. I haven't implemented elementsFromPoint, because from my past discussion with jdm, [it's not good yet](https://github.com/rilut/servo/commit/dbfa25214b2888dda7527d62b5df1bb61f1ab047#commitcomment-14668959) to implement elementsFromPoint because it may cause GC hazards.

By the way, I also have to include the test for this, right? I've found this [1]. So, is all I have to do is just to put this into `tests/wpt/web-platform-tests/cssom-view/elementFromPoint.html`?

[1] http://test.csswg.org/suites/cssom-view-1_dev/nightly-unstable/html/elementFromPosition.htm

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8932)
<!-- Reviewable:end -->
@highfive highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Feb 29, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt

@luthfianto

Copy link
Copy Markdown
Contributor Author

Thanks, Servo team.

@luthfianto
luthfianto deleted the add-elementfrompoint branch March 2, 2016 12:19
@nox

nox commented Mar 2, 2016

Copy link
Copy Markdown
Contributor

No, thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants