Skip to content

Add the scrollWidth and scrollHeight extensions to the element interface - #9824

Merged
bors-servo merged 1 commit into
servo:masterfrom
dlrobertson:element1
Mar 11, 2016
Merged

bors-servo merged 1 commit into
servo:masterfrom
dlrobertson:element1

Conversation

@dlrobertson

Copy link
Copy Markdown
Contributor

Add the scrollWidth and scrollHeight extensions to the element interface. My goal was to create a method that encompassed getting scrollWidth, scrollHeight, scrollTop, and scrollLeft.

I also noted that clientHeight and clientWidth to not handle the root element and the body element correctly.

Review on Reviewable

@highfive

highfive commented Mar 1, 2016

Copy link
Copy Markdown

warning Warning warning

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

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 1, 2016
@dlrobertson

Copy link
Copy Markdown
Contributor Author

Review status: 0 of 9 files reviewed at latest revision, 1 unresolved discussion.


components/layout/query.rs, line 433 [r1] (raw file):
Not a huge fan of this method of checking if the fragment is a child. Is there a better way of doing this?


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

I'm not sure about the relationship between the spec and the code. Care to clarify?

Also, are there any tests that now pass which previously failed?


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


components/layout/query.rs, line 405 [r1] (raw file):
It's not clear to me what the relationship between the spec and the code is. Can you add comments clarifying this?


components/layout/query.rs, line 424 [r1] (raw file):
Should this use Rect::union?

I'm not sure about the explicit setting of x and y. They are initialized at zero, then we set x = min(x, border.origin.x). Is this relying on the border x and y always being negative?


components/script/dom/node.rs, line 582 [r1] (raw file):
Again, not sure about the relationship between the spec and the code. The comments below look like they come from the spec but I can't find them.


components/script/dom/node.rs, line 589 [r1] (raw file):
Rect::zero()?


Comments from the review on Reviewable.io

@KiChjang

KiChjang commented Mar 1, 2016

Copy link
Copy Markdown
Contributor

Just one thing to add: if your code is following steps from the spec, an annotation of // Step 1. would be enough.

Comment thread components/script/dom/node.rs Outdated
window_from_node(self).client_rect_query(self.to_trusted_node_address())
}

// https://drafts.csswg.org/cssom-view/#extension-to-the-element-interface

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.

@dlrobertson

Copy link
Copy Markdown
Contributor Author

Also, are there any tests that now pass which previously failed?

Yes, two in https://github.com/servo/servo/tree/master/tests/wpt/css-tests/cssom-view-1_dev/html are now passing. I deleted the .ini files.

I'm not sure about the relationship between the spec and the code. Care to clarify?
and
Just one thing to add: if your code is following steps from the spec, an annotation of // Step 1. would be enough.

As far as i could tell the specifications for (at least the get methods) scrollWidth, scrollHeight, scrollTop, and scrollLeft are pretty much the same, so I combined them, but some of the step numbers don't line up, so I didn't comment with numbers. I can use something like // Step 1 for scrollHeight and Step 2 for scrollWidth

Thanks for the review!


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


components/layout/query.rs, line 405 [r1] (raw file):
Good point. This is used to get the https://drafts.csswg.org/cssom-view/#scrolling-area


components/layout/query.rs, line 424 [r1] (raw file):
Good point! I'm pretty sure. After looking at https://github.com/servo/euclid/blob/master/src/rect.rs#L138-L156 it looks like Rect::union is the right choice


components/script/dom/node.rs, line 582 [r1] (raw file):
It includes the get methods for scrollTop and scrollHeight as well. Should I just list them all above the method?


components/script/dom/node.rs, line 582 [r1] (raw file):
As KiChjang mentioned they're the common requirements from https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth and scrollHeight, scrollTop, scrollLeft. As far as i could tell they had the same basic requirements.


components/script/dom/node.rs, line 589 [r1] (raw file):
Ah! good point!


Comments from the review on Reviewable.io

@asajeffrey asajeffrey added S-awaiting-answer Someone asked a question that requires an answer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 2, 2016
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 2, 2016
@dlrobertson

Copy link
Copy Markdown
Contributor Author

Review status: 7 of 9 files reviewed at latest revision, 7 unresolved discussions.


components/layout/query.rs, line 426 [r2] (raw file):
I'm not 100% sure about what to use as the origin for this Rect. After reading some more docs and lots of trial and error, this works. If I'm honest I'm still a bit shaky on this.


Comments from the review on Reviewable.io

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #9832) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Mar 3, 2016
@asajeffrey asajeffrey removed S-awaiting-answer Someone asked a question that requires an answer. S-needs-rebase There are merge conflict errors. labels Mar 4, 2016
@asajeffrey

Copy link
Copy Markdown
Contributor

Reviewed 6 of 6 files at r3.
Review status: all files reviewed at latest revision, 4 unresolved discussions.


components/layout/query.rs, line 433 [r1] (raw file):
I'll ask on irc...


components/layout/query.rs, line 426 [r2] (raw file):
Hmm, it would help to find the relevant spec. I'm a bit surprised that writing mode is involved here, I'd have expected the bounding box to be independent of writing mode.


components/layout/query.rs, line 364 [r3] (raw file):
I still don't see the connection between the spec and the code I'm afraid.


Comments from the review on Reviewable.io

@asajeffrey asajeffrey added S-awaiting-answer Someone asked a question that requires an answer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 4, 2016
@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/layout/query.rs, line 433 [r1] (raw file):
Thanks! and thanks again for the feedback.


components/layout/query.rs, line 426 [r2] (raw file):
As far as I could tell, it has to do with block flow and inline flow directions (which is determined by the writing mode) and the overflow direction as those will impact what the top_edge, left_edge, etc will be. Is that correct?


components/layout/query.rs, line 364 [r3] (raw file):
I wrote it out step by step according to the spec, and then I found ComputedValues::get_border and Fragment::margin and I got the same answer when using them, so I assumed they computed the top_edge, right_edge, etc.

If I am incorrect, please let me know, and I'll go back to the "manual" version.


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

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


components/layout/query.rs, line 426 [r2] (raw file):
The spec says "The origin of a scrolling area is the origin of the initial containing block if the scrolling area is a viewport, and otherwise the top left padding edge of the element when the element has its default scroll position. The x-coordinate increases rightwards, and the y-coordinate increases downwards." which seems to suggest that for non-viewports, the origin is always top-left, irrespective of writing mode.


Comments from the review on Reviewable.io

@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/layout/query.rs, line 426 [r2] (raw file):
Ah, you're right! don't know how i missed that.... Is there a method of discovering if the scrolling area is a viewport?


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

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


components/layout/query.rs, line 426 [r2] (raw file):
Are we computing the scrolling area for viewports? I think we're just doing it for elements.


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

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


components/layout/query.rs, line 364 [r3] (raw file):
As discussed on IRC, perhaps we should go back to doing it manually, just so it's obvious how it lines up with the spec.


Comments from the review on Reviewable.io

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 8, 2016
@dlrobertson

Copy link
Copy Markdown
Contributor Author

There are a few things I'm still a bit unsure about, but I think it is getting closer. Thanks for the help! As always any feedback is appreciated!


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


components/layout/query.rs, line 364 [r3] (raw file):
After switching to doing it manually I found a few errors and it works now with terrible html like this


components/layout/query.rs, line 403 [r4] (raw file):
We match against the overflow direction of each child fragment which I don't think is correct. I think we should just match against the first.


components/layout/query.rs, line 406 [r4] (raw file):
Seems weird to me that we have to use writing_mode here, but that was the only way I could find to get the position of the margin.


Comments from the review on Reviewable.io

@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/script/dom/node.rs, line 607 [r4] (raw file):
Forgot to mention the spec mentions that if the element does not have an associated CSS layout box to return 0, but the computed value of the Box's display is always block for the tests. Not sure what to do here


Comments from the review on Reviewable.io

@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/layout/query.rs, line 406 [r4] (raw file):
I may be misunderstanding you, but after looking into it more, we will need, in some form or another, a new FragmentBorderBoxIterator as none of the other iterators return true forshould_process while level <= start-node-level. However, if you think something like UnioningFragmentBorderBoxIterator perhaps we could collect both the union of all children margins and children border_boxes and then compute the scrolling area in process_node_scroll_geometry_query using those, which would eliminate the need for pattern matching in FragmentBorderBoxIterator::process


components/script/dom/node.rs, line 607 [r5] (raw file):
Not sure if this is better or worse. Are there any good docs on Root?


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

Reviewed 1 of 3 files at r5.
Review status: 8 of 10 files reviewed at latest revision, 4 unresolved discussions.


components/layout/query.rs, line 406 [r4] (raw file):
OK, you've convinced me that we do need a custom iterator here, the logic in the spec is different enough from the existing iterators.


components/script/dom/node.rs, line 607 [r5] (raw file):
Probably the best docs on Root (if slightly out of date) are https://blog.mozilla.org/research/2014/08/26/javascript-servos-only-garbage-collector/ but this is probably more detail than you need.

Does something like self.is::<HTMLHtmlElement> not do the trick? Ditto for is_body_element?


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

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


components/layout/query.rs, line 406 [r4] (raw file):
But I do think we should have the iterator be independent of the OverflowDirection, and move the code which is dependent on it to when we calculate the scrolling area.


Comments from the review on Reviewable.io

@asajeffrey asajeffrey removed the S-awaiting-review There is new code that needs to be reviewed. label Mar 10, 2016
@dlrobertson

Copy link
Copy Markdown
Contributor Author

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


components/layout/query.rs, line 406 [r4] (raw file):
Yeah, that sounds like the right direction.


