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 16:44:34 +00:00
Родитель 3a62533f47
Коммит 2fd8ec2db1
1 изменённых файлов: 36 добавлений и 9 удалений

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

@ -655,20 +655,47 @@ nsLayoutUtils::GetEventCoordinatesForNearestView(nsEvent* aEvent,
GUIEvent->refPoint, frameView); 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 nsPoint
nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext, nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext,
nsIWidget* aWidget, nsIntPoint aPt, nsIWidget* aWidget, nsIntPoint aPt,
nsIView* aView) nsIView* aView)
{ {
nsIView* baseView = nsIView::GetViewFor(aWidget); nsPoint viewOffset;
if (!baseView) nsIWidget* viewWidget = aView->GetNearestWidget(&viewOffset);
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
nsPoint viewToWidget; nsIWidget* fromRoot;
nsIWidget* wid = baseView->GetNearestWidget(&viewToWidget); nsPoint fromOffset = GetWidgetOffset(aWidget, fromRoot);
NS_ASSERTION(aWidget == wid, "Clashing widgets"); nsIWidget* toRoot;
nsPoint refPointAppUnits(aPresContext->DevPixelsToAppUnits(aPt.x), nsPoint toOffset = GetWidgetOffset(viewWidget, toRoot);
aPresContext->DevPixelsToAppUnits(aPt.y));
return refPointAppUnits - viewToWidget - aView->GetOffsetTo(baseView); 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 // Combine aNewBreakType with aOrigBreakType, but limit the break types