Added support for basic Japanese input on Win32

This commit is contained in:
tague%netscape.com 1999-03-19 23:36:20 +00:00
parent 0aa9780658
commit 6e19645586
32 changed files with 829 additions and 41 deletions

View File

@ -35,7 +35,7 @@ static char* mEventNames[] = {
"onmousedown", "onmouseup", "onclick", "ondblclick", "onmouseover",
"onmouseout", "onmousemove", "onkeydown", "onkeyup", "onkeypress",
"onfocus", "onblur", "onload", "onunload", "onabort", "onerror",
"onsubmit", "onreset", "onchange", "onpaint"
"onsubmit", "onreset", "onchange", "onpaint" ,"text"
};
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
@ -43,12 +43,21 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
NS_ADDREF(mPresContext);
mEvent = aEvent;
mTarget = nsnull;
mText = nsnull;
if (aEvent->eventStructType ==NS_TEXT_EVENT) {
mText = new nsString(((nsTextEvent*)aEvent)->theText);
mCommitText = ((nsTextEvent*)aEvent)->commitText;
}
NS_INIT_REFCNT();
}
nsDOMEvent::~nsDOMEvent() {
NS_RELEASE(mPresContext);
NS_IF_RELEASE(mTarget);
delete mText;
}
NS_IMPL_ADDREF(nsDOMEvent)
@ -92,6 +101,30 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType)
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetText(nsString& aText)
{
if (mEvent->message == NS_TEXT_EVENT) {
aText = *mText;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetCommitText(PRBool* aCommitText)
{
if (mEvent->message == NS_TEXT_EVENT) {
*aCommitText = mCommitText;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::SetCommitText(PRBool aCommitText)
{
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::SetType(const nsString& aType)
{
return NS_ERROR_NOT_IMPLEMENTED;
@ -429,6 +462,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return mEventNames[eDOMEvents_change];
case NS_PAINT:
return mEventNames[eDOMEvents_paint];
case NS_TEXT_EVENT:
return mEventNames[eDOMEvents_text];
default:
break;
}

View File

@ -59,7 +59,8 @@ public:
eDOMEvents_submit,
eDOMEvents_reset,
eDOMEvents_change,
eDOMEvents_paint
eDOMEvents_paint,
eDOMEvents_text
};
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent);
@ -71,6 +72,11 @@ public:
NS_IMETHOD GetType(nsString& aType);
NS_IMETHOD SetType(const nsString& aType);
NS_IMETHOD GetText(nsString& aText);
NS_IMETHOD GetCommitText(PRBool* aCommitText);
NS_IMETHOD SetCommitText(PRBool aCommitText);
NS_IMETHOD GetTarget(nsIDOMNode** aTarget);
NS_IMETHOD SetTarget(nsIDOMNode* aTarget);
@ -136,7 +142,8 @@ protected:
nsEvent* mEvent;
nsIPresContext* mPresContext;
nsIDOMNode* mTarget;
nsString* mText;
PRBool mCommitText;
const char* GetEventName(PRUint32 aEventType);
};

View File

@ -24,6 +24,7 @@
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
#include "nsIDOMPaintListener.h"
#include "nsIDOMTextListener.h"
NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
@ -33,3 +34,4 @@ NS_DEFINE_IID(kIDOMFormListenerIID, NS_IDOMFORMLISTENER_IID);
NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
NS_DEFINE_IID(kIDOMPaintListenerIID, NS_IDOMPAINTLISTENER_IID);
NS_DEFINE_IID(kIDOMTextListenerIID,NS_IDOMTEXTLISTENER_IID);

View File

@ -28,5 +28,6 @@ extern const nsIID kIDOMFormListenerIID;
extern const nsIID kIDOMLoadListenerIID;
extern const nsIID kIDOMDragListenerIID;
extern const nsIID kIDOMPaintListenerIID;
extern const nsIID kIDOMTextListenerIID;
#endif /* nsDOMEVENTSIIDs_h___ */

View File

@ -30,6 +30,7 @@
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
#include "nsIDOMPaintListener.h"
#include "nsIDOMTextListener.h"
#include "nsIEventStateManager.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIScriptObjectOwner.h"
@ -52,6 +53,7 @@ nsEventListenerManager::nsEventListenerManager()
mFormListeners = nsnull;
mDragListeners = nsnull;
mPaintListeners = nsnull;
mTextListeners = nsnull;
NS_INIT_REFCNT();
}
@ -66,6 +68,7 @@ nsEventListenerManager::~nsEventListenerManager()
ReleaseListeners(mFormListeners);
ReleaseListeners(mDragListeners);
ReleaseListeners(mPaintListeners);
ReleaseListeners(mTextListeners);
}
NS_IMPL_ADDREF(nsEventListenerManager)
@ -112,6 +115,9 @@ nsVoidArray** nsEventListenerManager::GetListenersByIID(const nsIID& aIID)
else if (aIID.Equals(kIDOMPaintListenerIID)) {
return &mPaintListeners;
}
else if (aIID.Equals(kIDOMTextListenerIID)) {
return &mTextListeners;
}
return nsnull;
}
@ -143,7 +149,6 @@ nsresult nsEventListenerManager::GetEventListeners(nsVoidArray **aListeners, con
* Sets events listeners of all types.
* @param an event listener
*/
nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
{
nsVoidArray** mListeners = GetListenersByIID(aIID);
@ -162,7 +167,6 @@ nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener
return NS_OK;
}
const char *mEventArgv[] = {"event"};
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID)
@ -355,7 +359,35 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
}
}
break;
case NS_TEXT_EVENT:
#if DEBUG_TAGUE
printf("DOM: got text event\n");
#endif
if (nsnull != mTextListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMEvent(aDOMEvent,aPresContext,aEvent);
}
if (NS_OK == ret) {
for (int i=0; i<mTextListeners->Count(); i++) {
nsIDOMEventListener *mEventListener;
nsIDOMTextListener *mTextListener;
mEventListener = (nsIDOMEventListener*)mTextListeners->ElementAt(i);
if (NS_OK == mEventListener->QueryInterface(kIDOMTextListenerIID, (void**)&mTextListener)) {
ret = mTextListener->HandleText(*aDOMEvent);
NS_RELEASE(mTextListener);
}
else {
ret = mEventListener->ProcessEvent(*aDOMEvent);
}
}
aEventStatus = (NS_OK == ret) ? aEventStatus : nsEventStatus_eConsumeNoDefault;
}
}
break;
case NS_KEY_UP:
case NS_KEY_DOWN:
case NS_KEY_PRESS:

View File

@ -88,6 +88,7 @@ protected:
nsVoidArray* mFormListeners;
nsVoidArray* mDragListeners;
nsVoidArray* mPaintListeners;
nsVoidArray* mTextListeners;
};

View File

@ -34,6 +34,7 @@ EXPORTS = \
nsIDOMPaintListener.h \
nsIDOMDragListener.h \
nsIDOMNSEvent.h \
nsIDOMTextListener.h \
$(NULL)
MODULE=dom

View File

@ -150,6 +150,11 @@ public:
NS_IMETHOD GetType(nsString& aType)=0;
NS_IMETHOD SetType(const nsString& aType)=0;
NS_IMETHOD GetText(nsString& aText)=0;
NS_IMETHOD GetCommitText(PRBool* aCommitText)=0;
NS_IMETHOD SetCommitText(PRBool aCommitText)=0;
NS_IMETHOD GetTarget(nsIDOMNode** aTarget)=0;
NS_IMETHOD SetTarget(nsIDOMNode* aTarget)=0;
@ -194,6 +199,9 @@ public:
#define NS_DECL_IDOMEVENT \
NS_IMETHOD GetType(nsString& aType); \
NS_IMETHOD SetType(const nsString& aType); \
NS_IMETHOD GetText(nsString& aText); \
NS_IMETHOD GetCommitText(PRBool* aCommitText); \
NS_IMETHOD SetCommitText(PRBool aCommitText); \
NS_IMETHOD GetTarget(nsIDOMNode** aTarget); \
NS_IMETHOD SetTarget(nsIDOMNode* aTarget); \
NS_IMETHOD GetScreenX(PRInt32* aScreenX); \
@ -226,6 +234,9 @@ public:
#define NS_FORWARD_IDOMEVENT(_to) \
NS_IMETHOD GetType(nsString& aType) { return _to##GetType(aType); } \
NS_IMETHOD SetType(const nsString& aType) { return _to##SetType(aType); } \
NS_IMETHOD GetText(nsString& aText) { return _to##GetText(aText); } \
NS_IMETHOD GetCommitText(PRBool* aCommitText) { return _to##GetCommitText(aCommitText); } \
NS_IMETHOD SetCommitText(PRBool aCommitText) { return _to##SetCommitText(aCommitText); } \
NS_IMETHOD GetTarget(nsIDOMNode** aTarget) { return _to##GetTarget(aTarget); } \
NS_IMETHOD SetTarget(nsIDOMNode* aTarget) { return _to##SetTarget(aTarget); } \
NS_IMETHOD GetScreenX(PRInt32* aScreenX) { return _to##GetScreenX(aScreenX); } \

View File

@ -64,6 +64,7 @@ public:
EVENT_FORWARD = 134217728,
EVENT_HELP = 268435456,
EVENT_BACK = 536870912,
EVENT_TEXT = 1073741824,
EVENT_ALT_MASK = 1,
EVENT_CONTROL_MASK = 2,
EVENT_SHIFT_MASK = 4,

View File

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIDOMTextListener_h__
#define nsIDOMTextListener_h__
#include "nsIDOMEvent.h"
#include "nsIDOMEventListener.h"
/*
* Key pressed / released / typed listener interface.
*/
// {C6296E81-D823-11d2-9E7F-0060089FE59B}
#define NS_IDOMTEXTLISTENER_IID \
{ 0xc6296e81, 0xd823, 0x11d2, { 0x9e, 0x7f, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
class nsIDOMTextListener : public nsIDOMEventListener {
public:
virtual nsresult HandleText(nsIDOMEvent* aTextEvent) = 0;
};
#endif // nsIDOMTextListener_h__

View File

@ -123,6 +123,8 @@
const int VK_QUOTE = 0xDE;
attribute wstring type;
readonly attribute wstring text;
attribute boolean commitText;
attribute Node target;
attribute int screenX;
@ -177,6 +179,7 @@
const int EVENT_FORWARD = 0x08000000;
const int EVENT_HELP = 0x10000000;
const int EVENT_BACK = 0x20000000;
const int EVENT_TEXT = 0x40000000;
const int EVENT_ALT_MASK = 0x00000001;
const int EVENT_CONTROL_MASK = 0x00000002;

View File

@ -50,25 +50,27 @@ NS_DEF_PTR(nsIDOMRenderingContext);
//
enum Event_slots {
EVENT_TYPE = -1,
EVENT_TARGET = -2,
EVENT_SCREENX = -3,
EVENT_SCREENY = -4,
EVENT_CLIENTX = -5,
EVENT_CLIENTY = -6,
EVENT_ALTKEY = -7,
EVENT_CTRLKEY = -8,
EVENT_SHIFTKEY = -9,
EVENT_METAKEY = -10,
EVENT_CANCELBUBBLE = -11,
EVENT_CHARCODE = -12,
EVENT_KEYCODE = -13,
EVENT_BUTTON = -14,
NSEVENT_LAYERX = -15,
NSEVENT_LAYERY = -16,
NSEVENT_PAGEX = -17,
NSEVENT_PAGEY = -18,
NSEVENT_WHICH = -19,
NSEVENT_RC = -20
EVENT_TEXT = -2,
EVENT_COMMITTEXT = -3,
EVENT_TARGET = -4,
EVENT_SCREENX = -5,
EVENT_SCREENY = -6,
EVENT_CLIENTX = -7,
EVENT_CLIENTY = -8,
EVENT_ALTKEY = -9,
EVENT_CTRLKEY = -10,
EVENT_SHIFTKEY = -11,
EVENT_METAKEY = -12,
EVENT_CANCELBUBBLE = -13,
EVENT_CHARCODE = -14,
EVENT_KEYCODE = -15,
EVENT_BUTTON = -16,
NSEVENT_LAYERX = -17,
NSEVENT_LAYERY = -18,
NSEVENT_PAGEX = -19,
NSEVENT_PAGEY = -20,
NSEVENT_WHICH = -21,
NSEVENT_RC = -22
};
/***********************************************************************/
@ -98,6 +100,28 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case EVENT_TEXT:
{
nsAutoString prop;
if (NS_OK == a->GetText(prop)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return JS_FALSE;
}
break;
}
case EVENT_COMMITTEXT:
{
PRBool prop;
if (NS_OK == a->GetCommitText(&prop)) {
*vp = BOOLEAN_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case EVENT_TARGET:
{
nsIDOMNode* prop;
@ -399,6 +423,17 @@ SetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
break;
}
case EVENT_COMMITTEXT:
{
PRBool prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToBool(&prop, cx, *vp)) {
return JS_FALSE;
}
a->SetCommitText(prop);
break;
}
case EVENT_TARGET:
{
nsIDOMNode* prop;
@ -770,6 +805,8 @@ JSClass EventClass = {
static JSPropertySpec EventProperties[] =
{
{"type", EVENT_TYPE, JSPROP_ENUMERATE},
{"text", EVENT_TEXT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"commitText", EVENT_COMMITTEXT, JSPROP_ENUMERATE},
{"target", EVENT_TARGET, JSPROP_ENUMERATE},
{"screenX", EVENT_SCREENX, JSPROP_ENUMERATE},
{"screenY", EVENT_SCREENY, JSPROP_ENUMERATE},

View File

@ -41,7 +41,7 @@ NS_IMPL_ADDREF(nsTextEditorKeyListener)
NS_IMPL_RELEASE(nsTextEditorKeyListener)
nsTextEditorKeyListener::nsTextEditorKeyListener()
nsTextEditorKeyListener::nsTextEditorKeyListener()
{
NS_INIT_REFCNT();
}
@ -513,6 +513,33 @@ nsTextEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
/*
* nsTextEditorMouseListener implementation
*/
NS_IMPL_ADDREF(nsTextEditorTextListener)
NS_IMPL_RELEASE(nsTextEditorTextListener)
nsTextEditorTextListener::nsTextEditorTextListener()
: mCommitText(PR_FALSE),
mInTransaction(PR_FALSE)
{
NS_INIT_REFCNT();
}
nsTextEditorTextListener::~nsTextEditorTextListener()
{
}
/*
* nsTextEditorDragListener implementation
*/
@ -537,6 +564,77 @@ nsTextEditorDragListener::~nsTextEditorDragListener()
nsresult
nsTextEditorTextListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kIDOMTextListenerIID, NS_IDOMTEXTLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventListenerIID)) {
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMTextListenerIID)) {
*aInstancePtr = (void*)(nsIDOMTextListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
nsTextEditorTextListener::ProcessEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult
nsTextEditorTextListener::HandleText(nsIDOMEvent* aTextEvent)
{
nsString composedText;
const PRUnichar* composedTextAsChar;
PRBool commitText;
nsresult result;
aTextEvent->GetText(composedText);
composedTextAsChar = (const PRUnichar*)(&composedText);
if (!mInTransaction) {
// mEditor->BeginTransaction();
mInTransaction = PR_TRUE;
}
aTextEvent->GetCommitText(&commitText);
if (commitText) {
mEditor->Undo(1);
result = mEditor->InsertText(composedText);
// result = mEditor->EndTransaction();
mInTransaction=PR_FALSE;
mCommitText = PR_TRUE;
} else {
if (!mCommitText) {
mEditor->Undo(1);
} else {
mCommitText = PR_FALSE;
}
result = mEditor->InsertText(composedText);
}
return result;
}
nsresult
nsTextEditorDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
@ -632,6 +730,21 @@ NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult,
}
nsresult
NS_NewEditorTextListener(nsIDOMEventListener** aInstancePtrResult, nsITextEditor* aEditor)
{
nsTextEditorTextListener* it = new nsTextEditorTextListener();
if (nsnull==it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetEditor(aEditor);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
}
nsresult
NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult,
@ -650,3 +763,4 @@ NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult,
}

View File

@ -22,6 +22,7 @@
#include "nsIDOMEvent.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMTextListener.h"
#include "nsIDOMDragListener.h"
#include "nsITextEditor.h"
#include "nsCOMPtr.h"
@ -67,6 +68,39 @@ protected:
/** editor Implementation of the MouseListener interface
*/
class nsTextEditorTextListener : public nsIDOMTextListener
{
public:
/** default constructor
*/
nsTextEditorTextListener();
/** default destructor
*/
virtual ~nsTextEditorTextListener();
/** SetEditor gives an address to the editor that will be accessed
* @param aEditor the editor this listener calls for editing operations
*/
void SetEditor(nsITextEditor *aEditor){mEditor = do_QueryInterface(aEditor);}
/*interfaces for addref and release and queryinterface*/
NS_DECL_ISUPPORTS
/*BEGIN implementations of textevent handler interface*/
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
public:
virtual nsresult HandleText(nsIDOMEvent* aTextEvent);
/*END implementations of textevent handler interface*/
protected:
nsCOMPtr<nsITextEditor> mEditor;
PRBool mCommitText;
PRBool mInTransaction;
};
/** editor Implementation of the TextListener interface
*/
class nsTextEditorMouseListener : public nsIDOMMouseListener
{
public:
@ -101,6 +135,7 @@ protected:
};
/** editor Implementation of the MouseListener interface
*/
class nsTextEditorDragListener : public nsIDOMDragListener
@ -133,6 +168,7 @@ protected:
};
/** factory for the editor key listener
*/
extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
@ -141,6 +177,10 @@ extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResul
*/
extern nsresult NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
/** factory for the editor text listener
*/
extern nsresult NS_NewEditorTextListener(nsIDOMEventListener** aInstancePtrResult, nsITextEditor *aEditor);
/** factory for the editor drag listener
*/
extern nsresult NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);

View File

@ -40,6 +40,7 @@
#include "nsIDOMRange.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMTextListener.h"
#include "nsEditorCID.h"
#include "nsISupportsArray.h"
#include "nsIEnumerator.h"
@ -79,6 +80,7 @@ class nsIFrame;
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMTextListenerIID, NS_IDOMTEXTLISTENER_IID);
static NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
static NS_DEFINE_IID(kIEditPropertyIID, NS_IEDITPROPERTY_IID);
@ -116,9 +118,15 @@ nsTextEditor::~nsTextEditor()
if (mMouseListenerP) {
erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID);
}
if (mTextListenerP) {
erP->RemoveEventListener(mTextListenerP, kIDOMTextListenerIID);
}
if (mDragListenerP) {
erP->RemoveEventListener(mDragListenerP, kIDOMDragListenerIID);
}
}
else
NS_NOTREACHED("~nsTextEditor");
@ -178,9 +186,23 @@ NS_IMETHODIMP nsTextEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
return result;
}
result = NS_NewEditorTextListener(getter_AddRefs(mTextListenerP),this);
if (NS_OK !=result) {
// drop the key and mouse listeners
#ifdef DEBUG_TAGUE
printf("nsTextEditor.cpp: failed to get TextEvent Listener\n");
#endif
mMouseListenerP = do_QueryInterface(0);
mKeyListenerP = do_QueryInterface(0);
return result;
}
result = NS_NewEditorDragListener(getter_AddRefs(mDragListenerP), this);
if (NS_OK != result) {
//return result;
mMouseListenerP = do_QueryInterface(0);
mKeyListenerP = do_QueryInterface(0);
mTextListenerP = do_QueryInterface(0);
}
nsCOMPtr<nsIDOMEventReceiver> erP;
@ -189,6 +211,7 @@ NS_IMETHODIMP nsTextEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
{
mKeyListenerP = do_QueryInterface(0);
mMouseListenerP = do_QueryInterface(0); //dont need these if we cant register them
mTextListenerP = do_QueryInterface(0);
mDragListenerP = do_QueryInterface(0); //dont need these if we cant register them
return result;
}
@ -196,6 +219,8 @@ NS_IMETHODIMP nsTextEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
erP->AddEventListener(mKeyListenerP, kIDOMKeyListenerIID);
//erP->AddEventListener(mDragListenerP, kIDOMDragListenerIID);
//erP->AddEventListener(mMouseListenerP, kIDOMMouseListenerIID);
erP->AddEventListener(mTextListenerP,kIDOMTextListenerIID);
// instantiate the rules for this text editor
// XXX: we should be told which set of rules to instantiate

View File

@ -124,6 +124,7 @@ protected:
nsTextEditRules* mRules;
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
nsCOMPtr<nsIDOMEventListener> mTextListenerP;
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
};

View File

@ -41,7 +41,7 @@ NS_IMPL_ADDREF(nsTextEditorKeyListener)
NS_IMPL_RELEASE(nsTextEditorKeyListener)
nsTextEditorKeyListener::nsTextEditorKeyListener()
nsTextEditorKeyListener::nsTextEditorKeyListener()
{
NS_INIT_REFCNT();
}
@ -513,6 +513,33 @@ nsTextEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
/*
* nsTextEditorMouseListener implementation
*/
NS_IMPL_ADDREF(nsTextEditorTextListener)
NS_IMPL_RELEASE(nsTextEditorTextListener)
nsTextEditorTextListener::nsTextEditorTextListener()
: mCommitText(PR_FALSE),
mInTransaction(PR_FALSE)
{
NS_INIT_REFCNT();
}
nsTextEditorTextListener::~nsTextEditorTextListener()
{
}
/*
* nsTextEditorDragListener implementation
*/
@ -537,6 +564,77 @@ nsTextEditorDragListener::~nsTextEditorDragListener()
nsresult
nsTextEditorTextListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kIDOMTextListenerIID, NS_IDOMTEXTLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventListenerIID)) {
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMTextListenerIID)) {
*aInstancePtr = (void*)(nsIDOMTextListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
nsTextEditorTextListener::ProcessEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult
nsTextEditorTextListener::HandleText(nsIDOMEvent* aTextEvent)
{
nsString composedText;
const PRUnichar* composedTextAsChar;
PRBool commitText;
nsresult result;
aTextEvent->GetText(composedText);
composedTextAsChar = (const PRUnichar*)(&composedText);
if (!mInTransaction) {
// mEditor->BeginTransaction();
mInTransaction = PR_TRUE;
}
aTextEvent->GetCommitText(&commitText);
if (commitText) {
mEditor->Undo(1);
result = mEditor->InsertText(composedText);
// result = mEditor->EndTransaction();
mInTransaction=PR_FALSE;
mCommitText = PR_TRUE;
} else {
if (!mCommitText) {
mEditor->Undo(1);
} else {
mCommitText = PR_FALSE;
}
result = mEditor->InsertText(composedText);
}
return result;
}
nsresult
nsTextEditorDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
@ -632,6 +730,21 @@ NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult,
}
nsresult
NS_NewEditorTextListener(nsIDOMEventListener** aInstancePtrResult, nsITextEditor* aEditor)
{
nsTextEditorTextListener* it = new nsTextEditorTextListener();
if (nsnull==it) {
return NS_ERROR_OUT_OF_MEMORY;
}
it->SetEditor(aEditor);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
return it->QueryInterface(kIDOMEventListenerIID, (void **) aInstancePtrResult);
}
nsresult
NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult,
@ -650,3 +763,4 @@ NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult,
}

View File

@ -22,6 +22,7 @@
#include "nsIDOMEvent.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMTextListener.h"
#include "nsIDOMDragListener.h"
#include "nsITextEditor.h"
#include "nsCOMPtr.h"
@ -67,6 +68,39 @@ protected:
/** editor Implementation of the MouseListener interface
*/
class nsTextEditorTextListener : public nsIDOMTextListener
{
public:
/** default constructor
*/
nsTextEditorTextListener();
/** default destructor
*/
virtual ~nsTextEditorTextListener();
/** SetEditor gives an address to the editor that will be accessed
* @param aEditor the editor this listener calls for editing operations
*/
void SetEditor(nsITextEditor *aEditor){mEditor = do_QueryInterface(aEditor);}
/*interfaces for addref and release and queryinterface*/
NS_DECL_ISUPPORTS
/*BEGIN implementations of textevent handler interface*/
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
public:
virtual nsresult HandleText(nsIDOMEvent* aTextEvent);
/*END implementations of textevent handler interface*/
protected:
nsCOMPtr<nsITextEditor> mEditor;
PRBool mCommitText;
PRBool mInTransaction;
};
/** editor Implementation of the TextListener interface
*/
class nsTextEditorMouseListener : public nsIDOMMouseListener
{
public:
@ -101,6 +135,7 @@ protected:
};
/** editor Implementation of the MouseListener interface
*/
class nsTextEditorDragListener : public nsIDOMDragListener
@ -133,6 +168,7 @@ protected:
};
/** factory for the editor key listener
*/
extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
@ -141,6 +177,10 @@ extern nsresult NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResul
*/
extern nsresult NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);
/** factory for the editor text listener
*/
extern nsresult NS_NewEditorTextListener(nsIDOMEventListener** aInstancePtrResult, nsITextEditor *aEditor);
/** factory for the editor drag listener
*/
extern nsresult NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult, nsITextEditor *aEditor);

View File

@ -59,6 +59,15 @@ class nsIFrameSelection : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IFRAMESELECTION_IID; return iid; }
/** HandleKeyEvent will accept an event and frame and
* will return NS_OK if it handles the event or NS_COMFALSE if not.
* <P>DOES NOT ADDREF<P>
* @param tracker to ask where the current focus is and to set the new anchor ect.
* @param aGuiEvent is the event that should be dealt with by aFocusFrame
* @param aFrame is the frame that MAY handle the event
*/
NS_IMETHOD HandleTextEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent) = 0;
/** HandleKeyEvent will accept an event and frame and
* will return NS_OK if it handles the event or NS_COMFALSE if not.
* <P>DOES NOT ADDREF<P>

View File

@ -59,6 +59,15 @@ class nsIFrameSelection : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IFRAMESELECTION_IID; return iid; }
/** HandleKeyEvent will accept an event and frame and
* will return NS_OK if it handles the event or NS_COMFALSE if not.
* <P>DOES NOT ADDREF<P>
* @param tracker to ask where the current focus is and to set the new anchor ect.
* @param aGuiEvent is the event that should be dealt with by aFocusFrame
* @param aFrame is the frame that MAY handle the event
*/
NS_IMETHOD HandleTextEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent) = 0;
/** HandleKeyEvent will accept an event and frame and
* will return NS_OK if it handles the event or NS_COMFALSE if not.
* <P>DOES NOT ADDREF<P>

View File

@ -73,6 +73,7 @@ public:
NS_DECL_ISUPPORTS
/*BEGIN nsIFrameSelection interfaces*/
NS_IMETHOD HandleTextEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGUIEvent);
NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent);
NS_IMETHOD TakeFocus(nsIFocusTracker *aTracker, nsIFrame *aFrame, PRInt32 aOffset, PRInt32 aContentOffset, PRBool aContinueSelection);
NS_IMETHOD ResetSelection(nsIFocusTracker *aTracker, nsIFrame *aStartFrame);
@ -539,6 +540,42 @@ void printRange(nsIDOMRange *aDomRange)
*/
}
NS_IMETHODIMP
nsRangeList::HandleTextEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGUIEvent)
{
if (!aGUIEvent || !aTracker)
return NS_ERROR_NULL_POINTER;
#ifdef DEBUG_TAGUE
printf("nsRangeList: HandleTextEvent\n");
#endif
nsIFrame *anchor;
nsIFrame *frame;
nsresult result = aTracker->GetFocus(&frame, &anchor);
if (NS_FAILED(result))
return result;
if (NS_TEXT_EVENT == aGUIEvent->message) {
PRBool selected;
PRInt32 beginoffset = 0;
PRInt32 endoffset;
PRInt32 contentoffset;
nsresult result = NS_OK;
nsTextEvent *textEvent = (nsTextEvent *)aGUIEvent; //this is ok. It really is a textevent
nsIFrame *resultFrame;
PRInt32 frameOffset;
PRInt32 contentOffset;
PRInt32 offsetused = beginoffset;
nsIFrame *frameused;
nsSelectionAmount amount = eSelectCharacter; // for now
result = frame->GetSelected(&selected,&beginoffset,&endoffset, &contentoffset);
result = ScrollIntoView(aTracker);
}
return NS_OK;
}
/** This raises a question, if this method is called and the aFrame does not reflect the current
* focus DomNode, it is invalid? The answer now is yes.

View File

@ -35,7 +35,7 @@ static char* mEventNames[] = {
"onmousedown", "onmouseup", "onclick", "ondblclick", "onmouseover",
"onmouseout", "onmousemove", "onkeydown", "onkeyup", "onkeypress",
"onfocus", "onblur", "onload", "onunload", "onabort", "onerror",
"onsubmit", "onreset", "onchange", "onpaint"
"onsubmit", "onreset", "onchange", "onpaint" ,"text"
};
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
@ -43,12 +43,21 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
NS_ADDREF(mPresContext);
mEvent = aEvent;
mTarget = nsnull;
mText = nsnull;
if (aEvent->eventStructType ==NS_TEXT_EVENT) {
mText = new nsString(((nsTextEvent*)aEvent)->theText);
mCommitText = ((nsTextEvent*)aEvent)->commitText;
}
NS_INIT_REFCNT();
}
nsDOMEvent::~nsDOMEvent() {
NS_RELEASE(mPresContext);
NS_IF_RELEASE(mTarget);
delete mText;
}
NS_IMPL_ADDREF(nsDOMEvent)
@ -92,6 +101,30 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType)
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetText(nsString& aText)
{
if (mEvent->message == NS_TEXT_EVENT) {
aText = *mText;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetCommitText(PRBool* aCommitText)
{
if (mEvent->message == NS_TEXT_EVENT) {
*aCommitText = mCommitText;
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::SetCommitText(PRBool aCommitText)
{
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::SetType(const nsString& aType)
{
return NS_ERROR_NOT_IMPLEMENTED;
@ -429,6 +462,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return mEventNames[eDOMEvents_change];
case NS_PAINT:
return mEventNames[eDOMEvents_paint];
case NS_TEXT_EVENT:
return mEventNames[eDOMEvents_text];
default:
break;
}

View File

@ -59,7 +59,8 @@ public:
eDOMEvents_submit,
eDOMEvents_reset,
eDOMEvents_change,
eDOMEvents_paint
eDOMEvents_paint,
eDOMEvents_text
};
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent);
@ -71,6 +72,11 @@ public:
NS_IMETHOD GetType(nsString& aType);
NS_IMETHOD SetType(const nsString& aType);
NS_IMETHOD GetText(nsString& aText);
NS_IMETHOD GetCommitText(PRBool* aCommitText);
NS_IMETHOD SetCommitText(PRBool aCommitText);
NS_IMETHOD GetTarget(nsIDOMNode** aTarget);
NS_IMETHOD SetTarget(nsIDOMNode* aTarget);
@ -136,7 +142,8 @@ protected:
nsEvent* mEvent;
nsIPresContext* mPresContext;
nsIDOMNode* mTarget;
nsString* mText;
PRBool mCommitText;
const char* GetEventName(PRUint32 aEventType);
};

View File

@ -24,6 +24,7 @@
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
#include "nsIDOMPaintListener.h"
#include "nsIDOMTextListener.h"
NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
@ -33,3 +34,4 @@ NS_DEFINE_IID(kIDOMFormListenerIID, NS_IDOMFORMLISTENER_IID);
NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
NS_DEFINE_IID(kIDOMPaintListenerIID, NS_IDOMPAINTLISTENER_IID);
NS_DEFINE_IID(kIDOMTextListenerIID,NS_IDOMTEXTLISTENER_IID);

View File

@ -28,5 +28,6 @@ extern const nsIID kIDOMFormListenerIID;
extern const nsIID kIDOMLoadListenerIID;
extern const nsIID kIDOMDragListenerIID;
extern const nsIID kIDOMPaintListenerIID;
extern const nsIID kIDOMTextListenerIID;
#endif /* nsDOMEVENTSIIDs_h___ */

View File

@ -30,6 +30,7 @@
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
#include "nsIDOMPaintListener.h"
#include "nsIDOMTextListener.h"
#include "nsIEventStateManager.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIScriptObjectOwner.h"
@ -52,6 +53,7 @@ nsEventListenerManager::nsEventListenerManager()
mFormListeners = nsnull;
mDragListeners = nsnull;
mPaintListeners = nsnull;
mTextListeners = nsnull;
NS_INIT_REFCNT();
}
@ -66,6 +68,7 @@ nsEventListenerManager::~nsEventListenerManager()
ReleaseListeners(mFormListeners);
ReleaseListeners(mDragListeners);
ReleaseListeners(mPaintListeners);
ReleaseListeners(mTextListeners);
}
NS_IMPL_ADDREF(nsEventListenerManager)
@ -112,6 +115,9 @@ nsVoidArray** nsEventListenerManager::GetListenersByIID(const nsIID& aIID)
else if (aIID.Equals(kIDOMPaintListenerIID)) {
return &mPaintListeners;
}
else if (aIID.Equals(kIDOMTextListenerIID)) {
return &mTextListeners;
}
return nsnull;
}
@ -143,7 +149,6 @@ nsresult nsEventListenerManager::GetEventListeners(nsVoidArray **aListeners, con
* Sets events listeners of all types.
* @param an event listener
*/
nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
{
nsVoidArray** mListeners = GetListenersByIID(aIID);
@ -162,7 +167,6 @@ nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener
return NS_OK;
}
const char *mEventArgv[] = {"event"};
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID)
@ -355,7 +359,35 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext,
}
}
break;
case NS_TEXT_EVENT:
#if DEBUG_TAGUE
printf("DOM: got text event\n");
#endif
if (nsnull != mTextListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMEvent(aDOMEvent,aPresContext,aEvent);
}
if (NS_OK == ret) {
for (int i=0; i<mTextListeners->Count(); i++) {
nsIDOMEventListener *mEventListener;
nsIDOMTextListener *mTextListener;
mEventListener = (nsIDOMEventListener*)mTextListeners->ElementAt(i);
if (NS_OK == mEventListener->QueryInterface(kIDOMTextListenerIID, (void**)&mTextListener)) {
ret = mTextListener->HandleText(*aDOMEvent);
NS_RELEASE(mTextListener);
}
else {
ret = mEventListener->ProcessEvent(*aDOMEvent);
}
}
aEventStatus = (NS_OK == ret) ? aEventStatus : nsEventStatus_eConsumeNoDefault;
}
}
break;
case NS_KEY_UP:
case NS_KEY_DOWN:
case NS_KEY_PRESS:

