From b1a69f1bd1f62d019a99f0b4dfc1ecf583e8973c Mon Sep 17 00:00:00 2001 From: "brade%netscape.com" Date: Fri, 15 Oct 1999 14:52:45 +0000 Subject: [PATCH] don't allow other modifiers when cut/copy/pasting (bug #15693); this missed the keyEvent branch. r=kin@netscape.com --- editor/base/nsEditorEventListeners.cpp | 20 +++++++++++-------- .../libeditor/text/nsEditorEventListeners.cpp | 20 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/editor/base/nsEditorEventListeners.cpp b/editor/base/nsEditorEventListeners.cpp index 87c53a51def4..da7d3572cb5c 100644 --- a/editor/base/nsEditorEventListeners.cpp +++ b/editor/base/nsEditorEventListeners.cpp @@ -252,6 +252,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr aProcessed=PR_FALSE; PRUint32 charCode; PRBool ctrlKey; + PRBool isAltKey, isMetaKey, isShiftKey; nsCOMPtruiEvent; uiEvent = do_QueryInterface(aKeyEvent); @@ -261,6 +262,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr } if (NS_SUCCEEDED(uiEvent->GetCharCode(&charCode)) && + NS_SUCCEEDED(uiEvent->GetCtrlKey(&isAltKey)) && + NS_SUCCEEDED(uiEvent->GetCtrlKey(&isMetaKey)) && + NS_SUCCEEDED(uiEvent->GetCtrlKey(&isShiftKey)) && NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey)) ) { #ifdef XP_MAC @@ -268,10 +272,10 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // metaKey query is only way to query for command key on Mac // if that's pressed, we'll set the ctrlKey boolean // (even though the control key might also be pressed) - PRBool isMetaKey; - if (NS_SUCCEEDED(uiEvent->GetMetaKey(&isMetaKey)) && PR_TRUE==isMetaKey) { + if (PR_TRUE==isMetaKey) { ctrlKey = !ctrlKey; /* if controlKey is pressed, we shouldn't execute code below */ /* if it's not set and cmdKey is, then we should proceed to code below */ + isMetaKey = PR_FALSE; /* reset so there aren't extra modifiers to prevent binding from working */ } #endif @@ -284,7 +288,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr { // XXX: hard-coded select all case (PRUint32)('a'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->SelectAll(); @@ -293,7 +297,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded cut case (PRUint32)('x'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Cut(); @@ -302,7 +306,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded copy case (PRUint32)('c'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Copy(); @@ -311,7 +315,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded paste case (PRUint32)('v'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { printf("control-v\n"); if (mEditor) @@ -321,7 +325,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded undo case (PRUint32)('z'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Undo(1); @@ -330,7 +334,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded redo case (PRUint32)('y'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Redo(1); diff --git a/editor/libeditor/text/nsEditorEventListeners.cpp b/editor/libeditor/text/nsEditorEventListeners.cpp index 87c53a51def4..da7d3572cb5c 100644 --- a/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/editor/libeditor/text/nsEditorEventListeners.cpp @@ -252,6 +252,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr aProcessed=PR_FALSE; PRUint32 charCode; PRBool ctrlKey; + PRBool isAltKey, isMetaKey, isShiftKey; nsCOMPtruiEvent; uiEvent = do_QueryInterface(aKeyEvent); @@ -261,6 +262,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr } if (NS_SUCCEEDED(uiEvent->GetCharCode(&charCode)) && + NS_SUCCEEDED(uiEvent->GetCtrlKey(&isAltKey)) && + NS_SUCCEEDED(uiEvent->GetCtrlKey(&isMetaKey)) && + NS_SUCCEEDED(uiEvent->GetCtrlKey(&isShiftKey)) && NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey)) ) { #ifdef XP_MAC @@ -268,10 +272,10 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // metaKey query is only way to query for command key on Mac // if that's pressed, we'll set the ctrlKey boolean // (even though the control key might also be pressed) - PRBool isMetaKey; - if (NS_SUCCEEDED(uiEvent->GetMetaKey(&isMetaKey)) && PR_TRUE==isMetaKey) { + if (PR_TRUE==isMetaKey) { ctrlKey = !ctrlKey; /* if controlKey is pressed, we shouldn't execute code below */ /* if it's not set and cmdKey is, then we should proceed to code below */ + isMetaKey = PR_FALSE; /* reset so there aren't extra modifiers to prevent binding from working */ } #endif @@ -284,7 +288,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr { // XXX: hard-coded select all case (PRUint32)('a'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->SelectAll(); @@ -293,7 +297,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded cut case (PRUint32)('x'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Cut(); @@ -302,7 +306,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded copy case (PRUint32)('c'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Copy(); @@ -311,7 +315,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded paste case (PRUint32)('v'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { printf("control-v\n"); if (mEditor) @@ -321,7 +325,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded undo case (PRUint32)('z'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Undo(1); @@ -330,7 +334,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr // XXX: hard-coded redo case (PRUint32)('y'): - if (PR_TRUE==ctrlKey) + if (PR_TRUE==ctrlKey && PR_FALSE==isShiftKey && PR_FALSE==isAltKey && PR_FALSE==isMetaKey) { if (mEditor) mEditor->Redo(1);