Title: [109378] trunk/Source/WebCore
Revision
109378
Author
[email protected]
Date
2012-03-01 11:33:44 -0800 (Thu, 01 Mar 2012)

Log Message

Add roundToInt method for LayoutUnits
https://bugs.webkit.org/show_bug.cgi?id=79283

Reviewed by Eric Seidel.

Adding a roundToInt method that rounds a LayoutUnit to the nearest integer. This
only has an effect once we switch to sub-pixel positioning. Points and offsets
are rounded for painting and hit testing.

No new tests. No change in behavior.

* dom/MouseRelatedEvent.cpp:
(WebCore::MouseRelatedEvent::offsetX):
(WebCore::MouseRelatedEvent::offsetY):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::updateSizes):
* rendering/LayoutState.cpp:
(WebCore::LayoutState::computeLineGridPaginationOrigin):
* rendering/LayoutTypes.h:
(WebCore::roundToInt): Stub until we switch to sub-pixel LayoutUnits.
(WebCore):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::pageLogicalTopForOffset):
* rendering/RenderBlock.h:
(WebCore::RenderBlock::pixelSnappedLogicalLeftOffsetForLine): Correcting to use the
pixel snapped methods on FloatingObjects and removing the fixme.
(WebCore::RenderBlock::pixelSnappedLogicalTopForFloat): Ditto.
(WebCore::RenderBlock::pixelSnappedLogicalBottomForFloat): Ditto.
(WebCore::RenderBlock::pixelSnappedLogicalLeftForFloat): Ditto.
(WebCore::RenderBlock::pixelSnappedLogicalRightForFloat): Ditto.
(WebCore::RenderBlock::pixelSnappedLogicalWidthForFloat): Ditto.
* rendering/RenderBlockLineLayout.cpp:
(WebCore::LineWidth::updateAvailableWidth):
(WebCore::RenderBlock::computeInlineDirectionPositionsForLine): Using
pixelSnappedLogicalLeft/RightOffsetForLine convenience methods for line layout. When
we switch to sub-pixel positioning, we still pixel snap blocks before painting them,
but text is rendered using floats. We need to ensure the text is laid out using the
actual pixel width of the containing block to avoid bleeding out of the block.
* rendering/RenderBoxModelObject.h: Moving the fixme to pixelSnappedWidth/Height and
adding the necessary rounding for Left/Top.
(WebCore::RenderBoxModelObject::pixelSnappedOffsetLeft):
(WebCore::RenderBoxModelObject::pixelSnappedOffsetTop):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollRectToVisible):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::scrollHeight): Rounding the height for scrollHeight. Scrolling
always uses rounded values.
* rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::localToParentTransform): Similar to the line box tree, since
SVG renders using floats, we need to start with pixel snapped values from the render
tree or we'll end up with the contents not properly aligned to the rest of the page.
* rendering/svg/SVGRenderSupport.cpp:
(WebCore::SVGRenderSupport::prepareToRenderSVGContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (109377 => 109378)


--- trunk/Source/WebCore/ChangeLog	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/ChangeLog	2012-03-01 19:33:44 UTC (rev 109378)
@@ -1,3 +1,59 @@
+2012-03-01  Levi Weintraub  <[email protected]>
+
+        Add roundToInt method for LayoutUnits
+        https://bugs.webkit.org/show_bug.cgi?id=79283
+
+        Reviewed by Eric Seidel.
+
+        Adding a roundToInt method that rounds a LayoutUnit to the nearest integer. This
+        only has an effect once we switch to sub-pixel positioning. Points and offsets
+        are rounded for painting and hit testing.
+
+        No new tests. No change in behavior.
+
+        * dom/MouseRelatedEvent.cpp:
+        (WebCore::MouseRelatedEvent::offsetX):
+        (WebCore::MouseRelatedEvent::offsetY):
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlTextTrackContainerElement::updateSizes):
+        * rendering/LayoutState.cpp:
+        (WebCore::LayoutState::computeLineGridPaginationOrigin):
+        * rendering/LayoutTypes.h:
+        (WebCore::roundToInt): Stub until we switch to sub-pixel LayoutUnits.
+        (WebCore):
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::pageLogicalTopForOffset):
+        * rendering/RenderBlock.h:
+        (WebCore::RenderBlock::pixelSnappedLogicalLeftOffsetForLine): Correcting to use the
+        pixel snapped methods on FloatingObjects and removing the fixme.
+        (WebCore::RenderBlock::pixelSnappedLogicalTopForFloat): Ditto.
+        (WebCore::RenderBlock::pixelSnappedLogicalBottomForFloat): Ditto.
+        (WebCore::RenderBlock::pixelSnappedLogicalLeftForFloat): Ditto.
+        (WebCore::RenderBlock::pixelSnappedLogicalRightForFloat): Ditto.
+        (WebCore::RenderBlock::pixelSnappedLogicalWidthForFloat): Ditto.
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::LineWidth::updateAvailableWidth):
+        (WebCore::RenderBlock::computeInlineDirectionPositionsForLine): Using
+        pixelSnappedLogicalLeft/RightOffsetForLine convenience methods for line layout. When
+        we switch to sub-pixel positioning, we still pixel snap blocks before painting them,
+        but text is rendered using floats. We need to ensure the text is laid out using the
+        actual pixel width of the containing block to avoid bleeding out of the block.
+        * rendering/RenderBoxModelObject.h: Moving the fixme to pixelSnappedWidth/Height and
+        adding the necessary rounding for Left/Top.
+        (WebCore::RenderBoxModelObject::pixelSnappedOffsetLeft):
+        (WebCore::RenderBoxModelObject::pixelSnappedOffsetTop):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::scrollRectToVisible):
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::scrollHeight): Rounding the height for scrollHeight. Scrolling
+        always uses rounded values.
+        * rendering/svg/RenderSVGRoot.cpp:
+        (WebCore::RenderSVGRoot::localToParentTransform): Similar to the line box tree, since
+        SVG renders using floats, we need to start with pixel snapped values from the render
+        tree or we'll end up with the contents not properly aligned to the rest of the page.
+        * rendering/svg/SVGRenderSupport.cpp:
+        (WebCore::SVGRenderSupport::prepareToRenderSVGContent):
+
 2012-03-01  Pavel Feldman  <[email protected]>
 
         Web Inspector: arrays in object properties sections do not scale.

Modified: trunk/Source/WebCore/dom/MouseRelatedEvent.cpp (109377 => 109378)


--- trunk/Source/WebCore/dom/MouseRelatedEvent.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/dom/MouseRelatedEvent.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -214,14 +214,14 @@
 {
     if (!m_hasCachedRelativePosition)
         computeRelativePosition();
-    return m_offsetLocation.x();
+    return roundToInt(m_offsetLocation.x());
 }
 
 int MouseRelatedEvent::offsetY()
 {
     if (!m_hasCachedRelativePosition)
         computeRelativePosition();
-    return m_offsetLocation.y();
+    return roundToInt(m_offsetLocation.y());
 }
 
 int MouseRelatedEvent::pageX() const

Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.cpp (109377 => 109378)


--- trunk/Source/WebCore/html/shadow/MediaControlElements.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -1211,7 +1211,7 @@
     LayoutUnit bottom = static_cast<LayoutUnit>(m_videoDisplaySize.y() + m_videoDisplaySize.height() - (m_videoDisplaySize.height() * trackBottomMultiplier));
     if (bottom != m_bottom) {
         m_bottom = bottom;
-        setInlineStyleProperty(CSSPropertyBottom, String::number(bottom) + "px");
+        setInlineStyleProperty(CSSPropertyBottom, String::number(roundToInt(bottom)) + "px");
     }
 }
 

Modified: trunk/Source/WebCore/rendering/LayoutState.cpp (109377 => 109378)


--- trunk/Source/WebCore/rendering/LayoutState.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/LayoutState.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -278,7 +278,7 @@
         if (pageLogicalTop > firstLineTopWithLeading) {
             // Shift to the next highest line grid multiple past the page logical top. Cache the delta
             // between this new value and the page logical top as the pagination origin.
-            LayoutUnit remainder = (pageLogicalTop - firstLineTopWithLeading) % gridLineHeight;
+            LayoutUnit remainder = roundToInt(pageLogicalTop - firstLineTopWithLeading) % roundToInt(gridLineHeight);
             LayoutUnit paginationDelta = gridLineHeight - remainder;
             if (isHorizontalWritingMode)
                 m_lineGridPaginationOrigin.setHeight(paginationDelta);

Modified: trunk/Source/WebCore/rendering/LayoutTypes.h (109377 => 109378)


--- trunk/Source/WebCore/rendering/LayoutTypes.h	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/LayoutTypes.h	2012-03-01 19:33:44 UTC (rev 109378)
@@ -98,6 +98,11 @@
     return LayoutSize(static_cast<int>(p.x()), static_cast<int>(p.y()));
 }
 
