From 74861abc91b505fd869b4761156ac863838f423d Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Mon, 15 Apr 2002 22:25:17 +0000 Subject: [PATCH] Make sure nsDocShell::GetVisibility returns false if we are inside a hidden pane of a deck; this prevents ctrl+tab from focusing these documents (which causes focus to appear lost). Bug 106123, r=jkeiser, sr=hewitt. git-svn-id: svn://10.0.0.236/trunk@118994 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 61 +++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 84249b623bc..e4d2e03ff98 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -2883,15 +2883,64 @@ nsDocShell::GetVisibility(PRBool * aVisibility) NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); // get the root view - nsIView *rootView = nsnull; // views are not ref counted - NS_ENSURE_SUCCESS(vm->GetRootView(rootView), NS_ERROR_FAILURE); - NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); + nsIView *view = nsnull; // views are not ref counted + NS_ENSURE_SUCCESS(vm->GetRootView(view), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); - // convert the view's visibility attribute to a bool + nsRect viewBounds; + view->GetBounds(viewBounds); + printf("rootView: dim=(%d,%d)\n", viewBounds.width, viewBounds.height); + + // if our root view is hidden, we are not visible nsViewVisibility vis; - NS_ENSURE_SUCCESS(rootView->GetVisibility(vis), NS_ERROR_FAILURE); - *aVisibility = nsViewVisibility_kHide == vis ? PR_FALSE : PR_TRUE; + NS_ENSURE_SUCCESS(view->GetVisibility(vis), NS_ERROR_FAILURE); + if (vis == nsViewVisibility_kHide) { + *aVisibility = PR_FALSE; + return NS_OK; + } + // otherwise, we must walk up the document and view trees checking + // for a hidden view. + + nsCOMPtr treeItem = this; + nsCOMPtr parentItem; + treeItem->GetParent(getter_AddRefs(parentItem)); + while (parentItem) { + nsCOMPtr parentDS = do_QueryInterface(parentItem); + nsCOMPtr pPresShell; + parentDS->GetPresShell(getter_AddRefs(pPresShell)); + nsCOMPtr shellContent; + nsCOMPtr shellISupports = do_QueryInterface(treeItem); + pPresShell->FindContentForShell(shellISupports, getter_AddRefs(shellContent)); + NS_ASSERTION(shellContent, "subshell not in the map"); + + nsIFrame* frame; + pPresShell->GetPrimaryFrameFor(shellContent, &frame); + if (frame) { + nsCOMPtr pc; + pPresShell->GetPresContext(getter_AddRefs(pc)); + frame->GetView(pc, &view); + if (!view) { + nsIFrame* parentWithView; + frame->GetParentWithView(pc, &parentWithView); + parentWithView->GetView(pc, &view); + } + + while (view) { + view->GetVisibility(vis); + if (vis == nsViewVisibility_kHide) { + *aVisibility = PR_FALSE; + return NS_OK; + } + view->GetParent(view); + } + } + + treeItem = parentItem; + treeItem->GetParent(getter_AddRefs(parentItem)); + } + + *aVisibility = PR_TRUE; return NS_OK; }