Title: [161537] trunk/Source/WebCore
Revision
161537
Author
[email protected]
Date
2014-01-08 18:21:49 -0800 (Wed, 08 Jan 2014)

Log Message

Clean up confusing names and calculations in image-dragging functions
https://bugs.webkit.org/show_bug.cgi?id=126661

Reviewed by Timothy Hatcher.

No new tests.

* page/DragController.cpp:
(WebCore::DragController::doImageDrag): rename variables and
simplify the calculation of the image's scaled origin.

* platform/DragImage.cpp:
(WebCore::fitDragImageToMaxSize): rename variables.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161536 => 161537)


--- trunk/Source/WebCore/ChangeLog	2014-01-09 02:14:46 UTC (rev 161536)
+++ trunk/Source/WebCore/ChangeLog	2014-01-09 02:21:49 UTC (rev 161537)
@@ -1,3 +1,19 @@
+2014-01-08  Brian Burg  <[email protected]>
+
+        Clean up confusing names and calculations in image-dragging functions
+        https://bugs.webkit.org/show_bug.cgi?id=126661
+
+        Reviewed by Timothy Hatcher.
+
+        No new tests.
+
+        * page/DragController.cpp:
+        (WebCore::DragController::doImageDrag): rename variables and
+        simplify the calculation of the image's scaled origin.
+
+        * platform/DragImage.cpp:
+        (WebCore::fitDragImageToMaxSize): rename variables.
+
 2014-01-08  Seokju Kwon  <[email protected]>
 
         Web Inspector: Remove InspectorClient::captureScreenshot()

Modified: trunk/Source/WebCore/page/DragController.cpp (161536 => 161537)


--- trunk/Source/WebCore/page/DragController.cpp	2014-01-09 02:14:46 UTC (rev 161536)
+++ trunk/Source/WebCore/page/DragController.cpp	2014-01-09 02:21:49 UTC (rev 161537)
@@ -848,11 +848,11 @@
     return startedDrag;
 }
 
-void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& rect, Clipboard& clipboard, Frame& frame, IntPoint& dragImageOffset)
+void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& layoutRect, Clipboard& clipboard, Frame& frame, IntPoint& dragImageOffset)
 {
     IntPoint mouseDownPoint = dragOrigin;
-    DragImageRef dragImage = 0;
-    IntPoint origin;
+    DragImageRef dragImage = nullptr;
+    IntPoint scaledOrigin;
 
     if (!element.renderer())
         return;
@@ -865,34 +865,31 @@
     Image* image = getImage(element);
     if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea
         && (dragImage = createDragImageFromImage(image, element.renderer() ? orientationDescription : ImageOrientationDescription()))) {
-        IntSize originalSize = rect.size();
-        origin = rect.location();
 
-        dragImage = fitDragImageToMaxSize(dragImage, rect.size(), maxDragImageSize());
+        dragImage = fitDragImageToMaxSize(dragImage, layoutRect.size(), maxDragImageSize());
+        IntSize fittedSize = dragImageSize(dragImage);
+
         dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha);
-        IntSize newSize = dragImageSize(dragImage);
 
-        // Properly orient the drag image and orient it differently if it's smaller than the original
-        float scale = newSize.width() / (float)originalSize.width();
-        float dx = origin.x() - mouseDownPoint.x();
-        dx *= scale;
-        origin.setX((int)(dx + 0.5));
+        // Properly orient the drag image and orient it differently if it's smaller than the original.
+        float scale = fittedSize.width() / (float)layoutRect.width();
+        float dx = scale * (layoutRect.x() - mouseDownPoint.x());
+        float originY = layoutRect.y();
 #if PLATFORM(MAC)
-        //Compensate for accursed flipped coordinates in cocoa
-        origin.setY(origin.y() + originalSize.height());
+        // Compensate for accursed flipped coordinates in Cocoa.
+        originY += layoutRect.height();
 #endif
-        float dy = origin.y() - mouseDownPoint.y();
-        dy *= scale;
-        origin.setY((int)(dy + 0.5));
+        float dy = scale * (originY - mouseDownPoint.y());
+        scaledOrigin = IntPoint((int)(dx + 0.5), (int)(dy + 0.5));
     } else {
         if (CachedImage* cachedImage = getCachedImage(element)) {
             dragImage = createDragImageIconForCachedImageFilename(cachedImage->response().suggestedFilename());
             if (dragImage)
-                origin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset);
+                scaledOrigin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset);
         }
     }
 
-    dragImageOffset = mouseDownPoint + origin;
+    dragImageOffset = mouseDownPoint + scaledOrigin;
     doSystemDrag(dragImage, dragImageOffset, dragOrigin, clipboard, frame, false);
 
     deleteDragImage(dragImage);

Modified: trunk/Source/WebCore/platform/DragImage.cpp (161536 => 161537)


--- trunk/Source/WebCore/platform/DragImage.cpp	2014-01-09 02:14:46 UTC (rev 161536)
+++ trunk/Source/WebCore/platform/DragImage.cpp	2014-01-09 02:21:49 UTC (rev 161537)
@@ -38,36 +38,36 @@
 
 namespace WebCore {
 
-DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& srcSize, const IntSize& size)
+DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& layoutSize, const IntSize& maxSize)
 {
     float heightResizeRatio = 0.0f;
     float widthResizeRatio = 0.0f;
     float resizeRatio = -1.0f;
     IntSize originalSize = dragImageSize(image);
 
-    if (srcSize.width() > size.width()) {
-        widthResizeRatio = size.width() / (float)srcSize.width();
+    if (layoutSize.width() > maxSize.width()) {
+        widthResizeRatio = maxSize.width() / (float)layoutSize.width();
         resizeRatio = widthResizeRatio;
     }
 
-    if (srcSize.height() > size.height()) {
-        heightResizeRatio = size.height() / (float)srcSize.height();
+    if (layoutSize.height() > maxSize.height()) {
+        heightResizeRatio = maxSize.height() / (float)layoutSize.height();
         if ((resizeRatio < 0.0f) || (resizeRatio > heightResizeRatio))
             resizeRatio = heightResizeRatio;
     }
 
-    if (srcSize == originalSize)
+    if (layoutSize == originalSize)
         return resizeRatio > 0.0f ? scaleDragImage(image, FloatSize(resizeRatio, resizeRatio)) : image;
 
-    // The image was scaled in the webpage so at minimum we must account for that scaling
-    float scalex = srcSize.width() / (float)originalSize.width();
-    float scaley = srcSize.height() / (float)originalSize.height();
+    // The image was scaled in the webpage so at minimum we must account for that scaling.
+    float scaleX = layoutSize.width() / (float)originalSize.width();
+    float scaleY = layoutSize.height() / (float)originalSize.height();
     if (resizeRatio > 0.0f) {
-        scalex *= resizeRatio;
-        scaley *= resizeRatio;
+        scaleX *= resizeRatio;
+        scaleY *= resizeRatio;
     }
 
-    return scaleDragImage(image, FloatSize(scalex, scaley));
+    return scaleDragImage(image, FloatSize(scaleX, scaleY));
 }
 
 struct ScopedNodeDragEnabler {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to