Skip to content

Implement GetElementRect webdriver command: #8623 - #9708

Merged
bors-servo merged 2 commits into
servo:masterfrom
dlrobertson:i8623
Feb 25, 2016
Merged

bors-servo merged 2 commits into
servo:masterfrom
dlrobertson:i8623

Conversation

@dlrobertson

Copy link
Copy Markdown
Contributor

Implement the webdriver Get Element Rect command. Originally I wrote out the algorithm for Step 7 and then I found GetBoundingClientRect, and i thought it was probably best to use it instead.

As always, feedback is very welcomed!
#8623

Review on Reviewable

@highfive

Copy link
Copy Markdown

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 Feb 20, 2016
Comment thread components/webdriver_server/lib.rs Outdated
ServoExtensionCommand::ResetPrefs(ref x) => self.handle_reset_prefs(x),
}
}
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comma here isn't necessary when the match-arm uses braces.

@jdm

jdm commented Feb 20, 2016

Copy link
Copy Markdown
Member

If we fixed #9651, GetBoundingClientRect would become inappropriate for this, I believe.

@dlrobertson

Copy link
Copy Markdown
Contributor Author

If we fixed #9651, GetBoundingClientRect would become inappropriate for this, I believe.

Ah, I see... So would it be better to go back to the written out algorithm?

@jdm

jdm commented Feb 20, 2016

Copy link
Copy Markdown
Member

I think so, yes.

@dlrobertson

Copy link
Copy Markdown
Contributor Author

As stated in #9709, I think I'm wrong on my implementation of find_element_by_element_id. Step 3 in the spec mentions that the element should be found by UUID, so I think I should be using find_node_by_unique_id


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


components/script/webdriver_handlers.rs, line 227 [r2] (raw file):
webdriver::ElementRectResponse uses f64, so I just make the conversion here.


components/webdriver_server/lib.rs, line 837 [r1] (raw file):
Fixed. Thanks!


Comments from the review on Reviewable.io

Comment thread components/script/webdriver_handlers.rs Outdated
let mut y: i32 = 0;
// Step 2
let mut offset_parent = html_elem.GetOffsetParent();
while offset_parent.is_some() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be while let Some(element) = offset_parent {.

@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/script/webdriver_handlers.rs, line 210 [r2] (raw file):
Much cleaner 😄 i don't know why i didn't do that.


components/script/webdriver_handlers.rs, line 211 [r2] (raw file):
Nice!


Comments from the review on Reviewable.io

@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/script/webdriver_handlers.rs, line 40 [r4] (raw file):
After looking at this it seemed like this should use find. So I changed this in a separate commit


Comments from the review on Reviewable.io

Comment thread components/script/webdriver_handlers.rs Outdated
x += elem.OffsetLeft();
y += elem.OffsetTop();
elem.GetOffsetParent()
}).unwrap_or(None);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is an unwrap_or still necessary?

@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/script/webdriver_handlers.rs, line 209 [r4] (raw file):
Great question! Map will return an Option<T> and GetOffsetParent will return a Option<Root<Element>>, so unless I'm mistaken object.downcast<T>().map(...) should return an Option<Option<HTMLElement>> while offset_parent is an Option<HTMLElement>, so I used unwrap_or to unwrap the inner Option. I'll double check to see if it compiles without it, but I don't think it will.

Also if you know a better way around this let me know!


Comments from the review on Reviewable.io

Comment thread components/msg/webdriver_msg.rs Outdated
}

#[derive(Clone, Copy, Deserialize, Serialize)]
pub struct WebDriverElementRect {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not a Rect from Euclid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great point, didn't see that it impl'd Serialize. I'll make the change in the update.

Comment thread components/script/webdriver_handlers.rs Outdated
}
},
None => Err(())
}).unwrap()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function doesn't look like it has a return value. Perhaps you're missing a semi-colon here?

use dom::window::ScriptHelpers;
use euclid::point::Point2D;
use euclid::rect::Rect;
use euclid::size::Size2D;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these imports necessary?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wait, sorry, nevermind.

@dlrobertson
dlrobertson force-pushed the i8623 branch 2 times, most recently from 8d2320a to a640955 Compare February 24, 2016 14:27
@KiChjang KiChjang added the S-needs-code-changes Changes have not yet been made that were requested by a reviewer. label Feb 24, 2016
@KiChjang KiChjang removed the S-awaiting-review There is new code that needs to be reviewed. label Feb 24, 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 24, 2016
// https://w3c.github.io/webdriver/webdriver-spec.html#dfn-calculate-the-absolute-position
match elem.downcast::<HTMLElement>() {
Some(html_elem) => {
// Step 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will definitely confuse people as to which spec this step is following. I think this should only link to the absolute position spec.

@KiChjang KiChjang 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 Feb 24, 2016
Implement the webdriver Get Element Rect command
find_node_by_unique_id should use find instead of for-loop
@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 24, 2016
@KiChjang

Copy link
Copy Markdown
Contributor

@bors-servo r+

Thanks for working on this!

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit cad3115 has been approved by KiChjang

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

Copy link
Copy Markdown
Contributor

⌛ Testing commit cad3115 with merge e5f3c5b...

bors-servo pushed a commit that referenced this pull request Feb 25, 2016
Implement GetElementRect webdriver command: #8623

Implement the webdriver Get Element Rect command. Originally I wrote out the algorithm for [Step 7](https://w3c.github.io/webdriver/webdriver-spec.html#dfn-calculate-the-absolute-position) and then I found `GetBoundingClientRect`, and i thought it was probably best to use it instead.

As always, feedback is very welcomed!

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

Copy link
Copy Markdown
Contributor

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

@bors-servo
bors-servo merged commit cad3115 into servo:master Feb 25, 2016
@dlrobertson
dlrobertson deleted the i8623 branch February 25, 2016 01:17
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.

6 participants