Commit 7e579012 authored by bburg@apple.com's avatar bburg@apple.com

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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161537 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bba75580
2014-01-08 Brian Burg <bburg@apple.com>
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 <seokju@webkit.org>
Web Inspector: Remove InspectorClient::captureScreenshot()
......@@ -848,11 +848,11 @@ bool DragController::startDrag(Frame& src, const DragState& state, DragOperation
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 @@ void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, c
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);
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment