landing keyEvent_19991004_BRANCH

bugs # see the log of the check in into branch
author/reviewer:
mozilla/layout/base/src/nsRangeList.cpp brade/mjudge
mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp brade/ftang
mozilla/layout/events/src/nsDOMEvent.cpp brade/joki
mozilla/layout/events/src/nsEventStateManager.cpp brade/joki
mozilla/widget/public/nsGUIEvent.h akkana/ftang
mozilla/widget/src/windows/nsWindow.cpp ftang/mjudge
mozilla/widget/src/windows/nsWindow.h ftang/mjudge
mozilla/widget/src/mac/nsTextAreaWidget.cpp brade/ftang
mozilla/widget/src/mac/nsMacEventHandler.cpp brade/simon
mozilla/widget/src/xpwidgets/nsKeyBindMgr.cpp brade/ftang
mozilla/widget/src/gtk/nsGtkEventHandler.cpp akkana/?
mozilla/widget/src/gtk/nsWidget.cpp erik/ftang
mozilla/layout/xul/base/src/nsTreeCellFrame.cpp brade/ftang
mozilla/editor/base/nsEditorEventListeners.cpp brade/akkana
mozilla/editor/base/nsHTMLEditor.cpp brade/akkana
mozilla/rdf/content/src/nsXULKeyListener.cpp ftang/saari
fix the master bug- 15693
fix at least, but not limited to, the following bugs
10158,11956,6053,9333,10901,14348,6449,11845,13016,14410,15657,15307,15842,13856
This commit is contained in:
ftang%netscape.com 1999-10-14 18:27:01 +00:00
Родитель 865d4e7a0b
Коммит bd9000ea54
20 изменённых файлов: 487 добавлений и 1338 удалений

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

@ -441,11 +441,7 @@ NS_METHOD nsDOMEvent::GetShiftKey(PRBool* aIsDown)
NS_METHOD nsDOMEvent::GetMetaKey(PRBool* aIsDown)
{
#ifdef XP_MAC
*aIsDown = ((nsInputEvent*)mEvent)->isCommand;
#else
*aIsDown = ((nsInputEvent*)mEvent)->isControl;
#endif
*aIsDown = ((nsInputEvent*)mEvent)->isMeta;
return NS_OK;
}

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

@ -252,13 +252,6 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext,
mCurrentTargetContent = mCurrentFocus;
NS_ADDREF(mCurrentTargetContent);
}
if (aEvent->message == NS_KEY_PRESS) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->isControl) {
keyEvent->charCode += 64;
}
}
}
break;
}
@ -485,7 +478,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext,
}
}
break;
case NS_KEY_DOWN:
case NS_KEY_PRESS:
if (nsEventStatus_eConsumeNoDefault != aStatus) {
switch(((nsKeyEvent*)aEvent)->keyCode) {
case NS_VK_TAB:
@ -540,22 +533,20 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext,
}
}
break;
}
}
break;
case NS_KEY_PRESS:
if (nsEventStatus_eConsumeNoDefault != aStatus) {
//Handle key commands from keys with char representation here, not on KeyDown
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
//Spacebar
if (keyEvent->charCode == 0x20) {
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
sv->ScrollByPages(1);
case 0: /* check charcode since keycode is 0 */
{
//Spacebar
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->charCode == 0x20) {
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
sv->ScrollByPages(1);
}
}
}
}
break;
}
}
}

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

@ -160,10 +160,6 @@ nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
nsresult
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
nsAutoString key;
PRUint32 charCode;
PRUint32 keyCode;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
if (!uiEvent)
@ -171,11 +167,6 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
//non-key event passed to keydown. bad things.
return NS_OK;
}
//
// look at the keyCode if it is return or backspace, process it
// we handle these two special characters here because it makes windows integration
// eaiser
//
PRBool keyProcessed;
// we should check a flag here to see if we should be using built-in key bindings
@ -184,24 +175,15 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
ProcessShortCutKeys(aKeyEvent, keyProcessed);
if (PR_FALSE==keyProcessed)
{
PRBool ctrlKey, altKey, metaKey;
uiEvent->GetCtrlKey(&ctrlKey);
uiEvent->GetAltKey(&altKey);
uiEvent->GetMetaKey(&metaKey);
PRUint32 keyCode;
uiEvent->GetKeyCode(&keyCode);
uiEvent->GetCharCode(&charCode);
#ifdef BLOCK_META_FOR_SOME_REASON
if (metaKey)
return NS_OK; // don't consume
#endif
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (!htmlEditor) return NS_ERROR_NO_INTERFACE;
// if there is no charCode, then it's a key that doesn't map to a character,
// so look for special keys using keyCode
if (0==charCode)
if (0 != keyCode)
{
if (nsIDOMUIEvent::DOM_VK_BACK==keyCode)
{
@ -217,9 +199,6 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
if (nsIDOMUIEvent::DOM_VK_TAB==keyCode)
{
if (metaKey || altKey) // why block option-tab?
return NS_OK; // don't consume
PRUint32 flags=0;
mEditor->GetFlags(&flags);
if ((flags & nsIHTMLEditor::eEditorSingleLineMask))
@ -248,16 +227,16 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
}
if ((PR_FALSE==altKey) && (PR_FALSE==ctrlKey))
{
#if 0
// XXX: this must change. DOM_VK_tab must be handled here, not in keyDown
if (nsIDOMUIEvent::DOM_VK_TAB==keyCode)
{
return NS_OK; // ignore tabs here, they're handled in keyDown if at all
}
htmlEditor->EditorKeyPress(uiEvent);
ScrollSelectionIntoView();
}
#endif
htmlEditor->EditorKeyPress(uiEvent);
ScrollSelectionIntoView();
}
else
ScrollSelectionIntoView();
@ -267,18 +246,12 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
/* these includes are for debug only. this module should never instantiate it's own transactions */
#include "SplitElementTxn.h"
#include "TransactionFactory.h"
nsresult
nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed)
{
aProcessed=PR_FALSE;
PRUint32 keyCode;
PRBool isShift;
PRUint32 charCode;
PRBool ctrlKey;
PRBool altKey;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
@ -287,11 +260,8 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
return NS_OK;
}
if (NS_SUCCEEDED(uiEvent->GetCharCode(&keyCode)) &&
// if (NS_SUCCEEDED(uiEvent->GetKeyCode(&keyCode)) &&
NS_SUCCEEDED(uiEvent->GetShiftKey(&isShift)) &&
NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey)) &&
NS_SUCCEEDED(uiEvent->GetAltKey(&altKey)) )
if (NS_SUCCEEDED(uiEvent->GetCharCode(&charCode)) &&
NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey)) )
{
#ifdef XP_MAC
// hack to make Mac work for hard-coded keybindings
@ -300,7 +270,8 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
// (even though the control key might also be pressed)
PRBool isMetaKey;
if (NS_SUCCEEDED(uiEvent->GetMetaKey(&isMetaKey)) && PR_TRUE==isMetaKey) {
ctrlKey = PR_TRUE;
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 */
}
#endif
@ -309,10 +280,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
}
// swallow all control keys
// XXX: please please please get these mappings from an external source!
switch (keyCode)
switch (charCode)
{
// XXX: hard-coded select all
case nsIDOMUIEvent::DOM_VK_A:
case (PRUint32)('a'):
if (PR_TRUE==ctrlKey)
{
@ -322,158 +292,34 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
break;
// XXX: hard-coded cut
case nsIDOMUIEvent::DOM_VK_X:
case (PRUint32)('x'):
if (PR_TRUE==ctrlKey)
{
if (mEditor)
mEditor->Cut();
}
else if (PR_TRUE==altKey)
{
aProcessed=PR_TRUE;
nsAutoString output;
nsresult res = NS_ERROR_FAILURE;
nsAutoString format;
if (isShift)
format = "text/plain";
else
format = "text/html";
res = mEditor->OutputToString(output, format,
nsIDocumentEncoder::OutputFormatted);
if (NS_SUCCEEDED(res))
{
char* buf = output.ToNewCString();
if (buf)
{
puts(buf);
nsCRT::free(buf);
}
}
}
break;
// XXX: hard-coded copy
case nsIDOMUIEvent::DOM_VK_C:
case (PRUint32)('c'):
if (PR_TRUE==ctrlKey)
{
if (mEditor)
mEditor->Copy();
}
else if (PR_TRUE==altKey)
{
printf("Getting number of columns\n");
aProcessed=PR_TRUE;
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
{
PRInt32 wrap;
if (NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
printf("Currently wrapping to %d\n", wrap);
else
printf("GetBodyWrapWidth returned an error\n");
}
}
break;
case nsIDOMUIEvent::DOM_VK_OPEN_BRACKET:
// hard coded "Decrease wrap size"
if (PR_TRUE==altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
PRInt32 wrap;
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("GetBodyWrapWidth returned an error\n");
break;
}
mailEditor->SetBodyWrapWidth(wrap - 5);
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("Second GetBodyWrapWidth returned an error\n");
break;
}
else printf("Now wrapping to %d\n", wrap);
}
}
break;
case nsIDOMUIEvent::DOM_VK_CLOSE_BRACKET:
// hard coded "Increase wrap size"
if (PR_TRUE==altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
PRInt32 wrap;
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("GetBodyWrapWidth returned an error\n");
break;
}
mailEditor->SetBodyWrapWidth(wrap + 5);
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("Second GetBodyWrapWidth returned an error\n");
break;
}
else printf("Now wrapping to %d\n", wrap);
}
}
break;
// Hard coded "No wrap" or "wrap to window size"
case nsIDOMUIEvent::DOM_VK_BACK_SLASH:
{
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor =
do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
mailEditor->SetBodyWrapWidth(0);
}
}
else if (PR_TRUE==altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor =
do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
mailEditor->SetBodyWrapWidth(-1);
}
}
}
// XXX: hard-coded paste
case nsIDOMUIEvent::DOM_VK_V:
case (PRUint32)('v'):
if (PR_TRUE==ctrlKey)
{
printf("control-v\n");
if (mEditor)
{
if (altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
mailEditor->PasteAsQuotation();
}
else
mEditor->Paste();
}
}
break;
// XXX: hard-coded undo
case nsIDOMUIEvent::DOM_VK_Z:
case (PRUint32)('z'):
if (PR_TRUE==ctrlKey)
{
@ -483,7 +329,6 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
break;
// XXX: hard-coded redo
case nsIDOMUIEvent::DOM_VK_Y:
case (PRUint32)('y'):
if (PR_TRUE==ctrlKey)
{
@ -491,324 +336,6 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
mEditor->Redo(1);
}
break;
// hard-coded ChangeTextAttributes test -- italics
case nsIDOMUIEvent::DOM_VK_I:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
htmlEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
if (PR_FALSE==first) {
htmlEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
}
else {
htmlEditor->RemoveInlineProperty(nsIEditProperty::i, nsnull);
}
}
}
// Hardcoded Insert Arbitrary HTML
else if (PR_TRUE==altKey)
{
aProcessed=PR_TRUE;
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString nsstr ("This is <b>bold <em>and emphasized</em></b> text");
htmlEditor->InsertHTML(nsstr);
}
}
break;
// hard-coded ChangeTextAttributes test -- bold
case nsIDOMUIEvent::DOM_VK_B:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
if (PR_FALSE==first) {
htmlEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
}
else {
htmlEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
}
}
}
break;
// hard-coded ChangeTextAttributes test -- underline
case nsIDOMUIEvent::DOM_VK_U:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
htmlEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
if (PR_FALSE==first) {
htmlEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
}
else {
htmlEditor->RemoveInlineProperty(nsIEditProperty::u, nsnull);
}
}
}
break;
// hard-coded ChangeTextAttributes test -- font color red
case nsIDOMUIEvent::DOM_VK_1:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
nsAutoString color = "COLOR";
nsAutoString value = "red";
htmlEditor->GetInlineProperty(nsIEditProperty::font, &color, &value, first, any, all);
if (!all) {
htmlEditor->SetInlineProperty(nsIEditProperty::font, &color, &value);
}
else {
printf("NOOP: all selected text is already red\n");
}
}
}
break;
// hard-coded ChangeTextAttributes test -- remove font color
case nsIDOMUIEvent::DOM_VK_2:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
nsAutoString color = "COLOR";
htmlEditor->GetInlineProperty(nsIEditProperty::font, &color, nsnull, first, any, all);
if (any) {
htmlEditor->RemoveInlineProperty(nsIEditProperty::font, &color);
}
else {
printf("NOOP: no color set\n");
}
}
}
break;
// hard-coded ChangeTextAttributes test -- font size +2
case nsIDOMUIEvent::DOM_VK_3:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "SIZE";
nsAutoString value = "+2";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded ChangeTextAttributes test -- font size -2
case nsIDOMUIEvent::DOM_VK_4:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "SIZE";
nsAutoString value = "-2";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded ChangeTextAttributes test -- font face helvetica
case nsIDOMUIEvent::DOM_VK_5:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "FACE";
nsAutoString value = "helvetica";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded ChangeTextAttributes test -- font face times
case nsIDOMUIEvent::DOM_VK_6:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "FACE";
nsAutoString value = "times";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded change structure test -- transform block H1
case nsIDOMUIEvent::DOM_VK_7:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::h1->ToString(tag);
htmlEditor->ReplaceBlockParent(tag);
}
}
break;
// hard-coded change structure test -- transform block H2
case nsIDOMUIEvent::DOM_VK_8:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::h2->ToString(tag);
htmlEditor->ReplaceBlockParent(tag);
}
}
break;
// hard-coded change structure test -- normal
case nsIDOMUIEvent::DOM_VK_9:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor) {
htmlEditor->RemoveParagraphStyle();
}
}
break;
// hard-coded change structure test -- GetPargraphTags
case nsIDOMUIEvent::DOM_VK_0:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
{
printf("testing GetPargraphTags\n");
nsStringArray tagList;
nsresult result = htmlEditor->GetParagraphTags(&tagList);
if (NS_SUCCEEDED(result))
{
PRInt32 count = tagList.Count();
PRInt32 i;
for (i=0; i<count; i++)
{
nsString *tag = tagList.StringAt(i);
char *tagCString = tag->ToNewCString();
printf("%s ", tagCString);
nsCRT::free(tagCString);
}
printf("\n");
}
}
}
break;
// hard-coded change structure test -- block blockquote (indent)
case nsIDOMUIEvent::DOM_VK_COMMA:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::blockquote->ToString(tag);
htmlEditor->AddBlockParent(tag);
}
}
break;
// hard-coded change structure test -- un-BlockQuote
case nsIDOMUIEvent::DOM_VK_PERIOD:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::blockquote->ToString(tag);
htmlEditor->RemoveParent(tag);
}
}
break;
#ifdef NS_DEBUG
// hard-coded Text Editor Unit Test
case nsIDOMUIEvent::DOM_VK_T:
if (PR_TRUE==ctrlKey)
{
if (mEditor)
{
PRInt32 numTests, numFailed;
// the unit tests are only exposed through nsIEditor
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
editor->DebugUnitTests(&numTests, &numFailed);
}
}
break;
#endif
}
}
return NS_OK;

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

@ -617,9 +617,13 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMUIEvent* aKeyEvent)
}
}
else // normal typing
{
nsAutoString key(character);
return TypedText(key, eTypedText);
{
if ((PR_FALSE==altKey) && (PR_FALSE==ctrlKey)
&& (PR_FALSE==isShift) && (PR_FALSE==metaKey))
{
nsAutoString key(character);
return TypedText(key, eTypedText);
}
}
}
return NS_ERROR_FAILURE;

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

@ -617,9 +617,13 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMUIEvent* aKeyEvent)
}
}
else // normal typing
{
nsAutoString key(character);
return TypedText(key, eTypedText);
{
if ((PR_FALSE==altKey) && (PR_FALSE==ctrlKey)
&& (PR_FALSE==isShift) && (PR_FALSE==metaKey))
{
nsAutoString key(character);
return TypedText(key, eTypedText);
}
}
}
return NS_ERROR_FAILURE;

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

@ -160,10 +160,6 @@ nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
nsresult
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
nsAutoString key;
PRUint32 charCode;
PRUint32 keyCode;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
if (!uiEvent)
@ -171,11 +167,6 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
//non-key event passed to keydown. bad things.
return NS_OK;
}
//
// look at the keyCode if it is return or backspace, process it
// we handle these two special characters here because it makes windows integration
// eaiser
//
PRBool keyProcessed;
// we should check a flag here to see if we should be using built-in key bindings
@ -184,24 +175,15 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
ProcessShortCutKeys(aKeyEvent, keyProcessed);
if (PR_FALSE==keyProcessed)
{
PRBool ctrlKey, altKey, metaKey;
uiEvent->GetCtrlKey(&ctrlKey);
uiEvent->GetAltKey(&altKey);
uiEvent->GetMetaKey(&metaKey);
PRUint32 keyCode;
uiEvent->GetKeyCode(&keyCode);
uiEvent->GetCharCode(&charCode);
#ifdef BLOCK_META_FOR_SOME_REASON
if (metaKey)
return NS_OK; // don't consume
#endif
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (!htmlEditor) return NS_ERROR_NO_INTERFACE;
// if there is no charCode, then it's a key that doesn't map to a character,
// so look for special keys using keyCode
if (0==charCode)
if (0 != keyCode)
{
if (nsIDOMUIEvent::DOM_VK_BACK==keyCode)
{
@ -217,9 +199,6 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
if (nsIDOMUIEvent::DOM_VK_TAB==keyCode)
{
if (metaKey || altKey) // why block option-tab?
return NS_OK; // don't consume
PRUint32 flags=0;
mEditor->GetFlags(&flags);
if ((flags & nsIHTMLEditor::eEditorSingleLineMask))
@ -248,16 +227,16 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
}
if ((PR_FALSE==altKey) && (PR_FALSE==ctrlKey))
{
#if 0
// XXX: this must change. DOM_VK_tab must be handled here, not in keyDown
if (nsIDOMUIEvent::DOM_VK_TAB==keyCode)
{
return NS_OK; // ignore tabs here, they're handled in keyDown if at all
}
htmlEditor->EditorKeyPress(uiEvent);
ScrollSelectionIntoView();
}
#endif
htmlEditor->EditorKeyPress(uiEvent);
ScrollSelectionIntoView();
}
else
ScrollSelectionIntoView();
@ -267,18 +246,12 @@ nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
}
/* these includes are for debug only. this module should never instantiate it's own transactions */
#include "SplitElementTxn.h"
#include "TransactionFactory.h"
nsresult
nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed)
{
aProcessed=PR_FALSE;
PRUint32 keyCode;
PRBool isShift;
PRUint32 charCode;
PRBool ctrlKey;
PRBool altKey;
nsCOMPtr<nsIDOMUIEvent>uiEvent;
uiEvent = do_QueryInterface(aKeyEvent);
@ -287,11 +260,8 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
return NS_OK;
}
if (NS_SUCCEEDED(uiEvent->GetCharCode(&keyCode)) &&
// if (NS_SUCCEEDED(uiEvent->GetKeyCode(&keyCode)) &&
NS_SUCCEEDED(uiEvent->GetShiftKey(&isShift)) &&
NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey)) &&
NS_SUCCEEDED(uiEvent->GetAltKey(&altKey)) )
if (NS_SUCCEEDED(uiEvent->GetCharCode(&charCode)) &&
NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey)) )
{
#ifdef XP_MAC
// hack to make Mac work for hard-coded keybindings
@ -300,7 +270,8 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
// (even though the control key might also be pressed)
PRBool isMetaKey;
if (NS_SUCCEEDED(uiEvent->GetMetaKey(&isMetaKey)) && PR_TRUE==isMetaKey) {
ctrlKey = PR_TRUE;
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 */
}
#endif
@ -309,10 +280,9 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
}
// swallow all control keys
// XXX: please please please get these mappings from an external source!
switch (keyCode)
switch (charCode)
{
// XXX: hard-coded select all
case nsIDOMUIEvent::DOM_VK_A:
case (PRUint32)('a'):
if (PR_TRUE==ctrlKey)
{
@ -322,158 +292,34 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
break;
// XXX: hard-coded cut
case nsIDOMUIEvent::DOM_VK_X:
case (PRUint32)('x'):
if (PR_TRUE==ctrlKey)
{
if (mEditor)
mEditor->Cut();
}
else if (PR_TRUE==altKey)
{
aProcessed=PR_TRUE;
nsAutoString output;
nsresult res = NS_ERROR_FAILURE;
nsAutoString format;
if (isShift)
format = "text/plain";
else
format = "text/html";
res = mEditor->OutputToString(output, format,
nsIDocumentEncoder::OutputFormatted);
if (NS_SUCCEEDED(res))
{
char* buf = output.ToNewCString();
if (buf)
{
puts(buf);
nsCRT::free(buf);
}
}
}
break;
// XXX: hard-coded copy
case nsIDOMUIEvent::DOM_VK_C:
case (PRUint32)('c'):
if (PR_TRUE==ctrlKey)
{
if (mEditor)
mEditor->Copy();
}
else if (PR_TRUE==altKey)
{
printf("Getting number of columns\n");
aProcessed=PR_TRUE;
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
{
PRInt32 wrap;
if (NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
printf("Currently wrapping to %d\n", wrap);
else
printf("GetBodyWrapWidth returned an error\n");
}
}
break;
case nsIDOMUIEvent::DOM_VK_OPEN_BRACKET:
// hard coded "Decrease wrap size"
if (PR_TRUE==altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
PRInt32 wrap;
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("GetBodyWrapWidth returned an error\n");
break;
}
mailEditor->SetBodyWrapWidth(wrap - 5);
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("Second GetBodyWrapWidth returned an error\n");
break;
}
else printf("Now wrapping to %d\n", wrap);
}
}
break;
case nsIDOMUIEvent::DOM_VK_CLOSE_BRACKET:
// hard coded "Increase wrap size"
if (PR_TRUE==altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
PRInt32 wrap;
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("GetBodyWrapWidth returned an error\n");
break;
}
mailEditor->SetBodyWrapWidth(wrap + 5);
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
{
printf("Second GetBodyWrapWidth returned an error\n");
break;
}
else printf("Now wrapping to %d\n", wrap);
}
}
break;
// Hard coded "No wrap" or "wrap to window size"
case nsIDOMUIEvent::DOM_VK_BACK_SLASH:
{
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor =
do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
mailEditor->SetBodyWrapWidth(0);
}
}
else if (PR_TRUE==altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor =
do_QueryInterface(mEditor);
if (mailEditor)
{
aProcessed=PR_TRUE;
mailEditor->SetBodyWrapWidth(-1);
}
}
}
// XXX: hard-coded paste
case nsIDOMUIEvent::DOM_VK_V:
case (PRUint32)('v'):
if (PR_TRUE==ctrlKey)
{
printf("control-v\n");
if (mEditor)
{
if (altKey)
{
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
if (mailEditor)
mailEditor->PasteAsQuotation();
}
else
mEditor->Paste();
}
}
break;
// XXX: hard-coded undo
case nsIDOMUIEvent::DOM_VK_Z:
case (PRUint32)('z'):
if (PR_TRUE==ctrlKey)
{
@ -483,7 +329,6 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
break;
// XXX: hard-coded redo
case nsIDOMUIEvent::DOM_VK_Y:
case (PRUint32)('y'):
if (PR_TRUE==ctrlKey)
{
@ -491,324 +336,6 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
mEditor->Redo(1);
}
break;
// hard-coded ChangeTextAttributes test -- italics
case nsIDOMUIEvent::DOM_VK_I:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
htmlEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
if (PR_FALSE==first) {
htmlEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
}
else {
htmlEditor->RemoveInlineProperty(nsIEditProperty::i, nsnull);
}
}
}
// Hardcoded Insert Arbitrary HTML
else if (PR_TRUE==altKey)
{
aProcessed=PR_TRUE;
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString nsstr ("This is <b>bold <em>and emphasized</em></b> text");
htmlEditor->InsertHTML(nsstr);
}
}
break;
// hard-coded ChangeTextAttributes test -- bold
case nsIDOMUIEvent::DOM_VK_B:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
if (PR_FALSE==first) {
htmlEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
}
else {
htmlEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
}
}
}
break;
// hard-coded ChangeTextAttributes test -- underline
case nsIDOMUIEvent::DOM_VK_U:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
htmlEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
if (PR_FALSE==first) {
htmlEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
}
else {
htmlEditor->RemoveInlineProperty(nsIEditProperty::u, nsnull);
}
}
}
break;
// hard-coded ChangeTextAttributes test -- font color red
case nsIDOMUIEvent::DOM_VK_1:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
nsAutoString color = "COLOR";
nsAutoString value = "red";
htmlEditor->GetInlineProperty(nsIEditProperty::font, &color, &value, first, any, all);
if (!all) {
htmlEditor->SetInlineProperty(nsIEditProperty::font, &color, &value);
}
else {
printf("NOOP: all selected text is already red\n");
}
}
}
break;
// hard-coded ChangeTextAttributes test -- remove font color
case nsIDOMUIEvent::DOM_VK_2:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
PRBool any = PR_FALSE;
PRBool all = PR_FALSE;
PRBool first = PR_FALSE;
nsAutoString color = "COLOR";
htmlEditor->GetInlineProperty(nsIEditProperty::font, &color, nsnull, first, any, all);
if (any) {
htmlEditor->RemoveInlineProperty(nsIEditProperty::font, &color);
}
else {
printf("NOOP: no color set\n");
}
}
}
break;
// hard-coded ChangeTextAttributes test -- font size +2
case nsIDOMUIEvent::DOM_VK_3:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "SIZE";
nsAutoString value = "+2";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded ChangeTextAttributes test -- font size -2
case nsIDOMUIEvent::DOM_VK_4:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "SIZE";
nsAutoString value = "-2";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded ChangeTextAttributes test -- font face helvetica
case nsIDOMUIEvent::DOM_VK_5:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "FACE";
nsAutoString value = "helvetica";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded ChangeTextAttributes test -- font face times
case nsIDOMUIEvent::DOM_VK_6:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
// XXX: move this logic down into texteditor rules delegate
// should just call mEditor->ChangeTextProperty(prop)
//PRBool any = PR_FALSE;
//PRBool all = PR_FALSE;
//PRBool first = PR_FALSE;
nsAutoString prop = "FACE";
nsAutoString value = "times";
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
}
}
break;
// hard-coded change structure test -- transform block H1
case nsIDOMUIEvent::DOM_VK_7:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::h1->ToString(tag);
htmlEditor->ReplaceBlockParent(tag);
}
}
break;
// hard-coded change structure test -- transform block H2
case nsIDOMUIEvent::DOM_VK_8:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::h2->ToString(tag);
htmlEditor->ReplaceBlockParent(tag);
}
}
break;
// hard-coded change structure test -- normal
case nsIDOMUIEvent::DOM_VK_9:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor) {
htmlEditor->RemoveParagraphStyle();
}
}
break;
// hard-coded change structure test -- GetPargraphTags
case nsIDOMUIEvent::DOM_VK_0:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
{
printf("testing GetPargraphTags\n");
nsStringArray tagList;
nsresult result = htmlEditor->GetParagraphTags(&tagList);
if (NS_SUCCEEDED(result))
{
PRInt32 count = tagList.Count();
PRInt32 i;
for (i=0; i<count; i++)
{
nsString *tag = tagList.StringAt(i);
char *tagCString = tag->ToNewCString();
printf("%s ", tagCString);
nsCRT::free(tagCString);
}
printf("\n");
}
}
}
break;
// hard-coded change structure test -- block blockquote (indent)
case nsIDOMUIEvent::DOM_VK_COMMA:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::blockquote->ToString(tag);
htmlEditor->AddBlockParent(tag);
}
}
break;
// hard-coded change structure test -- un-BlockQuote
case nsIDOMUIEvent::DOM_VK_PERIOD:
if (PR_TRUE==ctrlKey)
{
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
if (htmlEditor)
{
nsAutoString tag;
nsIEditProperty::blockquote->ToString(tag);
htmlEditor->RemoveParent(tag);
}
}
break;
#ifdef NS_DEBUG
// hard-coded Text Editor Unit Test
case nsIDOMUIEvent::DOM_VK_T:
if (PR_TRUE==ctrlKey)
{
if (mEditor)
{
PRInt32 numTests, numFailed;
// the unit tests are only exposed through nsIEditor
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (editor)
editor->DebugUnitTests(&numTests, &numFailed);
}
}
break;
#endif
}
}
return NS_OK;

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

