summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/HTMLEditRules.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-04-17 06:10:23 -0400
committerMatt A. Tobin <email@mattatobin.com>2020-04-17 06:10:23 -0400
commit70c8ff8e5af7d2661b64fb92a158f2860af7766c (patch)
treee7fd37d81858a7dfa06fbf59880d837d9e7fa256 /editor/libeditor/HTMLEditRules.cpp
parent53428ad3f04ff1e01f0596ef0c592bdbe5fdd15b (diff)
downloadUXP-70c8ff8e5af7d2661b64fb92a158f2860af7766c.tar
UXP-70c8ff8e5af7d2661b64fb92a158f2860af7766c.tar.gz
UXP-70c8ff8e5af7d2661b64fb92a158f2860af7766c.tar.lz
UXP-70c8ff8e5af7d2661b64fb92a158f2860af7766c.tar.xz
UXP-70c8ff8e5af7d2661b64fb92a158f2860af7766c.zip
Bug 1377978 - Make nsRange use uint32_t to offset
Tag #1375
Diffstat (limited to 'editor/libeditor/HTMLEditRules.cpp')
-rw-r--r--editor/libeditor/HTMLEditRules.cpp67
1 files changed, 41 insertions, 26 deletions
diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp
index c97ebf27f..805092eb7 100644
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -427,7 +427,7 @@ HTMLEditRules::AfterEditInner(EditAction action,
NS_ENSURE_STATE(selection);
nsCOMPtr<nsIDOMNode> rangeStartParent, rangeEndParent;
- int32_t rangeStartOffset = 0, rangeEndOffset = 0;
+ uint32_t rangeStartOffset = 0, rangeEndOffset = 0;
// do we have a real range to act on?
bool bDamagedRange = false;
if (mDocChangeRange) {
@@ -535,8 +535,8 @@ HTMLEditRules::AfterEditInner(EditAction action,
mHTMLEditor->HandleInlineSpellCheck(action, selection,
GetAsDOMNode(mRangeItem->startNode),
mRangeItem->startOffset,
- rangeStartParent, rangeStartOffset,
- rangeEndParent, rangeEndOffset);
+ rangeStartParent, static_cast<int32_t>(rangeStartOffset),
+ rangeEndParent, static_cast<int32_t>(rangeEndOffset));
NS_ENSURE_SUCCESS(rv, rv);
// detect empty doc
@@ -5151,9 +5151,8 @@ HTMLEditRules::NormalizeSelection(Selection* inSelection)
RefPtr<nsRange> range = inSelection->GetRangeAt(0);
NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMNode> startNode, endNode;
- int32_t startOffset, endOffset;
+ uint32_t startOffset, endOffset;
nsCOMPtr<nsIDOMNode> newStartNode, newEndNode;
- int32_t newStartOffset, newEndOffset;
rv = range->GetStartContainer(getter_AddRefs(startNode));
NS_ENSURE_SUCCESS(rv, rv);
@@ -5166,22 +5165,22 @@ HTMLEditRules::NormalizeSelection(Selection* inSelection)
// adjusted values default to original values
newStartNode = startNode;
- newStartOffset = startOffset;
+ uint32_t newStartOffset = startOffset;
newEndNode = endNode;
- newEndOffset = endOffset;
+ uint32_t newEndOffset = endOffset;
// some locals we need for whitespace code
nsCOMPtr<nsINode> unused;
- int32_t offset;
+ int32_t offset = -1;
WSType wsType;
// let the whitespace code do the heavy lifting
- WSRunObject wsEndObj(mHTMLEditor, endNode, endOffset);
+ WSRunObject wsEndObj(mHTMLEditor, endNode, static_cast<int32_t>(endOffset));
// is there any intervening visible whitespace? if so we can't push selection past that,
// it would visibly change maening of users selection
nsCOMPtr<nsINode> endNode_(do_QueryInterface(endNode));
- wsEndObj.PriorVisibleNode(endNode_, endOffset, address_of(unused),
- &offset, &wsType);
+ wsEndObj.PriorVisibleNode(endNode_, static_cast<int32_t>(endOffset),
+ address_of(unused), &offset, &wsType);
if (wsType != WSType::text && wsType != WSType::normalWS) {
// eThisBlock and eOtherBlock conveniently distinquish cases
// of going "down" into a block and "up" out of a block.
@@ -5191,36 +5190,44 @@ HTMLEditRules::NormalizeSelection(Selection* inSelection)
GetAsDOMNode(mHTMLEditor->GetRightmostChild(wsEndObj.mStartReasonNode,
true));
if (child) {
- newEndNode = EditorBase::GetNodeLocation(child, &newEndOffset);
- ++newEndOffset; // offset *after* child
+ int32_t offset = -1;
+ newEndNode = EditorBase::GetNodeLocation(child, &offset);
+ // offset *after* child
+ newEndOffset = static_cast<uint32_t>(offset + 1);
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsEndObj.mStartReason == WSType::thisBlock) {
// endpoint is just after start of this block
nsCOMPtr<nsIDOMNode> child;
NS_ENSURE_STATE(mHTMLEditor);
- mHTMLEditor->GetPriorHTMLNode(endNode, endOffset, address_of(child));
+ mHTMLEditor->GetPriorHTMLNode(endNode, static_cast<int32_t>(endOffset),
+ address_of(child));
if (child) {
- newEndNode = EditorBase::GetNodeLocation(child, &newEndOffset);
- ++newEndOffset; // offset *after* child
+ int32_t offset = -1;
+ newEndNode = EditorBase::GetNodeLocation(child, &offset);
+ // offset *after* child
+ newEndOffset = static_cast<uint32_t>(offset + 1);
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsEndObj.mStartReason == WSType::br) {
// endpoint is just after break. lets adjust it to before it.
+ int32_t offset = -1;
newEndNode =
EditorBase::GetNodeLocation(GetAsDOMNode(wsEndObj.mStartReasonNode),
- &newEndOffset);
+ &offset);
+ newEndOffset = static_cast<uint32_t>(offset);;
}
}
// similar dealio for start of range
- WSRunObject wsStartObj(mHTMLEditor, startNode, startOffset);
+ WSRunObject wsStartObj(mHTMLEditor, startNode,
+ static_cast<int32_t>(startOffset));
// is there any intervening visible whitespace? if so we can't push selection past that,
// it would visibly change maening of users selection
nsCOMPtr<nsINode> startNode_(do_QueryInterface(startNode));
- wsStartObj.NextVisibleNode(startNode_, startOffset, address_of(unused),
- &offset, &wsType);
+ wsStartObj.NextVisibleNode(startNode_, static_cast<int32_t>(startOffset),
+ address_of(unused), &offset, &wsType);
if (wsType != WSType::text && wsType != WSType::normalWS) {
// eThisBlock and eOtherBlock conveniently distinquish cases
// of going "down" into a block and "up" out of a block.
@@ -5230,23 +5237,31 @@ HTMLEditRules::NormalizeSelection(Selection* inSelection)
GetAsDOMNode(mHTMLEditor->GetLeftmostChild(wsStartObj.mEndReasonNode,
true));
if (child) {
- newStartNode = EditorBase::GetNodeLocation(child, &newStartOffset);
+ int32_t offset = -1;
+ newStartNode = EditorBase::GetNodeLocation(child, &offset);
+ newStartOffset = static_cast<uint32_t>(offset);
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsStartObj.mEndReason == WSType::thisBlock) {
// startpoint is just before end of this block
nsCOMPtr<nsIDOMNode> child;
NS_ENSURE_STATE(mHTMLEditor);
- mHTMLEditor->GetNextHTMLNode(startNode, startOffset, address_of(child));
+ mHTMLEditor->GetNextHTMLNode(startNode, static_cast<int32_t>(startOffset),
+ address_of(child));
if (child) {
- newStartNode = EditorBase::GetNodeLocation(child, &newStartOffset);
+ int32_t offset = -1;
+ newStartNode = EditorBase::GetNodeLocation(child, &offset);
+ newStartOffset = static_cast<uint32_t>(offset);
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsStartObj.mEndReason == WSType::br) {
// startpoint is just before a break. lets adjust it to after it.
+ int32_t offset = -1;
newStartNode =
EditorBase::GetNodeLocation(GetAsDOMNode(wsStartObj.mEndReasonNode),
- &newStartOffset);
+ &offset);
+ // offset *after* break
+ newStartOffset = static_cast<uint32_t>(offset + 1);
++newStartOffset; // offset *after* break
}
}
@@ -7974,7 +7989,7 @@ HTMLEditRules::UpdateDocChangeRange(nsRange* aRange)
NS_ENSURE_SUCCESS(rv, rv);
// Positive result means mDocChangeRange start is after aRange start.
if (result > 0) {
- int32_t startOffset;
+ uint32_t startOffset;
rv = aRange->GetStartOffset(&startOffset);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDocChangeRange->SetStart(startNode, startOffset);
@@ -7988,9 +8003,9 @@ HTMLEditRules::UpdateDocChangeRange(nsRange* aRange)
// Negative result means mDocChangeRange end is before aRange end.
if (result < 0) {
nsCOMPtr<nsIDOMNode> endNode;
- int32_t endOffset;
rv = aRange->GetEndContainer(getter_AddRefs(endNode));
NS_ENSURE_SUCCESS(rv, rv);
+ uint32_t endOffset;
rv = aRange->GetEndOffset(&endOffset);
NS_ENSURE_SUCCESS(rv, rv);
rv = mDocChangeRange->SetEnd(endNode, endOffset);