20348: Make alt the modifier for Unix, and generally clean up code. r=brade

This commit is contained in:
akkana%netscape.com 1999-11-30 21:58:00 +00:00
Родитель 831cd57deb
Коммит 680a88820a
2 изменённых файлов: 100 добавлений и 126 удалений

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

@ -227,8 +227,6 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
{ {
aProcessed=PR_FALSE; aProcessed=PR_FALSE;
PRUint32 charCode; PRUint32 charCode;
PRBool ctrlKey;
PRBool isAltKey, isMetaKey, isShiftKey;
nsCOMPtr<nsIDOMKeyEvent>keyEvent; nsCOMPtr<nsIDOMKeyEvent>keyEvent;
keyEvent = do_QueryInterface(aKeyEvent); keyEvent = do_QueryInterface(aKeyEvent);
@ -237,87 +235,76 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
return NS_OK; return NS_OK;
} }
if (NS_SUCCEEDED(keyEvent->GetCharCode(&charCode)) && if (NS_SUCCEEDED(keyEvent->GetCharCode(&charCode)))
NS_SUCCEEDED(keyEvent->GetAltKey(&isAltKey)) && {
// Figure out the modifier key, different on every platform
PRBool isOnlyPlatformModifierKey = PR_FALSE;;
PRBool isCtrlKey, isAltKey, isMetaKey, isShiftKey;
if (NS_SUCCEEDED(keyEvent->GetAltKey(&isAltKey)) &&
NS_SUCCEEDED(keyEvent->GetMetaKey(&isMetaKey)) && NS_SUCCEEDED(keyEvent->GetMetaKey(&isMetaKey)) &&
NS_SUCCEEDED(keyEvent->GetShiftKey(&isShiftKey)) && NS_SUCCEEDED(keyEvent->GetShiftKey(&isShiftKey)) &&
NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) ) NS_SUCCEEDED(keyEvent->GetCtrlKey(&isCtrlKey)) )
{ {
#ifdef XP_MAC #if defined(XP_MAC)
// hack to make Mac work for hard-coded keybindings isOnlyPlatformModifierKey = (isMetaKey &&
// metaKey query is only way to query for command key on Mac !isShiftKey && !isCtrlKey && !isAltKey);
// if that's pressed, we'll set the ctrlKey boolean #elif defined(XP_UNIX)
// (even though the control key might also be pressed) isOnlyPlatformModifierKey = (isAltKey &&
if (PR_TRUE==isMetaKey) { !isShiftKey && !isCtrlKey && !isMetaKey);
ctrlKey = !ctrlKey; /* if controlKey is pressed, we shouldn't execute code below */ #else /* Windows and default */
/* if it's not set and cmdKey is, then we should proceed to code below */ isOnlyPlatformModifierKey = (isCtrlKey &&
isMetaKey = PR_FALSE; /* reset so there aren't extra modifiers to prevent binding from working */ !isShiftKey && !isAltKey && !isMetaKey);
}
#endif #endif
if (PR_TRUE==ctrlKey) {
aProcessed = PR_TRUE;
} }
// swallow all control keys
// XXX: please please please get these mappings from an external source! if (PR_TRUE == isOnlyPlatformModifierKey)
{
// swallow all keys with only the platform modifier
// even if we don't process them
aProcessed = PR_TRUE;
// A minimal set of fallback mappings in case
// XUL keybindings are unavailable:
switch (charCode) switch (charCode)
{ {
// XXX: hard-coded select all // XXX: hard-coded select all
case (PRUint32)('a'): case (PRUint32)('a'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->SelectAll(); mEditor->SelectAll();
}
break; break;
// XXX: hard-coded cut // XXX: hard-coded cut
case (PRUint32)('x'): case (PRUint32)('x'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Cut(); mEditor->Cut();
}
break; break;
// XXX: hard-coded copy // XXX: hard-coded copy
case (PRUint32)('c'): case (PRUint32)('c'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Copy(); mEditor->Copy();
}
break; break;
// XXX: hard-coded paste // XXX: hard-coded paste
case (PRUint32)('v'): case (PRUint32)('v'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
printf("control-v\n");
if (mEditor) if (mEditor)
mEditor->Paste(); mEditor->Paste();
}
break; break;
// XXX: hard-coded undo // XXX: hard-coded undo
case (PRUint32)('z'): case (PRUint32)('z'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Undo(1); mEditor->Undo(1);
}
break; break;
// XXX: hard-coded redo // XXX: hard-coded redo
case (PRUint32)('y'): case (PRUint32)('y'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Redo(1); mEditor->Redo(1);
}
break; break;
} }
} }
}
return NS_OK; return NS_OK;
} }

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