@ -850,7 +850,7 @@ nsRangeList::HandleKeyEvent(nsGUIEvent *aGuiEvent)
STATUS_CHECK_RETURN_MACRO();
nsresult result = NS_ERROR_FAILURE;
if (NS_KEY_DOWN == aGuiEvent->message) {
if (NS_KEY_PRESS == aGuiEvent->message) {
nsKeyEvent *keyEvent = (nsKeyEvent *)aGuiEvent; //this is ok. It really is a keyevent
switch (keyEvent->keyCode)
{

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

@ -441,11 +441,7 @@ NS_METHOD nsDOMEvent::GetShiftKey(PRBool* aIsDown)
NS_METHOD nsDOMEvent::GetMetaKey(PRBool* aIsDown)
{
#ifdef XP_MAC
*aIsDown = ((nsInputEvent*)mEvent)->isCommand;
#else
*aIsDown = ((nsInputEvent*)mEvent)->isControl;
#endif
*aIsDown = ((nsInputEvent*)mEvent)->isMeta;
return NS_OK;
}

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

@ -252,13 +252,6 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext,
mCurrentTargetContent = mCurrentFocus;
NS_ADDREF(mCurrentTargetContent);
}
if (aEvent->message == NS_KEY_PRESS) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->isControl) {
keyEvent->charCode += 64;
}
}
}
break;
}
@ -485,7 +478,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext,
}
}
break;
case NS_KEY_DOWN:
case NS_KEY_PRESS:
if (nsEventStatus_eConsumeNoDefault != aStatus) {
switch(((nsKeyEvent*)aEvent)->keyCode) {
case NS_VK_TAB:
@ -540,22 +533,20 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext,
}
}
break;
}
}
break;
case NS_KEY_PRESS:
if (nsEventStatus_eConsumeNoDefault != aStatus) {
//Handle key commands from keys with char representation here, not on KeyDown
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
//Spacebar
if (keyEvent->charCode == 0x20) {
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
sv->ScrollByPages(1);
case 0: /* check charcode since keycode is 0 */
{
//Spacebar
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
if (keyEvent->charCode == 0x20) {
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
sv->ScrollByPages(1);
}
}
}
}
break;
}
}
}

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

@ -1978,9 +1978,7 @@ nsEnderKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
uiEvent->GetShiftKey(&(event.isShift));
uiEvent->GetCtrlKey(&(event.isControl));
uiEvent->GetAltKey(&(event.isAlt));
#ifdef XP_MAC
uiEvent->GetMetaKey(&(event.isCommand));
#endif
uiEvent->GetMetaKey(&(event.isMeta));
nsIEventStateManager *manager=nsnull;
result = mContext->GetEventStateManager(&manager);
@ -2034,9 +2032,7 @@ nsEnderKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
uiEvent->GetShiftKey(&(event.isShift));
uiEvent->GetCtrlKey(&(event.isControl));
uiEvent->GetAltKey(&(event.isAlt));
#ifdef XP_MAC
uiEvent->GetMetaKey(&(event.isCommand));
#endif
uiEvent->GetMetaKey(&(event.isMeta));
nsIEventStateManager *manager=nsnull;
@ -2091,9 +2087,7 @@ nsEnderKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
uiEvent->GetShiftKey(&(event.isShift));
uiEvent->GetCtrlKey(&(event.isControl));
uiEvent->GetAltKey(&(event.isAlt));
#ifdef XP_MAC
uiEvent->GetMetaKey(&(event.isCommand));
#endif
uiEvent->GetMetaKey(&(event.isMeta));
nsIEventStateManager *manager=nsnull;
@ -2226,9 +2220,7 @@ nsEnderMouseListener::MouseDown(nsIDOMEvent* aEvent)
uiEvent->GetShiftKey(&(event.isShift));
uiEvent->GetCtrlKey(&(event.isControl));
uiEvent->GetAltKey(&(event.isAlt));
#ifdef XP_MAC
uiEvent->GetMetaKey(&(event.isCommand));
#endif
uiEvent->GetMetaKey(&(event.isMeta));
PRUint16 clickCount;
uiEvent->GetClickcount(&clickCount);
NS_ASSERTION(clickCount>0 && clickCount<3, "bad click count");

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

@ -226,7 +226,7 @@ nsTreeCellFrame::HandleMouseDownEvent(nsIPresContext& aPresContext,
if (((nsMouseEvent *)aEvent)->isShift)
mTreeFrame->RangedSelection(aPresContext, this); // Applying a ranged selection.
#ifdef XP_MAC
else if (((nsMouseEvent *)aEvent)->isCommand)
else if (((nsMouseEvent *)aEvent)->isMeta)
mTreeFrame->ToggleSelection(aPresContext, this);
#else
else if (((nsMouseEvent *)aEvent)->isControl)

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

@ -496,7 +496,17 @@ nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventTy
((isControl && (modControl==0)) ||
(!isControl && (modControl==1))))
{
#ifndef XP_MAC
// Temp hack. we should remove this
// after XUL can spec which key for keybinding
if((isControl && (modCommand==0)) ||
(!isControl && (modCommand==1)))
{
break;
}
#else
break;
#endif
}
//printf("Passed command/ctrl test \n"); // this leaks

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

