Diff
Modified: trunk/Source/WebCore/ChangeLog (110982 => 110983)
--- trunk/Source/WebCore/ChangeLog 2012-03-16 10:39:51 UTC (rev 110982)
+++ trunk/Source/WebCore/ChangeLog 2012-03-16 10:52:56 UTC (rev 110983)
@@ -1,3 +1,67 @@
+2012-03-16 Levi Weintraub <[email protected]>
+
+ Update usage of LayoutUnits in RenderBlock*
+ https://bugs.webkit.org/show_bug.cgi?id=80437
+
+ Reviewed by Julien Chaffraix.
+
+ Updating LayoutUnit usage in RenderBlock and RenderBlockLineLayout. This better readies trunk for
+ the transition to subpixel layout.
+
+ See https://trac.webkit.org/wiki/LayoutUnit for more details.
+
+ No new tests. No changed behavior.
+
+ * rendering/InlineTextBox.cpp:
+ (WebCore::InlineTextBox::paint): Adding the paint offset rounding previously in RenderBlock::paint.
+ * rendering/LayoutTypes.h:
+ (WebCore::floorToInt): Will floor a LayoutUnit to an integer once we switch to
+ FractionalLayoutUnits.
+ (WebCore::boundedMultiply): Method that will return the multiplied result of two LayoutUnits
+ or the max/min LayoutUnit if the result overflows. Only does a regular multiply while
+ LayoutUnits are integers instead of FractionalLayoutUnits.
+ (WebCore):
+ * rendering/RenderBlock.cpp:
+ (WebCore::RenderBlock::paintContents): Rounding the paintOffset here didn't work for all
+ inline blocks. This rounding is actually only needed for InlineTextBoxes, so the logic has
+ been moved there.
+ (WebCore::RenderBlock::newLine): Use a LayoutUnit for the y position.
+ (WebCore::RenderBlock::isPointInOverflowControl): Points for hit testing need to be rounded.
+ (WebCore::RenderBlock::layoutColumns): Using boundedMultiply for a calculation prone to overflow.
+ (WebCore::updatePreferredWidth): Reverting back to using ceilf. ceiledLayoutUnit was to be ultimately
+ converted to just a straight LayoutUnit constructor to preserve precision. This precision doesn't work
+ for us here as we still paint Boxes/Blocks on pixel boundaries, so we need to expand to a pixel size
+ that encloses the contained text.
+ (WebCore::RenderBlock::setPageLogicalOffset): LogicalOffset should be a LayoutUnit.
+ (WebCore::RenderBlock::marginValuesForChild): Margins should have subpixel resolution.
+ (WebCore::RenderBlock::FloatingObjects::intervalForFloatingObject): Intervals for floating objects
+ need to use pixel snapped values to give the proper results.
+ * rendering/RenderBlock.h:
+ (WebCore::RenderBlock::pixelSnappedLogicalLeftOffsetForLine): Only moved.
+ (WebCore::RenderBlock::pixelSnappedLogicalRightOffsetForLine): While we can round the left offset,
+ columns add an extra offset at paint that can't currently be planned for at line-layout time. To
+ avoid laying out lines that run off the end of columns, we floor the right offset. The resulting
+ lines will be up to 1 pixel shorter than they potentially could be.
+ (RenderBlock):
+ (WebCore::RenderBlock::FloatingObject::pixelSnappedX): Using corresponding pixelSnappedX value from
+ LayoutRects.
+ (WebCore::RenderBlock::FloatingObject::pixelSnappedMaxX): Ditto.
+ (WebCore::RenderBlock::FloatingObject::pixelSnappedY): Ditto.
+ (WebCore::RenderBlock::FloatingObject::pixelSnappedMaxY): Ditto.
+ (WebCore::RenderBlock::FloatingObject::pixelSnappedWidth): Ditto.
+ (WebCore::RenderBlock::FloatingObject::pixelSnappedHeight): Ditto.
+ * rendering/RenderBlockLineLayout.cpp:
+ (WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded): LogicalHeight is a LayoutUnit. Also
+ flooring textIndentOffset to an integer to match old behavior.
+ (WebCore::LineWidth::fitBelowFloats): Using LayoutUnits for float logical top and bottoms.
+ (WebCore::LineLayoutState::endLineLogicalTop): Changing to a LayoutUnit.
+ (WebCore::LineLayoutState::setEndLineLogicalTop): Ditto.
+ (LineLayoutState): Ditto.
+ (WebCore::RenderBlock::linkToEndLineIfNeeded): Calculating overflow with LayoutUnits.
+ (WebCore::RenderBlock::layoutInlineChildren): LowestAllowedPosition should be subpixel.
+ (WebCore::RenderBlock::checkLinesForTextOverflow): Reverting ellipsis width calculation to integers
+ as this value can be seen as representing pixels on screen.
+
2012-03-15 Kenneth Rohde Christiansen <[email protected]>
Follow up to: window.innerWidth/Height should not include page scale
Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (110982 => 110983)
--- trunk/Source/WebCore/rendering/InlineTextBox.cpp 2012-03-16 10:39:51 UTC (rev 110982)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp 2012-03-16 10:52:56 UTC (rev 110983)
@@ -483,7 +483,7 @@
LayoutUnit paintEnd = isHorizontal() ? paintInfo.rect.maxX() : paintInfo.rect.maxY();
LayoutUnit paintStart = isHorizontal() ? paintInfo.rect.x() : paintInfo.rect.y();
- LayoutPoint adjustedPaintOffset = paintOffset;
+ LayoutPoint adjustedPaintOffset = roundedIntPoint(paintOffset);
if (logicalStart >= paintEnd || logicalStart + logicalExtent <= paintStart)
return;
Modified: trunk/Source/WebCore/rendering/LayoutTypes.h (110982 => 110983)
--- trunk/Source/WebCore/rendering/LayoutTypes.h 2012-03-16 10:39:51 UTC (rev 110982)
+++ trunk/Source/WebCore/rendering/LayoutTypes.h 2012-03-16 10:52:56 UTC (rev 110983)
@@ -120,6 +120,11 @@
return value;
}
+inline int floorToInt(LayoutUnit value)
+{
+ return value;
+}
+
inline LayoutUnit roundedLayoutUnit(float value)
{
return lroundf(value);
@@ -155,6 +160,11 @@
return true;
}
+inline LayoutUnit boundedMultiply(const LayoutUnit& a, const LayoutUnit& b)
+{
+ return a * b;
+}
+
} // namespace WebCore
#endif // LayoutTypes_h
Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (110982 => 110983)
--- trunk/Source/WebCore/rendering/RenderBlock.cpp 2012-03-16 10:39:51 UTC (rev 110982)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp 2012-03-16 10:52:56 UTC (rev 110983)
@@ -2780,13 +2780,10 @@
if (document()->didLayoutWithPendingStylesheets() && !isRenderView())
return;
- // We don't want to hand off painting in the line box tree with the accumulated error of the render tree, as this will cause
- // us to mess up painting aligned things (such as underlines in text) with both the render tree and line box tree's error.
- LayoutPoint roundedPaintOffset = roundedIntPoint(paintOffset);
if (childrenInline())
- m_lineBoxes.paint(this, paintInfo, roundedPaintOffset);
+ m_lineBoxes.paint(this, paintInfo, paintOffset);
else
- paintChildren(paintInfo, roundedPaintOffset);
+ paintChildren(paintInfo, paintOffset);
}
void RenderBlock::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
@@ -3786,7 +3783,7 @@
{
positionNewFloats();
// set y position
- int newY = 0;
+ LayoutUnit newY = 0;
switch (clear)
{
case CLEFT:
@@ -4477,7 +4474,7 @@
if (!scrollsOverflow() || !hasLayer())
return false;
- return layer()->hitTestOverflowControls(result, pointInContainer - toLayoutSize(accumulatedOffset));
+ return layer()->hitTestOverflowControls(result, roundedIntPoint(pointInContainer - toLayoutSize(accumulatedOffset)));
}
bool RenderBlock::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
@@ -5018,7 +5015,7 @@
view()->layoutState()->pageLogicalOffset(borderBefore() + paddingBefore() + contentLogicalHeight()) - colInfo->forcedBreakOffset());
columnHeight = max(colInfo->minimumColumnHeight(), distanceBetweenBreaks);
}
- } else if (contentLogicalHeight() > pageLogicalHeight * desiredColumnCount) {
+ } else if (contentLogicalHeight() > boundedMultiply(pageLogicalHeight, desiredColumnCount)) {
// Now that we know the intrinsic height of the columns, we have to rebalance them.
columnHeight = max<LayoutUnit>(colInfo->minimumColumnHeight(), ceilf((float)contentLogicalHeight() / desiredColumnCount));
}
@@ -5409,7 +5406,7 @@
static inline void updatePreferredWidth(LayoutUnit& preferredWidth, float& result)
{
- LayoutUnit snappedResult = ceiledLayoutUnit(result);
+ LayoutUnit snappedResult = ceilf(result);
preferredWidth = max(snappedResult, preferredWidth);
}
@@ -6369,7 +6366,7 @@
m_rareData->m_paginationStrut = strut;
}
-void RenderBlock::setPageLogicalOffset(int logicalOffset)
+void RenderBlock::setPageLogicalOffset(LayoutUnit logicalOffset)
{
if (!m_rareData) {
if (!logicalOffset)
@@ -7172,13 +7169,13 @@
RenderBlock::MarginValues RenderBlock::marginValuesForChild(RenderBox* child)
{
- int childBeforePositive = 0;
- int childBeforeNegative = 0;
- int childAfterPositive = 0;
- int childAfterNegative = 0;
+ LayoutUnit childBeforePositive = 0;
+ LayoutUnit childBeforeNegative = 0;
+ LayoutUnit childAfterPositive = 0;
+ LayoutUnit childAfterNegative = 0;
- int beforeMargin = 0;
- int afterMargin = 0;
+ LayoutUnit beforeMargin = 0;
+ LayoutUnit afterMargin = 0;
RenderBlock* childRenderBlock = child->isRenderBlock() ? toRenderBlock(child) : 0;
@@ -7286,8 +7283,8 @@
inline RenderBlock::FloatingObjectInterval RenderBlock::FloatingObjects::intervalForFloatingObject(FloatingObject* floatingObject)
{
if (m_horizontalWritingMode)
- return RenderBlock::FloatingObjectInterval(floatingObject->y(), floatingObject->maxY(), floatingObject);
- return RenderBlock::FloatingObjectInterval(floatingObject->x(), floatingObject->maxX(), floatingObject);
+ return RenderBlock::FloatingObjectInterval(floatingObject->pixelSnappedY(), floatingObject->pixelSnappedMaxY(), floatingObject);
+ return RenderBlock::FloatingObjectInterval(floatingObject->pixelSnappedX(), floatingObject->pixelSnappedMaxX(), floatingObject);
}
void RenderBlock::FloatingObjects::addPlacedObject(FloatingObject* floatingObject)
Modified: trunk/Source/WebCore/rendering/RenderBlock.h (110982 => 110983)
--- trunk/Source/WebCore/rendering/RenderBlock.h 2012-03-16 10:39:51 UTC (rev 110982)
+++ trunk/Source/WebCore/rendering/RenderBlock.h 2012-03-16 10:52:56 UTC (rev 110983)
@@ -166,6 +166,17 @@
{
return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0);
}
+ LayoutUnit pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool firstLine) const
+ {
+ return roundToInt(logicalLeftOffsetForLine(position, firstLine));
+ }
+ LayoutUnit pixelSnappedLogicalRightOffsetForLine(LayoutUnit position, bool firstLine) const
+ {
+ // FIXME: Multicolumn layouts break carrying over subpixel values to the logical right offset because the lines may be shifted
+ // by a subpixel value for all but the first column. This can lead to the actual pixel snapped width of the column being off
+ // by one pixel when rendered versus layed out, which can result in the line being clipped. For now, we have to floor.
+ return floorToInt(logicalRightOffsetForLine(position, firstLine));
+ }
LayoutUnit startOffsetForLine(LayoutUnit position, bool firstLine) const
{
return style()->isLeftToRightDirection() ? logicalLeftOffsetForLine(position, firstLine)
@@ -177,17 +188,6 @@
: logicalWidth() - logicalRightOffsetForLine(position, firstLine);
}
- // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
- int pixelSnappedLogicalRightOffsetForLine(LayoutUnit position, bool firstLine) const
- {
- return logicalRightOffsetForLine(position, logicalRightOffsetForContent(position), firstLine, 0);
- }
-
- int pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool firstLine) const
- {
- return roundToInt(logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0));
- }
-
LayoutUnit startAlignedOffsetForLine(RenderBox* child, LayoutUnit position, bool firstLine);
LayoutUnit textIndentOffset() const;
@@ -261,7 +261,7 @@
// The page logical offset is the object's offset from the top of the page in the page progression
// direction (so an x-offset in vertical text and a y-offset for horizontal text).
LayoutUnit pageLogicalOffset() const { return m_rareData ? m_rareData->m_pageLogicalOffset : zeroLayoutUnit; }
- void setPageLogicalOffset(int);
+ void setPageLogicalOffset(LayoutUnit);
RootInlineBox* lineGridBox() const { return m_rareData ? m_rareData->m_lineGridBox : 0; }
void setLineGridBox(RootInlineBox* box)
@@ -600,13 +600,12 @@
LayoutUnit width() const { return m_frameRect.width(); }
LayoutUnit height() const { return m_frameRect.height(); }
- // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
- int pixelSnappedX() const { return x(); }
- int pixelSnappedMaxX() const { return maxX(); }
- int pixelSnappedY() const { return y(); }
- int pixelSnappedMaxY() const { return maxY(); }
- int pixelSnappedWidth() const { return width(); }
- int pixelSnappedHeight() const { return height(); }
+ int pixelSnappedX() const { ASSERT(isPlaced()); return m_frameRect.pixelSnappedX(); }
+ int pixelSnappedMaxX() const { ASSERT(isPlaced()); return m_frameRect.pixelSnappedMaxX(); }
+ int pixelSnappedY() const { ASSERT(isPlaced()); return m_frameRect.pixelSnappedY(); }
+ int pixelSnappedMaxY() const { ASSERT(isPlaced()); return m_frameRect.pixelSnappedMaxY(); }
+ int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
+ int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
void setX(LayoutUnit x) { ASSERT(!isInPlacedTree()); m_frameRect.setX(x); }
void setY(LayoutUnit y) { ASSERT(!isInPlacedTree()); m_frameRect.setY(y); }
Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (110982 => 110983)
--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp 2012-03-16 10:39:51 UTC (rev 110982)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp 2012-03-16 10:52:56 UTC (rev 110983)
@@ -123,18 +123,18 @@
inline void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(RenderBlock::FloatingObject* newFloat)
{
- int height = m_block->logicalHeight();
+ LayoutUnit height = m_block->logicalHeight();
if (height < m_block->logicalTopForFloat(newFloat) || height >= m_block->logicalBottomForFloat(newFloat))
return;
if (newFloat->type() == RenderBlock::FloatingObject::FloatLeft) {
m_left = m_block->pixelSnappedLogicalRightForFloat(newFloat);
if (m_isFirstLine && m_block->style()->isLeftToRightDirection())
- m_left += m_block->textIndentOffset();
+ m_left += floorToInt(m_block->textIndentOffset());
} else {
m_right = m_block->pixelSnappedLogicalLeftForFloat(newFloat);
if (m_isFirstLine && !m_block->style()->isLeftToRightDirection())
- m_right -= m_block->textIndentOffset();
+ m_right -= floorToInt(m_block->textIndentOffset());
}
computeAvailableWidthFromLeftAndRight();
@@ -159,8 +159,8 @@
ASSERT(!m_committedWidth);
ASSERT(!fitsOnLine());
- int floatLogicalBottom;
- int lastFloatLogicalBottom = m_block->logicalHeight();
+ LayoutUnit floatLogicalBottom;
+ LayoutUnit lastFloatLogicalBottom = m_block->logicalHeight();
float newLineWidth = m_availableWidth;
float newLineLeft = m_left;
float newLineRight = m_right;
@@ -654,7 +654,7 @@
glyphOverflow.computeBounds = true;
}
- int hyphenWidth = 0;
+ LayoutUnit hyphenWidth = 0;
if (toInlineTextBox(run->m_box)->hasHyphen()) {
const Font& font = renderer->style(lineInfo.isFirstLine())->font();
hyphenWidth = measureHyphenWidth(renderer, font);
@@ -1109,8 +1109,8 @@
LineInfo& lineInfo() { return m_lineInfo; }
const LineInfo& lineInfo() const { return m_lineInfo; }
- int endLineLogicalTop() const { return m_endLineLogicalTop; }
- void setEndLineLogicalTop(int logicalTop) { m_endLineLogicalTop = logicalTop; }
+ LayoutUnit endLineLogicalTop() const { return m_endLineLogicalTop; }
+ void setEndLineLogicalTop(LayoutUnit logicalTop) { m_endLineLogicalTop = logicalTop; }
RootInlineBox* endLine() const { return m_endLine; }
void setEndLine(RootInlineBox* line) { m_endLine = line; }
@@ -1129,7 +1129,7 @@
RootInlineBox* m_endLine;
LineInfo m_lineInfo;
unsigned m_floatIndex;
- int m_endLineLogicalTop;
+ LayoutUnit m_endLineLogicalTop;
bool m_endLineMatched;
bool m_checkForFloatsFromLastLine;
@@ -1400,19 +1400,19 @@
// This has to be done before adding in the bottom border/padding, or the float will
// include the padding incorrectly. -dwh
if (layoutState.checkForFloatsFromLastLine()) {
- int bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
- int bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
+ LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
+ LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
TrailingFloatsRootInlineBox* trailingFloatsLineBox = new (renderArena()) TrailingFloatsRootInlineBox(this);
m_lineBoxes.appendLineBox(trailingFloatsLineBox);
trailingFloatsLineBox->setConstructed();
GlyphOverflowAndFallbackFontsMap textBoxDataMap;
VerticalPositionCache verticalPositionCache;
- int blockLogicalHeight = logicalHeight();
+ LayoutUnit blockLogicalHeight = logicalHeight();
trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache);
trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight);
trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight));
- IntRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
- IntRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
+ LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight);
+ LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight);
trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom());
}
@@ -1517,7 +1517,7 @@
// Expand the last line to accommodate Ruby and emphasis marks.
int lastLineAnnotationsAdjustment = 0;
if (lastRootBox()) {
- int lowestAllowedPosition = max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
+ LayoutUnit lowestAllowedPosition = max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter());
if (!style()->isFlippedLinesWritingMode())
lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition);
else
@@ -2690,8 +2690,8 @@
const Font& font = style()->font();
DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
const Font& firstLineFont = firstLineStyle()->font();
- LayoutUnit firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
- LayoutUnit ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
+ int firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle()));
+ int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style()));
// For LTR text truncation, we want to get the right edge of our padding box, and then we want to see
// if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and