I'm overriding draggingUpdated:
in a WebView
subclass. This way I'm able to get the NSPoint
where the drag destination currently is [(id<NSDraggingInfo>)sender draggingLocation]
I want to get this NSPoint
and "convert" it to coordinates within the WebView
, and then get the underlying element at that point with WebView
's elementAtPoint:
The thing is, I got the NSPoint
, and I also have the bounds/frame of the WebView. How is this convertible?
It is not correct to use -convertPointFromBase:
for this. That method is deprecated and the suggested replacement (-convertPointFromBacking:
) is not right for this purpose because it assumes the input point is in the backing store coordinate system. (That actually gives a hint as to the original purpose of -convertPointFromBase:
, which was part of the now-abandoned, Leopard-era attempts at high-resolution support. The "base coordinate system" it converts from was supposed to be pixel-aligned. Search for 'Pixel Alignment and Transforming View Coordinates To and From "Base" Space' in the Leopard AppKit release notes.)
You want -convertPoint:fromView:
and you should pass nil
for the fromView
parameter. See Cocoa Drawing Guide: Coordinate Systems and Transforms – Converting from Window to View Coordinates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With