<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[182869] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/182869">182869</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2015-04-15 16:21:42 -0700 (Wed, 15 Apr 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Custom CSS cursors do not use -webkit-image-set on retina displays
https://bugs.webkit.org/show_bug.cgi?id=120783
.:
Reviewed by Beth Dakin.
Add a manual test for custom CSS cursors on retina displays.
* ManualTests/retina-cursors.html: Added.
Source/WebCore:
<rdar://problem/14921432>
Reviewed by Beth Dakin.
Scale NSCursor images correctly so custom CSS cursors work with
-webkit-image-set on retina displays.
* WebCore.exp.in:
* page/EventHandler.cpp:
(WebCore::EventHandler::selectCursor):
* platform/mac/CursorMac.mm:
(WebCore::createCustomCursor):
(WebCore::Cursor::ensurePlatformCursor):
Source/WebKit2:
Reviewed by Beth Dakin.
Serialize the cursor image scale for SetCursor messages so custom
CSS cursors work with -webkit-image-set on retina displays.
* Shared/WebCoreArgumentCoders.cpp:
(CoreIPC::ArgumentCoder<Cursor>::encode):
(CoreIPC::ArgumentCoder<Cursor>::decode):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkChangeLog">trunk/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlercpp">trunk/Source/WebCore/page/EventHandler.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformCursorh">trunk/Source/WebCore/platform/Cursor.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacCursorMacmm">trunk/Source/WebCore/platform/mac/CursorMac.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedWebCoreArgumentCoderscpp">trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkManualTestsretinacursorshtml">trunk/ManualTests/retina-cursors.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/ChangeLog (182868 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ChangeLog        2015-04-15 23:14:55 UTC (rev 182868)
+++ trunk/ChangeLog        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-04-15 Timothy Horton <timothy_horton@apple.com>
+
+ Custom CSS cursors do not use -webkit-image-set on retina displays
+ https://bugs.webkit.org/show_bug.cgi?id=120783
+
+ Reviewed by Beth Dakin.
+ Patch by Evan Wallace <evan.exe@gmail.com>.
+
+ Add a manual test for custom CSS cursors on retina displays.
+
+ * ManualTests/retina-cursors.html: Added.
+
</ins><span class="cx"> 2015-04-15 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Progress towards CMake on Mac.
</span></span></pre></div>
<a id="trunkManualTestsretinacursorshtml"></a>
<div class="addfile"><h4>Added: trunk/ManualTests/retina-cursors.html (0 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ManualTests/retina-cursors.html         (rev 0)
+++ trunk/ManualTests/retina-cursors.html        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -0,0 +1,83 @@
</span><ins>+<body>
+This is a test for custom CSS cursors on retina displays.
+Move the mouse over the green pixel in each red square and the left should match the right.
+Note that NSCursor has bugs with precise sub-pixel positioning on retina displays but if you zoom in using the control+scroll shortcut then the cursor will shift to the correct position.
+See https://bugs.webkit.org/show_bug.cgi?id=120783.
+<script>
+
+if (window.devicePixelRatio !== 2) {
+ document.write('<h1>Note: This test only makes sense on a retina display.</h1>');
+}
+
+var demoWidth = 64;
+var demoHeight = 64;
+
+function createCheckerboard(width, height) {
+ var c = document.createElement('canvas').getContext('2d');
+ var imageData = c.createImageData(width, height);
+ var data = imageData.data;
+ c.canvas.width = width;
+ c.canvas.height = height;
+ for (var y = 0; y < height; y++) {
+ for (var x = 0; x < width; x++) {
+ var i = x + y * width << 2;
+ data[i] = data[i + 1] = data[i + 2] = (x ^ y) & 1 ? 255 : 0;
+ data[i + 3] = 255;
+ }
+ }
+ c.putImageData(imageData, 0, 0);
+ return c.canvas;
+}
+
+function createRender(x, y, width, height, scale) {
+ var c = document.createElement('canvas').getContext('2d');
+ var checkerboard = createCheckerboard(width, height);
+ c.canvas.width = demoWidth * 2;
+ c.canvas.height = demoHeight * 2;
+ c.canvas.style.width = demoWidth + 'px';
+ c.canvas.style.height = demoHeight + 'px';
+ c.fillStyle = '#F00'; c.fillRect(0, 0, demoWidth * 2, demoHeight * 2);
+ c.fillStyle = '#D00'; c.fillRect(0, 0, demoWidth, demoHeight);
+ c.fillStyle = '#0F0'; c.fillRect(demoWidth, demoHeight, 2, 2);
+ c.drawImage(checkerboard, demoWidth - 2 * x, demoHeight - 2 * y, checkerboard.width * 2 / scale, checkerboard.height * 2 / scale);
+ return c.canvas;
+}
+
+var number = 0;
+
+function createCursorDemo(x, y, width, height, scale) {
+ var cursor = '-webkit-image-set(url(' + createCheckerboard(width, height).toDataURL() + ') ' + scale + 'x) ' + x + ' ' + y + ', help';
+ document.write('<h3 style="margin-bottom:0;">Test ' + ++number + '</h3>' +
+ '<div style="position:relative;width:' + demoWidth + 'px;height:' + demoHeight + 'px;background:#F00;display:inline-block;margin-right:20px;">' +
+ '<div style="position:absolute;width:' + demoWidth / 2 + 'px;height:' + demoHeight / 2 + 'px;background:#D00;"></div>' +
+ '<div style="position:absolute;left:' + demoWidth / 2 + 'px;top:' + demoHeight / 2 + 'px;width:1px;height:1px;background:#0F0;cursor:' + cursor + ';"></div>' +
+ '</div>');
+ document.body.appendChild(createRender(x, y, width, height, scale));
+}
+
+document.write('<h2>Size tests</h2>');
+createCursorDemo(0, 0, 64, 64, 2);
+createCursorDemo(0, 0, 63, 64, 2);
+createCursorDemo(0, 0, 64, 63, 2);
+createCursorDemo(0, 0, 63, 63, 2);
+createCursorDemo(0, 0, 5, 4, 2);
+createCursorDemo(0, 0, 5, 3, 2);
+createCursorDemo(0, 0, 4, 3, 2);
+createCursorDemo(0, 0, 2, 2, 2);
+createCursorDemo(0, 0, 1, 1, 2);
+
+document.write('<h2>Hot spot tests</h2>');
+createCursorDemo(15, 15, 64, 64, 2);
+createCursorDemo(15, 15, 32, 32, 1);
+createCursorDemo(31, 31, 64, 64, 2);
+createCursorDemo(31, 31, 32, 32, 1);
+createCursorDemo(1, 1, 9, 9, 2);
+createCursorDemo(16, 0, 64, 64, 2);
+createCursorDemo(0, 16, 64, 64, 2);
+createCursorDemo(3, 4, 8, 10, 2);
+createCursorDemo(2, 3, 7, 9, 2);
+createCursorDemo(1, 0, 5, 3, 2);
+createCursorDemo(2, 1, 5, 3, 2);
+
+</script>
+</body>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182868 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-04-15 23:14:55 UTC (rev 182868)
+++ trunk/Source/WebCore/ChangeLog        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2015-04-15 Timothy Horton <timothy_horton@apple.com>
+
+ Custom CSS cursors do not use -webkit-image-set on retina displays
+ https://bugs.webkit.org/show_bug.cgi?id=120783
+ <rdar://problem/14921432>
+
+ Reviewed by Beth Dakin.
+ Patch by Evan Wallace <evan.exe@gmail.com>.
+
+ Scale NSCursor images correctly so custom CSS cursors work with
+ -webkit-image-set on retina displays.
+
+ * WebCore.exp.in:
+ * page/EventHandler.cpp:
+ (WebCore::EventHandler::selectCursor):
+ * platform/mac/CursorMac.mm:
+ (WebCore::createCustomCursor):
+ (WebCore::Cursor::ensurePlatformCursor):
+
</ins><span class="cx"> 2015-04-15 Alexey Proskuryakov <ap@apple.com>
</span><span class="cx">
</span><span class="cx"> No thread safety when passing ThreadableLoaderOptions from a worker thread
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (182868 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.cpp        2015-04-15 23:14:55 UTC (rev 182868)
+++ trunk/Source/WebCore/page/EventHandler.cpp        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -1413,7 +1413,6 @@
</span><span class="cx"> float scale = styleImage->imageScaleFactor();
</span><span class="cx"> // Get hotspot and convert from logical pixels to physical pixels.
</span><span class="cx"> IntPoint hotSpot = (*cursors)[i].hotSpot();
</span><del>- hotSpot.scale(scale, scale);
</del><span class="cx"> FloatSize size = cachedImage->imageForRenderer(renderer)->size();
</span><span class="cx"> if (cachedImage->errorOccurred())
</span><span class="cx"> continue;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformCursorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/Cursor.h (182868 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/Cursor.h        2015-04-15 23:14:55 UTC (rev 182868)
+++ trunk/Source/WebCore/platform/Cursor.h        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -146,7 +146,7 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(MOUSE_CURSOR_SCALE)
</span><span class="cx"> // Hot spot is in image pixels.
</span><del>- Cursor(Image*, const IntPoint& hotSpot, float imageScaleFactor);
</del><ins>+ WEBCORE_EXPORT Cursor(Image*, const IntPoint& hotSpot, float imageScaleFactor);
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> WEBCORE_EXPORT ~Cursor();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacCursorMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/CursorMac.mm (182868 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/CursorMac.mm        2015-04-15 23:14:55 UTC (rev 182868)
+++ trunk/Source/WebCore/platform/mac/CursorMac.mm        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -41,16 +41,43 @@
</span><span class="cx"> // Simple NSCursor calls shouldn't need protection,
</span><span class="cx"> // but creating a cursor with a bad image might throw.
</span><span class="cx">
</span><ins>+#if ENABLE(MOUSE_CURSOR_SCALE)
+static RetainPtr<NSCursor> createCustomCursor(Image* image, const IntPoint& hotSpot, float scale)
+#else
</ins><span class="cx"> static RetainPtr<NSCursor> createCustomCursor(Image* image, const IntPoint& hotSpot)
</span><ins>+#endif
</ins><span class="cx"> {
</span><span class="cx"> // FIXME: The cursor won't animate. Not sure if that's a big deal.
</span><span class="cx"> NSImage* nsImage = image->getNSImage();
</span><span class="cx"> if (!nsImage)
</span><span class="cx"> return 0;
</span><span class="cx"> BEGIN_BLOCK_OBJC_EXCEPTIONS;
</span><ins>+
+#if ENABLE(MOUSE_CURSOR_SCALE)
+ NSSize size = NSMakeSize(image->width() / scale, image->height() / scale);
+ NSSize expandedSize = NSMakeSize(ceil(size.width), ceil(size.height));
+
+ // Pad the image with transparent pixels so it has an integer boundary.
+ if (size.width != expandedSize.width || size.height != expandedSize.height) {
+ RetainPtr<NSImage> expandedImage = adoptNS([[NSImage alloc] initWithSize:expandedSize]);
+ NSRect toRect = NSMakeRect(0, expandedSize.height - size.height, size.width, size.height);
+ NSRect fromRect = NSMakeRect(0, 0, image->width(), image->height());
+
+ [expandedImage lockFocus];
+ [nsImage drawInRect:toRect fromRect:fromRect operation:NSCompositeSourceOver fraction:1];
+ [expandedImage unlockFocus];
+
+ return adoptNS([[NSCursor alloc] initWithImage:expandedImage.get() hotSpot:hotSpot]);
+ }
+
+ // Scale the image and its representation to match retina resolution.
+ [nsImage setSize:expandedSize];
+ [[[nsImage representations] objectAtIndex:0] setSize:expandedSize];
+#endif
+
</ins><span class="cx"> return adoptNS([[NSCursor alloc] initWithImage:nsImage hotSpot:hotSpot]);
</span><span class="cx"> END_BLOCK_OBJC_EXCEPTIONS;
</span><del>- return 0;
</del><ins>+ return nullptr;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Cursor::ensurePlatformCursor() const
</span><span class="lines">@@ -205,7 +232,11 @@
</span><span class="cx"> break;
</span><span class="cx">
</span><span class="cx"> case Cursor::Custom:
</span><ins>+#if ENABLE(MOUSE_CURSOR_SCALE)
+ m_platformCursor = createCustomCursor(m_image.get(), m_hotSpot, m_imageScaleFactor);
+#else
</ins><span class="cx"> m_platformCursor = createCustomCursor(m_image.get(), m_hotSpot);
</span><ins>+#endif
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (182868 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-04-15 23:14:55 UTC (rev 182868)
+++ trunk/Source/WebKit2/ChangeLog        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-04-15 Timothy Horton <timothy_horton@apple.com>
+
+ Custom CSS cursors do not use -webkit-image-set on retina displays
+ https://bugs.webkit.org/show_bug.cgi?id=120783
+
+ Reviewed by Beth Dakin.
+ Patch by Evan Wallace <evan.exe@gmail.com>.
+
+ Serialize the cursor image scale for SetCursor messages so custom
+ CSS cursors work with -webkit-image-set on retina displays.
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ (CoreIPC::ArgumentCoder<Cursor>::encode):
+ (CoreIPC::ArgumentCoder<Cursor>::decode):
+
</ins><span class="cx"> 2015-04-15 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Progress towards CMake on Mac.
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedWebCoreArgumentCoderscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp (182868 => 182869)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp        2015-04-15 23:14:55 UTC (rev 182868)
+++ trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp        2015-04-15 23:21:42 UTC (rev 182869)
</span><span class="lines">@@ -766,6 +766,9 @@
</span><span class="cx"> encoder << true;
</span><span class="cx"> encodeImage(encoder, cursor.image());
</span><span class="cx"> encoder << cursor.hotSpot();
</span><ins>+#if ENABLE(MOUSE_CURSOR_SCALE)
+ encoder << cursor.imageScaleFactor();
+#endif
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ArgumentCoder<Cursor>::decode(ArgumentDecoder& decoder, Cursor& cursor)
</span><span class="lines">@@ -807,7 +810,15 @@
</span><span class="cx"> if (!image->rect().contains(hotSpot))
</span><span class="cx"> return false;
</span><span class="cx">
</span><ins>+#if ENABLE(MOUSE_CURSOR_SCALE)
+ float scale;
+ if (!decoder.decode(scale))
+ return false;
+
+ cursor = Cursor(image.get(), hotSpot, scale);
+#else
</ins><span class="cx"> cursor = Cursor(image.get(), hotSpot);
</span><ins>+#endif
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>
</body>
</html>