зеркало из https://github.com/mozilla/gecko-dev.git
Bug 82123 -- enable embeddors to alter the focus traversal so that the document itself receives focus first instead of last. r=saari, adamlock, sr=jst, a=chofmann.
This commit is contained in:
Родитель
ecc25a875f
Коммит
89a8648447
|
@ -2581,23 +2581,16 @@ PrintDocTree(nsIDocShellTreeNode * aParentNode)
|
|||
void
|
||||
nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot)
|
||||
{
|
||||
#ifdef DEBUG_DOCSHELL_FOCUS
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
mDocument->GetShellAt(0, getter_AddRefs(presShell));
|
||||
if (presShell) {
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
presShell->GetPresContext(getter_AddRefs(presContext));
|
||||
if (presContext) {
|
||||
nsCOMPtr<nsISupports> pcContainer;
|
||||
presContext->GetContainer(getter_AddRefs(pcContainer));
|
||||
if (pcContainer) {
|
||||
nsCOMPtr<nsIDocShell> docshell(do_QueryInterface(pcContainer));
|
||||
printf("ShiftFocus DocShell %p Doc: %p\n", docshell.get(), mDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
if (mPresContext) {
|
||||
nsCOMPtr<nsISupports> pcContainer;
|
||||
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
||||
if (pcContainer)
|
||||
docShell = do_QueryInterface(pcContainer);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DOCSHELL_FOCUS
|
||||
printf("ShiftFocus DocShell %p Doc: %p\n", docshell.get(), mDocument);
|
||||
#endif
|
||||
|
||||
// Indicates whether the document itself (i.e. no content) has focus
|
||||
|
@ -2655,9 +2648,6 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot)
|
|||
// so if we are going backwards then find the last piece of content
|
||||
// and and look backwards for the last focusable content
|
||||
if (!forward) {
|
||||
nsCOMPtr<nsISupports> container;
|
||||
mPresContext->GetContainer(getter_AddRefs(container));
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
||||
nsCOMPtr<nsIContent> lastContent = getter_AddRefs(GetLastContent(docShell));
|
||||
nsCOMPtr<nsIDOMHTMLIFrameElement> iframe(do_QueryInterface(lastContent));
|
||||
if (iframe) {
|
||||
|
@ -2704,8 +2694,12 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot)
|
|||
}
|
||||
|
||||
|
||||
PRBool docFocusFirst = PR_FALSE;
|
||||
if (docShell)
|
||||
docShell->GetFocusDocBeforeContent(&docFocusFirst);
|
||||
|
||||
//Get the next tab item. This takes tabIndex into account
|
||||
if (!docHasFocus && !next)
|
||||
if ((docFocusFirst || !docHasFocus) && !next)
|
||||
GetNextTabbableContent(rootContent, primaryFrame, forward, getter_AddRefs(next));
|
||||
|
||||
//Either no tabbable items or the end of the document
|
||||
|
@ -2713,7 +2707,10 @@ 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 (!docHasFocus && !doFocusAvailDocShells) {
|
||||
|
||||
// Only do this if we're not in document-before-content focus mode
|
||||
|
||||
if (!docHasFocus && !doFocusAvailDocShells && !docFocusFirst) {
|
||||
PRBool focusDoc = PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
|
@ -2793,19 +2790,11 @@ nsEventStateManager::ShiftFocus(PRBool forward, nsIContent* aRoot)
|
|||
mCurrentFocus = next;
|
||||
NS_IF_ADDREF(mCurrentFocus);
|
||||
|
||||
nsCOMPtr<nsISupports> container;
|
||||
mPresContext->GetContainer(getter_AddRefs(container));
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
||||
if (docShell) {
|
||||
if (docShell)
|
||||
docShell->SetCanvasHasFocus(PR_FALSE);
|
||||
}
|
||||
|
||||
if (hadDocFocus) {
|
||||
nsCOMPtr<nsISupports> container;
|
||||
mPresContext->GetContainer(getter_AddRefs(container));
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
||||
if (hadDocFocus)
|
||||
ForceUpdate(docShell);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -179,11 +179,12 @@ nsDocShell::nsDocShell():
|
|||
mItemType(typeContent),
|
||||
mCurrentScrollbarPref(-1, -1),
|
||||
mDefaultScrollbarPref(-1, -1),
|
||||
mAllowSubframes(PR_TRUE),
|
||||
mAllowPlugins(PR_TRUE),
|
||||
mAllowJavascript(PR_TRUE),
|
||||
mAllowMetaRedirects(PR_TRUE),
|
||||
mAllowSubframes(PR_TRUE),
|
||||
mAllowImages(PR_TRUE),
|
||||
mFocusDocFirst(PR_FALSE),
|
||||
mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
|
||||
mBusyFlags(BUSY_FLAGS_NONE),
|
||||
mEODForCurrentDocument(PR_FALSE),
|
||||
|
@ -1209,6 +1210,22 @@ NS_IMETHODIMP nsDocShell::SetAllowImages(PRBool aAllowImages)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetFocusDocBeforeContent(PRBool* aDocFirst)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDocFirst);
|
||||
|
||||
*aDocFirst = mFocusDocFirst;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::SetFocusDocBeforeContent(PRBool aDocFirst)
|
||||
{
|
||||
mFocusDocFirst = aDocFirst;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetDocShellEnumerator(PRInt32 aItemType, PRInt32 aDirection, nsISimpleEnumerator **outEnum)
|
||||
{
|
||||
|
@ -2680,6 +2697,9 @@ nsDocShell::SetFocus()
|
|||
doFocusDoc = type == nsIDocShellTreeItem::typeContent;
|
||||
}
|
||||
|
||||
if (mFocusDocFirst)
|
||||
doFocusDoc = PR_TRUE;
|
||||
|
||||
// Tell itself (and the DocShellFocusController) who has focus
|
||||
// this way focus gets removed from the currently focused DocShell
|
||||
SetHasFocus(PR_TRUE);
|
||||
|
@ -2881,6 +2901,7 @@ nsDocShell::FocusAvailable(nsIBaseWindow * aCurrentFocus,
|
|||
// For DocShell's not implemented by this class
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(chromeFocus));
|
||||
MakeSureOfSetFocus(nsnull, docShell);
|
||||
*aTookFocus = PR_TRUE;
|
||||
return ret;
|
||||
} else {
|
||||
// If the embeddor does not implement FocusNext/PrevElement,
|
||||
|
|
|
@ -303,11 +303,14 @@ protected:
|
|||
nsPoint mCurrentScrollbarPref; // this document only
|
||||
nsPoint mDefaultScrollbarPref; // persistent across doc loads
|
||||
PRUint32 mLoadType;
|
||||
PRBool mAllowPlugins;
|
||||
PRBool mAllowJavascript;
|
||||
PRBool mAllowMetaRedirects;
|
||||
|
||||
PRBool mAllowSubframes;
|
||||
PRBool mAllowImages;
|
||||
PRPackedBool mAllowPlugins;
|
||||
PRPackedBool mAllowJavascript;
|
||||
PRPackedBool mAllowMetaRedirects;
|
||||
PRPackedBool mAllowImages;
|
||||
PRPackedBool mFocusDocFirst;
|
||||
|
||||
PRUint32 mAppType;
|
||||
PRInt32 mChildOffset; // Offset in the parent's child list.
|
||||
PRUint32 mBusyFlags;
|
||||
|
|
|
@ -195,6 +195,13 @@ interface nsIDocShell : nsISupports
|
|||
*/
|
||||
attribute boolean allowSubframes;
|
||||
|
||||
/**
|
||||
* Attribute stating whether the document itself should come before
|
||||
* its focusable content in tab traversal (the default is for the document
|
||||
* to be focused last).
|
||||
*/
|
||||
attribute boolean focusDocBeforeContent;
|
||||
|
||||
/**
|
||||
* Attribute stating whether or not images should be loaded.
|
||||
*/
|
||||
|
|
|
@ -47,6 +47,14 @@ interface nsIWebBrowserSetup : nsISupports
|
|||
* re-setting the src attributes.
|
||||
*/
|
||||
const unsigned long SETUP_ALLOW_IMAGES = 5;
|
||||
|
||||
/* SETUP_FOCUS_DOC_BEFORE_CONTENT lets an embeddor control whether the document
|
||||
* as a whole gets focus before traversing the document's content, or after
|
||||
* traversing its content.
|
||||
*/
|
||||
|
||||
const unsigned long SETUP_FOCUS_DOC_BEFORE_CONTENT = 6;
|
||||
|
||||
const unsigned long SETUP_USE_GLOBAL_HISTORY = 256;
|
||||
|
||||
void setProperty(in unsigned long aId, in unsigned long aValue);
|
||||
|
|
|
@ -673,6 +673,13 @@ NS_IMETHODIMP nsWebBrowser::SetProperty(PRUint32 aId, PRUint32 aValue)
|
|||
rv = EnableGlobalHistory(aValue);
|
||||
}
|
||||
break;
|
||||
case nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT:
|
||||
{
|
||||
NS_ENSURE_STATE(mDocShell);
|
||||
NS_ENSURE_TRUE((aValue == PR_TRUE || aValue == PR_FALSE), NS_ERROR_INVALID_ARG);
|
||||
mDocShell->SetFocusDocBeforeContent(aValue);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
rv = NS_ERROR_INVALID_ARG;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче