Menu

#1997 Element height calculation ignores children if the height of the element itself is 0

2.33
accepted
RBRi
None
1
2018-10-24
2018-10-18
No

The test code:

    @Test
    public void testMain() throws Exception
    {
        List<String> alerts = new ArrayList<>();
        WebClient wc=new WebClient();
        wc.setAlertHandler(new CollectingAlertHandler(alerts));
        wc.getPage(getClass().getResource("element_size.html"));
        System.out.println(alerts.toString());
    }

The element_size.html page:

<html>
<head>
<title>size test</title>
</head>

<body>
    <div id="div1">
        <iframe height="360" src="http://www.bing.com" frameborder="0" width="410"></iframe>
    </div>
<script language="JavaScript"> 
    alert(div1.offsetHeight);
</script>
</body>
</html>

In real browser, the alert result is 360. In htmlunit, the result is 0.
If I comment out the code below in ComputedCSSStyleDeclaration.getCalculatedHeight(), the alert result is 154. Though it's still not the same as the browser, but it's much better.

private int getCalculatedHeight() {
        if (height_ != null) {
            return height_.intValue();
        }

        int height = getEmptyHeight();
//        if (height == 0) {
//            height_ = Integer.valueOf(0);
//            return 0;
//        }

        if (super.getHeight().isEmpty()) {

I also noticed the logic in getCalculatedWidth() is different:

        private int getCalculatedWidth() {
        if (width_ != null) {
            return width_.intValue();
        }

        final Element element = getElement();
        final DomNode node = element.getDomNodeOrDie();
        if (!node.mayBeDisplayed()) {
            width_ = Integer.valueOf(0);
            return 0;
        }

Discussion

  • RBRi

    RBRi - 2018-10-24

    Sorry, but this is not that simple.... will try to fix this if there is time

     
  • RBRi

    RBRi - 2018-10-24
    • status: open --> accepted
    • assigned_to: RBRi
     

Log in to post a comment.

MongoDB Logo MongoDB