Changeset 161537 in webkit
- Timestamp:
- Jan 8, 2014 6:21:49 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r161534 r161537 1 2014-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 1 17 2014-01-08 Seokju Kwon <seokju@webkit.org> 2 18 -
trunk/Source/WebCore/page/DragController.cpp
r161342 r161537 849 849 } 850 850 851 void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& rect, Clipboard& clipboard, Frame& frame, IntPoint& dragImageOffset)851 void DragController::doImageDrag(Element& element, const IntPoint& dragOrigin, const IntRect& layoutRect, Clipboard& clipboard, Frame& frame, IntPoint& dragImageOffset) 852 852 { 853 853 IntPoint mouseDownPoint = dragOrigin; 854 DragImageRef dragImage = 0;855 IntPoint origin;854 DragImageRef dragImage = nullptr; 855 IntPoint scaledOrigin; 856 856 857 857 if (!element.renderer()) … … 866 866 if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea 867 867 && (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 872 872 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(); 880 878 #if PLATFORM(MAC) 881 // Compensate for accursed flipped coordinates in cocoa882 origin .setY(origin.y() + originalSize.height());879 // Compensate for accursed flipped coordinates in Cocoa. 880 originY += layoutRect.height(); 883 881 #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)); 887 884 } else { 888 885 if (CachedImage* cachedImage = getCachedImage(element)) { 889 886 dragImage = createDragImageIconForCachedImageFilename(cachedImage->response().suggestedFilename()); 890 887 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; 896 893 doSystemDrag(dragImage, dragImageOffset, dragOrigin, clipboard, frame, false); 897 894 -
trunk/Source/WebCore/platform/DragImage.cpp
r160152 r161537 39 39 namespace WebCore { 40 40 41 DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& srcSize, const IntSize& size)41 DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& layoutSize, const IntSize& maxSize) 42 42 { 43 43 float heightResizeRatio = 0.0f; … … 46 46 IntSize originalSize = dragImageSize(image); 47 47 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(); 50 50 resizeRatio = widthResizeRatio; 51 51 } 52 52 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(); 55 55 if ((resizeRatio < 0.0f) || (resizeRatio > heightResizeRatio)) 56 56 resizeRatio = heightResizeRatio; 57 57 } 58 58 59 if ( srcSize == originalSize)59 if (layoutSize == originalSize) 60 60 return resizeRatio > 0.0f ? scaleDragImage(image, FloatSize(resizeRatio, resizeRatio)) : image; 61 61 62 // The image was scaled in the webpage so at minimum we must account for that scaling 63 float scale x = srcSize.width() / (float)originalSize.width();64 float scale y = 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(); 65 65 if (resizeRatio > 0.0f) { 66 scale x*= resizeRatio;67 scale y*= resizeRatio;68 } 69 70 return scaleDragImage(image, FloatSize(scale x, scaley));66 scaleX *= resizeRatio; 67 scaleY *= resizeRatio; 68 } 69 70 return scaleDragImage(image, FloatSize(scaleX, scaleY)); 71 71 } 72 72
Note: See TracChangeset
for help on using the changeset viewer.