View File

@ -88,6 +88,7 @@ protected:
nsVoidArray* mFormListeners;
nsVoidArray* mDragListeners;
nsVoidArray* mPaintListeners;
nsVoidArray* mTextListeners;
};

View File

@ -48,9 +48,10 @@ nsNativeViewerApp::Run()
!gConsole->GetMainWindow() ||
!TranslateAccelerator(gConsole->GetMainWindow(),
JSConsole::sAccelTable, &msg)) {
TranslateMessage(&msg);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return msg.wParam;
}

View File

@ -138,6 +138,11 @@ struct nsKeyEvent : public nsInputEvent {
* Tooltip event
*/
struct nsTextEvent : public nsInputEvent {
PRUnichar* theText;
PRBool commitText;
};
struct nsTooltipEvent : public nsGUIEvent {
/// Index of tooltip area which generated the event. @see SetTooltips in nsIWidget
PRUint32 tipIndex;
@ -196,6 +201,7 @@ struct nsDragDropEvent : public nsGUIEvent {
#define NS_TOOLTIP_EVENT 9
#define NS_MENU_EVENT 10
#define NS_DRAGDROP_EVENT 11
#define NS_TEXT_EVENT 12
/**
* GUI MESSAGES

View File

@ -56,8 +56,9 @@ LCFLAGS = \
LLIBS= \
comctl32.lib \
comdlg32.lib \
Uuid.lib \
ole32.lib \
imm32.lib \
Uuid.lib \
ole32.lib \
shell32.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorgfxwin.lib \

View File

@ -41,6 +41,7 @@
#include "nsIMenuItem.h"
#include "nsIMenuListener.h"
#include "nsMenuItem.h"
#include <imm.h>
#ifdef DRAG_DROP
@ -100,11 +101,19 @@ nsWindow::nsWindow() : nsBaseWidget()
mHitSubMenus = new nsVoidArray();
mVScrollbar = nsnull;
mIMEProperty = 0;
mIMEIsComposing = PR_FALSE;
mIMECompositionString = NULL;
mIMECompositionStringSize = 0;
mIMECompositionStringSize = 0;
mIMECompositionUniString = NULL;
#ifdef DRAG_DROP
mDragDrop = nsnull;
mDropTarget = nsnull;
mDropSource = nsnull;
#endif
}
@ -1762,7 +1771,11 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
//LONG newdata2 = (data & 0xFFFF00F);
int x = 0;
}
result = OnKey(NS_KEY_UP, wParam, LOWORD(lParam), HIWORD(lParam));
if (!mIMEIsComposing)
result = OnKey(NS_KEY_UP, wParam, LOWORD(lParam), HIWORD(lParam));
else
result = PR_FALSE;
break;
case WM_KEYDOWN:
@ -1770,8 +1783,11 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT);
mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL);
mIsAltDown = IS_VK_DOWN(NS_VK_ALT);
result = OnKey(NS_KEY_DOWN, wParam, LOWORD(lParam), HIWORD(lParam));
if (!mIMEIsComposing)
result = OnKey(NS_KEY_DOWN, wParam, LOWORD(lParam), HIWORD(lParam));
else
result = PR_FALSE;
break;
// say we've dealt with erase background if widget does
@ -2028,6 +2044,95 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
result = PR_TRUE;
break;
case WM_IME_STARTCOMPOSITION: {
COMPOSITIONFORM compForm;
HIMC hIMEContext;
mIMEIsComposing = PR_TRUE;
#ifdef DEBUG_TAGUE
printf("IME: Recieved WM_IME_STARTCOMPOSITION\n");
#endif
if ((mIMEProperty & IME_PROP_SPECIAL_UI) || (mIMEProperty & IME_PROP_AT_CARET)) {
return PR_FALSE;
}
hIMEContext = ::ImmGetContext(mWnd);
if (hIMEContext==NULL) {
return PR_TRUE;
}
compForm.dwStyle = CFS_POINT;
compForm.ptCurrentPos.x = 100;
compForm.ptCurrentPos.y = 100;
::ImmSetCompositionWindow(hIMEContext,&compForm);
::ImmReleaseContext(mWnd,hIMEContext);
result = PR_TRUE;
}
break;
case WM_IME_COMPOSITION: {
COMPOSITIONFORM compForm;
HIMC hIMEContext;
result = PR_FALSE; // will change this if an IME message we handle
hIMEContext = ::ImmGetContext(mWnd);
if (hIMEContext==NULL) {
return PR_TRUE;
}
if (lParam & GCS_COMPSTR) {
long compStrLen = ::ImmGetCompositionString(hIMEContext,GCS_COMPSTR,NULL,0);
if (compStrLen+1>mIMECompositionStringSize) {
if (mIMECompositionString!=NULL) delete [] mIMECompositionString;
mIMECompositionString = new char[compStrLen+32];
mIMECompositionStringSize = compStrLen+32;
}
::ImmGetCompositionString(hIMEContext,GCS_COMPSTR,mIMECompositionString,mIMECompositionStringSize);
mIMECompositionStringLength = compStrLen;
mIMECompositionString[compStrLen]='\0';
HandleTextEvent(PR_FALSE);
result = PR_TRUE;
}
if (lParam & GCS_RESULTSTR) {
long compStrLen = ::ImmGetCompositionString(hIMEContext,GCS_RESULTSTR,NULL,0);
if (compStrLen+1>mIMECompositionStringSize) {
delete [] mIMECompositionString;
mIMECompositionString = new char[compStrLen+32];
mIMECompositionStringSize = compStrLen+32;
}
::ImmGetCompositionString(hIMEContext,GCS_RESULTSTR,mIMECompositionString,mIMECompositionStringSize);
mIMECompositionStringLength = compStrLen;
mIMECompositionString[compStrLen]='\0';
result = PR_TRUE;
HandleTextEvent(PR_TRUE);
}
#ifdef DEBUG_TAGUE
if (lParam & GCS_COMPSTR)
printf("IME: Composition String = %s\n",mIMECompositionString);
if (lParam & GCS_RESULTSTR)
printf("IME: Result String = %s\n",mIMECompositionString);
#endif
::ImmReleaseContext(mWnd,hIMEContext);
}
break;
case WM_IME_ENDCOMPOSITION:
mIMEIsComposing = PR_FALSE;
#ifdef DEBUG_TAGUE
printf("IME: Received WM_IME_ENDCOMPOSITION\n");
#endif
result = PR_TRUE;
break;
case WM_DROPFILES: {
HDROP hDropInfo = (HDROP) wParam;
UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0);
@ -2046,7 +2151,6 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
DispatchEvent(&event, status);
}
} break;
}
return result;
@ -2555,6 +2659,35 @@ NS_METHOD nsWindow::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight)
return NS_OK;
}
void
nsWindow::HandleTextEvent(PRBool commit)
{
nsTextEvent event;
nsPoint point;
size_t unicharSize;
point.x = 0;
point.y = 0;
InitEvent(event, NS_TEXT_EVENT, &point);
if (mIMECompositionUniString!=NULL)
delete [] mIMECompositionUniString;
unicharSize = ::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,mIMECompositionString,mIMECompositionStringLength,
mIMECompositionUniString,0);
mIMECompositionUniString = new PRUnichar[unicharSize+1];
::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,mIMECompositionString,mIMECompositionStringLength,
mIMECompositionUniString,unicharSize);
mIMECompositionUniString[unicharSize] = (PRUnichar)0;
event.theText = mIMECompositionUniString;
event.commitText = commit;
event.isShift = mIsShiftDown;
event.isControl = mIsControlDown;
event.isAlt = mIsAltDown;
event.eventStructType = NS_TEXT_EVENT;
(void)DispatchWindowEvent(&event);
NS_RELEASE(event.widget);
}

View File

@ -186,6 +186,7 @@ protected:
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
void GetNonClientBounds(nsRect &aRect);
void HandleTextEvent(PRBool commit);
protected:
static nsWindow* gCurrentWindow;
@ -214,6 +215,14 @@ protected:
nsIMenu * mHitMenu;
nsVoidArray * mHitSubMenus;
// For Input Method Support
DWORD mIMEProperty;
PRBool mIMEIsComposing;
char* mIMECompositionString;
PRUnichar* mIMECompositionUniString;
PRInt32 mIMECompositionStringLength;
PRInt32 mIMECompositionStringSize;
// Drag & Drop
#ifdef DRAG_DROP