Bug 13652: select method should fire onselect handlers, blur should blur, r=jst@netscape.com

This commit is contained in:
pollmann%netscape.com 2000-09-08 01:46:00 +00:00
Родитель 8315aef3a4
Коммит 4262a79a1f
10 изменённых файлов: 468 добавлений и 332 удалений

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

@ -245,8 +245,9 @@ nsHTMLAnchorElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aC
NS_IMETHODIMP
nsHTMLAnchorElement::Blur()
{
// XXX write me
return NS_OK;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
@ -314,8 +315,24 @@ nsHTMLAnchorElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLAnchorElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX write me
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP

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

@ -40,6 +40,7 @@
#include "nsIEventStateManager.h"
#include "nsDOMEvent.h"
#include "nsISizeOfHandler.h"
#include "nsIDocument.h"
static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID);
@ -317,46 +318,37 @@ NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Value, value)
NS_IMETHODIMP
nsHTMLButtonElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLButtonElement::Focus()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext)
{
// first see if we are disabled or not. If disabled then do nothing.
// first see if we are disabled or not. If disabled then do nothing.
nsAutoString disabled;
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
return NS_OK;
nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm);
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) {
return NS_OK;
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
Focus();
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
formControlFrame->ScrollIntoView(aPresContext);
}
return rv;
@ -365,8 +357,30 @@ nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLButtonElement::RemoveFocus(nsIPresContext* aPresContext)
{
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
static nsGenericHTMLElement::EnumTable kButtonTypeTable[] = {

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

@ -602,39 +602,17 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
NS_IMETHODIMP
nsHTMLInputElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
}
return NS_OK;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLInputElement::Focus()
{
nsCOMPtr<nsIDocument> doc; // Strong
nsresult rv = GetDocument(*getter_AddRefs(doc));
if (NS_SUCCEEDED(rv) && doc) {
PRInt32 numShells = doc->GetNumberOfShells();
nsCOMPtr<nsIPresContext> context;
for (PRInt32 i=0; i<numShells; i++)
{
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(i));
if (!shell) { rv = NS_ERROR_NULL_POINTER; break; }
rv = shell->GetPresContext(getter_AddRefs(context));
if (NS_FAILED(rv)) { break; }
if (!context) { rv = NS_ERROR_NULL_POINTER; break; }
rv = SetFocus(context);
if (NS_FAILED(rv)) { break; }
}
}
return NS_OK;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
@ -666,9 +644,30 @@ nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLInputElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX Should focus only this presContext
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP
@ -688,27 +687,16 @@ nsHTMLInputElement::Select()
if (NS_FORM_INPUT_PASSWORD == type ||
NS_FORM_INPUT_TEXT == type) {
// Currently we have to give focus to the text field before we
// can select text in it. :S
// Just like SetFocus() but without the ScrollIntoView()!
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == presContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent event;
event.eventStructType = NS_GUI_EVENT;
event.message = NS_FORM_SELECTED;
event.flags = NS_EVENT_FLAG_NONE;
event.widget = nsnull;
rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
}
// Now Select all the text!
if (NS_SUCCEEDED(rv)) {
rv = SelectAll(presContext);
}
}
return rv;
}
@ -742,7 +730,7 @@ nsHTMLInputElement::Click()
return rv;
}
// see what type of input we are. Only select for texts and passwords
// see what type of input we are. Only click button, checkbox, radio, reset, submit, & image
PRInt32 type;
GetType(&type);
if (NS_FORM_INPUT_BUTTON == type ||
@ -1027,6 +1015,28 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
} //switch
} break;// NS_MOUSE_LEFT_BUTTON_DOWN
case NS_FORM_SELECTED:
{
// XXX Bug? We have to give the input focus before contents can be selected
// Just like SetFocus() but without the ScrollIntoView()!
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
}
// Now Select all the text!
if (NS_SUCCEEDED(rv)) {
SelectAll(aPresContext);
}
} break; //NS_FORM_SELECTED
} //switch
} // if

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

