- Revision
- 216303
- Author
- [email protected]
- Date
- 2017-05-05 18:39:00 -0700 (Fri, 05 May 2017)
Log Message
[Mac] Adjust cursor position for dragged link (and stop it from moving based on how fast you are dragging)
https://bugs.webkit.org/show_bug.cgi?id=171764
<rdar://problem/32005865>
Reviewed by Simon Fraser.
* page/DragController.cpp:
(WebCore::DragController::startDrag):
Compute dragImageAnchorPoint only if it is needed.
Don't compute a random unused imageRect.
Factor link drag image offset computation out into DragImage functions
for platforms to override.
Pass dragOrigin (the mouseDown point), not mouseDraggedPoint, to
doSystemDrag, just like all the other drag types. This plus the
WebKit2 change makes the link stable vs. the cursor, instead of
positioned based on how fast you move after the mouse down.
* page/DragController.h:
* page/gtk/DragControllerGtk.cpp:
* page/mac/DragControllerMac.mm:
* page/win/DragControllerWin.cpp:
Move LinkDragBorderInset into DragImage, and share between the non-Mac platforms.
* platform/DragImage.cpp:
(WebCore::dragOffsetForLinkDragImage):
(WebCore::anchorPointForLinkDragImage):
* platform/DragImage.h:
As previously mentioned, move the computation of drag image offset here.
* platform/mac/DragImageMac.mm:
(WebCore::dragOffsetForLinkDragImage):
(WebCore::anchorPointForLinkDragImage):
Put the new drag image to the bottom right of the cursor.
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::dragImageForView):
Always use the last mouse down event to originate the drag; this was a 2004 hack
to work around a seemingly-fixed macOS bug that somehow propagated into WebKit2.
With WebKit2, this would cause trouble because currentEvent could move on
during the bounce to the Web Content process and back, causing the delta between
clientPoint and the mouse point to be dependent on timing, and thus causing the
link to sit at timing-dependent distance from the cursor, instead of exactly
where dragOffsetForLinkDragImage placed it.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (216302 => 216303)
--- trunk/Source/WebCore/ChangeLog 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/ChangeLog 2017-05-06 01:39:00 UTC (rev 216303)
@@ -1,3 +1,40 @@
+2017-05-05 Timothy Horton <[email protected]>
+
+ [Mac] Adjust cursor position for dragged link (and stop it from moving based on how fast you are dragging)
+ https://bugs.webkit.org/show_bug.cgi?id=171764
+ <rdar://problem/32005865>
+
+ Reviewed by Simon Fraser.
+
+ * page/DragController.cpp:
+ (WebCore::DragController::startDrag):
+ Compute dragImageAnchorPoint only if it is needed.
+ Don't compute a random unused imageRect.
+ Factor link drag image offset computation out into DragImage functions
+ for platforms to override.
+
+ Pass dragOrigin (the mouseDown point), not mouseDraggedPoint, to
+ doSystemDrag, just like all the other drag types. This plus the
+ WebKit2 change makes the link stable vs. the cursor, instead of
+ positioned based on how fast you move after the mouse down.
+
+ * page/DragController.h:
+ * page/gtk/DragControllerGtk.cpp:
+ * page/mac/DragControllerMac.mm:
+ * page/win/DragControllerWin.cpp:
+ Move LinkDragBorderInset into DragImage, and share between the non-Mac platforms.
+
+ * platform/DragImage.cpp:
+ (WebCore::dragOffsetForLinkDragImage):
+ (WebCore::anchorPointForLinkDragImage):
+ * platform/DragImage.h:
+ As previously mentioned, move the computation of drag image offset here.
+
+ * platform/mac/DragImageMac.mm:
+ (WebCore::dragOffsetForLinkDragImage):
+ (WebCore::anchorPointForLinkDragImage):
+ Put the new drag image to the bottom right of the cursor.
+
2017-05-05 Dean Jackson <[email protected]>
...and now the GTK and Windows builds.
Modified: trunk/Source/WebCore/page/DragController.cpp (216302 => 216303)
--- trunk/Source/WebCore/page/DragController.cpp 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/page/DragController.cpp 2017-05-06 01:39:00 UTC (rev 216303)
@@ -864,7 +864,6 @@
m_sourceDragOperation = srcOp;
DragImage dragImage;
- FloatPoint dragImageAnchorPoint;
IntPoint dragLoc(0, 0);
IntPoint dragImageOffset(0, 0);
@@ -946,7 +945,6 @@
if (textIndicator.contentImage)
dragImage.setIndicatorData(textIndicator);
dragLoc = dragLocForSelectionDrag(src);
- dragImageAnchorPoint = dragImageAnchorPointForSelectionDrag(src, mouseDraggedPoint);
m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y());
}
@@ -959,8 +957,8 @@
}
DragItem dragItem;
+ dragItem.imageAnchorPoint = dragImageAnchorPointForSelectionDrag(src, mouseDraggedPoint);
dragItem.image = WTFMove(dragImage);
- dragItem.imageAnchorPoint = dragImageAnchorPoint;
dragItem.data = ""
beginDrag(WTFMove(dragItem), src, dragOrigin, mouseDraggedPoint, dataTransfer, DragSourceActionSelection);
@@ -986,11 +984,9 @@
m_client.willPerformDragSourceAction(DragSourceActionImage, dragOrigin, dataTransfer);
- if (!dragImage) {
- IntRect imageRect = hitTestResult.imageRect();
- imageRect.setLocation(m_page.mainFrame().view()->rootViewToContents(src.view()->contentsToRootView(imageRect.location())));
+ if (!dragImage)
doImageDrag(element, dragOrigin, hitTestResult.imageRect(), dataTransfer, src, m_dragOffset);
- } else {
+ else {
// DHTML defined drag image
doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, DragSourceActionImage);
}
@@ -1035,24 +1031,22 @@
TextIndicatorData textIndicator;
dragImage = DragImage { createDragImageForLink(element, linkURL, textContentWithSimplifiedWhiteSpace, textIndicator, src.settings().fontRenderingMode(), m_page.deviceScaleFactor()) };
if (dragImage) {
- IntSize size = dragImageSize(dragImage.get());
- m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset);
- dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y());
+ m_dragOffset = dragOffsetForLinkDragImage(dragImage.get());
+ dragLoc = IntPoint(dragOrigin.x() + m_dragOffset.x(), dragOrigin.y() + m_dragOffset.y());
dragImage = DragImage { platformAdjustDragImageForDeviceScaleFactor(dragImage.get(), m_page.deviceScaleFactor()) };
if (textIndicator.contentImage)
dragImage.setIndicatorData(textIndicator);
- dragImageAnchorPoint = FloatPoint { 0.5, static_cast<float>((size.height() - LinkDragBorderInset) / size.height()) };
}
}
if (mustUseLegacyDragClient) {
- doSystemDrag(WTFMove(dragImage), dragLoc, mouseDraggedPoint, { }, dataTransfer, src, DragSourceActionLink);
+ doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, { }, dataTransfer, src, DragSourceActionLink);
return true;
}
DragItem dragItem;
+ dragItem.imageAnchorPoint = dragImage ? anchorPointForLinkDragImage(dragImage.get()) : FloatPoint();
dragItem.image = WTFMove(dragImage);
- dragItem.imageAnchorPoint = dragImageAnchorPoint;
dragItem.data = ""
beginDrag(WTFMove(dragItem), src, dragOrigin, mouseDraggedPoint, dataTransfer, DragSourceActionSelection);
Modified: trunk/Source/WebCore/page/DragController.h (216302 => 216303)
--- trunk/Source/WebCore/page/DragController.h 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/page/DragController.h 2017-05-06 01:39:00 UTC (rev 216303)
@@ -94,7 +94,6 @@
bool startDrag(Frame& src, const DragState&, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin);
static const IntSize& maxDragImageSize();
- static const int LinkDragBorderInset;
static const int MaxOriginalImageArea;
static const int DragIconRightInset;
static const int DragIconBottomInset;
Modified: trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp (216302 => 216303)
--- trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp 2017-05-06 01:39:00 UTC (rev 216303)
@@ -39,7 +39,6 @@
// FIXME: These values are straight out of DragControllerMac, so probably have
// little correlation with Gdk standards...
-const int DragController::LinkDragBorderInset = 2;
const int DragController::MaxOriginalImageArea = 1500 * 1500;
const int DragController::DragIconRightInset = 7;
const int DragController::DragIconBottomInset = 3;
Modified: trunk/Source/WebCore/page/mac/DragControllerMac.mm (216302 => 216303)
--- trunk/Source/WebCore/page/mac/DragControllerMac.mm 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/page/mac/DragControllerMac.mm 2017-05-06 01:39:00 UTC (rev 216303)
@@ -50,8 +50,6 @@
namespace WebCore {
-const int DragController::LinkDragBorderInset = -10;
-
const int DragController::MaxOriginalImageArea = 1500 * 1500;
const int DragController::DragIconRightInset = 7;
const int DragController::DragIconBottomInset = 3;
Modified: trunk/Source/WebCore/page/win/DragControllerWin.cpp (216302 => 216303)
--- trunk/Source/WebCore/page/win/DragControllerWin.cpp 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/page/win/DragControllerWin.cpp 2017-05-06 01:39:00 UTC (rev 216303)
@@ -36,7 +36,6 @@
namespace WebCore {
-const int DragController::LinkDragBorderInset = 2;
const int DragController::MaxOriginalImageArea = 1500 * 1500;
const int DragController::DragIconRightInset = 7;
const int DragController::DragIconBottomInset = 3;
Modified: trunk/Source/WebCore/platform/DragImage.cpp (216302 => 216303)
--- trunk/Source/WebCore/platform/DragImage.cpp 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/platform/DragImage.cpp 2017-05-06 01:39:00 UTC (rev 216303)
@@ -226,6 +226,22 @@
}
#endif
+#if !PLATFORM(MAC)
+const int linkDragBorderInset = 2;
+
+IntPoint dragOffsetForLinkDragImage(DragImageRef dragImage)
+{
+ IntSize size = dragImageSize(dragImage);
+ return { -size.width() / 2, -linkDragBorderInset };
+}
+
+FloatPoint anchorPointForLinkDragImage(DragImageRef dragImage)
+{
+ IntSize size = dragImageSize(dragImage);
+ return { 0.5, static_cast<float>((size.height() - linkDragBorderInset) / size.height()) };
+}
+#endif
+
DragImage::DragImage()
: m_dragImageRef { nullptr }
{
Modified: trunk/Source/WebCore/platform/DragImage.h (216302 => 216303)
--- trunk/Source/WebCore/platform/DragImage.h 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/platform/DragImage.h 2017-05-06 01:39:00 UTC (rev 216303)
@@ -92,6 +92,9 @@
DragImageRef createDragImageForLink(Element&, URL&, const String& label, TextIndicatorData&, FontRenderingMode, float deviceScaleFactor);
void deleteDragImage(DragImageRef);
+IntPoint dragOffsetForLinkDragImage(DragImageRef);
+FloatPoint anchorPointForLinkDragImage(DragImageRef);
+
class DragImage final {
public:
DragImage();
Modified: trunk/Source/WebCore/platform/mac/DragImageMac.mm (216302 => 216303)
--- trunk/Source/WebCore/platform/mac/DragImageMac.mm 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebCore/platform/mac/DragImageMac.mm 2017-05-06 01:39:00 UTC (rev 216303)
@@ -154,13 +154,27 @@
}
-const CGFloat linkImagePadding = 10; // Keep in sync with DragController::LinkDragBorderInset.
+const CGFloat linkImagePadding = 10;
const CGFloat linkImageDomainBaselineToTitleBaseline = 18;
const CGFloat linkImageCornerRadius = 5;
const CGFloat linkImageMaximumWidth = 400;
const CGFloat linkImageFontSize = 11;
const CFIndex linkImageTitleMaximumLineCount = 2;
+const int linkImageDragCornerOutsetX = 6;
+const int linkImageDragCornerOutsetY = 10;
+IntPoint dragOffsetForLinkDragImage(DragImageRef dragImage)
+{
+ IntSize size = dragImageSize(dragImage);
+ return { linkImageDragCornerOutsetX, size.height() + linkImageDragCornerOutsetY };
+}
+
+FloatPoint anchorPointForLinkDragImage(DragImageRef dragImage)
+{
+ IntSize size = dragImageSize(dragImage);
+ return { -static_cast<float>(linkImageDragCornerOutsetX) / size.width(), -static_cast<float>(linkImageDragCornerOutsetY) / size.height() };
+}
+
struct LinkImageLayout {
LinkImageLayout(URL&, const String& title);
Modified: trunk/Source/WebKit2/ChangeLog (216302 => 216303)
--- trunk/Source/WebKit2/ChangeLog 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebKit2/ChangeLog 2017-05-06 01:39:00 UTC (rev 216303)
@@ -1,3 +1,21 @@
+2017-05-05 Timothy Horton <[email protected]>
+
+ [Mac] Adjust cursor position for dragged link (and stop it from moving based on how fast you are dragging)
+ https://bugs.webkit.org/show_bug.cgi?id=171764
+ <rdar://problem/32005865>
+
+ Reviewed by Simon Fraser.
+
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::dragImageForView):
+ Always use the last mouse down event to originate the drag; this was a 2004 hack
+ to work around a seemingly-fixed macOS bug that somehow propagated into WebKit2.
+ With WebKit2, this would cause trouble because currentEvent could move on
+ during the bounce to the Web Content process and back, causing the delta between
+ clientPoint and the mouse point to be dependent on timing, and thus causing the
+ link to sit at timing-dependent distance from the cursor, instead of exactly
+ where dragOffsetForLinkDragImage placed it.
+
2017-05-05 Brady Eidson <[email protected]>
API test WebKit2.WebsiteDataStoreCustomPaths is failing on ios-simulator.
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (216302 => 216303)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2017-05-06 01:10:32 UTC (rev 216302)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2017-05-06 01:39:00 UTC (rev 216303)
@@ -3765,7 +3765,7 @@
}
#endif
-void WebViewImpl::dragImageForView(NSView *view, NSImage *image, CGPoint clientPoint, bool linkDrag)
+void WebViewImpl::dragImageForView(NSView *view, NSImage *image, CGPoint clientPoint, bool)
{
// The call below could release the view.
RetainPtr<NSView> protector(m_view);
@@ -3779,7 +3779,7 @@
[view dragImage:image
at:NSPointFromCGPoint(clientPoint)
offset:NSZeroSize
- event:linkDrag ? [NSApp currentEvent] : m_lastMouseDownEvent.get()
+ event:m_lastMouseDownEvent.get()
pasteboard:pasteboard
source:m_view
slideBack:YES];