servo: Merge #19127 - scroll, SetScrollTop, SetScrollLeft in element.rs (from tigercosmos:overflow10); r=emilio

<!-- 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. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 37760054e2cf742c9043b96b832d2fbdf796d367

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 0ef07d51bdd1317c10e1e17dda15740f2df610ad
This commit is contained in:
tigercosmos 2017-11-12 17:24:33 -06:00
parent 5f0719ad1d
commit f3abc6bb9f

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);