| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2013 Adobe Systems Incorporated. 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
| 9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
| 10 * disclaimer. | 10 * disclaimer. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "core/layout/shapes/ShapeOutsideInfo.h" | 33 #include "core/layout/shapes/ShapeOutsideInfo.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 LineWidth::LineWidth(LineLayoutBlockFlow block, bool isFirstLine, IndentTextOrNo
t indentText) | 37 LineWidth::LineWidth(LineLayoutBlockFlow block, bool isFirstLine, IndentTextOrNo
t indentText) |
| 38 : m_block(block) | 38 : m_block(block) |
| 39 , m_uncommittedWidth(0) | 39 , m_uncommittedWidth(0) |
| 40 , m_committedWidth(0) | 40 , m_committedWidth(0) |
| 41 , m_overhangWidth(0) | 41 , m_overhangWidth(0) |
| 42 , m_trailingWhitespaceWidth(0) | 42 , m_trailingWhitespaceWidth(0) |
| 43 , m_left(0) | |
| 44 , m_right(0) | |
| 45 , m_availableWidth(0) | |
| 46 , m_isFirstLine(isFirstLine) | 43 , m_isFirstLine(isFirstLine) |
| 47 , m_indentText(indentText) | 44 , m_indentText(indentText) |
| 48 { | 45 { |
| 49 updateAvailableWidth(); | 46 updateAvailableWidth(); |
| 50 } | 47 } |
| 51 | 48 |
| 52 void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight) | 49 void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight) |
| 53 { | 50 { |
| 54 LayoutUnit height = m_block.logicalHeight(); | 51 LayoutUnit height = m_block.logicalHeight(); |
| 55 LayoutUnit logicalHeight = m_block.minLineHeightForReplacedObject(m_isFirstL
ine, replacedHeight); | 52 LayoutUnit logicalHeight = m_block.minLineHeightForReplacedObject(m_isFirstL
ine, replacedHeight); |
| 56 m_left = m_block.logicalLeftOffsetForLine(height, indentText(), logicalHeigh
t).toFloat(); | 53 m_left = m_block.logicalLeftOffsetForLine(height, indentText(), logicalHeigh
t); |
| 57 m_right = m_block.logicalRightOffsetForLine(height, indentText(), logicalHei
ght).toFloat(); | 54 m_right = m_block.logicalRightOffsetForLine(height, indentText(), logicalHei
ght); |
| 58 | 55 |
| 59 computeAvailableWidthFromLeftAndRight(); | 56 computeAvailableWidthFromLeftAndRight(); |
| 60 } | 57 } |
| 61 | 58 |
| 62 void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(const FloatingObject& ne
wFloat) | 59 void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(const FloatingObject& ne
wFloat) |
| 63 { | 60 { |
| 64 LayoutUnit height = m_block.logicalHeight(); | 61 LayoutUnit height = m_block.logicalHeight(); |
| 65 if (height < m_block.logicalTopForFloat(newFloat) || height >= m_block.logic
alBottomForFloat(newFloat)) | 62 if (height < m_block.logicalTopForFloat(newFloat) || height >= m_block.logic
alBottomForFloat(newFloat)) |
| 66 return; | 63 return; |
| 67 | 64 |
| 68 ShapeOutsideDeltas shapeDeltas; | 65 ShapeOutsideDeltas shapeDeltas; |
| 69 if (ShapeOutsideInfo* shapeOutsideInfo = newFloat.layoutObject()->shapeOutsi
deInfo()) { | 66 if (ShapeOutsideInfo* shapeOutsideInfo = newFloat.layoutObject()->shapeOutsi
deInfo()) { |
| 70 LayoutUnit lineHeight = m_block.lineHeight(m_isFirstLine, m_block.isHori
zontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes
); | 67 LayoutUnit lineHeight = m_block.lineHeight(m_isFirstLine, m_block.isHori
zontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes
); |
| 71 shapeDeltas = shapeOutsideInfo->computeDeltasForContainingBlockLine(m_bl
ock, newFloat, m_block.logicalHeight(), lineHeight); | 68 shapeDeltas = shapeOutsideInfo->computeDeltasForContainingBlockLine(m_bl
ock, newFloat, m_block.logicalHeight(), lineHeight); |
| 72 } | 69 } |
| 73 | 70 |
| 74 if (newFloat.getType() == FloatingObject::FloatLeft) { | 71 if (newFloat.getType() == FloatingObject::FloatLeft) { |
| 75 float newLeft = m_block.logicalRightForFloat(newFloat).toFloat(); | 72 LayoutUnit newLeft = m_block.logicalRightForFloat(newFloat); |
| 76 if (shapeDeltas.isValid()) { | 73 if (shapeDeltas.isValid()) { |
| 77 if (shapeDeltas.lineOverlapsShape()) | 74 if (shapeDeltas.lineOverlapsShape()) |
| 78 newLeft += shapeDeltas.rightMarginBoxDelta(); | 75 newLeft += shapeDeltas.rightMarginBoxDelta(); |
| 79 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. | 76 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. |
| 80 newLeft = m_left; | 77 newLeft = m_left; |
| 81 } | 78 } |
| 82 if (indentText() == IndentText && m_block.style()->isLeftToRightDirectio
n()) | 79 if (indentText() == IndentText && m_block.style()->isLeftToRightDirectio
n()) |
| 83 newLeft += floorToInt(m_block.textIndentOffset()); | 80 newLeft += floorToInt(m_block.textIndentOffset()); |
| 84 m_left = std::max<float>(m_left, newLeft); | 81 m_left = std::max(m_left, newLeft); |
| 85 } else { | 82 } else { |
| 86 float newRight = m_block.logicalLeftForFloat(newFloat).toFloat(); | 83 LayoutUnit newRight = m_block.logicalLeftForFloat(newFloat); |
| 87 if (shapeDeltas.isValid()) { | 84 if (shapeDeltas.isValid()) { |
| 88 if (shapeDeltas.lineOverlapsShape()) | 85 if (shapeDeltas.lineOverlapsShape()) |
| 89 newRight += shapeDeltas.leftMarginBoxDelta(); | 86 newRight += shapeDeltas.leftMarginBoxDelta(); |
| 90 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. | 87 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. |
| 91 newRight = m_right; | 88 newRight = m_right; |
| 92 } | 89 } |
| 93 if (indentText() == IndentText && !m_block.style()->isLeftToRightDirecti
on()) | 90 if (indentText() == IndentText && !m_block.style()->isLeftToRightDirecti
on()) |
| 94 newRight -= floorToInt(m_block.textIndentOffset()); | 91 newRight -= floorToInt(m_block.textIndentOffset()); |
| 95 m_right = std::min<float>(m_right, newRight); | 92 m_right = std::min(m_right, newRight); |
| 96 } | 93 } |
| 97 | 94 |
| 98 computeAvailableWidthFromLeftAndRight(); | 95 computeAvailableWidthFromLeftAndRight(); |
| 99 } | 96 } |
| 100 | 97 |
| 101 void LineWidth::commit() | 98 void LineWidth::commit() |
| 102 { | 99 { |
| 103 m_committedWidth += m_uncommittedWidth; | 100 m_committedWidth += m_uncommittedWidth; |
| 104 m_uncommittedWidth = 0; | 101 m_uncommittedWidth = 0; |
| 105 } | 102 } |
| 106 | 103 |
| 107 void LineWidth::applyOverhang(LineLayoutRubyRun rubyRun, LineLayoutItem startLay
outItem, LineLayoutItem endLayoutItem) | 104 void LineWidth::applyOverhang(LineLayoutRubyRun rubyRun, LineLayoutItem startLay
outItem, LineLayoutItem endLayoutItem) |
| 108 { | 105 { |
| 109 int startOverhang; | 106 int startOverhang; |
| 110 int endOverhang; | 107 int endOverhang; |
| 111 rubyRun.getOverhang(m_isFirstLine, startLayoutItem, endLayoutItem, startOver
hang, endOverhang); | 108 rubyRun.getOverhang(m_isFirstLine, startLayoutItem, endLayoutItem, startOver
hang, endOverhang); |
| 112 | 109 |
| 113 startOverhang = std::min<int>(startOverhang, m_committedWidth); | 110 startOverhang = std::min<int>(startOverhang, m_committedWidth); |
| 114 m_availableWidth += startOverhang; | 111 m_availableWidth += startOverhang; |
| 115 | 112 |
| 116 endOverhang = std::max(std::min<int>(endOverhang, m_availableWidth - current
Width()), 0); | 113 endOverhang = std::max(std::min<int>(endOverhang, m_availableWidth - current
Width()), 0); |
| 117 m_availableWidth += endOverhang; | 114 m_availableWidth += endOverhang; |
| 118 m_overhangWidth += startOverhang + endOverhang; | 115 m_overhangWidth += startOverhang + endOverhang; |
| 119 } | 116 } |
| 120 | 117 |
| 121 inline static float availableWidthAtOffset(LineLayoutBlockFlow block, const Layo
utUnit& offset, IndentTextOrNot indentText, float& newLineLeft, | 118 inline static LayoutUnit availableWidthAtOffset(LineLayoutBlockFlow block, |
| 122 float& newLineRight, const LayoutUnit& lineHeight = LayoutUnit()) | 119 const LayoutUnit& offset, IndentTextOrNot indentText, LayoutUnit& newLineLef
t, |
| 120 LayoutUnit& newLineRight, const LayoutUnit& lineHeight = LayoutUnit()) |
| 123 { | 121 { |
| 124 newLineLeft = block.logicalLeftOffsetForLine(offset, indentText, lineHeight)
.toFloat(); | 122 newLineLeft = block.logicalLeftOffsetForLine(offset, indentText, lineHeight)
; |
| 125 newLineRight = block.logicalRightOffsetForLine(offset, indentText, lineHeigh
t).toFloat(); | 123 newLineRight = block.logicalRightOffsetForLine(offset, indentText, lineHeigh
t); |
| 126 return std::max(0.0f, newLineRight - newLineLeft); | 124 return (newLineRight - newLineLeft).clampNegativeToZero(); |
| 127 } | 125 } |
| 128 | 126 |
| 129 void LineWidth::updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWid
th, const float& newLineLeft, const float& newLineRight) | 127 void LineWidth::updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWid
th, const LayoutUnit& newLineLeft, const LayoutUnit& newLineRight) |
| 130 { | 128 { |
| 131 if (newLineWidth <= m_availableWidth) | 129 if (newLineWidth <= m_availableWidth) |
| 132 return; | 130 return; |
| 133 | 131 |
| 134 m_block.setLogicalHeight(newLineTop); | 132 m_block.setLogicalHeight(newLineTop); |
| 135 m_availableWidth = newLineWidth + m_overhangWidth; | 133 m_availableWidth = newLineWidth + LayoutUnit::fromFloatCeil(m_overhangWidth)
; |
| 136 m_left = newLineLeft; | 134 m_left = newLineLeft; |
| 137 m_right = newLineRight; | 135 m_right = newLineRight; |
| 138 } | 136 } |
| 139 | 137 |
| 140 void LineWidth::wrapNextToShapeOutside(bool isFirstLine) | 138 void LineWidth::wrapNextToShapeOutside(bool isFirstLine) |
| 141 { | 139 { |
| 142 LayoutUnit lineHeight = m_block.lineHeight(isFirstLine, m_block.isHorizontal
WritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); | 140 LayoutUnit lineHeight = m_block.lineHeight(isFirstLine, m_block.isHorizontal
WritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
| 143 LayoutUnit lineLogicalTop = m_block.logicalHeight(); | 141 LayoutUnit lineLogicalTop = m_block.logicalHeight(); |
| 144 LayoutUnit newLineTop = lineLogicalTop; | 142 LayoutUnit newLineTop = lineLogicalTop; |
| 145 LayoutUnit floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lineLogi
calTop); | 143 LayoutUnit floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lineLogi
calTop); |
| 146 | 144 |
| 147 float newLineWidth; | 145 LayoutUnit newLineWidth; |
| 148 float newLineLeft = m_left; | 146 LayoutUnit newLineLeft = m_left; |
| 149 float newLineRight = m_right; | 147 LayoutUnit newLineRight = m_right; |
| 150 while (true) { | 148 while (true) { |
| 151 newLineWidth = availableWidthAtOffset(m_block, newLineTop, indentText(),
newLineLeft, newLineRight, lineHeight); | 149 newLineWidth = availableWidthAtOffset(m_block, newLineTop, indentText(),
newLineLeft, newLineRight, lineHeight); |
| 152 if (newLineWidth >= m_uncommittedWidth) | 150 if (newLineWidth >= m_uncommittedWidth) |
| 153 break; | 151 break; |
| 154 | 152 |
| 155 if (newLineTop >= floatLogicalBottom) | 153 if (newLineTop >= floatLogicalBottom) |
| 156 break; | 154 break; |
| 157 | 155 |
| 158 newLineTop++; | 156 newLineTop++; |
| 159 } | 157 } |
| 160 updateLineDimension(newLineTop, LayoutUnit(newLineWidth), newLineLeft, newLi
neRight); | 158 updateLineDimension(newLineTop, LayoutUnit(newLineWidth), newLineLeft, newLi
neRight); |
| 161 } | 159 } |
| 162 | 160 |
| 163 void LineWidth::fitBelowFloats(bool isFirstLine) | 161 void LineWidth::fitBelowFloats(bool isFirstLine) |
| 164 { | 162 { |
| 165 ASSERT(!m_committedWidth); | 163 ASSERT(!m_committedWidth); |
| 166 ASSERT(!fitsOnLine()); | 164 ASSERT(!fitsOnLine()); |
| 167 m_block.positionNewFloats(this); | 165 m_block.positionNewFloats(this); |
| 168 | 166 |
| 169 LayoutUnit floatLogicalBottom; | 167 LayoutUnit floatLogicalBottom; |
| 170 LayoutUnit lastFloatLogicalBottom = m_block.logicalHeight(); | 168 LayoutUnit lastFloatLogicalBottom = m_block.logicalHeight(); |
| 171 float newLineWidth = m_availableWidth; | 169 LayoutUnit newLineWidth = m_availableWidth; |
| 172 float newLineLeft = m_left; | 170 LayoutUnit newLineLeft = m_left; |
| 173 float newLineRight = m_right; | 171 LayoutUnit newLineRight = m_right; |
| 174 | 172 |
| 175 FloatingObject* lastFloatFromPreviousLine = m_block.lastFloatFromPreviousLin
e(); | 173 FloatingObject* lastFloatFromPreviousLine = m_block.lastFloatFromPreviousLin
e(); |
| 176 if (lastFloatFromPreviousLine && lastFloatFromPreviousLine->layoutObject
()->shapeOutsideInfo()) | 174 if (lastFloatFromPreviousLine && lastFloatFromPreviousLine->layoutObject
()->shapeOutsideInfo()) |
| 177 return wrapNextToShapeOutside(isFirstLine); | 175 return wrapNextToShapeOutside(isFirstLine); |
| 178 | 176 |
| 179 while (true) { | 177 while (true) { |
| 180 floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lastFloatLogica
lBottom); | 178 floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lastFloatLogica
lBottom); |
| 181 if (floatLogicalBottom <= lastFloatLogicalBottom) | 179 if (floatLogicalBottom <= lastFloatLogicalBottom) |
| 182 break; | 180 break; |
| 183 | 181 |
| 184 newLineWidth = availableWidthAtOffset(m_block, floatLogicalBottom, inden
tText(), newLineLeft, newLineRight); | 182 newLineWidth = availableWidthAtOffset(m_block, floatLogicalBottom, inden
tText(), newLineLeft, newLineRight); |
| 185 lastFloatLogicalBottom = floatLogicalBottom; | 183 lastFloatLogicalBottom = floatLogicalBottom; |
| 186 | 184 |
| 187 if (newLineWidth >= m_uncommittedWidth) | 185 if (newLineWidth >= m_uncommittedWidth) |
| 188 break; | 186 break; |
| 189 } | 187 } |
| 190 updateLineDimension(lastFloatLogicalBottom, LayoutUnit(newLineWidth), newLin
eLeft, newLineRight); | 188 updateLineDimension(lastFloatLogicalBottom, LayoutUnit(newLineWidth), newLin
eLeft, newLineRight); |
| 191 } | 189 } |
| 192 | 190 |
| 193 void LineWidth::computeAvailableWidthFromLeftAndRight() | 191 void LineWidth::computeAvailableWidthFromLeftAndRight() |
| 194 { | 192 { |
| 195 m_availableWidth = max(0.0f, m_right - m_left) + m_overhangWidth; | 193 m_availableWidth = (m_right - m_left).clampNegativeToZero() + LayoutUnit::fr
omFloatCeil(m_overhangWidth); |
| 196 } | 194 } |
| 197 | 195 |
| 198 } // namespace blink | 196 } // namespace blink |
| OLD | NEW |