Bug 78493

Summary: [CSSRegions][CSSOM] Implement Element.getRegionFlowRanges
Product: WebKit Reporter: Raul Hudea <rhudea>
Component: WebKit Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, cmarcelo, donggwan.kim, eric, mihnea, ojan, stearns, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 66643    
Attachments:
Description Flags
Current work (still lots of fprintf's)
none
patch
hyatt: review-, hyatt: commit-queue-
Address reviewer comments
none
Removed duplicate changelog entry (from the patch above)
webkit-ews: commit-queue-
Make the qt bot happy
hyatt: review-, hyatt: commit-queue-
Remove the copy-pasted toInt()
none
Addresses Adam's comment about visibility on IDL
hyatt: review+, webkit.review.bot: commit-queue-
Rebased patch
none
Fix the reviewer name in rebased patch
webkit.review.bot: commit-queue-
Some extraspace manages to enter somehow in the previous patch none

Description Raul Hudea 2012-02-13 06:35:47 PST
Implement the Element.getRegionsFlowRanges extension from http://dev.w3.org/csswg/css3-regions/
Comment 1 Raul Hudea 2012-08-03 11:26:25 PDT
Created attachment 156424 [details]
Current work (still lots of fprintf's)

This is the current status for this:
- the patch is still in its infancy (no tests in this one)
- the idea behind is to do walk the RenderFlowThread in order to find the RenderObjects that starts and ends this region (it uses an identical AnchorType as the Position, in order to be able have things like BeforeAnchor, BeforeChildren, InAnchor (for text)..)
- after this RenderObject boundary is found, then it tries to map it over the DOM tree and create extra Ranges when a hole is found (for example a node inside a content node is also a content node => those nodes are siblings in the RenderTree).
Comment 2 Raul Hudea 2012-08-30 09:36:45 PDT
Created attachment 161495 [details]
patch
Comment 3 Dave Hyatt 2012-08-30 10:11:12 PDT
Comment on attachment 161495 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=161495&action=review

r-. Comments below.

> Source/WebCore/rendering/RenderBlock.cpp:7189
> +    // slower path without layout state
> +    LayoutUnit offsetTop;
> +    const RenderBlock* currBlock = this;

Can you put in a FIXME above this code that it doesn't work for columns or pages? Right now nothing works outside of layout, but with your change, only regions will work outside of layout. That's actually fine, since the new columns and pages are written using regions and will work with this new code you've put in, but I'd at least like a FIXME for now that it doesn't work with the current columns and pages code.

Something like;

// FIXME: This is a slower path that doesn't use layout state and relies on getting your logical top inside the enclosing flow thread. It doesn't
// work with columns or pages currently, but it should once they have been switched over to using flow threads.

Also, I'd like to see an ASSERT added to prevent anyone from calling this outside of layout for anything but regions. You can do this by adding:

ASSERT(currBlock->inRenderFlowThread());

before your loop. You could also just go ahead and bail with a return value of ZERO_LAYOUT_UNIT if currBlock isn't inside a render flow thread (following the assert).

> Source/WebCore/rendering/RenderBlock.cpp:7192
> +        offsetTop += currBlock->logicalTop();

This isn't correct. You have to account for changes in writing mode as you crawl up containing blocks. You're going to need to add isWritingModeRoot checks and do flipping as needed in order to get the correct offset.

You're going to need some additional tests here. Embed a few orthogonal writing mode objects inside your regions so that you are testing this, e.g., put a vertical-rl object inside a horizontal-tb flow thread etc. They don't paginate and just move atomically, but they should still work correctly as far as knowing what region they're in.

> Source/WebCore/rendering/RenderFlowThread.cpp:-792
> -

Random whitespace change. Please revert this.

> Source/WebCore/rendering/RenderNamedFlowThread.cpp:378
> +    LayoutRect regionRect(region->flowThreadPortionRect());

I would prefer you call the local flowThreadPortionRect and not regionRect.

Ultimately we're probably going to move to adopt CSS3 Fragmentation's terminology and start calling these fragmentRects, but for now let's keep using flowThreadPortion.

> Source/WebCore/rendering/RenderNamedFlowThread.cpp:387
> +        logicalTopForRegion = logicalTopForBox(isHorizontalWritingMode(), regionRect);

I think this would be a useful method to put on RenderRegion itself. I can see this being used by others, and I think there are even existing places in the code that grab this value that would benefit from such a helper.

Something like:

LayoutUnit RenderRegion::logicalTopForFlowThreadContent() const { return flowThread()->isHorizontalWritingMode() ? flowThreadPortionRect().y() : flowThreadPortionRect().x(); }

If you look around you'll see we do the above in other places in the code too.

> Source/WebCore/rendering/RenderNamedFlowThread.cpp:393
> +        logicalBottomForRegion = logicalBottomForBox(isHorizontalWritingMode(), regionRect);

LayoutUnit RenderRegion::logicalBottomForFlowThreadContent() const { return flowThread()->isHorizontalWritingMode() ? flowThreadPortionRect().maxY() : flowThreadPortionRect().maxX(); }

> Source/WebCore/rendering/RenderNamedFlowThread.cpp:439
> +            LayoutUnit logicalTopForRenderer = logicalTopForBox(isHorizontalWritingMode(), boundingBox);
> +            LayoutUnit logicalBottomForRenderer = logicalBottomForBox(isHorizontalWritingMode(), boundingBox);

RenderRegion::logicalTopOfFlowThreadContentRect(const LayoutRect& rect) const;
RenderRegion::logicalBottomOfFlowThreadContentRect(const LayoutRect& rect) const;

Could even implement the previous helpers I suggested and have them call these, passing in the flowThreadPortionRect().
Comment 4 Raul Hudea 2012-09-06 06:34:46 PDT
Created attachment 162493 [details]
Address reviewer comments
Comment 5 Raul Hudea 2012-09-06 06:43:51 PDT
Created attachment 162499 [details]
Removed duplicate changelog entry (from the patch above)
Comment 6 Early Warning System Bot 2012-09-06 08:11:57 PDT
Comment on attachment 162499 [details]
Removed duplicate changelog entry (from the patch above)

Attachment 162499 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/13761983
Comment 7 Raul Hudea 2012-09-06 08:17:32 PDT
Created attachment 162511 [details]
Make the qt bot happy
Comment 8 Dave Hyatt 2012-09-10 10:06:16 PDT
Comment on attachment 162511 [details]
Make the qt bot happy

View in context: https://bugs.webkit.org/attachment.cgi?id=162511&action=review

Looks good. Just minor nits. I would possibly think about that writing mode section, since it feels like that could be simplified to me, but if you fix the other issues I pointed out that's good enough for a +.

> Source/WebCore/rendering/RenderBlock.cpp:7220
> +        if (containerBlock->style()->writingMode() != currentBlock->style()->writingMode()) {

You can use the method isWritingModeRoot() here. That's cleaner than having to compare the writing mode styles.

> Source/WebCore/rendering/RenderBlock.cpp:7231
> +            if (containerBlock->style()->isFlippedBlocksWritingMode()) {
> +                if (containerBlock->isHorizontalWritingMode())
> +                    blockRect.setY(currentBlock->height() - blockRect.maxY());
> +                else
> +                    blockRect.setX(currentBlock->width() - blockRect.maxX());
> +            }
> +            currentBlock->flipForWritingMode(blockRect);
> +        }
> +        blockRect.moveBy(currentBlockLocation);

I think this is correct, but it feels kind of convoluted to me. I think it could be simplified, but I won't hold up review for it.

> Source/WebCore/rendering/RenderBlock.cpp:7234
> +    return currentBlock->isHorizontalWritingMode() ? blockRect.y().toInt() : blockRect.x().toInt();

You should not be returning toInt() here, should you? Your function is returning a LayoutUnit, which means you don't need to be converting to int.
Comment 9 Adam Barth 2012-09-10 10:10:59 PDT
Comment on attachment 162511 [details]
Make the qt bot happy

View in context: https://bugs.webkit.org/attachment.cgi?id=162511&action=review

> Source/WebCore/dom/Element.idl:147
>          // CSS Regions API
>          readonly attribute DOMString webkitRegionOverset;
> +        sequence<Range> webkitGetRegionFlowRanges();

Is there no ENABLE macro for regions?  These DOM APIs shouldn't be enabled by default.
Comment 10 Raul Hudea 2012-09-10 12:06:45 PDT
Created attachment 163176 [details]
Remove the copy-pasted toInt()

- As discussed on IRC, the isWritingModeRoot is using the parent style writing mode, while here is needed the container's one
- For now, I would like to leave the writing mode code as is. If there were a function like flipForWritingModeForBlock(RenderBlock*, LayoutRect&) the code would be just:

   container->flipForWritingModeForBlock(currentBlock, rect);
   currentBlock->flipForWritingMode(rect);

  In the worst case, you need to do two flips.
Comment 11 Raul Hudea 2012-09-10 12:21:24 PDT
Created attachment 163179 [details]
Addresses Adam's comment about visibility on IDL
Comment 12 Raul Hudea 2012-09-10 12:25:58 PDT
(In reply to comment #9)
> (From update of attachment 162511 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=162511&action=review
> 
> > Source/WebCore/dom/Element.idl:147
> >          // CSS Regions API
> >          readonly attribute DOMString webkitRegionOverset;
> > +        sequence<Range> webkitGetRegionFlowRanges();
> 
> Is there no ENABLE macro for regions?  These DOM APIs shouldn't be enabled by default.

I made the webkitGetRegionFlowRanges not visible if CSS_REGIONS is not enable, but for the others I've added a new bug to make sure every Regions API is validated: https://bugs.webkit.org/show_bug.cgi?id=96300

Thanks for catching that.
Comment 13 Adam Barth 2012-09-10 12:38:19 PDT
Comment on attachment 163179 [details]
Addresses Adam's comment about visibility on IDL

View in context: https://bugs.webkit.org/attachment.cgi?id=163179&action=review

> Source/WebCore/dom/Element.idl:147
> +        [Conditional=CSS_REGIONS] sequence<Range> webkitGetRegionFlowRanges();

Thanks!
Comment 14 Dave Hyatt 2012-09-12 13:03:54 PDT
Comment on attachment 163179 [details]
Addresses Adam's comment about visibility on IDL

r=me
Comment 15 WebKit Review Bot 2012-09-12 13:05:50 PDT
Comment on attachment 163179 [details]
Addresses Adam's comment about visibility on IDL

Rejecting attachment 163179 [details] from commit-queue.

Failed to run "['/mnt/git/webkit-commit-queue/Tools/Scripts/webkit-patch', '--status-host=queues.webkit.org', '-..." exit_code: 2

Last 500 characters of output:
ile Source/WebCore/rendering/RenderNamedFlowThread.h
patching file Source/WebCore/rendering/RenderRegion.cpp
Hunk #3 succeeded at 542 with fuzz 1 (offset 40 lines).
patching file Source/WebCore/rendering/RenderRegion.h
Hunk #2 FAILED at 98.
1 out of 2 hunks FAILED -- saving rejects to file Source/WebCore/rendering/RenderRegion.h.rej

Failed to run "[u'/mnt/git/webkit-commit-queue/Tools/Scripts/svn-apply', u'--force', u'--reviewer', u'David Hyatt']" exit_code: 1 cwd: /mnt/git/webkit-commit-queue

Full output: http://queues.webkit.org/results/13825755
Comment 16 Raul Hudea 2012-09-12 22:31:46 PDT
Created attachment 163777 [details]
Rebased patch
Comment 17 Raul Hudea 2012-09-12 23:06:25 PDT
Created attachment 163785 [details]
Fix the reviewer name in rebased patch
Comment 18 WebKit Review Bot 2012-09-12 23:13:00 PDT
Comment on attachment 163785 [details]
Fix the reviewer name in rebased patch

Rejecting attachment 163785 [details] from commit-queue.

Failed to run "['/mnt/git/webkit-commit-queue/Tools/Scripts/webkit-patch', '--status-host=queues.webkit.org', '-..." exit_code: 2

Last 500 characters of output:
rBox.cpp
patching file Source/WebCore/rendering/RenderNamedFlowThread.cpp
patching file Source/WebCore/rendering/RenderNamedFlowThread.h
patching file Source/WebCore/rendering/RenderRegion.cpp
Hunk #3 FAILED at 542.
1 out of 3 hunks FAILED -- saving rejects to file Source/WebCore/rendering/RenderRegion.cpp.rej
patching file Source/WebCore/rendering/RenderRegion.h

Failed to run "[u'/mnt/git/webkit-commit-queue/Tools/Scripts/svn-apply', u'--force']" exit_code: 1 cwd: /mnt/git/webkit-commit-queue

Full output: http://queues.webkit.org/results/13841222
Comment 19 Raul Hudea 2012-09-13 00:08:30 PDT
Created attachment 163794 [details]
Some extraspace manages to enter somehow in the previous patch
Comment 20 Mihnea Ovidenie 2012-09-13 00:15:14 PDT
Comment on attachment 163794 [details]
Some extraspace manages to enter somehow in the previous patch

One more round :)
Comment 21 WebKit Review Bot 2012-09-13 00:50:39 PDT
Comment on attachment 163794 [details]
Some extraspace manages to enter somehow in the previous patch

Clearing flags on attachment: 163794

Committed r128416: <http://trac.webkit.org/changeset/128416>
Comment 22 WebKit Review Bot 2012-09-13 00:50:44 PDT
All reviewed patches have been landed.  Closing bug.