Changeset 212154 in webkit
- Timestamp:
- Feb 10, 2017 3:09:45 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r212153 r212154 1 2017-02-10 Anders Carlsson <andersca@apple.com> 2 3 Add a DragImage class that wraps a DragImageRef 4 https://bugs.webkit.org/show_bug.cgi?id=168131 5 6 Reviewed by Beth Dakin. 7 8 This allows us to get rid of the explicit deleteDragImage calls and will make additional cleanup of the 9 various drag code paths possible. No functionality change. 10 11 * dom/DataTransfer.cpp: 12 (WebCore::DataTransfer::updateDragImage): 13 * page/DragController.cpp: 14 (WebCore::DragController::startDrag): 15 (WebCore::DragController::doImageDrag): 16 (WebCore::DragController::doSystemDrag): 17 * page/DragController.h: 18 * platform/DragImage.cpp: 19 (WebCore::DragImage::DragImage): 20 (WebCore::DragImage::operator=): 21 (WebCore::DragImage::~DragImage): 22 * platform/DragImage.h: 23 * platform/Pasteboard.h: 24 * platform/StaticPasteboard.h: 25 * platform/mac/PasteboardMac.mm: 26 (WebCore::Pasteboard::setDragImage): 27 1 28 2017-02-10 Simon Fraser <simon.fraser@apple.com> 2 29 -
trunk/Source/WebCore/dom/DataTransfer.cpp
r211591 r212154 284 284 285 285 IntPoint computedHotSpot; 286 DragImageRef computedImage = createDragImage(computedHotSpot);286 auto computedImage = DragImage { createDragImage(computedHotSpot) }; 287 287 if (!computedImage) 288 288 return; 289 289 290 m_pasteboard->setDragImage( computedImage, computedHotSpot);290 m_pasteboard->setDragImage(WTFMove(computedImage), computedHotSpot); 291 291 } 292 292 -
trunk/Source/WebCore/page/DragController.cpp
r211597 r212154 773 773 sourceContainsHitNode = state.source->containsIncludingShadowDOM(hitTestResult.innerNode()); 774 774 775 if (!sourceContainsHitNode) 775 if (!sourceContainsHitNode) { 776 776 // The original node being dragged isn't under the drag origin anymore... maybe it was 777 777 // hidden or moved out from under the cursor. Regardless, we don't want to start a drag on 778 778 // something that's not actually under the drag origin. 779 779 return false; 780 } 781 780 782 URL linkURL = hitTestResult.absoluteLinkURL(); 781 783 URL imageURL = hitTestResult.absoluteImageURL(); … … 790 792 m_sourceDragOperation = srcOp; 791 793 792 DragImage Ref dragImage = nullptr;794 DragImage dragImage; 793 795 IntPoint dragLoc(0, 0); 794 796 IntPoint dragImageOffset(0, 0); … … 798 800 DataTransfer& dataTransfer = *state.dataTransfer; 799 801 if (state.type == DragSourceActionDHTML) 800 dragImage = dataTransfer.createDragImage(dragImageOffset);802 dragImage = DragImage { dataTransfer.createDragImage(dragImageOffset) }; 801 803 if (state.type == DragSourceActionSelection || !imageURL.isEmpty() || !linkURL.isEmpty()) 802 804 // Selection, image, and link drags receive a default set of allowed drag operations that … … 851 853 m_client.willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, dataTransfer); 852 854 if (!dragImage) { 853 dragImage = dissolveDragImageToFraction(createDragImageForSelection(src), DragImageAlpha);855 dragImage = DragImage { dissolveDragImageToFraction(createDragImageForSelection(src), DragImageAlpha) }; 854 856 dragLoc = dragLocForSelectionDrag(src); 855 857 m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y()); … … 859 861 return false; 860 862 861 doSystemDrag( dragImage, dragLoc, dragOrigin, dragImageBounds, dataTransfer, src, false);863 doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, dragImageBounds, dataTransfer, src, false); 862 864 } else if (!src.document()->securityOrigin().canDisplay(linkURL)) { 863 865 src.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to drag local resource: " + linkURL.stringCenterEllipsizedToLength()); … … 882 884 } else { 883 885 // DHTML defined drag image 884 doSystemDrag( dragImage, dragLoc, dragOrigin, { }, dataTransfer, src, false);886 doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false); 885 887 } 886 888 } else if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) { … … 911 913 m_client.willPerformDragSourceAction(DragSourceActionLink, dragOrigin, dataTransfer); 912 914 if (!dragImage) { 913 dragImage = createDragImageForLink(linkURL, hitTestResult.textContent(), src.settings().fontRenderingMode());914 IntSize size = dragImageSize(dragImage );915 dragImage = DragImage { createDragImageForLink(linkURL, hitTestResult.textContent(), src.settings().fontRenderingMode()) }; 916 IntSize size = dragImageSize(dragImage.get()); 915 917 m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset); 916 918 dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y()); 917 919 // Later code expects the drag image to be scaled by device's scale factor. 918 dragImage = scaleDragImage(dragImage, FloatSize(m_page.deviceScaleFactor(), m_page.deviceScaleFactor()));919 } 920 doSystemDrag( dragImage, dragLoc, mouseDraggedPoint, { }, dataTransfer, src, true);920 dragImage = DragImage { scaleDragImage(dragImage.get(), FloatSize(m_page.deviceScaleFactor(), m_page.deviceScaleFactor())) }; 921 } 922 doSystemDrag(WTFMove(dragImage), dragLoc, mouseDraggedPoint, { }, dataTransfer, src, true); 921 923 #if ENABLE(ATTACHMENT_ELEMENT) 922 924 } else if (!attachmentURL.isEmpty() && (m_dragSourceAction & DragSourceActionAttachment)) { … … 930 932 931 933 if (!dragImage) { 932 dragImage = dissolveDragImageToFraction(createDragImageForSelection(src), DragImageAlpha);934 dragImage = DragImage { dissolveDragImageToFraction(createDragImageForSelection(src), DragImageAlpha) }; 933 935 dragLoc = dragLocForSelectionDrag(src); 934 936 m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y()); 935 937 } 936 doSystemDrag( dragImage, dragLoc, dragOrigin, { }, dataTransfer, src, false);938 doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false); 937 939 #endif 938 940 } else if (state.type == DragSourceActionDHTML) { … … 940 942 ASSERT(m_dragSourceAction & DragSourceActionDHTML); 941 943 m_client.willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, dataTransfer); 942 doSystemDrag( dragImage, dragLoc, dragOrigin, { }, dataTransfer, src, false);944 doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, false); 943 945 } else 944 946 startedDrag = false; … … 949 951 } 950 952 951 if (dragImage)952 deleteDragImage(dragImage);953 953 return startedDrag; 954 954 } … … 957 957 { 958 958 IntPoint mouseDownPoint = dragOrigin; 959 DragImage Ref dragImage = nullptr;959 DragImage dragImage; 960 960 IntPoint scaledOrigin; 961 961 … … 967 967 Image* image = getImage(element); 968 968 if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea 969 && (dragImage = createDragImageFromImage(image, element.renderer() ? orientationDescription : ImageOrientationDescription()))) {970 971 dragImage = fitDragImageToMaxSize(dragImage, layoutRect.size(), maxDragImageSize());972 IntSize fittedSize = dragImageSize(dragImage );973 974 dragImage = scaleDragImage(dragImage, FloatSize(m_page.deviceScaleFactor(), m_page.deviceScaleFactor()));975 dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha);969 && (dragImage = DragImage { createDragImageFromImage(image, element.renderer() ? orientationDescription : ImageOrientationDescription()) })) { 970 971 dragImage = DragImage { fitDragImageToMaxSize(dragImage.get(), layoutRect.size(), maxDragImageSize()) }; 972 IntSize fittedSize = dragImageSize(dragImage.get()); 973 974 dragImage = DragImage { scaleDragImage(dragImage.get(), FloatSize(m_page.deviceScaleFactor(), m_page.deviceScaleFactor())) }; 975 dragImage = DragImage { dissolveDragImageToFraction(dragImage.get(), DragImageAlpha) }; 976 976 977 977 // Properly orient the drag image and orient it differently if it's smaller than the original. … … 987 987 } else { 988 988 if (CachedImage* cachedImage = getCachedImage(element)) { 989 dragImage = createDragImageIconForCachedImageFilename(cachedImage->response().suggestedFilename());989 dragImage = DragImage { createDragImageIconForCachedImageFilename(cachedImage->response().suggestedFilename()) }; 990 990 if (dragImage) 991 scaledOrigin = IntPoint(DragIconRightInset - dragImageSize(dragImage ).width(), DragIconBottomInset);991 scaledOrigin = IntPoint(DragIconRightInset - dragImageSize(dragImage.get()).width(), DragIconBottomInset); 992 992 } 993 993 } … … 997 997 998 998 dragImageOffset = mouseDownPoint + scaledOrigin; 999 doSystemDrag(dragImage, dragImageOffset, dragOrigin, element.boundsInRootViewSpace(), dataTransfer, frame, false); 1000 1001 deleteDragImage(dragImage); 1002 } 1003 1004 void DragController::doSystemDrag(DragImageRef image, const IntPoint& dragLoc, const IntPoint& eventPos, const IntRect& dragImageBounds, DataTransfer& dataTransfer, Frame& frame, bool forLink) 999 doSystemDrag(WTFMove(dragImage), dragImageOffset, dragOrigin, element.boundsInRootViewSpace(), dataTransfer, frame, false); 1000 } 1001 1002 void DragController::doSystemDrag(DragImage image, const IntPoint& dragLoc, const IntPoint& eventPos, const IntRect& dragImageBounds, DataTransfer& dataTransfer, Frame& frame, bool forLink) 1005 1003 { 1006 1004 FloatPoint dragImageAnchor = { 0.5, 0.5 }; … … 1015 1013 Ref<MainFrame> frameProtector(m_page.mainFrame()); 1016 1014 RefPtr<FrameView> viewProtector = frameProtector->view(); 1017 m_client.startDrag(image , viewProtector->rootViewToContents(frame.view()->contentsToRootView(dragLoc)), viewProtector->rootViewToContents(frame.view()->contentsToRootView(eventPos)), dragImageAnchor, dataTransfer, frameProtector.get(), forLink);1015 m_client.startDrag(image.get(), viewProtector->rootViewToContents(frame.view()->contentsToRootView(dragLoc)), viewProtector->rootViewToContents(frame.view()->contentsToRootView(eventPos)), dragImageAnchor, dataTransfer, frameProtector.get(), forLink); 1018 1016 // DragClient::startDrag can cause our Page to dispear, deallocating |this|. 1019 1017 if (!frameProtector->page()) -
trunk/Source/WebCore/page/DragController.h
r211597 r212154 113 113 114 114 void doImageDrag(Element&, const IntPoint&, const IntRect&, DataTransfer&, Frame&, IntPoint&); 115 void doSystemDrag(DragImage Ref, const IntPoint&, const IntPoint&, const IntRect& dragImageBounds, DataTransfer&, Frame&, bool forLink);115 void doSystemDrag(DragImage, const IntPoint&, const IntPoint&, const IntRect& dragImageBounds, DataTransfer&, Frame&, bool forLink); 116 116 void cleanupAfterSystemDrag(); 117 117 void declareAndWriteDragImage(DataTransfer&, Element&, const URL&, const String& label); -
trunk/Source/WebCore/platform/DragImage.cpp
r211192 r212154 218 218 #endif 219 219 220 DragImage::DragImage() 221 : m_dragImageRef { nullptr } 222 { 223 } 224 225 DragImage::DragImage(DragImageRef dragImageRef) 226 : m_dragImageRef { dragImageRef } 227 { 228 } 229 230 DragImage::DragImage(DragImage&& other) 231 : m_dragImageRef { std::exchange(other.m_dragImageRef, nullptr) } 232 { 233 } 234 235 DragImage& DragImage::operator=(DragImage&& other) 236 { 237 if (m_dragImageRef) 238 deleteDragImage(m_dragImageRef); 239 240 m_dragImageRef = std::exchange(other.m_dragImageRef, nullptr); 241 242 return *this; 243 } 244 245 DragImage::~DragImage() 246 { 247 if (m_dragImageRef) 248 deleteDragImage(m_dragImageRef); 249 } 250 220 251 } // namespace WebCore 221 252 -
trunk/Source/WebCore/platform/DragImage.h
r211597 r212154 91 91 void deleteDragImage(DragImageRef); 92 92 93 class DragImage final { 94 public: 95 DragImage(); 96 explicit DragImage(DragImageRef); 97 DragImage(DragImage&&); 98 ~DragImage(); 99 100 DragImage& operator=(DragImage&&); 101 102 explicit operator bool() const { return !!m_dragImageRef; } 103 DragImageRef get() const { return m_dragImageRef; } 104 105 private: 106 DragImageRef m_dragImageRef; 107 }; 108 93 109 } -
trunk/Source/WebCore/platform/Pasteboard.h
r211192 r212154 24 24 */ 25 25 26 #ifndef Pasteboard_h 27 #define Pasteboard_h 26 #pragma once 28 27 29 28 #include "DragImage.h" … … 183 182 WEBCORE_EXPORT static std::unique_ptr<Pasteboard> createForDragAndDrop(const DragData&); 184 183 185 virtual void setDragImage(DragImage Ref, const IntPoint& hotSpot);184 virtual void setDragImage(DragImage, const IntPoint& hotSpot); 186 185 #endif 187 186 … … 263 262 264 263 } // namespace WebCore 265 266 #endif // Pasteboard_h -
trunk/Source/WebCore/platform/StaticPasteboard.h
r207841 r212154 63 63 64 64 #if ENABLE(DRAG_SUPPORT) 65 void setDragImage(DragImage Ref, const IntPoint&) final { }65 void setDragImage(DragImage, const IntPoint&) final { } 66 66 #endif 67 67 -
trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp
r208576 r212154 120 120 121 121 #if ENABLE(DRAG_SUPPORT) 122 void Pasteboard::setDragImage(DragImage Ref, const IntPoint&)122 void Pasteboard::setDragImage(DragImage, const IntPoint&) 123 123 { 124 124 notImplemented(); -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r208576 r212154 272 272 273 273 #if ENABLE(DRAG_SUPPORT) 274 void Pasteboard::setDragImage(DragImage Ref, const IntPoint&)274 void Pasteboard::setDragImage(DragImage, const IntPoint&) 275 275 { 276 276 } -
trunk/Source/WebCore/platform/mac/PasteboardMac.mm
r211906 r212154 664 664 665 665 #if ENABLE(DRAG_SUPPORT) 666 void Pasteboard::setDragImage(DragImage Refimage, const IntPoint& location)666 void Pasteboard::setDragImage(DragImage image, const IntPoint& location) 667 667 { 668 668 // Don't allow setting the drag image if someone kept a pasteboard and is trying to set the image too late. … … 672 672 // Dashboard wants to be able to set the drag image during dragging, but Cocoa does not allow this. 673 673 // Instead we must drop down to the CoreGraphics API. 674 wkSetDragImage(image.get() , location);674 wkSetDragImage(image.get().get(), location); 675 675 676 676 // Hack: We must post an event to wake up the NSDragManager, which is sitting in a nextEvent call
Note: See TracChangeset
for help on using the changeset viewer.