Enable fieldsets to be flexboxes, grids and multicolumn.
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Mar 2017 18:00:35 +0000 (18:00 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Mar 2017 18:00:35 +0000 (18:00 +0000)
commit04ba00fc0060755bb9e4cb4027c919f05098c905
treea220aec0a0e4810104bfcf79312a144cd82ee0f9
parent3329867c2a99016401cfe37f2cc5c178777c4ebb
Enable fieldsets to be flexboxes, grids and multicolumn.
https://bugs.webkit.org/show_bug.cgi?id=169082

Source/WebCore:

Reviewed by Simon Fraser .

Added new tests in fast/forms/fieldset.

This patch eliminates RenderFieldset and moves the functionality into RenderBlock so that
derived classes can also be fieldsets.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
Remove RenderFieldset from the project.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::titleUIElement):
Call in to RenderBlock now instead of RenderFieldset.

* html/HTMLFieldSetElement.cpp:
(WebCore::HTMLFieldSetElement::createElementRenderer):
* html/HTMLFieldSetElement.h:
The fieldset DOM element now uses RenderElement::createFor to make renderers so that multiple display types
can be supported. A special flag has been added that indicates only to make flexbox and block-related
renderers (not table display types).

* rendering/OrderIterator.cpp:
(WebCore::OrderIterator::shouldSkipChild):
(WebCore::OrderIteratorPopulator::collectChild):
* rendering/OrderIterator.h:
Streamline child collection for flexboxes and grids to indicate whether the child should be skipped as a return
value from collectChild. Add a shouldSkipChild method that skips both out of flow positioned objects and
excluded children like the legends of fieldsets.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlockRareData::RenderBlockRareData):
When the legend is taller than the fieldset's borderBefore(), intrinsic border is added to the CSS border width.
This intrinsic border being factored in ensures that the padding and content boxes of fieldsets are correct
across any layout system, since the legend is now just treated as part of the border.

(WebCore::RenderBlock::computePreferredLogicalWidths):
(WebCore::RenderBlock::computeBlockPreferredLogicalWidths):
Call the new computePreferredWidthsForExcludedChildren to ensure that excluded children contribute to
preferred width in their own way and not as part of a specific layout system.

(WebCore::RenderBlock::renderName):
Hacked to still return RenderFieldSet for RenderBlockFlow-backed fieldsets for layout test compatibility.

(WebCore::RenderBlock::layoutExcludedChildren):
Renamed from layoutSpecialExcludedChild to more accurately reflect the fact that multiple excluded children
can be included here (e.g., both a multicolumn flow thread and a legend). The RenderBlock base class handles
the layout of legends by both placing them and setting the correct intrinsic border before amount on the
block.

(WebCore::RenderBlock::findFieldsetLegend):
Moved from RenderFieldset.

(WebCore::RenderBlock::adjustBorderBoxRectForPainting):
(WebCore::RenderBlock::paintRectToClipOutFromBorder):
These methods are used when painting to shrink the border box as needed to account for the legend and to
provide the portion of the border that needs to be clipped out. These methods have been enhanced to
properly support all writing modes.

(WebCore::RenderBlock::intrinsicBorderForFieldset):
(WebCore::RenderBlock::setIntrinsicBorderForFieldset):
(WebCore::RenderBlock::borderTop):
(WebCore::RenderBlock::borderLeft):
(WebCore::RenderBlock::borderBottom):
(WebCore::RenderBlock::borderRight):
(WebCore::RenderBlock::borderBefore):
These methods are overridden for border to ensure that the intrinsic border added by a tall legend is
properly factored in.

(WebCore::RenderBlock::computePreferredWidthsForExcludedChildren):
* rendering/RenderBlock.h:
This method computes the preferred widths for legend children in order to ensure that the legend properly
grows the width of the fieldset when it is the widest item.

(WebCore::RenderBlock::adjustBorderBoxLogicalHeightForBoxSizing):
(WebCore::RenderBlock::adjustContentBoxLogicalHeightForBoxSizing):
Preserve the behavior of fieldsets in that the available content size includes the space lost accounting
for the legend. I don't think this makes much sense, but it matches the behavior of other browsers
(and our old behavior).

(WebCore::RenderBlock::paintExcludedChildrenInBorder):
Method for painting the excluded children that might be present in our border. We only do this if the
paint phase is a box decoration painting phase and if the legend isn't self-painting.

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::willCreateColumns):
Allow fieldsets to create columns now.

(WebCore::RenderBlockFlow::layoutBlockChildren):
(WebCore::RenderBlockFlow::layoutExcludedChildren):
Renamed this method and change it to call the base class to ensure that legends in multicolumn fieldsets
get handled properly.

(WebCore::RenderBlockFlow::addChild):
Patched to make sure legends don't get put into the multicolumn flow thread, as they need to
remain outside of it.

