mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-30 01:59:29 +00:00
Fix for my 0.9 focus issues. r=saari, sr=brendan
This commit is contained in:
parent
f578c74b05
commit
174428fb65
@ -376,7 +376,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||
if(ourWindow) {
|
||||
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
|
||||
if (focusController)
|
||||
focusController->SetSuppressFocus(PR_TRUE);
|
||||
focusController->SetSuppressFocus(PR_TRUE, "NS_GOTFOCUS ESM Suppression");
|
||||
}
|
||||
|
||||
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &blurevent, nsnull, NS_EVENT_FLAG_INIT, &blurstatus);
|
||||
@ -385,7 +385,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||
|
||||
|
||||
if (focusController) {
|
||||
focusController->SetSuppressFocus(PR_FALSE);
|
||||
focusController->SetSuppressFocus(PR_FALSE, "NS_GOTFOCUS ESM Suppression");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -494,7 +494,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||
PRBool isSuppressed;
|
||||
focusController->GetSuppressFocus(&isSuppressed);
|
||||
while(isSuppressed){
|
||||
focusController->SetSuppressFocus(PR_FALSE); // Unsuppress and let the command dispatcher listen again.
|
||||
focusController->SetSuppressFocus(PR_FALSE, "Activation Suppression"); // Unsuppress and let the command dispatcher listen again.
|
||||
focusController->GetSuppressFocus(&isSuppressed);
|
||||
}
|
||||
focusController->SetSuppressFocusScroll(PR_FALSE);
|
||||
@ -533,7 +533,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
|
||||
if (focusController) {
|
||||
// Suppress the command dispatcher.
|
||||
focusController->SetSuppressFocus(PR_TRUE);
|
||||
focusController->SetSuppressFocus(PR_TRUE, "Deactivate Suppression");
|
||||
}
|
||||
}
|
||||
|
||||
@ -587,7 +587,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext,
|
||||
|
||||
if (focusController) {
|
||||
focusController->SetActive(PR_FALSE);
|
||||
//focusController->SetSuppressFocus(PR_FALSE);
|
||||
focusController->SetSuppressFocus(PR_FALSE, "Deactivate Suppression");
|
||||
}
|
||||
}
|
||||
|
||||
@ -3158,7 +3158,7 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo
|
||||
if(oldWindow)
|
||||
oldWindow->GetRootFocusController(getter_AddRefs(oldFocusController));
|
||||
if(oldFocusController && oldFocusController != newFocusController)
|
||||
oldFocusController->SetSuppressFocus(PR_TRUE);
|
||||
oldFocusController->SetSuppressFocus(PR_TRUE, "SendFocusBlur Window Switch");
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIEventStateManager> esm;
|
||||
@ -3207,7 +3207,7 @@ nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aCo
|
||||
newWindow->GetRootFocusController(getter_AddRefs(newFocusController));
|
||||
oldWindow->GetRootFocusController(getter_AddRefs(oldFocusController));
|
||||
if(oldFocusController && oldFocusController != newFocusController)
|
||||
oldFocusController->SetSuppressFocus(PR_TRUE);
|
||||
oldFocusController->SetSuppressFocus(PR_TRUE, "SendFocusBlur Window Switch #2");
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIEventStateManager> esm;
|
||||
|
@ -25,7 +25,9 @@
|
||||
#include "nsIDOMNSHTMLInputElement.h"
|
||||
#include "nsIControllers.h"
|
||||
#include "nsIEditorController.h"
|
||||
|
||||
#include "nsIFocusController.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIDOMHTMLFormElement.h"
|
||||
@ -678,6 +680,21 @@ nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If the window is not active, do not allow the focus to bring the
|
||||
// window to the front. We update the focus controller, but do
|
||||
// nothing else.
|
||||
nsCOMPtr<nsIFocusController> focusController;
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
||||
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObj));
|
||||
win->GetRootFocusController(getter_AddRefs(focusController));
|
||||
PRBool isActive = PR_FALSE;
|
||||
focusController->GetActive(&isActive);
|
||||
if (!isActive) {
|
||||
focusController->SetFocusedElement(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIEventStateManager> esm;
|
||||
|
||||
aPresContext->GetEventStateManager(getter_AddRefs(esm));
|
||||
|
@ -2982,7 +2982,7 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
|
||||
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
|
||||
if (focusController) {
|
||||
// Suppress the command dispatcher.
|
||||
focusController->SetSuppressFocus(PR_TRUE);
|
||||
focusController->SetSuppressFocus(PR_TRUE, "Win32-Only Link Traversal Issue");
|
||||
}
|
||||
}
|
||||
|
||||
@ -3002,7 +3002,7 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
|
||||
// See the book I wrote above regarding why the focus controller is
|
||||
// being used here. -- hyatt
|
||||
if (focusController)
|
||||
focusController->SetSuppressFocus(PR_FALSE);
|
||||
focusController->SetSuppressFocus(PR_FALSE, "Win32-Only Link Traversal Issue");
|
||||
|
||||
mContentViewer = aNewViewer;
|
||||
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
NS_IMETHOD SetFocusedWindow(nsIDOMWindowInternal* aResult)=0;
|
||||
|
||||
NS_IMETHOD GetSuppressFocus(PRBool* aSuppressFlag)=0;
|
||||
NS_IMETHOD SetSuppressFocus(PRBool aSuppressFlag)=0;
|
||||
NS_IMETHOD SetSuppressFocus(PRBool aSuppressFlag, char* aReason)=0;
|
||||
|
||||
NS_IMETHOD GetSuppressFocusScroll(PRBool* aSuppressFlag)=0;
|
||||
NS_IMETHOD SetSuppressFocusScroll(PRBool aSuppressFlag)=0;
|
||||
|
@ -392,12 +392,22 @@ nsFocusController::GetSuppressFocus(PRBool* aSuppressFocus)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFocusController::SetSuppressFocus(PRBool aSuppressFocus)
|
||||
nsFocusController::SetSuppressFocus(PRBool aSuppressFocus, char* aReason)
|
||||
{
|
||||
if(aSuppressFocus)
|
||||
if(aSuppressFocus) {
|
||||
++mSuppressFocus;
|
||||
else if(mSuppressFocus > 0)
|
||||
#ifdef DEBUG_hyatt
|
||||
printf("[%d] SuppressFocus incremented to %d. The reason is %s.\n", this, mSuppressFocus, aReason);
|
||||
#endif
|
||||
}
|
||||
else if(mSuppressFocus > 0) {
|
||||
--mSuppressFocus;
|
||||
#ifdef DEBUG_hyatt
|
||||
printf("[%d] SuppressFocus decremented to %d. The reason is %s.\n", this, mSuppressFocus, aReason);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
NS_ASSERTION(PR_FALSE, "Attempt to decrement focus controller's suppression when no suppression active!\n");
|
||||
|
||||
// we are unsuppressing after activating, so update focus-related commands
|
||||
// we need this to update commands in the case where an element is focused.
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
NS_IMETHOD SetFocusedWindow(nsIDOMWindowInternal* aResult);
|
||||
|
||||
NS_IMETHOD GetSuppressFocus(PRBool* aSuppressFlag);
|
||||
NS_IMETHOD SetSuppressFocus(PRBool aSuppressFlag);
|
||||
NS_IMETHOD SetSuppressFocus(PRBool aSuppressFlag, char* aReason);
|
||||
|
||||
NS_IMETHOD GetSuppressFocusScroll(PRBool* aSuppressFlag);
|
||||
NS_IMETHOD SetSuppressFocusScroll(PRBool aSuppressFlag);
|
||||
|
@ -2329,7 +2329,7 @@ static void CheckForFocus(nsIDocument* aDocument)
|
||||
|
||||
if (focusController) {
|
||||
// Suppress the command dispatcher.
|
||||
focusController->SetSuppressFocus(PR_TRUE);
|
||||
focusController->SetSuppressFocus(PR_TRUE, "PresShell suppression on Web page loads");
|
||||
nsCOMPtr<nsIDOMWindowInternal> focusedWindow;
|
||||
focusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
||||
|
||||
@ -2358,7 +2358,7 @@ static void CheckForFocus(nsIDocument* aDocument)
|
||||
domWindow->Focus();
|
||||
}
|
||||
}
|
||||
focusController->SetSuppressFocus(PR_FALSE);
|
||||
focusController->SetSuppressFocus(PR_FALSE, "PresShell suppression on Web page loads");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2329,7 +2329,7 @@ static void CheckForFocus(nsIDocument* aDocument)
|
||||
|
||||
if (focusController) {
|
||||
// Suppress the command dispatcher.
|
||||
focusController->SetSuppressFocus(PR_TRUE);
|
||||
focusController->SetSuppressFocus(PR_TRUE, "PresShell suppression on Web page loads");
|
||||
nsCOMPtr<nsIDOMWindowInternal> focusedWindow;
|
||||
focusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
||||
|
||||
@ -2358,7 +2358,7 @@ static void CheckForFocus(nsIDocument* aDocument)
|
||||
domWindow->Focus();
|
||||
}
|
||||
}
|
||||
focusController->SetSuppressFocus(PR_FALSE);
|
||||
focusController->SetSuppressFocus(PR_FALSE, "PresShell suppression on Web page loads");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -505,10 +505,20 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
||||
nsCOMPtr<nsIFocusController> focusController;
|
||||
piWin->GetRootFocusController(getter_AddRefs(focusController));
|
||||
if (focusController) {
|
||||
// This is essentially the first stage of activation (NS_GOTFOCUS is
|
||||
// followed by the DOM window getting activated (which is direct on Win32
|
||||
// and done through web shell window via an NS_ACTIVATE message on the
|
||||
// other platforms).
|
||||
//
|
||||
// Go ahead and mark the focus controller as being active. We have
|
||||
// to do this even before the activate message comes in, since focus
|
||||
// memory kicks in prior to the activate being processed.
|
||||
focusController->SetActive(PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> focusedWindow;
|
||||
focusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
||||
if (focusedWindow) {
|
||||
focusController->SetSuppressFocus(PR_TRUE);
|
||||
focusController->SetSuppressFocus(PR_TRUE, "Activation Suppression");
|
||||
domWindow->Focus(); // This sets focus, but we'll ignore it.
|
||||
// A subsequent activate will cause us to stop suppressing.
|
||||
|
||||
@ -520,21 +530,8 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWebShell> contentShell;
|
||||
eventWindow->GetContentWebShell(getter_AddRefs(contentShell));
|
||||
if (contentShell) {
|
||||
|
||||
if (NS_SUCCEEDED(eventWindow->
|
||||
ConvertWebShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) {
|
||||
domWindow->Focus();
|
||||
}
|
||||
}
|
||||
else if (domWindow)
|
||||
domWindow->Focus();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user