Subpixel rendering: Inline text selection painting should not snap to integral CSS...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2014 13:31:46 +0000 (13:31 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2014 13:31:46 +0000 (13:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132164

Reviewed by Darin Adler.

Inline text selection painting now snaps to device pixels. It uses the same rounding logic as
other painting functions.

Source/WebCore:
Test: fast/inline/hidpi-select-inline-on-subpixel-position.html

* rendering/EllipsisBox.cpp:
(WebCore::EllipsisBox::paintSelection):
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::paintSelection):
(WebCore::alignSelectionRectToDevicePixels): Deleted.
* rendering/InlineTextBox.h:

LayoutTests:
* fast/inline/hidpi-select-inline-on-subpixel-position-expected.html: Added.
* fast/inline/hidpi-select-inline-on-subpixel-position.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168095 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/inline/hidpi-select-inline-on-subpixel-position-expected.html [new file with mode: 0644]
LayoutTests/fast/inline/hidpi-select-inline-on-subpixel-position.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/EllipsisBox.cpp
Source/WebCore/rendering/InlineTextBox.cpp
Source/WebCore/rendering/InlineTextBox.h

index 3f7679f..63b3d1b 100644 (file)
@@ -1,3 +1,16 @@
+2014-05-01  Zalan Bujtas  <zalan@apple.com>
+
+        Subpixel rendering: Inline text selection painting should not snap to integral CSS pixel position.
+        https://bugs.webkit.org/show_bug.cgi?id=132164
+
+        Reviewed by Darin Adler.
+
+        Inline text selection painting now snaps to device pixels. It uses the same rounding logic as
+        other painting functions.
+
+        * fast/inline/hidpi-select-inline-on-subpixel-position-expected.html: Added.
+        * fast/inline/hidpi-select-inline-on-subpixel-position.html: Added.
+
 2014-05-01  Rik Cabanier  <cabanier@adobe.com>
 
         Calling createPattern with a broken image must throw an invalidstate error
diff --git a/LayoutTests/fast/inline/hidpi-select-inline-on-subpixel-position-expected.html b/LayoutTests/fast/inline/hidpi-select-inline-on-subpixel-position-expected.html
new file mode 100644 (file)
index 0000000..941455a
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that inline text selection can paint to subpixel position.</title>
+<style>
+  div {
+    font-size: 16px;
+    width: 21px;
+    height: 18px;
+    position: fixed;
+    background: rgba(255, 0, 0, 0.9);
+  }
+</style>
+</head>
+<body>
+<p id="container"></p>
+<script>
+  var container = document.getElementById("container");
+  adjustment = 0.1;
+  for (i = 0; i < 10; ++i) {
+    adjustment+=0.1;
+    for (j = 0; j < 10; ++j) {
+      var e = document.createElement("div");
+      e.style.top = (30 * i + j * adjustment) + "px";
+      e.style.left = (30 * j + i * adjustment) + "px";
+      e.innerHTML = "foo";
+      container.appendChild(e);
+    }
+  }  
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/inline/hidpi-select-inline-on-subpixel-position.html b/LayoutTests/fast/inline/hidpi-select-inline-on-subpixel-position.html
new file mode 100644 (file)
index 0000000..f497cc8
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that inline text selection can paint to subpixel position.</title>
+<style>
+  ::selection {
+    background: rgba(255, 0, 0, 0.9);
+  }
+
+  div {
+    font-size: 16px;
+    height: 10px;
+    width: 1px;
+    height: 1px;
+    position: fixed;
+  }
+
+</style>
+</head>
+<body>
+<p id="container"></p>
+<script>
+  var container = document.getElementById("container");
+  adjustment = 0.1;
+  for (i = 0; i < 10; ++i) {
+    adjustment+=0.1;
+    for (j = 0; j < 10; ++j) {
+      var e = document.createElement("div");
+      e.style.top = (30 * i + j * adjustment) + "px";
+      e.style.left = (30 * j + i * adjustment) + "px";
+      e.innerHTML = "foo";
+      container.appendChild(e);
+    }
+  }
+  
+  var range = document.createRange(); 
+  range.selectNode(document.getElementById("container")); 
+  window.getSelection().addRange(range);
+</script>
+</body>
+</html>
index 6ee14e7..0a1d5d9 100644 (file)
@@ -1,3 +1,22 @@
+2014-05-01  Zalan Bujtas  <zalan@apple.com>
+
+        Subpixel rendering: Inline text selection painting should not snap to integral CSS pixel position.
+        https://bugs.webkit.org/show_bug.cgi?id=132164
+
+        Reviewed by Darin Adler.
+
+        Inline text selection painting now snaps to device pixels. It uses the same rounding logic as
+        other painting functions.
+
+        Test: fast/inline/hidpi-select-inline-on-subpixel-position.html
+
+        * rendering/EllipsisBox.cpp:
+        (WebCore::EllipsisBox::paintSelection):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::paintSelection):
+        (WebCore::alignSelectionRectToDevicePixels): Deleted.
+        * rendering/InlineTextBox.h:
+
 2014-05-01  Ryuan Choi  <ryuan.choi@samsung.com>
 
         [EFL] There are many warnings with software backend
