Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement GetElementRect webdriver command: #8623 #9708
Conversation
highfive
commented
Feb 20, 2016
| @@ -816,7 +834,7 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler { | |||
| ServoExtensionCommand::SetPrefs(ref x) => self.handle_set_prefs(x), | |||
| ServoExtensionCommand::ResetPrefs(ref x) => self.handle_reset_prefs(x), | |||
| } | |||
| } | |||
| }, | |||
This comment has been minimized.
This comment has been minimized.
|
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? |
|
I think so, yes. |
|
As stated in #9709, I think I'm wrong on my implementation of Review status: 0 of 4 files reviewed at latest revision, 2 unresolved discussions. components/script/webdriver_handlers.rs, line 227 [r2] (raw file): components/webdriver_server/lib.rs, line 837 [r1] (raw file): Comments from the review on Reviewable.io |
| let mut y: i32 = 0; | ||
| // Step 2 | ||
| let mut offset_parent = html_elem.GetOffsetParent(); | ||
| while offset_parent.is_some() { |
This comment has been minimized.
This comment has been minimized.
| // Step 2 | ||
| let mut offset_parent = html_elem.GetOffsetParent(); | ||
| while offset_parent.is_some() { | ||
| offset_parent = match offset_parent.unwrap().downcast::<HTMLElement>() { |
This comment has been minimized.
This comment has been minimized.
|
Review status: 0 of 4 files reviewed at latest revision, 4 unresolved discussions. components/script/webdriver_handlers.rs, line 210 [r2] (raw file): components/script/webdriver_handlers.rs, line 211 [r2] (raw file): Comments from the review on Reviewable.io |
|
Review status: 0 of 4 files reviewed at latest revision, 5 unresolved discussions. components/script/webdriver_handlers.rs, line 40 [r4] (raw file): Comments from the review on Reviewable.io |
| x += elem.OffsetLeft(); | ||
| y += elem.OffsetTop(); | ||
| elem.GetOffsetParent() | ||
| }).unwrap_or(None); |
This comment has been minimized.
This comment has been minimized.
|
Review status: 0 of 4 files reviewed at latest revision, 6 unresolved discussions. components/script/webdriver_handlers.rs, line 209 [r4] (raw file): Also if you know a better way around this let me know! Comments from the review on Reviewable.io |
| @@ -52,6 +53,14 @@ pub enum WebDriverFrameId { | |||
| Parent | |||
| } | |||
|
|
|||
| #[derive(Clone, Copy, Deserialize, Serialize)] | |||
| pub struct WebDriverElementRect { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dlrobertson
Feb 21, 2016
Author
Contributor
Great point, didn't see that it impl'd Serialize. I'll make the change in the update.
| page.document().upcast::<Node>().traverse_preorder().find(|x| match x.downcast::<Element>() { | ||
| Some(elem) => elem.Id() == &*element_id, | ||
| None => false | ||
| }).map(|x| Root::from_ref(x.downcast::<Element>().unwrap())) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dlrobertson
Feb 21, 2016
Author
Contributor
Good point, but I think I'm wrong here. See Step 3 of the spec. I think I'm supposed to find by UUID or Node::unique_id.
| while let Some(element) = offset_parent { | ||
| offset_parent = element.downcast::<HTMLElement>().and_then(|elem| { | ||
| x += elem.OffsetLeft(); | ||
| y += elem.OffsetTop(); |
This comment has been minimized.
This comment has been minimized.
Ms2ger
Feb 21, 2016
Contributor
Using and_then with a callback that mutates closed-over state us poor practice
This comment has been minimized.
This comment has been minimized.
dlrobertson
Feb 21, 2016
Author
Contributor
- Is there documentation for this?
- Is this the case for all iterator adapters or just the
Option<T>methods that take aFnOnceor justand_then?
Ideally I'd like to create a OffsetParentIterator struct, impl Iterator, and use fold, but this seems to be the only case where this would be used. Without an iterator as far as I know we're pretty much stuck to a while loop and mutating x and y. Let me know if I'm missing anything. Thanks for the comments!
| } | ||
| }, | ||
| None => Err(()) | ||
| }).unwrap() |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 24, 2016
Member
This function doesn't look like it has a return value. Perhaps you're missing a semi-colon here?
| Some(html_elem) => { | ||
| // Step 1 | ||
| let mut x: i32 = 0; | ||
| let mut y: i32 = 0; |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 24, 2016
Member
nit: Instead of specifying the type of x and y, specify the type of the 0 constant instead (i.e. use 0i32 instead of 0).
| @@ -22,6 +22,9 @@ use dom::htmlinputelement::HTMLInputElement; | |||
| use dom::htmloptionelement::HTMLOptionElement; | |||
| use dom::node::Node; | |||
| use dom::window::ScriptHelpers; | |||
| use euclid::point::Point2D; | |||
| use euclid::rect::Rect; | |||
| use euclid::size::Size2D; | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -540,6 +541,24 @@ impl Handler { | |||
| } | |||
| } | |||
|
|
|||
| fn handle_element_rect(&self, element: &WebElement) -> WebDriverResult<WebDriverResponse> { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8d2320a
to
a640955
| // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-calculate-the-absolute-position | ||
| match elem.downcast::<HTMLElement>() { | ||
| Some(html_elem) => { | ||
| // Step 1 |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 24, 2016
Member
This will definitely confuse people as to which spec this step is following. I think this should only link to the absolute position spec.
|
@bors-servo r+ Thanks for working on this! |
|
|
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 -->
|
|
dlrobertson commentedFeb 20, 2016
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