зеркало из https://github.com/mozilla/gecko-dev.git
Bug 25300: Enable activation of buttons by the keyboard (space or enter) r=nisheeth
This commit is contained in:
Родитель
fa76031aa1
Коммит
a97d394820
|
@ -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:
|
||||||
|
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;
|
nsEventStatus status = nsEventStatus_eIgnore;
|
||||||
GetChecked(&checked);
|
nsMouseEvent event;
|
||||||
SetChecked(!checked);
|
event.eventStructType = NS_GUI_EVENT;
|
||||||
}
|
event.message = NS_MOUSE_LEFT_CLICK;
|
||||||
break;
|
event.isShift = PR_FALSE;
|
||||||
case NS_FORM_INPUT_RADIO:
|
event.isControl = PR_FALSE;
|
||||||
SetChecked(PR_TRUE);
|
event.isAlt = PR_FALSE;
|
||||||
break;
|
event.isMeta = PR_FALSE;
|
||||||
case NS_FORM_INPUT_BUTTON:
|
event.clickCount = 0;
|
||||||
case NS_FORM_INPUT_RESET:
|
event.widget = nsnull;
|
||||||
case NS_FORM_INPUT_SUBMIT:
|
rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||||
{
|
} // case
|
||||||
//Checkboxes and radio trigger off return or space but buttons
|
} // switch
|
||||||
//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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} 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:
|
||||||
|
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;
|
nsEventStatus status = nsEventStatus_eIgnore;
|
||||||
GetChecked(&checked);
|
nsMouseEvent event;
|
||||||
SetChecked(!checked);
|
event.eventStructType = NS_GUI_EVENT;
|
||||||
}
|
event.message = NS_MOUSE_LEFT_CLICK;
|
||||||
break;
|
event.isShift = PR_FALSE;
|
||||||
case NS_FORM_INPUT_RADIO:
|
event.isControl = PR_FALSE;
|
||||||
SetChecked(PR_TRUE);
|
event.isAlt = PR_FALSE;
|
||||||
break;
|
event.isMeta = PR_FALSE;
|
||||||
case NS_FORM_INPUT_BUTTON:
|
event.clickCount = 0;
|
||||||
case NS_FORM_INPUT_RESET:
|
event.widget = nsnull;
|
||||||
case NS_FORM_INPUT_SUBMIT:
|
rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||||
{
|
} // case
|
||||||
//Checkboxes and radio trigger off return or space but buttons
|
} // switch
|
||||||
//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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче