Changeset 107032 in webkit


Ignore:
Timestamp:
Feb 7, 2012 7:56:27 PM (12 years ago)
Author:
eae@chromium.org
Message:

Add pixelSnappedX/Y/Width/Height methods
https://bugs.webkit.org/show_bug.cgi?id=78040

Reviewed by Eric Seidel.

Add pixel snapped versions of x/y/width/height methods. These return the
same value as the x/w/width/height methods for now but once we move over
to sub pixel layout they will snap the subpixel value to a device pixel
and return an integer value.

When snapping the left and top edge is simply rounded to the nearest
device pixel.
The right and bottom edges are computed by subtracting the rounded left/
top edge from the precise location and size. This ensures that the edges
all line up with device pixels and that the total size of an object,
including borders, is at most one pixel off.

In summary, the values are computed as follows:

x: round(x)
y: round(y)
maxX: round(x + width)
maxY: round(y + height)
width: round(x + width) - round(x)
height: round(y + height) - round(y)

We use the term pixel snapped to indicate that the numbers are not merely
rounded. This also matches the naming used by the line box tree.

No new tests, no functionality changes.

  • page/PrintContext.cpp:

(WebCore::PrintContext::pageNumberForElement):

  • rendering/RenderBlock.cpp:

(WebCore::::collectIfNeeded):

  • rendering/RenderBlock.h:

(RenderBlock):
(WebCore::RenderBlock::pixelSnappedLogicalRightOffsetForLine):
(WebCore::RenderBlock::pixelSnappedLogicalLeftOffsetForLine):
(WebCore::RenderBlock::FloatingObject::pixelSnappedX):
(WebCore::RenderBlock::FloatingObject::pixelSnappedMaxX):
(WebCore::RenderBlock::FloatingObject::pixelSnappedY):
(WebCore::RenderBlock::FloatingObject::pixelSnappedMaxY):
(WebCore::RenderBlock::FloatingObject::pixelSnappedWidth):
(WebCore::RenderBlock::FloatingObject::pixelSnappedHeight):
(FloatingObject):
(WebCore::RenderBlock::pixelSnappedLogicalTopForFloat):
(WebCore::RenderBlock::pixelSnappedLogicalBottomForFloat):
(WebCore::RenderBlock::pixelSnappedLogicalLeftForFloat):
(WebCore::RenderBlock::pixelSnappedLogicalRightForFloat):

  • rendering/RenderBlockLineLayout.cpp:

(WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded):

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::pixelSnappedClientWidth):
(WebCore):
(WebCore::RenderBox::pixelSnappedClientHeight):
(WebCore::RenderBox::scrollHeight):

  • rendering/RenderBox.h:

(WebCore::RenderBox::pixelSnappedWidth):
(WebCore::RenderBox::pixelSnappedHeight):
(RenderBox):
(WebCore::RenderBox::pixelSnappedOffsetWidth):
(WebCore::RenderBox::pixelSnappedOffsetHeight):
(WebCore::RenderBox::clientLogicalWidth):
(WebCore::RenderBox::clientLogicalHeight):

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::pixelSnappedOffsetWidth):
(WebCore):
(WebCore::RenderBoxModelObject::pixelSnappedOffsetHeight):

  • rendering/RenderBoxModelObject.h:

(WebCore::RenderBoxModelObject::pixelSnappedOffsetLeft):
(WebCore::RenderBoxModelObject::pixelSnappedOffsetTop):
(RenderBoxModelObject):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::pixelSnappedScrollWidth):
(WebCore):
(WebCore::RenderLayer::pixelSnappedScrollHeight):
(WebCore::RenderLayer::computeScrollDimensions):
(WebCore::RenderLayer::updateScrollInfoAfterLayout):

  • rendering/RenderLayer.h:

(RenderLayer):

  • rendering/RenderListBox.cpp:

(WebCore::RenderListBox::scrollHeight):

  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::volumeSliderOffsetFromMuteButton):

  • rendering/RenderTreeAsText.cpp:

(WebCore::write):

Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107030 r107032  
     12012-02-07  Emil A Eklund  <eae@chromium.org>
     2
     3        Add pixelSnappedX/Y/Width/Height methods
     4        https://bugs.webkit.org/show_bug.cgi?id=78040
     5
     6        Reviewed by Eric Seidel.
     7
     8        Add pixel snapped versions of x/y/width/height methods. These return the
     9        same value as the x/w/width/height methods for now but once we move over
     10        to sub pixel layout they will snap the subpixel value to a device pixel
     11        and return an integer value.
     12
     13        When snapping the left and top edge is simply rounded to the nearest
     14        device pixel.
     15        The right and bottom edges are computed by subtracting the rounded left/
     16        top edge from the precise location and size. This ensures that the edges
     17        all line up with device pixels and that the total size of an object,
     18        including borders, is at most one pixel off.
     19
     20        In summary, the values are computed as follows:
     21                x: round(x)
     22                y: round(y)
     23                maxX: round(x + width)
     24                maxY: round(y + height)
     25                width: round(x + width) - round(x)
     26                height: round(y + height) - round(y)
     27
     28        We use the term pixel snapped to indicate that the numbers are not merely
     29        rounded. This also matches the naming used by the line box tree.
     30
     31        No new tests, no functionality changes.
     32
     33        * page/PrintContext.cpp:
     34        (WebCore::PrintContext::pageNumberForElement):
     35        * rendering/RenderBlock.cpp:
     36        (WebCore::::collectIfNeeded):
     37        * rendering/RenderBlock.h:
     38        (RenderBlock):
     39        (WebCore::RenderBlock::pixelSnappedLogicalRightOffsetForLine):
     40        (WebCore::RenderBlock::pixelSnappedLogicalLeftOffsetForLine):
     41        (WebCore::RenderBlock::FloatingObject::pixelSnappedX):
     42        (WebCore::RenderBlock::FloatingObject::pixelSnappedMaxX):
     43        (WebCore::RenderBlock::FloatingObject::pixelSnappedY):
     44        (WebCore::RenderBlock::FloatingObject::pixelSnappedMaxY):
     45        (WebCore::RenderBlock::FloatingObject::pixelSnappedWidth):
     46        (WebCore::RenderBlock::FloatingObject::pixelSnappedHeight):
     47        (FloatingObject):
     48        (WebCore::RenderBlock::pixelSnappedLogicalTopForFloat):
     49        (WebCore::RenderBlock::pixelSnappedLogicalBottomForFloat):
     50        (WebCore::RenderBlock::pixelSnappedLogicalLeftForFloat):
     51        (WebCore::RenderBlock::pixelSnappedLogicalRightForFloat):
     52        * rendering/RenderBlockLineLayout.cpp:
     53        (WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded):
     54        * rendering/RenderBox.cpp:
     55        (WebCore::RenderBox::pixelSnappedClientWidth):
     56        (WebCore):
     57        (WebCore::RenderBox::pixelSnappedClientHeight):
     58        (WebCore::RenderBox::scrollHeight):
     59        * rendering/RenderBox.h:
     60        (WebCore::RenderBox::pixelSnappedWidth):
     61        (WebCore::RenderBox::pixelSnappedHeight):
     62        (RenderBox):
     63        (WebCore::RenderBox::pixelSnappedOffsetWidth):
     64        (WebCore::RenderBox::pixelSnappedOffsetHeight):
     65        (WebCore::RenderBox::clientLogicalWidth):
     66        (WebCore::RenderBox::clientLogicalHeight):
     67        * rendering/RenderBoxModelObject.cpp:
     68        (WebCore::RenderBoxModelObject::pixelSnappedOffsetWidth):
     69        (WebCore):
     70        (WebCore::RenderBoxModelObject::pixelSnappedOffsetHeight):
     71        * rendering/RenderBoxModelObject.h:
     72        (WebCore::RenderBoxModelObject::pixelSnappedOffsetLeft):
     73        (WebCore::RenderBoxModelObject::pixelSnappedOffsetTop):
     74        (RenderBoxModelObject):
     75        * rendering/RenderLayer.cpp:
     76        (WebCore::RenderLayer::pixelSnappedScrollWidth):
     77        (WebCore):
     78        (WebCore::RenderLayer::pixelSnappedScrollHeight):
     79        (WebCore::RenderLayer::computeScrollDimensions):
     80        (WebCore::RenderLayer::updateScrollInfoAfterLayout):
     81        * rendering/RenderLayer.h:
     82        (RenderLayer):
     83        * rendering/RenderListBox.cpp:
     84        (WebCore::RenderListBox::scrollHeight):
     85        * rendering/RenderTheme.cpp:
     86        (WebCore::RenderTheme::volumeSliderOffsetFromMuteButton):
     87        * rendering/RenderTreeAsText.cpp:
     88        (WebCore::write):
     89
    1902012-02-07  Mike Lawther  <mikelawther@chromium.org>
    291
  • trunk/Source/WebCore/page/PrintContext.cpp

    r95901 r107032  
    250250    printContext.computePageRectsWithPageSize(scaledPageSize, false);
    251251
    252     int top = box->offsetTop();
    253     int left = box->offsetLeft();
     252    int top = box->pixelSnappedOffsetTop();
     253    int left = box->pixelSnappedOffsetLeft();
    254254    size_t pageNumber = 0;
    255255    for (; pageNumber < printContext.pageCount(); pageNumber++) {
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r106744 r107032  
    36743674    if (r->type() == FloatTypeValue && interval.low() <= m_value && m_value < interval.high()) {
    36753675        // All the objects returned from the tree should be already placed.
    3676         ASSERT(r->isPlaced() && m_renderer->logicalTopForFloat(r) <= m_value && m_renderer->logicalBottomForFloat(r) > m_value);
     3676        ASSERT(r->isPlaced() && m_renderer->pixelSnappedLogicalTopForFloat(r) <= m_value && m_renderer->pixelSnappedLogicalBottomForFloat(r) > m_value);
    36773677
    36783678        if (FloatTypeValue == FloatingObject::FloatLeft
  • trunk/Source/WebCore/rendering/RenderBlock.h

    r106694 r107032  
    164164            : logicalWidth() - logicalRightOffsetForLine(position, firstLine);
    165165    }
     166
     167    // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
     168    int pixelSnappedLogicalRightOffsetForLine(LayoutUnit position, bool firstLine) const
     169    {
     170        return logicalRightOffsetForLine(position, logicalRightOffsetForContent(position), firstLine, 0);
     171    }
     172
     173    int pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool firstLine) const
     174    {
     175        return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0);
     176    }
    166177   
    167178    LayoutUnit startAlignedOffsetForLine(RenderBox* child, LayoutUnit position, bool firstLine);
     
    562573        LayoutUnit height() const { return m_frameRect.height(); }
    563574
     575        // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
     576        int pixelSnappedX() const { return x(); }
     577        int pixelSnappedMaxX() const { return maxX(); }
     578        int pixelSnappedY() const { return y(); }
     579        int pixelSnappedMaxY() const { return maxY(); }
     580        int pixelSnappedWidth() const { return width(); }
     581        int pixelSnappedHeight() const { return height(); }
     582
    564583        void setX(LayoutUnit x) { ASSERT(!isInPlacedTree()); m_frameRect.setX(x); }
    565584        void setY(LayoutUnit y) { ASSERT(!isInPlacedTree()); m_frameRect.setY(y); }
     
    595614    LayoutUnit logicalRightForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->maxX() : child->maxY(); }
    596615    LayoutUnit logicalWidthForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->width() : child->height(); }
     616
     617    // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
     618    int pixelSnappedLogicalTopForFloat(const FloatingObject* child) const { return logicalTopForFloat(child); }
     619    int pixelSnappedLogicalBottomForFloat(const FloatingObject* child) const { return logicalBottomForFloat(child); }
     620    int pixelSnappedLogicalLeftForFloat(const FloatingObject* child) const { return logicalLeftForFloat(child); }
     621    int pixelSnappedLogicalRightForFloat(const FloatingObject* child) const { return logicalRightForFloat(child); }
    597622
    598623    void setLogicalTopForFloat(FloatingObject* child, LayoutUnit logicalTop)
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r107000 r107032  
    129129
    130130    if (newFloat->type() == RenderBlock::FloatingObject::FloatLeft) {
    131         m_left = m_block->logicalRightForFloat(newFloat);
     131        m_left = m_block->pixelSnappedLogicalRightForFloat(newFloat);
    132132        if (m_isFirstLine && m_block->style()->isLeftToRightDirection())
    133133            m_left += m_block->textIndentOffset();
    134134    } else {
    135         m_right = m_block->logicalLeftForFloat(newFloat);
     135        m_right = m_block->pixelSnappedLogicalLeftForFloat(newFloat);
    136136        if (m_isFirstLine && !m_block->style()->isLeftToRightDirection())
    137137            m_right -= m_block->textIndentOffset();
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r106510 r107032  
    479479}
    480480
     481int RenderBox::pixelSnappedClientWidth() const
     482{
     483    return clientWidth();
     484}
     485
     486int RenderBox::pixelSnappedClientHeight() const
     487{
     488    return clientHeight();
     489}
     490
    481491int RenderBox::scrollWidth() const
    482492{
     
    496506    // For objects with visible overflow, this matches IE.
    497507    // FIXME: Need to work right with writing modes.
    498     return max(clientHeight(), maxYLayoutOverflow() - borderTop());
     508    return max(pixelSnappedClientHeight(), maxYLayoutOverflow() - borderTop());
    499509}
    500510
  • trunk/Source/WebCore/rendering/RenderBox.h

    r106146 r107032  
    5252    LayoutUnit height() const { return m_frameRect.height(); }
    5353
     54    // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
     55    int pixelSnappedWidth() const { return m_frameRect.width(); }
     56    int pixelSnappedHeight() const { return m_frameRect.height(); }
     57
    5458    // These represent your location relative to your container as a physical offset.
    5559    // In layout related methods you almost always want the logical location (e.g. x() and y()).
     
    184188    virtual LayoutUnit offsetHeight() const { return height(); }
    185189
     190    // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
     191    virtual int pixelSnappedOffsetWidth() const { return pixelSnappedWidth(); }
     192    virtual int pixelSnappedOffsetHeight() const { return pixelSnappedHeight(); }
     193
    186194    // More IE extensions.  clientWidth and clientHeight represent the interior of an object
    187195    // excluding border and scrollbar.  clientLeft/Top are just the borderLeftWidth and borderTopWidth.
     
    190198    LayoutUnit clientWidth() const;
    191199    LayoutUnit clientHeight() const;
    192     LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
    193     LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
     200    LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedClientWidth() : pixelSnappedClientHeight(); }
     201    LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedClientHeight() : pixelSnappedClientWidth(); }
    194202    LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
    195203    LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
     204
     205    int pixelSnappedClientWidth() const;
     206    int pixelSnappedClientHeight() const;
    196207
    197208    // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r105515 r107032  
    511511    }
    512512    return yPos;
     513}
     514
     515int RenderBoxModelObject::pixelSnappedOffsetWidth() const
     516{
     517    return offsetWidth();
     518}
     519
     520int RenderBoxModelObject::pixelSnappedOffsetHeight() const
     521{
     522    return offsetHeight();
    513523}
    514524
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.h

    r104123 r107032  
    6060    virtual LayoutUnit offsetWidth() const = 0;
    6161    virtual LayoutUnit offsetHeight() const = 0;
     62
     63    // 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(); }
     66    int pixelSnappedOffsetWidth() const;
     67    int pixelSnappedOffsetHeight() const;
    6268
    6369    virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r107001 r107032  
    22272227}
    22282228
     2229int RenderLayer::pixelSnappedScrollWidth()
     2230{
     2231    return scrollWidth();
     2232}
     2233
     2234int RenderLayer::pixelSnappedScrollHeight()
     2235{
     2236    return scrollHeight();
     2237}
     2238
    22292239LayoutUnit RenderLayer::overflowTop() const
    22302240{
     
    22752285
    22762286    if (needHBar)
    2277         *needHBar = m_scrollSize.width() > box->clientWidth();
     2287        *needHBar = pixelSnappedScrollWidth() > box->pixelSnappedClientWidth();
    22782288    if (needVBar)
    2279         *needVBar = m_scrollSize.height() > box->clientHeight();
     2289        *needVBar = pixelSnappedScrollHeight() > box->pixelSnappedClientHeight();
    22802290}
    22812291
     
    23822392    // Set up the range (and page step/line step).
    23832393    if (m_hBar) {
    2384         LayoutUnit clientWidth = box->clientWidth();
    2385         LayoutUnit pageStep = max<LayoutUnit>(max<LayoutUnit>(clientWidth * Scrollbar::minFractionToStepWhenPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1);
     2394        int clientWidth = box->pixelSnappedClientWidth();
     2395        int pageStep = max(max<int>(clientWidth * Scrollbar::minFractionToStepWhenPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1);
    23862396        m_hBar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep);
    23872397        m_hBar->setProportion(clientWidth, m_scrollSize.width());
    23882398    }
    23892399    if (m_vBar) {
    2390         LayoutUnit clientHeight = box->clientHeight();
    2391         LayoutUnit pageStep = max<LayoutUnit>(max<LayoutUnit>(clientHeight * Scrollbar::minFractionToStepWhenPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1);
     2400        int clientHeight = box->pixelSnappedClientHeight();
     2401        int pageStep = max(max<int>(clientHeight * Scrollbar::minFractionToStepWhenPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1);
    23922402        m_vBar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep);
    23932403        m_vBar->setProportion(clientHeight, m_scrollSize.height());
  • trunk/Source/WebCore/rendering/RenderLayer.h

    r107001 r107032  
    283283    LayoutUnit scrollWidth();
    284284    LayoutUnit scrollHeight();
     285    int pixelSnappedScrollWidth();
     286    int pixelSnappedScrollHeight();
    285287
    286288    void panScrollFromPoint(const LayoutPoint&);
  • trunk/Source/WebCore/rendering/RenderListBox.cpp

    r107001 r107032  
    652652int RenderListBox::scrollHeight() const
    653653{
    654     return max(clientHeight(), listHeight());
     654    return max(pixelSnappedClientHeight(), listHeight());
    655655}
    656656
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r106734 r107032  
    504504{
    505505    LayoutUnit y = -size.height();
    506     FloatPoint absPoint = muteButtonBox->localToAbsolute(FloatPoint(muteButtonBox->offsetLeft(), y), true, true);
     506    FloatPoint absPoint = muteButtonBox->localToAbsolute(FloatPoint(muteButtonBox->pixelSnappedOffsetLeft(), y), true, true);
    507507    if (absPoint.y() < 0)
    508508        y = muteButtonBox->height();
  • trunk/Source/WebCore/rendering/RenderTreeAsText.cpp

    r106695 r107032  
    618618        if (l.scrollYOffset())
    619619            ts << " scrollY " << l.scrollYOffset();
    620         if (l.renderBox() && l.renderBox()->clientWidth() != l.scrollWidth())
    621             ts << " scrollWidth " << l.scrollWidth();
    622         if (l.renderBox() && l.renderBox()->clientHeight() != l.scrollHeight())
    623             ts << " scrollHeight " << l.scrollHeight();
     620        if (l.renderBox() && l.renderBox()->pixelSnappedClientWidth() != l.pixelSnappedScrollWidth())
     621            ts << " scrollWidth " << l.pixelSnappedScrollWidth();
     622        if (l.renderBox() && l.renderBox()->pixelSnappedClientHeight() != l.pixelSnappedScrollHeight())
     623            ts << " scrollHeight " << l.pixelSnappedScrollHeight();
    624624    }
    625625
Note: See TracChangeset for help on using the changeset viewer.