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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBox.cpp

Issue 1603603002: Move specialized computePositionedLogicalWidth to LayoutReplaced. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/LayoutBox.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBox.cpp b/third_party/WebKit/Source/core/layout/LayoutBox.cpp
index 405cfa8fa480d7b8e0c57767319f7d3be211aec1..bbb153b8db23d56d7ca0f244b6b0d3a63b417c8e 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBox.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBox.cpp
@@ -2959,7 +2959,7 @@ LayoutUnit LayoutBox::containingBlockLogicalHeightForPositioned(const LayoutBoxM
return heightResult;
}
-static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRight, const LayoutBox* child, const LayoutBoxModelObject* containerBlock, LayoutUnit containerLogicalWidth)
+void LayoutBox::computeInlineStaticDistance(Length& logicalLeft, Length& logicalRight, const LayoutBox* child, const LayoutBoxModelObject* containerBlock, LayoutUnit containerLogicalWidth)
{
if (!logicalLeft.isAuto() || !logicalRight.isAuto())
return;
@@ -3011,11 +3011,6 @@ static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRigh
void LayoutBox::computePositionedLogicalWidth(LogicalExtentComputedValues& computedValues) const
{
- if (isAtomicInlineLevel()) {
mstensho (USE GERRIT) 2016/01/21 18:50:46 Yeah, this became absurd, with the isReplaced -> i
- computePositionedLogicalWidthReplaced(computedValues);
- return;
- }
-
// QUESTIONS
// FIXME 1: Should we still deal with these the cases of 'left' or 'right' having
// the type 'static' in determining whether to calculate the static distance?
@@ -3125,7 +3120,7 @@ void LayoutBox::computePositionedLogicalWidth(LogicalExtentComputedValues& compu
computedValues.m_extent += bordersPlusPadding;
}
-static void computeLogicalLeftPositionedOffset(LayoutUnit& logicalLeftPos, const LayoutBox* child, LayoutUnit logicalWidthValue, const LayoutBoxModelObject* containerBlock, LayoutUnit containerLogicalWidth)
+void LayoutBox::computeLogicalLeftPositionedOffset(LayoutUnit& logicalLeftPos, const LayoutBox* child, LayoutUnit logicalWidthValue, const LayoutBoxModelObject* containerBlock, LayoutUnit containerLogicalWidth)
{
// Deal with differing writing modes here. Our offset needs to be in the containing block's coordinate space. If the containing block is flipped
// along this axis, then we need to flip the coordinate. This can only happen if the containing block is both a flipped mode and perpendicular to us.
@@ -3322,7 +3317,7 @@ void LayoutBox::computePositionedLogicalWidthUsing(SizeType widthSizeType, Lengt
computeLogicalLeftPositionedOffset(computedValues.m_position, this, computedValues.m_extent, containerBlock, containerLogicalWidth);
}
-static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom, const LayoutBox* child, const LayoutBoxModelObject* containerBlock)
+void LayoutBox::computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom, const LayoutBox* child, const LayoutBoxModelObject* containerBlock)
{
if (!logicalTop.isAuto() || !logicalBottom.isAuto())
return;
@@ -3338,11 +3333,6 @@ static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom
void LayoutBox::computePositionedLogicalHeight(LogicalExtentComputedValues& computedValues) const
{
- if (isAtomicInlineLevel()) {
- computePositionedLogicalHeightReplaced(computedValues);
- return;
- }
-
// The following is based off of the W3C Working Draft from April 11, 2006 of
// CSS 2.1: Section 10.6.4 "Absolutely positioned, non-replaced elements"
// <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-non-replaced-height>
@@ -3431,7 +3421,7 @@ void LayoutBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp
computedValues.m_extent += bordersPlusPadding;
}
-static void computeLogicalTopPositionedOffset(LayoutUnit& logicalTopPos, const LayoutBox* child, LayoutUnit logicalHeightValue, const LayoutBoxModelObject* containerBlock, LayoutUnit containerLogicalHeight)
+void LayoutBox::computeLogicalTopPositionedOffset(LayoutUnit& logicalTopPos, const LayoutBox* child, LayoutUnit logicalHeightValue, const LayoutBoxModelObject* containerBlock, LayoutUnit containerLogicalHeight)
{
// Deal with differing writing modes here. Our offset needs to be in the containing block's coordinate space. If the containing block is flipped
// along this axis, then we need to flip the coordinate. This can only happen if the containing block is both a flipped mode and perpendicular to us.
@@ -3587,304 +3577,6 @@ void LayoutBox::computePositionedLogicalHeightUsing(SizeType heightSizeType, Len
computeLogicalTopPositionedOffset(computedValues.m_position, this, logicalHeightValue, containerBlock, containerLogicalHeight);
}
-void LayoutBox::computePositionedLogicalWidthReplaced(LogicalExtentComputedValues& computedValues) const
-{
- // The following is based off of the W3C Working Draft from April 11, 2006 of
- // CSS 2.1: Section 10.3.8 "Absolutely positioned, replaced elements"
- // <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-replaced-width>
- // (block-style-comments in this function correspond to text from the spec and
- // the numbers correspond to numbers in spec)
-
- // We don't use containingBlock(), since we may be positioned by an enclosing
- // relative positioned inline.
- const LayoutBoxModelObject* containerBlock = toLayoutBoxModelObject(container());
-
- const LayoutUnit containerLogicalWidth = containingBlockLogicalWidthForPositioned(containerBlock);
- const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidthForPositioned(containerBlock, false);
-
- // To match WinIE, in quirks mode use the parent's 'direction' property
- // instead of the the container block's.
- TextDirection containerDirection = containerBlock->style()->direction();
-
- // Variables to solve.
- bool isHorizontal = isHorizontalWritingMode();
- Length logicalLeft = style()->logicalLeft();
- Length logicalRight = style()->logicalRight();
- Length marginLogicalLeft = isHorizontal ? style()->marginLeft() : style()->marginTop();
- Length marginLogicalRight = isHorizontal ? style()->marginRight() : style()->marginBottom();
- LayoutUnit& marginLogicalLeftAlias = style()->isLeftToRightDirection() ? computedValues.m_margins.m_start : computedValues.m_margins.m_end;
- LayoutUnit& marginLogicalRightAlias = style()->isLeftToRightDirection() ? computedValues.m_margins.m_end : computedValues.m_margins.m_start;
-
- /*-----------------------------------------------------------------------*\
- * 1. The used value of 'width' is determined as for inline replaced
- * elements.
- \*-----------------------------------------------------------------------*/
- // NOTE: This value of width is final in that the min/max width calculations
- // are dealt with in computeReplacedWidth(). This means that the steps to produce
- // correct max/min in the non-replaced version, are not necessary.
- computedValues.m_extent = computeReplacedLogicalWidth() + borderAndPaddingLogicalWidth();
-
- const LayoutUnit availableSpace = containerLogicalWidth - computedValues.m_extent;
-
- /*-----------------------------------------------------------------------*\
- * 2. If both 'left' and 'right' have the value 'auto', then if 'direction'
- * of the containing block is 'ltr', set 'left' to the static position;
- * else if 'direction' is 'rtl', set 'right' to the static position.
- \*-----------------------------------------------------------------------*/
- // see FIXME 1
- computeInlineStaticDistance(logicalLeft, logicalRight, this, containerBlock, containerLogicalWidth);
-
- /*-----------------------------------------------------------------------*\
- * 3. If 'left' or 'right' are 'auto', replace any 'auto' on 'margin-left'
- * or 'margin-right' with '0'.
- \*-----------------------------------------------------------------------*/
- if (logicalLeft.isAuto() || logicalRight.isAuto()) {
- if (marginLogicalLeft.isAuto())
- marginLogicalLeft.setValue(Fixed, 0);
- if (marginLogicalRight.isAuto())
- marginLogicalRight.setValue(Fixed, 0);
- }
-
- /*-----------------------------------------------------------------------*\
- * 4. If at this point both 'margin-left' and 'margin-right' are still
- * 'auto', solve the equation under the extra constraint that the two
- * margins must get equal values, unless this would make them negative,
- * in which case when the direction of the containing block is 'ltr'
- * ('rtl'), set 'margin-left' ('margin-right') to zero and solve for
- * 'margin-right' ('margin-left').
- \*-----------------------------------------------------------------------*/
- LayoutUnit logicalLeftValue = 0;
- LayoutUnit logicalRightValue = 0;
-
- if (marginLogicalLeft.isAuto() && marginLogicalRight.isAuto()) {
- // 'left' and 'right' cannot be 'auto' due to step 3
- ASSERT(!(logicalLeft.isAuto() && logicalRight.isAuto()));
-
- logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth);
- logicalRightValue = valueForLength(logicalRight, containerLogicalWidth);
-
- LayoutUnit difference = availableSpace - (logicalLeftValue + logicalRightValue);
- if (difference > 0) {
- marginLogicalLeftAlias = difference / 2; // split the difference
- marginLogicalRightAlias = difference - marginLogicalLeftAlias; // account for odd valued differences
- } else {
- // Use the containing block's direction rather than the parent block's
- // per CSS 2.1 reference test abspos-replaced-width-margin-000.
- if (containerDirection == LTR) {
- marginLogicalLeftAlias = 0;
- marginLogicalRightAlias = difference; // will be negative
- } else {
- marginLogicalLeftAlias = difference; // will be negative
- marginLogicalRightAlias = 0;
- }
- }
-
- /*-----------------------------------------------------------------------*\
- * 5. If at this point there is an 'auto' left, solve the equation for
- * that value.
- \*-----------------------------------------------------------------------*/
- } else if (logicalLeft.isAuto()) {
- marginLogicalLeftAlias = valueForLength(marginLogicalLeft, containerRelativeLogicalWidth);
- marginLogicalRightAlias = valueForLength(marginLogicalRight, containerRelativeLogicalWidth);
- logicalRightValue = valueForLength(logicalRight, containerLogicalWidth);
-
- // Solve for 'left'
- logicalLeftValue = availableSpace - (logicalRightValue + marginLogicalLeftAlias + marginLogicalRightAlias);
- } else if (logicalRight.isAuto()) {
- marginLogicalLeftAlias = valueForLength(marginLogicalLeft, containerRelativeLogicalWidth);
- marginLogicalRightAlias = valueForLength(marginLogicalRight, containerRelativeLogicalWidth);
- logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth);
-
- // Solve for 'right'
- logicalRightValue = availableSpace - (logicalLeftValue + marginLogicalLeftAlias + marginLogicalRightAlias);
- } else if (marginLogicalLeft.isAuto()) {
- marginLogicalRightAlias = valueForLength(marginLogicalRight, containerRelativeLogicalWidth);
- logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth);
- logicalRightValue = valueForLength(logicalRight, containerLogicalWidth);
-
- // Solve for 'margin-left'
- marginLogicalLeftAlias = availableSpace - (logicalLeftValue + logicalRightValue + marginLogicalRightAlias);
- } else if (marginLogicalRight.isAuto()) {
- marginLogicalLeftAlias = valueForLength(marginLogicalLeft, containerRelativeLogicalWidth);
- logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth);
- logicalRightValue = valueForLength(logicalRight, containerLogicalWidth);
-
- // Solve for 'margin-right'
- marginLogicalRightAlias = availableSpace - (logicalLeftValue + logicalRightValue + marginLogicalLeftAlias);
- } else {
- // Nothing is 'auto', just calculate the values.
- marginLogicalLeftAlias = valueForLength(marginLogicalLeft, containerRelativeLogicalWidth);
- marginLogicalRightAlias = valueForLength(marginLogicalRight, containerRelativeLogicalWidth);
- logicalRightValue = valueForLength(logicalRight, containerLogicalWidth);
- logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth);
- // If the containing block is right-to-left, then push the left position as far to the right as possible
- if (containerDirection == RTL) {
- int totalLogicalWidth = computedValues.m_extent + logicalLeftValue + logicalRightValue + marginLogicalLeftAlias + marginLogicalRightAlias;
- logicalLeftValue = containerLogicalWidth - (totalLogicalWidth - logicalLeftValue);
- }
- }
-
- /*-----------------------------------------------------------------------*\
- * 6. If at this point the values are over-constrained, ignore the value
- * for either 'left' (in case the 'direction' property of the
- * containing block is 'rtl') or 'right' (in case 'direction' is
- * 'ltr') and solve for that value.
- \*-----------------------------------------------------------------------*/
- // NOTE: Constraints imposed by the width of the containing block and its content have already been accounted for above.
-
- // FIXME: Deal with differing writing modes here. Our offset needs to be in the containing block's coordinate space, so that
- // can make the result here rather complicated to compute.
-
- // Use computed values to calculate the horizontal position.
-
- // FIXME: This hack is needed to calculate the logical left position for a 'rtl' relatively
- // positioned, inline containing block because right now, it is using the logical left position
- // of the first line box when really it should use the last line box. When
- // this is fixed elsewhere, this block should be removed.
- if (containerBlock->isLayoutInline() && !containerBlock->style()->isLeftToRightDirection()) {
- const LayoutInline* flow = toLayoutInline(containerBlock);
- InlineFlowBox* firstLine = flow->firstLineBox();
- InlineFlowBox* lastLine = flow->lastLineBox();
- if (firstLine && lastLine && firstLine != lastLine) {
- computedValues.m_position = logicalLeftValue + marginLogicalLeftAlias + lastLine->borderLogicalLeft() + (lastLine->logicalLeft() - firstLine->logicalLeft());
- return;
- }
- }
-
- LayoutUnit logicalLeftPos = logicalLeftValue + marginLogicalLeftAlias;
- computeLogicalLeftPositionedOffset(logicalLeftPos, this, computedValues.m_extent, containerBlock, containerLogicalWidth);
- computedValues.m_position = logicalLeftPos;
-}
-
-void LayoutBox::computePositionedLogicalHeightReplaced(LogicalExtentComputedValues& computedValues) const
-{
- // The following is based off of the W3C Working Draft from April 11, 2006 of
- // CSS 2.1: Section 10.6.5 "Absolutely positioned, replaced elements"
- // <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-replaced-height>
- // (block-style-comments in this function correspond to text from the spec and
- // the numbers correspond to numbers in spec)
-
- // We don't use containingBlock(), since we may be positioned by an enclosing relpositioned inline.
- const LayoutBoxModelObject* containerBlock = toLayoutBoxModelObject(container());
-
- const LayoutUnit containerLogicalHeight = containingBlockLogicalHeightForPositioned(containerBlock);
- const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidthForPositioned(containerBlock, false);
-
- // Variables to solve.
- Length marginBefore = style()->marginBefore();
- Length marginAfter = style()->marginAfter();
- LayoutUnit& marginBeforeAlias = computedValues.m_margins.m_before;
- LayoutUnit& marginAfterAlias = computedValues.m_margins.m_after;
-
- Length logicalTop = style()->logicalTop();
- Length logicalBottom = style()->logicalBottom();
-
- /*-----------------------------------------------------------------------*\
- * 1. The used value of 'height' is determined as for inline replaced
- * elements.
- \*-----------------------------------------------------------------------*/
- // NOTE: This value of height is final in that the min/max height calculations
- // are dealt with in computeReplacedHeight(). This means that the steps to produce
- // correct max/min in the non-replaced version, are not necessary.
- computedValues.m_extent = computeReplacedLogicalHeight() + borderAndPaddingLogicalHeight();
- const LayoutUnit availableSpace = containerLogicalHeight - computedValues.m_extent;
-
- /*-----------------------------------------------------------------------*\
- * 2. If both 'top' and 'bottom' have the value 'auto', replace 'top'
- * with the element's static position.
- \*-----------------------------------------------------------------------*/
- // see FIXME 1
- computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock);
-
- /*-----------------------------------------------------------------------*\
- * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or
- * 'margin-bottom' with '0'.
- \*-----------------------------------------------------------------------*/
- // FIXME: The spec. says that this step should only be taken when bottom is
- // auto, but if only top is auto, this makes step 4 impossible.
- if (logicalTop.isAuto() || logicalBottom.isAuto()) {
- if (marginBefore.isAuto())
- marginBefore.setValue(Fixed, 0);
- if (marginAfter.isAuto())
- marginAfter.setValue(Fixed, 0);
- }
-
- /*-----------------------------------------------------------------------*\
- * 4. If at this point both 'margin-top' and 'margin-bottom' are still
- * 'auto', solve the equation under the extra constraint that the two
- * margins must get equal values.
- \*-----------------------------------------------------------------------*/
- LayoutUnit logicalTopValue = 0;
- LayoutUnit logicalBottomValue = 0;
-
- if (marginBefore.isAuto() && marginAfter.isAuto()) {
- // 'top' and 'bottom' cannot be 'auto' due to step 2 and 3 combined.
- ASSERT(!(logicalTop.isAuto() || logicalBottom.isAuto()));
-
- logicalTopValue = valueForLength(logicalTop, containerLogicalHeight);
- logicalBottomValue = valueForLength(logicalBottom, containerLogicalHeight);
-
- LayoutUnit difference = availableSpace - (logicalTopValue + logicalBottomValue);
- // NOTE: This may result in negative values.
- marginBeforeAlias = difference / 2; // split the difference
- marginAfterAlias = difference - marginBeforeAlias; // account for odd valued differences
-
- /*-----------------------------------------------------------------------*\
- * 5. If at this point there is only one 'auto' left, solve the equation
- * for that value.
- \*-----------------------------------------------------------------------*/
- } else if (logicalTop.isAuto()) {
- marginBeforeAlias = valueForLength(marginBefore, containerRelativeLogicalWidth);
- marginAfterAlias = valueForLength(marginAfter, containerRelativeLogicalWidth);
- logicalBottomValue = valueForLength(logicalBottom, containerLogicalHeight);
-
- // Solve for 'top'
- logicalTopValue = availableSpace - (logicalBottomValue + marginBeforeAlias + marginAfterAlias);
- } else if (logicalBottom.isAuto()) {
- marginBeforeAlias = valueForLength(marginBefore, containerRelativeLogicalWidth);
- marginAfterAlias = valueForLength(marginAfter, containerRelativeLogicalWidth);
- logicalTopValue = valueForLength(logicalTop, containerLogicalHeight);
-
- // Solve for 'bottom'
- // NOTE: It is not necessary to solve for 'bottom' because we don't ever
- // use the value.
- } else if (marginBefore.isAuto()) {
- marginAfterAlias = valueForLength(marginAfter, containerRelativeLogicalWidth);
- logicalTopValue = valueForLength(logicalTop, containerLogicalHeight);
- logicalBottomValue = valueForLength(logicalBottom, containerLogicalHeight);
-
- // Solve for 'margin-top'
- marginBeforeAlias = availableSpace - (logicalTopValue + logicalBottomValue + marginAfterAlias);
- } else if (marginAfter.isAuto()) {
- marginBeforeAlias = valueForLength(marginBefore, containerRelativeLogicalWidth);
- logicalTopValue = valueForLength(logicalTop, containerLogicalHeight);
- logicalBottomValue = valueForLength(logicalBottom, containerLogicalHeight);
-
- // Solve for 'margin-bottom'
- marginAfterAlias = availableSpace - (logicalTopValue + logicalBottomValue + marginBeforeAlias);
- } else {
- // Nothing is 'auto', just calculate the values.
- marginBeforeAlias = valueForLength(marginBefore, containerRelativeLogicalWidth);
- marginAfterAlias = valueForLength(marginAfter, containerRelativeLogicalWidth);
- logicalTopValue = valueForLength(logicalTop, containerLogicalHeight);
- // NOTE: It is not necessary to solve for 'bottom' because we don't ever
- // use the value.
- }
-
- /*-----------------------------------------------------------------------*\
- * 6. If at this point the values are over-constrained, ignore the value
- * for 'bottom' and solve for that value.
- \*-----------------------------------------------------------------------*/
- // NOTE: It is not necessary to do this step because we don't end up using
- // the value of 'bottom' regardless of whether the values are over-constrained
- // or not.
-
- // Use computed values to calculate the vertical position.
- LayoutUnit logicalTopPos = logicalTopValue + marginBeforeAlias;
- computeLogicalTopPositionedOffset(logicalTopPos, this, computedValues.m_extent, containerBlock, containerLogicalHeight);
- computedValues.m_position = logicalTopPos;
-}
-
LayoutRect LayoutBox::localCaretRect(InlineBox* box, int caretOffset, LayoutUnit* extraWidthToEndOfLine)
{
// VisiblePositions at offsets inside containers either a) refer to the positions before/after
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBox.h ('k') | third_party/WebKit/Source/core/layout/LayoutReplaced.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698