+inline int roundToInt(LayoutUnit value)
+{
+    return value;
+}
+
 inline LayoutUnit roundedLayoutUnit(float value)
 {
     return lroundf(value);

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (109377 => 109378)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -6673,7 +6673,7 @@
         LayoutUnit pageLogicalHeight = renderView->layoutState()->pageLogicalHeight();
         if (!pageLogicalHeight)
             return 0;
-        return cumulativeOffset - (cumulativeOffset - firstPageLogicalTop) % pageLogicalHeight;
+        return cumulativeOffset - roundToInt(cumulativeOffset - firstPageLogicalTop) % roundToInt(pageLogicalHeight);
     }
     return enclosingRenderFlowThread()->regionLogicalTopForLine(cumulativeOffset);
 }

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (109377 => 109378)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2012-03-01 19:33:44 UTC (rev 109378)
@@ -182,7 +182,7 @@
 
     int pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool firstLine) const
     {
-        return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0);
+        return roundToInt(logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0));
     }
     
     LayoutUnit startAlignedOffsetForLine(RenderBox* child, LayoutUnit position, bool firstLine);
@@ -636,11 +636,11 @@
     LayoutUnit logicalRightForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->maxX() : child->maxY(); }
     LayoutUnit logicalWidthForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->width() : child->height(); }
 
-    // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
-    int pixelSnappedLogicalTopForFloat(const FloatingObject* child) const { return logicalTopForFloat(child); }
-    int pixelSnappedLogicalBottomForFloat(const FloatingObject* child) const { return logicalBottomForFloat(child); }
-    int pixelSnappedLogicalLeftForFloat(const FloatingObject* child) const { return logicalLeftForFloat(child); }
-    int pixelSnappedLogicalRightForFloat(const FloatingObject* child) const { return logicalRightForFloat(child); }
+    int pixelSnappedLogicalTopForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedY() : child->pixelSnappedX(); }
+    int pixelSnappedLogicalBottomForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedMaxY() : child->pixelSnappedMaxX(); }
+    int pixelSnappedLogicalLeftForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedX() : child->pixelSnappedY(); }
+    int pixelSnappedLogicalRightForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedMaxX() : child->pixelSnappedMaxY(); }
+    int pixelSnappedLogicalWidthForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedWidth() : child->pixelSnappedHeight(); }
 
     void setLogicalTopForFloat(FloatingObject* child, LayoutUnit logicalTop)
     {

Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (109377 => 109378)


--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -114,9 +114,9 @@
 
 inline void LineWidth::updateAvailableWidth()
 {
-    int height = m_block->logicalHeight();
-    m_left = m_block->logicalLeftOffsetForLine(height, m_isFirstLine);
-    m_right = m_block->logicalRightOffsetForLine(height, m_isFirstLine);
+    LayoutUnit height = m_block->logicalHeight();
+    m_left = m_block->pixelSnappedLogicalLeftOffsetForLine(height, m_isFirstLine);
+    m_right = m_block->pixelSnappedLogicalRightOffsetForLine(height, m_isFirstLine);
 
     computeAvailableWidthFromLeftAndRight();
 }
@@ -759,8 +759,8 @@
                                                          GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache)
 {
     ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
-    float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), lineInfo.isFirstLine());
-    float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), lineInfo.isFirstLine()) - logicalLeft;
+    float logicalLeft = pixelSnappedLogicalLeftOffsetForLine(logicalHeight(), lineInfo.isFirstLine());
+    float availableLogicalWidth = pixelSnappedLogicalRightOffsetForLine(logicalHeight(), lineInfo.isFirstLine()) - logicalLeft;
 
     bool needsWordSpacing = false;
     float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.h (109377 => 109378)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2012-03-01 19:33:44 UTC (rev 109378)
@@ -60,9 +60,9 @@
     virtual LayoutUnit offsetWidth() const = 0;
     virtual LayoutUnit offsetHeight() const = 0;
 
+    int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
+    int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
     // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
-    int pixelSnappedOffsetLeft() const { return offsetLeft(); }
-    int pixelSnappedOffsetTop() const { return offsetTop(); }
     int pixelSnappedOffsetWidth() const;
     int pixelSnappedOffsetHeight() const;
 

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (109377 => 109378)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -1547,11 +1547,14 @@
         LayoutRect exposeRect = LayoutRect(rect.x() + scrollXOffset(), rect.y() + scrollYOffset(), rect.width(), rect.height());
         LayoutRect r = getRectToExpose(layerBounds, exposeRect, alignX, alignY);
         
-        LayoutUnit xOffset = r.x() - absPos.x();
-        LayoutUnit yOffset = r.y() - absPos.y();
+        LayoutUnit adjustedX = r.x() - absPos.x();
+        LayoutUnit adjustedY = r.y() - absPos.y();
         // Adjust offsets if they're outside of the allowable range.
-        xOffset = max<LayoutUnit>(0, min(scrollWidth() - layerBounds.width(), xOffset));
-        yOffset = max<LayoutUnit>(0, min(scrollHeight() - layerBounds.height(), yOffset));
+        adjustedX = max<LayoutUnit>(0, min(scrollWidth() - layerBounds.width(), adjustedX));
+        adjustedY = max<LayoutUnit>(0, min(scrollHeight() - layerBounds.height(), adjustedY));
+
+        int xOffset = roundToInt(adjustedX);
+        int yOffset = roundToInt(adjustedY);
         
         if (xOffset != scrollXOffset() || yOffset != scrollYOffset()) {
             LayoutUnit diffX = scrollXOffset();
@@ -1578,8 +1581,8 @@
                     LayoutRect viewRect = frameView->visibleContentRect();
                     LayoutRect exposeRect = getRectToExpose(viewRect, rect, alignX, alignY);
 
-                    LayoutUnit xOffset = exposeRect.x();
-                    LayoutUnit yOffset = exposeRect.y();
+                    int xOffset = roundToInt(exposeRect.x());
+                    int yOffset = roundToInt(exposeRect.y());
                     // Adjust offsets if they're outside of the allowable range.
                     xOffset = max<LayoutUnit>(0, min(frameView->contentsWidth(), xOffset));
                     yOffset = max<LayoutUnit>(0, min(frameView->contentsHeight(), yOffset));

Modified: trunk/Source/WebCore/rendering/RenderListBox.cpp (109377 => 109378)


--- trunk/Source/WebCore/rendering/RenderListBox.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/RenderListBox.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -651,7 +651,7 @@
 
 int RenderListBox::scrollHeight() const
 {
-    return max(pixelSnappedClientHeight(), listHeight());
+    return max(pixelSnappedClientHeight(), roundToInt(listHeight()));
 }
 
 int RenderListBox::scrollLeft() const

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp (109377 => 109378)


--- trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -336,9 +336,9 @@
     // Slightly optimized version of m_localToParentTransform = AffineTransform::translation(x(), y()) * m_localToBorderBoxTransform;
     m_localToParentTransform = m_localToBorderBoxTransform;
     if (x())
-        m_localToParentTransform.setE(m_localToParentTransform.e() + x());
+        m_localToParentTransform.setE(m_localToParentTransform.e() + roundToInt(x()));
     if (y())
-        m_localToParentTransform.setF(m_localToParentTransform.f() + y());
+        m_localToParentTransform.setF(m_localToParentTransform.f() + roundToInt(y()));
     return m_localToParentTransform;
 }
 

Modified: trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp (109377 => 109378)


--- trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp	2012-03-01 19:26:02 UTC (rev 109377)
+++ trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp	2012-03-01 19:33:44 UTC (rev 109378)
@@ -111,7 +111,7 @@
 
         if (shadow) {
             paintInfo.context->clip(repaintRect);
-            paintInfo.context->setShadow(IntSize(shadow->x(), shadow->y()), shadow->blur(), shadow->color(), style->colorSpace());
+            paintInfo.context->setShadow(IntSize(roundToInt(shadow->x()), roundToInt(shadow->y())), shadow->blur(), shadow->color(), style->colorSpace());
             paintInfo.context->beginTransparencyLayer(1);
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to