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

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

Issue 2156323002: [css-flexbox] Simplify code a bit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 LayoutUnit LayoutFlexibleBox::crossAxisIntrinsicExtentForChild(const LayoutBox& child) const 491 LayoutUnit LayoutFlexibleBox::crossAxisIntrinsicExtentForChild(const LayoutBox& child) const
492 { 492 {
493 return isHorizontalFlow() ? childIntrinsicHeight(child) : childIntrinsicWidt h(child); 493 return isHorizontalFlow() ? childIntrinsicHeight(child) : childIntrinsicWidt h(child);
494 } 494 }
495 495
496 LayoutUnit LayoutFlexibleBox::mainAxisExtentForChild(const LayoutBox& child) con st 496 LayoutUnit LayoutFlexibleBox::mainAxisExtentForChild(const LayoutBox& child) con st
497 { 497 {
498 return isHorizontalFlow() ? child.size().width() : child.size().height(); 498 return isHorizontalFlow() ? child.size().width() : child.size().height();
499 } 499 }
500 500
501 LayoutUnit LayoutFlexibleBox::mainAxisContentExtentForChild(const LayoutBox& chi ld) const
502 {
503 return isHorizontalFlow() ? child.contentWidth() : child.contentHeight();
504 }
505
501 LayoutUnit LayoutFlexibleBox::crossAxisExtent() const 506 LayoutUnit LayoutFlexibleBox::crossAxisExtent() const
502 { 507 {
503 return isHorizontalFlow() ? size().height() : size().width(); 508 return isHorizontalFlow() ? size().height() : size().width();
504 } 509 }
505 510
506 LayoutUnit LayoutFlexibleBox::mainAxisExtent() const 511 LayoutUnit LayoutFlexibleBox::mainAxisExtent() const
507 { 512 {
508 return isHorizontalFlow() ? size().width() : size().height(); 513 return isHorizontalFlow() ? size().width() : size().height();
509 } 514 }
510 515
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 case ItemPositionLeft: 1407 case ItemPositionLeft:
1403 case ItemPositionRight: 1408 case ItemPositionRight:
1404 // FIXME: Implement these (https://crbug.com/507690). The extended gramm ar 1409 // FIXME: Implement these (https://crbug.com/507690). The extended gramm ar
1405 // is not enabled by default so we shouldn't hit this codepath. 1410 // is not enabled by default so we shouldn't hit this codepath.
1406 ASSERT_NOT_REACHED(); 1411 ASSERT_NOT_REACHED();
1407 break; 1412 break;
1408 } 1413 }
1409 return LayoutUnit(); 1414 return LayoutUnit();
1410 } 1415 }
1411 1416
1412 void LayoutFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout Unit childPreferredSize) 1417 void LayoutFlexibleBox::setOverrideMainAxisContentSizeForChild(LayoutBox& child, LayoutUnit childPreferredSize)
1413 { 1418 {
1414 if (hasOrthogonalFlow(child)) 1419 if (hasOrthogonalFlow(child))
1415 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA ndPaddingLogicalHeight()); 1420 child.setOverrideLogicalContentHeight(childPreferredSize);
1416 else 1421 else
1417 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn dPaddingLogicalWidth()); 1422 child.setOverrideLogicalContentWidth(childPreferredSize);
1418 } 1423 }
1419 1424
1420 LayoutUnit LayoutFlexibleBox::staticMainAxisPositionForPositionedChild(const Lay outBox& child) 1425 LayoutUnit LayoutFlexibleBox::staticMainAxisPositionForPositionedChild(const Lay outBox& child)
1421 { 1426 {
1422 const LayoutUnit availableSpace = mainAxisContentExtent(contentLogicalHeight ()) - mainAxisExtentForChild(child); 1427 const LayoutUnit availableSpace = mainAxisContentExtent(contentLogicalHeight ()) - mainAxisExtentForChild(child);
1423 1428
1424 ContentPosition position = styleRef().resolvedJustifyContentPosition(normalV alueBehavior()); 1429 ContentPosition position = styleRef().resolvedJustifyContentPosition(normalV alueBehavior());
1425 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(normalValueBehavior()); 1430 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(normalValueBehavior());
1426 LayoutUnit offset = initialJustifyContentOffset(availableSpace, position, di stribution, 1); 1431 LayoutUnit offset = initialJustifyContentOffset(availableSpace, position, di stribution, 1);
1427 if (styleRef().flexDirection() == FlowRowReverse || styleRef().flexDirection () == FlowColumnReverse) 1432 if (styleRef().flexDirection() == FlowRowReverse || styleRef().flexDirection () == FlowColumnReverse)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 const FlexItem& flexItem = children[i]; 1609 const FlexItem& flexItem = children[i];
1605 LayoutBox* child = flexItem.box; 1610 LayoutBox* child = flexItem.box;
1606 1611
1607 if (child->isOutOfFlowPositioned()) { 1612 if (child->isOutOfFlowPositioned()) {
1608 prepareChildForPositionedLayout(*child); 1613 prepareChildForPositionedLayout(*child);
1609 continue; 1614 continue;
1610 } 1615 }
1611 1616
1612 child->setMayNeedPaintInvalidation(); 1617 child->setMayNeedPaintInvalidation();
1613 1618
1614 LayoutUnit childPreferredSize = flexItem.flexedContentSize + mainAxisBor derAndPaddingExtentForChild(*child); 1619 setOverrideMainAxisContentSizeForChild(*child, flexItem.flexedContentSiz e);
1615 setOverrideMainAxisSizeForChild(*child, childPreferredSize); 1620 if (flexItem.flexedContentSize != mainAxisContentExtentForChild(*child)) {
1616 if (childPreferredSize != mainAxisExtentForChild(*child)) {
1617 child->setChildNeedsLayout(MarkOnlyThis); 1621 child->setChildNeedsLayout(MarkOnlyThis);
1618 } else { 1622 } else {
1619 // To avoid double applying margin changes in updateAutoMarginsInCro ssAxis, we reset the margins here. 1623 // To avoid double applying margin changes in updateAutoMarginsInCro ssAxis, we reset the margins here.
1620 resetAutoMarginsAndLogicalTopInCrossAxis(*child); 1624 resetAutoMarginsAndLogicalTopInCrossAxis(*child);
1621 } 1625 }
1622 // We may have already forced relayout for orthogonal flowing children i n computeInnerFlexBaseSizeForChild. 1626 // We may have already forced relayout for orthogonal flowing children i n computeInnerFlexBaseSizeForChild.
1623 bool forceChildRelayout = relayoutChildren && !m_relaidOutChildren.conta ins(child); 1627 bool forceChildRelayout = relayoutChildren && !m_relaidOutChildren.conta ins(child);
1624 if (child->isLayoutBlock() && toLayoutBlock(*child).hasPercentHeightDesc endants()) { 1628 if (child->isLayoutBlock() && toLayoutBlock(*child).hasPercentHeightDesc endants()) {
1625 // Have to force another relayout even though the child is sized cor rectly, because 1629 // Have to force another relayout even though the child is sized cor rectly, because
1626 // its descendants are not sized correctly yet. Our previous layout of the child was 1630 // its descendants are not sized correctly yet. Our previous layout of the child was
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 ASSERT(child); 1906 ASSERT(child);
1903 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1907 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1904 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1908 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1905 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1909 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1906 adjustAlignmentForChild(*child, newOffset - originalOffset); 1910 adjustAlignmentForChild(*child, newOffset - originalOffset);
1907 } 1911 }
1908 } 1912 }
1909 } 1913 }
1910 1914
1911 } // namespace blink 1915 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698