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

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

Issue 2056043002: [css-flexbox] Cache whether our main axis size is definite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 5 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const LayoutUnit innerFlexBaseSize; 83 const LayoutUnit innerFlexBaseSize;
84 const LayoutUnit hypotheticalMainSize; 84 const LayoutUnit hypotheticalMainSize;
85 LayoutUnit flexedContentSize; 85 LayoutUnit flexedContentSize;
86 bool frozen; 86 bool frozen;
87 }; 87 };
88 88
89 LayoutFlexibleBox::LayoutFlexibleBox(Element* element) 89 LayoutFlexibleBox::LayoutFlexibleBox(Element* element)
90 : LayoutBlock(element) 90 : LayoutBlock(element)
91 , m_orderIterator(this) 91 , m_orderIterator(this)
92 , m_numberOfInFlowChildrenOnFirstLine(-1) 92 , m_numberOfInFlowChildrenOnFirstLine(-1)
93 , m_hasDefiniteHeight(-1)
93 { 94 {
94 ASSERT(!childrenInline()); 95 ASSERT(!childrenInline());
95 } 96 }
96 97
97 LayoutFlexibleBox::~LayoutFlexibleBox() 98 LayoutFlexibleBox::~LayoutFlexibleBox()
98 { 99 {
99 } 100 }
100 101
101 LayoutFlexibleBox* LayoutFlexibleBox::createAnonymous(Document* document) 102 LayoutFlexibleBox* LayoutFlexibleBox::createAnonymous(Document* document)
102 { 103 {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 331 }
331 } 332 }
332 333
333 void LayoutFlexibleBox::layoutBlock(bool relayoutChildren) 334 void LayoutFlexibleBox::layoutBlock(bool relayoutChildren)
334 { 335 {
335 ASSERT(needsLayout()); 336 ASSERT(needsLayout());
336 337
337 if (!relayoutChildren && simplifiedLayout()) 338 if (!relayoutChildren && simplifiedLayout())
338 return; 339 return;
339 340
341 LayoutBox* firstChild = firstInFlowChildBox();
342 if (firstChild)
343 m_hasDefiniteHeight = firstChild->computePercentageLogicalHeight(Length( 0, Percent)) != LayoutUnit(-1);
344
340 m_relaidOutChildren.clear(); 345 m_relaidOutChildren.clear();
341 346
342 if (updateLogicalWidthAndColumnWidth()) 347 if (updateLogicalWidthAndColumnWidth())
343 relayoutChildren = true; 348 relayoutChildren = true;
344 349
345 SubtreeLayoutScope layoutScope(*this); 350 SubtreeLayoutScope layoutScope(*this);
346 LayoutUnit previousHeight = logicalHeight(); 351 LayoutUnit previousHeight = logicalHeight();
347 setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight()) ; 352 setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight()) ;
348 353
349 PaintLayerScrollableArea::DelayScrollPositionClampScope delayClampScope; 354 PaintLayerScrollableArea::DelayScrollPositionClampScope delayClampScope;
(...skipping 23 matching lines...) Expand all
373 computeOverflow(clientLogicalBottomAfterRepositioning()); 378 computeOverflow(clientLogicalBottomAfterRepositioning());
374 } 379 }
375 380
376 updateLayerTransformAfterLayout(); 381 updateLayerTransformAfterLayout();
377 382
378 // Update our scroll information if we're overflow:auto/scroll/hidden now th at we know if 383 // Update our scroll information if we're overflow:auto/scroll/hidden now th at we know if
379 // we overflow or not. 384 // we overflow or not.
380 updateAfterLayout(); 385 updateAfterLayout();
381 386
382 clearNeedsLayout(); 387 clearNeedsLayout();
388
389 // We have to reset this, because changes to our ancestors' style
390 // can affect this value.
391 m_hasDefiniteHeight = -1;
383 } 392 }
384 393
385 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo int& paintOffset) const 394 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo int& paintOffset) const
386 { 395 {
387 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); 396 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset);
388 } 397 }
389 398
390 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon text>& lineContexts) 399 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon text>& lineContexts)
391 { 400 {
392 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line Contexts[0].crossAxisOffset; 401 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line Contexts[0].crossAxisOffset;
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 LayoutUnit LayoutFlexibleBox::mainAxisBorderAndPaddingExtentForChild(const Layou tBox& child) const 771 LayoutUnit LayoutFlexibleBox::mainAxisBorderAndPaddingExtentForChild(const Layou tBox& child) const
763 { 772 {
764 return isHorizontalFlow() ? child.borderAndPaddingWidth() : child.borderAndP addingHeight(); 773 return isHorizontalFlow() ? child.borderAndPaddingWidth() : child.borderAndP addingHeight();
765 } 774 }
766 775
767 bool LayoutFlexibleBox::mainAxisLengthIsDefinite(const LayoutBox& child, const L ength& flexBasis) const 776 bool LayoutFlexibleBox::mainAxisLengthIsDefinite(const LayoutBox& child, const L ength& flexBasis) const
768 { 777 {
769 if (flexBasis.isAuto()) 778 if (flexBasis.isAuto())
770 return false; 779 return false;
771 if (flexBasis.hasPercent()) { 780 if (flexBasis.hasPercent()) {
772 return isColumnFlow() ? 781 if (!isColumnFlow() || m_hasDefiniteHeight == 1)
773 child.computePercentageLogicalHeight(flexBasis) != -1 : 782 return true;
774 true; 783 if (m_hasDefiniteHeight == 0)
784 return false;
785 return child.computePercentageLogicalHeight(flexBasis) != -1;
775 } 786 }
776 return true; 787 return true;
777 } 788 }
778 789
779 bool LayoutFlexibleBox::crossAxisLengthIsDefinite(const LayoutBox& child, const Length& length) const 790 bool LayoutFlexibleBox::crossAxisLengthIsDefinite(const LayoutBox& child, const Length& length) const
780 { 791 {
781 if (length.isAuto()) 792 if (length.isAuto())
782 return false; 793 return false;
783 if (length.hasPercent()) { 794 if (length.hasPercent()) {
784 return hasOrthogonalFlow(child) ? 795 if (hasOrthogonalFlow(child) || m_hasDefiniteHeight == 1)
785 true : 796 return true;
786 child.computePercentageLogicalHeight(length) != -1; 797 if (m_hasDefiniteHeight == 0)
798 return false;
799 return child.computePercentageLogicalHeight(length) != -1;
787 } 800 }
788 // TODO(cbiesinger): Eventually we should support other types of sizes here. Requires updating 801 // TODO(cbiesinger): Eventually we should support other types of sizes here. Requires updating
789 // computeMainSizeFromAspectRatioUsing. 802 // computeMainSizeFromAspectRatioUsing.
790 return length.isFixed(); 803 return length.isFixed();
791 } 804 }
792 805
793 bool LayoutFlexibleBox::childFlexBaseSizeRequiresLayout(const LayoutBox& child) const 806 bool LayoutFlexibleBox::childFlexBaseSizeRequiresLayout(const LayoutBox& child) const
794 { 807 {
795 return (!mainAxisLengthIsDefinite(child, flexBasisForChild(child)) 808 return (!mainAxisLengthIsDefinite(child, flexBasisForChild(child))
796 && (hasOrthogonalFlow(child) 809 && (hasOrthogonalFlow(child)
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 // 2) of the flexbox spec. 1155 // 2) of the flexbox spec.
1143 // We need to check for the flexbox to have a definite main size, and for th e 1156 // We need to check for the flexbox to have a definite main size, and for th e
1144 // flex item to have a definite flex basis. 1157 // flex item to have a definite flex basis.
1145 const Length& flexBasis = flexBasisForChild(child); 1158 const Length& flexBasis = flexBasisForChild(child);
1146 if (!mainAxisLengthIsDefinite(child, flexBasis)) 1159 if (!mainAxisLengthIsDefinite(child, flexBasis))
1147 return LayoutUnit(-1); 1160 return LayoutUnit(-1);
1148 if (!flexBasis.hasPercent()) { 1161 if (!flexBasis.hasPercent()) {
1149 // If flex basis had a percentage, our size is guaranteed to be definite or the flex item's 1162 // If flex basis had a percentage, our size is guaranteed to be definite or the flex item's
1150 // size could not be definite. 1163 // size could not be definite.
1151 // Otherwise, we make up a percentage to check whether we have a definit e size. 1164 // Otherwise, we make up a percentage to check whether we have a definit e size.
1152 // TODO(cbiesinger): cache this somewhere
1153 if (!mainAxisLengthIsDefinite(child, Length(0, Percent))) 1165 if (!mainAxisLengthIsDefinite(child, Length(0, Percent)))
1154 return LayoutUnit(-1); 1166 return LayoutUnit(-1);
1155 } 1167 }
1156 1168
1157 if (hasOrthogonalFlow(child)) 1169 if (hasOrthogonalFlow(child))
1158 return child.hasOverrideLogicalContentHeight() ? child.overrideLogicalCo ntentHeight() : LayoutUnit(-1); 1170 return child.hasOverrideLogicalContentHeight() ? child.overrideLogicalCo ntentHeight() : LayoutUnit(-1);
1159 return child.hasOverrideLogicalContentWidth() ? child.overrideLogicalContent Width() : LayoutUnit(-1); 1171 return child.hasOverrideLogicalContentWidth() ? child.overrideLogicalContent Width() : LayoutUnit(-1);
1160 } 1172 }
1161 1173
1162 LayoutUnit LayoutFlexibleBox::childLogicalHeightForPercentageResolution(const La youtBox& child) 1174 LayoutUnit LayoutFlexibleBox::childLogicalHeightForPercentageResolution(const La youtBox& child)
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 ASSERT(child); 1897 ASSERT(child);
1886 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1898 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1887 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1899 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1888 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1900 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1889 adjustAlignmentForChild(*child, newOffset - originalOffset); 1901 adjustAlignmentForChild(*child, newOffset - originalOffset);
1890 } 1902 }
1891 } 1903 }
1892 } 1904 }
1893 1905
1894 } // namespace blink 1906 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698