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

Side by Side Diff: Source/core/rendering/RenderFlexibleBox.cpp

Issue 138683005: Avoid forcing layout on children with orthogonal flow (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Now with expected results! Created 6 years, 11 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 | Annotate | Revision Log
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 198
199 static EAlignItems resolveAlignment(const RenderStyle* parentStyle, const Render Style* childStyle) 199 static EAlignItems resolveAlignment(const RenderStyle* parentStyle, const Render Style* childStyle)
200 { 200 {
201 EAlignItems align = childStyle->alignSelf(); 201 EAlignItems align = childStyle->alignSelf();
202 if (align == AlignAuto) 202 if (align == AlignAuto)
203 align = parentStyle->alignItems(); 203 align = parentStyle->alignItems();
204 return align; 204 return align;
205 } 205 }
206 206
207 void RenderFlexibleBox::removeChild(RenderObject* child)
208 {
209 RenderBlock::removeChild(child);
210 m_intrinsicSizeAlongMainAxis.remove(child);
211 }
212
207 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) 213 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
208 { 214 {
209 RenderBlock::styleDidChange(diff, oldStyle); 215 RenderBlock::styleDidChange(diff, oldStyle);
210 216
211 if (oldStyle && oldStyle->alignItems() == AlignStretch && diff == StyleDiffe renceLayout) { 217 if (oldStyle && oldStyle->alignItems() == AlignStretch && diff == StyleDiffe renceLayout) {
212 // Flex items that were previously stretching need to be relayed out so we can compute new available cross axis space. 218 // Flex items that were previously stretching need to be relayed out so we can compute new available cross axis space.
213 // This is only necessary for stretching since other alignment values do n't change the size of the box. 219 // This is only necessary for stretching since other alignment values do n't change the size of the box.
214 for (RenderBox* child = firstChildBox(); child; child = child->nextSibli ngBox()) { 220 for (RenderBox* child = firstChildBox(); child; child = child->nextSibli ngBox()) {
215 EAlignItems previousAlignment = resolveAlignment(oldStyle, child->st yle()); 221 EAlignItems previousAlignment = resolveAlignment(oldStyle, child->st yle());
216 if (previousAlignment == AlignStretch && previousAlignment != resolv eAlignment(style(), child->style())) 222 if (previousAlignment == AlignStretch && previousAlignment != resolv eAlignment(style(), child->style()))
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 return isHorizontalFlow() ? child->borderAndPaddingWidth() : child->borderAn dPaddingHeight(); 635 return isHorizontalFlow() ? child->borderAndPaddingWidth() : child->borderAn dPaddingHeight();
630 } 636 }
631 637
632 LayoutUnit RenderFlexibleBox::mainAxisScrollbarExtentForChild(RenderBox* child) const 638 LayoutUnit RenderFlexibleBox::mainAxisScrollbarExtentForChild(RenderBox* child) const
633 { 639 {
634 return isHorizontalFlow() ? child->verticalScrollbarWidth() : child->horizon talScrollbarHeight(); 640 return isHorizontalFlow() ? child->verticalScrollbarWidth() : child->horizon talScrollbarHeight();
635 } 641 }
636 642
637 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox* child, bool hasInfiniteLineLength) 643 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox* child, bool hasInfiniteLineLength)
638 { 644 {
639 bool hasOverrideSize = child->hasOverrideWidth() || child->hasOverrideHeight (); 645 if (child->hasOverrideWidth() || child->hasOverrideHeight())
ojan 2014/01/14 22:05:02 I think you can unconditionally call clearOverride
640 if (hasOverrideSize)
641 child->clearOverrideSize(); 646 child->clearOverrideSize();
642 647
643 Length flexBasis = flexBasisForChild(child); 648 Length flexBasis = flexBasisForChild(child);
644 if (flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && hasI nfiniteLineLength)) { 649 if (flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && hasI nfiniteLineLength)) {
650 LayoutUnit mainAxisExtent;
645 if (hasOrthogonalFlow(child)) { 651 if (hasOrthogonalFlow(child)) {
646 if (hasOverrideSize) 652 if (child->needsLayout()) {
647 child->setChildNeedsLayout(MarkOnlyThis); 653 m_intrinsicSizeAlongMainAxis.remove(child);
648 child->layoutIfNeeded(); 654 child->layout();
655 m_intrinsicSizeAlongMainAxis.set(child, child->logicalHeight());
656 }
657 ASSERT(m_intrinsicSizeAlongMainAxis.contains(child));
658 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(child);
659 } else {
660 mainAxisExtent = child->maxPreferredLogicalWidth();
649 } 661 }
650 LayoutUnit mainAxisExtent = hasOrthogonalFlow(child) ? child->logicalHei ght() : child->maxPreferredLogicalWidth();
651 ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >= 0); 662 ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >= 0);
652 return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child); 663 return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child);
653 } 664 }
654 return std::max(LayoutUnit(0), computeMainAxisExtentForChild(child, MainOrPr eferredSize, flexBasis)); 665 return std::max(LayoutUnit(0), computeMainAxisExtentForChild(child, MainOrPr eferredSize, flexBasis));
655 } 666 }
656 667
657 void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren, Vector<LineContex t>& lineContexts) 668 void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren, Vector<LineContex t>& lineContexts)
658 { 669 {
659 OrderedFlexItemList orderedChildren; 670 OrderedFlexItemList orderedChildren;
660 LayoutUnit sumFlexBaseSize; 671 LayoutUnit sumFlexBaseSize;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 for (size_t i = 0; i < children.size(); ++i) { 1050 for (size_t i = 0; i < children.size(); ++i) {
1040 RenderBox* child = children[i]; 1051 RenderBox* child = children[i];
1041 if (!child->isOutOfFlowPositioned()) 1052 if (!child->isOutOfFlowPositioned())
1042 ++count; 1053 ++count;
1043 } 1054 }
1044 return count; 1055 return count;
1045 } 1056 }
1046 1057
1047 void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox* chil d) 1058 void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox* chil d)
1048 { 1059 {
1049 if (hasAutoMarginsInCrossAxis(child)) 1060 if (hasAutoMarginsInCrossAxis(child)) {
1050 child->updateLogicalHeight(); 1061 child->updateLogicalHeight();
1062 if (isHorizontalFlow()) {
1063 if (child->style()->marginTop().isAuto())
1064 child->setMarginTop(0);
1065 if (child->style()->marginBottom().isAuto())
1066 child->setMarginBottom(0);
1067 } else {
1068 if (child->style()->marginLeft().isAuto())
1069 child->setMarginLeft(0);
1070 if (child->style()->marginRight().isAuto())
1071 child->setMarginRight(0);
1072 }
1073 }
1051 } 1074 }
1052 1075
1053 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit>& childSizes, LayoutUni t availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContexts) 1076 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit>& childSizes, LayoutUni t availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContexts)
1054 { 1077 {
1055 ASSERT(childSizes.size() == children.size()); 1078 ASSERT(childSizes.size() == children.size());
1056 1079
1057 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); 1080 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children);
1058 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); 1081 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace);
1059 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; 1082 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ;
1060 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), numberOfChildrenForJustifyContent); 1083 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), numberOfChildrenForJustifyContent);
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 ASSERT(child); 1379 ASSERT(child);
1357 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1380 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1358 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1381 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1359 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1382 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1360 adjustAlignmentForChild(child, newOffset - originalOffset); 1383 adjustAlignmentForChild(child, newOffset - originalOffset);
1361 } 1384 }
1362 } 1385 }
1363 } 1386 }
1364 1387
1365 } 1388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698