Fix for #6896: Windows editor interprests the '.' key as a forward delete. Not building by default -- will switch over once tested on Mac and Unix.

This commit is contained in:
tague%netscape.com 1999-06-04 05:14:01 +00:00
Родитель 375f039a3d
Коммит 9fbcbaf99a
4 изменённых файлов: 301 добавлений и 16 удалений

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

@ -104,7 +104,75 @@ nsTextEditorKeyListener::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
#ifdef DEBUG_TAGUE
nsresult
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
PRUint32 keyCode;
PRBool isShift;
PRBool ctrlKey;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
if (!uiEvent) {
//non-key event passed to keydown. bad things.
return NS_OK;
}
if (NS_SUCCEEDED(uiEvent->GetKeyCode(&keyCode)) &&
NS_SUCCEEDED(uiEvent->GetShiftKey(&isShift)) &&
NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey))
) {
PRBool keyProcessed;
ProcessShortCutKeys(aKeyEvent, keyProcessed);
if (PR_FALSE==keyProcessed)
{
switch(keyCode) {
case nsIDOMUIEvent::VK_BACK:
mEditor->DeleteSelection(nsIEditor::eDeleteLeft);
break;
case nsIDOMUIEvent::VK_DELETE:
mEditor->DeleteSelection(nsIEditor::eDeleteRight);
break;
case nsIDOMUIEvent::VK_RETURN:
//case nsIDOMUIEvent::VK_ENTER: // why does this not exist?
// Need to implement creation of either <P> or <BR> nodes.
mEditor->InsertBreak();
break;
case nsIDOMUIEvent::VK_LEFT:
case nsIDOMUIEvent::VK_RIGHT:
case nsIDOMUIEvent::VK_UP:
case nsIDOMUIEvent::VK_DOWN:
// these have already been handled in nsRangeList. Why are we getting them
// again here (Mac)? In switch to avoid putting in bogus chars.
//return NS_OK to allow page scrolling.
return NS_OK;
break;
case nsIDOMUIEvent::VK_HOME:
case nsIDOMUIEvent::VK_END:
// who handles these?
#if DEBUG
printf("Key not handled\n");
#endif
break;
case nsIDOMUIEvent::VK_PAGE_UP:
case nsIDOMUIEvent::VK_PAGE_DOWN:
//return NS_OK to allow page scrolling.
return NS_OK;
break;
}
}
}
return NS_ERROR_BASE;
}
#else
nsresult
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
@ -186,7 +254,7 @@ nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
return NS_ERROR_BASE;
}
#endif
nsresult
@ -196,12 +264,43 @@ nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
}
#ifdef DEBUG_TAGUE
nsresult
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
nsAutoString key;
PRUint32 character;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
if (!uiEvent) {
//non-key event passed to keydown. bad things.
return NS_OK;
}
if (NS_SUCCEEDED(uiEvent->GetCharCode(&character)))
{
//
// this is a temporary hack to get around the re-firing of key_downs as key_presses
// in nsEventStateManager
//
if (character<0x20) { return NS_OK; }
key += character;
if (0!=character)
return mEditor->InsertText(key);
}
return NS_ERROR_BASE;
}
#else
nsresult
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
return NS_OK;
}
#endif
/* these includes are for debug only. this module should never instantiate it's own transactions */
#include "SplitElementTxn.h"

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

@ -104,7 +104,75 @@ nsTextEditorKeyListener::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
#ifdef DEBUG_TAGUE
nsresult
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
PRUint32 keyCode;
PRBool isShift;
PRBool ctrlKey;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
if (!uiEvent) {
//non-key event passed to keydown. bad things.
return NS_OK;
}
if (NS_SUCCEEDED(uiEvent->GetKeyCode(&keyCode)) &&
NS_SUCCEEDED(uiEvent->GetShiftKey(&isShift)) &&
NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey))
) {
PRBool keyProcessed;
ProcessShortCutKeys(aKeyEvent, keyProcessed);
if (PR_FALSE==keyProcessed)
{
switch(keyCode) {
case nsIDOMUIEvent::VK_BACK:
mEditor->DeleteSelection(nsIEditor::eDeleteLeft);
break;
case nsIDOMUIEvent::VK_DELETE:
mEditor->DeleteSelection(nsIEditor::eDeleteRight);
break;
case nsIDOMUIEvent::VK_RETURN:
//case nsIDOMUIEvent::VK_ENTER: // why does this not exist?
// Need to implement creation of either <P> or <BR> nodes.
mEditor->InsertBreak();
break;
case nsIDOMUIEvent::VK_LEFT:
case nsIDOMUIEvent::VK_RIGHT:
case nsIDOMUIEvent::VK_UP:
case nsIDOMUIEvent::VK_DOWN:
// these have already been handled in nsRangeList. Why are we getting them
// again here (Mac)? In switch to avoid putting in bogus chars.
//return NS_OK to allow page scrolling.
return NS_OK;
break;
case nsIDOMUIEvent::VK_HOME:
case nsIDOMUIEvent::VK_END:
// who handles these?
#if DEBUG
printf("Key not handled\n");
#endif
break;
case nsIDOMUIEvent::VK_PAGE_UP:
case nsIDOMUIEvent::VK_PAGE_DOWN:
//return NS_OK to allow page scrolling.
return NS_OK;
break;
}
}
}
return NS_ERROR_BASE;
}
#else
nsresult
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
@ -186,7 +254,7 @@ nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
return NS_ERROR_BASE;
}
#endif
nsresult
@ -196,12 +264,43 @@ nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
}
#ifdef DEBUG_TAGUE
nsresult
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
nsAutoString key;
PRUint32 character;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
if (!uiEvent) {
//non-key event passed to keydown. bad things.
return NS_OK;
}
if (NS_SUCCEEDED(uiEvent->GetCharCode(&character)))
{
//
// this is a temporary hack to get around the re-firing of key_downs as key_presses
// in nsEventStateManager
//
if (character<0x20) { return NS_OK; }
key += character;
if (0!=character)
return mEditor->InsertText(key);
}
return NS_ERROR_BASE;
}
#else
nsresult
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
return NS_OK;
}
#endif
/* these includes are for debug only. this module should never instantiate it's own transactions */
#include "SplitElementTxn.h"

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

