DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& srcSize, const IntSize& size) { 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(); resizeRatio = widthResizeRatio; } if (srcSize.height() > size.height()) { heightResizeRatio = size.height() / (float)srcSize.height(); if ((resizeRatio < 0.0f) || (resizeRatio > heightResizeRatio)) resizeRatio = heightResizeRatio; } if (srcSize == 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(); if (resizeRatio > 0.0f) { scalex *= resizeRatio; scaley *= resizeRatio; } return scaleDragImage(image, FloatSize(scalex, scaley)); }
void DragClientImpl::startDrag(DragImageRef dragImage, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool isLinkDrag) { // Add a ref to the frame just in case a load occurs mid-drag. RefPtr<Frame> frameProtector = frame; WebDragData dragData = static_cast<ClipboardChromium*>(clipboard)->dataObject(); DragOperation dragOperationMask = clipboard->sourceOperation(); IntSize offsetSize(eventPos - dragImageOrigin); WebPoint offsetPoint(offsetSize.width(), offsetSize.height()); if (dragImage && dragImage->bitmap && m_webView->deviceScaleFactor() != dragImage->resolutionScale) { ASSERT(dragImage->resolutionScale > 0); float scale = m_webView->deviceScaleFactor() / dragImage->resolutionScale; dragImage = scaleDragImage(dragImage, WebCore::FloatSize(scale, scale)); } m_webView->startDragging(frame, dragData, static_cast<WebDragOperationsMask>(dragOperationMask), (dragImage && dragImage->bitmap) ? WebImage(*dragImage->bitmap) : WebImage(), offsetPoint); }