It will now mask out any focus events that may be generated because of native windows

r=buster, bug 17196
This commit is contained in:
rods%netscape.com 1999-11-15 15:13:12 +00:00
parent 1cbaf268cf
commit 3989b4018f
2 changed files with 28 additions and 6 deletions

View File

@ -178,6 +178,7 @@ protected:
nsGenericHTMLLeafElement mInner; nsGenericHTMLLeafElement mInner;
nsIForm* mForm; nsIForm* mForm;
PRInt32 mType; PRInt32 mType;
PRBool mSkipFocusEvent;
PRBool IsImage() const { PRBool IsImage() const {
nsAutoString tmp; nsAutoString tmp;
@ -209,6 +210,7 @@ nsHTMLInputElement::nsHTMLInputElement(nsIAtom* aTag)
mInner.Init(this, aTag); mInner.Init(this, aTag);
mType = NS_FORM_INPUT_TEXT; // default value mType = NS_FORM_INPUT_TEXT; // default value
mForm = nsnull; mForm = nsnull;
mSkipFocusEvent = PR_FALSE;
//nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__); //nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
} }
@ -535,19 +537,21 @@ nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext)
nsAutoString disabled; nsAutoString disabled;
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
return NS_OK; return NS_OK;
nsIEventStateManager* esm; nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) { if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS); esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm); NS_RELEASE(esm);
} }
nsIFormControlFrame* formControlFrame = nsnull; nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE); // XXX commented out - redundant
// formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
formControlFrame->ScrollIntoView(aPresContext); formControlFrame->ScrollIntoView(aPresContext);
} }
return rv; return rv;
} }
@ -611,6 +615,11 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext& aPresContext,
PRUint32 aFlags, PRUint32 aFlags,
nsEventStatus& aEventStatus) nsEventStatus& aEventStatus)
{ {
if ((aEvent->message == NS_FOCUS_CONTENT && mSkipFocusEvent) ||
(aEvent->message == NS_BLUR_CONTENT && mSkipFocusEvent)) {
return NS_OK;
}
// Try script event handlers first // Try script event handlers first
nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent, nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus); aFlags, aEventStatus);
@ -622,7 +631,9 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext& aPresContext,
nsIFormControlFrame* formControlFrame = nsnull; nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
mSkipFocusEvent = PR_TRUE;
formControlFrame->SetFocus(PR_TRUE, PR_TRUE); formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
mSkipFocusEvent = PR_FALSE;
return NS_OK; return NS_OK;
} }
} }

View File

@ -178,6 +178,7 @@ protected:
nsGenericHTMLLeafElement mInner; nsGenericHTMLLeafElement mInner;
nsIForm* mForm; nsIForm* mForm;
PRInt32 mType; PRInt32 mType;
PRBool mSkipFocusEvent;
PRBool IsImage() const { PRBool IsImage() const {
nsAutoString tmp; nsAutoString tmp;
@ -209,6 +210,7 @@ nsHTMLInputElement::nsHTMLInputElement(nsIAtom* aTag)
mInner.Init(this, aTag); mInner.Init(this, aTag);
mType = NS_FORM_INPUT_TEXT; // default value mType = NS_FORM_INPUT_TEXT; // default value
mForm = nsnull; mForm = nsnull;
mSkipFocusEvent = PR_FALSE;
//nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__); //nsTraceRefcnt::Create((nsIFormControl*)this, "nsHTMLFormControlElement", __FILE__, __LINE__);
} }
@ -535,19 +537,21 @@ nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext)
nsAutoString disabled; nsAutoString disabled;
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
return NS_OK; return NS_OK;
nsIEventStateManager* esm; nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) { if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS); esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm); NS_RELEASE(esm);
} }
nsIFormControlFrame* formControlFrame = nsnull; nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE); // XXX commented out - redundant
// formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
formControlFrame->ScrollIntoView(aPresContext); formControlFrame->ScrollIntoView(aPresContext);
} }
return rv; return rv;
} }
@ -611,6 +615,11 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext& aPresContext,
PRUint32 aFlags, PRUint32 aFlags,
nsEventStatus& aEventStatus) nsEventStatus& aEventStatus)
{ {
if ((aEvent->message == NS_FOCUS_CONTENT && mSkipFocusEvent) ||
(aEvent->message == NS_BLUR_CONTENT && mSkipFocusEvent)) {
return NS_OK;
}
// Try script event handlers first // Try script event handlers first
nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent, nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus); aFlags, aEventStatus);
@ -622,7 +631,9 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext& aPresContext,
nsIFormControlFrame* formControlFrame = nsnull; nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
mSkipFocusEvent = PR_TRUE;
formControlFrame->SetFocus(PR_TRUE, PR_TRUE); formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
mSkipFocusEvent = PR_FALSE;
return NS_OK; return NS_OK;
} }
} }