Account for device scale factor when creating image for dragging.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Jun 2012 22:49:13 +0000 (22:49 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Jun 2012 22:49:13 +0000 (22:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89489

Patch by Varun Jain <varunjain@chromium.org> on 2012-06-20
Reviewed by Adam Barth.

.:

* ManualTests/chromium/drag-image-accounts-for-device-scale.html: Added.

Source/WebCore:

Manual Test: ManualTests/chromium/drag-image-accounts-for-device-scale.html

* page/Frame.cpp:
(WebCore::Frame::nodeImage):
(WebCore::Frame::dragImageForSelection):

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

ChangeLog
ManualTests/chromium/drag-image-accounts-for-device-scale.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/Frame.cpp

index 91f15e36b914a9f228def46d57171a73d41ce748..df3e8453d9db46a614b7ff3a366a08c169d83124 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-06-20  Varun Jain  <varunjain@chromium.org>
+
+        Account for device scale factor when creating image for dragging.
+        https://bugs.webkit.org/show_bug.cgi?id=89489
+
+        Reviewed by Adam Barth.
+
+        * ManualTests/chromium/drag-image-accounts-for-device-scale.html: Added.
+
 2012-06-18  Philippe Normand  <pnormand@igalia.com>
 
         [GStreamer] 0.11 video-sink
diff --git a/ManualTests/chromium/drag-image-accounts-for-device-scale.html b/ManualTests/chromium/drag-image-accounts-for-device-scale.html
new file mode 100644 (file)
index 0000000..1564cae
--- /dev/null
@@ -0,0 +1,10 @@
+<html>
+<body>
+    <p>To test device scale, run chrome with --force-device-scale-factor=2 (or run chrome on a device with > 1 device scale, such as a macbook running in high dpi mode)</p>
+    <p>Select some text and start dragging. If the text in the drag image is rendered at the same size as the text on the page and is not blurry (due to scaling), 1st part of this test passes.</p>
+    <p>For 2nd part, try dragging "Drag me" below. Again, if the text in the drag image is rendered at the same size as the text on the page is not blurry, the test passes.</p>
+    <div draggable='true' id='dragme'>
+        Drag me
+    </div>
+</body>
+</html>
index d0dcc11abacc40edf7b4f1d34e86cc842e727094..1c31aa8a7dd5be26568e29f45a95242081470549 100644 (file)
@@ -1,3 +1,16 @@
+2012-06-20  Varun Jain  <varunjain@chromium.org>
+
+        Account for device scale factor when creating image for dragging.
+        https://bugs.webkit.org/show_bug.cgi?id=89489
+
+        Reviewed by Adam Barth.
+
+        Manual Test: ManualTests/chromium/drag-image-accounts-for-device-scale.html
+
+        * page/Frame.cpp:
+        (WebCore::Frame::nodeImage):
+        (WebCore::Frame::dragImageForSelection):
+
 2012-06-20  Jacky Jiang  <zhajiang@rim.com>
 
         Add a != operator to ViewportArguments
index 91d31e3bfd147a890f76a739000d3b002534f8b4..ea57bb4f1d852cf005109f017087bef40c2b99a7 100644 (file)
@@ -1089,9 +1089,16 @@ DragImageRef Frame::nodeImage(Node* node)
     LayoutRect topLevelRect;
     IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect));
 
+    float deviceScaleFactor = 1;
+    if (m_page)
+        deviceScaleFactor = m_page->deviceScaleFactor();
+    paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);
+    paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);
+
     OwnPtr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size(), 1, ColorSpaceDeviceRGB));
     if (!buffer)
         return 0;
+    buffer->context()->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
     buffer->context()->translate(-paintingRect.x(), -paintingRect.y());
     buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));
 
@@ -1112,9 +1119,16 @@ DragImageRef Frame::dragImageForSelection()
 
     IntRect paintingRect = enclosingIntRect(selection()->bounds());
 
+    float deviceScaleFactor = 1;
+    if (m_page)
+        deviceScaleFactor = m_page->deviceScaleFactor();
+    paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);
+    paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);
+
     OwnPtr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size(), 1, ColorSpaceDeviceRGB));
     if (!buffer)
         return 0;
+    buffer->context()->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
     buffer->context()->translate(-paintingRect.x(), -paintingRect.y());
     buffer->context()->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));