From 7d9b30ae3aab4a9cd507d63e38c72df68fef821f Mon Sep 17 00:00:00 2001 From: "jaggernaut%netscape.com" Date: Fri, 22 Jun 2001 07:25:28 +0000 Subject: [PATCH] Bug 83394: Tabindex attribute not working properly in mfcembed app''. Fixes problems with tabbing from the document to elements with the index attribute set in both mfcembed and the regular browser app. patch by bryner, r=jag, sr=hyatt, a=chofmann git-svn-id: svn://10.0.0.236/trunk@97768 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/public/nsIEventStateManager.h | 5 +-- .../events/src/nsEventStateManager.cpp | 42 +++++++------------ .../content/events/src/nsEventStateManager.h | 3 -- mozilla/docshell/base/nsDocShell.cpp | 1 - 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h index 84e83af88e5..ea170f5668d 100644 --- a/mozilla/content/events/public/nsIEventStateManager.h +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -102,10 +102,7 @@ public: // Method for moving the focus forward/back. NS_IMETHOD MoveFocus(PRBool aDirection, nsIContent* aRoot)=0; - // Method for indicating that we are at top of a doc in a special situation - NS_IMETHOD SetSpecialTopOfDoc(PRBool aIsAtTop)=0; - - //-- Special Enums needed for DocShell Identification + //-- Special Enums needed for DocShell Identification enum eDocType {eChrome = 0, eGenericContent, eFrameSet, eFrame, eIFrame}; NS_IMETHOD FigureOutKindOfDoc(nsIDocument* aDoc, eDocType* aDocType) = 0; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index a2dc0b4283a..8a360214244 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -159,7 +159,6 @@ nsEventStateManager::nsEventStateManager() mAccessKeys = nsnull; mBrowseWithCaret = PR_FALSE; hHover = PR_FALSE; - mSpecialTopOfDoc = PR_FALSE; NS_INIT_REFCNT(); @@ -1519,9 +1518,6 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, activeContent = par; } SetContentState(activeContent, NS_EVENT_STATE_ACTIVE); - nsCOMPtr bodyElement(do_QueryInterface(activeContent)); - if (bodyElement) - mSpecialTopOfDoc = PR_TRUE; } } else { @@ -2604,7 +2600,8 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) } #endif - PRBool topOfDoc = PR_FALSE; + // Indicates whether the document itself (i.e. no content) has focus + PRBool docHasFocus = PR_FALSE; if (nsnull == mPresContext) { return; @@ -2639,7 +2636,7 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) return; } mCurrentTabIndex = forward ? 1 : 0; - topOfDoc = PR_TRUE; + docHasFocus = PR_TRUE; } nsIFrame* primaryFrame = nsnull; @@ -2651,17 +2648,10 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) nsCOMPtr caretFocus; PRUint32 caretOffset; GetCaretLocation(getter_AddRefs(caretFocus), &primaryFrame, &caretOffset); - } - else if (topOfDoc && !mSpecialTopOfDoc) { - primaryFrame = nsnull; } else { shell->GetPrimaryFrameFor(mCurrentFocus, &primaryFrame); - // Check to see if we are in the special situation - // where we are at the top of the document and mSpecialTopOfDoc is set - // this means the document is focus and the first piece of content is not - if (topOfDoc && mSpecialTopOfDoc) { - topOfDoc = PR_FALSE; + if (docHasFocus) { // so if we are going backwards then find the last piece of content // and and look backwards for the last focusable content if (!forward) { @@ -2684,8 +2674,7 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) PRBool doFocusAvailDocShells = PR_FALSE; nsCOMPtr next; - // rememeber whether mSpecialTopOfDoc was set - PRBool wasSpecialDocFocus = mSpecialTopOfDoc; + PRBool hadDocFocus = docHasFocus; nsCOMPtr rootContent; mDocument->GetRootContent(getter_AddRefs(rootContent)); @@ -2696,7 +2685,7 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) if (docType == eFrame && aRoot == nsnull) { if (FocusWithinHTMLFrameDoc(aRoot, shell, forward, doFocusAvailDocShells)) { return; - } else if (mSpecialTopOfDoc) { + } else if (docHasFocus) { // If we are starting at the top of the document // first check to see if there is a tabbable index to go to // @@ -2704,17 +2693,19 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) // so we remember it here and reset it back if it didn't find anything PRInt32 currentTabIndex = mCurrentTabIndex; GetNextTabbableIndexContent(rootContent, forward, PR_TRUE, getter_AddRefs(next)); - if (next) { - topOfDoc = PR_TRUE; - } else { + if (!next) { mCurrentTabIndex = currentTabIndex; } + + // frames are document first, then content + // so this allows us to call GetNextTabbableContent below + docHasFocus = PR_FALSE; } } //Get the next tab item. This takes tabIndex into account - if (!topOfDoc) + if (!docHasFocus && !next) GetNextTabbableContent(rootContent, primaryFrame, forward, getter_AddRefs(next)); //Either no tabbable items or the end of the document @@ -2722,7 +2713,7 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) // If we've reached the end of the content in this document, we // focus the document itself before leaving. - if (!topOfDoc && !doFocusAvailDocShells) { + if (!docHasFocus && !doFocusAvailDocShells) { PRBool focusDoc = PR_TRUE; nsCOMPtr docShell; @@ -2769,7 +2760,7 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) //No one took focus and we're not already at the top of the doc //so calling ShiftFocus will start at the top of the doc again. - if (!focusTaken && !topOfDoc) { + if (!focusTaken && !docHasFocus) { ShiftFocus(forward); } @@ -2809,7 +2800,7 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot) docShell->SetCanvasHasFocus(PR_FALSE); } - if (wasSpecialDocFocus) { + if (hadDocFocus) { nsCOMPtr container; mPresContext->GetContainer(getter_AddRefs(container)); nsCOMPtr docShell(do_QueryInterface(container)); @@ -2824,8 +2815,6 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* *aResult = nsnull; PRBool keepFirstFrame = PR_FALSE; - mSpecialTopOfDoc = mCurrentFocus == nsnull; - nsCOMPtr frameTraversal; if (!aFrame) { @@ -3792,7 +3781,6 @@ nsEventStateManager::SetFocusedContent(nsIContent* aContent) NS_IF_RELEASE(mCurrentFocus); mCurrentFocus = aContent; NS_IF_ADDREF(mCurrentFocus); - mSpecialTopOfDoc = PR_FALSE; return NS_OK; } diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 47d9bc6729b..65eefedf497 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -114,8 +114,6 @@ public: NS_IMETHOD MoveFocus(PRBool aDirection, nsIContent* aRoot); - NS_IMETHOD SetSpecialTopOfDoc(PRBool aIsAtTop) { mSpecialTopOfDoc = aIsAtTop; return NS_OK; } - NS_IMETHOD FigureOutKindOfDoc(nsIDocument* aDoc, eDocType* aDocType); protected: @@ -221,7 +219,6 @@ protected: PRInt32 mLockCursor; // DocShell Traversal Data Memebers - PRPackedBool mSpecialTopOfDoc; nsCOMPtr mLastContentFocus; //Anti-recursive stack controls diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 7a371ad03e6..287541e4e52 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -2698,7 +2698,6 @@ nsDocShell::SetFocus() // 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 content; esm->GetNextTabbableIndexContent(rootContent, PR_TRUE, PR_TRUE, getter_AddRefs(content));