Bug 510008, clientX/Y not correct in popupshowing event for popup inside a frame, fix to use correct widget for event, r=roc

This commit is contained in:
Neil Deakin 2009-09-03 15:30:07 -04:00
Родитель b79a438dd5
Коммит f531f1f8e3
2 изменённых файлов: 60 добавлений и 17 удалений

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

@ -1018,7 +1018,12 @@ nsXULPopupManager::FirePopupShowingEvent(nsIContent* aPopup,
// all the globals people keep adding to nsIDOMXULDocument.
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull, nsMouseEvent::eReal);
presShell->GetViewManager()->GetRootWidget(getter_AddRefs(event.widget));
// coordinates are relative to the root widget
nsPresContext* rootPresContext =
presShell->GetPresContext()->RootPresContext();
rootPresContext->PresShell()->GetViewManager()->GetRootWidget(getter_AddRefs(event.widget));
event.refPoint = mCachedMousePoint;
nsEventDispatcher::Dispatch(aPopup, aPresContext, &event, nsnull, &status);
mCachedMousePoint = nsIntPoint(0, 0);

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

@ -3,39 +3,77 @@
<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<menupopup id="popup" onpopupshown="popupShown()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<menupopup id="popup" onpopupshowing="if (isSecondTest) popupShowing(event)" onpopupshown="popupShown()"
onpopuphidden="nextTest()">
<menuitem label="One"/>
<menuitem label="Two"/>
</menupopup>
<button id="button" label="OK" popup="popup"/>
<script class="testbody" type="application/javascript">
<![CDATA[
var isSecondTest = false;
function openPopup()
{
document.getElementById("popup").openPopup(parent.document.getElementById("outerbutton"), "after_start", 3, 1);
}
function popupShowing(event)
{
var buttonrect = document.getElementById("button").getBoundingClientRect();
parent.opener.wrappedJSObject.SimpleTest.is(event.clientX, buttonrect.left + 6, "popup clientX with mouse");
parent.opener.wrappedJSObject.SimpleTest.is(event.clientY, buttonrect.top + 6, "popup clientY with mouse");
}
function popupShown()
{
var left, top;
var popuprect = document.getElementById("popup").getBoundingClientRect();
var iframerect = parent.document.getElementById("frame").getBoundingClientRect();
var buttonrect = parent.document.getElementById("outerbutton").getBoundingClientRect();
if (isSecondTest) {
var buttonrect = document.getElementById("button").getBoundingClientRect();
left = buttonrect.left + 6;
top = buttonrect.top + 6;
}
else {
var iframerect = parent.document.getElementById("frame").getBoundingClientRect();
var buttonrect = parent.document.getElementById("outerbutton").getBoundingClientRect();
// The popup should appear anchored on the bottom left edge of the button, however
// the client rectangle is relative to the iframe's document. Thus the coordinates
// are:
// left = iframe's left - anchor button's left - 3 pixel offset passed to openPopup +
// iframe border (17px) + iframe padding (0)
// top = iframe's top - anchor button's bottom - 1 pixel offset passed to openPopup +
// iframe border (0) + iframe padding (3px);
var left = -(Math.round(iframerect.left) - Math.round(buttonrect.left) + 14);
var top = -(Math.round(iframerect.top) - Math.round(buttonrect.bottom) + 2);
// The popup should appear anchored on the bottom left edge of the button, however
// the client rectangle is relative to the iframe's document. Thus the coordinates
// are:
// left = iframe's left - anchor button's left - 3 pixel offset passed to openPopup +
// iframe border (17px) + iframe padding (0)
// top = iframe's top - anchor button's bottom - 1 pixel offset passed to openPopup +
// iframe border (0) + iframe padding (3px);
left = -(Math.round(iframerect.left) - Math.round(buttonrect.left) + 14);
top = -(Math.round(iframerect.top) - Math.round(buttonrect.bottom) + 2);
}
parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.left), left, "popup left");
parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.top), top, "popup top");
parent.opener.wrappedJSObject.SimpleTest.finish();
parent.close();
var testid = isSecondTest ? "with mouse" : "anchored to parent frame";
parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.left), left, "popup left " + testid);
parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.top), top, "popup top " + testid);
document.getElementById("popup").hidePopup();
}
function nextTest()
{
if (isSecondTest) {
parent.opener.wrappedJSObject.SimpleTest.finish();
parent.close();
}
else {
// this second test ensures that the popupshowing coordinates when a popup in
// a frame is opened are correct
isSecondTest = true;
synthesizeMouse(document.getElementById("button"), 6, 6, { });
}
}
]]>