| OLD | NEW |
| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include "core/frame/UseCounter.h" | 33 #include "core/frame/UseCounter.h" |
| 34 #include "core/layout/FlexibleBoxAlgorithm.h" | 34 #include "core/layout/FlexibleBoxAlgorithm.h" |
| 35 #include "core/layout/LayoutState.h" | 35 #include "core/layout/LayoutState.h" |
| 36 #include "core/layout/LayoutView.h" | 36 #include "core/layout/LayoutView.h" |
| 37 #include "core/layout/TextAutosizer.h" | 37 #include "core/layout/TextAutosizer.h" |
| 38 #include "core/paint/BlockPainter.h" | 38 #include "core/paint/BlockPainter.h" |
| 39 #include "core/paint/PaintLayer.h" | 39 #include "core/paint/PaintLayer.h" |
| 40 #include "core/style/ComputedStyle.h" | 40 #include "core/style/ComputedStyle.h" |
| 41 #include "platform/LengthFunctions.h" | 41 #include "platform/LengthFunctions.h" |
| 42 #include "wtf/AutoReset.h" |
| 42 #include "wtf/MathExtras.h" | 43 #include "wtf/MathExtras.h" |
| 43 #include <limits> | 44 #include <limits> |
| 44 | 45 |
| 45 namespace blink { | 46 namespace blink { |
| 46 | 47 |
| 47 static bool hasAspectRatio(const LayoutBox& child) { | 48 static bool hasAspectRatio(const LayoutBox& child) { |
| 48 return child.isImage() || child.isCanvas() || child.isVideo(); | 49 return child.isImage() || child.isCanvas() || child.isVideo(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 struct LayoutFlexibleBox::LineContext { | 52 struct LayoutFlexibleBox::LineContext { |
| 52 LineContext(LayoutUnit crossAxisOffset, | 53 LineContext(LayoutUnit crossAxisOffset, |
| 53 LayoutUnit crossAxisExtent, | 54 LayoutUnit crossAxisExtent, |
| 54 LayoutUnit maxAscent, | 55 LayoutUnit maxAscent, |
| 55 Vector<FlexItem>&& flexItems) | 56 Vector<FlexItem>&& flexItems) |
| 56 : crossAxisOffset(crossAxisOffset), | 57 : crossAxisOffset(crossAxisOffset), |
| 57 crossAxisExtent(crossAxisExtent), | 58 crossAxisExtent(crossAxisExtent), |
| 58 maxAscent(maxAscent), | 59 maxAscent(maxAscent), |
| 59 flexItems(flexItems) {} | 60 flexItems(flexItems) {} |
| 60 | 61 |
| 61 LayoutUnit crossAxisOffset; | 62 LayoutUnit crossAxisOffset; |
| 62 LayoutUnit crossAxisExtent; | 63 LayoutUnit crossAxisExtent; |
| 63 LayoutUnit maxAscent; | 64 LayoutUnit maxAscent; |
| 64 Vector<FlexItem> flexItems; | 65 Vector<FlexItem> flexItems; |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 LayoutFlexibleBox::LayoutFlexibleBox(Element* element) | 68 LayoutFlexibleBox::LayoutFlexibleBox(Element* element) |
| 68 : LayoutBlock(element), | 69 : LayoutBlock(element), |
| 69 m_orderIterator(this), | 70 m_orderIterator(this), |
| 70 m_numberOfInFlowChildrenOnFirstLine(-1), | 71 m_numberOfInFlowChildrenOnFirstLine(-1), |
| 71 m_hasDefiniteHeight(SizeDefiniteness::Unknown) { | 72 m_hasDefiniteHeight(SizeDefiniteness::Unknown), |
| 73 m_inLayout(false) { |
| 72 DCHECK(!childrenInline()); | 74 DCHECK(!childrenInline()); |
| 73 if (!isAnonymous()) | 75 if (!isAnonymous()) |
| 74 UseCounter::count(document(), UseCounter::CSSFlexibleBox); | 76 UseCounter::count(document(), UseCounter::CSSFlexibleBox); |
| 75 } | 77 } |
| 76 | 78 |
| 77 LayoutFlexibleBox::~LayoutFlexibleBox() {} | 79 LayoutFlexibleBox::~LayoutFlexibleBox() {} |
| 78 | 80 |
| 79 LayoutFlexibleBox* LayoutFlexibleBox::createAnonymous(Document* document) { | 81 LayoutFlexibleBox* LayoutFlexibleBox::createAnonymous(Document* document) { |
| 80 LayoutFlexibleBox* layoutObject = new LayoutFlexibleBox(nullptr); | 82 LayoutFlexibleBox* layoutObject = new LayoutFlexibleBox(nullptr); |
| 81 layoutObject->setDocumentForAnonymous(document); | 83 layoutObject->setDocumentForAnonymous(document); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 348 } |
| 347 } | 349 } |
| 348 | 350 |
| 349 void LayoutFlexibleBox::layoutBlock(bool relayoutChildren) { | 351 void LayoutFlexibleBox::layoutBlock(bool relayoutChildren) { |
| 350 DCHECK(needsLayout()); | 352 DCHECK(needsLayout()); |
| 351 | 353 |
| 352 if (!relayoutChildren && simplifiedLayout()) | 354 if (!relayoutChildren && simplifiedLayout()) |
| 353 return; | 355 return; |
| 354 | 356 |
| 355 m_relaidOutChildren.clear(); | 357 m_relaidOutChildren.clear(); |
| 358 WTF::AutoReset<bool> reset1(&m_inLayout, true); |
| 359 DCHECK_EQ(m_hasDefiniteHeight, SizeDefiniteness::Unknown); |
| 356 | 360 |
| 357 if (updateLogicalWidthAndColumnWidth()) | 361 if (updateLogicalWidthAndColumnWidth()) |
| 358 relayoutChildren = true; | 362 relayoutChildren = true; |
| 359 | 363 |
| 360 SubtreeLayoutScope layoutScope(*this); | 364 SubtreeLayoutScope layoutScope(*this); |
| 361 LayoutUnit previousHeight = logicalHeight(); | 365 LayoutUnit previousHeight = logicalHeight(); |
| 362 setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight()); | 366 setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight()); |
| 363 | 367 |
| 364 PaintLayerScrollableArea::DelayScrollOffsetClampScope delayClampScope; | 368 PaintLayerScrollableArea::DelayScrollOffsetClampScope delayClampScope; |
| 365 | 369 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 384 | 388 |
| 385 layoutPositionedObjects(relayoutChildren || isDocumentElement()); | 389 layoutPositionedObjects(relayoutChildren || isDocumentElement()); |
| 386 | 390 |
| 387 // FIXME: css3/flexbox/repaint-rtl-column.html seems to issue paint | 391 // FIXME: css3/flexbox/repaint-rtl-column.html seems to issue paint |
| 388 // invalidations for more overflow than it needs to. | 392 // invalidations for more overflow than it needs to. |
| 389 computeOverflow(clientLogicalBottomAfterRepositioning()); | 393 computeOverflow(clientLogicalBottomAfterRepositioning()); |
| 390 } | 394 } |
| 391 | 395 |
| 392 updateLayerTransformAfterLayout(); | 396 updateLayerTransformAfterLayout(); |
| 393 | 397 |
| 398 // We have to reset this, because changes to our ancestors' style can affect |
| 399 // this value. Also, this needs to be before we call updateAfterLayout, as |
| 400 // that function may re-enter this one. |
| 401 m_hasDefiniteHeight = SizeDefiniteness::Unknown; |
| 402 |
| 394 // Update our scroll information if we're overflow:auto/scroll/hidden now | 403 // Update our scroll information if we're overflow:auto/scroll/hidden now |
| 395 // that we know if we overflow or not. | 404 // that we know if we overflow or not. |
| 396 updateAfterLayout(); | 405 updateAfterLayout(); |
| 397 | 406 |
| 398 clearNeedsLayout(); | 407 clearNeedsLayout(); |
| 399 | |
| 400 // We have to reset this, because changes to our ancestors' style can affect | |
| 401 // this value. | |
| 402 m_hasDefiniteHeight = SizeDefiniteness::Unknown; | |
| 403 } | 408 } |
| 404 | 409 |
| 405 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, | 410 void LayoutFlexibleBox::paintChildren(const PaintInfo& paintInfo, |
| 406 const LayoutPoint& paintOffset) const { | 411 const LayoutPoint& paintOffset) const { |
| 407 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); | 412 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); |
| 408 } | 413 } |
| 409 | 414 |
| 410 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems( | 415 void LayoutFlexibleBox::repositionLogicalHeightDependentFlexItems( |
| 411 Vector<LineContext>& lineContexts) { | 416 Vector<LineContext>& lineContexts) { |
| 412 LayoutUnit crossAxisStartEdge = | 417 LayoutUnit crossAxisStartEdge = |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 const LayoutBox& child, | 830 const LayoutBox& child, |
| 826 const Length& flexBasis) const { | 831 const Length& flexBasis) const { |
| 827 if (flexBasis.isAuto()) | 832 if (flexBasis.isAuto()) |
| 828 return false; | 833 return false; |
| 829 if (flexBasis.isPercentOrCalc()) { | 834 if (flexBasis.isPercentOrCalc()) { |
| 830 if (!isColumnFlow() || m_hasDefiniteHeight == SizeDefiniteness::Definite) | 835 if (!isColumnFlow() || m_hasDefiniteHeight == SizeDefiniteness::Definite) |
| 831 return true; | 836 return true; |
| 832 if (m_hasDefiniteHeight == SizeDefiniteness::Indefinite) | 837 if (m_hasDefiniteHeight == SizeDefiniteness::Indefinite) |
| 833 return false; | 838 return false; |
| 834 bool definite = child.computePercentageLogicalHeight(flexBasis) != -1; | 839 bool definite = child.computePercentageLogicalHeight(flexBasis) != -1; |
| 835 m_hasDefiniteHeight = | 840 if (m_inLayout) { |
| 836 definite ? SizeDefiniteness::Definite : SizeDefiniteness::Indefinite; | 841 // We can reach this code even while we're not laying ourselves out, such |
| 842 // as from mainSizeForPercentageResolution. |
| 843 m_hasDefiniteHeight = |
| 844 definite ? SizeDefiniteness::Definite : SizeDefiniteness::Indefinite; |
| 845 } |
| 837 return definite; | 846 return definite; |
| 838 } | 847 } |
| 839 return true; | 848 return true; |
| 840 } | 849 } |
| 841 | 850 |
| 842 bool LayoutFlexibleBox::crossAxisLengthIsDefinite(const LayoutBox& child, | 851 bool LayoutFlexibleBox::crossAxisLengthIsDefinite(const LayoutBox& child, |
| 843 const Length& length) const { | 852 const Length& length) const { |
| 844 if (length.isAuto()) | 853 if (length.isAuto()) |
| 845 return false; | 854 return false; |
| 846 if (length.isPercentOrCalc()) { | 855 if (length.isPercentOrCalc()) { |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2173 LayoutUnit originalOffset = | 2182 LayoutUnit originalOffset = |
| 2174 lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; | 2183 lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; |
| 2175 LayoutUnit newOffset = | 2184 LayoutUnit newOffset = |
| 2176 contentExtent - originalOffset - lineCrossAxisExtent; | 2185 contentExtent - originalOffset - lineCrossAxisExtent; |
| 2177 adjustAlignmentForChild(*flexItem.box, newOffset - originalOffset); | 2186 adjustAlignmentForChild(*flexItem.box, newOffset - originalOffset); |
| 2178 } | 2187 } |
| 2179 } | 2188 } |
| 2180 } | 2189 } |
| 2181 | 2190 |
| 2182 } // namespace blink | 2191 } // namespace blink |
| OLD | NEW |