Bug 25300: Enable activation of buttons by the keyboard (space or enter) r=nisheeth

This commit is contained in:
pollmann%netscape.com 2000-06-21 00:40:11 +00:00
Родитель fa76031aa1
Коммит a97d394820
6 изменённых файлов: 108 добавлений и 72 удалений

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

@ -481,6 +481,38 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext,
if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) && if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) { !(aFlags & NS_EVENT_FLAG_CAPTURE)) {
switch (aEvent->message) { switch (aEvent->message) {
case NS_KEY_PRESS:
{
// For backwards compat, trigger buttons with space or enter (bug 25300)
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->keyCode == NS_VK_RETURN || keyEvent->charCode == NS_VK_SPACE) {
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_GUI_EVENT;
event.message = NS_MOUSE_LEFT_CLICK;
event.isShift = PR_FALSE;
event.isControl = PR_FALSE;
event.isAlt = PR_FALSE;
event.isMeta = PR_FALSE;
event.clickCount = 0;
event.widget = nsnull;
rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
}
}
break;// NS_KEY_PRESS
case NS_MOUSE_LEFT_CLICK:
{
// Tell the frame about the click
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->MouseClicked(aPresContext);
}
}
break;// NS_MOUSE_LEFT_CLICK
case NS_MOUSE_LEFT_BUTTON_DOWN: case NS_MOUSE_LEFT_BUTTON_DOWN:
{ {
nsIEventStateManager *stateManager; nsIEventStateManager *stateManager;

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

@ -845,40 +845,32 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
case NS_KEY_PRESS: case NS_KEY_PRESS:
{ {
// For backwards compat, trigger checks/radios/buttons with space or enter (bug 25300)
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->keyCode == NS_VK_RETURN || keyEvent->charCode == 0x20) { if (keyEvent->keyCode == NS_VK_RETURN || keyEvent->charCode == NS_VK_SPACE) {
PRInt32 type; PRInt32 type;
GetType(&type); GetType(&type);
switch(type) { switch(type) {
case NS_FORM_INPUT_CHECKBOX: case NS_FORM_INPUT_CHECKBOX:
{
PRBool checked;
GetChecked(&checked);
SetChecked(!checked);
}
break;
case NS_FORM_INPUT_RADIO: case NS_FORM_INPUT_RADIO:
SetChecked(PR_TRUE);
break;
case NS_FORM_INPUT_BUTTON: case NS_FORM_INPUT_BUTTON:
case NS_FORM_INPUT_RESET: case NS_FORM_INPUT_RESET:
case NS_FORM_INPUT_SUBMIT: case NS_FORM_INPUT_SUBMIT:
// case NS_FORM_INPUT_IMAGE: // XXX should we do this for images too?
{ {
//Checkboxes and radio trigger off return or space but buttons nsEventStatus status = nsEventStatus_eIgnore;
//just trigger off space, go figure. nsMouseEvent event;
if (keyEvent->charCode == 0x20) { event.eventStructType = NS_GUI_EVENT;
//XXX We should just be able to call Click() here but then event.message = NS_MOUSE_LEFT_CLICK;
//Click wouldn't have a PresContext. event.isShift = PR_FALSE;
nsIFormControlFrame* formControlFrame = nsnull; event.isControl = PR_FALSE;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) { event.isAlt = PR_FALSE;
if (formControlFrame) { event.isMeta = PR_FALSE;
formControlFrame->MouseClicked(aPresContext); event.clickCount = 0;
} event.widget = nsnull;
} rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
} } // case
} } // switch
break;
}
} }
} break;// NS_KEY_PRESS } break;// NS_KEY_PRESS

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

@ -390,13 +390,7 @@ nsHTMLButtonControlFrame::HandleEvent(nsIPresContext* aPresContext,
return NS_OK; return NS_OK;
} }
// lets see if the button was clicked. -EDV // mouse clicks are handled by content
switch (aEvent->message) {
case NS_MOUSE_LEFT_CLICK:
MouseClicked(aPresContext);
break;
}
// we don't want our children to get any events. So just pass it to frame. // we don't want our children to get any events. So just pass it to frame.
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
} }

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

@ -481,6 +481,38 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext,
if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) && if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE)) { !(aFlags & NS_EVENT_FLAG_CAPTURE)) {
switch (aEvent->message) { switch (aEvent->message) {
case NS_KEY_PRESS:
{
// For backwards compat, trigger buttons with space or enter (bug 25300)
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->keyCode == NS_VK_RETURN || keyEvent->charCode == NS_VK_SPACE) {
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_GUI_EVENT;
event.message = NS_MOUSE_LEFT_CLICK;
event.isShift = PR_FALSE;
event.isControl = PR_FALSE;
event.isAlt = PR_FALSE;
event.isMeta = PR_FALSE;
event.clickCount = 0;
event.widget = nsnull;
rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
}
}
break;// NS_KEY_PRESS
case NS_MOUSE_LEFT_CLICK:
{
// Tell the frame about the click
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);
if (NS_SUCCEEDED(rv)) {
formControlFrame->MouseClicked(aPresContext);
}
}
break;// NS_MOUSE_LEFT_CLICK
case NS_MOUSE_LEFT_BUTTON_DOWN: case NS_MOUSE_LEFT_BUTTON_DOWN:
{ {
nsIEventStateManager *stateManager; nsIEventStateManager *stateManager;

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

@ -845,40 +845,32 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
case NS_KEY_PRESS: case NS_KEY_PRESS:
{ {
// For backwards compat, trigger checks/radios/buttons with space or enter (bug 25300)
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->keyCode == NS_VK_RETURN || keyEvent->charCode == 0x20) { if (keyEvent->keyCode == NS_VK_RETURN || keyEvent->charCode == NS_VK_SPACE) {
PRInt32 type; PRInt32 type;
GetType(&type); GetType(&type);
switch(type) { switch(type) {
case NS_FORM_INPUT_CHECKBOX: case NS_FORM_INPUT_CHECKBOX:
{
PRBool checked;
GetChecked(&checked);
SetChecked(!checked);
}
break;
case NS_FORM_INPUT_RADIO: case NS_FORM_INPUT_RADIO:
SetChecked(PR_TRUE);
break;
case NS_FORM_INPUT_BUTTON: case NS_FORM_INPUT_BUTTON:
case NS_FORM_INPUT_RESET: case NS_FORM_INPUT_RESET:
case NS_FORM_INPUT_SUBMIT: case NS_FORM_INPUT_SUBMIT:
// case NS_FORM_INPUT_IMAGE: // XXX should we do this for images too?
{ {
//Checkboxes and radio trigger off return or space but buttons nsEventStatus status = nsEventStatus_eIgnore;
//just trigger off space, go figure. nsMouseEvent event;
if (keyEvent->charCode == 0x20) { event.eventStructType = NS_GUI_EVENT;
//XXX We should just be able to call Click() here but then event.message = NS_MOUSE_LEFT_CLICK;
//Click wouldn't have a PresContext. event.isShift = PR_FALSE;
nsIFormControlFrame* formControlFrame = nsnull; event.isControl = PR_FALSE;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) { event.isAlt = PR_FALSE;
if (formControlFrame) { event.isMeta = PR_FALSE;
formControlFrame->MouseClicked(aPresContext); event.clickCount = 0;
} event.widget = nsnull;
} rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
} } // case
} } // switch
break;
}
} }
} break;// NS_KEY_PRESS } break;// NS_KEY_PRESS

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

@ -390,13 +390,7 @@ nsHTMLButtonControlFrame::HandleEvent(nsIPresContext* aPresContext,
return NS_OK; return NS_OK;
} }
// lets see if the button was clicked. -EDV // mouse clicks are handled by content
switch (aEvent->message) {
case NS_MOUSE_LEFT_CLICK:
MouseClicked(aPresContext);
break;
}
// we don't want our children to get any events. So just pass it to frame. // we don't want our children to get any events. So just pass it to frame.
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
} }