@ -112,12 +112,16 @@ nsWindow::nsWindow() : nsBaseWidget()
mHitSubMenus = new nsVoidArray();
mVScrollbar = nsnull;
mIMEProperty = 0;
mIMEIsComposing = PR_FALSE;
mIMECompositionString = NULL;
mIMECompositionStringSize = 0;
mIMECompositionStringSize = 0;
mIMECompositionUniString = NULL;
mIMEProperty = 0;
mIMEIsComposing = PR_FALSE;
mIMECompositionString = NULL;
mIMECompositionStringSize = 0;
mIMECompositionStringSize = 0;
mIMECompositionUniString = NULL;
#ifdef DEBUG_TAGUE
mHaveDBCSLeadByte = false;
mDBCSLeadByte = '\0';
#endif
#ifdef NEW_DRAG_AND_DROP
mNativeDragTarget = nsnull;
@ -1918,8 +1922,12 @@ ULONG nsWindow::IsSpecialChar(UINT aVirtualKeyCode, WORD *aAsciiKey)
case VK_F9:
case VK_F10:
case VK_F11:
case VK_F12:
*aAsciiKey = aVirtualKeyCode;
case VK_F12:
#ifdef DEBUG_TAGUE
case VK_RETURN:
case VK_BACK:
#endif
*aAsciiKey = aVirtualKeyCode;
break;
case VK_DELETE:
@ -1927,10 +1935,6 @@ ULONG nsWindow::IsSpecialChar(UINT aVirtualKeyCode, WORD *aAsciiKey)
keyType = SPECIAL_KEY;
break;
//case VK_RETURN:*aAsciiKey = '\n';
//keyType = SPECIAL_KEY;
//break;
case VK_MENU:
keyType = DONT_PROCESS_KEY;
break;
@ -2084,6 +2088,36 @@ BOOL nsWindow::OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode)
//
//
//-------------------------------------------------------------------------
#ifdef DEBUG_TAGUE
BOOL nsWindow::OnChar( UINT aVirtualKeyCode, bool isMultiByte )
{
wchar_t uniChar;
char charToConvert[2];
size_t length;
if (isMultiByte) {
charToConvert[0]=HIBYTE(aVirtualKeyCode);
charToConvert[1] = LOBYTE(aVirtualKeyCode);
length=2;
} else {
charToConvert[0] = LOBYTE(aVirtualKeyCode);
length=1;
}
// if we get a '\n', ignore it because we already processed it in OnKeyDown.
// This is the safest assumption since not always pressing enter produce a WM_CHAR
//if (IsDBCSLeadByte(aVirtualKeyCode) || aVirtualKeyCode == 0xD /*'\n'*/ ) {
// return FALSE;
//}
//printf("OnChar (KeyDown) %d\n", aVirtualKeyCode);
::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,charToConvert,length,
&uniChar,sizeof(uniChar));
DispatchKeyEvent(NS_KEY_PRESS, uniChar, uniChar);
return FALSE;
}
#else
BOOL nsWindow::OnChar( UINT aVirtualKeyCode )
{
@ -2098,6 +2132,7 @@ BOOL nsWindow::OnChar( UINT aVirtualKeyCode )
return FALSE;
}
#endif
@ -2211,7 +2246,50 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
case WM_PAINT:
result = OnPaint();
break;
#ifdef DEBUG_TAGUE
case WM_SYSCHAR:
case WM_CHAR:
{
unsigned char ch = (unsigned char)wParam;
UINT char_result;
//
// check first for backspace or return, these are currently being handled on
// the WM_KEYDOWN
//
if (ch==0x0d || ch==0x08) {
result = PR_TRUE;
break;
}
//
// check first to see if we have the first byte of a two-byte DBCS sequence
// if so, store it away and do nothing until we get the second sequence
//
if (IsDBCSLeadByte(ch) && !mHaveDBCSLeadByte) {
mHaveDBCSLeadByte = TRUE;
mDBCSLeadByte = ch;
result = PR_TRUE;
break;
}
//
// at this point, we may have the second byte of a DBCS sequence or a single byte
// character, depending on the previous message. Check and handle accordingly
//
if (mHaveDBCSLeadByte) {
char_result = (mDBCSLeadByte << 8) | ch;
mHaveDBCSLeadByte = FALSE;
mDBCSLeadByte = 0;
result = OnChar(char_result,true);
} else {
char_result = ch;
result = OnChar(char_result,false);
}
break;
}
#else
case WM_SYSCHAR:
case WM_CHAR:
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
@ -2234,7 +2312,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
result = PR_FALSE;
break;
#endif
// Let ths fall through if it isn't a key pad
case WM_SYSKEYUP:
// if it's a keypad key don't process a WM_CHAR will come or...oh well...

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

@ -169,7 +169,12 @@ protected:
virtual PRBool OnPaint();
virtual PRBool OnResize(nsRect &aWindowRect);
BOOL OnChar(UINT aVirtualKeyCode);
#ifdef DEBUG_TAGUE
BOOL OnChar(UINT aVirtualKeyCode, bool isMultibyte);
#else
BOOL OnChar(UINT aVirtualKeyCode);
#endif
BOOL OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode);
BOOL OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode);
ULONG IsSpecialChar(UINT aVirtualKeyCode, WORD *aAsciiKey);
@ -230,6 +235,10 @@ protected:
PRUnichar* mIMECompositionUniString;
PRInt32 mIMECompositionStringLength;
PRInt32 mIMECompositionStringSize;
#ifdef DEBUG_TAGUE
BOOL mHaveDBCSLeadByte;
unsigned char mDBCSLeadByte;
#endif
// Drag & Drop