@ -1070,56 +1070,74 @@ NS_IMPL_INT_ATTR(nsHTMLSelectElement, Size, size)
NS_IMPL_INT_ATTR(nsHTMLSelectElement, TabIndex, tabindex)
NS_IMETHODIMP
nsHTMLSelectElement::Blur() // XXX not tested
nsHTMLSelectElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLSelectElement::Focus()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
nsHTMLSelectElement::SetFocus(nsIPresContext* aPresContext)
{
nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm);
// first see if we are disabled or not. If disabled then do nothing.
nsAutoString disabled;
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) {
return NS_OK;
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
// XXX Should focus only this presContext
Focus();
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
formControlFrame->ScrollIntoView(aPresContext);
// Could call SelectAll(aPresContext) here to automatically
// select text when we receive focus.
}
return rv;
}
NS_IMETHODIMP
nsHTMLSelectElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX Should focus only this presContext
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP

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

@ -206,43 +206,19 @@ nsHTMLTextAreaElement::GetForm(nsIDOMHTMLFormElement** aForm)
NS_IMETHODIMP
nsHTMLTextAreaElement::Blur() // XXX not tested
nsHTMLTextAreaElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLTextAreaElement::Focus()
{
nsCOMPtr<nsIDocument> doc; // Strong
nsresult rv = GetDocument(*getter_AddRefs(doc));
if (NS_SUCCEEDED(rv) && doc) {
PRInt32 numShells = doc->GetNumberOfShells();
nsCOMPtr<nsIPresContext> context;
for (PRInt32 i=0; i<numShells; i++)
{
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(i));
if (!shell) { rv = NS_ERROR_NULL_POINTER; break; }
rv = shell->GetPresContext(getter_AddRefs(context));
if (NS_FAILED(rv)) { break; }
if (!context) { rv = NS_ERROR_NULL_POINTER; break; }
rv = SetFocus(context);
if (NS_FAILED(rv)) { break; }
}
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
@ -254,10 +230,9 @@ nsHTMLTextAreaElement::SetFocus(nsIPresContext* aPresContext)
return NS_OK;
}
nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm);
}
nsIFormControlFrame* formControlFrame = nsnull;
@ -275,9 +250,30 @@ nsHTMLTextAreaElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLTextAreaElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX Should focus only this presContext
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP
@ -291,30 +287,16 @@ nsHTMLTextAreaElement::Select()
return rv;
}
// Currently we have to give focus to the text field before we
// can select text in it. :S
// Just like SetFocus() but without the ScrollIntoView()!
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
nsCOMPtr<nsIEventStateManager> esm;
rv = presContext->GetEventStateManager(getter_AddRefs(esm));
if (NS_SUCCEEDED(rv)) {
rv = esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent event;
event.eventStructType = NS_GUI_EVENT;
event.message = NS_FORM_SELECTED;
event.flags = NS_EVENT_FLAG_NONE;
event.widget = nsnull;
rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
if (NS_SUCCEEDED(rv)) {
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
}
}
}
// Now Select all the text!
if (NS_SUCCEEDED(rv)) {
rv = SelectAll(presContext);
}
return rv;
}
@ -568,6 +550,33 @@ nsHTMLTextAreaElement::HandleDOMEvent(nsIPresContext* aPresContext,
rv = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
if ((NS_OK == rv) && (nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
switch (aEvent->message) {
case NS_FORM_SELECTED:
{
// XXX Selection bug?
// XXX We have to give the textarea focus before contents can be selected
// Just like SetFocus() but without the ScrollIntoView(), should we scroll?
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
// Now Select all the text!
rv = SelectAll(aPresContext);
}
} break; //NS_FORM_SELECTED
} //switch
} // if
// Finish the special anonymous content processing...
{
// If the event is starting here that's fine. If it's not

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

@ -245,8 +245,9 @@ nsHTMLAnchorElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aC
NS_IMETHODIMP
nsHTMLAnchorElement::Blur()
{
// XXX write me
return NS_OK;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
@ -314,8 +315,24 @@ nsHTMLAnchorElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLAnchorElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX write me
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP

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

@ -40,6 +40,7 @@
#include "nsIEventStateManager.h"
#include "nsDOMEvent.h"
#include "nsISizeOfHandler.h"
#include "nsIDocument.h"
static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID);
@ -317,46 +318,37 @@ NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Value, value)
NS_IMETHODIMP
nsHTMLButtonElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLButtonElement::Focus()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext)
{
// first see if we are disabled or not. If disabled then do nothing.
// first see if we are disabled or not. If disabled then do nothing.
nsAutoString disabled;
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled))
return NS_OK;
nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm);
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) {
return NS_OK;
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
Focus();
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
formControlFrame->ScrollIntoView(aPresContext);
}
return rv;
@ -365,8 +357,30 @@ nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLButtonElement::RemoveFocus(nsIPresContext* aPresContext)
{
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
static nsGenericHTMLElement::EnumTable kButtonTypeTable[] = {

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

@ -602,39 +602,17 @@ nsHTMLInputElement::SetChecked(PRBool aValue)
NS_IMETHODIMP
nsHTMLInputElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
}
return NS_OK;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLInputElement::Focus()
{
nsCOMPtr<nsIDocument> doc; // Strong
nsresult rv = GetDocument(*getter_AddRefs(doc));
if (NS_SUCCEEDED(rv) && doc) {
PRInt32 numShells = doc->GetNumberOfShells();
nsCOMPtr<nsIPresContext> context;
for (PRInt32 i=0; i<numShells; i++)
{
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(i));
if (!shell) { rv = NS_ERROR_NULL_POINTER; break; }
rv = shell->GetPresContext(getter_AddRefs(context));
if (NS_FAILED(rv)) { break; }
if (!context) { rv = NS_ERROR_NULL_POINTER; break; }
rv = SetFocus(context);
if (NS_FAILED(rv)) { break; }
}
}
return NS_OK;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
@ -666,9 +644,30 @@ nsHTMLInputElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLInputElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX Should focus only this presContext
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP
@ -688,27 +687,16 @@ nsHTMLInputElement::Select()
if (NS_FORM_INPUT_PASSWORD == type ||
NS_FORM_INPUT_TEXT == type) {
// Currently we have to give focus to the text field before we
// can select text in it. :S
// Just like SetFocus() but without the ScrollIntoView()!
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == presContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent event;
event.eventStructType = NS_GUI_EVENT;
event.message = NS_FORM_SELECTED;
event.flags = NS_EVENT_FLAG_NONE;
event.widget = nsnull;
rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
}
// Now Select all the text!
if (NS_SUCCEEDED(rv)) {
rv = SelectAll(presContext);
}
}
return rv;
}
@ -742,7 +730,7 @@ nsHTMLInputElement::Click()
return rv;
}
// see what type of input we are. Only select for texts and passwords
// see what type of input we are. Only click button, checkbox, radio, reset, submit, & image
PRInt32 type;
GetType(&type);
if (NS_FORM_INPUT_BUTTON == type ||
@ -1027,6 +1015,28 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
} //switch
} break;// NS_MOUSE_LEFT_BUTTON_DOWN
case NS_FORM_SELECTED:
{
// XXX Bug? We have to give the input focus before contents can be selected
// Just like SetFocus() but without the ScrollIntoView()!
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
}
// Now Select all the text!
if (NS_SUCCEEDED(rv)) {
SelectAll(aPresContext);
}
} break; //NS_FORM_SELECTED
} //switch
} // if

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

