Bug 681192. Part 13: Make nsDOMWindowUtils event coordinate calculations more accurate. r=matspal

--HG--
extra : rebase_source : fef4ef568baf1a67038aeb0e187511771fe0d565
This commit is contained in:
Robert O'Callahan 2012-05-10 17:24:20 +12:00
Родитель 2433703320
Коммит b3c1f50812
1 изменённых файлов: 14 добавлений и 29 удалений

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

@ -524,6 +524,16 @@ nsDOMWindowUtils::SendMouseEventToWindow(const nsAString& aType,
aIgnoreRootScrollFrame, true); aIgnoreRootScrollFrame, true);
} }
static nsIntPoint
ToWidgetPoint(float aX, float aY, const nsPoint& aOffset,
nsPresContext* aPresContext)
{
double appPerDev = aPresContext->AppUnitsPerDevPixel();
nscoord appPerCSS = nsPresContext::AppUnitsPerCSSPixel();
return nsIntPoint(NSToIntRound((aX*appPerCSS + aOffset.x)/appPerDev),
NSToIntRound((aY*appPerCSS + aOffset.y)/appPerDev));
}
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType, nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
float aX, float aX,
@ -577,13 +587,7 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
if (!presContext) if (!presContext)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
PRInt32 appPerDev = presContext->AppUnitsPerDevPixel(); event.refPoint = ToWidgetPoint(aX, aY, offset, presContext);
event.refPoint.x =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aX) + offset.x,
appPerDev);
event.refPoint.y =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aY) + offset.y,
appPerDev);
event.ignoreRootScrollFrame = aIgnoreRootScrollFrame; event.ignoreRootScrollFrame = aIgnoreRootScrollFrame;
nsEventStatus status; nsEventStatus status;
@ -644,13 +648,7 @@ nsDOMWindowUtils::SendMouseScrollEvent(const nsAString& aType,
if (!presContext) if (!presContext)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
PRInt32 appPerDev = presContext->AppUnitsPerDevPixel(); event.refPoint = ToWidgetPoint(aX, aY, offset, presContext);
event.refPoint.x =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aX) + offset.x,
appPerDev);
event.refPoint.y =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aY) + offset.y,
appPerDev);
nsEventStatus status; nsEventStatus status;
return widget->DispatchEvent(&event, status); return widget->DispatchEvent(&event, status);
@ -703,15 +701,8 @@ nsDOMWindowUtils::SendTouchEvent(const nsAString& aType,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
event.touches.SetCapacity(aCount); event.touches.SetCapacity(aCount);
PRInt32 appPerDev = presContext->AppUnitsPerDevPixel();
for (PRUint32 i = 0; i < aCount; ++i) { for (PRUint32 i = 0; i < aCount; ++i) {
nsIntPoint pt(0, 0); nsIntPoint pt = ToWidgetPoint(aXs[i], aYs[i], offset, presContext);
pt.x =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aXs[i]) + offset.x,
appPerDev);
pt.y =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aYs[i]) + offset.y,
appPerDev);
nsCOMPtr<nsIDOMTouch> t(new nsDOMTouch(aIdentifiers[i], nsCOMPtr<nsIDOMTouch> t(new nsDOMTouch(aIdentifiers[i],
pt, pt,
nsIntPoint(aRxs[i], aRys[i]), nsIntPoint(aRxs[i], aRys[i]),
@ -1081,13 +1072,7 @@ nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType,
if (!presContext) if (!presContext)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
PRInt32 appPerDev = presContext->AppUnitsPerDevPixel(); event.refPoint = ToWidgetPoint(aX, aY, offset, presContext);
event.refPoint.x =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aX) + offset.x,
appPerDev);
event.refPoint.y =
NSAppUnitsToIntPixels(nsPresContext::CSSPixelsToAppUnits(aY) + offset.y,
appPerDev);
nsEventStatus status; nsEventStatus status;
return widget->DispatchEvent(&event, status); return widget->DispatchEvent(&event, status);