Auto merge of #19127 - tigercosmos:overflow10, r=emilio

scroll, SetScrollTop, SetScrollLeft in `element.rs`

<!-- Please describe your changes on the following line: -->
Currently dom-element-scroll have not finished yet. (Step 10)
This PR finish the step 10 of `scroll`, `SetScrollTop`, `SetScrollLeft`

[Step 10 description](https://drafts.csswg.org/cssom-view/#dom-element-scrolltop):
> If the element does not have any associated CSS layout box, the element has no associated scrolling box, or the element has no overflow, terminate these steps.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #19114 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19127)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-12 17:24:33 -06:00 committed by GitHub
commit 37760054e2
4 changed files with 157 additions and 5 deletions

View file

@ -362,6 +362,19 @@ impl Element {
!self.overflow_y_is_visible()
}
// https://drafts.csswg.org/cssom-view/#scrolling-box
fn has_scrolling_box(&self) -> bool {
// TODO: scrolling mechanism, such as scrollbar (We don't have scrollbar yet)
// self.has_scrolling_mechanism()
self.overflow_x_is_hidden() ||
self.overflow_y_is_hidden()
}
fn has_overflow(&self) -> bool {
self.ScrollHeight() > self.ClientHeight() ||
self.ScrollWidth() > self.ClientWidth()
}
// used value of overflow-x is "visible"
fn overflow_x_is_visible(&self) -> bool {
let window = window_from_node(self);
@ -375,6 +388,20 @@ impl Element {
let overflow_pair = window.overflow_query(self.upcast::<Node>().to_trusted_node_address());
overflow_pair.y == overflow_y::computed_value::T::visible
}
// used value of overflow-x is "hidden"
fn overflow_x_is_hidden(&self) -> bool {
let window = window_from_node(self);
let overflow_pair = window.overflow_query(self.upcast::<Node>().to_trusted_node_address());
overflow_pair.x == overflow_x::computed_value::T::hidden
}
// used value of overflow-y is "hidden"
fn overflow_y_is_hidden(&self) -> bool {
let window = window_from_node(self);
let overflow_pair = window.overflow_query(self.upcast::<Node>().to_trusted_node_address());
overflow_pair.y == overflow_y::computed_value::T::hidden
}
}
#[allow(unsafe_code)]
@ -1470,7 +1497,13 @@ impl Element {
return;
}
// Step 10 (TODO)
// Step 10
if !self.has_css_layout_box() ||
!self.has_scrolling_box() ||
!self.has_overflow()
{
return;
}
// Step 11
win.scroll_node(node, x, y, behavior);
@ -1926,7 +1959,13 @@ impl ElementMethods for Element {
return;
}
// Step 10 (TODO)
// Step 10
if !self.has_css_layout_box() ||
!self.has_scrolling_box() ||
!self.has_overflow()
{
return;
}
// Step 11
win.scroll_node(node, self.ScrollLeft(), y, behavior);
@ -2019,7 +2058,13 @@ impl ElementMethods for Element {
return;
}
// Step 10 (TODO)
// Step 10
if !self.has_css_layout_box() ||
!self.has_scrolling_box() ||
!self.has_overflow()
{
return;
}
// Step 11
win.scroll_node(node, x, self.ScrollTop(), behavior);