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
This commit is contained in:
parent
51c4a2545c
commit
67ddcd0311
@ -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<nsIDOMSelection> 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<nsIDOMNode> focusNode;
|
||||
PRInt32 focusOffset;
|
||||
|
||||
if (NS_SUCCEEDED(domSelection->GetFocusNode(getter_AddRefs(focusNode))) && focusNode &&
|
||||
NS_SUCCEEDED(domSelection->GetFocusOffset(&focusOffset)))
|
||||
{
|
||||
// is this a text node?
|
||||
nsCOMPtr<nsIDOMCharacterData> 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)
|
||||
{
|
||||
nsCOMPtr<nsIContent>contentNode = 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<nsIPresContext> 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()
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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<nsIDOMSelection> 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<nsIDOMNode> focusNode;
|
||||
PRInt32 focusOffset;
|
||||
|
||||
if (NS_SUCCEEDED(domSelection->GetFocusNode(getter_AddRefs(focusNode))) && focusNode &&
|
||||
NS_SUCCEEDED(domSelection->GetFocusOffset(&focusOffset)))
|
||||
{
|
||||
// is this a text node?
|
||||
nsCOMPtr<nsIDOMCharacterData> 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)
|
||||
{
|
||||
nsCOMPtr<nsIContent>contentNode = 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<nsIPresContext> 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()
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user