Changeset 117491 in webkit


Ignore:
Timestamp:
May 17, 2012 1:57:38 PM (12 years ago)
Author:
eae@chromium.org
Message:

Fix rounding in paintSelection
https://bugs.webkit.org/show_bug.cgi?id=86693

Reviewed by Eric Seidel.

Break out rounding logic from InlineTextBox::paintSelection into separate
function and use it for all the EllipsisBox paintSelection implementation
and selection gap calculation. This ensures that selections are painted
without gaps and overlaps once we turn on subpixel layout.

No new tests, covered by existing tests in editing/selection and
editing/style.

  • rendering/EllipsisBox.cpp:

(WebCore::EllipsisBox::paintSelection):

  • rendering/InlineTextBox.cpp:

(WebCore::alignSelectionRectToDevicePixels):
(WebCore):
(WebCore::InlineTextBox::paintSelection):

  • rendering/InlineTextBox.h:

(WebCore):

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::logicalLeftSelectionGap):
(WebCore::RenderBlock::logicalRightSelectionGap):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117485 r117491  
     12012-05-17  Emil A Eklund  <eae@chromium.org>
     2
     3        Fix rounding in paintSelection
     4        https://bugs.webkit.org/show_bug.cgi?id=86693
     5
     6        Reviewed by Eric Seidel.
     7
     8        Break out rounding logic from InlineTextBox::paintSelection into separate
     9        function and use it for all the EllipsisBox paintSelection implementation
     10        and selection gap calculation. This ensures that selections are painted
     11        without gaps and overlaps once we turn on subpixel layout.
     12
     13        No new tests, covered by existing tests in editing/selection and
     14        editing/style.
     15
     16        * rendering/EllipsisBox.cpp:
     17        (WebCore::EllipsisBox::paintSelection):
     18        * rendering/InlineTextBox.cpp:
     19        (WebCore::alignSelectionRectToDevicePixels):
     20        (WebCore):
     21        (WebCore::InlineTextBox::paintSelection):
     22        * rendering/InlineTextBox.h:
     23        (WebCore):
     24        * rendering/RenderBlock.cpp:
     25        (WebCore::RenderBlock::logicalLeftSelectionGap):
     26        (WebCore::RenderBlock::logicalRightSelectionGap):
     27
    1282012-05-17  Michal Mocny  <mmocny@google.com>
    229
  • trunk/Source/WebCore/rendering/EllipsisBox.cpp

    r114784 r117491  
    2424#include "GraphicsContext.h"
    2525#include "HitTestResult.h"
     26#include "InlineTextBox.h"
    2627#include "PaintInfo.h"
    2728#include "RenderBlock.h"
     
    9798    LayoutUnit top = root()->selectionTop();
    9899    LayoutUnit h = root()->selectionHeight();
    99     // FIXME: We'll need to apply the correct clip rounding here: https://bugs.webkit.org/show_bug.cgi?id=63656
    100     context->clip(IntRect(x() + paintOffset.x(), top + paintOffset.y(), m_logicalWidth, h));
     100    LayoutRect clipRect(x() + paintOffset.x(), top + paintOffset.y(), m_logicalWidth, h);
     101    alignSelectionRectToDevicePixels(clipRect);
     102    context->clip(clipRect);
    101103    // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
    102     context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x() + paintOffset.x(), y() + paintOffset.y() + top), h, c, style->colorSpace());
     104    context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), roundedIntPoint(LayoutPoint(x() + paintOffset.x(), y() + paintOffset.y() + top)), h, c, style->colorSpace());
    103105}
    104106
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r116723 r117491  
    808808}
    809809
     810void alignSelectionRectToDevicePixels(LayoutRect& rect)
     811{
     812    LayoutUnit maxX = floorToInt(rect.maxX());
     813    rect.setX(floorToInt(rect.x()));
     814    rect.setWidth(maxX - rect.x());
     815}
     816
     817#if !ENABLE(SUBPIXEL_LAYOUT)
     818void alignSelectionRectToDevicePixels(FloatRect& rect)
     819{
     820    float maxX = floorf(rect.maxX());
     821    rect.setX(floorf(rect.x()));
     822    rect.setWidth(roundf(maxX - rect.x()));
     823}
     824#endif
     825
    810826void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color textColor)
    811827{
     
    845861    LayoutUnit selectionTop = root()->selectionTopAdjustedForPrecedingBlock();
    846862
    847     int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop;
    848     int selHeight = max<LayoutUnit>(0, selectionBottom - selectionTop);
    849 
     863    LayoutUnit deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop;
     864    LayoutUnit selHeight = max<LayoutUnit>(0, selectionBottom - selectionTop);
     865
     866#if ENABLE(SUBPIXEL_LAYOUT)
     867    LayoutPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
     868    LayoutRect clipRect(localOrigin, LayoutSize(m_logicalWidth, selHeight));
     869    alignSelectionRectToDevicePixels(clipRect);
     870#else
    850871    FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
    851 
    852872    FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight));
    853     float maxX = floorf(clipRect.maxX());
    854     clipRect.setX(floorf(clipRect.x()));
    855     clipRect.setWidth(maxX - clipRect.x());
     873    alignSelectionRectToDevicePixels(clipRect);
     874#endif
    856875    context->clip(clipRect);
    857876
  • trunk/Source/WebCore/rendering/InlineTextBox.h

    r116353 r117491  
    214214}
    215215
     216void alignSelectionRectToDevicePixels(LayoutRect&);
     217#if !ENABLE(SUBPIXEL_LAYOUT)
     218void alignSelectionRectToDevicePixels(FloatRect&);
     219#endif
     220
    216221} // namespace WebCore
    217222
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r117484 r117491  
    33583358
    33593359    LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, LayoutRect(rootBlockLogicalLeft, rootBlockLogicalTop, rootBlockLogicalWidth, logicalHeight));
     3360    alignSelectionRectToDevicePixels(gapRect);
    33603361    if (paintInfo)
    33613362        paintInfo->context->fillRect(gapRect, selObj->selectionBackgroundColor(), selObj->style()->colorSpace());
     
    33743375
    33753376    LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, LayoutRect(rootBlockLogicalLeft, rootBlockLogicalTop, rootBlockLogicalWidth, logicalHeight));
     3377    alignSelectionRectToDevicePixels(gapRect);
    33763378    if (paintInfo)
    33773379        paintInfo->context->fillRect(gapRect, selObj->selectionBackgroundColor(), selObj->style()->colorSpace());
Note: See TracChangeset for help on using the changeset viewer.