index 623aeb0..80a2119 100644 (file)
@@ -131,13 +131,13 @@ void EllipsisBox::paintSelection(GraphicsContext* context, const LayoutPoint& pa
     const RootInlineBox& rootBox = root();
     LayoutUnit top = rootBox.selectionTop();
     LayoutUnit h = rootBox.selectionHeight();
-    FloatRect clipRect(x() + paintOffset.x(), top + paintOffset.y(), m_logicalWidth, h);
-    alignSelectionRectToDevicePixels(clipRect);
 
     GraphicsContextStateSaver stateSaver(*context);
-    context->clip(clipRect);
+    float deviceScaleFactor = renderer().document().deviceScaleFactor();
+    context->clip(pixelSnappedForPainting(x() + paintOffset.x(), top + paintOffset.y(), m_logicalWidth, h, renderer().document().deviceScaleFactor()));
     // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
-    context->drawHighlightForText(font, RenderBlock::constructTextRun(&blockFlow(), font, m_str, style, TextRun::AllowTrailingExpansion), roundedIntPoint(LayoutPoint(x() + paintOffset.x(), y() + paintOffset.y() + top)), h, c, style.colorSpace());
+    FloatPoint localOrigin = roundedForPainting(LayoutPoint(x() + paintOffset.x(), y() + paintOffset.y() + top), deviceScaleFactor);
+    context->drawHighlightForText(font, RenderBlock::constructTextRun(&blockFlow(), font, m_str, style, TextRun::AllowTrailingExpansion), localOrigin, h, c, style.colorSpace());
 }
 
 bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
index aff8756..b328434 100644 (file)
@@ -712,13 +712,6 @@ void InlineTextBox::selectionStartEnd(int& sPos, int& ePos)
     ePos = std::min(endPos - m_start, (int)m_len);
 }
 
-void alignSelectionRectToDevicePixels(FloatRect& rect)
-{
-    float maxX = floorf(rect.maxX());
-    rect.setX(floorf(rect.x()));
-    rect.setWidth(roundf(maxX - rect.x()));
-}
-
 void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& boxOrigin, const RenderStyle& style, const Font& font, Color textColor)
 {
 #if ENABLE(TEXT_SELECTION)
@@ -763,16 +756,13 @@ void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& b
     LayoutUnit selectionBottom = rootBox.selectionBottom();
     LayoutUnit selectionTop = rootBox.selectionTopAdjustedForPrecedingBlock();
 
-    int deltaY = roundToInt(renderer().style().isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop);
-    int selHeight = std::max(0, roundToInt(selectionBottom - selectionTop));
-
-    FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
-    FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight));
-    alignSelectionRectToDevicePixels(clipRect);
-
-    context->clip(clipRect);
+    LayoutUnit deltaY = renderer().style().isFlippedLinesWritingMode() ? selectionBottom - logicalBottom() : logicalTop() - selectionTop;
+    LayoutUnit selectionHeight = std::max<LayoutUnit>(0, selectionBottom - selectionTop);
 
-    context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, style.colorSpace(), sPos, ePos);
+    float deviceScaleFactor = renderer().document().deviceScaleFactor();
+    FloatPoint localOrigin = roundedForPainting(LayoutPoint(boxOrigin.x(), boxOrigin.y() - deltaY), deviceScaleFactor);
+    context->clip(pixelSnappedForPainting(LayoutRect(LayoutPoint(localOrigin), LayoutSize(m_logicalWidth, selectionHeight)), deviceScaleFactor));
+    context->drawHighlightForText(font, textRun, localOrigin, selectionHeight, c, style.colorSpace(), sPos, ePos);
 #else
     UNUSED_PARAM(context);
     UNUSED_PARAM(boxOrigin);
index 405a9be..c42b54e 100644 (file)
@@ -197,8 +197,6 @@ private:
 
 INLINE_BOX_OBJECT_TYPE_CASTS(InlineTextBox, isInlineTextBox())
 
-void alignSelectionRectToDevicePixels(FloatRect&);
-
 } // namespace WebCore
 
 #endif // InlineTextBox_h