Added support for a reply from the StartComposition message. Necessary for XIM support on UNIX.

This commit is contained in:
tague%netscape.com 1999-08-31 01:20:32 +00:00
parent 7e5e37e98e
commit 97b0bd802c
23 changed files with 196 additions and 29 deletions

View File

@ -6,3 +6,4 @@ nsIEventStateManager.h
nsIPrivateDOMEvent.h
nsIPrivateTextEvent.h
nsIPrivateTextRange.h
nsIPrivateCompositionEvent.h

View File

@ -30,6 +30,7 @@ EXPORTS = \
nsIPrivateDOMEvent.h \
nsIPrivateTextEvent.h \
nsIPrivateTextRange.h \
nsIPrivateCompositionEvent.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

View File

@ -24,6 +24,7 @@ EXPORTS = \
nsIPrivateDOMEvent.h \
nsIPrivateTextEvent.h \
nsIPrivateTextRange.h \
nsIPrivateCompositionEvent.h \
$(NULL)
MODULE=raptor

View File

@ -0,0 +1,39 @@
/* -*- 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 nsIPrivateCompositionEvent_h__
#define nsIPrivateCompositionEvent_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
// {ECF6BEF1-5F0C-11d3-9EB3-0060089FE59B}
#define NS_IPRIVATECOMPOSITIONEVENT_IID \
{ 0xecf6bef1, 0x5f0c, 0x11d3, \
{ 0x9e, 0xb3, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
class nsIPrivateCompositionEvent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATECOMPOSITIONEVENT_IID; return iid; }
NS_IMETHOD GetCompositionReply(struct nsTextEventReply** aReply) = 0;
};
#endif // nsIPrivateCompositionEvent_h__

View File

@ -28,6 +28,7 @@
#include "nsIPresShell.h"
#include "nsPrivateTextRange.h"
#include "nsIDocument.h"
#include "nsIPrivateCompositionEvent.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
@ -38,6 +39,7 @@ static NS_DEFINE_IID(kIDOMNSUIEventIID, NS_IDOMNSUIEVENT_IID);
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
static NS_DEFINE_IID(kIPrivateTextEventIID, NS_IPRIVATETEXTEVENT_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIPrivateCompositionEventIID,NS_IPRIVATECOMPOSITIONEVENT_IID);
static char* mEventNames[] = {
"mousedown", "mouseup", "click", "dblclick", "mouseover",
@ -128,6 +130,11 @@ nsresult nsDOMEvent::QueryInterface(const nsIID& aIID,
AddRef();
return NS_OK;
}
if (aIID.Equals(kIPrivateCompositionEventIID)) {
*aInstancePtrResult = (void*)((nsIPrivateCompositionEvent*)this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
@ -269,6 +276,17 @@ NS_METHOD nsDOMEvent::GetEventReply(nsTextEventReply** aReply)
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetCompositionReply(nsTextEventReply** aReply)
{
if (mEvent->message==NS_COMPOSITION_START) {
*aReply = &(((nsCompositionEvent*)mEvent)->theReply);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetScreenX(PRInt32* aScreenX)
{
// pinkerton -- i don't understand how we can assume that mEvent

View File

@ -23,6 +23,7 @@
#include "nsIDOMNSUIEvent.h"
#include "nsISupports.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIPrivateTextRange.h"
@ -33,7 +34,7 @@ class nsIContent;
class nsIDOMRenderingContext;
class nsDOMEvent : public nsIDOMUIEvent, public nsIDOMNSUIEvent, public nsIPrivateDOMEvent, public nsIPrivateTextEvent {
class nsDOMEvent : public nsIDOMUIEvent, public nsIDOMNSUIEvent, public nsIPrivateDOMEvent, public nsIPrivateTextEvent, public nsIPrivateCompositionEvent {
public:
// Note: this enum must be kept in sync with mEventNames in nsDOMEvent.cpp
@ -135,6 +136,8 @@ public:
NS_IMETHOD GetInputRange(nsIPrivateTextRangeList** aInputRange);
NS_IMETHOD GetEventReply(nsTextEventReply** aReply);
// nsIPrivateCompositionEvent interface
NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply);
protected:

View File

@ -1104,7 +1104,7 @@ nsEditor::DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed)
// created of IMETextTxn's.
//
NS_IMETHODIMP
nsEditor::BeginComposition(void)
nsEditor::BeginComposition(nsTextEventReply* aReply)
{
#ifdef DEBUG_tague
printf("nsEditor::StartComposition\n");
@ -1113,10 +1113,16 @@ nsEditor::BeginComposition(void)
PRInt32 offset;
nsCOMPtr<nsIDOMSelection> selection;
nsCOMPtr<nsIDOMCharacterData> nodeAsText;
nsCOMPtr<nsICaret> caretP;
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps) return NS_ERROR_NOT_INITIALIZED;
result = ps->GetCaret(getter_AddRefs(caretP));
if (NS_SUCCEEDED(result) && caretP) {
if (aReply) {
caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
}
}
result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
if ((NS_SUCCEEDED(result)) && selection)
{
@ -3879,7 +3885,7 @@ nsEditor::CreateTxnForIMEText(const nsString & aStringToInsert,
nsresult result;
if (mIMETextNode==nsnull)
BeginComposition();
BeginComposition(nsnull);
result = TransactionFactory::GetNewTransaction(IMETextTxn::GetCID(), (EditTxn **)aTxn);
if (nsnull!=*aTxn) {

View File

@ -193,7 +193,7 @@ public:
/* ------------ nsIEditorIMESupport methods -------------- */
NS_IMETHOD BeginComposition(void);
NS_IMETHOD BeginComposition(nsTextEventReply* aReply);
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIPrivateTextRangeList* aTextRangeList,nsTextEventReply* aReply);
NS_IMETHOD EndComposition(void);

