From 7e501c5ca2979e68ac88888f19c72454cd961a11 Mon Sep 17 00:00:00 2001 From: "shanjian%netscape.com" Date: Thu, 19 Apr 2001 22:46:29 +0000 Subject: [PATCH] #59405 IME candidate window position is not correct in text field on New card and To field r = sfraser sr=kin a=blizzard Handle the difference of cursor coordinate required by different platform. nsICaret.h nsCaret.cpp nsEditor.cpp nsPlaintextEditor.cpp nsHTMLEditor.cpp --- editor/base/nsEditor.cpp | 2 +- editor/base/nsHTMLEditor.cpp | 2 +- editor/base/nsPlaintextEditor.cpp | 13 +------------ editor/libeditor/base/nsEditor.cpp | 2 +- editor/libeditor/html/nsHTMLEditor.cpp | 2 +- editor/libeditor/text/nsPlaintextEditor.cpp | 13 +------------ layout/base/nsCaret.cpp | 9 +++++++++ layout/base/nsICaret.h | 3 ++- layout/base/public/nsICaret.h | 3 ++- layout/base/src/nsCaret.cpp | 9 +++++++++ 10 files changed, 28 insertions(+), 30 deletions(-) diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index c7d62a08449..ff403593173 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -1893,7 +1893,7 @@ nsEditor::QueryComposition(nsTextEventReply* aReply) if (NS_SUCCEEDED(result) && caretP) { if (aReply) { caretP->SetCaretDOMSelection(selection); - result = caretP->GetCaretCoordinates(nsICaret::eTopLevelWindowCoordinates, selection, + result = caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); } } diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index cc6b1bd9bc3..21903d36d5e 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -3404,7 +3404,7 @@ nsHTMLEditor::SetCompositionString(const nsAReadableString& aCompositionString, if (!ps) return NS_ERROR_NOT_INITIALIZED; ps->GetCaret(getter_AddRefs(caretP)); caretP->SetCaretDOMSelection(selection); - result = caretP->GetCaretCoordinates(nsICaret::eTopLevelWindowCoordinates, selection, + result = caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); // second part of 23558 fix: diff --git a/editor/base/nsPlaintextEditor.cpp b/editor/base/nsPlaintextEditor.cpp index e9c928899ba..1e6073612fa 100644 --- a/editor/base/nsPlaintextEditor.cpp +++ b/editor/base/nsPlaintextEditor.cpp @@ -1886,19 +1886,8 @@ nsPlaintextEditor::SetCompositionString(const nsAReadableString& aCompositionStr ps->GetCaret(getter_AddRefs(caretP)); caretP->SetCaretDOMSelection(selection); -// XXX: The following ifdef should really be pushed up into the -// IME front-end code, or down into the caret code. There was a -// suggestion that perhaps nsCaret::GetCaretCoordinates() should -// be modified so that we can pass in something like eIMECoordinates -// and let it decide what to return based on the platform we are -// running on. -#ifdef XP_MAC - caretP->GetCaretCoordinates(nsICaret::eTopLevelWindowCoordinates, selection, + caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); -#else - caretP->GetCaretCoordinates(nsICaret::eRenderingViewCoordinates, selection, - &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); -#endif // second part of 23558 fix: if (aCompositionString.IsEmpty()) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index c7d62a08449..ff403593173 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -1893,7 +1893,7 @@ nsEditor::QueryComposition(nsTextEventReply* aReply) if (NS_SUCCEEDED(result) && caretP) { if (aReply) { caretP->SetCaretDOMSelection(selection); - result = caretP->GetCaretCoordinates(nsICaret::eTopLevelWindowCoordinates, selection, + result = caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); } } diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index cc6b1bd9bc3..21903d36d5e 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -3404,7 +3404,7 @@ nsHTMLEditor::SetCompositionString(const nsAReadableString& aCompositionString, if (!ps) return NS_ERROR_NOT_INITIALIZED; ps->GetCaret(getter_AddRefs(caretP)); caretP->SetCaretDOMSelection(selection); - result = caretP->GetCaretCoordinates(nsICaret::eTopLevelWindowCoordinates, selection, + result = caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); // second part of 23558 fix: diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index e9c928899ba..1e6073612fa 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -1886,19 +1886,8 @@ nsPlaintextEditor::SetCompositionString(const nsAReadableString& aCompositionStr ps->GetCaret(getter_AddRefs(caretP)); caretP->SetCaretDOMSelection(selection); -// XXX: The following ifdef should really be pushed up into the -// IME front-end code, or down into the caret code. There was a -// suggestion that perhaps nsCaret::GetCaretCoordinates() should -// be modified so that we can pass in something like eIMECoordinates -// and let it decide what to return based on the platform we are -// running on. -#ifdef XP_MAC - caretP->GetCaretCoordinates(nsICaret::eTopLevelWindowCoordinates, selection, + caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); -#else - caretP->GetCaretCoordinates(nsICaret::eRenderingViewCoordinates, selection, - &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); -#endif // second part of 23558 fix: if (aCompositionString.IsEmpty()) diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 5b5f3d24dda..60d7ec659e6 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -305,6 +305,15 @@ NS_IMETHODIMP nsCaret::GetCaretCoordinates(EViewCoordinates aRelativeToType, nsI nsPoint viewOffset(0, 0); nsRect clipRect; nsIView *drawingView; // views are not refcounted + + //#59405, on windows and unix, the coordinate for IME need to be view (nearest native window) related. + if (aRelativeToType == eIMECoordinates) +#ifdef XP_MAC + aRelativeToType = eTopLevelWindowCoordinates; +#else + aRelativeToType = eRenderingViewCoordinates; +#endif + GetViewForRendering(theFrame, aRelativeToType, viewOffset, clipRect, drawingView); if (!drawingView) return NS_ERROR_UNEXPECTED; diff --git a/layout/base/nsICaret.h b/layout/base/nsICaret.h index 36e2920ce18..3cfa639141f 100644 --- a/layout/base/nsICaret.h +++ b/layout/base/nsICaret.h @@ -45,7 +45,8 @@ public: typedef enum EViewCoordinates { eTopLevelWindowCoordinates, eRenderingViewCoordinates, - eClosestViewCoordinates + eClosestViewCoordinates, + eIMECoordinates } EViewCoordinates; NS_IMETHOD Init(nsIPresShell *inPresShell) = 0; diff --git a/layout/base/public/nsICaret.h b/layout/base/public/nsICaret.h index 36e2920ce18..3cfa639141f 100644 --- a/layout/base/public/nsICaret.h +++ b/layout/base/public/nsICaret.h @@ -45,7 +45,8 @@ public: typedef enum EViewCoordinates { eTopLevelWindowCoordinates, eRenderingViewCoordinates, - eClosestViewCoordinates + eClosestViewCoordinates, + eIMECoordinates } EViewCoordinates; NS_IMETHOD Init(nsIPresShell *inPresShell) = 0; diff --git a/layout/base/src/nsCaret.cpp b/layout/base/src/nsCaret.cpp index 5b5f3d24dda..60d7ec659e6 100644 --- a/layout/base/src/nsCaret.cpp +++ b/layout/base/src/nsCaret.cpp @@ -305,6 +305,15 @@ NS_IMETHODIMP nsCaret::GetCaretCoordinates(EViewCoordinates aRelativeToType, nsI nsPoint viewOffset(0, 0); nsRect clipRect; nsIView *drawingView; // views are not refcounted + + //#59405, on windows and unix, the coordinate for IME need to be view (nearest native window) related. + if (aRelativeToType == eIMECoordinates) +#ifdef XP_MAC + aRelativeToType = eTopLevelWindowCoordinates; +#else + aRelativeToType = eRenderingViewCoordinates; +#endif + GetViewForRendering(theFrame, aRelativeToType, viewOffset, clipRect, drawingView); if (!drawingView) return NS_ERROR_UNEXPECTED;