зеркало из https://github.com/mozilla/pjs.git
Bug 526394. Part 24: Create sane nsCaret::GetGeometry API to obsolete nsCaret::GetCaretCoordinates. r=mats
This commit is contained in:
Родитель
c77e79e942
Коммит
ee429dc38d
|
@ -369,6 +369,48 @@ nsresult nsCaret::GetCaretCoordinates(EViewCoordinates aRelativeToType,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsIFrame* nsCaret::GetGeometry(nsISelection* aSelection, nsRect* aRect)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDOMNode> focusNode;
|
||||||
|
nsresult rv = aSelection->GetFocusNode(getter_AddRefs(focusNode));
|
||||||
|
if (NS_FAILED(rv) || !focusNode)
|
||||||
|
return nsnull;
|
||||||
|
|
||||||
|
PRInt32 focusOffset;
|
||||||
|
rv = aSelection->GetFocusOffset(&focusOffset);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return nsnull;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContent> contentNode = do_QueryInterface(focusNode);
|
||||||
|
if (!contentNode)
|
||||||
|
return nsnull;
|
||||||
|
|
||||||
|
// find the frame that contains the content node that has focus
|
||||||
|
nsIFrame* theFrame = nsnull;
|
||||||
|
PRInt32 theFrameOffset = 0;
|
||||||
|
|
||||||
|
nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
||||||
|
if (!frameSelection)
|
||||||
|
return nsnull;
|
||||||
|
PRUint8 bidiLevel = frameSelection->GetCaretBidiLevel();
|
||||||
|
rv = GetCaretFrameForNodeOffset(contentNode, focusOffset,
|
||||||
|
frameSelection->GetHint(), bidiLevel,
|
||||||
|
&theFrame, &theFrameOffset);
|
||||||
|
if (NS_FAILED(rv) || !theFrame)
|
||||||
|
return nsnull;
|
||||||
|
|
||||||
|
nsPoint framePos(0, 0);
|
||||||
|
rv = theFrame->GetPointFromOffset(theFrameOffset, &framePos);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return nsnull;
|
||||||
|
|
||||||
|
// now add the frame offset to the view offset, and we're done
|
||||||
|
nscoord height = theFrame->GetSize().height;
|
||||||
|
nscoord width = ComputeMetrics(theFrame, theFrameOffset, height).mCaretWidth;
|
||||||
|
*aRect = nsRect(framePos.x, 0, width, height);
|
||||||
|
return theFrame;
|
||||||
|
}
|
||||||
|
|
||||||
void nsCaret::DrawCaretAfterBriefDelay()
|
void nsCaret::DrawCaretAfterBriefDelay()
|
||||||
{
|
{
|
||||||
// Make sure readonly caret gets drawn again if it needs to be
|
// Make sure readonly caret gets drawn again if it needs to be
|
||||||
|
|
|
@ -104,6 +104,7 @@ class nsCaret : public nsISelectionListener
|
||||||
return mReadOnly;
|
return mReadOnly;
|
||||||
}
|
}
|
||||||
/** GetCaretCoordinates
|
/** GetCaretCoordinates
|
||||||
|
* OBSOLETE use GetGeometry instead.
|
||||||
* Get the position of the caret in coordinates relative to the typed
|
* Get the position of the caret in coordinates relative to the typed
|
||||||
* specified (aRelativeToType).
|
* specified (aRelativeToType).
|
||||||
* This function is virtual so that it can be used by nsCaretAccessible
|
* This function is virtual so that it can be used by nsCaretAccessible
|
||||||
|
@ -118,6 +119,16 @@ class nsCaret : public nsISelectionListener
|
||||||
PRBool* outIsCollapsed,
|
PRBool* outIsCollapsed,
|
||||||
nsIView **outView);
|
nsIView **outView);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces GetCaretCoordinates.
|
||||||
|
* Gets the position and size of the caret that would be drawn for
|
||||||
|
* the focus node/offset of aSelection (assuming it would be drawn,
|
||||||
|
* i.e., disregarding blink status). The geometry is stored in aRect,
|
||||||
|
* and we return the frame aRect is relative to.
|
||||||
|
*/
|
||||||
|
virtual nsIFrame* GetGeometry(nsISelection* aSelection,
|
||||||
|
nsRect* aRect);
|
||||||
|
|
||||||
/** EraseCaret
|
/** EraseCaret
|
||||||
* this will erase the caret if its drawn and reset drawn status
|
* this will erase the caret if its drawn and reset drawn status
|
||||||
*/
|
*/
|
||||||
|
|
Загрузка…
Ссылка в новой задаче