[webkit-dev] Unit Test for Page Breaks / absolute coordinates in PrintContext::pageNumberForElement

Milian Wolff milian.wolff at kdab.com
Thu Mar 29 07:02:31 PDT 2012

On Thursday 29 March 2012 15:23:37 Milian Wolff wrote:
> Hey there,
> I'm trying to write a unit test for my layouting patch, that prevents page
> breaks in table rows. So far, I've extended the layoutTestController with a
> pageBreaksInElementById function, similar to pageNumberForElementById.
> The logic behind the implementation is basically an extended copy of
> PrintContext::pageNumberForElement, see e.g. [1].
> Now in my unit test, I call this function for every table row and "ensure"
> that the return value is always 0, i.e. no page break. Turns out, that this
> does not work as expected: My table layouting code [2] takes the offset of
> the surrounding table into account, and the visual result looks OK. The
> unit test code ([1]) though apparently assumes absolute coordinates, which
> (I think?!) box->pixelSnappedOffsetLeft() is *not*. What could be used
> instead? Also, doesn't this also mean that the logic of
> PrintContext::pageNumberForElement is flawed for nested elements that are
> offsetted?
> Note btw. that the box does not have any layout state when called from
> PrintContext::pageBreaksInElement, as such I cannot simply add a call to
> RenderBlock::offsetFromLogicalTopOfFirstPage().
> Thanks
> [1]: http://paste.kde.org/448514/
> [2]: http://paste.kde.org/448520/

Hey again,

I figured out a hackish way to resolve my use-case by doing this:

    if (box->isTableRow() && box->offsetParent()) {
        top += box->offsetParent()->offsetTop();

I wonder why this is required? Looking at RenderBoxModelObject::offsetTop - 
which should be inherited by RenderTableRow - there is already code like that 
in place... but somehow it does not have any effect on table rows, even though 
they are not positioned (!isPositioned() == true) and have an offset parent...

Could someone explain this?

Milian Wolff | milian.wolff at kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel. Germany +49-30-521325470, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20120329/ceb20e02/attachment.bin>

More information about the webkit-dev mailing list