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

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

Issue 343103003: Flexbox: Allow intrinsic aspect ratios to inform main-size calculation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: WIP Patch 3: Addressing comments of WIP Patch 2 Created 6 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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasi s, bool hasInfiniteLineLength) 601 static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasi s, bool hasInfiniteLineLength)
602 { 602 {
603 return flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && h asInfiniteLineLength); 603 return flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && h asInfiniteLineLength);
604 } 604 }
605 605
606 bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render Box* child, bool hasInfiniteLineLength) const 606 bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render Box* child, bool hasInfiniteLineLength) const
607 { 607 {
608 return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasI nfiniteLineLength) && hasOrthogonalFlow(child); 608 return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasI nfiniteLineLength) && hasOrthogonalFlow(child);
609 } 609 }
610 610
611 bool RenderFlexibleBox::childHasFiniteCrossSize(RenderBox* child) const
612 {
613 if (child->style()->logicalHeight().isFixed())
614 return true;
615
616 if (!style()->logicalHeight().isFixed())
617 return false;
618
619 if (child->style()->logicalHeight().isPercent())
620 return true;
621
622 if (!isMultiline() && needToStretchChildLogicalHeight(child))
623 return true;
624
625 return false;
626 }
627
628 void RenderFlexibleBox::computeAspectRatioOfChild(RenderBox* child, double& aspe ctRatio)
629 {
630 if (child->style()->hasAspectRatio())
631 aspectRatio = child->style()->aspectRatio();
632 else if (child->hasAspectRatio() && child->intrinsicLogicalHeight())
633 aspectRatio = child->intrinsicLogicalWidth().rawValue() / child->intrins icLogicalHeight().rawValue();
634 }
635
611 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox* child, bool hasInfiniteLineLength, bool relayoutChildren) 636 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox* child, bool hasInfiniteLineLength, bool relayoutChildren)
612 { 637 {
613 child->clearOverrideSize(); 638 child->clearOverrideSize();
614 639
615 Length flexBasis = flexBasisForChild(child); 640 Length flexBasis = flexBasisForChild(child);
641 double aspectRatio = -1.0;
642 computeAspectRatioOfChild(child, aspectRatio);
643
644 if (aspectRatio >= 0 && flexBasis.isAuto() && childHasFiniteCrossSize(child) ) {
645 if (!isMultiline() && needToStretchChildLogicalHeight(child))
646 return aspectRatio * style()->logicalHeight().value();
647 return aspectRatio * crossAxisIntrinsicExtentForChild(child);
648 }
649
616 if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength) ) { 650 if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength) ) {
617 LayoutUnit mainAxisExtent; 651 LayoutUnit mainAxisExtent;
618 if (hasOrthogonalFlow(child)) { 652 if (hasOrthogonalFlow(child)) {
619 if (child->needsLayout() || relayoutChildren) { 653 if (child->needsLayout() || relayoutChildren) {
620 m_intrinsicSizeAlongMainAxis.remove(child); 654 m_intrinsicSizeAlongMainAxis.remove(child);
621 child->forceChildLayout(); 655 child->forceChildLayout();
622 m_intrinsicSizeAlongMainAxis.set(child, child->logicalHeight()); 656 m_intrinsicSizeAlongMainAxis.set(child, child->logicalHeight());
623 } 657 }
624 ASSERT(m_intrinsicSizeAlongMainAxis.contains(child)); 658 ASSERT(m_intrinsicSizeAlongMainAxis.contains(child));
625 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(child); 659 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(child);
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 ASSERT(child); 1430 ASSERT(child);
1397 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1431 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1398 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1432 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1399 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1433 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1400 adjustAlignmentForChild(child, newOffset - originalOffset); 1434 adjustAlignmentForChild(child, newOffset - originalOffset);
1401 } 1435 }
1402 } 1436 }
1403 } 1437 }
1404 1438
1405 } 1439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698