@ -107,18 +107,15 @@ struct nsScrollbarEvent : public nsGUIEvent {
struct nsInputEvent : public nsGUIEvent {
/// PR_TRUE indicates the shift key in down
/// PR_TRUE indicates the shift key is down
PRBool isShift;
/// PR_TRUE indicates the control key in down
/// PR_TRUE indicates the control key is down
PRBool isControl;
/// PR_TRUE indicates the alt key in down
/// PR_TRUE indicates the alt key is down
PRBool isAlt;
#ifdef XP_MAC
/// PR_TRUE indicates the command key in down
/// For now, it's only used in Widget: not for export
/// in nsIDOMEvent.h or nsJSEvent.cpp (later maybe)
PRBool isCommand;
#endif
/// PR_TRUE indicates the meta key is down
/// (or, on Mac, the Command key)
PRBool isMeta;
};
/**

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

@ -54,101 +54,6 @@ struct EventInfo {
nsRect *rect; // the rect
};
struct nsKeyConverter {
int vkCode; // Platform independent key code
int keysym; // GDK keysym key code
};
struct nsKeyConverter nsKeycodes[] = {
{ NS_VK_CANCEL, GDK_Cancel },
{ NS_VK_BACK, GDK_BackSpace },
{ NS_VK_TAB, GDK_Tab },
{ NS_VK_TAB, GDK_ISO_Left_Tab },
{ NS_VK_CLEAR, GDK_Clear },
{ NS_VK_RETURN, GDK_Return },
{ NS_VK_SHIFT, GDK_Shift_L },
{ NS_VK_SHIFT, GDK_Shift_R },
{ NS_VK_CONTROL, GDK_Control_L },
{ NS_VK_CONTROL, GDK_Control_R },
{ NS_VK_ALT, GDK_Alt_L },
{ NS_VK_ALT, GDK_Alt_R },
{ NS_VK_PAUSE, GDK_Pause },
{ NS_VK_CAPS_LOCK, GDK_Caps_Lock },
{ NS_VK_ESCAPE, GDK_Escape },
{ NS_VK_SPACE, GDK_space },
{ NS_VK_PAGE_UP, GDK_Page_Up },
{ NS_VK_PAGE_DOWN, GDK_Page_Down },
{ NS_VK_END, GDK_End },
{ NS_VK_HOME, GDK_Home },
{ NS_VK_LEFT, GDK_Left },
{ NS_VK_UP, GDK_Up },
{ NS_VK_RIGHT, GDK_Right },
{ NS_VK_DOWN, GDK_Down },
{ NS_VK_PRINTSCREEN, GDK_Print },
{ NS_VK_INSERT, GDK_Insert },
{ NS_VK_DELETE, GDK_Delete },
{ NS_VK_MULTIPLY, GDK_KP_Multiply },
{ NS_VK_ADD, GDK_KP_Add },
{ NS_VK_SEPARATOR, GDK_KP_Separator },
{ NS_VK_SUBTRACT, GDK_KP_Subtract },
{ NS_VK_DECIMAL, GDK_KP_Decimal },
{ NS_VK_DIVIDE, GDK_KP_Divide },
{ NS_VK_RETURN, GDK_KP_Enter },
{ NS_VK_COMMA, GDK_comma },
{ NS_VK_PERIOD, GDK_period },
{ NS_VK_SLASH, GDK_slash },
{ NS_VK_BACK_SLASH, GDK_backslash },
//XXX: How do you get a BACK_QUOTE? NS_VK_BACK_QUOTE, GDK_backquote,
{ NS_VK_OPEN_BRACKET, GDK_bracketleft },
{ NS_VK_CLOSE_BRACKET, GDK_bracketright },
{ NS_VK_QUOTE, GDK_quotedbl }
};
void nsGtkWidget_InitNSKeyEvent(int aEventType, nsKeyEvent& aKeyEvent,
GtkWidget *w, gpointer p, GdkEventKey * event);
// Input keysym is in gtk format; output is in NS_VK format
int nsConvertKey(int keysym)
{
int i;
int length = sizeof(nsKeycodes) / sizeof(struct nsKeyConverter);
// First, try to handle alphanumeric input, not listed in nsKeycodes:
// most likely, more letters will be getting typed in than things in
// the key list, so we will look through these first.
// since X has different key symbols for upper and lowercase letters and
// mozilla does not, convert gdk's to mozilla's
if (keysym >= GDK_a && keysym <= GDK_z)
return keysym - GDK_a + NS_VK_A;
if (keysym >= GDK_A && keysym <= GDK_Z)
return keysym - GDK_A + NS_VK_A;
// numbers
if (keysym >= GDK_0 && keysym <= GDK_9)
return keysym - GDK_0 + NS_VK_0;
// keypad numbers
if (keysym >= GDK_KP_0 && keysym <= GDK_KP_9)
return keysym - GDK_KP_0 + NS_VK_NUMPAD0;
// misc other things
for (i = 0; i < length; i++) {
if (nsKeycodes[i].keysym == keysym)
return(nsKeycodes[i].vkCode);
}
// function keys
if (keysym >= GDK_F1 && keysym <= GDK_F24)
return keysym - GDK_F1 + NS_VK_F1;
return((int)0);
}
//==============================================================
void InitAllocationEvent(GtkAllocation *aAlloc,
gpointer p,
@ -241,6 +146,104 @@ void UninitExposeEvent(GdkEventExpose *aGEE,
}
}
struct nsKeyConverter {
int vkCode; // Platform independent key code
int keysym; // GDK keysym key code
};
struct nsKeyConverter nsKeycodes[] = {
{ NS_VK_CANCEL, GDK_Cancel },
{ NS_VK_BACK, GDK_BackSpace },
{ NS_VK_TAB, GDK_Tab },
{ NS_VK_TAB, GDK_ISO_Left_Tab },
{ NS_VK_CLEAR, GDK_Clear },
{ NS_VK_RETURN, GDK_Return },
{ NS_VK_SHIFT, GDK_Shift_L },
{ NS_VK_SHIFT, GDK_Shift_R },
{ NS_VK_CONTROL, GDK_Control_L },
{ NS_VK_CONTROL, GDK_Control_R },
{ NS_VK_ALT, GDK_Alt_L },
{ NS_VK_ALT, GDK_Alt_R },
{ NS_VK_PAUSE, GDK_Pause },
{ NS_VK_CAPS_LOCK, GDK_Caps_Lock },
{ NS_VK_ESCAPE, GDK_Escape },
{ NS_VK_SPACE, GDK_space },
{ NS_VK_PAGE_UP, GDK_Page_Up },
{ NS_VK_PAGE_DOWN, GDK_Page_Down },
{ NS_VK_END, GDK_End },
{ NS_VK_HOME, GDK_Home },
{ NS_VK_LEFT, GDK_Left },
{ NS_VK_UP, GDK_Up },
{ NS_VK_RIGHT, GDK_Right },
{ NS_VK_DOWN, GDK_Down },
{ NS_VK_PRINTSCREEN, GDK_Print },
{ NS_VK_INSERT, GDK_Insert },
{ NS_VK_DELETE, GDK_Delete },
{ NS_VK_MULTIPLY, GDK_KP_Multiply },
{ NS_VK_ADD, GDK_KP_Add },
{ NS_VK_SEPARATOR, GDK_KP_Separator },
{ NS_VK_SUBTRACT, GDK_KP_Subtract },
{ NS_VK_DECIMAL, GDK_KP_Decimal },
{ NS_VK_DIVIDE, GDK_KP_Divide },
{ NS_VK_RETURN, GDK_KP_Enter },
{ NS_VK_COMMA, GDK_comma },
{ NS_VK_PERIOD, GDK_period },
{ NS_VK_SLASH, GDK_slash },
{ NS_VK_BACK_SLASH, GDK_backslash },
//XXX: How do you get a BACK_QUOTE? NS_VK_BACK_QUOTE, GDK_backquote,
{ NS_VK_OPEN_BRACKET, GDK_bracketleft },
{ NS_VK_CLOSE_BRACKET, GDK_bracketright },
{ NS_VK_QUOTE, GDK_quotedbl }
};
void nsGtkWidget_InitNSKeyEvent(int aEventType, nsKeyEvent& aKeyEvent,
GtkWidget *w, gpointer p, GdkEventKey * event);
//==============================================================
// Input keysym is in gtk format; output is in NS_VK format
int nsPlatformToDOMKeyCode(GdkEventKey *aGEK)
{
int i;
int length = sizeof(nsKeycodes) / sizeof(struct nsKeyConverter);
int keysym = aGEK->keyval;
// First, try to handle alphanumeric input, not listed in nsKeycodes:
// most likely, more letters will be getting typed in than things in
// the key list, so we will look through these first.
// since X has different key symbols for upper and lowercase letters and
// mozilla does not, convert gdk's to mozilla's
if (keysym >= GDK_a && keysym <= GDK_z)
return keysym - GDK_a + NS_VK_A;
if (keysym >= GDK_A && keysym <= GDK_Z)
return keysym - GDK_A + NS_VK_A;
// numbers
if (keysym >= GDK_0 && keysym <= GDK_9)
return keysym - GDK_0 + NS_VK_0;
// keypad numbers
if (keysym >= GDK_KP_0 && keysym <= GDK_KP_9)
return keysym - GDK_KP_0 + NS_VK_NUMPAD0;
// misc other things
for (i = 0; i < length; i++) {
if (nsKeycodes[i].keysym == keysym)
return(nsKeycodes[i].vkCode);
}
// function keys
if (keysym >= GDK_F1 && keysym <= GDK_F24)
return keysym - GDK_F1 + NS_VK_F1;
return((int)0);
}
//==============================================================
PRUint32 nsConvertCharCodeToUnicode(GdkEventKey* aGEK)
@ -253,7 +256,12 @@ PRUint32 nsConvertCharCodeToUnicode(GdkEventKey* aGEK)
// This is only true for control chars; for alt chars, send the
// ascii for the key, i.e. a for alt-a.
if (aGEK->state & GDK_CONTROL_MASK)
return aGEK->string[0];
{
if (aGEK->state & GDK_SHIFT_MASK)
return aGEK->string[0] + 'A' - 1;
else
return aGEK->string[0] + 'a' - 1;
}
// For now (obviously this will need to change for IME),
// only set a char code if the result is printable:
@ -286,7 +294,7 @@ void InitKeyEvent(GdkEventKey *aGEK,
anEvent.eventStructType = NS_KEY_EVENT;
if (aGEK != nsnull) {
anEvent.keyCode = nsConvertKey(aGEK->keyval) & 0x00FF;
anEvent.keyCode = nsPlatformToDOMKeyCode(aGEK);
anEvent.charCode = 0;
anEvent.time = aGEK->time;
anEvent.isShift = (aGEK->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE;
@ -308,22 +316,35 @@ void InitKeyPressEvent(GdkEventKey *aGEK,
anEvent.message = NS_KEY_PRESS;
anEvent.widget = (nsWidget*)p;
if (aGEK!=nsnull) {
anEvent.charCode = nsConvertCharCodeToUnicode(aGEK);
if (anEvent.charCode == 0)
anEvent.keyCode = nsConvertKey(aGEK->keyval) & 0x00FF;
else
anEvent.keyCode = 0;
if (aGEK!=nsnull)
{
anEvent.isShift = (aGEK->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE;
anEvent.isControl = (aGEK->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE;
anEvent.isAlt = (aGEK->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE;
// XXX need meta, but nsKeyEvent doesn't offer it -- see bug 14465
anEvent.isMeta = (aGEK->state & GDK_MOD2_MASK) ? PR_TRUE : PR_FALSE;
#ifdef DEBUG_pavlov
g_print("%s\n", aGEK->string);
anEvent.charCode = nsConvertCharCodeToUnicode(aGEK);
if (anEvent.charCode)
anEvent.keyCode = 0;
else
anEvent.keyCode = nsPlatformToDOMKeyCode(aGEK);
#if defined(DEBUG_akkana) || defined(DEBUG_pavlov)
printf("Key Press event: keyCode = %d, char code = '%c'",
anEvent.keyCode, anEvent.charCode);
if (anEvent.isShift)
printf(" [shift]");
if (anEvent.isControl)
printf(" [ctrl]");
if (anEvent.isAlt)
printf(" [alt]");
if (anEvent.isMeta)
printf(" [meta]");
printf("\n");
#endif
anEvent.time = aGEK->time;
anEvent.isShift = (aGEK->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE;
anEvent.point.x = 0;
anEvent.point.y = 0;
}
@ -599,7 +620,7 @@ static gint composition_end(GdkEventKey *aEvent, nsWindow *aWin,
static nsIUnicodeDecoder*
open_unicode_decoder(void) {
nsresult result;
nsresult result = NS_ERROR_FAILURE;
nsIUnicodeDecoder *decoder = nsnull;
NS_WITH_SERVICE(nsIPlatformCharset, platform, NS_PLATFORMCHARSET_PROGID,
&result);
@ -614,7 +635,7 @@ open_unicode_decoder(void) {
GetService(kCharsetConverterManagerCID,
nsCOMTypeInfo<nsICharsetConverterManager>::GetIID(),
(nsISupports**)&manager);
if (NS_SUCCEEDED(res)) {
if (manager && NS_SUCCEEDED(res)) {
manager->GetUnicodeDecoder(&charset, &decoder);
nsServiceManager::ReleaseService(kCharsetConverterManagerCID, manager);
}
@ -721,13 +742,13 @@ gint handle_key_press_event(GtkWidget *w, GdkEventKey* event, gpointer p)
// character code. Note we have to check for modifier keys, since
// gtk returns a character value for them
//
#ifdef USE_XIM_NOT
#ifdef USE_XIM
if (event->length) {
static nsIUnicodeDecoder *decoder = nsnull;
if (!decoder) {
decoder = open_unicode_decoder();
}
if (decoder) {
if (decoder && (!kevent.keyCode)) {
nsEventStatus status;
composition_start(event, win, &status);
composition_draw(event, win, decoder, &status);

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

@ -146,6 +146,13 @@ nsWidget::~nsWidget()
if (!sWidgetCount--) {
NS_IF_RELEASE(sLookAndFeel);
}
#ifdef USE_XIM
if (mIMECompositionUniString) {
delete[] mIMECompositionUniString;
mIMECompositionUniString = nsnull;
}
#endif /* USE_XIM */
}
NS_IMETHODIMP nsWidget::GetAbsoluteBounds(nsRect &aRect)

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

