mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 10:33:33 +00:00
Bug 25300: Enable activation of buttons by the keyboard (space or enter) r=nisheeth
This commit is contained in:
parent
fa76031aa1
commit
a97d394820
@ -481,6 +481,38 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&
|
||||
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
|
||||
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:
|
||||
{
|
||||
nsIEventStateManager *stateManager;
|
||||
|
@ -845,40 +845,32 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
|
||||
case NS_KEY_PRESS:
|
||||
{
|
||||
// For backwards compat, trigger checks/radios/buttons with space or enter (bug 25300)
|
||||
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;
|
||||
GetType(&type);
|
||||
switch(type) {
|
||||
case NS_FORM_INPUT_CHECKBOX:
|
||||
case NS_FORM_INPUT_CHECKBOX:
|
||||
case NS_FORM_INPUT_RADIO:
|
||||
case NS_FORM_INPUT_BUTTON:
|
||||
case NS_FORM_INPUT_RESET:
|
||||
case NS_FORM_INPUT_SUBMIT:
|
||||
// case NS_FORM_INPUT_IMAGE: // XXX should we do this for images too?
|
||||
{
|
||||
PRBool checked;
|
||||
GetChecked(&checked);
|
||||
SetChecked(!checked);
|
||||
}
|
||||
break;
|
||||
case NS_FORM_INPUT_RADIO:
|
||||
SetChecked(PR_TRUE);
|
||||
break;
|
||||
case NS_FORM_INPUT_BUTTON:
|
||||
case NS_FORM_INPUT_RESET:
|
||||
case NS_FORM_INPUT_SUBMIT:
|
||||
{
|
||||
//Checkboxes and radio trigger off return or space but buttons
|
||||
//just trigger off space, go figure.
|
||||
if (keyEvent->charCode == 0x20) {
|
||||
//XXX We should just be able to call Click() here but then
|
||||
//Click wouldn't have a PresContext.
|
||||
nsIFormControlFrame* formControlFrame = nsnull;
|
||||
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
|
||||
if (formControlFrame) {
|
||||
formControlFrame->MouseClicked(aPresContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
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);
|
||||
} // case
|
||||
} // switch
|
||||
}
|
||||
} break;// NS_KEY_PRESS
|
||||
|
||||
|
@ -390,13 +390,7 @@ nsHTMLButtonControlFrame::HandleEvent(nsIPresContext* aPresContext,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// lets see if the button was clicked. -EDV
|
||||
switch (aEvent->message) {
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
MouseClicked(aPresContext);
|
||||
break;
|
||||
}
|
||||
|
||||
// mouse clicks are handled by content
|
||||
// we don't want our children to get any events. So just pass it to frame.
|
||||
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
@ -481,6 +481,38 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&
|
||||
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
|
||||
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:
|
||||
{
|
||||
nsIEventStateManager *stateManager;
|
||||
|
@ -845,40 +845,32 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
|
||||
case NS_KEY_PRESS:
|
||||
{
|
||||
// For backwards compat, trigger checks/radios/buttons with space or enter (bug 25300)
|
||||
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;
|
||||
GetType(&type);
|
||||
switch(type) {
|
||||
case NS_FORM_INPUT_CHECKBOX:
|
||||
case NS_FORM_INPUT_CHECKBOX:
|
||||
case NS_FORM_INPUT_RADIO:
|
||||
case NS_FORM_INPUT_BUTTON:
|
||||
case NS_FORM_INPUT_RESET:
|
||||
case NS_FORM_INPUT_SUBMIT:
|
||||
// case NS_FORM_INPUT_IMAGE: // XXX should we do this for images too?
|
||||
{
|
||||
PRBool checked;
|
||||
GetChecked(&checked);
|
||||
SetChecked(!checked);
|
||||
}
|
||||
break;
|
||||
case NS_FORM_INPUT_RADIO:
|
||||
SetChecked(PR_TRUE);
|
||||
break;
|
||||
case NS_FORM_INPUT_BUTTON:
|
||||
case NS_FORM_INPUT_RESET:
|
||||
case NS_FORM_INPUT_SUBMIT:
|
||||
{
|
||||
//Checkboxes and radio trigger off return or space but buttons
|
||||
//just trigger off space, go figure.
|
||||
if (keyEvent->charCode == 0x20) {
|
||||
//XXX We should just be able to call Click() here but then
|
||||
//Click wouldn't have a PresContext.
|
||||
nsIFormControlFrame* formControlFrame = nsnull;
|
||||
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
|
||||
if (formControlFrame) {
|
||||
formControlFrame->MouseClicked(aPresContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
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);
|
||||
} // case
|
||||
} // switch
|
||||
}
|
||||
} break;// NS_KEY_PRESS
|
||||
|
||||
|
@ -390,13 +390,7 @@ nsHTMLButtonControlFrame::HandleEvent(nsIPresContext* aPresContext,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// lets see if the button was clicked. -EDV
|
||||
switch (aEvent->message) {
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
MouseClicked(aPresContext);
|
||||
break;
|
||||
}
|
||||
|
||||
// mouse clicks are handled by content
|
||||
// we don't want our children to get any events. So just pass it to frame.
|
||||
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user