View File

@ -32,6 +32,7 @@
#include "nsIDOMUIEvent.h"
#include "nsIDOMNSUIEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIEditorMailSupport.h"
#include "nsIDocumentEncoder.h"
@ -1489,7 +1490,15 @@ void nsTextEditorCompositionListener::SetEditor(nsIEditor *aEditor)
nsresult
nsTextEditorCompositionListener::HandleStartComposition(nsIDOMEvent* aCompositionEvent)
{
return mEditor->BeginComposition();
nsCOMPtr<nsIPrivateCompositionEvent> pCompositionEvent = do_QueryInterface(aCompositionEvent);
nsTextEventReply* eventReply;
if (!pCompositionEvent) return NS_ERROR_FAILURE;
nsresult rv = pCompositionEvent->GetCompositionReply(&eventReply);
if (NS_FAILED(rv)) return rv;
return mEditor->BeginComposition(eventReply);
}
nsresult

View File

@ -1104,7 +1104,7 @@ nsEditor::DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed)
// created of IMETextTxn's.
//
NS_IMETHODIMP
nsEditor::BeginComposition(void)
nsEditor::BeginComposition(nsTextEventReply* aReply)
{
#ifdef DEBUG_tague
printf("nsEditor::StartComposition\n");
@ -1113,10 +1113,16 @@ nsEditor::BeginComposition(void)
PRInt32 offset;
nsCOMPtr<nsIDOMSelection> selection;
nsCOMPtr<nsIDOMCharacterData> nodeAsText;
nsCOMPtr<nsICaret> caretP;
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps) return NS_ERROR_NOT_INITIALIZED;
result = ps->GetCaret(getter_AddRefs(caretP));
if (NS_SUCCEEDED(result) && caretP) {
if (aReply) {
caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
}
}
result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
if ((NS_SUCCEEDED(result)) && selection)
{
@ -3879,7 +3885,7 @@ nsEditor::CreateTxnForIMEText(const nsString & aStringToInsert,
nsresult result;
if (mIMETextNode==nsnull)
BeginComposition();
BeginComposition(nsnull);
result = TransactionFactory::GetNewTransaction(IMETextTxn::GetCID(), (EditTxn **)aTxn);
if (nsnull!=*aTxn) {

View File

@ -193,7 +193,7 @@ public:
/* ------------ nsIEditorIMESupport methods -------------- */
NS_IMETHOD BeginComposition(void);
NS_IMETHOD BeginComposition(nsTextEventReply* aReply);
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIPrivateTextRangeList* aTextRangeList,nsTextEventReply* aReply);
NS_IMETHOD EndComposition(void);

View File

@ -32,6 +32,7 @@
#include "nsIDOMUIEvent.h"
#include "nsIDOMNSUIEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIEditorMailSupport.h"
#include "nsIDocumentEncoder.h"
@ -1489,7 +1490,15 @@ void nsTextEditorCompositionListener::SetEditor(nsIEditor *aEditor)
nsresult
nsTextEditorCompositionListener::HandleStartComposition(nsIDOMEvent* aCompositionEvent)
{
return mEditor->BeginComposition();
nsCOMPtr<nsIPrivateCompositionEvent> pCompositionEvent = do_QueryInterface(aCompositionEvent);
nsTextEventReply* eventReply;
if (!pCompositionEvent) return NS_ERROR_FAILURE;
nsresult rv = pCompositionEvent->GetCompositionReply(&eventReply);
if (NS_FAILED(rv)) return rv;
return mEditor->BeginComposition(eventReply);
}
nsresult

View File

@ -36,10 +36,10 @@ public:
/**
* BeginComposition() Handles the start of inline input composition.
* BeginComposition(nsTextEventReply* aReply) Handles the start of inline input composition.
*/
NS_IMETHOD BeginComposition(void) = 0;
NS_IMETHOD BeginComposition(nsTextEventReply *aReply) = 0;
/**
* SetCompositionString() Sets the inline input composition string.

View File

@ -6,3 +6,4 @@ nsIEventStateManager.h
nsIPrivateDOMEvent.h
nsIPrivateTextEvent.h
nsIPrivateTextRange.h
nsIPrivateCompositionEvent.h

View File

@ -30,6 +30,7 @@ EXPORTS = \
nsIPrivateDOMEvent.h \
nsIPrivateTextEvent.h \
nsIPrivateTextRange.h \
nsIPrivateCompositionEvent.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

View File

@ -24,6 +24,7 @@ EXPORTS = \
nsIPrivateDOMEvent.h \
nsIPrivateTextEvent.h \
nsIPrivateTextRange.h \
nsIPrivateCompositionEvent.h \
$(NULL)
MODULE=raptor

View File

@ -0,0 +1,39 @@
/* -*- 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 nsIPrivateCompositionEvent_h__
#define nsIPrivateCompositionEvent_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
// {ECF6BEF1-5F0C-11d3-9EB3-0060089FE59B}
#define NS_IPRIVATECOMPOSITIONEVENT_IID \
{ 0xecf6bef1, 0x5f0c, 0x11d3, \
{ 0x9e, 0xb3, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
class nsIPrivateCompositionEvent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATECOMPOSITIONEVENT_IID; return iid; }
NS_IMETHOD GetCompositionReply(struct nsTextEventReply** aReply) = 0;
};
#endif // nsIPrivateCompositionEvent_h__

View File

@ -28,6 +28,7 @@
#include "nsIPresShell.h"
#include "nsPrivateTextRange.h"
#include "nsIDocument.h"
#include "nsIPrivateCompositionEvent.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
@ -38,6 +39,7 @@ static NS_DEFINE_IID(kIDOMNSUIEventIID, NS_IDOMNSUIEVENT_IID);
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
static NS_DEFINE_IID(kIPrivateTextEventIID, NS_IPRIVATETEXTEVENT_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIPrivateCompositionEventIID,NS_IPRIVATECOMPOSITIONEVENT_IID);
static char* mEventNames[] = {
"mousedown", "mouseup", "click", "dblclick", "mouseover",
@ -128,6 +130,11 @@ nsresult nsDOMEvent::QueryInterface(const nsIID& aIID,
AddRef();
return NS_OK;
}
if (aIID.Equals(kIPrivateCompositionEventIID)) {
*aInstancePtrResult = (void*)((nsIPrivateCompositionEvent*)this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
@ -269,6 +276,17 @@ NS_METHOD nsDOMEvent::GetEventReply(nsTextEventReply** aReply)
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetCompositionReply(nsTextEventReply** aReply)
{
if (mEvent->message==NS_COMPOSITION_START) {
*aReply = &(((nsCompositionEvent*)mEvent)->theReply);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetScreenX(PRInt32* aScreenX)
{
// pinkerton -- i don't understand how we can assume that mEvent

View File

@ -23,6 +23,7 @@
#include "nsIDOMNSUIEvent.h"
#include "nsISupports.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIPrivateTextRange.h"
@ -33,7 +34,7 @@ class nsIContent;
class nsIDOMRenderingContext;
class nsDOMEvent : public nsIDOMUIEvent, public nsIDOMNSUIEvent, public nsIPrivateDOMEvent, public nsIPrivateTextEvent {
class nsDOMEvent : public nsIDOMUIEvent, public nsIDOMNSUIEvent, public nsIPrivateDOMEvent, public nsIPrivateTextEvent, public nsIPrivateCompositionEvent {
public:
// Note: this enum must be kept in sync with mEventNames in nsDOMEvent.cpp
@ -135,6 +136,8 @@ public:
NS_IMETHOD GetInputRange(nsIPrivateTextRangeList** aInputRange);
NS_IMETHOD GetEventReply(nsTextEventReply** aReply);
// nsIPrivateCompositionEvent interface
NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply);
protected:

View File

@ -1585,9 +1585,13 @@ NS_IMETHODIMP nsViewManager :: DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &
if (aEvent->message==NS_TEXT_EVENT) {
((nsTextEvent*)aEvent)->theReply.mCursorPosition.x=NSTwipsToIntPixels(((nsTextEvent*)aEvent)->theReply.mCursorPosition.x, t2p);
((nsTextEvent*)aEvent)->theReply.mCursorPosition.y=NSTwipsToIntPixels(((nsTextEvent*)aEvent)->theReply.mCursorPosition.y, t2p);
}
}
}
if (aEvent->message==NS_COMPOSITION_START) {
((nsCompositionEvent*)aEvent)->theReply.mCursorPosition.x=NSTwipsToIntPixels(((nsCompositionEvent*)aEvent)->theReply.mCursorPosition.x,t2p);
((nsCompositionEvent*)aEvent)->theReply.mCursorPosition.y=NSTwipsToIntPixels(((nsCompositionEvent*)aEvent)->theReply.mCursorPosition.y,t2p);
}
}
break;
}
}

View File

@ -166,6 +166,7 @@ struct nsTextEvent : public nsInputEvent {
struct nsCompositionEvent : public nsInputEvent {
PRUint32 compositionMessage;
nsTextEventReply theReply;
};
/**

View File

@ -2680,16 +2680,9 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
if (hIMEContext==NULL) {
return PR_TRUE;
}
compForm.dwStyle = CFS_POINT;
compForm.ptCurrentPos.x = 100;
compForm.ptCurrentPos.y = 100;
// ::ImmSetCompositionWindow(hIMEContext,&compForm); don't do this! it's bad.
::ImmReleaseContext(mWnd,hIMEContext);
HandleStartComposition();
HandleStartComposition(hIMEContext);
result = PR_TRUE;
::ImmReleaseContext(mWnd,hIMEContext);
}
break;
@ -2779,7 +2772,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
result = PR_TRUE;
HandleTextEvent(hIMEContext);
HandleEndComposition();
HandleStartComposition();
HandleStartComposition(hIMEContext);
}
::ImmReleaseContext(mWnd,hIMEContext);
@ -3533,10 +3526,11 @@ nsWindow::HandleTextEvent(HIMC hIMEContext)
}
void
nsWindow::HandleStartComposition(void)
nsWindow::HandleStartComposition(HIMC hIMEContext)
{
nsCompositionEvent event;
nsPoint point;
CANDIDATEFORM candForm;
point.x = 0;
point.y = 0;
@ -3545,6 +3539,18 @@ nsWindow::HandleStartComposition(void)
event.eventStructType = NS_COMPOSITION_START;
event.compositionMessage = NS_COMPOSITION_START;
(void)DispatchWindowEvent(&event);
//
// Post process event
//
candForm.dwIndex = 0;
candForm.dwStyle = CFS_CANDIDATEPOS;
candForm.ptCurrentPos.x = event.theReply.mCursorPosition.x + IME_X_OFFSET;
candForm.ptCurrentPos.y = event.theReply.mCursorPosition.y + IME_Y_OFFSET;
#ifdef DEBUG_tague
printf("Candidate window position: x=%d, y=%d\n",candForm.ptCurrentPos.x,candForm.ptCurrentPos.y);
#endif
::ImmSetCandidateWindow(hIMEContext,&candForm);
NS_RELEASE(event.widget);
}

View File

@ -193,7 +193,7 @@ protected:
void GetNonClientBounds(nsRect &aRect);
void HandleTextEvent(HIMC hIMEContext);
void HandleStartComposition(void);
void HandleStartComposition(HIMC hIMEContext);
void HandleEndComposition(void);
void MapDBCSAtrributeArrayToUnicodeOffsets(PRUint32* textRangeListLengthResult, nsTextRangeArray* textRangeListResult);