Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

element.clientHeight & element.scrollHeight incomplete implement #19280

Open
tigercosmos opened this issue Nov 18, 2017 · 4 comments
Open

element.clientHeight & element.scrollHeight incomplete implement #19280

tigercosmos opened this issue Nov 18, 2017 · 4 comments

Comments

@tigercosmos
Copy link
Collaborator

@tigercosmos tigercosmos commented Nov 18, 2017

With the following test.html:

    <body>
        <div id="scroller" style="height: 100px; width: 100px; overflow: scroll; background: red;">
            <div style="background: green; margin-top: 100px; width: 100px; height: 100px;"></div>
        </div>
  
        <script>
            var scroller = document.getElementById("scroller");
            console.log(scroller.clientHeight)
            console.log(scroller.scrollHeight) 
        </script>
    </body>

Firefox will get:

96  <--- this is caused by scrollbar
200

Servo will get:

100 <---- servo count scrollbar currently
100 <---- this is wrong

As clientHeight is a known issue, we may need to check out scrollHeight

This might be an issue related to #19268

fn has_overflow(&self) -> bool {
self.ScrollHeight() > self.ClientHeight() ||
self.ScrollWidth() > self.ClientWidth()
}

@tigercosmos
Copy link
Collaborator Author

@tigercosmos tigercosmos commented Nov 19, 2017

I figure out that ScrollHeight cannot deal with margin-top: 100px;
If we change the second line of this:

        <div id="scroller" style="height: 100px; width: 100px; overflow: scroll; background: red;">
            <div style="background: green; margin-top: 100px; width: 100px; height: 100px;"></div>
        </div>

to
margin-top: 100px and height: 190px;
ScrollHeight will get correct answser 190

@tigercosmos
Copy link
Collaborator Author

@tigercosmos tigercosmos commented Nov 20, 2017

Seems scrollHeight will return max(margin-top, height)
As shown in following:


scroller.scrollHeight will get 100

<style>
    #scroller {
        height: 100px;
        width: 100px;
        overflow: hidden;
        background: red;
    }

    #container {
        background: green;
        margin-top: 100px;
        width: 100px;
        height: 30px;
    }
</style>
<div id="scroller">
        <div id="container"></div>
 </div>

scroller.scrollHeight will get 190

<style>
    #scroller {
        height: 100px;
        width: 100px;
        overflow: hidden;
        background: red;
    }

    #container {
        background: green;
        margin-top: 100px;
        width: 100px;
        height: 190px;
    }
</style>
<div id="scroller">
        <div id="container"></div>
 </div>

I also test changing margin to padding, and padding will run correctly.

@tigercosmos
Copy link
Collaborator Author

@tigercosmos tigercosmos commented Nov 26, 2017

Something might be related:

fn node_scroll_area(&self) -> NodeGeometryResponse {
NodeGeometryResponse {
client_rect: self.0.lock().unwrap().scroll_area_response
}
}

pub fn process_node_scroll_area_request< N: LayoutNode>(requested_node: N, layout_root: &mut Flow)
-> Rect<i32> {
let mut iterator = UnioningFragmentScrollAreaIterator::new(requested_node.opaque());
sequential::iterate_through_flow_tree_fragment_border_boxes(layout_root, &mut iterator);
match iterator.overflow_direction {
OverflowDirection::RightAndDown => {
let right = max(iterator.union_rect.size.width, iterator.origin_rect.size.width);
let bottom = max(iterator.union_rect.size.height, iterator.origin_rect.size.height);
Rect::new(iterator.origin_rect.origin, Size2D::new(right, bottom))
},
OverflowDirection::LeftAndDown => {
let bottom = max(iterator.union_rect.size.height, iterator.origin_rect.size.height);
let left = max(iterator.union_rect.origin.x, iterator.origin_rect.origin.x);
Rect::new(Point2D::new(left, iterator.origin_rect.origin.y),
Size2D::new(iterator.origin_rect.size.width, bottom))
},
OverflowDirection::LeftAndUp => {
let top = min(iterator.union_rect.origin.y, iterator.origin_rect.origin.y);
let left = min(iterator.union_rect.origin.x, iterator.origin_rect.origin.x);
Rect::new(Point2D::new(left, top), iterator.origin_rect.size)
},
OverflowDirection::RightAndUp => {
let top = min(iterator.union_rect.origin.y, iterator.origin_rect.origin.y);
let right = max(iterator.union_rect.size.width, iterator.origin_rect.size.width);
Rect::new(Point2D::new(iterator.origin_rect.origin.x, top),
Size2D::new(right, iterator.origin_rect.size.height))
}
}
}

@tigercosmos
Copy link
Collaborator Author

@tigercosmos tigercosmos commented Nov 30, 2017

pub fn process_margin_style_query<N: LayoutNode>(requested_node: N)
-> MarginStyleResponse {
let layout_node = requested_node.to_threadsafe();
let style = &*layout_node.as_element().unwrap().resolved_style();
let margin = style.get_margin();
MarginStyleResponse {
top: margin.margin_top,
right: margin.margin_right,
bottom: margin.margin_bottom,
left: margin.margin_left,
}
}

bors-servo added a commit that referenced this issue Dec 3, 2017
[WIP] fix scroll area about scrollHeight and scrollWidth

<!-- Please describe your changes on the following line: -->
Currently `scrollHeight` will get the result that `max(height + padding, margin)`
It should be `scrollHeight = height + padding + margin`

---
<!-- 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 #19280 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/19469)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Dec 7, 2017
[WIP] fix scroll area about scrollHeight and scrollWidth

<!-- Please describe your changes on the following line: -->
Currently `scrollHeight` will get the result that `max(height + padding, margin)`
It should be `scrollHeight = height + padding + margin`
Same as `scrollWidth`

---
<!-- 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 #19280 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/19469)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.