Bug 510388, check descendant documents for focus when closing popups, r=bz,sr=smaug

This commit is contained in:
Neil Deakin 2009-08-27 08:51:41 -07:00
parent d688108446
commit 3028324937
4 changed files with 37 additions and 2 deletions

View File

@ -29,6 +29,7 @@ function testCustomizeFrameLoaded()
var framedoc = document.getElementById("customizeToolbarSheetIFrame").contentDocument;
var b = framedoc.getElementById("donebutton");
b.focus();
framedoc.getElementById("donebutton").doCommand();
}
@ -36,5 +37,7 @@ function testCustomizePopupHidden()
{
var panel = document.getElementById("customizeToolbarSheetPopup");
panel.removeEventListener("popuphidden", testCustomizePopupHidden, false);
is(document.activeElement, document.documentElement, "focus after customize done");
finish();
}

View File

@ -211,6 +211,12 @@ public:
static PRBool ContentIsDescendantOf(nsINode* aPossibleDescendant,
nsINode* aPossibleAncestor);
/**
* Similar to ContentIsDescendantOf except it crosses document boundaries.
*/
static PRBool ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant,
nsINode* aPossibleAncestor);
/*
* This method fills the |aArray| with all ancestor nodes of |aNode|
* including |aNode| at the zero index.

View File

@ -1409,6 +1409,32 @@ nsContentUtils::ContentIsDescendantOf(nsINode* aPossibleDescendant,
return PR_FALSE;
}
// static
PRBool
nsContentUtils::ContentIsCrossDocDescendantOf(nsINode* aPossibleDescendant,
nsINode* aPossibleAncestor)
{
NS_PRECONDITION(aPossibleDescendant, "The possible descendant is null!");
NS_PRECONDITION(aPossibleAncestor, "The possible ancestor is null!");
do {
if (aPossibleDescendant == aPossibleAncestor)
return PR_TRUE;
nsINode* parent = aPossibleDescendant->GetNodeParent();
if (!parent && aPossibleDescendant->IsNodeOfType(nsINode::eDOCUMENT)) {
nsIDocument* doc = static_cast<nsIDocument*>(aPossibleDescendant);
nsIDocument* parentDoc = doc->GetParentDocument();
aPossibleDescendant = parentDoc ?
parentDoc->FindContentForSubDocument(doc) : nsnull;
}
else {
aPossibleDescendant = parent;
}
} while (aPossibleDescendant);
return PR_FALSE;
}
// static
nsresult

View File

@ -1043,7 +1043,7 @@ nsXULPopupManager::FirePopupShowingEvent(nsIContent* aPopup,
fm->GetFocusedElement(getter_AddRefs(currentFocusElement));
nsCOMPtr<nsIContent> currentFocus = do_QueryInterface(currentFocusElement);
if (doc && currentFocus &&
!nsContentUtils::ContentIsDescendantOf(currentFocus, aPopup)) {
!nsContentUtils::ContentIsCrossDocDescendantOf(currentFocus, aPopup)) {
fm->ClearFocus(doc->GetWindow());
}
}
@ -1101,7 +1101,7 @@ nsXULPopupManager::FirePopupHidingEvent(nsIContent* aPopup,
fm->GetFocusedElement(getter_AddRefs(currentFocusElement));
nsCOMPtr<nsIContent> currentFocus = do_QueryInterface(currentFocusElement);
if (doc && currentFocus &&
nsContentUtils::ContentIsDescendantOf(currentFocus, aPopup)) {
nsContentUtils::ContentIsCrossDocDescendantOf(currentFocus, aPopup)) {
fm->ClearFocus(doc->GetWindow());
}
}