diff --git a/accessible/src/html/nsHyperTextAccessible.cpp b/accessible/src/html/nsHyperTextAccessible.cpp
index c1060c317002..31426a26ef29 100644
--- a/accessible/src/html/nsHyperTextAccessible.cpp
+++ b/accessible/src/html/nsHyperTextAccessible.cpp
@@ -47,6 +47,7 @@
#include "States.h"
#include "nsIClipboard.h"
+#include "nsContentUtils.h"
#include "nsFocusManager.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMDocument.h"
@@ -1153,15 +1154,14 @@ nsHyperTextAccessible::GetTextAttributes(bool aIncludeDefAttrs,
// Compute spelling attributes on text accessible only.
nsIFrame *offsetFrame = accAtOffset->GetFrame();
if (offsetFrame && offsetFrame->GetType() == nsGkAtoms::textFrame) {
- nsCOMPtr node = accAtOffset->DOMNode();
-
PRInt32 nodeOffset = 0;
nsresult rv = RenderedToContentOffset(offsetFrame, offsetInAcc,
&nodeOffset);
NS_ENSURE_SUCCESS(rv, rv);
// Set 'misspelled' text attribute.
- rv = GetSpellTextAttribute(node, nodeOffset, &startOffset, &endOffset,
+ rv = GetSpellTextAttribute(accAtOffset->GetNode(), nodeOffset,
+ &startOffset, &endOffset,
aAttributes ? *aAttributes : nsnull);
NS_ENSURE_SUCCESS(rv, rv);
}
@@ -1789,13 +1789,11 @@ nsHyperTextAccessible::GetSelectionDOMRanges(PRInt16 aType,
// Remove collapsed ranges
PRUint32 numRanges = aRanges->Length();
- for (PRUint32 count = 0; count < numRanges; count ++) {
- bool isCollapsed = false;
- (*aRanges)[count]->GetCollapsed(&isCollapsed);
- if (isCollapsed) {
- aRanges->RemoveElementAt(count);
+ for (PRUint32 idx = 0; idx < numRanges; idx ++) {
+ if ((*aRanges)[idx]->Collapsed()) {
+ aRanges->RemoveElementAt(idx);
--numRanges;
- --count;
+ --idx;
}
}
}
@@ -1837,29 +1835,19 @@ nsHyperTextAccessible::GetSelectionBounds(PRInt32 aSelectionNum,
nsRange* range = ranges[aSelectionNum];
- // Get start point
- nsCOMPtr startDOMNode;
- range->GetStartContainer(getter_AddRefs(startDOMNode));
- nsCOMPtr startNode(do_QueryInterface(startDOMNode));
- PRInt32 startOffset = 0;
- range->GetStartOffset(&startOffset);
+ // Get start and end points.
+ nsINode* startNode = range->GetStartParent();
+ nsINode* endNode = range->GetEndParent();
+ PRInt32 startOffset = range->StartOffset(), endOffset = range->EndOffset();
- // Get end point
- nsCOMPtr endDOMNode;
- range->GetEndContainer(getter_AddRefs(endDOMNode));
- nsCOMPtr endNode(do_QueryInterface(endDOMNode));
- PRInt32 endOffset = 0;
- range->GetEndOffset(&endOffset);
-
- PRInt16 rangeCompareResult = 0;
- nsresult rv = range->CompareBoundaryPoints(nsIDOMRange::START_TO_END, range,
- &rangeCompareResult);
- NS_ENSURE_SUCCESS(rv, rv);
-
- if (rangeCompareResult < 0) {
- // Make sure start is before end, by swapping offsets
- // This occurs when the user selects backwards in the text
- startNode.swap(endNode);
+ // Make sure start is before end, by swapping DOM points. This occurs when
+ // the user selects backwards in the text.
+ PRInt32 rangeCompare = nsContentUtils::ComparePoints(endNode, endOffset,
+ startNode, startOffset);
+ if (rangeCompare < 0) {
+ nsINode* tempNode = startNode;
+ startNode = endNode;
+ endNode = tempNode;
PRInt32 tempOffset = startOffset;
startOffset = endOffset;
endOffset = tempOffset;
@@ -2324,25 +2312,17 @@ nsHyperTextAccessible::RangeBoundToHypertextOffset(nsRange *aRange,
bool aIsStartHTOffset,
PRInt32 *aHTOffset)
{
- nsCOMPtr DOMNode;
+ nsINode* node = nsnull;
PRInt32 nodeOffset = 0;
- nsresult rv;
if (aIsStartBound) {
- rv = aRange->GetStartContainer(getter_AddRefs(DOMNode));
- NS_ENSURE_SUCCESS(rv, rv);
-
- rv = aRange->GetStartOffset(&nodeOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ node = aRange->GetStartParent();
+ nodeOffset = aRange->StartOffset();
} else {
- rv = aRange->GetEndContainer(getter_AddRefs(DOMNode));
- NS_ENSURE_SUCCESS(rv, rv);
-
- rv = aRange->GetEndOffset(&nodeOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ node = aRange->GetEndParent();
+ nodeOffset = aRange->EndOffset();
}
- nsCOMPtr node(do_QueryInterface(DOMNode));
nsAccessible *startAcc =
DOMPointToHypertextOffset(node, nodeOffset, aHTOffset);
@@ -2354,7 +2334,7 @@ nsHyperTextAccessible::RangeBoundToHypertextOffset(nsRange *aRange,
// nsHyperTextAccessible
nsresult
-nsHyperTextAccessible::GetSpellTextAttribute(nsIDOMNode *aNode,
+nsHyperTextAccessible::GetSpellTextAttribute(nsINode* aNode,
PRInt32 aNodeOffset,
PRInt32 *aHTStartOffset,
PRInt32 *aHTEndOffset,
@@ -2367,25 +2347,19 @@ nsHyperTextAccessible::GetSpellTextAttribute(nsIDOMNode *aNode,
if (!rangeCount)
return NS_OK;
+ nsCOMPtr DOMNode = do_QueryInterface(aNode);
for (PRUint32 index = 0; index < rangeCount; index++) {
nsRange* range = ranges[index];
PRInt16 result;
- nsresult rv = range->ComparePoint(aNode, aNodeOffset, &result);
+ nsresult rv = range->ComparePoint(DOMNode, aNodeOffset, &result);
NS_ENSURE_SUCCESS(rv, rv);
// ComparePoint checks boundary points, but we need to check that
// text at aNodeOffset is inside the range.
// See also bug 460690.
if (result == 0) {
- nsCOMPtr end;
- rv = range->GetEndContainer(getter_AddRefs(end));
- NS_ENSURE_SUCCESS(rv, rv);
- PRInt32 endOffset;
- rv = range->GetEndOffset(&endOffset);
- NS_ENSURE_SUCCESS(rv, rv);
- if (aNode == end && aNodeOffset == endOffset) {
+ if (aNode == range->GetEndParent() && aNodeOffset == range->EndOffset())
result = 1;
- }
}
if (result == 1) { // range is before point
diff --git a/accessible/src/html/nsHyperTextAccessible.h b/accessible/src/html/nsHyperTextAccessible.h
index 44e93ca4cfe8..a53d20bb7b76 100644
--- a/accessible/src/html/nsHyperTextAccessible.h
+++ b/accessible/src/html/nsHyperTextAccessible.h
@@ -409,7 +409,7 @@ protected:
* @param aEndOffset [in, out] the end offset
* @param aAttributes [out, optional] result attributes
*/
- nsresult GetSpellTextAttribute(nsIDOMNode *aNode, PRInt32 aNodeOffset,
+ nsresult GetSpellTextAttribute(nsINode* aNode, PRInt32 aNodeOffset,
PRInt32 *aStartOffset,
PRInt32 *aEndOffset,
nsIPersistentProperties *aAttributes);