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

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

Issue 1653673002: Even more explicit LayoutUnit conversion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@moarConstructors
Patch Set: address comments Created 4 years, 10 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 if (hasInvertedDirection) 2129 if (hasInvertedDirection)
2130 computedValues.m_margins.m_end += adjustedMargin; 2130 computedValues.m_margins.m_end += adjustedMargin;
2131 else 2131 else
2132 computedValues.m_margins.m_start += adjustedMargin; 2132 computedValues.m_margins.m_start += adjustedMargin;
2133 } 2133 }
2134 } 2134 }
2135 } 2135 }
2136 2136
2137 LayoutUnit LayoutBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth) con st 2137 LayoutUnit LayoutBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth) con st
2138 { 2138 {
2139 LayoutUnit marginStart = 0; 2139 LayoutUnit marginStart;
2140 LayoutUnit marginEnd = 0; 2140 LayoutUnit marginEnd;
2141 return fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd); 2141 return fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd);
2142 } 2142 }
2143 2143
2144 LayoutUnit LayoutBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth, Lay outUnit& marginStart, LayoutUnit& marginEnd) const 2144 LayoutUnit LayoutBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth, Lay outUnit& marginStart, LayoutUnit& marginEnd) const
2145 { 2145 {
2146 ASSERT(availableLogicalWidth >= 0); 2146 ASSERT(availableLogicalWidth >= 0);
2147 marginStart = minimumValueForLength(style()->marginStart(), availableLogical Width); 2147 marginStart = minimumValueForLength(style()->marginStart(), availableLogical Width);
2148 marginEnd = minimumValueForLength(style()->marginEnd(), availableLogicalWidt h); 2148 marginEnd = minimumValueForLength(style()->marginEnd(), availableLogicalWidt h);
2149 LayoutUnit available = availableLogicalWidth - marginStart - marginEnd; 2149 LayoutUnit available = availableLogicalWidth - marginStart - marginEnd;
2150 available = std::max(available, LayoutUnit()); 2150 available = std::max(available, LayoutUnit());
2151 return available; 2151 return available;
2152 } 2152 }
2153 2153
2154 LayoutUnit LayoutBox::computeIntrinsicLogicalWidthUsing(const Length& logicalWid thLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const 2154 LayoutUnit LayoutBox::computeIntrinsicLogicalWidthUsing(const Length& logicalWid thLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const
2155 { 2155 {
2156 if (logicalWidthLength.type() == FillAvailable) 2156 if (logicalWidthLength.type() == FillAvailable)
2157 return fillAvailableMeasure(availableLogicalWidth); 2157 return fillAvailableMeasure(availableLogicalWidth);
2158 2158
2159 LayoutUnit minLogicalWidth = 0; 2159 LayoutUnit minLogicalWidth;
2160 LayoutUnit maxLogicalWidth = 0; 2160 LayoutUnit maxLogicalWidth;
2161 computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth); 2161 computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
2162 2162
2163 if (logicalWidthLength.type() == MinContent) 2163 if (logicalWidthLength.type() == MinContent)
2164 return minLogicalWidth + borderAndPadding; 2164 return minLogicalWidth + borderAndPadding;
2165 2165
2166 if (logicalWidthLength.type() == MaxContent) 2166 if (logicalWidthLength.type() == MaxContent)
2167 return maxLogicalWidth + borderAndPadding; 2167 return maxLogicalWidth + borderAndPadding;
2168 2168
2169 if (logicalWidthLength.type() == FitContent) { 2169 if (logicalWidthLength.type() == FitContent) {
2170 minLogicalWidth += borderAndPadding; 2170 minLogicalWidth += borderAndPadding;
(...skipping 12 matching lines...) Expand all
2183 return adjustBorderBoxLogicalWidthForBoxSizing(0); 2183 return adjustBorderBoxLogicalWidthForBoxSizing(0);
2184 2184
2185 if (!logicalWidth.isIntrinsicOrAuto()) { 2185 if (!logicalWidth.isIntrinsicOrAuto()) {
2186 // FIXME: If the containing block flow is perpendicular to our direction we need to use the available logical height instead. 2186 // FIXME: If the containing block flow is perpendicular to our direction we need to use the available logical height instead.
2187 return adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(logicalWid th, availableLogicalWidth)); 2187 return adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(logicalWid th, availableLogicalWidth));
2188 } 2188 }
2189 2189
2190 if (logicalWidth.isIntrinsic()) 2190 if (logicalWidth.isIntrinsic())
2191 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth()); 2191 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth());
2192 2192
2193 LayoutUnit marginStart = 0; 2193 LayoutUnit marginStart;
2194 LayoutUnit marginEnd = 0; 2194 LayoutUnit marginEnd;
2195 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd); 2195 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd);
2196 2196
2197 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlow(cb )->containsFloats()) 2197 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlow(cb )->containsFloats())
2198 logicalWidthResult = std::min(logicalWidthResult, shrinkLogicalWidthToAv oidFloats(marginStart, marginEnd, toLayoutBlockFlow(cb))); 2198 logicalWidthResult = std::min(logicalWidthResult, shrinkLogicalWidthToAv oidFloats(marginStart, marginEnd, toLayoutBlockFlow(cb)));
2199 2199
2200 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica lWidth)) 2200 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica lWidth))
2201 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical Width(), logicalWidthResult)); 2201 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical Width(), logicalWidthResult));
2202 return logicalWidthResult; 2202 return logicalWidthResult;
2203 } 2203 }
2204 2204
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 return document().inQuirksMode() && !containingBlock->isTableCell() && !cont ainingBlock->isOutOfFlowPositioned() && !containingBlock->isLayoutGrid() && cont ainingBlock->style()->logicalHeight().isAuto(); 2576 return document().inQuirksMode() && !containingBlock->isTableCell() && !cont ainingBlock->isOutOfFlowPositioned() && !containingBlock->isLayoutGrid() && cont ainingBlock->style()->logicalHeight().isAuto();
2577 } 2577 }
2578 2578
2579 LayoutUnit LayoutBox::computePercentageLogicalHeight(const Length& height) const 2579 LayoutUnit LayoutBox::computePercentageLogicalHeight(const Length& height) const
2580 { 2580 {
2581 LayoutUnit availableHeight = -1; 2581 LayoutUnit availableHeight = -1;
2582 2582
2583 bool skippedAutoHeightContainingBlock = false; 2583 bool skippedAutoHeightContainingBlock = false;
2584 LayoutBlock* cb = containingBlock(); 2584 LayoutBlock* cb = containingBlock();
2585 const LayoutBox* containingBlockChild = this; 2585 const LayoutBox* containingBlockChild = this;
2586 LayoutUnit rootMarginBorderPaddingHeight = 0; 2586 LayoutUnit rootMarginBorderPaddingHeight;
2587 while (!cb->isLayoutView() && skipContainingBlockForPercentHeightCalculation (cb)) { 2587 while (!cb->isLayoutView() && skipContainingBlockForPercentHeightCalculation (cb)) {
2588 if (cb->isBody() || cb->isDocumentElement()) 2588 if (cb->isBody() || cb->isDocumentElement())
2589 rootMarginBorderPaddingHeight += cb->marginBefore() + cb->marginAfte r() + cb->borderAndPaddingLogicalHeight(); 2589 rootMarginBorderPaddingHeight += cb->marginBefore() + cb->marginAfte r() + cb->borderAndPaddingLogicalHeight();
2590 skippedAutoHeightContainingBlock = true; 2590 skippedAutoHeightContainingBlock = true;
2591 containingBlockChild = cb; 2591 containingBlockChild = cb;
2592 cb = cb->containingBlock(); 2592 cb = cb->containingBlock();
2593 } 2593 }
2594 cb->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); 2594 cb->addPercentHeightDescendant(const_cast<LayoutBox*>(this));
2595 2595
2596 const ComputedStyle& cbstyle = cb->styleRef(); 2596 const ComputedStyle& cbstyle = cb->styleRef();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalWid th.isAuto()); 2692 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalWid th.isAuto());
2693 if (sizeType == MinSize && logicalWidth.isAuto()) 2693 if (sizeType == MinSize && logicalWidth.isAuto())
2694 return adjustContentBoxLogicalWidthForBoxSizing(0); 2694 return adjustContentBoxLogicalWidthForBoxSizing(0);
2695 2695
2696 switch (logicalWidth.type()) { 2696 switch (logicalWidth.type()) {
2697 case Fixed: 2697 case Fixed:
2698 return adjustContentBoxLogicalWidthForBoxSizing(logicalWidth.value()); 2698 return adjustContentBoxLogicalWidthForBoxSizing(logicalWidth.value());
2699 case MinContent: 2699 case MinContent:
2700 case MaxContent: { 2700 case MaxContent: {
2701 // MinContent/MaxContent don't need the availableLogicalWidth argument. 2701 // MinContent/MaxContent don't need the availableLogicalWidth argument.
2702 LayoutUnit availableLogicalWidth = 0; 2702 LayoutUnit availableLogicalWidth;
2703 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth()) - borderAndPaddingLogicalWidth(); 2703 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth()) - borderAndPaddingLogicalWidth();
2704 } 2704 }
2705 case FitContent: 2705 case FitContent:
2706 case FillAvailable: 2706 case FillAvailable:
2707 case Percent: 2707 case Percent:
2708 case Calculated: { 2708 case Calculated: {
2709 // FIXME: containingBlockLogicalWidthForContent() is wrong if the replac ed element's writing-mode is perpendicular to the 2709 // FIXME: containingBlockLogicalWidthForContent() is wrong if the replac ed element's writing-mode is perpendicular to the
2710 // containing block's writing-mode. 2710 // containing block's writing-mode.
2711 // https://bugs.webkit.org/show_bug.cgi?id=46496 2711 // https://bugs.webkit.org/show_bug.cgi?id=46496
2712 const LayoutUnit cw = isOutOfFlowPositioned() ? containingBlockLogicalWi dthForPositioned(toLayoutBoxModelObject(container())) : containingBlockLogicalWi dthForContent(); 2712 const LayoutUnit cw = isOutOfFlowPositioned() ? containingBlockLogicalWi dthForPositioned(toLayoutBoxModelObject(container())) : containingBlockLogicalWi dthForContent();
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
3477 3477
3478 // 'top' and 'bottom' cannot both be 'auto' because 'top would of been 3478 // 'top' and 'bottom' cannot both be 'auto' because 'top would of been
3479 // converted to the static position in computePositionedLogicalHeight() 3479 // converted to the static position in computePositionedLogicalHeight()
3480 ASSERT(!(logicalTop.isAuto() && logicalBottom.isAuto())); 3480 ASSERT(!(logicalTop.isAuto() && logicalBottom.isAuto()));
3481 3481
3482 LayoutUnit logicalHeightValue; 3482 LayoutUnit logicalHeightValue;
3483 LayoutUnit contentLogicalHeight = logicalHeight - bordersPlusPadding; 3483 LayoutUnit contentLogicalHeight = logicalHeight - bordersPlusPadding;
3484 3484
3485 const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidth ForPositioned(containerBlock, false); 3485 const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidth ForPositioned(containerBlock, false);
3486 3486
3487 LayoutUnit logicalTopValue = 0; 3487 LayoutUnit logicalTopValue;
3488 3488
3489 bool logicalHeightIsAuto = logicalHeightLength.isAuto(); 3489 bool logicalHeightIsAuto = logicalHeightLength.isAuto();
3490 bool logicalTopIsAuto = logicalTop.isAuto(); 3490 bool logicalTopIsAuto = logicalTop.isAuto();
3491 bool logicalBottomIsAuto = logicalBottom.isAuto(); 3491 bool logicalBottomIsAuto = logicalBottom.isAuto();
3492 3492
3493 LayoutUnit resolvedLogicalHeight; 3493 LayoutUnit resolvedLogicalHeight;
3494 // Height is never unsolved for tables. 3494 // Height is never unsolved for tables.
3495 if (isTable()) { 3495 if (isTable()) {
3496 resolvedLogicalHeight = contentLogicalHeight; 3496 resolvedLogicalHeight = contentLogicalHeight;
3497 logicalHeightIsAuto = false; 3497 logicalHeightIsAuto = false;
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
4640 4640
4641 void LayoutBox::clearPercentHeightDescendants() 4641 void LayoutBox::clearPercentHeightDescendants()
4642 { 4642 {
4643 for (LayoutObject* curr = slowFirstChild(); curr; curr = curr->nextInPreOrde r(this)) { 4643 for (LayoutObject* curr = slowFirstChild(); curr; curr = curr->nextInPreOrde r(this)) {
4644 if (curr->isBox()) 4644 if (curr->isBox())
4645 toLayoutBox(curr)->removeFromPercentHeightContainer(); 4645 toLayoutBox(curr)->removeFromPercentHeightContainer();
4646 } 4646 }
4647 } 4647 }
4648 4648
4649 } // namespace blink 4649 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698