components/script/dom/node.rs, line 607 [r5] (raw file):
Sweet! Nah, that was perfect. Thanks for the reference!

That's what I thought too, but nox and Ms2ger corrected me on IRC. The log is here-ish.


Comments from the review on Reviewable.io

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 11, 2016
@dlrobertson

Copy link
Copy Markdown
Contributor Author

Let me know if you have any feedback!


Review status: 3 of 10 files reviewed at latest revision, 8 unresolved discussions.


components/layout/query.rs, line 323 [r6] (raw file):
Renamed to reflect the purpose better


components/layout/query.rs, line 326 [r6] (raw file):
I used two rectangles. One to save the "original" state, and one to iterate through the children and collect the largest width, height, etc.


components/layout/query.rs, line 415 [r6] (raw file):
Is the margin ever less than the padding? The spec states

The (top|right|bottom|left)-most edge of the element’s (top|right|bottom|left) padding edge and the (top|right|bottom|left) margin edge

So i used the union of the padding and margin rectangles to follow the spec, but I was curious as to why it is written like that.


components/layout/query.rs, line 523 [r6] (raw file):
Ideally we wouldn't have to use two separate rectangles or we could initialize union_rect at query.rs:423 as a clone of origin_rect to avoid the use of min and max, but due to the way union is implemented if a larger parent fragment has top or left padding and the child does not the child the result will be something like the following

let parent = Rect(Point2D::new(1, 1), Size2D::new(10, 10));
let child = Rect::new(Point2D::zero(), Size2D::new(1,1));
let result = parent.union(&child);
// result size will be (11, 11) because the child origin is (0, 0)
assert_eq!(Size2D::new(11, 11), result.size)

If you can think of a better way of working around this let me know. This is just the best I could think of


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

Looks good!


Reviewed 1 of 3 files at r5, 6 of 6 files at r6.
Review status: all files reviewed at latest revision, 8 unresolved discussions.


components/layout/query.rs, line 41 [r6] (raw file):
Is this comment still needed? It looks like there is an inline_base_direction to me :)


components/layout/query.rs, line 415 [r6] (raw file):
https://www.w3.org/TR/CSS2/box.html#margin-properties says "Negative values for margin properties are allowed, but there may be implementation-specific limits." My reading is that this can result in margin that is less than padding.


components/layout/query.rs, line 523 [r6] (raw file):
Can't think of anything off the top of my head. Add a comment explaining the code, and I think we're good to go.


components/script/dom/node.rs, line 607 [r5] (raw file):
Well, for well-formed HTML, I think that checking self.is::<HTMLHtmlElement>() is the same as html_element.r() == self.downcast::<Element>() but there may be odd cases of documents containg more than one <html> element where this isn't the case. In any case, this is fine.


components/style/logical_geometry.rs, line 101 [r6] (raw file):
Yay, much nicer!


Comments from the review on Reviewable.io

@asajeffrey asajeffrey removed the S-awaiting-review There is new code that needs to be reviewed. label Mar 11, 2016
@jdm jdm 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. labels Mar 11, 2016
@jdm

jdm commented Mar 11, 2016

Copy link
Copy Markdown
Member

Just want to say that I'm super pumped that @danlrobertson is tackling this and implementing the useful building blocks like get_scroll_area. Thanks!

Add the scrollWidth and scrollHeight extensions to the element
interface.
@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 Mar 11, 2016
@dlrobertson

Copy link
Copy Markdown
Contributor Author

Thanks! This was a ton of fun and I learned a lot


Review status: 9 of 10 files reviewed at latest revision, 8 unresolved discussions.


components/layout/query.rs, line 41 [r6] (raw file):
Ha! nope... just a note to myself. good catch


components/layout/query.rs, line 415 [r6] (raw file):
good to know!


components/layout/query.rs, line 523 [r6] (raw file):
I thought the best place to list it was probably in UnioningFragmentScrollAreaIterator::process. Did my best to describe the reasoning. Let me know if I should change it at all


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

Glad you enjoyed the experience!


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


Comments from the review on Reviewable.io

@asajeffrey

Copy link
Copy Markdown
Contributor

@bors-servo: r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 16d2778 has been approved by asajeffrey

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

Copy link
Copy Markdown
Contributor

⌛ Testing commit 16d2778 with merge 7ff7932...

bors-servo pushed a commit that referenced this pull request Mar 11, 2016
Add the scrollWidth and scrollHeight extensions to the element interface

Add the `scrollWidth` and `scrollHeight` extensions to the element interface. My goal was to create a method that encompassed getting `scrollWidth`, `scrollHeight`, `scrollTop`, and `scrollLeft`.

I also noted that `clientHeight` and `clientWidth` to not handle the root element and the body element correctly.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9824)
<!-- 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, status-appveyor

@bors-servo
bors-servo merged commit 16d2778 into servo:master Mar 11, 2016
@dlrobertson
dlrobertson deleted the element1 branch March 11, 2016 19:43
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