(WebCore::RenderBlockFlow::layoutSpecialExcludedChild): Deleted.
Renamed to layoutExcludedChildren.

* rendering/RenderBlockFlow.h:
* rendering/RenderBox.cpp:
(WebCore::RenderBox::paintBoxDecorations):
(WebCore::RenderBox::paintMask):
Patched to call the new adjustBorderBoxRectForPainting and paintRectToClipOutFromBorder methods in
order to properly shrink the border box rect for painting and to clip out the portion of the border
covered by the legend.

(WebCore::RenderBox::avoidsFloats):
Add fieldsets as avoiding floats. RenderFieldset used to subclass this method to return true, but with
its removal, we need to put this in the base class along with legends.

* rendering/RenderBox.h:
(WebCore::RenderBox::isGridItem):
(WebCore::RenderBox::isFlexItem):
Patched to exclude legends so that they don't try to size like they are really in the grid or flexbox.

(WebCore::RenderBox::adjustBorderBoxRectForPainting):
This method is overridden by RenderBLock to handle adjusting fieldset border rects for painting.

* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintBorder):
* rendering/RenderBoxModelObject.h:
(WebCore::RenderBoxModelObject::paintRectToClipOutFromBorder):
Patched to properly paint fieldsets using the new helpers.

* rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::FlexBoxIterator::next):
(WebCore::RenderDeprecatedFlexibleBox::layoutBlock):
(WebCore::RenderDeprecatedFlexibleBox::layoutHorizontalBox):
Make sure deprecated flexible boxes lay out their legends properly by calling layoutExcludedChildren.

* rendering/RenderElement.cpp:
(WebCore::RenderElement::createFor):
* rendering/RenderElement.h:
Patched to take a flag that limits what renderers can be created so that fieldsets don't make table
display types.

* rendering/RenderFieldset.cpp: Removed.
* rendering/RenderFieldset.h: Removed.
Remove RenderFieldset files from the tree.

* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::computeIntrinsicLogicalWidths):
(WebCore::RenderFlexibleBox::firstLineBaseline):
(WebCore::RenderFlexibleBox::layoutBlock):
(WebCore::RenderFlexibleBox::layoutFlexItems):
(WebCore::RenderFlexibleBox::prepareOrderIteratorAndMargins):
Make sure flexible boxes lay out their legends properly by calling layoutExcludedChildren.
Patch methods to use the OrderIterator's new shouldSkipChild method to ensure legends aren't
part of the flexible box layout.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::computeIntrinsicLogicalWidths):
(WebCore::RenderGrid::placeItemsOnGrid):
(WebCore::RenderGrid::populateExplicitGridAndOrderIterator):
(WebCore::RenderGrid::layoutGridItems):
Make sure grids lay out their legends properly by calling layoutExcludedChildren.
Patch methods to use the OrderIterator's new shouldSkipChild method to ensure legends aren't
part of the grid's layout.

* rendering/RenderMultiColumnFlowThread.cpp:
(WebCore::RenderMultiColumnFlowThread::populate):
Pull legends back up into the block and don't let them be part of the flow thread.

* rendering/RenderMultiColumnSet.cpp:
(WebCore::RenderMultiColumnSet::requiresBalancing):
Fix an assert to allow legends to exist as siblings of multicolumn sets.

* rendering/RenderObject.cpp:
(WebCore::RenderObject::isFieldset):
Changed to examine the HTML element rather than RenderFieldset.

* rendering/RenderObject.h:
(WebCore::RenderObject::isExcludedFromNormalLayout):
(WebCore::RenderObject::setIsExcludedFromNormalLayout):
(WebCore::RenderObject::RenderObjectBitfields::RenderObjectBitfields):
RenderObjects now have a new bit that is set for excluded objects like legends, flow threads,
placeholders, and ruby text. This bit lets code easily detect that an object is excluded from
the layout system and can be skipped.

(WebCore::RenderObject::isExcludedAndPlacedInBorder):
Helper method for asking if an object is painting inside the border. Used to know we
need to factor it into preferred width calculations outside of any one layout system
and also to know that we need to paint it when we paint the fieldset's border instead of
later (after we might have scrolled or clipped the child painting area).

* rendering/RenderRubyRun.cpp:
(WebCore::RenderRubyRun::layoutExcludedChildren):
(WebCore::RenderRubyRun::layoutSpecialExcludedChild): Deleted.
* rendering/RenderRubyRun.h:
Rename layoutSpecialExcludedChild to layoutExcludedChildren.

* rendering/RenderTable.cpp:
(WebCore::RenderTable::adjustBorderBoxRectForPainting):
(WebCore::RenderTable::paintBoxDecorations):
(WebCore::RenderTable::paintMask):
(WebCore::RenderTable::subtractCaptionRect): Deleted.
* rendering/RenderTable.h:
Patched tables to share the same border box rect adjustment used by fieldsets when subtracting
out captions. This is prep work to allow tables to be fieldsets, but for now I didn't go all the
way.

