Bug 394688. nsIAccessibleText::SetCaretOffset of by characters, affected by source whitespace. r=davidb, a=dsicore

This commit is contained in:
aaronleventhal@moonset.net 2007-09-05 09:38:20 -07:00
parent f109b55a04
commit b0b11ee13f
2 changed files with 34 additions and 6 deletions

View File

@ -57,6 +57,10 @@ interface nsIAccessibleText : nsISupports
const nsAccessibleTextBoundary BOUNDARY_LINE_END = 6;
const nsAccessibleTextBoundary BOUNDARY_ATTRIBUTE_RANGE = 7;
/**
* The current current caret offset.
* If set < 0 then caret will be placed at the end of the text
*/
attribute long caretOffset;
readonly attribute long characterCount;
@ -160,9 +164,13 @@ interface nsIAccessibleText : nsISupports
out long startOffset,
out long endOffset);
/**
* Set the bounds for the given selection range
* Offsets < 0 will be treated as the equal to the end of the text
*/
void setSelectionBounds (in long selectionNum,
in long startOffset,
in long endOffset);
in long startOffset,
in long endOffset);
void addSelection (in long startOffset, in long endOffset);

View File

@ -1495,15 +1495,26 @@ NS_IMETHODIMP nsHyperTextAccessible::SetSelectionBounds(PRInt32 aSelectionNum, P
nsIFrame *startFrame = GetPosAndText(aStartOffset, aEndOffset, nsnull, &endFrame);
NS_ENSURE_TRUE(startFrame, NS_ERROR_FAILURE);
nsCOMPtr<nsIPresShell> shell = GetPresShell();
nsIContent *startParentContent = startFrame->GetContent();
PRInt32 startOffset;
if (startFrame->GetType() != nsAccessibilityAtoms::textFrame) {
nsIContent *newParent = startParentContent->GetParent();
aStartOffset = newParent->IndexOf(startParentContent);
startOffset = newParent->IndexOf(startParentContent);
startParentContent = newParent;
}
else {
// We have a rendered offset into the text frame, and it needs to be
// a content offset for us to set the caret
nsIFrame *startPrimaryFrame =
shell->GetPrimaryFrameFor(startFrame->GetContent());
rv = RenderedToContentOffset(startPrimaryFrame, aStartOffset, &startOffset);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIDOMNode> startParentNode(do_QueryInterface(startParentContent));
NS_ENSURE_TRUE(startParentNode, NS_ERROR_FAILURE);
rv = range->SetStart(startParentNode, aStartOffset);
rv = range->SetStart(startParentNode, startOffset);
NS_ENSURE_SUCCESS(rv, rv);
if (isOnlyCaret) {
@ -1512,14 +1523,23 @@ NS_IMETHODIMP nsHyperTextAccessible::SetSelectionBounds(PRInt32 aSelectionNum, P
}
else {
nsIContent *endParentContent = endFrame->GetContent();
PRInt32 endOffset;
if (endFrame->GetType() != nsAccessibilityAtoms::textFrame) {
nsIContent *newParent = endParentContent->GetParent();
aEndOffset = newParent->IndexOf(endParentContent);
endOffset = newParent->IndexOf(endParentContent);
endParentContent = newParent;
}
else {
// We have a rendered offset into the text frame, and it needs to be
// a content offset for us to set the caret
nsIFrame *endPrimaryFrame =
shell->GetPrimaryFrameFor(endFrame->GetContent());
rv = RenderedToContentOffset(endPrimaryFrame, aEndOffset, &endOffset);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIDOMNode> endParentNode(do_QueryInterface(endParentContent));
NS_ENSURE_TRUE(endParentNode, NS_ERROR_FAILURE);
rv = range->SetEnd(endParentNode, aEndOffset);
rv = range->SetEnd(endParentNode, endOffset);
NS_ENSURE_SUCCESS(rv, rv);
}