Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutFlexibleBox.cpp

Issue 2150003005: Add grid/flex layout support for <fieldset> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add grid/flex layout support for <fieldset> Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // We have to reset this, because changes to our ancestors' style 401 // We have to reset this, because changes to our ancestors' style
402 // can affect this value. 402 // can affect this value.
403 m_hasDefiniteHeight = SizeDefiniteness::Unknown; 403 m_hasDefiniteHeight = SizeDefiniteness::Unknown;
404 } 404 }
405 405
406 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo int& paintOffset) const 406 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo int& paintOffset) const
407 { 407 {
408 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); 408 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset);
409 } 409 }
410 410
411 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon text>& lineContexts) 411 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon text>& lineContexts, LayoutObject* childToExclude)
412 { 412 {
413 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line Contexts[0].crossAxisOffset; 413 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line Contexts[0].crossAxisOffset;
414 alignFlexLines(lineContexts); 414 alignFlexLines(lineContexts);
415 415
416 alignChildren(lineContexts); 416 alignChildren(lineContexts, childToExclude);
417 417
418 if (style()->flexWrap() == FlexWrapReverse) 418 if (style()->flexWrap() == FlexWrapReverse)
419 flipForWrapReverse(lineContexts, crossAxisStartEdge); 419 flipForWrapReverse(lineContexts, crossAxisStartEdge);
420 420
421 // direction:rtl + flex-direction:column means the cross-axis direction is f lipped. 421 // direction:rtl + flex-direction:column means the cross-axis direction is f lipped.
422 flipForRightToLeftColumn(); 422 flipForRightToLeftColumn();
423 } 423 }
424 424
425 LayoutUnit LayoutFlexibleBox::clientLogicalBottomAfterRepositioning() 425 LayoutUnit LayoutFlexibleBox::clientLogicalBottomAfterRepositioning()
426 { 426 {
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 Vector<LineContext> lineContexts; 885 Vector<LineContext> lineContexts;
886 OrderedFlexItemList orderedChildren; 886 OrderedFlexItemList orderedChildren;
887 LayoutUnit sumFlexBaseSize; 887 LayoutUnit sumFlexBaseSize;
888 double totalFlexGrow; 888 double totalFlexGrow;
889 double totalFlexShrink; 889 double totalFlexShrink;
890 double totalWeightedFlexShrink; 890 double totalWeightedFlexShrink;
891 LayoutUnit sumHypotheticalMainSize; 891 LayoutUnit sumHypotheticalMainSize;
892 892
893 PaintLayerScrollableArea::PreventRelayoutScope preventRelayoutScope(layoutSc ope); 893 PaintLayerScrollableArea::PreventRelayoutScope preventRelayoutScope(layoutSc ope);
894 894
895 // Fieldsets need to find their legend and position it inside the border of the object.
896 // The legend then gets skipped during normal layout.
897 // It doesn't get included in the normal layout process but is instead skipp ed.
898 LayoutObject* childToExclude = layoutSpecialExcludedChild(relayoutChildren, layoutScope);
899
895 m_orderIterator.first(); 900 m_orderIterator.first();
896 LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefor e(); 901 LayoutUnit crossAxisOffset = flowAwareBorderBefore() + flowAwarePaddingBefor e();
897 while (computeNextFlexLine(orderedChildren, sumFlexBaseSize, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink, sumHypotheticalMainSize, relayoutChild ren)) { 902 while (computeNextFlexLine(orderedChildren, sumFlexBaseSize, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink, sumHypotheticalMainSize, relayoutChild ren, childToExclude)) {
898 LayoutUnit containerMainInnerSize = mainAxisContentExtent(sumHypothetica lMainSize); 903 LayoutUnit containerMainInnerSize = mainAxisContentExtent(sumHypothetica lMainSize);
899 // availableFreeSpace is the initial amount of free space in this flexbo x. 904 // availableFreeSpace is the initial amount of free space in this flexbo x.
900 // remainingFreeSpace starts out at the same value but as we place and l ay out 905 // remainingFreeSpace starts out at the same value but as we place and l ay out
901 // flex items we subtract from it. Note that both values can be negative . 906 // flex items we subtract from it. Note that both values can be negative .
902 LayoutUnit remainingFreeSpace = containerMainInnerSize - sumFlexBaseSize ; 907 LayoutUnit remainingFreeSpace = containerMainInnerSize - sumFlexBaseSize ;
903 FlexSign flexSign = (sumHypotheticalMainSize < containerMainInnerSize) ? PositiveFlexibility : NegativeFlexibility; 908 FlexSign flexSign = (sumHypotheticalMainSize < containerMainInnerSize) ? PositiveFlexibility : NegativeFlexibility;
904 freezeInflexibleItems(flexSign, orderedChildren, remainingFreeSpace, tot alFlexGrow, totalFlexShrink, totalWeightedFlexShrink); 909 freezeInflexibleItems(flexSign, orderedChildren, remainingFreeSpace, tot alFlexGrow, totalFlexShrink, totalWeightedFlexShrink);
905 // The initial free space gets calculated after freezing inflexible item s. https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 3 910 // The initial free space gets calculated after freezing inflexible item s. https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 3
906 const LayoutUnit initialFreeSpace = remainingFreeSpace; 911 const LayoutUnit initialFreeSpace = remainingFreeSpace;
907 while (!resolveFlexibleLengths(flexSign, orderedChildren, initialFreeSpa ce, remainingFreeSpace, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink) ) { 912 while (!resolveFlexibleLengths(flexSign, orderedChildren, initialFreeSpa ce, remainingFreeSpace, totalFlexGrow, totalFlexShrink, totalWeightedFlexShrink) ) {
(...skipping 17 matching lines...) Expand all
925 // Even if computeNextFlexLine returns true, the flexbox might not have 930 // Even if computeNextFlexLine returns true, the flexbox might not have
926 // a line because all our children might be out of flow positioned. 931 // a line because all our children might be out of flow positioned.
927 // Instead of just checking if we have a line, make sure the flexbox 932 // Instead of just checking if we have a line, make sure the flexbox
928 // has at least a line's worth of height to cover this case. 933 // has at least a line's worth of height to cover this case.
929 LayoutUnit minHeight = minimumLogicalHeightForEmptyLine(); 934 LayoutUnit minHeight = minimumLogicalHeightForEmptyLine();
930 if (size().height() < minHeight) 935 if (size().height() < minHeight)
931 setLogicalHeight(minHeight); 936 setLogicalHeight(minHeight);
932 } 937 }
933 938
934 updateLogicalHeight(); 939 updateLogicalHeight();
935 repositionLogicalHeightDependentFlexItems(lineContexts); 940 repositionLogicalHeightDependentFlexItems(lineContexts, childToExclude);
936 } 941 }
937 942
938 LayoutUnit LayoutFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi st& children, LayoutUnit& availableFreeSpace) 943 LayoutUnit LayoutFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi st& children, LayoutUnit& availableFreeSpace)
939 { 944 {
940 if (availableFreeSpace <= LayoutUnit()) 945 if (availableFreeSpace <= LayoutUnit())
941 return LayoutUnit(); 946 return LayoutUnit();
942 947
943 int numberOfAutoMargins = 0; 948 int numberOfAutoMargins = 0;
944 bool isHorizontal = isHorizontalFlow(); 949 bool isHorizontal = isHorizontalFlow();
945 for (size_t i = 0; i < children.size(); ++i) { 950 for (size_t i = 0; i < children.size(); ++i) {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1219
1215 LayoutFlexibleBox::FlexItem LayoutFlexibleBox::constructFlexItem(LayoutBox& chil d, ChildLayoutType layoutType) 1220 LayoutFlexibleBox::FlexItem LayoutFlexibleBox::constructFlexItem(LayoutBox& chil d, ChildLayoutType layoutType)
1216 { 1221 {
1217 LayoutUnit borderAndPadding = isHorizontalFlow() ? child.borderAndPaddingWid th() : child.borderAndPaddingHeight(); 1222 LayoutUnit borderAndPadding = isHorizontalFlow() ? child.borderAndPaddingWid th() : child.borderAndPaddingHeight();
1218 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(child, borderAndPadding, layoutType); 1223 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(child, borderAndPadding, layoutType);
1219 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(ch ild, childInnerFlexBaseSize); 1224 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(ch ild, childInnerFlexBaseSize);
1220 LayoutUnit margin = isHorizontalFlow() ? child.marginWidth() : child.marginH eight(); 1225 LayoutUnit margin = isHorizontalFlow() ? child.marginWidth() : child.marginH eight();
1221 return FlexItem(&child, childInnerFlexBaseSize, childMinMaxAppliedMainAxisEx tent, borderAndPadding, margin); 1226 return FlexItem(&child, childInnerFlexBaseSize, childMinMaxAppliedMainAxisEx tent, borderAndPadding, margin);
1222 } 1227 }
1223 1228
1224 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren , LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalFlexShrink, d ouble& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool relayo utChildren) 1229 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren , LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalFlexShrink, d ouble& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool relayo utChildren, LayoutObject* childToExclude)
1225 { 1230 {
1226 orderedChildren.clear(); 1231 orderedChildren.clear();
1227 sumFlexBaseSize = LayoutUnit(); 1232 sumFlexBaseSize = LayoutUnit();
1228 totalFlexGrow = totalFlexShrink = totalWeightedFlexShrink = 0; 1233 totalFlexGrow = totalFlexShrink = totalWeightedFlexShrink = 0;
1229 sumHypotheticalMainSize = LayoutUnit(); 1234 sumHypotheticalMainSize = LayoutUnit();
1230 1235
1231 if (!m_orderIterator.currentChild()) 1236 if (!m_orderIterator.currentChild())
1232 return false; 1237 return false;
1233 1238
1234 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); 1239 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max());
1235 1240
1236 bool lineHasInFlowItem = false; 1241 bool lineHasInFlowItem = false;
1237 1242
1238 for (LayoutBox* child = m_orderIterator.currentChild(); child; child = m_ord erIterator.next()) { 1243 for (LayoutBox* child = m_orderIterator.currentChild(); child; child = m_ord erIterator.next()) {
1244
1245 if (childToExclude == child)
1246 continue; // Skip this child, since it will be positioned by the spe cialized subclass (fieldsets runs).
1247
1239 if (child->isOutOfFlowPositioned()) { 1248 if (child->isOutOfFlowPositioned()) {
1240 orderedChildren.append(FlexItem(child)); 1249 orderedChildren.append(FlexItem(child));
1241 continue; 1250 continue;
1242 } 1251 }
1243 1252
1244 ChildLayoutType layoutType = relayoutChildren ? ForceLayout : LayoutIfNe eded; 1253 ChildLayoutType layoutType = relayoutChildren ? ForceLayout : LayoutIfNe eded;
1245 1254
1246 // If this condition is true, then computeMainAxisExtentForChild will ca ll child.intrinsicContentLogicalHeight() 1255 // If this condition is true, then computeMainAxisExtentForChild will ca ll child.intrinsicContentLogicalHeight()
1247 // and child.scrollbarLogicalHeight(), so if the child has intrinsic min /max/preferred size, 1256 // and child.scrollbarLogicalHeight(), so if the child has intrinsic min /max/preferred size,
1248 // run layout on it now to make sure its logical height and scroll bars are up to date. 1257 // run layout on it now to make sure its logical height and scroll bars are up to date.
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 } 1808 }
1800 1809
1801 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del ta) 1810 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del ta)
1802 { 1811 {
1803 if (child.isOutOfFlowPositioned()) 1812 if (child.isOutOfFlowPositioned())
1804 return; 1813 return;
1805 1814
1806 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou tSize(LayoutUnit(), delta)); 1815 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou tSize(LayoutUnit(), delta));
1807 } 1816 }
1808 1817
1809 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) 1818 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts, L ayoutObject* childToExclude)
1810 { 1819 {
1811 // Keep track of the space between the baseline edge and the after edge of t he box for each line. 1820 // Keep track of the space between the baseline edge and the after edge of t he box for each line.
1812 Vector<LayoutUnit> minMarginAfterBaselines; 1821 Vector<LayoutUnit> minMarginAfterBaselines;
1813 1822
1814 LayoutBox* child = m_orderIterator.first(); 1823 LayoutBox* child = m_orderIterator.first();
1815 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber) { 1824 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber) {
1816 LayoutUnit minMarginAfterBaseline = LayoutUnit::max(); 1825 LayoutUnit minMarginAfterBaseline = LayoutUnit::max();
1817 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExten t; 1826 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExten t;
1818 LayoutUnit maxAscent = lineContexts[lineNumber].maxAscent; 1827 LayoutUnit maxAscent = lineContexts[lineNumber].maxAscent;
1819 1828
1820 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb erOfChildren; ++childNumber, child = m_orderIterator.next()) { 1829 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb erOfChildren; ++childNumber, child = m_orderIterator.next()) {
1821 DCHECK(child); 1830 DCHECK(child);
1831 if (child == childToExclude)
1832 continue;
1822 if (child->isOutOfFlowPositioned()) { 1833 if (child->isOutOfFlowPositioned()) {
1823 if (style()->flexWrap() == FlexWrapReverse) 1834 if (style()->flexWrap() == FlexWrapReverse)
1824 adjustAlignmentForChild(*child, lineCrossAxisExtent); 1835 adjustAlignmentForChild(*child, lineCrossAxisExtent);
1825 continue; 1836 continue;
1826 } 1837 }
1827 1838
1828 if (updateAutoMarginsInCrossAxis(*child, std::max(LayoutUnit(), avai lableAlignmentSpaceForChild(lineCrossAxisExtent, *child)))) 1839 if (updateAutoMarginsInCrossAxis(*child, std::max(LayoutUnit(), avai lableAlignmentSpaceForChild(lineCrossAxisExtent, *child))))
1829 continue; 1840 continue;
1830 1841
1831 ItemPosition position = alignmentForChild(*child); 1842 ItemPosition position = alignmentForChild(*child);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 DCHECK(child); 1933 DCHECK(child);
1923 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1934 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1924 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1935 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1925 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1936 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1926 adjustAlignmentForChild(*child, newOffset - originalOffset); 1937 adjustAlignmentForChild(*child, newOffset - originalOffset);
1927 } 1938 }
1928 } 1939 }
1929 } 1940 }
1930 1941
1931 } // namespace blink 1942 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.h ('k') | third_party/WebKit/Source/core/layout/LayoutGrid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698