зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
2ee4fc0f24
Коммит
13d96b2d7e
|
@ -611,8 +611,8 @@ void nsDragService::DragMovedWithView(NSDraggingSession* aSession, NSPoint aPoin
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsPoint pt = LayoutDevicePixel::ToAppUnits(
|
nsPoint pt =
|
||||||
devPoint, pc->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
LayoutDevicePixel::ToAppUnits(devPoint, pc->DeviceContext()->AppUnitsPerDevPixel());
|
||||||
CSSIntPoint screenPoint = CSSIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
CSSIntPoint screenPoint = CSSIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
||||||
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
||||||
|
|
||||||
|
|
|
@ -1931,8 +1931,8 @@ void nsDragService::SetDragIcon(GdkDragContext* aContext) {
|
||||||
DrawDrag(mSourceNode, mRegion, mScreenPosition, &dragRect, &surface, &pc);
|
DrawDrag(mSourceNode, mRegion, mScreenPosition, &dragRect, &surface, &pc);
|
||||||
if (!pc) return;
|
if (!pc) return;
|
||||||
|
|
||||||
LayoutDeviceIntPoint screenPoint =
|
const auto screenPoint =
|
||||||
ConvertToUnscaledDevPixels(pc, mScreenPosition);
|
LayoutDeviceIntPoint::Round(mScreenPosition * pc->CSSToDevPixelScale());
|
||||||
int32_t offsetX = screenPoint.x - dragRect.x;
|
int32_t offsetX = screenPoint.x - dragRect.x;
|
||||||
int32_t offsetY = screenPoint.y - dragRect.y;
|
int32_t offsetY = screenPoint.y - dragRect.y;
|
||||||
|
|
||||||
|
|
|
@ -394,8 +394,7 @@ nsBaseDragService::InvokeDragSessionWithImage(
|
||||||
mSourceWindowContext =
|
mSourceWindowContext =
|
||||||
aDOMNode ? aDOMNode->OwnerDoc()->GetWindowContext() : nullptr;
|
aDOMNode ? aDOMNode->OwnerDoc()->GetWindowContext() : nullptr;
|
||||||
|
|
||||||
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
|
mScreenPosition = aDragEvent->ScreenPoint(CallerType::System);
|
||||||
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
|
|
||||||
mInputSource = aDragEvent->MozInputSource();
|
mInputSource = aDragEvent->MozInputSource();
|
||||||
|
|
||||||
// If dragging within a XUL tree and no custom drag image was
|
// If dragging within a XUL tree and no custom drag image was
|
||||||
|
@ -443,8 +442,7 @@ nsBaseDragService::InvokeDragSessionWithRemoteImage(
|
||||||
mImageOffset = CSSIntPoint(0, 0);
|
mImageOffset = CSSIntPoint(0, 0);
|
||||||
mSourceWindowContext = mDragStartData->GetSourceWindowContext();
|
mSourceWindowContext = mDragStartData->GetSourceWindowContext();
|
||||||
|
|
||||||
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
|
mScreenPosition = aDragEvent->ScreenPoint(CallerType::System);
|
||||||
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
|
|
||||||
mInputSource = aDragEvent->MozInputSource();
|
mInputSource = aDragEvent->MozInputSource();
|
||||||
|
|
||||||
nsresult rv = InvokeDragSession(
|
nsresult rv = InvokeDragSession(
|
||||||
|
@ -692,7 +690,7 @@ nsBaseDragService::DragMoved(int32_t aX, int32_t aY) {
|
||||||
RoundedToInt(LayoutDeviceIntPoint(aX, aY) /
|
RoundedToInt(LayoutDeviceIntPoint(aX, aY) /
|
||||||
frame->PresContext()->CSSToDevPixelScale()) -
|
frame->PresContext()->CSSToDevPixelScale()) -
|
||||||
mImageOffset;
|
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
|
// convert mouse position to dev pixels of the prescontext
|
||||||
CSSIntPoint screenPosition(aScreenPosition);
|
const CSSIntPoint screenPosition = aScreenPosition - mImageOffset;
|
||||||
screenPosition.x -= mImageOffset.x;
|
const auto screenPoint = LayoutDeviceIntPoint::Round(
|
||||||
screenPosition.y -= mImageOffset.y;
|
screenPosition * (*aPresContext)->CSSToDevPixelScale());
|
||||||
LayoutDeviceIntPoint screenPoint =
|
|
||||||
ConvertToUnscaledDevPixels(*aPresContext, screenPosition);
|
|
||||||
aScreenDragRect->MoveTo(screenPoint.x, screenPoint.y);
|
aScreenDragRect->MoveTo(screenPoint.x, screenPoint.y);
|
||||||
|
|
||||||
// check if drag images are disabled
|
// check if drag images are disabled
|
||||||
|
@ -931,15 +927,6 @@ nsresult nsBaseDragService::DrawDragForImage(
|
||||||
return result;
|
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
|
NS_IMETHODIMP
|
||||||
nsBaseDragService::Suppress() {
|
nsBaseDragService::Suppress() {
|
||||||
EndDragSession(false, 0);
|
EndDragSession(false, 0);
|
||||||
|
|
|
@ -121,12 +121,6 @@ class nsBaseDragService : public nsIDragService, public nsIDragSession {
|
||||||
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
||||||
RefPtr<SourceSurface>* aSurface);
|
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.
|
* 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.cx = bmWidth;
|
||||||
psdi->sizeDragImage.cy = bmHeight;
|
psdi->sizeDragImage.cy = bmHeight;
|
||||||
|
|
||||||
LayoutDeviceIntPoint screenPoint =
|
const auto screenPoint =
|
||||||
ConvertToUnscaledDevPixels(pc, mScreenPosition);
|
LayoutDeviceIntPoint::Round(mScreenPosition * pc->CSSToDevPixelScale());
|
||||||
psdi->ptOffset.x = screenPoint.x - dragRect.X();
|
psdi->ptOffset.x = screenPoint.x - dragRect.X();
|
||||||
psdi->ptOffset.y = screenPoint.y - dragRect.Y();
|
psdi->ptOffset.y = screenPoint.y - dragRect.Y();
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче