Bug 392818 - getTextAtOffset broken for all but the first line in a multi-line entry, r=ginn.chen, a=dsicore

This commit is contained in:
surkov.alexander@gmail.com 2007-08-29 00:12:09 -07:00
Родитель c0c8114b7a
Коммит db8a59dfa3
2 изменённых файлов: 48 добавлений и 21 удалений

Просмотреть файл

@ -624,8 +624,14 @@ nsresult nsHyperTextAccessible::DOMPointToHypertextOffset(nsIDOMNode* aNode, PRI
return NS_OK;
}
PRInt32 nsHyperTextAccessible::GetRelativeOffset(nsIPresShell *aPresShell, nsIFrame *aFromFrame, PRInt32 aFromOffset,
nsSelectionAmount aAmount, nsDirection aDirection, PRBool aNeedsStart)
PRInt32
nsHyperTextAccessible::GetRelativeOffset(nsIPresShell *aPresShell,
nsIFrame *aFromFrame,
PRInt32 aFromOffset,
nsIAccessible *aFromAccessible,
nsSelectionAmount aAmount,
nsDirection aDirection,
PRBool aNeedsStart)
{
const PRBool kIsJumpLinesOk = PR_TRUE; // okay to jump lines
const PRBool kIsScrollViewAStop = PR_FALSE; // do not stop at scroll views
@ -640,9 +646,18 @@ PRInt32 nsHyperTextAccessible::GetRelativeOffset(nsIPresShell *aPresShell, nsIFr
// Ask layout for the new node and offset, after moving the appropriate amount
nsPeekOffsetStruct pos;
PRInt32 contentOffset;
nsresult rv = RenderedToContentOffset(aFromFrame, aFromOffset, &contentOffset);
NS_ENSURE_SUCCESS(rv, -1);
nsresult rv;
PRInt32 contentOffset = aFromOffset;
if (IsText(aFromAccessible)) {
nsCOMPtr<nsPIAccessNode> accessNode(do_QueryInterface(aFromAccessible));
NS_ASSERTION(accessNode, "nsIAccessible doesn't support nsPIAccessNode");
nsIFrame *frame = accessNode->GetFrame();
NS_ENSURE_TRUE(frame, -1);
rv = RenderedToContentOffset(frame, aFromOffset, &contentOffset);
NS_ENSURE_SUCCESS(rv, -1);
}
pos.SetData(aAmount, aDirection, contentOffset,
0, kIsJumpLinesOk, kIsScrollViewAStop, kIsKeyboardSelect, kIsVisualBidi,
@ -740,7 +755,10 @@ nsresult nsHyperTextAccessible::GetTextHelper(EGetTextType aType, nsAccessibleTe
++ endOffset;
}
// Convert offsets to frame-relative
nsIFrame *startFrame = GetPosAndText(startOffset, endOffset);
nsCOMPtr<nsIAccessible> startAcc;
nsIFrame *startFrame = GetPosAndText(startOffset, endOffset, nsnull, nsnull,
nsnull, getter_AddRefs(startAcc));
if (!startFrame) {
PRInt32 textLength;
GetCharacterCount(&textLength);
@ -809,8 +827,9 @@ nsresult nsHyperTextAccessible::GetTextHelper(EGetTextType aType, nsAccessibleTe
finalStartOffset = aOffset;
}
else {
finalStartOffset = GetRelativeOffset(presShell, startFrame, startOffset,
amount, eDirPrevious, needsStart);
finalStartOffset = GetRelativeOffset(presShell, startFrame, startOffset,
startAcc, amount, eDirPrevious,
needsStart);
NS_ENSURE_TRUE(finalStartOffset >= 0, NS_ERROR_FAILURE);
}
@ -822,12 +841,14 @@ nsresult nsHyperTextAccessible::GetTextHelper(EGetTextType aType, nsAccessibleTe
// 2 words/lines if the offset occured on whitespace boundary
// Careful, startOffset and endOffset are passed by reference to GetPosAndText() and changed
startOffset = endOffset = finalStartOffset;
nsIFrame *endFrame = GetPosAndText(startOffset, endOffset);
nsCOMPtr<nsIAccessible> endAcc;
nsIFrame *endFrame = GetPosAndText(startOffset, endOffset, nsnull, nsnull,
nsnull, getter_AddRefs(endAcc));
if (!endFrame) {
return NS_ERROR_FAILURE;
}
finalEndOffset = GetRelativeOffset(presShell, endFrame, endOffset, amount,
eDirNext, needsStart);
finalEndOffset = GetRelativeOffset(presShell, endFrame, endOffset, endAcc,
amount, eDirNext, needsStart);
NS_ENSURE_TRUE(endOffset >= 0, NS_ERROR_FAILURE);
if (finalEndOffset == aOffset) {
// This happens sometimes when current character at finalStartOffset

Просмотреть файл

@ -131,17 +131,23 @@ protected:
nsAString & aText);
/**
* Used by GetPosAndText to move backward/forward from a given point by word/line/etc.
* @param aPresShell, the current presshell we're moving in
* @param aFromFrame, the starting frame we're moving from
* @param aFromOffset, the starting offset we're moving from
* @param aAmount, how much are we moving (word/line/etc.) ?
* @param aDirection, forward or backward?
* @param aNeedsStart, for word and line cases, are we basing this on the start or end?
* @return, the resulting offset into this hypertext
* Used by GetTextHelper() to move backward/forward from a given point
* by word/line/etc.
*
* @param aPresShell the current presshell we're moving in
* @param aFromFrame the starting frame we're moving from
* @param aFromOffset the starting offset we're moving from
* @param aFromAccessible the starting accessible we're moving from
* @param aAmount how much are we moving (word/line/etc.) ?
* @param aDirection forward or backward?
* @param aNeedsStart for word and line cases, are we basing this on
* the start or end?
* @return the resulting offset into this hypertext
*/
PRInt32 GetRelativeOffset(nsIPresShell *aPresShell, nsIFrame *aFromFrame, PRInt32 aFromOffset,
nsSelectionAmount aAmount, nsDirection aDirection, PRBool aNeedsStart);
PRInt32 GetRelativeOffset(nsIPresShell *aPresShell, nsIFrame *aFromFrame,
PRInt32 aFromOffset, nsIAccessible *aFromAccessible,
nsSelectionAmount aAmount, nsDirection aDirection,
PRBool aNeedsStart);
/**
* Provides information for substring that is defined by the given start