Menu

Confused by contentBounds and bounds

Nogge
2013-02-26
2013-04-29
  • Nogge

    Nogge - 2013-02-26

    Hello,

    First of all: You do a great job! An HTML engine is so basic for further analysis und processing that I do not know why you are the first and only guys who have developed such an engine in Java.

    However, please, either explain the contentBounds and the bounds properties of cssbox to me or instruct me to post a bug report: Consider the example below.

    <style type="text/css">
    body {
        margin: 0;
    }
    
    div.page {
        position: relative;
        margin: 10% 7%;
        height: 180mm;
    }
    
    </style>
    
    <body>
        <div class="page">
            <div>
                <table class="header">
                    <tr>
                        <td class="left">Test</td>
                        <td class="right">18.02.2013</td>
                    </tr>
                </table>
            </div>
            <div class="title">
                <h1>Wochenbericht</h1>
                <p>zum</p>
                <p>Wohnungsleerstand</p>
            </div>
            <div id="logo">
                <img ... />
            </div>
        </div>
    </body>
    

    We investigate div.page: Why is contentBounds.y=0 and bounds.y negative? Although the contentBounds are still correctly relative to the bounds, the negative y-value of the bounds takes me by surprise. I expect the bounds.y to be 0 as always and the contentBounds.y to be the sum of the corresponding margin+border+padding.

    Thank you,
    Nogge

     
  • Radek Burget

    Radek Burget - 2013-02-27

    Hello,
    the reason is margin collapsing as defined in CSS specs. In the presented case, the negative Y is equal to the computed value of top margin of div.page. For collapsing the margins, the top margin is propagated to parent nodes (see the EMargin of body and html elements and the content bounds of html). Then, the top margins are collapsed (placed over each other) and therefore, the body and div.page need to be shifted up by Y in order to align the border edges.
    Radek

     
  • Nogge

    Nogge - 2013-03-02

    Ok, I see. But couldn't you also provide a relative content property that considers and thus abstracts those cases, too? Negative values are not intuitive and you need to combine them with the contentbound to get the exact relative content poition.

     
  • Radek Burget

    Radek Burget - 2013-03-10

    I have been thinking about it but I mean it would make the API more complicated as I would have to provide the "original" content bounds as well. I don't know the details of your application but couldn't you just subtract the computed absolute coordinates if you need something like relative values?

     
  • Nogge

    Nogge - 2013-04-29

    Of course, thank you for your suggestion.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.