Subpixel rendering: Make selection gaps painting subpixel aware.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2014 18:49:37 +0000 (18:49 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2014 18:49:37 +0000 (18:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132169

Reviewed by Simon Fraser.

Push selection gaps painting to device pixel boundaries instead of integral CSS pixel positions.

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

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::blockSelectionGap):
(WebCore::RenderBlock::logicalLeftSelectionGap):
(WebCore::RenderBlock::logicalRightSelectionGap):

LayoutTests:
* fast/inline/hidpi-selection-gap-on-subpixel-position-expected.html: Added.
* fast/inline/hidpi-selection-gap-on-subpixel-position.html: Added. : &nbsp is needed to make
this test pass on WK2. Font rendering reports differences. 0.9 transparency is added so that
text selection code does modify the color's alpha channel and I can properly match it.

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

LayoutTests/ChangeLog
LayoutTests/fast/inline/hidpi-selection-gap-on-subpixel-position-expected.html [new file with mode: 0644]
LayoutTests/fast/inline/hidpi-selection-gap-on-subpixel-position.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlock.cpp

index 76d0e63..e659baa 100644 (file)
@@ -1,3 +1,17 @@
+2014-05-01  Zalan Bujtas  <zalan@apple.com>
+
+        Subpixel rendering: Make selection gaps painting subpixel aware.
+        https://bugs.webkit.org/show_bug.cgi?id=132169
+
+        Reviewed by Simon Fraser.
+
+        Push selection gaps painting to device pixel boundaries instead of integral CSS pixel positions.
+
+        * fast/inline/hidpi-selection-gap-on-subpixel-position-expected.html: Added.
+        * fast/inline/hidpi-selection-gap-on-subpixel-position.html: Added. : &nbsp is needed to make
+        this test pass on WK2. Font rendering reports differences. 0.9 transparency is added so that
+        text selection code does modify the color's alpha channel and I can properly match it.
+
 2014-05-01  Javier Fernandez  <jfernandez@igalia.com>
 
         [CSS Grid Layout] Clamping the number of repetitions in repeat()
diff --git a/LayoutTests/fast/inline/hidpi-selection-gap-on-subpixel-position-expected.html b/LayoutTests/fast/inline/hidpi-selection-gap-on-subpixel-position-expected.html
new file mode 100644 (file)
index 0000000..d912514
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that selection gaps can be painted on subpixel position.</title>
+<style>
+  div {
+    font-size: 16px;
+    height: 20px;
+  }
+
+  .bckg {
+    position: fixed;
+    background: rgba(255, 0, 0, 0.9);
+    z-index: -1000;
+  }
+</style>
+</head>
+<body>
+<p id="container"></p>
+<div class=bckg style="left: 8px; top: 16px; width: 784px; height: 475px;"></div> 
+<div class=bckg style="left: 8px; top: 491px; width: 15.5px; height: 26px;"></div> 
+<script>
+  var container = document.getElementById("container");
+  fontSize = 16;
+  margin = 0;
+  for (i = 0; i < 20; ++i) {
+    var e = document.createElement("div");
+    e.innerHTML = "&nbsp";
+    e.style.fontSize = fontSize + "px";
+    e.style.margin = margin+ "px";
+    container.appendChild(e);
+    fontSize+=0.3;
+    margin+=0.5;
+  }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/inline/hidpi-selection-gap-on-subpixel-position.html b/LayoutTests/fast/inline/hidpi-selection-gap-on-subpixel-position.html
new file mode 100644 (file)
index 0000000..5eb8751
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that selection gaps can be painted on subpixel position.</title>
+<style>
+  ::selection {
+    background: rgba(255, 0, 0, 0.9);
+  }
+
+  div {
+    font-size: 16px;
+    height: 20px;
+  }
+
+</style>
+</head>
+<body>
+<p id="container"></p>
+<script>
+  var container = document.getElementById("container");
+  fontSize = 16;
+  margin = 0;
+  for (i = 0; i < 20; ++i) {
+    var e = document.createElement("div");
+    e.innerHTML = "&nbsp";
+    e.style.fontSize = fontSize + "px";
+    e.style.margin = margin + "px";
+    container.appendChild(e);
+    fontSize+=0.3;
+    margin+=0.5;
+  }
+
+  var range = document.createRange(); 
+  range.selectNode(document.getElementById("container")); 
+  window.getSelection().addRange(range);
+</script>
+</body>
+</html>
index 67b555d..3edc28b 100644 (file)
@@ -1,3 +1,19 @@
+2014-05-01  Zalan Bujtas  <zalan@apple.com>
+
+        Subpixel rendering: Make selection gaps painting subpixel aware.
+        https://bugs.webkit.org/show_bug.cgi?id=132169
+
+        Reviewed by Simon Fraser.
+
+        Push selection gaps painting to device pixel boundaries instead of integral CSS pixel positions.
+
+        Test: fast/inline/hidpi-selection-gap-on-subpixel-position.html
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::blockSelectionGap):
+        (WebCore::RenderBlock::logicalLeftSelectionGap):
+        (WebCore::RenderBlock::logicalRightSelectionGap):
+
 2014-05-01  David Kilzer  <ddkilzer@apple.com>
 
         Really remove ENABLE_PLUGIN_PROXY_FOR_VIDEO
index f771a59..87f3b8c 100644 (file)
@@ -2533,7 +2533,7 @@ LayoutRect RenderBlock::blockSelectionGap(RenderBlock& rootBlock, const LayoutPo
 
     LayoutRect gapRect = rootBlock.logicalRectToPhysicalRect(rootBlockPhysicalPosition, LayoutRect(logicalLeft, logicalTop, logicalWidth, logicalHeight));
     if (paintInfo)
-        paintInfo->context->fillRect(pixelSnappedIntRect(gapRect), selectionBackgroundColor(), style().colorSpace());
+        paintInfo->context->fillRect(pixelSnappedForPainting(gapRect, document().deviceScaleFactor()), selectionBackgroundColor(), style().colorSpace());
     return gapRect;
 }
 
@@ -2550,7 +2550,7 @@ LayoutRect RenderBlock::logicalLeftSelectionGap(RenderBlock& rootBlock, const La
 
     LayoutRect gapRect = rootBlock.logicalRectToPhysicalRect(rootBlockPhysicalPosition, LayoutRect(rootBlockLogicalLeft, rootBlockLogicalTop, rootBlockLogicalWidth, logicalHeight));
     if (paintInfo)
-        paintInfo->context->fillRect(pixelSnappedIntRect(gapRect), selObj->selectionBackgroundColor(), selObj->style().colorSpace());
+        paintInfo->context->fillRect(pixelSnappedForPainting(gapRect, document().deviceScaleFactor()), selObj->selectionBackgroundColor(), selObj->style().colorSpace());
     return gapRect;
 }
 
@@ -2567,7 +2567,7 @@ LayoutRect RenderBlock::logicalRightSelectionGap(RenderBlock& rootBlock, const L
 
     LayoutRect gapRect = rootBlock.logicalRectToPhysicalRect(rootBlockPhysicalPosition, LayoutRect(rootBlockLogicalLeft, rootBlockLogicalTop, rootBlockLogicalWidth, logicalHeight));
     if (paintInfo)
-        paintInfo->context->fillRect(pixelSnappedIntRect(gapRect), selObj->selectionBackgroundColor(), selObj->style().colorSpace());
+        paintInfo->context->fillRect(pixelSnappedForPainting(gapRect, document().deviceScaleFactor()), selObj->selectionBackgroundColor(), selObj->style().colorSpace());
     return gapRect;
 }