From d85ad8e6a8404af85db8604fce0267f003f5f5e4 Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Thu, 2 Dec 1999 10:11:38 +0000 Subject: [PATCH] Implemented the nsIBaseWindow::FocusAvailable. Hooked up the old nsIWebShellContainer::FocusAvailable to go through the new one. git-svn-id: svn://10.0.0.236/trunk@55065 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsWebShell.cpp | 67 +++++++++++++++++----------- mozilla/webshell/src/nsWebShell.cpp | 67 +++++++++++++++++----------- 2 files changed, 80 insertions(+), 54 deletions(-) diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 853c7e572d9..931ef8bc069 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -2413,33 +2413,8 @@ nsWebShell::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult) NS_IMETHODIMP nsWebShell::FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTaken) { - //If the WebShell with focus is us, pass this up to container - if (this == aFocusedWebShell && nsnull != mContainer) { - mContainer->FocusAvailable(this, aFocusTaken); - } - - nsIDocShell* shell = nsnull; - - //Other wise, check children and move focus to next one - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) { - shell = (nsIDocShell*)mChildren.ElementAt(i); - nsCOMPtr webShell(do_QueryInterface(shell)); - if (webShell.get() == aFocusedWebShell) { - if (++i < n) { - shell = (nsIDocShell*)mChildren.ElementAt(i); - nsCOMPtr shellWin(do_QueryInterface(shell)); - shellWin->SetFocus(); - break; - } - else if (nsnull != mContainer) { - mContainer->FocusAvailable(this, aFocusTaken); - break; - } - } - } - - return NS_OK; + nsCOMPtr webShellAsWin(do_QueryInterface(aFocusedWebShell)); + return FocusAvailable(webShellAsWin, &aFocusTaken); } NS_IMETHODIMP @@ -4075,6 +4050,44 @@ NS_IMETHODIMP nsWebShell::FocusAvailable(nsIBaseWindow* aCurrentFocus, PRBool* aTookFocus) { NS_ENSURE_ARG_POINTER(aTookFocus); + // Next person we should call is first the parent otherwise the + // docshell tree owner. + nsCOMPtr nextCallWin(do_QueryInterface(mParent)); + if(!nextCallWin) + {//XXX Enable this when docShellTreeOwner is added + //nextCallWin = do_QueryInterface(mDocShellTreeOwner); + } + + //If the current focus is us, offer it to the next owner. + if(aCurrentFocus == NS_STATIC_CAST(nsIBaseWindow*, this)) + { + if(nextCallWin) + return nextCallWin->FocusAvailable(aCurrentFocus, aTookFocus); + return NS_OK; + } + + //Otherwise, check the chilren and offer it to the next sibling. + PRInt32 i; + PRInt32 n = mChildren.Count(); + for(i = 0; i < n; i++) + { + nsCOMPtr + child(do_QueryInterface((nsISupports*)mChildren.ElementAt(i))); + if(child.get() == aCurrentFocus) + { + while(++i < n) + { + child = do_QueryInterface((nsISupports*)mChildren.ElementAt(i)); + if(NS_SUCCEEDED(child->SetFocus())) + { + *aTookFocus = PR_TRUE; + return NS_OK; + } + } + } + } + if(nextCallWin) + return nextCallWin->FocusAvailable(aCurrentFocus, aTookFocus); return NS_OK; } diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 853c7e572d9..931ef8bc069 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -2413,33 +2413,8 @@ nsWebShell::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult) NS_IMETHODIMP nsWebShell::FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTaken) { - //If the WebShell with focus is us, pass this up to container - if (this == aFocusedWebShell && nsnull != mContainer) { - mContainer->FocusAvailable(this, aFocusTaken); - } - - nsIDocShell* shell = nsnull; - - //Other wise, check children and move focus to next one - PRInt32 i, n = mChildren.Count(); - for (i = 0; i < n; i++) { - shell = (nsIDocShell*)mChildren.ElementAt(i); - nsCOMPtr webShell(do_QueryInterface(shell)); - if (webShell.get() == aFocusedWebShell) { - if (++i < n) { - shell = (nsIDocShell*)mChildren.ElementAt(i); - nsCOMPtr shellWin(do_QueryInterface(shell)); - shellWin->SetFocus(); - break; - } - else if (nsnull != mContainer) { - mContainer->FocusAvailable(this, aFocusTaken); - break; - } - } - } - - return NS_OK; + nsCOMPtr webShellAsWin(do_QueryInterface(aFocusedWebShell)); + return FocusAvailable(webShellAsWin, &aFocusTaken); } NS_IMETHODIMP @@ -4075,6 +4050,44 @@ NS_IMETHODIMP nsWebShell::FocusAvailable(nsIBaseWindow* aCurrentFocus, PRBool* aTookFocus) { NS_ENSURE_ARG_POINTER(aTookFocus); + // Next person we should call is first the parent otherwise the + // docshell tree owner. + nsCOMPtr nextCallWin(do_QueryInterface(mParent)); + if(!nextCallWin) + {//XXX Enable this when docShellTreeOwner is added + //nextCallWin = do_QueryInterface(mDocShellTreeOwner); + } + + //If the current focus is us, offer it to the next owner. + if(aCurrentFocus == NS_STATIC_CAST(nsIBaseWindow*, this)) + { + if(nextCallWin) + return nextCallWin->FocusAvailable(aCurrentFocus, aTookFocus); + return NS_OK; + } + + //Otherwise, check the chilren and offer it to the next sibling. + PRInt32 i; + PRInt32 n = mChildren.Count(); + for(i = 0; i < n; i++) + { + nsCOMPtr + child(do_QueryInterface((nsISupports*)mChildren.ElementAt(i))); + if(child.get() == aCurrentFocus) + { + while(++i < n) + { + child = do_QueryInterface((nsISupports*)mChildren.ElementAt(i)); + if(NS_SUCCEEDED(child->SetFocus())) + { + *aTookFocus = PR_TRUE; + return NS_OK; + } + } + } + } + if(nextCallWin) + return nextCallWin->FocusAvailable(aCurrentFocus, aTookFocus); return NS_OK; }