@ -411,7 +411,7 @@ PRBool nsMacEventHandler::DragEvent ( unsigned int aMessage, Point aMouseGlobal,
geckoEvent.isShift = ((aKeyModifiers & shiftKey) != 0);
geckoEvent.isControl = ((aKeyModifiers & controlKey) != 0);
geckoEvent.isAlt = ((aKeyModifiers & optionKey) != 0);
geckoEvent.isCommand = ((aKeyModifiers & cmdKey) != 0);
geckoEvent.isMeta = ((aKeyModifiers & cmdKey) != 0);
// nsMouseEvent
geckoEvent.clickCount = 1;
@ -575,7 +575,9 @@ static PRUint32 ConvertMacToRaptorKeyCode(UInt32 eventMessage, UInt32 eventModif
case kDownArrowKeyCode: raptorKeyCode = NS_VK_DOWN; break;
default:
if ((eventModifiers & controlKey) != 0)
charCode += 64;
// if we haven't gotten the key code already, look at the char code
switch (charCode)
{
@ -648,13 +650,31 @@ void nsMacEventHandler::InitializeKeyEvent(nsKeyEvent& aKeyEvent, EventRecord& a
aKeyEvent.isShift = ((aOSEvent.modifiers & shiftKey) != 0);
aKeyEvent.isControl = ((aOSEvent.modifiers & controlKey) != 0);
aKeyEvent.isAlt = ((aOSEvent.modifiers & optionKey) != 0);
aKeyEvent.isCommand = ((aOSEvent.modifiers & cmdKey) != 0);
aKeyEvent.isMeta = ((aOSEvent.modifiers & cmdKey) != 0);
//
// nsKeyEvent parts
//
if (message == NS_KEY_PRESS && !IsSpecialRaptorKey((aOSEvent.message & keyCodeMask) >> 8) )
if (message == NS_KEY_PRESS
&& !IsSpecialRaptorKey((aOSEvent.message & keyCodeMask) >> 8) )
{
if ( aKeyEvent.isControl )
{
aKeyEvent.charCode = (aOSEvent.message & charCodeMask);
if ( aKeyEvent.charCode <= 26 )
{
if ( aKeyEvent.isShift )
aKeyEvent.charCode += 'A';
else
aKeyEvent.charCode += 'a';
}
}
else
if ( !aKeyEvent.isMeta)
{
aKeyEvent.isShift = aKeyEvent.isControl = aKeyEvent.isAlt = aKeyEvent.isMeta = 0;
}
aKeyEvent.keyCode = 0;
aKeyEvent.charCode = ConvertKeyEventToUnicode(aOSEvent);
NS_ASSERTION(0 != aKeyEvent.charCode, "nsMacEventHandler::InitializeKeyEvent: ConvertKeyEventToUnicode returned 0.");
@ -1226,7 +1246,7 @@ void nsMacEventHandler::ConvertOSEventToMouseEvent(
aMouseEvent.isShift = ((aOSEvent.modifiers & shiftKey) != 0);
aMouseEvent.isControl = ((aOSEvent.modifiers & controlKey) != 0);
aMouseEvent.isAlt = ((aOSEvent.modifiers & optionKey) != 0);
aMouseEvent.isCommand = ((aOSEvent.modifiers & cmdKey) != 0);
aMouseEvent.isMeta = ((aOSEvent.modifiers & cmdKey) != 0);
// nsMouseEvent
aMouseEvent.clickCount = sLastClickCount;

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

@ -372,7 +372,7 @@ PRBool nsTextAreaWidget::DispatchWindowEvent(nsGUIEvent &aEvent)
theModifiers |= controlKey;
if (keyEvent->isAlt)
theModifiers |= optionKey;
if (keyEvent->isCommand)
if (keyEvent->isMeta)
theModifiers |= cmdKey;
}
PrimitiveKeyDown(theChar, theModifiers);

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

@ -16,6 +16,8 @@
* Reserved.
*/
//#define KE_DEBUG
#include "nsWindow.h"
#include "nsIAppShell.h"
#include "nsIFontMetrics.h"
@ -46,6 +48,9 @@
#include "nsNativeDragTarget.h"
#include "nsIRollupListener.h"
// we define the following because there are some MS sample code say
// we should do it. We are not sure we really need it.
#define IME_FROM_ON_CHAR
//~~~ windowless plugin support
#include "nsplugindefs.h"
@ -61,6 +66,7 @@ static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
BOOL nsWindow::sIsRegistered = FALSE;
////////////////////////////////////////////////////
static nsIRollupListener * gRollupListener = nsnull;
static nsIWidget * gRollupWidget = nsnull;
@ -68,7 +74,19 @@ static PRBool gRollupConsumeRollupEvent = PR_FALSE;
nsWindow* nsWindow::gCurrentWindow = nsnull;
#if 0
// #ifdef KE_DEBUG
static PRBool is_vk_down(int vk)
{
SHORT st = GetKeyState(vk);
printf("is_vk_down vk=%x st=%x\n",vk, st);
return (st & 0x80) ? PR_TRUE : PR_FALSE;
}
#define IS_VK_DOWN is_vk_down
#else
#define IS_VK_DOWN(a) (PRBool)(((GetKeyState(a) & 0x80)) ? (PR_TRUE) : (PR_FALSE))
#endif
// Global variable
// g_hinst - handle of the application instance
@ -80,6 +98,46 @@ extern HINSTANCE g_hinst;
#define IME_X_OFFSET 35
#define IME_Y_OFFSET 35
#ifdef IME_FROM_ON_CHAR
static PRBool NS_IsDBCSLeadByte(UINT aCP, BYTE aByte)
{
switch(aCP) {
case 932:
return (((0x81<=aByte)&&(aByte<=0x9F))||((0xE0<=aByte)&&(aByte<=0xFC)));
case 936:
case 949:
case 950:
return ((0x81<=aByte)&&(aByte<=0xFE));
default:
return PR_FALSE;
};
}
#endif // IME_FROM_ON_CHAR
static PRBool LangIDToCP(WORD aLangID, UINT& oCP)
{
int localeid=MAKELCID(aLangID,SORT_DEFAULT);
int numchar=GetLocaleInfo(localeid,LOCALE_IDEFAULTANSICODEPAGE,NULL,0);
char cp_on_stack[32];
char* cp_name;
if(numchar > 32)
cp_name = new char[numchar];
else
cp_name = cp_on_stack;
if (cp_name) {
GetLocaleInfo(localeid,LOCALE_IDEFAULTANSICODEPAGE,cp_name,numchar);
oCP = atoi(cp_name);
if(cp_name != cp_on_stack)
delete [] cp_name;
return PR_TRUE;
} else {
oCP = CP_ACP;
return PR_FALSE;
}
}
//-------------------------------------------------------------------------
//
// nsWindow constructor
@ -133,12 +191,13 @@ nsWindow::nsWindow() : nsBaseWidget()
mIMECompClauseString = NULL;
mIMECompClauseStringSize = 0;
mIMECompClauseStringLength = 0;
mCurrentKeyboardCP = CP_ACP;
WORD kblayout = (WORD)GetKeyboardLayout(0);
LangIDToCP((WORD)(0x0FFFFL & kblayout), mCurrentKeyboardCP);
#if 1
#ifdef IME_FROM_ON_CHAR
mHaveDBCSLeadByte = false;
mDBCSLeadByte = '\0';
#endif
#endif // IME_FROM_ON_CHAR
mNativeDragTarget = nsnull;
mIsTopWidgetWindow = PR_FALSE;
@ -1961,11 +2020,29 @@ PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVir
event.charCode = aCharCode;
event.keyCode = aVirtualCharCode;
//printf("Type: %s charCode %d keyCode %d ", (aEventType == NS_KEY_UP?"Up":"Down"), event.charCode, event.keyCode);
//printf("Shift: %s Control %s Alt: %s \n", (mIsShiftDown?"D":"U"), (mIsControlDown?"D":"U"), (mIsAltDown?"D":"U"));
#ifdef KE_DEBUG
static cnt=0;
printf("%d DispatchKE Type: %s charCode %d keyCode %d ", cnt++,
(NS_KEY_PRESS == aEventType)?"PRESS":(aEventType == NS_KEY_UP?"Up":"Down"),
event.charCode, event.keyCode);
printf("Shift: %s Control %s Alt: %s \n", (mIsShiftDown?"D":"U"), (mIsControlDown?"D":"U"), (mIsAltDown?"D":"U"));
printf("[%c][%c][%c] <== [%c][%c][%c][ space bar ][%c][%c][%c]\n",
IS_VK_DOWN(NS_VK_SHIFT) ? 'S' : ' ',
IS_VK_DOWN(NS_VK_CONTROL) ? 'C' : ' ',
IS_VK_DOWN(NS_VK_ALT) ? 'A' : ' ',
IS_VK_DOWN(VK_LSHIFT) ? 'S' : ' ',
IS_VK_DOWN(VK_LCONTROL) ? 'C' : ' ',
IS_VK_DOWN(VK_LMENU) ? 'A' : ' ',
IS_VK_DOWN(VK_RMENU) ? 'A' : ' ',
IS_VK_DOWN(VK_RCONTROL) ? 'C' : ' ',
IS_VK_DOWN(VK_RSHIFT) ? 'S' : ' '
);
#endif
event.isShift = mIsShiftDown;
event.isControl = mIsControlDown;
event.isMeta = PR_FALSE;
event.isAlt = mIsAltDown;
event.eventStructType = NS_KEY_EVENT;
@ -2061,10 +2138,8 @@ ULONG nsWindow::IsSpecialChar(UINT aVirtualKeyCode, WORD *aAsciiKey)
case VK_F10:
case VK_F11:
case VK_F12:
#if 1
case VK_RETURN:
case VK_BACK:
#endif
*aAsciiKey = aVirtualKeyCode;
break;
@ -2154,7 +2229,11 @@ BOOL TranslateToAscii(BYTE *aKeyState,
//
//
//-------------------------------------------------------------------------
#if 1
#define WM_CHAR_LATER(vk) ( ((vk)<= VK_SPACE) || \
(('0'<=(vk))&&((vk)<='9')) || \
(('A'<=(vk))&&((vk)<='Z')))
#define NO_WM_CHAR_LATER(vk) (! WM_CHAR_LATER(vk))
BOOL nsWindow::OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode)
{
WORD asciiKey;
@ -2169,47 +2248,23 @@ BOOL nsWindow::OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode)
// do the right thing for all SPECIAL_KEY codes
// "SPECIAL_KEY" keys don't generate a WM_CHAR, so don't generate an NS_KEY_PRESS
// this is a special case for the delete key
if (aVirtualKeyCode==VK_DELETE)
if (aVirtualKeyCode==VK_DELETE)
{
DispatchKeyEvent(NS_KEY_PRESS, 0, aVirtualKeyCode);
}
else if (NO_WM_CHAR_LATER(aVirtualKeyCode))
{
DispatchKeyEvent(NS_KEY_PRESS, 0, aVirtualKeyCode);
}
else if (mIsControlDown &&
(( NS_VK_0 <= aVirtualKeyCode)&&( aVirtualKeyCode <= NS_VK_9)))
{
// put the 0 - 9 in charcode instead of keycode.
DispatchKeyEvent(NS_KEY_PRESS, aVirtualKeyCode, 0);
}
return result;
}
#else
BOOL nsWindow::OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode)
{
WORD asciiKey;
asciiKey = 0;
switch (IsSpecialChar(aVirtualKeyCode, &asciiKey)) {
case EXTENDED_KEY:
break;
// special keys don't generate an action but don't even go
// through WM_CHAR
case SPECIAL_KEY:
break;
// standard keys are processed through WM_CHAR
case STANDARD_KEY:
asciiKey = 0; // just to be paranoid
break;
}
//printf("In OnKeyDown ascii %d virt: %d scan: %d\n", asciiKey, aVirtualKeyCode, aScanCode);
// if we enter this if statement we expect not to get a WM_CHAR
if (asciiKey) {
//printf("Dispatching Key Down [%d]\n", asciiKey);
return DispatchKeyEvent(NS_KEY_DOWN, asciiKey, aVirtualKeyCode);
}
// always let the def proc process a WM_KEYDOWN
return FALSE;
}
#endif
//-------------------------------------------------------------------------
//
@ -2250,52 +2305,48 @@ BOOL nsWindow::OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode)
//
//
//-------------------------------------------------------------------------
#if 1
BOOL nsWindow::OnChar( UINT mbcsCharCode, UINT virtualKeyCode, bool isMultiByte )
{
wchar_t uniChar;
char charToConvert[2];
size_t length;
#ifdef IME_FROM_ON_CHAR
if (isMultiByte) {
charToConvert[0]=HIBYTE(mbcsCharCode);
charToConvert[1] = LOBYTE(mbcsCharCode);
length=2;
} else {
}
else
#endif
{
charToConvert[0] = LOBYTE(mbcsCharCode);
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", virtualKeyCode);
::MultiByteToWideChar(mCurrentKeyboardCP,MB_PRECOMPOSED,charToConvert,length,
&uniChar,sizeof(uniChar));
if(mIsControlDown && (virtualKeyCode <= 0x1A)) // Ctrl+A Ctrl+Z, see Programming Windows 3.1 page 110 for details
{
uniChar = virtualKeyCode - 1 + NS_VK_A ;
virtualKeyCode = 0;
}
else
if(virtualKeyCode < 0x20)
{
uniChar = 0;
}
else
{
::MultiByteToWideChar(mCurrentKeyboardCP,MB_PRECOMPOSED,charToConvert,length,
&uniChar,sizeof(uniChar));
virtualKeyCode = 0;
mIsShiftDown = PR_FALSE;
}
return DispatchKeyEvent(NS_KEY_PRESS, uniChar, virtualKeyCode);
//return FALSE;
}
#else
BOOL nsWindow::OnChar( UINT aVirtualKeyCode )
{
// 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);
return DispatchKeyEvent(NS_KEY_DOWN, aVirtualKeyCode, aVirtualKeyCode);
//return FALSE;
}
#endif
//-------------------------------------------------------------------------
@ -2399,86 +2450,98 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
case WM_PAINT:
result = OnPaint();
break;
#if 1
case WM_SYSCHAR:
case WM_CHAR:
{
unsigned char ch = (unsigned char)wParam;
UINT char_result;
//
// check first for backspace or return, handle them specially
//
if (ch==0x0d || ch==0x08) {
mHaveDBCSLeadByte = PR_FALSE;
result = OnChar(ch,ch==0x0d ? VK_RETURN : VK_BACK,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,ch,true);
} else {
char_result = ch;
result = OnChar(char_result,ch,false);
}
break;
}
#else
case WM_SYSCHAR:
case WM_CHAR:
case WM_SYSCHAR:
case WM_CHAR:
{
#ifdef KE_DEBUG
printf("%s\tchar=%c\twp=%4x\tlp=%8x\n", (msg == WM_SYSCHAR) ? "WM_SYSCHAR" : "WM_CHAR" , ch, wParam, lParam);
#endif
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
// Process non-standard Control Keys
// I am unclear whether I should process these like this (rods)
if (mIsControlDown && !mIsAltDown &&
(wParam >= 0x01 && wParam <= 0x1A)) { // a-z
wParam += 0x40; // 64 decimal
} else if (!mIsControlDown && mIsAltDown &&
(wParam >= 0x61 && wParam <= 0x7A)) { // a-z
wParam -= 0x20; // 32 decimal
if(WM_SYSCHAR==msg)
{
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
} else { // WM_KEYUP
// If the Context Code bit is down and we got a WM_KEY
// it is a key press for character, not accelerator
// see p246 of Programming Windows 95 [Charles Petzold] for details
mIsControlDown = (0 == (KF_ALTDOWN & HIWORD(lParam)))&& IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = (0 == (KF_ALTDOWN & HIWORD(lParam)))&& IS_VK_DOWN(NS_VK_ALT);
}
if (!mIMEIsComposing)
result = OnChar(wParam);
else
result = PR_FALSE;
break;
#endif
unsigned char ch = (unsigned char)wParam;
UINT char_result;
//
// check first for backspace or return, handle them specially
//
if (ch==0x0d || ch==0x08) {
#ifdef IME_FROM_ON_CHAR
mHaveDBCSLeadByte = PR_FALSE;
#endif // IME_FROM_ON_CHAR
result = OnChar(ch,ch==0x0d ? VK_RETURN : VK_BACK,true);
break;
}
#ifdef IME_FROM_ON_CHAR
//
// 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 (NS_IsDBCSLeadByte(mCurrentKeyboardCP, 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,ch,true);
}
else
#endif // IME_FROM_ON_CHAR
{
char_result = ch;
result = OnChar(char_result,ch,false);
}
break;
}
// 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...
if (IsKeypadKey(wParam, lParam & 0x01000000)) {
result = PR_TRUE;
break;
result = PR_TRUE;
break;
}
case WM_KEYUP:
#ifdef KE_DEBUG
printf("%s\t\twp=%x\tlp=%x\n",
(WM_KEYUP==msg)?"WM_KEYUP":"WM_SYSKEYUP" , wParam, lParam);
#endif
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
if(WM_SYSKEYUP==msg)
{
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
} else { // WM_KEYUP
// If the Context Code bit is down and we got a WM_KEY
// it is a key press for character, not accelerator
// see p246 of Programming Windows 95 [Charles Petzold] for details
mIsControlDown = (0 == (KF_ALTDOWN & HIWORD(lParam)))&& IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = (0 == (KF_ALTDOWN & HIWORD(lParam)))&& IS_VK_DOWN(NS_VK_ALT);
}
if (!mIMEIsComposing)
if (!mIMEIsComposing)
result = OnKeyUp(wParam, (HIWORD(lParam) & 0xFF));
else
result = PR_FALSE;
@ -2504,14 +2567,27 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
break;
}
case WM_KEYDOWN: {
#ifdef KE_DEBUG
printf("%s\t\twp=%4x\tlp=%8x\n",
(WM_KEYDOWN==msg)?"WM_KEYDOWN":"WM_SYSKEYDOWN" , wParam, lParam);
#endif
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
if (!mIMEIsComposing)
result = OnKeyDown(wParam, (HIWORD(lParam) & 0xFF));
else
result = PR_FALSE;
if(WM_SYSKEYDOWN==msg)
{
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
} else { // WM_KEYUP
// If the Context Code bit is down and we got a WM_KEY
// If the Context Code bit is down and we got a WM_KEY
// it is a key press for character, not accelerator
// see p246 of Programming Windows 95 [Charles Petzold] for details
mIsControlDown = (0 == (KF_ALTDOWN & HIWORD(lParam)))&& IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = (0 == (KF_ALTDOWN & HIWORD(lParam)))&& IS_VK_DOWN(NS_VK_ALT);
}
if (!mIMEIsComposing)
result = OnKeyDown(wParam, (HIWORD(lParam) & 0xFF));
else
result = PR_FALSE;
}
break;
@ -2773,18 +2849,12 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
printf("input language changed\n");
#endif
int langid =(int)(lParam&0xFFFF);
int localeid=MAKELCID(langid,SORT_DEFAULT);
int numchar=GetLocaleInfo(localeid,LOCALE_IDEFAULTANSICODEPAGE,NULL,0);
char* cp_name = new char[numchar];
if (cp_name) {
GetLocaleInfo(localeid,LOCALE_IDEFAULTANSICODEPAGE,cp_name,numchar);
mCurrentKeyboardCP = atoi(cp_name);
delete [] cp_name;
*aRetValue=TRUE;
result = PR_TRUE;
}
result = PR_FALSE; // always pass to child window
*aRetValue = LangIDToCP((WORD)(lParam&0x0FFFF),mCurrentKeyboardCP);
#ifdef IME_FROM_ON_CHAR
mHaveDBCSLeadByte=PR_FALSE; // reset this when we change keyboard layout
#endif
break;
}
case WM_IME_STARTCOMPOSITION: {
@ -3248,6 +3318,7 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint)
event.isShift = IS_VK_DOWN(NS_VK_SHIFT);
event.isControl = IS_VK_DOWN(NS_VK_CONTROL);
event.isMeta = PR_FALSE;
event.isAlt = IS_VK_DOWN(NS_VK_ALT);
event.eventStructType = NS_MOUSE_EVENT;
@ -3679,6 +3750,7 @@ nsWindow::HandleTextEvent(HIMC hIMEContext)
event.theText = mIMECompositionUniString;
event.isShift = mIsShiftDown;
event.isControl = mIsControlDown;
event.isMeta = PR_FALSE;
event.isAlt = mIsAltDown;
event.eventStructType = NS_TEXT_EVENT;

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

@ -168,11 +168,7 @@ protected:
virtual PRBool OnPaint();
virtual PRBool OnResize(nsRect &aWindowRect);
#if 1
BOOL OnChar(UINT mbcsCharCode, UINT virtualKeyCode, bool isMultibyte);
#else
BOOL OnChar(UINT aVirtualKeyCode);
#endif
BOOL OnKeyDown( UINT aVirtualKeyCode, UINT aScanCode);
BOOL OnKeyUp( UINT aVirtualKeyCode, UINT aScanCode);
@ -254,10 +250,8 @@ protected:
PRBool mIsInMouseCapture;
#if 1
BOOL mHaveDBCSLeadByte;
unsigned char mDBCSLeadByte;
#endif
// Drag & Drop
nsNativeDragTarget * mNativeDragTarget;

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

@ -136,7 +136,7 @@ nsresult nsKeyBindMgr::ProcessKeyEvent(
do {
// Test Command attribute
#ifdef XP_MAC
if (theEvent.isCommand && (modCommand != "true"))
if (theEvent.isMeta && (modCommand != "true"))
break;
#else
if (theEvent.isControl && (modCommand != "true"))