Changeset 161537 in webkit


Ignore:
Timestamp:
Jan 8, 2014 6:21:49 PM (10 years ago)
Author:
BJ Burg
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161534 r161537  
     12014-01-08  Brian Burg  <bburg@apple.com>
     2
     3        Clean up confusing names and calculations in image-dragging functions
     4        https://bugs.webkit.org/show_bug.cgi?id=126661
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        No new tests.
     9
     10        * page/DragController.cpp:
     11        (WebCore::DragController::doImageDrag): rename variables and
     12        simplify the calculation of the image's scaled origin.
     13
     14        * platform/DragImage.cpp:
     15        (WebCore::fitDragImageToMaxSize): rename variables.
     16
    1172014-01-08  Seokju Kwon  <seokju@webkit.org>
    218
  • trunk/Source/WebCore/page/DragController.cpp

    r161342 r161537  
    849849}
    850850
    851 void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& rect, Clipboard& clipboard, Frame& frame, IntPoint& dragImageOffset)
     851void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& layoutRect, Clipboard& clipboard, Frame& frame, IntPoint& dragImageOffset)
    852852{
    853853    IntPoint mouseDownPoint = dragOrigin;
    854     DragImageRef dragImage = 0;
    855     IntPoint origin;
     854    DragImageRef dragImage = nullptr;
     855    IntPoint scaledOrigin;
    856856
    857857    if (!element.renderer())
     
    866866    if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea
    867867        && (dragImage = createDragImageFromImage(image, element.renderer() ? orientationDescription : ImageOrientationDescription()))) {
    868         IntSize originalSize = rect.size();
    869         origin = rect.location();
    870 
    871         dragImage = fitDragImageToMaxSize(dragImage, rect.size(), maxDragImageSize());
     868
     869        dragImage = fitDragImageToMaxSize(dragImage, layoutRect.size(), maxDragImageSize());
     870        IntSize fittedSize = dragImageSize(dragImage);
     871
    872872        dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha);
    873         IntSize newSize = dragImageSize(dragImage);
    874 
    875         // Properly orient the drag image and orient it differently if it's smaller than the original
    876         float scale = newSize.width() / (float)originalSize.width();
    877         float dx = origin.x() - mouseDownPoint.x();
    878         dx *= scale;
    879         origin.setX((int)(dx + 0.5));
     873
     874        // Properly orient the drag image and orient it differently if it's smaller than the original.
     875        float scale = fittedSize.width() / (float)layoutRect.width();
     876        float dx = scale * (layoutRect.x() - mouseDownPoint.x());
     877        float originY = layoutRect.y();
    880878#if PLATFORM(MAC)
    881         //Compensate for accursed flipped coordinates in cocoa
    882         origin.setY(origin.y() + originalSize.height());
     879        // Compensate for accursed flipped coordinates in Cocoa.
     880        originY += layoutRect.height();
    883881#endif
    884         float dy = origin.y() - mouseDownPoint.y();
    885         dy *= scale;
    886         origin.setY((int)(dy + 0.5));
     882        float dy = scale * (originY - mouseDownPoint.y());
     883        scaledOrigin = IntPoint((int)(dx + 0.5), (int)(dy + 0.5));
    887884    } else {
    888885        if (CachedImage* cachedImage = getCachedImage(element)) {
    889886            dragImage = createDragImageIconForCachedImageFilename(cachedImage->response().suggestedFilename());
    890887            if (dragImage)
    891                 origin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset);
    892         }
    893     }
    894 
    895     dragImageOffset = mouseDownPoint + origin;
     888                scaledOrigin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset);
     889        }
     890    }
     891
     892    dragImageOffset = mouseDownPoint + scaledOrigin;
    896893    doSystemDrag(dragImage, dragImageOffset, dragOrigin, clipboard, frame, false);
    897894
  • trunk/Source/WebCore/platform/DragImage.cpp

    r160152 r161537  
    3939namespace WebCore {
    4040
    41 DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& srcSize, const IntSize& size)
     41DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& layoutSize, const IntSize& maxSize)
    4242{
    4343    float heightResizeRatio = 0.0f;
     
    4646    IntSize originalSize = dragImageSize(image);
    4747
    48     if (srcSize.width() > size.width()) {
    49         widthResizeRatio = size.width() / (float)srcSize.width();
     48    if (layoutSize.width() > maxSize.width()) {
     49        widthResizeRatio = maxSize.width() / (float)layoutSize.width();
    5050        resizeRatio = widthResizeRatio;
    5151    }
    5252
    53     if (srcSize.height() > size.height()) {
    54         heightResizeRatio = size.height() / (float)srcSize.height();
     53    if (layoutSize.height() > maxSize.height()) {
     54        heightResizeRatio = maxSize.height() / (float)layoutSize.height();
    5555        if ((resizeRatio < 0.0f) || (resizeRatio > heightResizeRatio))
    5656            resizeRatio = heightResizeRatio;
    5757    }
    5858
    59     if (srcSize == originalSize)
     59    if (layoutSize == originalSize)
    6060        return resizeRatio > 0.0f ? scaleDragImage(image, FloatSize(resizeRatio, resizeRatio)) : image;
    6161
    62     // The image was scaled in the webpage so at minimum we must account for that scaling
    63     float scalex = srcSize.width() / (float)originalSize.width();
    64     float scaley = srcSize.height() / (float)originalSize.height();
     62    // The image was scaled in the webpage so at minimum we must account for that scaling.
     63    float scaleX = layoutSize.width() / (float)originalSize.width();
     64    float scaleY = layoutSize.height() / (float)originalSize.height();
    6565    if (resizeRatio > 0.0f) {
    66         scalex *= resizeRatio;
    67         scaley *= resizeRatio;
    68     }
    69 
    70     return scaleDragImage(image, FloatSize(scalex, scaley));
     66        scaleX *= resizeRatio;
     67        scaleY *= resizeRatio;
     68    }
     69
     70    return scaleDragImage(image, FloatSize(scaleX, scaleY));
    7171}
    7272
Note: See TracChangeset for help on using the changeset viewer.