@ -1070,56 +1070,74 @@ NS_IMPL_INT_ATTR(nsHTMLSelectElement, Size, size)
NS_IMPL_INT_ATTR(nsHTMLSelectElement, TabIndex, tabindex)
NS_IMETHODIMP
nsHTMLSelectElement::Blur() // XXX not tested
nsHTMLSelectElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLSelectElement::Focus()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
nsHTMLSelectElement::SetFocus(nsIPresContext* aPresContext)
{
nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm);
// first see if we are disabled or not. If disabled then do nothing.
nsAutoString disabled;
if (NS_CONTENT_ATTR_HAS_VALUE == mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, disabled)) {
return NS_OK;
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
// XXX Should focus only this presContext
Focus();
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
formControlFrame->ScrollIntoView(aPresContext);
// Could call SelectAll(aPresContext) here to automatically
// select text when we receive focus.
}
return rv;
}
NS_IMETHODIMP
nsHTMLSelectElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX Should focus only this presContext
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP

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

@ -206,43 +206,19 @@ nsHTMLTextAreaElement::GetForm(nsIDOMHTMLFormElement** aForm)
NS_IMETHODIMP
nsHTMLTextAreaElement::Blur() // XXX not tested
nsHTMLTextAreaElement::Blur()
{
nsIFormControlFrame* formControlFrame = nsnull;
nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
// Ask the frame to Deselect focus (i.e Blur).
formControlFrame->SetFocus(PR_FALSE, PR_TRUE);
return NS_OK;
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return RemoveFocus(presContext);
}
NS_IMETHODIMP
nsHTMLTextAreaElement::Focus()
{
nsCOMPtr<nsIDocument> doc; // Strong
nsresult rv = GetDocument(*getter_AddRefs(doc));
if (NS_SUCCEEDED(rv) && doc) {
PRInt32 numShells = doc->GetNumberOfShells();
nsCOMPtr<nsIPresContext> context;
for (PRInt32 i=0; i<numShells; i++)
{
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(i));
if (!shell) { rv = NS_ERROR_NULL_POINTER; break; }
rv = shell->GetPresContext(getter_AddRefs(context));
if (NS_FAILED(rv)) { break; }
if (!context) { rv = NS_ERROR_NULL_POINTER; break; }
rv = SetFocus(context);
if (NS_FAILED(rv)) { break; }
}
}
return rv;
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
return SetFocus(presContext);
}
NS_IMETHODIMP
@ -254,10 +230,9 @@ nsHTMLTextAreaElement::SetFocus(nsIPresContext* aPresContext)
return NS_OK;
}
nsIEventStateManager* esm;
if (NS_OK == aPresContext->GetEventStateManager(&esm)) {
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
NS_RELEASE(esm);
}
nsIFormControlFrame* formControlFrame = nsnull;
@ -275,9 +250,30 @@ nsHTMLTextAreaElement::SetFocus(nsIPresContext* aPresContext)
NS_IMETHODIMP
nsHTMLTextAreaElement::RemoveFocus(nsIPresContext* aPresContext)
{
// XXX Should focus only this presContext
Blur();
return NS_OK;
// If we are disabled, we probably shouldn't have focus in the
// first place, so allow it to be removed.
nsresult rv = NS_OK;
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
}
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> rootContent;
rootContent = getter_AddRefs(doc->GetRootContent());
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
}
return rv;
}
NS_IMETHODIMP
@ -291,30 +287,16 @@ nsHTMLTextAreaElement::Select()
return rv;
}
// Currently we have to give focus to the text field before we
// can select text in it. :S
// Just like SetFocus() but without the ScrollIntoView()!
nsCOMPtr<nsIPresContext> presContext;
nsGenericHTMLElement::GetPresContext(this, getter_AddRefs(presContext));
nsCOMPtr<nsIEventStateManager> esm;
rv = presContext->GetEventStateManager(getter_AddRefs(esm));
if (NS_SUCCEEDED(rv)) {
rv = esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent event;
event.eventStructType = NS_GUI_EVENT;
event.message = NS_FORM_SELECTED;
event.flags = NS_EVENT_FLAG_NONE;
event.widget = nsnull;
rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
if (NS_SUCCEEDED(rv)) {
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
}
}
}
// Now Select all the text!
if (NS_SUCCEEDED(rv)) {
rv = SelectAll(presContext);
}
return rv;
}
@ -568,6 +550,33 @@ nsHTMLTextAreaElement::HandleDOMEvent(nsIPresContext* aPresContext,
rv = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
if ((NS_OK == rv) && (nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
switch (aEvent->message) {
case NS_FORM_SELECTED:
{
// XXX Selection bug?
// XXX We have to give the textarea focus before contents can be selected
// Just like SetFocus() but without the ScrollIntoView(), should we scroll?
nsCOMPtr<nsIEventStateManager> esm;
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
}
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
// Now Select all the text!
rv = SelectAll(aPresContext);
}
} break; //NS_FORM_SELECTED
} //switch
} // if
// Finish the special anonymous content processing...
{
// If the event is starting here that's fine. If it's not