зеркало из https://github.com/mozilla/gecko-dev.git
reorganize SetFocus to be less likely to bail early on errors; more likely to default to focusing the whole window. and strip the extraneous braces rods added to my previous fix for this bug :) bug 50881 gets slapped down one more time. r=bryner,hyatt a=asa
This commit is contained in:
Родитель
89d2873215
Коммит
5389a6bb30
|
@ -2629,99 +2629,93 @@ NS_IMETHODIMP
|
||||||
nsDocShell::SetFocus()
|
nsDocShell::SetFocus()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_DOCSHELL_FOCUS
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
||||||
printf("nsDocShell::SetFocus %p\n", (nsIDocShell*)this);
|
printf("nsDocShell::SetFocus %p\n", (nsIDocShell*)this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
nsCOMPtr<nsIDocument> document;
|
GetPresShell(getter_AddRefs(presShell));
|
||||||
GetPresShell(getter_AddRefs(presShell));
|
if (!presShell)
|
||||||
if (!presShell)
|
return NS_ERROR_FAILURE;
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPresContext> presContext;
|
|
||||||
GetPresContext(getter_AddRefs(presContext));
|
|
||||||
if (!presContext)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
/* Check to make sure the root frame for this document
|
|
||||||
is not collapsed. */
|
|
||||||
nsIFrame* rootFrame;
|
|
||||||
presShell->GetRootFrame(&rootFrame);
|
|
||||||
if (!rootFrame)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
|
/* Check to make sure the root frame for this document
|
||||||
|
is not collapsed. */
|
||||||
|
nsIFrame* rootFrame;
|
||||||
|
presShell->GetRootFrame(&rootFrame);
|
||||||
|
if (rootFrame) {
|
||||||
nsRect frameRect;
|
nsRect frameRect;
|
||||||
rootFrame->GetRect(frameRect);
|
rootFrame->GetRect(frameRect);
|
||||||
if (frameRect.IsEmpty()) {
|
if (frameRect.IsEmpty()) {
|
||||||
#ifdef DEBUG_bryner
|
#ifdef DEBUG_bryner
|
||||||
printf("SetFocus: empty frame rect, not accepting focus\n");
|
printf("SetFocus: empty frame rect, not accepting focus\n");
|
||||||
#endif
|
#endif
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIEventStateManager> esm;
|
nsCOMPtr<nsIDocument> document;
|
||||||
|
presShell->GetDocument(getter_AddRefs(document));
|
||||||
|
|
||||||
|
// Figure out what type of document this is
|
||||||
|
// if parent doc is content then set focus to document itself
|
||||||
|
// and set the "special" flag so it knows we are at the beginning
|
||||||
|
// of the document
|
||||||
|
PRBool doFocusDoc = PR_FALSE;
|
||||||
|
nsIDocShellTreeItem* treeItem = NS_STATIC_CAST(nsIDocShellTreeItem *, this);
|
||||||
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||||
|
treeItem->GetParent(getter_AddRefs(parentItem));
|
||||||
|
if (parentItem) {
|
||||||
|
PRInt32 type;
|
||||||
|
parentItem->GetItemType(&type);
|
||||||
|
doFocusDoc = type == nsIDocShellTreeItem::typeContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell itself (and the DocShellFocusController) who has focus
|
||||||
|
// this way focus gets removed from the currently focused DocShell
|
||||||
|
SetHasFocus(PR_TRUE);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContent> focusContent;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIEventStateManager> esm;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPresContext> presContext;
|
||||||
|
GetPresContext(getter_AddRefs(presContext));
|
||||||
|
if (presContext) {
|
||||||
presContext->GetEventStateManager(getter_AddRefs(esm));
|
presContext->GetEventStateManager(getter_AddRefs(esm));
|
||||||
if (!esm)
|
nsCOMPtr<nsIContent> rootContent(getter_AddRefs(document->GetRootContent()));
|
||||||
return NS_ERROR_FAILURE;
|
if (esm && rootContent) {
|
||||||
|
// Either focus the document or the "first" piece of content
|
||||||
presShell->GetDocument(getter_AddRefs(document));
|
if (doFocusDoc) {
|
||||||
nsCOMPtr<nsIContent>
|
esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
||||||
rootContent(getter_AddRefs(document->GetRootContent()));
|
esm->SetSpecialTopOfDoc(PR_TRUE);
|
||||||
if (!rootContent)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> focusContent;
|
|
||||||
|
|
||||||
// Figure out what type of document this is
|
|
||||||
// if parent doc is content then set focus to document itself
|
|
||||||
// and set the "special" flag so it knows we are at the beginning
|
|
||||||
// of the document
|
|
||||||
PRBool doFocusDoc = PR_FALSE;
|
|
||||||
nsIDocShellTreeItem* treeItem = NS_STATIC_CAST(nsIDocShellTreeItem *, this);
|
|
||||||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
||||||
treeItem->GetParent(getter_AddRefs(parentItem));
|
|
||||||
if (parentItem) {
|
|
||||||
PRInt32 type;
|
|
||||||
parentItem->GetItemType(&type);
|
|
||||||
doFocusDoc = type == nsIDocShellTreeItem::typeContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell itself (and the DocShellFocusController) who has focus
|
|
||||||
// this way focus gets removed from the currently focused DocShell
|
|
||||||
SetHasFocus(PR_TRUE);
|
|
||||||
|
|
||||||
// Either focus the document or the "first" piece of content
|
|
||||||
if (doFocusDoc) {
|
|
||||||
esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
||||||
esm->SetSpecialTopOfDoc(PR_TRUE);
|
|
||||||
} else {
|
|
||||||
nsCOMPtr<nsIContent> content;
|
|
||||||
esm->GetNextTabbableIndexContent(rootContent, PR_TRUE, PR_TRUE, getter_AddRefs(content));
|
|
||||||
if (!content) {
|
|
||||||
esm->GetNextTabbableContent(rootContent, nsnull, PR_TRUE,
|
|
||||||
getter_AddRefs(focusContent));
|
|
||||||
} else {
|
} else {
|
||||||
focusContent = content;
|
nsCOMPtr<nsIContent> content;
|
||||||
|
esm->GetNextTabbableIndexContent(rootContent, PR_TRUE, PR_TRUE, getter_AddRefs(content));
|
||||||
|
if (!content) {
|
||||||
|
esm->GetNextTabbableContent(rootContent, nsnull, PR_TRUE,
|
||||||
|
getter_AddRefs(focusContent));
|
||||||
|
} else {
|
||||||
|
focusContent = content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (focusContent) {
|
if (focusContent) {
|
||||||
nsIFrame *focusFrame = nsnull;
|
nsIFrame *focusFrame = nsnull;
|
||||||
presShell->GetPrimaryFrameFor(focusContent, &focusFrame);
|
presShell->GetPrimaryFrameFor(focusContent, &focusFrame);
|
||||||
esm->ChangeFocus(focusContent, focusFrame, PR_TRUE);
|
esm->ChangeFocus(focusContent, focusFrame, PR_TRUE);
|
||||||
SetCanvasHasFocus(PR_FALSE);
|
SetCanvasHasFocus(PR_FALSE);
|
||||||
} else {
|
} else {
|
||||||
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
||||||
document->GetScriptGlobalObject(getter_AddRefs(sgo));
|
document->GetScriptGlobalObject(getter_AddRefs(sgo));
|
||||||
if (sgo) {
|
if (sgo) {
|
||||||
nsCOMPtr<nsIDOMWindowInternal> domwin(do_QueryInterface(sgo));
|
nsCOMPtr<nsIDOMWindowInternal> domwin(do_QueryInterface(sgo));
|
||||||
if (domwin) {
|
if (domwin)
|
||||||
domwin->Focus();
|
domwin->Focus();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
|
|
Загрузка…
Ссылка в новой задаче