From 67ddcd031145296cceed294aedd7e4e184c18ee5 Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Tue, 27 Apr 1999 21:59:18 +0000 Subject: [PATCH] WIP to get caret position in window coordinates for IME git-svn-id: svn://10.0.0.236/trunk@29534 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCaret.cpp | 68 ++++++++++++++++++++++++++- mozilla/layout/base/nsCaret.h | 1 + mozilla/layout/base/nsICaret.h | 11 ++++- mozilla/layout/base/public/nsICaret.h | 11 ++++- mozilla/layout/base/src/nsCaret.cpp | 68 ++++++++++++++++++++++++++- mozilla/layout/base/src/nsCaret.h | 1 + 6 files changed, 156 insertions(+), 4 deletions(-) diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index 5c1f26cb47c..e7adbbeb083 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -170,6 +170,72 @@ NS_IMETHODIMP nsCaret::Refresh(nsIView *aView, nsIRenderingContext& inRendContex } +//----------------------------------------------------------------------------- +NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRBool& outIsCollapsed) +{ + if (!mPresShell) + return NS_ERROR_NOT_INITIALIZED; + + nsCOMPtr domSelection; + nsresult err = mPresShell->GetSelection(getter_AddRefs(domSelection)); + if (NS_FAILED(err)) + return err; + + if (!domSelection) + return NS_ERROR_NOT_INITIALIZED; // no selection + + // fill in defaults for failure + outCoordinates.x = -1; + outCoordinates.y = -1; + outIsCollapsed = PR_FALSE; + + err = domSelection->GetIsCollapsed(&outIsCollapsed); + if (NS_FAILED(err)) + return err; + +#if 0 + // code in progress + nsCOMPtr focusNode; + PRInt32 focusOffset; + + if (NS_SUCCEEDED(domSelection->GetFocusNode(getter_AddRefs(focusNode))) && focusNode && + NS_SUCCEEDED(domSelection->GetFocusOffset(&focusOffset))) + { + // is this a text node? + nsCOMPtr nodeAsText = do_QueryInterface(focusNode); + + // note that we only work with text nodes here, unlike when drawing the caret. + // this is because this routine is intended for IME support, which only cares about text. + if (nodeAsText) + { + nsCOMPtrcontentNode = do_QueryInterface(focusNode); + + if (contentNode) + { + nsIFrame* theFrame = nsnull; + PRInt32 contentOffset = focusOffset; + + if (NS_SUCCEEDED(mPresShell->GetPrimaryFrameFor(contentNode, &theFrame)) && + theFrame && NS_SUCCEEDED(theFrame->GetChildFrameContainingOffset(focusOffset, &focusOffset, &theFrame))) + { + nsCOMPtr presContext; + if (NS_SUCCEEDED(mPresShell->GetPresContext(getter_AddRefs(presContext)))) + { + nsPoint framePos(0, 0); + + theFrame->GetPointFromOffset(presContext, &inRendContext, mLastContentOffset, &framePos); + frameRect += framePos; + + } + } + } + } + } +#endif + + return NS_ERROR_NOT_IMPLEMENTED; +} + //----------------------------------------------------------------------------- NS_IMETHODIMP nsCaret::ClearFrameRefs(nsIFrame* aFrame) { @@ -275,7 +341,7 @@ nsresult nsCaret::StopBlinking() //----------------------------------------------------------------------------- // Get the nsIFrame and the content offset for the current caret position. -// Returns PR_TRUE if we should go ahead and draw, PR_FALSE otherwise. +// Returns PR_TRUE if we should go ahead and draw, PR_FALSE otherwise. // PRBool nsCaret::SetupDrawingFrameAndOffset() { diff --git a/mozilla/layout/base/nsCaret.h b/mozilla/layout/base/nsCaret.h index d121808ab5a..1bd755b76ab 100644 --- a/mozilla/layout/base/nsCaret.h +++ b/mozilla/layout/base/nsCaret.h @@ -51,6 +51,7 @@ class nsCaret : public nsICaret, NS_IMETHOD SetCaretVisible(PRBool inMakeVisible); NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); NS_IMETHOD Refresh(nsIView *aView, nsIRenderingContext& inRendContext, const nsRect& aDirtyRect); + NS_IMETHOD GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRBool& outIsCollapsed); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); //nsIDOMSelectionListener interface diff --git a/mozilla/layout/base/nsICaret.h b/mozilla/layout/base/nsICaret.h index b2ebc7be55c..956ea0a4b16 100644 --- a/mozilla/layout/base/nsICaret.h +++ b/mozilla/layout/base/nsICaret.h @@ -45,7 +45,16 @@ public: /** Refresh * Refresh the caret after the frame it is being drawn in has painted */ - NS_IMETHOD Refresh(nsIView *aView, nsIRenderingContext& inRendContext, const nsRect& aDirtyRect) = 0; + NS_IMETHOD Refresh(nsIView *aView, nsIRenderingContext& inRendContext, const nsRect& aDirtyRect) = 0; + + /** GetWindowRelativeCoordinates + * Get the position of the caret in (top-level) window coordinates. + * If the selection is collapsed, this returns the caret location + * and true in outIsCollapsed. + * If the selection is not collapsed, this returns the location of the focus pos, + * and false in outIsCollapsed. + */ + NS_IMETHOD GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRBool& outIsCollapsed) = 0; /** ClearFrameRefs * The caret stores a reference to the frame that the caret was last drawn in. diff --git a/mozilla/layout/base/public/nsICaret.h b/mozilla/layout/base/public/nsICaret.h index b2ebc7be55c..956ea0a4b16 100644 --- a/mozilla/layout/base/public/nsICaret.h +++ b/mozilla/layout/base/public/nsICaret.h @@ -45,7 +45,16 @@ public: /** Refresh * Refresh the caret after the frame it is being drawn in has painted */ - NS_IMETHOD Refresh(nsIView *aView, nsIRenderingContext& inRendContext, const nsRect& aDirtyRect) = 0; + NS_IMETHOD Refresh(nsIView *aView, nsIRenderingContext& inRendContext, const nsRect& aDirtyRect) = 0; + + /** GetWindowRelativeCoordinates + * Get the position of the caret in (top-level) window coordinates. + * If the selection is collapsed, this returns the caret location + * and true in outIsCollapsed. + * If the selection is not collapsed, this returns the location of the focus pos, + * and false in outIsCollapsed. + */ + NS_IMETHOD GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRBool& outIsCollapsed) = 0; /** ClearFrameRefs * The caret stores a reference to the frame that the caret was last drawn in. diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index 5c1f26cb47c..e7adbbeb083 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -170,6 +170,72 @@ NS_IMETHODIMP nsCaret::Refresh(nsIView *aView, nsIRenderingContext& inRendContex } +//----------------------------------------------------------------------------- +NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRBool& outIsCollapsed) +{ + if (!mPresShell) + return NS_ERROR_NOT_INITIALIZED; + + nsCOMPtr domSelection; + nsresult err = mPresShell->GetSelection(getter_AddRefs(domSelection)); + if (NS_FAILED(err)) + return err; + + if (!domSelection) + return NS_ERROR_NOT_INITIALIZED; // no selection + + // fill in defaults for failure + outCoordinates.x = -1; + outCoordinates.y = -1; + outIsCollapsed = PR_FALSE; + + err = domSelection->GetIsCollapsed(&outIsCollapsed); + if (NS_FAILED(err)) + return err; + +#if 0 + // code in progress + nsCOMPtr focusNode; + PRInt32 focusOffset; + + if (NS_SUCCEEDED(domSelection->GetFocusNode(getter_AddRefs(focusNode))) && focusNode && + NS_SUCCEEDED(domSelection->GetFocusOffset(&focusOffset))) + { + // is this a text node? + nsCOMPtr nodeAsText = do_QueryInterface(focusNode); + + // note that we only work with text nodes here, unlike when drawing the caret. + // this is because this routine is intended for IME support, which only cares about text. + if (nodeAsText) + { + nsCOMPtrcontentNode = do_QueryInterface(focusNode); + + if (contentNode) + { + nsIFrame* theFrame = nsnull; + PRInt32 contentOffset = focusOffset; + + if (NS_SUCCEEDED(mPresShell->GetPrimaryFrameFor(contentNode, &theFrame)) && + theFrame && NS_SUCCEEDED(theFrame->GetChildFrameContainingOffset(focusOffset, &focusOffset, &theFrame))) + { + nsCOMPtr presContext; + if (NS_SUCCEEDED(mPresShell->GetPresContext(getter_AddRefs(presContext)))) + { + nsPoint framePos(0, 0); + + theFrame->GetPointFromOffset(presContext, &inRendContext, mLastContentOffset, &framePos); + frameRect += framePos; + + } + } + } + } + } +#endif + + return NS_ERROR_NOT_IMPLEMENTED; +} + //----------------------------------------------------------------------------- NS_IMETHODIMP nsCaret::ClearFrameRefs(nsIFrame* aFrame) { @@ -275,7 +341,7 @@ nsresult nsCaret::StopBlinking() //----------------------------------------------------------------------------- // Get the nsIFrame and the content offset for the current caret position. -// Returns PR_TRUE if we should go ahead and draw, PR_FALSE otherwise. +// Returns PR_TRUE if we should go ahead and draw, PR_FALSE otherwise. // PRBool nsCaret::SetupDrawingFrameAndOffset() { diff --git a/mozilla/layout/base/src/nsCaret.h b/mozilla/layout/base/src/nsCaret.h index d121808ab5a..1bd755b76ab 100644 --- a/mozilla/layout/base/src/nsCaret.h +++ b/mozilla/layout/base/src/nsCaret.h @@ -51,6 +51,7 @@ class nsCaret : public nsICaret, NS_IMETHOD SetCaretVisible(PRBool inMakeVisible); NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); NS_IMETHOD Refresh(nsIView *aView, nsIRenderingContext& inRendContext, const nsRect& aDirtyRect); + NS_IMETHOD GetWindowRelativeCoordinates(nsPoint& outCoordinates, PRBool& outIsCollapsed); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); //nsIDOMSelectionListener interface