Bug 104371 - shiftKey not set correctly for keypress events, breaking shift+space binding. r=brade, bzbarsky, sr=hyatt.

This commit is contained in:
bryner%netscape.com 2002-11-07 03:34:13 +00:00
parent da13ded012
commit be89105ec4
16 changed files with 50 additions and 61 deletions

View File

@ -30,8 +30,8 @@ Can't yet put script tags in XBL (hyatt has the bug)
-->
</handler>
<handler event="keypress" key=" " command="cmd_scrollPageDown" />
<handler event="keypress" key=" " modifiers="shift" command="cmd_scrollPageUp" />
<handler event="keypress" key=" " command="cmd_scrollPageDown" />
<handler event="keypress" keycode="VK_UP" command="cmd_scrollLineUp" />
<handler event="keypress" keycode="VK_DOWN" command="cmd_scrollLineDown" />

View File

@ -92,6 +92,7 @@ const PRInt32 nsXBLPrototypeHandler::cShift = (1<<1);
const PRInt32 nsXBLPrototypeHandler::cAlt = (1<<2);
const PRInt32 nsXBLPrototypeHandler::cControl = (1<<3);
const PRInt32 nsXBLPrototypeHandler::cMeta = (1<<4);
const PRInt32 nsXBLPrototypeHandler::cAllModifiers = cShift | cAlt | cControl | cMeta;
nsXBLPrototypeHandler::nsXBLPrototypeHandler(const PRUnichar* aEvent, const PRUnichar* aPhase,
const PRUnichar* aAction, const PRUnichar* aCommand,
@ -612,7 +613,12 @@ nsXBLPrototypeHandler::KeyEventMatched(nsIAtom* aEventType, nsIDOMKeyEvent* aKey
}
// Now check modifier keys
PRBool result = ModifiersMatchMask(aKeyEvent);
PRInt32 modKeys = cAllModifiers;
// Don't check shift if we matched the char code and shift isn't specified
// in the handler.
if (mMisc && !(mKeyMask & cShift))
modKeys &= ~cShift;
PRBool result = ModifiersMatchMask(aKeyEvent, modKeys);
*aResult = result;
return NS_OK;
}
@ -644,7 +650,7 @@ nsXBLPrototypeHandler::MouseEventMatched(nsIAtom* aEventType, nsIDOMMouseEvent*
return NS_OK;
}
PRBool result = ModifiersMatchMask(aMouseEvent);
PRBool result = ModifiersMatchMask(aMouseEvent, cAllModifiers);
*aResult = result;
return NS_OK;
}
@ -945,27 +951,36 @@ nsXBLPrototypeHandler::ConstructPrototype(nsIContent* aKeyElement,
}
PRBool
nsXBLPrototypeHandler::ModifiersMatchMask(nsIDOMUIEvent* aEvent)
nsXBLPrototypeHandler::ModifiersMatchMask(nsIDOMUIEvent* aEvent,
PRInt32 aModifiersMask)
{
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent));
PRBool keyPresent;
key ? key->GetMetaKey(&keyPresent) : mouse->GetMetaKey(&keyPresent);
if (keyPresent != ((mKeyMask & cMeta) != 0))
return PR_FALSE;
if (aModifiersMask & cMeta) {
key ? key->GetMetaKey(&keyPresent) : mouse->GetMetaKey(&keyPresent);
if (keyPresent != ((mKeyMask & cMeta) != 0))
return PR_FALSE;
}
key ? key->GetShiftKey(&keyPresent) : mouse->GetShiftKey(&keyPresent);
if (keyPresent != ((mKeyMask & cShift) != 0))
return PR_FALSE;
key ? key->GetAltKey(&keyPresent) : mouse->GetAltKey(&keyPresent);
if (keyPresent != ((mKeyMask & cAlt) != 0))
return PR_FALSE;
if (aModifiersMask & cShift) {
key ? key->GetShiftKey(&keyPresent) : mouse->GetShiftKey(&keyPresent);
if (keyPresent != ((mKeyMask & cShift) != 0))
return PR_FALSE;
}
key ? key->GetCtrlKey(&keyPresent) : mouse->GetCtrlKey(&keyPresent);
if (keyPresent != ((mKeyMask & cControl) != 0))
return PR_FALSE;
if (aModifiersMask & cAlt) {
key ? key->GetAltKey(&keyPresent) : mouse->GetAltKey(&keyPresent);
if (keyPresent != ((mKeyMask & cAlt) != 0))
return PR_FALSE;
}
if (aModifiersMask & cControl) {
key ? key->GetCtrlKey(&keyPresent) : mouse->GetCtrlKey(&keyPresent);
if (keyPresent != ((mKeyMask & cControl) != 0))
return PR_FALSE;
}
return PR_TRUE;
}