@ -227,8 +227,6 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
{ {
aProcessed=PR_FALSE; aProcessed=PR_FALSE;
PRUint32 charCode; PRUint32 charCode;
PRBool ctrlKey;
PRBool isAltKey, isMetaKey, isShiftKey;
nsCOMPtr<nsIDOMKeyEvent>keyEvent; nsCOMPtr<nsIDOMKeyEvent>keyEvent;
keyEvent = do_QueryInterface(aKeyEvent); keyEvent = do_QueryInterface(aKeyEvent);
@ -237,87 +235,76 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
return NS_OK; return NS_OK;
} }
if (NS_SUCCEEDED(keyEvent->GetCharCode(&charCode)) && if (NS_SUCCEEDED(keyEvent->GetCharCode(&charCode)))
NS_SUCCEEDED(keyEvent->GetAltKey(&isAltKey)) && {
// Figure out the modifier key, different on every platform
PRBool isOnlyPlatformModifierKey = PR_FALSE;;
PRBool isCtrlKey, isAltKey, isMetaKey, isShiftKey;
if (NS_SUCCEEDED(keyEvent->GetAltKey(&isAltKey)) &&
NS_SUCCEEDED(keyEvent->GetMetaKey(&isMetaKey)) && NS_SUCCEEDED(keyEvent->GetMetaKey(&isMetaKey)) &&
NS_SUCCEEDED(keyEvent->GetShiftKey(&isShiftKey)) && NS_SUCCEEDED(keyEvent->GetShiftKey(&isShiftKey)) &&
NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) ) NS_SUCCEEDED(keyEvent->GetCtrlKey(&isCtrlKey)) )
{ {
#ifdef XP_MAC #if defined(XP_MAC)
// hack to make Mac work for hard-coded keybindings isOnlyPlatformModifierKey = (isMetaKey &&
// metaKey query is only way to query for command key on Mac !isShiftKey && !isCtrlKey && !isAltKey);
// if that's pressed, we'll set the ctrlKey boolean #elif defined(XP_UNIX)
// (even though the control key might also be pressed) isOnlyPlatformModifierKey = (isAltKey &&
if (PR_TRUE==isMetaKey) { !isShiftKey && !isCtrlKey && !isMetaKey);
ctrlKey = !ctrlKey; /* if controlKey is pressed, we shouldn't execute code below */ #else /* Windows and default */
/* if it's not set and cmdKey is, then we should proceed to code below */ isOnlyPlatformModifierKey = (isCtrlKey &&
isMetaKey = PR_FALSE; /* reset so there aren't extra modifiers to prevent binding from working */ !isShiftKey && !isAltKey && !isMetaKey);
}
#endif #endif
if (PR_TRUE==ctrlKey) {
aProcessed = PR_TRUE;
} }
// swallow all control keys
// XXX: please please please get these mappings from an external source! if (PR_TRUE == isOnlyPlatformModifierKey)
{
// swallow all keys with only the platform modifier
// even if we don't process them
aProcessed = PR_TRUE;
// A minimal set of fallback mappings in case
// XUL keybindings are unavailable:
switch (charCode) switch (charCode)
{ {
// XXX: hard-coded select all // XXX: hard-coded select all
case (PRUint32)('a'): case (PRUint32)('a'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->SelectAll(); mEditor->SelectAll();
}
break; break;
// XXX: hard-coded cut // XXX: hard-coded cut
case (PRUint32)('x'): case (PRUint32)('x'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Cut(); mEditor->Cut();
}
break; break;
// XXX: hard-coded copy // XXX: hard-coded copy
case (PRUint32)('c'): case (PRUint32)('c'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Copy(); mEditor->Copy();
}
break; break;
// XXX: hard-coded paste // XXX: hard-coded paste
case (PRUint32)('v'): case (PRUint32)('v'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
printf("control-v\n");
if (mEditor) if (mEditor)
mEditor->Paste(); mEditor->Paste();
}
break; break;
// XXX: hard-coded undo // XXX: hard-coded undo
case (PRUint32)('z'): case (PRUint32)('z'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Undo(1); mEditor->Undo(1);
}
break; break;
// XXX: hard-coded redo // XXX: hard-coded redo
case (PRUint32)('y'): case (PRUint32)('y'):
if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey)
{
if (mEditor) if (mEditor)
mEditor->Redo(1); mEditor->Redo(1);
}
break; break;
} }
} }
}
return NS_OK; return NS_OK;
} }