diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 644b6facb497..bc168deb1598 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -65,6 +65,7 @@ #include "nsIDOMHTMLMapElement.h" #include "nsIDOMHTMLBodyElement.h" #include "nsIDOMXULControlElement.h" +#include "nsIDOMXULTextboxElement.h" #include "nsImageMapUtils.h" #include "nsIHTMLDocument.h" #include "nsINameSpaceManager.h" @@ -191,7 +192,6 @@ static nsIDocument * GetDocumentFromWindow(nsIDOMWindow *aWindow) { nsCOMPtr win = do_QueryInterface(aWindow); - nsPIDOMWindow *innerWin; nsCOMPtr doc; if (win) { @@ -4164,8 +4164,24 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, if (aContent) { // Check if the HandleDOMEvent calls above destroyed our frame (bug #118685) - // or made it not focusable in any way + // or made it not focusable in any way. + // Flush pending updates to the frame tree first (bug 305840). + presShell->FlushPendingNotifications(Flush_Frames); + nsIFrame* focusFrame = presShell->GetPrimaryFrameFor(aContent); + + // XUL textboxes are not focusable for various reasons so we check if + // the inner html:input frame is focusable instead (bug 305840). + if (aContent->IsContentOfType(nsIContent::eXUL)) { + nsCOMPtr textbox = do_QueryInterface(aContent); + if (textbox) { + nsCOMPtr inputNode; + textbox->GetInputField(getter_AddRefs(inputNode)); + nsCOMPtr input = do_QueryInterface(inputNode); + focusFrame = input ? presShell->GetPrimaryFrameFor(input) : nsnull; + } + } + if (focusFrame) { if (aContent->Tag() != nsHTMLAtoms::area) { if (!focusFrame->IsFocusable()) { diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index d6258b80139a..15b3c5689127 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -1170,7 +1170,7 @@ nsHTMLInputElement::Select() esm->GetContentState(this, currentState); if (!(currentState & NS_EVENT_STATE_FOCUS) && !esm->SetContentState(this, NS_EVENT_STATE_FOCUS)) { - return NS_ERROR_FAILURE; // Unable to focus + return rv; // We ended up unfocused, e.g. due to a DOM event handler. } } diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index 2860c8f40aee..e1df59348b54 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -287,7 +287,7 @@ nsHTMLTextAreaElement::Select() if (shouldFocus && !presContext->EventStateManager()->SetContentState(this, NS_EVENT_STATE_FOCUS)) { - return NS_ERROR_FAILURE; // Unable to focus + return rv; // We ended up unfocused, e.g. due to a DOM event handler. } nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);