View File

@ -114,7 +114,7 @@ protected:
const PRUnichar* aClickCount=nsnull, const PRUnichar* aPreventDefault=nsnull);
void GetEventType(nsAString& type);
PRBool ModifiersMatchMask(nsIDOMUIEvent* aEvent);
PRBool ModifiersMatchMask(nsIDOMUIEvent* aEvent, PRInt32 aModifiersMask);
inline PRBool KeyEventMatched(nsIDOMKeyEvent* aKeyEvent);
inline PRBool MouseEventMatched(nsIDOMMouseEvent* aMouseEvent);
@ -129,6 +129,7 @@ protected:
static const PRInt32 cAlt;
static const PRInt32 cControl;
static const PRInt32 cMeta;
static const PRInt32 cAllModifiers;
protected:
union {

View File

@ -1309,7 +1309,7 @@ NS_IMETHODIMP nsHTMLEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent)
// if we got here we either fell out of the tab case or have a normal character.
// Either way, treat as normal character.
if (character && !altKey && !ctrlKey && !isShift && !metaKey)
if (character && !altKey && !ctrlKey && !metaKey)
{
aKeyEvent->PreventDefault();
nsAutoString key(character);

View File

@ -514,12 +514,11 @@ PRBool nsPlaintextEditor::IsModifiable()
NS_IMETHODIMP nsPlaintextEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent)
{
PRUint32 keyCode, character;
PRBool isShift, ctrlKey, altKey, metaKey;
PRBool ctrlKey, altKey, metaKey;
if (!aKeyEvent) return NS_ERROR_NULL_POINTER;
if (NS_SUCCEEDED(aKeyEvent->GetKeyCode(&keyCode)) &&
NS_SUCCEEDED(aKeyEvent->GetShiftKey(&isShift)) &&
NS_SUCCEEDED(aKeyEvent->GetCtrlKey(&ctrlKey)) &&
NS_SUCCEEDED(aKeyEvent->GetAltKey(&altKey)) &&
NS_SUCCEEDED(aKeyEvent->GetMetaKey(&metaKey)))
@ -538,7 +537,7 @@ NS_IMETHODIMP nsPlaintextEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent)
return TypedText(empty, eTypedText);
}
if (character && !altKey && !ctrlKey && !isShift && !metaKey)
if (character && !altKey && !ctrlKey && !metaKey)
{
aKeyEvent->PreventDefault();
nsAutoString key(character);

View File

@ -2210,7 +2210,6 @@ PRBool nsWindow::OnKeyDown(PRUint32 aEventType, const char *bytes,
}
aTranslatedKeyCode = 0;
mIsShiftDown = PR_FALSE;
break;
}
}

View File

@ -2628,7 +2628,7 @@ static PRBool IsSpecialRaptorKey(UInt32 macKeyCode)
if (aMessage == NS_KEY_PRESS && !IsSpecialRaptorKey([aKeyEvent keyCode]))
{
if (!outGeckoEvent->isControl && !outGeckoEvent->isMeta)
outGeckoEvent->isShift = outGeckoEvent->isControl = outGeckoEvent->isAlt = outGeckoEvent->isMeta = 0;
outGeckoEvent->isControl = outGeckoEvent->isAlt = outGeckoEvent->isMeta = 0;
// We're not a special key.
outGeckoEvent->keyCode = 0;

View File

@ -430,8 +430,7 @@ void InitKeyPressEvent(GdkEventKey *aGEK,
anEvent.charCode >= GDK_A &&
anEvent.charCode <= GDK_Z )
anEvent.charCode = gdk_keyval_to_lower(anEvent.charCode);
} else
anEvent.isShift = PR_FALSE;
}
} else {
anEvent.keyCode = nsPlatformToDOMKeyCode(aGEK);
}

View File

@ -1545,8 +1545,7 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent)
event.charCode >= GDK_A &&
event.charCode <= GDK_Z )
event.charCode = gdk_keyval_to_lower(event.charCode);
} else
event.isShift = PR_FALSE;
}
}
// send the key press event

View File

@ -973,7 +973,7 @@ void nsMacEventHandler::InitializeKeyEvent(nsKeyEvent& aKeyEvent,
{
if (!aKeyEvent.isMeta)
{
aKeyEvent.isShift = aKeyEvent.isControl = aKeyEvent.isAlt = aKeyEvent.isMeta = 0;
aKeyEvent.isControl = aKeyEvent.isAlt = aKeyEvent.isMeta = 0;
} // if (!aKeyEvent.isMeta)
aKeyEvent.keyCode = 0;

View File

@ -2132,13 +2132,8 @@ PRBool nsWindow::OnKey( MPARAM mp1, MPARAM mp2)
if ( !(fsFlags & KC_VIRTUALKEY) ||
((fsFlags & KC_CHAR) && (event.keyCode == 0)) )
{
event.isShift = PR_FALSE;
event.keyCode = 0;
}
else if (usVKey == VK_SPACE)
{
event.isShift = PR_FALSE;
}
else // Real virtual key
{
event.charCode = 0;

View File

@ -1392,16 +1392,15 @@ void nsWidget::InitKeyEvent(PhKeyEvent_t *aPhKeyEvent,
if ((anEvent.isControl) || (anEvent.isAlt))
anEvent.charCode = aPhKeyEvent->key_cap;
else
anEvent.isShift = anEvent.isControl = anEvent.isAlt = anEvent.isMeta = PR_FALSE;
}
else {
anEvent.charCode = 0;
anEvent.keyCode = (keysym & 0x00FF);
}
}
}
else
anEvent.isControl = anEvent.isAlt = anEvent.isMeta = PR_FALSE;
}
else {
anEvent.charCode = 0;
anEvent.keyCode = (keysym & 0x00FF);
}
}
}
PRBool nsWidget::DispatchKeyEvent( PhKeyEvent_t *aPhKeyEvent ) {

View File

@ -697,7 +697,6 @@ bool nsQEventHandler::KeyPressEvent(QKeyEvent *event,
}
if (nsEvent.charCode) {
nsEvent.keyCode = 0;
nsEvent.isShift = PR_FALSE;
}
else
nsEvent.keyCode = GetNSKey(event->key(),event->state());

View File

@ -922,7 +922,6 @@ PRBool nsQBaseWidget::KeyPressEvent(QKeyEvent *aEvent)
}
if (nsEvent.charCode) {
nsEvent.keyCode = 0;
nsEvent.isShift = PR_FALSE;
}
else
nsEvent.keyCode = NS_GetKey(aEvent->key());

View File

@ -3135,7 +3135,6 @@ BOOL nsWindow::OnChar( UINT mbcsCharCode, UINT virtualKeyCode, bool isMultiByte
}
#endif /* MOZ_UNICODE */
virtualKeyCode = 0;
mIsShiftDown = PR_FALSE;
}
}
return DispatchKeyEvent(NS_KEY_PRESS, uniChar, virtualKeyCode, 0);

View File

@ -953,20 +953,6 @@ nsAppShell::HandleKeyPressEvent(XEvent *event, nsWidget *aWidget)
keyEvent.widget = focusWidget;
keyEvent.eventStructType = NS_KEY_EVENT;
if (keyEvent.charCode)
{
/* This is the comment from the GTK code. Hope it makes more sense to you
* than it did for me.
*
* if the control, meta, or alt key is down, then we should leave
* the isShift flag alone (probably not a printable character)
* if none of the other modifier keys are pressed then we need to
* clear isShift so the character can be inserted in the editor
*/
if (!keyEvent.isControl && !keyEvent.isAlt && !keyEvent.isMeta)
keyEvent.isShift = PR_FALSE;
}
focusWidget->DispatchKeyEvent(keyEvent);
}