mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 13:07:52 +00:00
Bug 167145. When PreventDefault() called for onkeydown event, do the same for onkeypress that follows. r=bryner, sr=neil
This commit is contained in:
parent
c4f9945247
commit
84910111ef
@ -145,16 +145,8 @@ nsMenuListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||||||
|
|
||||||
// Since a menu was open, eat the event to keep other event
|
// Since a menu was open, eat the event to keep other event
|
||||||
// listeners from becoming confused.
|
// listeners from becoming confused.
|
||||||
|
aKeyEvent->StopPropagation();
|
||||||
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aKeyEvent));
|
|
||||||
|
|
||||||
if (nsevent) {
|
|
||||||
nsevent->PreventBubble();
|
|
||||||
nsevent->PreventCapture();
|
|
||||||
}
|
|
||||||
|
|
||||||
aKeyEvent->PreventDefault();
|
aKeyEvent->PreventDefault();
|
||||||
|
|
||||||
return NS_ERROR_BASE; // I am consuming event
|
return NS_ERROR_BASE; // I am consuming event
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,14 +154,9 @@ nsMenuListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||||||
nsresult
|
nsresult
|
||||||
nsMenuListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
nsMenuListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
||||||
{
|
{
|
||||||
// if event has already been handled, bail
|
// Don't check prevent default flag -- menus always get first shot at key events.
|
||||||
nsCOMPtr<nsIDOMNSUIEvent> uiEvent ( do_QueryInterface(aKeyEvent) );
|
// When a menu is open, the prevent default flag on a keypress is always set, so
|
||||||
if ( uiEvent ) {
|
// that no one else uses the key event.
|
||||||
PRBool eventHandled = PR_FALSE;
|
|
||||||
uiEvent->GetPreventDefault ( &eventHandled );
|
|
||||||
if ( eventHandled )
|
|
||||||
return NS_OK; // don't consume event
|
|
||||||
}
|
|
||||||
|
|
||||||
//handlers shouldn't be triggered by non-trusted events.
|
//handlers shouldn't be triggered by non-trusted events.
|
||||||
nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
|
nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
|
||||||
@ -229,15 +216,8 @@ nsMenuListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aKeyEvent));
|
aKeyEvent->StopPropagation();
|
||||||
|
|
||||||
if (nsevent) {
|
|
||||||
nsevent->PreventBubble();
|
|
||||||
nsevent->PreventCapture();
|
|
||||||
}
|
|
||||||
|
|
||||||
aKeyEvent->PreventDefault();
|
aKeyEvent->PreventDefault();
|
||||||
|
|
||||||
return NS_ERROR_BASE; // I am consuming event
|
return NS_ERROR_BASE; // I am consuming event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ public:
|
|||||||
|
|
||||||
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
||||||
|
|
||||||
NS_IMETHOD KeyUp(nsIDOMEvent* aMouseEvent);
|
NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent);
|
||||||
NS_IMETHOD KeyDown(nsIDOMEvent* aMouseEvent);
|
NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent);
|
||||||
NS_IMETHOD KeyPress(nsIDOMEvent* aMouseEvent);
|
NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent);
|
||||||
|
|
||||||
NS_IMETHOD Focus(nsIDOMEvent* aEvent);
|
NS_IMETHOD Focus(nsIDOMEvent* aEvent);
|
||||||
NS_IMETHOD Blur(nsIDOMEvent* aEvent);
|
NS_IMETHOD Blur(nsIDOMEvent* aEvent);
|
||||||
|
@ -2155,7 +2155,7 @@ PRBool nsWindow::OnKeyDown(PRUint32 aEventType, const char *bytes,
|
|||||||
int32 numBytes, PRUint32 mod, PRUint32 bekeycode, int32 rawcode)
|
int32 numBytes, PRUint32 mod, PRUint32 bekeycode, int32 rawcode)
|
||||||
{
|
{
|
||||||
PRUint32 aTranslatedKeyCode;
|
PRUint32 aTranslatedKeyCode;
|
||||||
PRBool result = PR_FALSE;
|
PRBool noDefault = PR_FALSE;
|
||||||
|
|
||||||
mIsShiftDown = (mod & B_SHIFT_KEY) ? PR_TRUE : PR_FALSE;
|
mIsShiftDown = (mod & B_SHIFT_KEY) ? PR_TRUE : PR_FALSE;
|
||||||
mIsControlDown = (mod & B_CONTROL_KEY) ? PR_TRUE : PR_FALSE;
|
mIsControlDown = (mod & B_CONTROL_KEY) ? PR_TRUE : PR_FALSE;
|
||||||
@ -2171,7 +2171,7 @@ PRBool nsWindow::OnKeyDown(PRUint32 aEventType, const char *bytes,
|
|||||||
|
|
||||||
if (numBytes <= 1)
|
if (numBytes <= 1)
|
||||||
{
|
{
|
||||||
result = DispatchKeyEvent(NS_KEY_DOWN, 0, aTranslatedKeyCode);
|
noDefault = DispatchKeyEvent(NS_KEY_DOWN, 0, aTranslatedKeyCode);
|
||||||
} else {
|
} else {
|
||||||
// non ASCII chars
|
// non ASCII chars
|
||||||
}
|
}
|
||||||
@ -2187,13 +2187,13 @@ PRBool nsWindow::OnKeyDown(PRUint32 aEventType, const char *bytes,
|
|||||||
aTranslatedKeyCode = 0;
|
aTranslatedKeyCode = 0;
|
||||||
} else {
|
} else {
|
||||||
if (numBytes == 0) // deal with unmapped key
|
if (numBytes == 0) // deal with unmapped key
|
||||||
return result;
|
return noDefault;
|
||||||
|
|
||||||
switch((unsigned char)bytes[0])
|
switch((unsigned char)bytes[0])
|
||||||
{
|
{
|
||||||
case 0xc8://System Request
|
case 0xc8://System Request
|
||||||
case 0xca://Break
|
case 0xca://Break
|
||||||
return result;// do not send 'KEY_PRESS' message
|
return noDefault;// do not send 'KEY_PRESS' message
|
||||||
|
|
||||||
case B_INSERT:
|
case B_INSERT:
|
||||||
case B_ESCAPE:
|
case B_ESCAPE:
|
||||||
@ -2238,9 +2238,9 @@ PRBool nsWindow::OnKeyDown(PRUint32 aEventType, const char *bytes,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool result2 = DispatchKeyEvent(NS_KEY_PRESS, uniChar, aTranslatedKeyCode);
|
// If prevent default set for onkeydown, do the same for onkeypress
|
||||||
|
PRUint32 extraFlags = (noDefault ? NS_EVENT_FLAG_NO_DEFAULT : 0);
|
||||||
return result && result2;
|
return DispatchKeyEvent(NS_KEY_PRESS, uniChar, aTranslatedKeyCode, extraFlags) && noDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -2273,7 +2273,7 @@ PRBool nsWindow::OnKeyUp(PRUint32 aEventType, const char *bytes,
|
|||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode,
|
PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode,
|
||||||
PRUint32 aKeyCode)
|
PRUint32 aKeyCode, PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
nsKeyEvent event(aEventType, this);
|
nsKeyEvent event(aEventType, this);
|
||||||
nsPoint point;
|
nsPoint point;
|
||||||
@ -2283,6 +2283,7 @@ PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode,
|
|||||||
|
|
||||||
InitEvent(event, &point); // this add ref's event.widget
|
InitEvent(event, &point); // this add ref's event.widget
|
||||||
|
|
||||||
|
event.flags |= aFlags;
|
||||||
event.charCode = aCharCode;
|
event.charCode = aCharCode;
|
||||||
event.keyCode = aKeyCode;
|
event.keyCode = aKeyCode;
|
||||||
|
|
||||||
|
@ -206,7 +206,8 @@ protected:
|
|||||||
PRUint32 mod,
|
PRUint32 mod,
|
||||||
PRUint32 bekeycode,
|
PRUint32 bekeycode,
|
||||||
int32 rawcode);
|
int32 rawcode);
|
||||||
virtual PRBool DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode, PRUint32 aKeyCode);
|
virtual PRBool DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode,
|
||||||
|
PRUint32 aKeyCode, PRUint32 aFlags = 0);
|
||||||
virtual PRBool DispatchFocus(PRUint32 aEventType);
|
virtual PRBool DispatchFocus(PRUint32 aEventType);
|
||||||
virtual PRBool OnScroll();
|
virtual PRBool OnScroll();
|
||||||
static PRBool ConvertStatus(nsEventStatus aStatus);
|
static PRBool ConvertStatus(nsEventStatus aStatus);
|
||||||
|
@ -477,7 +477,7 @@ gint handle_key_press_event_for_text(GtkObject *w, GdkEventKey* event,
|
|||||||
NS_ADDREF(win);
|
NS_ADDREF(win);
|
||||||
nsKeyEvent keyDownEvent(NS_KEY_DOWN, win);
|
nsKeyEvent keyDownEvent(NS_KEY_DOWN, win);
|
||||||
InitKeyEvent(event, keyDownEvent);
|
InitKeyEvent(event, keyDownEvent);
|
||||||
win->OnKey(keyDownEvent);
|
PRBool noDefault = win->OnKey(keyDownEvent);
|
||||||
|
|
||||||
// Don't pass Shift, Control, Alt and Meta as NS_KEY_PRESS events.
|
// Don't pass Shift, Control, Alt and Meta as NS_KEY_PRESS events.
|
||||||
if (event->keyval == GDK_Shift_L
|
if (event->keyval == GDK_Shift_L
|
||||||
@ -498,6 +498,10 @@ gint handle_key_press_event_for_text(GtkObject *w, GdkEventKey* event,
|
|||||||
//
|
//
|
||||||
nsKeyEvent keyPressEvent(NS_KEY_PRESS, win);
|
nsKeyEvent keyPressEvent(NS_KEY_PRESS, win);
|
||||||
InitKeyPressEvent(event, keyPressEvent);
|
InitKeyPressEvent(event, keyPressEvent);
|
||||||
|
if (noDefault) { // If prevent default set for onkeydown, do the same for onkeypress
|
||||||
|
event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
win->OnKey(keyPressEvent);
|
win->OnKey(keyPressEvent);
|
||||||
|
|
||||||
NS_RELEASE(win);
|
NS_RELEASE(win);
|
||||||
@ -552,13 +556,14 @@ gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p)
|
|||||||
// but lie about where it came from and say it is from the
|
// but lie about where it came from and say it is from the
|
||||||
// window that currently has focus inside our app...
|
// window that currently has focus inside our app...
|
||||||
//
|
//
|
||||||
|
PRBool noDefault = PR_FALSE;
|
||||||
nsKeyEvent keyDownEvent(NS_KEY_DOWN, win);
|
nsKeyEvent keyDownEvent(NS_KEY_DOWN, win);
|
||||||
InitKeyEvent(event, keyDownEvent);
|
InitKeyEvent(event, keyDownEvent);
|
||||||
// if we need to suppress this NS_KEY_DOWN event, reset the flag
|
// if we need to suppress this NS_KEY_DOWN event, reset the flag
|
||||||
if (suppressNextKeyDown == PR_TRUE)
|
if (suppressNextKeyDown == PR_TRUE)
|
||||||
suppressNextKeyDown = PR_FALSE;
|
suppressNextKeyDown = PR_FALSE;
|
||||||
else
|
else
|
||||||
win->OnKey(keyDownEvent);
|
noDefault = win->OnKey(keyDownEvent);
|
||||||
|
|
||||||
// Don't pass Shift, Alt, Control and Meta as NS_KEY_PRESS events.
|
// Don't pass Shift, Alt, Control and Meta as NS_KEY_PRESS events.
|
||||||
if (event->keyval == GDK_Shift_L
|
if (event->keyval == GDK_Shift_L
|
||||||
@ -580,6 +585,9 @@ gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p)
|
|||||||
// Call nsConvertCharCodeToUnicode() here to get kevent.charCode
|
// Call nsConvertCharCodeToUnicode() here to get kevent.charCode
|
||||||
nsKeyEvent keyPressEvent(NS_KEY_PRESS, win);
|
nsKeyEvent keyPressEvent(NS_KEY_PRESS, win);
|
||||||
InitKeyPressEvent(event, keyPressEvent);
|
InitKeyPressEvent(event, keyPressEvent);
|
||||||
|
if (noDefault) { // If prevent default set for onkeydown, do the same for onkeypress
|
||||||
|
event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
if (event->length) {
|
if (event->length) {
|
||||||
if (keyPressEvent.charCode || keyPressEvent.keyCode) {
|
if (keyPressEvent.charCode || keyPressEvent.keyCode) {
|
||||||
|
@ -1571,6 +1571,10 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent)
|
|||||||
}
|
}
|
||||||
nsKeyEvent event(NS_KEY_PRESS, this);
|
nsKeyEvent event(NS_KEY_PRESS, this);
|
||||||
InitKeyEvent(event, aEvent);
|
InitKeyEvent(event, aEvent);
|
||||||
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
||||||
|
// If prevent default set for onkeydown, do the same for onkeypress
|
||||||
|
event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
event.charCode = nsConvertCharCodeToUnicode(aEvent);
|
event.charCode = nsConvertCharCodeToUnicode(aEvent);
|
||||||
if (event.charCode) {
|
if (event.charCode) {
|
||||||
event.keyCode = 0;
|
event.keyCode = 0;
|
||||||
|
@ -1167,6 +1167,10 @@ PRBool nsMacEventHandler::HandleKeyEvent(EventRecord& aOSEvent)
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
InitializeKeyEvent(keyPressEvent, aOSEvent, focusedWidget, NS_KEY_PRESS);
|
InitializeKeyEvent(keyPressEvent, aOSEvent, focusedWidget, NS_KEY_PRESS);
|
||||||
|
if (result) {
|
||||||
|
// If keydown default was prevented, do same for keypress
|
||||||
|
keyPressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
// before we dispatch this key, check if it's the contextmenu key.
|
// before we dispatch this key, check if it's the contextmenu key.
|
||||||
// If so, send a context menu event instead.
|
// If so, send a context menu event instead.
|
||||||
|
@ -2274,6 +2274,9 @@ PRBool nsWindow::OnKey( MPARAM mp1, MPARAM mp2)
|
|||||||
// Now we need to dispatch a keypress event which has the unicode char.
|
// Now we need to dispatch a keypress event which has the unicode char.
|
||||||
|
|
||||||
pressEvent.message = NS_KEY_PRESS;
|
pressEvent.message = NS_KEY_PRESS;
|
||||||
|
if (rc) { // If keydown default was prevented, do same for keypress
|
||||||
|
pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
if( usChar)
|
if( usChar)
|
||||||
{
|
{
|
||||||
|
@ -884,10 +884,13 @@ PRBool nsWidget::DispatchKeyEvent( PhKeyEvent_t *aPhKeyEvent ) {
|
|||||||
if (aPhKeyEvent->key_flags & Pk_KF_Key_Down) {
|
if (aPhKeyEvent->key_flags & Pk_KF_Key_Down) {
|
||||||
nsKeyEvent keyDownEvent(NS_KEY_DOWN, w);
|
nsKeyEvent keyDownEvent(NS_KEY_DOWN, w);
|
||||||
InitKeyEvent(aPhKeyEvent, keyDownEvent);
|
InitKeyEvent(aPhKeyEvent, keyDownEvent);
|
||||||
w->OnKey(keyDownEvent);
|
PRBool noDefault = w->OnKey(keyDownEvent);
|
||||||
|
|
||||||
nsKeyEvent keyPressEvent(NS_KEY_PRESS, w);
|
nsKeyEvent keyPressEvent(NS_KEY_PRESS, w);
|
||||||
InitKeyPressEvent(aPhKeyEvent, keyPressEvent);
|
InitKeyPressEvent(aPhKeyEvent, keyPressEvent);
|
||||||
|
if (noDefault) { // If prevent default set for keydown, do same for keypress
|
||||||
|
keyPressEvent.flags = NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
w->OnKey(keyPressEvent);
|
w->OnKey(keyPressEvent);
|
||||||
}
|
}
|
||||||
else if (aPhKeyEvent->key_flags & Pk_KF_Key_Repeat) {
|
else if (aPhKeyEvent->key_flags & Pk_KF_Key_Repeat) {
|
||||||
|
@ -991,28 +991,31 @@ nsCommonWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
// release. gtk2 already filters the extra key release events for
|
// release. gtk2 already filters the extra key release events for
|
||||||
// us.
|
// us.
|
||||||
|
|
||||||
|
nsKeyEvent pressEvent(NS_KEY_PRESS, this);
|
||||||
|
InitKeyEvent(&pressEvent, e);
|
||||||
|
pressEvent.charCode = (PRInt32)e->text()[0].unicode();
|
||||||
|
|
||||||
if (!e->isAutoRepeat()) {
|
if (!e->isAutoRepeat()) {
|
||||||
|
|
||||||
// send the key down event
|
// send the key down event
|
||||||
nsKeyEvent downEvent(NS_KEY_DOWN, this);
|
nsKeyEvent downEvent(NS_KEY_DOWN, this);
|
||||||
InitKeyEvent(&downEvent, e);
|
InitKeyEvent(&downEvent, e);
|
||||||
DispatchEvent(&downEvent, status);
|
DispatchEvent(&downEvent, status);
|
||||||
|
if (ignoreEvent(status)) { // If prevent default on keydown, do same for keypress
|
||||||
|
pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsKeyEvent event(NS_KEY_PRESS, this);
|
|
||||||
InitKeyEvent(&event, e);
|
|
||||||
event.charCode = (PRInt32)e->text()[0].unicode();
|
|
||||||
|
|
||||||
// before we dispatch a key, check if it's the context menu key.
|
// before we dispatch a key, check if it's the context menu key.
|
||||||
// If so, send a context menu key event instead.
|
// If so, send a context menu key event instead.
|
||||||
if (isContextMenuKey(event)) {
|
if (isContextMenuKey(pressEvent)) {
|
||||||
nsMouseEvent contextMenuEvent;
|
nsMouseEvent contextMenuEvent;
|
||||||
keyEventToContextMenuEvent(&event, &contextMenuEvent);
|
keyEventToContextMenuEvent(&pressEvent, &contextMenuEvent);
|
||||||
DispatchEvent(&contextMenuEvent, status);
|
DispatchEvent(&contextMenuEvent, status);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// send the key press event
|
// send the key press event
|
||||||
DispatchEvent(&event, status);
|
DispatchEvent(&pressEvent, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ignoreEvent(status);
|
return ignoreEvent(status);
|
||||||
|
@ -2987,13 +2987,15 @@ UINT nsWindow::MapFromNativeToDOM(UINT aNativeKeyCode)
|
|||||||
// OnKey
|
// OnKey
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode, LPARAM aKeyData)
|
PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode,
|
||||||
|
LPARAM aKeyData, PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
nsKeyEvent event(aEventType, this);
|
nsKeyEvent event(aEventType, this);
|
||||||
nsPoint point(0, 0);
|
nsPoint point(0, 0);
|
||||||
|
|
||||||
InitEvent(event, &point); // this add ref's event.widget
|
InitEvent(event, &point); // this add ref's event.widget
|
||||||
|
|
||||||
|
event.flags |= aFlags;
|
||||||
event.charCode = aCharCode;
|
event.charCode = aCharCode;
|
||||||
event.keyCode = aVirtualCharCode;
|
event.keyCode = aVirtualCharCode;
|
||||||
|
|
||||||
@ -3060,7 +3062,7 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
|
|||||||
//printf("In OnKeyDown virt: %d scan: %d\n", virtualKeyCode, aScanCode);
|
//printf("In OnKeyDown virt: %d scan: %d\n", virtualKeyCode, aScanCode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BOOL result = DispatchKeyEvent(NS_KEY_DOWN, 0, virtualKeyCode, aKeyData);
|
BOOL noDefault = DispatchKeyEvent(NS_KEY_DOWN, 0, virtualKeyCode, aKeyData);
|
||||||
|
|
||||||
// If we won't be getting a WM_CHAR, WM_SYSCHAR or WM_DEADCHAR, synthesize a keypress
|
// If we won't be getting a WM_CHAR, WM_SYSCHAR or WM_DEADCHAR, synthesize a keypress
|
||||||
// for almost all keys
|
// for almost all keys
|
||||||
@ -3070,9 +3072,11 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
|
|||||||
case NS_VK_ALT:
|
case NS_VK_ALT:
|
||||||
case NS_VK_CAPS_LOCK:
|
case NS_VK_CAPS_LOCK:
|
||||||
case NS_VK_NUM_LOCK:
|
case NS_VK_NUM_LOCK:
|
||||||
case NS_VK_SCROLL_LOCK: return result;
|
case NS_VK_SCROLL_LOCK: return noDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRUint32 extraFlags = (noDefault ? NS_EVENT_FLAG_NO_DEFAULT : 0);
|
||||||
|
|
||||||
MSG msg;
|
MSG msg;
|
||||||
BOOL gotMsg = ::PeekMessage(&msg, mWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD);
|
BOOL gotMsg = ::PeekMessage(&msg, mWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD);
|
||||||
// Enter and backspace are always handled here to avoid for example the
|
// Enter and backspace are always handled here to avoid for example the
|
||||||
@ -3123,7 +3127,9 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
|
|||||||
}
|
}
|
||||||
else if (gotMsg &&
|
else if (gotMsg &&
|
||||||
(msg.message == WM_CHAR || msg.message == WM_SYSCHAR || msg.message == WM_DEADCHAR)) {
|
(msg.message == WM_CHAR || msg.message == WM_SYSCHAR || msg.message == WM_DEADCHAR)) {
|
||||||
return result;
|
// If prevent default set for keydown, do same for keypress
|
||||||
|
::GetMessage(&msg, mWnd, msg.message, msg.message);
|
||||||
|
return (msg.message == WM_DEADCHAR) ? PR_FALSE : OnChar(msg.wParam, extraFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
WORD asciiKey = 0;
|
WORD asciiKey = 0;
|
||||||
@ -3161,12 +3167,13 @@ BOOL nsWindow::OnKeyDown(UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
|
|||||||
asciiKey += 0x20;
|
asciiKey += 0x20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (asciiKey)
|
|
||||||
DispatchKeyEvent(NS_KEY_PRESS, asciiKey, 0, aKeyData);
|
|
||||||
else
|
|
||||||
DispatchKeyEvent(NS_KEY_PRESS, 0, virtualKeyCode, aKeyData);
|
|
||||||
|
|
||||||
return result;
|
if (asciiKey)
|
||||||
|
DispatchKeyEvent(NS_KEY_PRESS, asciiKey, 0, aKeyData, extraFlags);
|
||||||
|
else
|
||||||
|
DispatchKeyEvent(NS_KEY_PRESS, 0, virtualKeyCode, aKeyData, extraFlags);
|
||||||
|
|
||||||
|
return noDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -3185,8 +3192,28 @@ BOOL nsWindow::OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyData)
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
BOOL nsWindow::OnChar(UINT charCode)
|
BOOL nsWindow::OnChar(UINT charCode, PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
|
#ifdef KE_DEBUG
|
||||||
|
printf("%s\tchar=%c\twp=%4x\tlp=%8x\n", (msg == WM_SYSCHAR) ? "WM_SYSCHAR" : "WM_CHAR" , wParam, wParam, lParam);
|
||||||
|
#endif
|
||||||
|
// These must be checked here too as a lone WM_CHAR could be received
|
||||||
|
// if a child window didn't handle it (for example Alt+Space in a content window)
|
||||||
|
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
|
||||||
|
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
|
||||||
|
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
|
||||||
|
|
||||||
|
// ignore [shift+]alt+space so the OS can handle it
|
||||||
|
if (mIsAltDown && !mIsControlDown && IS_VK_DOWN(NS_VK_SPACE)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WM_CHAR with Control and Alt (== AltGr) down really means a normal character
|
||||||
|
PRBool saveIsAltDown = mIsAltDown;
|
||||||
|
PRBool saveIsControlDown = mIsControlDown;
|
||||||
|
if (mIsAltDown && mIsControlDown)
|
||||||
|
mIsAltDown = mIsControlDown = PR_FALSE;
|
||||||
|
|
||||||
wchar_t uniChar;
|
wchar_t uniChar;
|
||||||
|
|
||||||
if (sIMEIsComposing) {
|
if (sIMEIsComposing) {
|
||||||
@ -3228,6 +3255,8 @@ BOOL nsWindow::OnChar(UINT charCode)
|
|||||||
charToConvert[0] = LOBYTE(charCode);
|
charToConvert[0] = LOBYTE(charCode);
|
||||||
if (::IsDBCSLeadByteEx(gCurrentKeyboardCP, charToConvert[0])) {
|
if (::IsDBCSLeadByteEx(gCurrentKeyboardCP, charToConvert[0])) {
|
||||||
mLeadByte = charToConvert[0];
|
mLeadByte = charToConvert[0];
|
||||||
|
mIsAltDown = saveIsAltDown;
|
||||||
|
mIsControlDown = saveIsControlDown;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
length = 1;
|
length = 1;
|
||||||
@ -3246,7 +3275,11 @@ BOOL nsWindow::OnChar(UINT charCode)
|
|||||||
charCode = 0;
|
charCode = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DispatchKeyEvent(NS_KEY_PRESS, uniChar, charCode, 0);
|
|
||||||
|
PRBool result = DispatchKeyEvent(NS_KEY_PRESS, uniChar, charCode, 0, aFlags);
|
||||||
|
mIsAltDown = saveIsAltDown;
|
||||||
|
mIsControlDown = saveIsControlDown;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3909,31 +3942,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
|
|||||||
case WM_SYSCHAR:
|
case WM_SYSCHAR:
|
||||||
case WM_CHAR:
|
case WM_CHAR:
|
||||||
{
|
{
|
||||||
#ifdef KE_DEBUG
|
|
||||||
printf("%s\tchar=%c\twp=%4x\tlp=%8x\n", (msg == WM_SYSCHAR) ? "WM_SYSCHAR" : "WM_CHAR" , wParam, wParam, lParam);
|
|
||||||
#endif
|
|
||||||
// These must be checked here too as a lone WM_CHAR could be received
|
|
||||||
// if a child window didn't handle it (for example Alt+Space in a content window)
|
|
||||||
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
|
|
||||||
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
|
|
||||||
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
|
|
||||||
|
|
||||||
// ignore [shift+]alt+space so the OS can handle it
|
|
||||||
if (mIsAltDown && !mIsControlDown && IS_VK_DOWN(NS_VK_SPACE)) {
|
|
||||||
result = PR_FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// WM_CHAR with Control and Alt (== AltGr) down really means a normal character
|
|
||||||
PRBool saveIsAltDown = mIsAltDown;
|
|
||||||
PRBool saveIsControlDown = mIsControlDown;
|
|
||||||
if (mIsAltDown && mIsControlDown)
|
|
||||||
mIsAltDown = mIsControlDown = PR_FALSE;
|
|
||||||
|
|
||||||
result = OnChar(wParam);
|
result = OnChar(wParam);
|
||||||
|
|
||||||
mIsAltDown = saveIsAltDown;
|
|
||||||
mIsControlDown = saveIsControlDown;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ protected:
|
|||||||
virtual PRBool OnPaint(HDC aDC = nsnull);
|
virtual PRBool OnPaint(HDC aDC = nsnull);
|
||||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
|
||||||
BOOL OnChar(UINT charCode);
|
BOOL OnChar(UINT charCode, PRUint32 aFlags = 0);
|
||||||
|
|
||||||
BOOL OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyCode);
|
BOOL OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyCode);
|
||||||
BOOL OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyCode);
|
BOOL OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode, LPARAM aKeyCode);
|
||||||
@ -455,7 +455,8 @@ protected:
|
|||||||
|
|
||||||
void GetCompositionString(HIMC aHIMC, DWORD aIndex, nsString* aStrUnicode, nsCString* aStrAnsi);
|
void GetCompositionString(HIMC aHIMC, DWORD aIndex, nsString* aStrUnicode, nsCString* aStrAnsi);
|
||||||
|
|
||||||
virtual PRBool DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode, LPARAM aKeyCode);
|
virtual PRBool DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode,
|
||||||
|
LPARAM aKeyCode, PRUint32 aFlags = 0);
|
||||||
|
|
||||||
virtual PRBool DispatchFocus(PRUint32 aEventType, PRBool isMozWindowTakingFocus);
|
virtual PRBool DispatchFocus(PRUint32 aEventType, PRBool isMozWindowTakingFocus);
|
||||||
virtual PRBool OnScroll(UINT scrollCode, int cPos);
|
virtual PRBool OnScroll(UINT scrollCode, int cPos);
|
||||||
|
@ -895,7 +895,7 @@ nsAppShell::HandleKeyPressEvent(XEvent *event, nsWidget *aWidget)
|
|||||||
// event->xkey.keycode,
|
// event->xkey.keycode,
|
||||||
// keyEvent.keyCode);
|
// keyEvent.keyCode);
|
||||||
|
|
||||||
focusWidget->DispatchKeyEvent(keyEvent);
|
PRBool noDefault = focusWidget->DispatchKeyEvent(keyEvent);
|
||||||
|
|
||||||
nsKeyEvent pressEvent(NS_KEY_PRESS, focusWidget);
|
nsKeyEvent pressEvent(NS_KEY_PRESS, focusWidget);
|
||||||
pressEvent.keyCode = nsKeyCode::ConvertKeySymToVirtualKey(keysym);
|
pressEvent.keyCode = nsKeyCode::ConvertKeySymToVirtualKey(keysym);
|
||||||
@ -905,9 +905,11 @@ nsAppShell::HandleKeyPressEvent(XEvent *event, nsWidget *aWidget)
|
|||||||
pressEvent.isControl = (event->xkey.state & ControlMask) ? 1 : 0;
|
pressEvent.isControl = (event->xkey.state & ControlMask) ? 1 : 0;
|
||||||
pressEvent.isAlt = (event->xkey.state & Mod1Mask) ? 1 : 0;
|
pressEvent.isAlt = (event->xkey.state & Mod1Mask) ? 1 : 0;
|
||||||
pressEvent.isMeta = (event->xkey.state & Mod1Mask) ? 1 : 0;
|
pressEvent.isMeta = (event->xkey.state & Mod1Mask) ? 1 : 0;
|
||||||
|
if (noDefault) { // If default prevented on keydown, do same for keypress
|
||||||
|
pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
focusWidget->DispatchKeyEvent(pressEvent);
|
focusWidget->DispatchKeyEvent(pressEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user