Skip to content

element.clientHeight & element.scrollHeight incomplete implement #19280

Closed

Description

@tigercosmos

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()
}

Activity

  1. tigercosmos commented on Nov 19, 2017

    @tigercosmos
    ContributorAuthor

    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

  2. tigercosmos commented on Nov 20, 2017

    @tigercosmos
    ContributorAuthor

    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.

  3. tigercosmos commented on Nov 26, 2017

    @tigercosmos
    ContributorAuthor

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

  4. tigercosmos commented on Nov 30, 2017

    @tigercosmos
    ContributorAuthor

    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,
    }
    }

  5. added 2 commits that reference this issue on Dec 3, 2017
    9a684b4
    69e24cf
  6. lumiscosity commented on May 17, 2026

    @lumiscosity
    Member

    Servo now correctly returns 100 and 200 and so does Firefox. Tested on Arch Linux x86_64, Servo built against commit 6c2ac81, Firefox 150.0.3.

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions