From 70c8ff8e5af7d2661b64fb92a158f2860af7766c Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 06:10:23 -0400 Subject: Bug 1377978 - Make nsRange use uint32_t to offset Tag #1375 --- editor/txtsvc/nsTextServicesDocument.cpp | 47 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'editor/txtsvc/nsTextServicesDocument.cpp') diff --git a/editor/txtsvc/nsTextServicesDocument.cpp b/editor/txtsvc/nsTextServicesDocument.cpp index ccf964d2c..23a1bec3f 100644 --- a/editor/txtsvc/nsTextServicesDocument.cpp +++ b/editor/txtsvc/nsTextServicesDocument.cpp @@ -510,7 +510,6 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, nsCOMPtr iter; RefPtr range; nsCOMPtr parent; - int32_t rangeCount, offset; if (isCollapsed) { // We have a caret. Check if the caret is in a text node. @@ -537,6 +536,7 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, return NS_ERROR_FAILURE; } + uint32_t offset; rv = range->GetStartOffset(&offset); if (NS_FAILED(rv)) { @@ -596,8 +596,9 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, // position to the end of the document, then walk forwards // till you find a text node, then find the beginning of it's block. - rv = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false, - getter_AddRefs(range)); + rv = CreateDocumentContentRootToNodeOffsetRange( + parent, static_cast(offset), false, + getter_AddRefs(range)); if (NS_FAILED(rv)) { UNLOCK_DOC(this); @@ -690,6 +691,7 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, // beginning of its text block, and make it the current // block. + int32_t rangeCount; rv = selection->GetRangeCount(&rangeCount); if (NS_FAILED(rv)) { @@ -797,6 +799,7 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, return NS_ERROR_FAILURE; } + uint32_t offset; rv = range->GetEndOffset(&offset); if (NS_FAILED(rv)) { @@ -804,8 +807,8 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, return rv; } - rv = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false, - getter_AddRefs(range)); + rv = CreateDocumentContentRootToNodeOffsetRange( + parent, static_cast(offset), false, getter_AddRefs(range)); if (NS_FAILED(rv)) { UNLOCK_DOC(this); @@ -2377,14 +2380,16 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS nsCOMPtr parent = do_QueryInterface(domParent); MOZ_ASSERT(parent); - int32_t offset; + uint32_t offset; rv = range->GetStartOffset(&offset); NS_ENSURE_SUCCESS(rv, rv); int32_t e1s1 = nsContentUtils::ComparePoints(eStart->mNode, eStartOffset, - domParent, offset); + domParent, + static_cast(offset)); int32_t e2s1 = nsContentUtils::ComparePoints(eEnd->mNode, eEndOffset, - domParent, offset); + domParent, + static_cast(offset)); if (e1s1 > 0 || e2s1 < 0) { // We're done if the caret is outside the current text block. @@ -2401,8 +2406,8 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE); if (entry->mNode == domParent.get() && - entry->mNodeOffset <= offset && - offset <= entry->mNodeOffset + entry->mLength) { + entry->mNodeOffset <= static_cast(offset) && + static_cast(offset) <= entry->mNodeOffset + entry->mLength) { *aSelStatus = nsITextServicesDocument::eBlockContains; *aSelOffset = entry->mStrOffset + (offset - entry->mNodeOffset); *aSelLength = 0; @@ -2440,7 +2445,7 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS // If the parent has children, position the iterator // on the child that is to the left of the offset. - uint32_t childIndex = (uint32_t)offset; + uint32_t childIndex = offset; if (childIndex > 0) { uint32_t numChildren = parent->GetChildCount(); @@ -2526,8 +2531,8 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE); if (entry->mNode == node->AsDOMNode() && - entry->mNodeOffset <= offset && - offset <= entry->mNodeOffset + entry->mLength) { + entry->mNodeOffset <= static_cast(offset) && + static_cast(offset) <= entry->mNodeOffset + entry->mLength) { *aSelStatus = nsITextServicesDocument::eBlockContains; *aSelOffset = entry->mStrOffset + (offset - entry->mNodeOffset); *aSelLength = 0; @@ -2817,9 +2822,12 @@ nsTextServicesDocument::GetRangeEndPoints(nsRange* aRange, NS_ENSURE_TRUE(aStartParent, NS_ERROR_FAILURE); - rv = aRange->GetStartOffset(aStartOffset); - - NS_ENSURE_SUCCESS(rv, rv); + uint32_t offset; + rv = aRange->GetStartOffset(&offset); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + *aStartOffset = static_cast(offset); rv = aRange->GetEndContainer(aEndParent); @@ -2827,7 +2835,12 @@ nsTextServicesDocument::GetRangeEndPoints(nsRange* aRange, NS_ENSURE_TRUE(aEndParent, NS_ERROR_FAILURE); - return aRange->GetEndOffset(aEndOffset); + rv = aRange->GetEndOffset(&offset); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + *aEndOffset = static_cast(offset); + return NS_OK; } nsresult -- cgit v1.2.3