summaryrefslogtreecommitdiffstats
path: root/editor/libeditor
diff options
context:
space:
mode:
Diffstat (limited to 'editor/libeditor')
-rw-r--r--editor/libeditor/EditorBase.cpp6
-rw-r--r--editor/libeditor/HTMLEditRules.cpp67
-rw-r--r--editor/libeditor/HTMLEditor.cpp10
-rw-r--r--editor/libeditor/HTMLEditorDataTransfer.cpp7
-rw-r--r--editor/libeditor/HTMLStyleEditor.cpp2
-rw-r--r--editor/libeditor/HTMLTableEditor.cpp15
6 files changed, 55 insertions, 52 deletions
diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp
index 5df4ff2c4..27983df31 100644
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -5275,7 +5275,7 @@ EditorBase::GetIMESelectionStartOffsetIn(nsINode* aTextNode)
return -1;
}
- int32_t minOffset = INT32_MAX;
+ uint32_t minOffset = UINT32_MAX;
static const SelectionType kIMESelectionTypes[] = {
SelectionType::eIMERawClause,
SelectionType::eIMESelectedRawClause,
@@ -5295,15 +5295,11 @@ EditorBase::GetIMESelectionStartOffsetIn(nsINode* aTextNode)
if (NS_WARN_IF(range->GetStartParent() != aTextNode)) {
// ignore the start offset...
} else {
- MOZ_ASSERT(range->StartOffset() >= 0,
- "start offset shouldn't be negative");
minOffset = std::min(minOffset, range->StartOffset());
}
if (NS_WARN_IF(range->GetEndParent() != aTextNode)) {
// ignore the end offset...
} else {
- MOZ_ASSERT(range->EndOffset() >= 0,
- "start offset shouldn't be negative");
minOffset = std::min(minOffset, range->EndOffset());
}
}
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);
diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index fd11d1a45..766ab81cf 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2405,21 +2405,19 @@ HTMLEditor::GetSelectedElement(const nsAString& aTagName,
NS_ENSURE_STATE(range);
nsCOMPtr<nsIDOMNode> startParent;
- int32_t startOffset, endOffset;
nsresult rv = range->GetStartContainer(getter_AddRefs(startParent));
NS_ENSURE_SUCCESS(rv, rv);
- rv = range->GetStartOffset(&startOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ uint32_t startOffset = range->StartOffset();
nsCOMPtr<nsIDOMNode> endParent;
rv = range->GetEndContainer(getter_AddRefs(endParent));
NS_ENSURE_SUCCESS(rv, rv);
- rv = range->GetEndOffset(&endOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ uint32_t endOffset = range->EndOffset();
// Optimization for a single selected element
if (startParent && startParent == endParent && endOffset - startOffset == 1) {
- nsCOMPtr<nsIDOMNode> selectedNode = GetChildAt(startParent, startOffset);
+ nsCOMPtr<nsIDOMNode> selectedNode =
+ GetChildAt(startParent, static_cast<int32_t>(startOffset));
NS_ENSURE_SUCCESS(rv, NS_OK);
if (selectedNode) {
selectedNode->GetNodeName(domTagName);
diff --git a/editor/libeditor/HTMLEditorDataTransfer.cpp b/editor/libeditor/HTMLEditorDataTransfer.cpp
index c56fbead7..0c01bdd1c 100644
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -145,14 +145,13 @@ HTMLEditor::LoadHTML(const nsAString& aInputString)
rv = range->GetStartContainer(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
- int32_t childOffset;
- rv = range->GetStartOffset(&childOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ uint32_t childOffset = range->StartOffset();
nsCOMPtr<nsIDOMNode> nodeToInsert;
docfrag->GetFirstChild(getter_AddRefs(nodeToInsert));
while (nodeToInsert) {
- rv = InsertNode(nodeToInsert, parent, childOffset++);
+ rv = InsertNode(nodeToInsert, parent,
+ static_cast<int32_t>(childOffset++));
NS_ENSURE_SUCCESS(rv, rv);
docfrag->GetFirstChild(getter_AddRefs(nodeToInsert));
}
diff --git a/editor/libeditor/HTMLStyleEditor.cpp b/editor/libeditor/HTMLStyleEditor.cpp
index 7141cfd61..7d1217069 100644
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -1078,7 +1078,7 @@ HTMLEditor::GetInlinePropertyBase(nsIAtom& aProperty,
if (content->GetAsText()) {
if (!isCollapsed && first && firstNodeInRange) {
firstNodeInRange = false;
- if (range->StartOffset() == (int32_t)content->Length()) {
+ if (range->StartOffset() == content->Length()) {
continue;
}
} else if (content == endNode && !endOffset) {
diff --git a/editor/libeditor/HTMLTableEditor.cpp b/editor/libeditor/HTMLTableEditor.cpp
index 06d6cae26..b26466179 100644
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -2932,11 +2932,10 @@ HTMLEditor::GetCellFromRange(nsRange* aRange,
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(startParent, NS_ERROR_FAILURE);
- int32_t startOffset;
- rv = aRange->GetStartOffset(&startOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ uint32_t startOffset = aRange->StartOffset();
- nsCOMPtr<nsIDOMNode> childNode = GetChildAt(startParent, startOffset);
+ nsCOMPtr<nsIDOMNode> childNode =
+ GetChildAt(startParent, static_cast<int32_t>(startOffset));
// This means selection is probably at a text node (or end of doc?)
if (!childNode) {
return NS_ERROR_FAILURE;
@@ -2947,15 +2946,11 @@ HTMLEditor::GetCellFromRange(nsRange* aRange,
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(startParent, NS_ERROR_FAILURE);
- int32_t endOffset;
- rv = aRange->GetEndOffset(&endOffset);
- NS_ENSURE_SUCCESS(rv, rv);
-
// If a cell is deleted, the range is collapse
- // (startOffset == endOffset)
+ // (startOffset == aRange->EndOffset())
// so tell caller the cell wasn't found
if (startParent == endParent &&
- endOffset == startOffset+1 &&
+ aRange->EndOffset() == startOffset+1 &&
HTMLEditUtils::IsTableCell(childNode)) {
// Should we also test if frame is selected? (Use GetCellDataAt())
// (Let's not for now -- more efficient)