Bug 388359: Menu items are highlighted as mouse pointer moves below menu. Fix makes GetEventCoordinatesRelativeTo work across window roots. r+sr=roc.

This commit is contained in:
sharparrow1@yahoo.com 2007-07-23 09:44:34 -07:00
Родитель 955e5d5a58
Коммит 7f1f88be47
1 изменённых файлов: 36 добавлений и 9 удалений

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

@ -655,20 +655,47 @@ nsLayoutUtils::GetEventCoordinatesForNearestView(nsEvent* aEvent,
GUIEvent->refPoint, frameView);
}
static nsPoint GetWidgetOffset(nsIWidget* aWidget, nsIWidget*& aRootWidget) {
nsPoint offset(0, 0);
nsIWidget* parent = aWidget->GetParent();
while (parent) {
nsRect bounds;
aWidget->GetBounds(bounds);
offset += bounds.TopLeft();
aWidget = parent;
parent = aWidget->GetParent();
}
aRootWidget = aWidget;
return offset;
}
nsPoint
nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext,
nsIWidget* aWidget, nsIntPoint aPt,
nsIView* aView)
{
nsIView* baseView = nsIView::GetViewFor(aWidget);
if (!baseView)
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
nsPoint viewToWidget;
nsIWidget* wid = baseView->GetNearestWidget(&viewToWidget);
NS_ASSERTION(aWidget == wid, "Clashing widgets");
nsPoint refPointAppUnits(aPresContext->DevPixelsToAppUnits(aPt.x),
aPresContext->DevPixelsToAppUnits(aPt.y));
return refPointAppUnits - viewToWidget - aView->GetOffsetTo(baseView);
nsPoint viewOffset;
nsIWidget* viewWidget = aView->GetNearestWidget(&viewOffset);
nsIWidget* fromRoot;
nsPoint fromOffset = GetWidgetOffset(aWidget, fromRoot);
nsIWidget* toRoot;
nsPoint toOffset = GetWidgetOffset(viewWidget, toRoot);
nsIntPoint widgetPoint;
if (fromRoot == toRoot) {
widgetPoint = aPt + fromOffset - toOffset;
} else {
nsIntRect widgetRect(0, 0, 0, 0);
nsIntRect screenRect;
aWidget->WidgetToScreen(widgetRect, screenRect);
viewWidget->ScreenToWidget(screenRect, widgetRect);
widgetPoint = aPt + widgetRect.TopLeft();
}
nsPoint widgetAppUnits(aPresContext->DevPixelsToAppUnits(widgetPoint.x),
aPresContext->DevPixelsToAppUnits(widgetPoint.y));
return widgetAppUnits - viewOffset;
}
// Combine aNewBreakType with aOrigBreakType, but limit the break types