Changeset 109378 in webkit


Ignore:
Timestamp:
Mar 1, 2012 11:33:44 AM (12 years ago)
Author:
leviw@chromium.org
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):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r109372 r109378  
     12012-03-01  Levi Weintraub  <leviw@chromium.org>
     2
     3        Add roundToInt method for LayoutUnits
     4        https://bugs.webkit.org/show_bug.cgi?id=79283
     5
     6        Reviewed by Eric Seidel.
     7
     8        Adding a roundToInt method that rounds a LayoutUnit to the nearest integer. This
     9        only has an effect once we switch to sub-pixel positioning. Points and offsets
     10        are rounded for painting and hit testing.
     11
     12        No new tests. No change in behavior.
     13
     14        * dom/MouseRelatedEvent.cpp:
     15        (WebCore::MouseRelatedEvent::offsetX):
     16        (WebCore::MouseRelatedEvent::offsetY):
     17        * html/shadow/MediaControlElements.cpp:
     18        (WebCore::MediaControlTextTrackContainerElement::updateSizes):
     19        * rendering/LayoutState.cpp:
     20        (WebCore::LayoutState::computeLineGridPaginationOrigin):
     21        * rendering/LayoutTypes.h:
     22        (WebCore::roundToInt): Stub until we switch to sub-pixel LayoutUnits.
     23        (WebCore):
     24        * rendering/RenderBlock.cpp:
     25        (WebCore::RenderBlock::pageLogicalTopForOffset):
     26        * rendering/RenderBlock.h:
     27        (WebCore::RenderBlock::pixelSnappedLogicalLeftOffsetForLine): Correcting to use the
     28        pixel snapped methods on FloatingObjects and removing the fixme.
     29        (WebCore::RenderBlock::pixelSnappedLogicalTopForFloat): Ditto.
     30        (WebCore::RenderBlock::pixelSnappedLogicalBottomForFloat): Ditto.
     31        (WebCore::RenderBlock::pixelSnappedLogicalLeftForFloat): Ditto.
     32        (WebCore::RenderBlock::pixelSnappedLogicalRightForFloat): Ditto.
     33        (WebCore::RenderBlock::pixelSnappedLogicalWidthForFloat): Ditto.
     34        * rendering/RenderBlockLineLayout.cpp:
     35        (WebCore::LineWidth::updateAvailableWidth):
     36        (WebCore::RenderBlock::computeInlineDirectionPositionsForLine): Using
     37        pixelSnappedLogicalLeft/RightOffsetForLine convenience methods for line layout. When
     38        we switch to sub-pixel positioning, we still pixel snap blocks before painting them,
     39        but text is rendered using floats. We need to ensure the text is laid out using the
     40        actual pixel width of the containing block to avoid bleeding out of the block.
     41        * rendering/RenderBoxModelObject.h: Moving the fixme to pixelSnappedWidth/Height and
     42        adding the necessary rounding for Left/Top.
     43        (WebCore::RenderBoxModelObject::pixelSnappedOffsetLeft):
     44        (WebCore::RenderBoxModelObject::pixelSnappedOffsetTop):
     45        * rendering/RenderLayer.cpp:
     46        (WebCore::RenderLayer::scrollRectToVisible):
     47        * rendering/RenderListBox.cpp:
     48        (WebCore::RenderListBox::scrollHeight): Rounding the height for scrollHeight. Scrolling
     49        always uses rounded values.
     50        * rendering/svg/RenderSVGRoot.cpp:
     51        (WebCore::RenderSVGRoot::localToParentTransform): Similar to the line box tree, since
     52        SVG renders using floats, we need to start with pixel snapped values from the render
     53        tree or we'll end up with the contents not properly aligned to the rest of the page.
     54        * rendering/svg/SVGRenderSupport.cpp:
     55        (WebCore::SVGRenderSupport::prepareToRenderSVGContent):
     56
    1572012-03-01  Pavel Feldman  <pfeldman@chromium.org>
    258
  • trunk/Source/WebCore/dom/MouseRelatedEvent.cpp

    r101111 r109378  
    215215    if (!m_hasCachedRelativePosition)
    216216        computeRelativePosition();
    217     return m_offsetLocation.x();
     217    return roundToInt(m_offsetLocation.x());
    218218}
    219219
     
    222222    if (!m_hasCachedRelativePosition)
    223223        computeRelativePosition();
    224     return m_offsetLocation.y();
     224    return roundToInt(m_offsetLocation.y());
    225225}
    226226
  • trunk/Source/WebCore/html/shadow/MediaControlElements.cpp

    r107899 r109378  
    12121212    if (bottom != m_bottom) {
    12131213        m_bottom = bottom;
    1214         setInlineStyleProperty(CSSPropertyBottom, String::number(bottom) + "px");
     1214        setInlineStyleProperty(CSSPropertyBottom, String::number(roundToInt(bottom)) + "px");
    12151215    }
    12161216}
  • trunk/Source/WebCore/rendering/LayoutState.cpp

    r109157 r109378  
    279279            // Shift to the next highest line grid multiple past the page logical top. Cache the delta
    280280            // between this new value and the page logical top as the pagination origin.
    281             LayoutUnit remainder = (pageLogicalTop - firstLineTopWithLeading) % gridLineHeight;
     281            LayoutUnit remainder = roundToInt(pageLogicalTop - firstLineTopWithLeading) % roundToInt(gridLineHeight);
    282282            LayoutUnit paginationDelta = gridLineHeight - remainder;
    283283            if (isHorizontalWritingMode)
  • trunk/Source/WebCore/rendering/LayoutTypes.h

    r108719 r109378  
    9999}
    100100
     101inline int roundToInt(LayoutUnit value)
     102{
     103    return value;
     104}
     105
    101106inline LayoutUnit roundedLayoutUnit(float value)
    102107{
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r109367 r109378  
    66746674        if (!pageLogicalHeight)
    66756675            return 0;
    6676         return cumulativeOffset - (cumulativeOffset - firstPageLogicalTop) % pageLogicalHeight;
     6676        return cumulativeOffset - roundToInt(cumulativeOffset - firstPageLogicalTop) % roundToInt(pageLogicalHeight);
    66776677    }
    66786678    return enclosingRenderFlowThread()->regionLogicalTopForLine(cumulativeOffset);
  • trunk/Source/WebCore/rendering/RenderBlock.h

    r109367 r109378  
    183183    int pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool firstLine) const
    184184    {
    185         return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0);
     185        return roundToInt(logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0));
    186186    }
    187187   
     
    637637    LayoutUnit logicalWidthForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->width() : child->height(); }
    638638
    639     // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
    640     int pixelSnappedLogicalTopForFloat(const FloatingObject* child) const { return logicalTopForFloat(child); }
    641     int pixelSnappedLogicalBottomForFloat(const FloatingObject* child) const { return logicalBottomForFloat(child); }
    642     int pixelSnappedLogicalLeftForFloat(const FloatingObject* child) const { return logicalLeftForFloat(child); }
    643     int pixelSnappedLogicalRightForFloat(const FloatingObject* child) const { return logicalRightForFloat(child); }
     639    int pixelSnappedLogicalTopForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedY() : child->pixelSnappedX(); }
     640    int pixelSnappedLogicalBottomForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedMaxY() : child->pixelSnappedMaxX(); }
     641    int pixelSnappedLogicalLeftForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedX() : child->pixelSnappedY(); }
     642    int pixelSnappedLogicalRightForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedMaxX() : child->pixelSnappedMaxY(); }
     643    int pixelSnappedLogicalWidthForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->pixelSnappedWidth() : child->pixelSnappedHeight(); }
    644644
    645645    void setLogicalTopForFloat(FloatingObject* child, LayoutUnit logicalTop)
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r109104 r109378  
    115115inline void LineWidth::updateAvailableWidth()
    116116{
    117     int height = m_block->logicalHeight();
    118     m_left = m_block->logicalLeftOffsetForLine(height, m_isFirstLine);
    119     m_right = m_block->logicalRightOffsetForLine(height, m_isFirstLine);
     117    LayoutUnit height = m_block->logicalHeight();
     118    m_left = m_block->pixelSnappedLogicalLeftOffsetForLine(height, m_isFirstLine);
     119    m_right = m_block->pixelSnappedLogicalRightOffsetForLine(height, m_isFirstLine);
    120120
    121121    computeAvailableWidthFromLeftAndRight();
     
    760760{
    761761    ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
    762     float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), lineInfo.isFirstLine());
    763     float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), lineInfo.isFirstLine()) - logicalLeft;
     762    float logicalLeft = pixelSnappedLogicalLeftOffsetForLine(logicalHeight(), lineInfo.isFirstLine());
     763    float availableLogicalWidth = pixelSnappedLogicalRightOffsetForLine(logicalHeight(), lineInfo.isFirstLine()) - logicalLeft;
    764764
    765765    bool needsWordSpacing = false;
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.h

    r109367 r109378  
    6161    virtual LayoutUnit offsetHeight() const = 0;
    6262
     63    int pixelSnappedOffsetLeft() const { return roundToInt(offsetLeft()); }
     64    int pixelSnappedOffsetTop() const { return roundToInt(offsetTop()); }
    6365    // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
    64     int pixelSnappedOffsetLeft() const { return offsetLeft(); }
    65     int pixelSnappedOffsetTop() const { return offsetTop(); }
    6666    int pixelSnappedOffsetWidth() const;
    6767    int pixelSnappedOffsetHeight() const;
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r109125 r109378  
    15481548        LayoutRect r = getRectToExpose(layerBounds, exposeRect, alignX, alignY);
    15491549       
    1550         LayoutUnit xOffset = r.x() - absPos.x();
    1551         LayoutUnit yOffset = r.y() - absPos.y();
     1550        LayoutUnit adjustedX = r.x() - absPos.x();
     1551        LayoutUnit adjustedY = r.y() - absPos.y();
    15521552        // Adjust offsets if they're outside of the allowable range.
    1553         xOffset = max<LayoutUnit>(0, min(scrollWidth() - layerBounds.width(), xOffset));
    1554         yOffset = max<LayoutUnit>(0, min(scrollHeight() - layerBounds.height(), yOffset));
     1553        adjustedX = max<LayoutUnit>(0, min(scrollWidth() - layerBounds.width(), adjustedX));
     1554        adjustedY = max<LayoutUnit>(0, min(scrollHeight() - layerBounds.height(), adjustedY));
     1555
     1556        int xOffset = roundToInt(adjustedX);
     1557        int yOffset = roundToInt(adjustedY);
    15551558       
    15561559        if (xOffset != scrollXOffset() || yOffset != scrollYOffset()) {
     
    15791582                    LayoutRect exposeRect = getRectToExpose(viewRect, rect, alignX, alignY);
    15801583
    1581                     LayoutUnit xOffset = exposeRect.x();
    1582                     LayoutUnit yOffset = exposeRect.y();
     1584                    int xOffset = roundToInt(exposeRect.x());
     1585                    int yOffset = roundToInt(exposeRect.y());
    15831586                    // Adjust offsets if they're outside of the allowable range.
    15841587                    xOffset = max<LayoutUnit>(0, min(frameView->contentsWidth(), xOffset));
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r107880 r109378  
    652652int RenderListBox::scrollHeight() const
    653653{
    654     return max(pixelSnappedClientHeight(), listHeight());
     654    return max(pixelSnappedClientHeight(), roundToInt(listHeight()));
    655655}
    656656
  • trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp

    r109273 r109378  
    337337    m_localToParentTransform = m_localToBorderBoxTransform;
    338338    if (x())
    339         m_localToParentTransform.setE(m_localToParentTransform.e() + x());
     339        m_localToParentTransform.setE(m_localToParentTransform.e() + roundToInt(x()));
    340340    if (y())
    341         m_localToParentTransform.setF(m_localToParentTransform.f() + y());
     341        m_localToParentTransform.setF(m_localToParentTransform.f() + roundToInt(y()));
    342342    return m_localToParentTransform;
    343343}
  • trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp

    r108699 r109378  
    112112        if (shadow) {
    113113            paintInfo.context->clip(repaintRect);
    114             paintInfo.context->setShadow(IntSize(shadow->x(), shadow->y()), shadow->blur(), shadow->color(), style->colorSpace());
     114            paintInfo.context->setShadow(IntSize(roundToInt(shadow->x()), roundToInt(shadow->y())), shadow->blur(), shadow->color(), style->colorSpace());
    115115            paintInfo.context->beginTransparencyLayer(1);
    116116        }
Note: See TracChangeset for help on using the changeset viewer.