Bug 1767944 - Fix drag image coordinates after bug 1753836. r=tnikkel

The existing code was relying on the drag event coordinates being
already unscaled by the zoom, which bug 1753836 fixed.

This simplifies the relevant code and fixes the bug.

Differential Revision: https://phabricator.services.mozilla.com/D145578
This commit is contained in:
Emilio Cobos Álvarez 2022-05-05 12:10:08 +00:00
Родитель 2ee4fc0f24
Коммит 13d96b2d7e
5 изменённых файлов: 12 добавлений и 31 удалений

Просмотреть файл

@ -611,8 +611,8 @@ void nsDragService::DragMovedWithView(NSDraggingSession* aSession, NSPoint aPoin
return;
}
nsPoint pt = LayoutDevicePixel::ToAppUnits(
devPoint, pc->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
nsPoint pt =
LayoutDevicePixel::ToAppUnits(devPoint, pc->DeviceContext()->AppUnitsPerDevPixel());
CSSIntPoint screenPoint = CSSIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
nsPresContext::AppUnitsToIntCSSPixels(pt.y));

Просмотреть файл

@ -1931,8 +1931,8 @@ void nsDragService::SetDragIcon(GdkDragContext* aContext) {
DrawDrag(mSourceNode, mRegion, mScreenPosition, &dragRect, &surface, &pc);
if (!pc) return;
LayoutDeviceIntPoint screenPoint =
ConvertToUnscaledDevPixels(pc, mScreenPosition);
const auto screenPoint =
LayoutDeviceIntPoint::Round(mScreenPosition * pc->CSSToDevPixelScale());
int32_t offsetX = screenPoint.x - dragRect.x;
int32_t offsetY = screenPoint.y - dragRect.y;

Просмотреть файл

@ -394,8 +394,7 @@ nsBaseDragService::InvokeDragSessionWithImage(
mSourceWindowContext =
aDOMNode ? aDOMNode->OwnerDoc()->GetWindowContext() : nullptr;
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
mScreenPosition = aDragEvent->ScreenPoint(CallerType::System);
mInputSource = aDragEvent->MozInputSource();
// If dragging within a XUL tree and no custom drag image was
@ -443,8 +442,7 @@ nsBaseDragService::InvokeDragSessionWithRemoteImage(
mImageOffset = CSSIntPoint(0, 0);
mSourceWindowContext = mDragStartData->GetSourceWindowContext();
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
mScreenPosition = aDragEvent->ScreenPoint(CallerType::System);
mInputSource = aDragEvent->MozInputSource();
nsresult rv = InvokeDragSession(
@ -692,7 +690,7 @@ nsBaseDragService::DragMoved(int32_t aX, int32_t aY) {
RoundedToInt(LayoutDeviceIntPoint(aX, aY) /
frame->PresContext()->CSSToDevPixelScale()) -
mImageOffset;
(static_cast<nsMenuPopupFrame*>(frame))->MoveTo(cssPos, true);
static_cast<nsMenuPopupFrame*>(frame)->MoveTo(cssPos, true);
}
}
@ -753,11 +751,9 @@ nsresult nsBaseDragService::DrawDrag(nsINode* aDOMNode,
}
// convert mouse position to dev pixels of the prescontext
CSSIntPoint screenPosition(aScreenPosition);
screenPosition.x -= mImageOffset.x;
screenPosition.y -= mImageOffset.y;
LayoutDeviceIntPoint screenPoint =
ConvertToUnscaledDevPixels(*aPresContext, screenPosition);
const CSSIntPoint screenPosition = aScreenPosition - mImageOffset;
const auto screenPoint = LayoutDeviceIntPoint::Round(
screenPosition * (*aPresContext)->CSSToDevPixelScale());
aScreenDragRect->MoveTo(screenPoint.x, screenPoint.y);
// check if drag images are disabled
@ -931,15 +927,6 @@ nsresult nsBaseDragService::DrawDragForImage(
return result;
}
LayoutDeviceIntPoint nsBaseDragService::ConvertToUnscaledDevPixels(
nsPresContext* aPresContext, CSSIntPoint aScreenPosition) {
int32_t adj =
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
return LayoutDeviceIntPoint(
nsPresContext::CSSPixelsToAppUnits(aScreenPosition.x) / adj,
nsPresContext::CSSPixelsToAppUnits(aScreenPosition.y) / adj);
}
NS_IMETHODIMP
nsBaseDragService::Suppress() {
EndDragSession(false, 0);

Просмотреть файл

@ -121,12 +121,6 @@ class nsBaseDragService : public nsIDragService, public nsIDragSession {
mozilla::LayoutDeviceIntRect* aScreenDragRect,
RefPtr<SourceSurface>* aSurface);
/**
* Convert aScreenPosition from CSS pixels into unscaled device pixels.
*/
mozilla::LayoutDeviceIntPoint ConvertToUnscaledDevPixels(
nsPresContext* aPresContext, mozilla::CSSIntPoint aScreenPosition);
/**
* If the drag image is a popup, open the popup when the drag begins.
*/

Просмотреть файл

@ -133,8 +133,8 @@ bool nsDragService::CreateDragImage(nsINode* aDOMNode,
psdi->sizeDragImage.cx = bmWidth;
psdi->sizeDragImage.cy = bmHeight;
LayoutDeviceIntPoint screenPoint =
ConvertToUnscaledDevPixels(pc, mScreenPosition);
const auto screenPoint =
LayoutDeviceIntPoint::Round(mScreenPosition * pc->CSSToDevPixelScale());
psdi->ptOffset.x = screenPoint.x - dragRect.X();
psdi->ptOffset.y = screenPoint.y - dragRect.Y();