Title: [117491] trunk/Source/WebCore
Revision
117491
Author
e...@chromium.org
Date
2012-05-17 13:57:38 -0700 (Thu, 17 May 2012)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (117490 => 117491)


--- trunk/Source/WebCore/ChangeLog	2012-05-17 20:55:31 UTC (rev 117490)
+++ trunk/Source/WebCore/ChangeLog	2012-05-17 20:57:38 UTC (rev 117491)
@@ -1,3 +1,30 @@
+2012-05-17  Emil A Eklund  <e...@chromium.org>
+
+        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):
+
 2012-05-17  Michal Mocny  <mmo...@google.com>
 
         [chromium] Limiting render surface texture manager memory to 0 when contentsMemoryUseBytes is large.

Modified: trunk/Source/WebCore/rendering/EllipsisBox.cpp (117490 => 117491)


--- trunk/Source/WebCore/rendering/EllipsisBox.cpp	2012-05-17 20:55:31 UTC (rev 117490)
+++ trunk/Source/WebCore/rendering/EllipsisBox.cpp	2012-05-17 20:57:38 UTC (rev 117491)
@@ -23,6 +23,7 @@
 #include "Document.h"
 #include "GraphicsContext.h"
 #include "HitTestResult.h"
+#include "InlineTextBox.h"
 #include "PaintInfo.h"
 #include "RenderBlock.h"
 #include "RootInlineBox.h"
@@ -96,10 +97,11 @@
     GraphicsContextStateSaver stateSaver(*context);
     LayoutUnit top = root()->selectionTop();
     LayoutUnit h = root()->selectionHeight();
-    // FIXME: We'll need to apply the correct clip rounding here: https://bugs.webkit.org/show_bug.cgi?id=63656
-    context->clip(IntRect(x() + paintOffset.x(), top + paintOffset.y(), m_logicalWidth, h));
+    LayoutRect clipRect(x() + paintOffset.x(), top + paintOffset.y(), m_logicalWidth, h);
+    alignSelectionRectToDevicePixels(clipRect);
+    context->clip(clipRect);
     // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
-    context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x() + paintOffset.x(), y() + paintOffset.y() + top), h, c, style->colorSpace());
+    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());
 }
 
 bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom)

Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (117490 => 117491)


--- trunk/Source/WebCore/rendering/InlineTextBox.cpp	2012-05-17 20:55:31 UTC (rev 117490)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp	2012-05-17 20:57:38 UTC (rev 117491)
@@ -807,6 +807,22 @@
     ePos = min(endPos - m_start, (int)m_len);
 }
 
+void alignSelectionRectToDevicePixels(LayoutRect& rect)
+{
+    LayoutUnit maxX = floorToInt(rect.maxX());
+    rect.setX(floorToInt(rect.x()));
+    rect.setWidth(maxX - rect.x());
+}
+
+#if !ENABLE(SUBPIXEL_LAYOUT)
+void alignSelectionRectToDevicePixels(FloatRect& rect)
+{
+    float maxX = floorf(rect.maxX());
+    rect.setX(floorf(rect.x()));
+    rect.setWidth(roundf(maxX - rect.x()));
+}
+#endif
+
 void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color textColor)
 {
     if (context->paintingDisabled())
@@ -844,15 +860,18 @@
     LayoutUnit selectionBottom = root()->selectionBottom();
     LayoutUnit selectionTop = root()->selectionTopAdjustedForPrecedingBlock();
 
-    int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop;
-    int selHeight = max<LayoutUnit>(0, selectionBottom - selectionTop);
+    LayoutUnit deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop;
+    LayoutUnit selHeight = max<LayoutUnit>(0, selectionBottom - selectionTop);
 
+#if ENABLE(SUBPIXEL_LAYOUT)
+    LayoutPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
+    LayoutRect clipRect(localOrigin, LayoutSize(m_logicalWidth, selHeight));
+    alignSelectionRectToDevicePixels(clipRect);
+#else
     FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
-
     FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight));
-    float maxX = floorf(clipRect.maxX());
-    clipRect.setX(floorf(clipRect.x()));
-    clipRect.setWidth(maxX - clipRect.x());
+    alignSelectionRectToDevicePixels(clipRect);
+#endif
     context->clip(clipRect);
 
     context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, style->colorSpace(), sPos, ePos);

Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (117490 => 117491)


--- trunk/Source/WebCore/rendering/InlineTextBox.h	2012-05-17 20:55:31 UTC (rev 117490)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h	2012-05-17 20:57:38 UTC (rev 117491)
@@ -213,6 +213,11 @@
     return toRenderText(renderer());
 }
 
+void alignSelectionRectToDevicePixels(LayoutRect&);
+#if !ENABLE(SUBPIXEL_LAYOUT)
+void alignSelectionRectToDevicePixels(FloatRect&);
+#endif
+
 } // namespace WebCore
 
 #endif // InlineTextBox_h

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (117490 => 117491)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2012-05-17 20:55:31 UTC (rev 117490)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2012-05-17 20:57:38 UTC (rev 117491)
@@ -3357,6 +3357,7 @@
         return LayoutRect();
 
     LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, LayoutRect(rootBlockLogicalLeft, rootBlockLogicalTop, rootBlockLogicalWidth, logicalHeight));
+    alignSelectionRectToDevicePixels(gapRect);
     if (paintInfo)
         paintInfo->context->fillRect(gapRect, selObj->selectionBackgroundColor(), selObj->style()->colorSpace());
     return gapRect;
@@ -3373,6 +3374,7 @@
         return LayoutRect();
 
     LayoutRect gapRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, LayoutRect(rootBlockLogicalLeft, rootBlockLogicalTop, rootBlockLogicalWidth, logicalHeight));
+    alignSelectionRectToDevicePixels(gapRect);
     if (paintInfo)
         paintInfo->context->fillRect(gapRect, selObj->selectionBackgroundColor(), selObj->style()->colorSpace());
     return gapRect;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to