* rendering/RenderTableCell.cpp:
(WebCore::RenderTableCell::paintBoxDecorations):
(WebCore::RenderTableCell::paintMask):
Make sure table cells adjust their border box rects for painting. Again this is prep work for
cells potentially being fieldsets, but not supported yet.

* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::layoutExcludedChildren):
(WebCore::RenderTextControl::layoutSpecialExcludedChild): Deleted.
* rendering/RenderTextControl.h:
* rendering/RenderTextControlMultiLine.cpp:
(WebCore::RenderTextControlMultiLine::layoutExcludedChildren):
(WebCore::RenderTextControlMultiLine::layoutSpecialExcludedChild): Deleted.
* rendering/RenderTextControlMultiLine.h:
Renamed the methods for doing the excluded child layout.

* rendering/RenderTreeAsText.cpp:
(WebCore::RenderTreeAsText::writeRenderObject):
Make sure to dump the original fieldset border and not the border with the extra legend stuff in it.

LayoutTests:

Reviewed by Simon Fraser.

* fast/forms/fieldset/abs-pos-child-sizing-expected.html: Added.
* fast/forms/fieldset/abs-pos-child-sizing.html: Added.
* fast/forms/fieldset/fieldset-deprecated-flexbox-expected.html: Added.
* fast/forms/fieldset/fieldset-deprecated-flexbox.html: Added.
* fast/forms/fieldset/fieldset-flexbox-expected.html: Added.
* fast/forms/fieldset/fieldset-flexbox.html: Added.
* fast/forms/fieldset/fieldset-grid-expected.html: Added.
* fast/forms/fieldset/fieldset-grid.html: Added.
* fast/forms/fieldset/fieldset-multicolumn-expected.html: Added.
* fast/forms/fieldset/fieldset-multicolumn.html: Added.
* fast/forms/fieldset/fieldset-overflow-auto-expected.html: Added.
* fast/forms/fieldset/fieldset-overflow-auto.html: Added.
* fast/forms/fieldset/fieldset-overflow-hidden-expected.html: Added.
* fast/forms/fieldset/fieldset-overflow-hidden.html: Added.
* fast/forms/fieldset/fieldset-positioned-children-expected.html: Added.
* fast/forms/fieldset/fieldset-positioned-children.html: Added.
* fast/forms/fieldset/fieldset-positioned-legend-expected.html: Added.
* fast/forms/fieldset/fieldset-positioned-legend.html: Added.
* fast/forms/fieldset/fieldset-self-painting-legend-expected.html: Added.
* fast/forms/fieldset/fieldset-self-painting-legend.html: Added.
* fast/forms/fieldset/fieldset-writing-modes-expected.html: Added.
* fast/forms/fieldset/fieldset-writing-modes.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213455 268f45cc-cd09-0410-ab3c-d52691b4dbfc
62 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/fieldset/abs-pos-child-sizing-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/abs-pos-child-sizing.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-deprecated-flexbox-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-deprecated-flexbox.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-flexbox-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-flexbox.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-grid-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-grid.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-multicolumn-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-multicolumn.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-overflow-auto-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-overflow-auto.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-overflow-hidden-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-overflow-hidden.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-positioned-children-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-positioned-children.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-positioned-legend-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-positioned-legend.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-self-painting-legend-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-self-painting-legend.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-writing-modes-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-writing-modes.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
Source/WebCore/html/HTMLFieldSetElement.cpp
Source/WebCore/html/HTMLFieldSetElement.h
Source/WebCore/rendering/OrderIterator.cpp
Source/WebCore/rendering/OrderIterator.h
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBlock.h
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderBlockFlow.h
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBox.h
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderBoxModelObject.h
Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderElement.h
Source/WebCore/rendering/RenderFieldset.cpp [deleted file]
Source/WebCore/rendering/RenderFieldset.h [deleted file]
Source/WebCore/rendering/RenderFlexibleBox.cpp
Source/WebCore/rendering/RenderGrid.cpp
Source/WebCore/rendering/RenderMultiColumnFlowThread.cpp
Source/WebCore/rendering/RenderMultiColumnSet.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/RenderRubyRun.cpp
Source/WebCore/rendering/RenderRubyRun.h
Source/WebCore/rendering/RenderTable.cpp
Source/WebCore/rendering/RenderTable.h
Source/WebCore/rendering/RenderTableCell.cpp
Source/WebCore/rendering/RenderTextControl.cpp
Source/WebCore/rendering/RenderTextControl.h
Source/WebCore/rendering/RenderTextControlMultiLine.cpp
Source/WebCore/rendering/RenderTextControlMultiLine.h
Source/WebCore/rendering/RenderTreeAsText.cpp
Source/WebCore/rendering/RenderingAllInOne.cpp