Skip to content

Implement Element.client{Top,Left,Width,Height} - #6662

Merged
bors-servo merged 3 commits into
servo:masterfrom
tschneidereit:client-geometry
Jul 28, 2015
Merged

bors-servo merged 3 commits into
servo:masterfrom
tschneidereit:client-geometry

Conversation

@tschneidereit

Copy link
Copy Markdown
Contributor

This isn't done, but contains a working implementation of at least clientTop. Feedback would be much appreciated: it's probably far from ideal.

Implementing clientLeft is straight-forward, I think, but clientWidth and clientHeight require accessing the border_box - and I don't know how that works, yet.

Review on Reviewable

@highfive

Copy link
Copy Markdown

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @metajack (or someone else) soon.

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 18, 2015
@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@hoppipolla-critic-bot

Copy link
Copy Markdown

Critic review: https://critic.hoppipolla.co.uk/r/5594

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

Comment thread components/script/layout_interface.rs Outdated

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.

Maybe we should group this into a single get_geometry() umbrella function with an associated GeometryMetric enum containing ClientTop, ClientWidth enum so we don't have a dozen functions here. (BTW, ClientGeometry probably isn't the right word, since there are non-"client" metrics too; offsetTop, for example.)

@pcwalton

Copy link
Copy Markdown
Contributor

Looks good. For clientWidth, just take the fragment's border_box.width and subtract the left and right border widths. Likewise for clientHeight.

Thanks for the work here, BTW—this is going to make a lot of pages throw exceptions less often 👍

@tschneidereit

Copy link
Copy Markdown
Contributor Author

This now fully implements clientTop, clientLeft, clientHeight, and clientWidth, and passes the tests I could come up with. offsetTop et al have to be calculated in a somewhat different way, so I'm not sure it makes sense to integrate them into the same mechanism.


Review status: 0 of 8 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


components/script/layout_interface.rs, line 99 [r1] (raw file):
I did group it, but in a slightly different way: node_geometry now returns a NodeGeometryResponse which, for now, contains a client_rect field that always gets fully populated. ISTM that that's quite a bit simpler, and the overhead of always populating all four values is negligible. This could well be different once offsetFoo properties enter the mix, though.


Comments from the review on Reviewable.io

@jdm

jdm commented Jul 19, 2015

Copy link
Copy Markdown
Member

A test for something with display: none wouldn't go amiss (c.f. step 1 of http://drafts.csswg.org/cssom-view/#dom-element-clienttop):

> var d = document.createElement('div')
undefined
> document.body.appendChild(d)
<div>
>d.style.borderLeft = "100px solid black"
"100px solid black"
>d.clientLeft
100
>d.style.display = "none"
"none"
>d.clientLeft
0

@tschneidereit

Copy link
Copy Markdown
Contributor Author

D'oh, of course. I had that in my manual testing but completely forgot to add it to the wpt test. Fixed.


Review status: 0 of 8 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


Comments from the review on Reviewable.io

Comment thread components/layout/layout_task.rs Outdated

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.

Specify in the comment that this is in pixels.

@pcwalton

Copy link
Copy Markdown
Contributor

This looks good modulo some minor nits.

@tschneidereit

Copy link
Copy Markdown
Contributor Author

Nits addressed. r? @pcwalton.


Review status: 0 of 8 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful.


components/layout/layout_task.rs, line 130 [r3] (raw file):
Done.


components/layout/layout_task.rs, line 1443 [r3] (raw file):
I realized that while working on another patch, yes. Fixed.


components/script/layout_interface.rs, line 98 [r3] (raw file):
Done.


tests/wpt/mozilla/tests/mozilla/client-top-left-height-width.html, line 113 [r3] (raw file):
I was also pretty surprised, yes.


Comments from the review on Reviewable.io

@glennw

glennw commented Jul 28, 2015

Copy link
Copy Markdown
Member

Reviewed 7 of 7 files at r1, 9 of 9 files at r2, 1 of 1 files at r3.
Review status: 5 of 8 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful.


Comments from the review on Reviewable.io

@glennw glennw assigned glennw and unassigned pcwalton Jul 28, 2015
@glennw

glennw commented Jul 28, 2015

Copy link
Copy Markdown
Member

@bors-servo r=glennw,pcwatson

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 126938a has been approved by glennw,pcwatson

@jdm

jdm commented Jul 28, 2015

Copy link
Copy Markdown
Member

Good old Patrick Watson. Project wouldn't be the same without him.

@jdm jdm added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 28, 2015
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