Bug 303730 - <textarea>s in other tabs mess up focus in current 'tab', patch by chpe(at)gnome.org, r=jst, sr=bryner

This commit is contained in:
martijn.martijn%gmail.com 2006-07-13 09:14:56 +00:00
Родитель e53577c4d3
Коммит 03ed60c2d0
1 изменённых файлов: 44 добавлений и 0 удалений

Просмотреть файл

@ -41,6 +41,8 @@
#include "nsITextControlElement.h"
#include "nsIDOMNSEditableElement.h"
#include "nsIControllers.h"
#include "nsIFocusController.h"
#include "nsPIDOMWindow.h"
#include "nsContentCID.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
@ -251,6 +253,27 @@ nsHTMLTextAreaElement::SetFocus(nsPresContext* aPresContext)
return;
}
// We can't be focus'd if we aren't in a document
nsIDocument* doc = GetCurrentDoc();
if (!doc)
return;
// 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.
nsPIDOMWindow* win = doc->GetWindow();
if (win) {
nsIFocusController *focusController = win->GetRootFocusController();
PRBool isActive = PR_FALSE;
focusController->GetActive(&isActive);
if (!isActive) {
focusController->SetFocusedWindow(win);
focusController->SetFocusedElement(this);
return;
}
}
nsIEventStateManager *esm = aPresContext->EventStateManager();
if (esm->SetContentState(this, NS_EVENT_STATE_FOCUS)) {
nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
@ -271,6 +294,27 @@ nsHTMLTextAreaElement::Select()
return rv;
}
// We can't be focus'd if we aren't in a document
nsIDocument* doc = GetCurrentDoc();
if (!doc)
return rv;
// 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.
nsPIDOMWindow* win = doc->GetWindow();
if (win) {
nsIFocusController *focusController = win->GetRootFocusController();
PRBool isActive = PR_FALSE;
focusController->GetActive(&isActive);
if (!isActive) {
focusController->SetFocusedWindow(win);
focusController->SetFocusedElement(this);
return rv;
}
}
// XXX Bug? We have to give the input focus before contents can be
// selected