зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1377978 - Make nsRange use uint32_t to offset r=smaug
DOM Standard defines that offset of Range is unsigned long. However, nsRange uses int32_t to them. This patch makes nsRange use uint32_t instead. However, this patch does NOT allow to set over INT32_MAX as offset values since a lot of users of nsRange cannot treat the values as over INT32_MAX because a lot of internal APIs take int32_t as offsets. For easier to search such points, this patch adds static_cast<int32_t> to uint32_t variables when they are used for int32_t arguments. And note that nsContentUtils::ComparePoints() behaves odd. It accepts negative offset and compares such value with valid offset simply. This patch still uses int32_t offset variables in nsRange::CompareNodeToRange() even though it may be negative value if nsINode::IndexOf() returns -1 because the caller of it depends on this behavior. MozReview-Commit-ID: 8RbOgA86JuT --HG-- extra : rebase_source : 46d526c6d50dfa2f104439b19b8691477b17a4af
This commit is contained in:
Родитель
864962970b
Коммит
2f92264fb7
|
@ -1402,13 +1402,14 @@ static inline bool
|
|||
RangeMatchesBeginPoint(nsRange* aRange, nsINode* aNode, int32_t aOffset)
|
||||
{
|
||||
return aRange->GetStartContainer() == aNode &&
|
||||
aRange->StartOffset() == aOffset;
|
||||
static_cast<int32_t>(aRange->StartOffset()) == aOffset;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
RangeMatchesEndPoint(nsRange* aRange, nsINode* aNode, int32_t aOffset)
|
||||
{
|
||||
return aRange->GetEndContainer() == aNode && aRange->EndOffset() == aOffset;
|
||||
return aRange->GetEndContainer() == aNode &&
|
||||
static_cast<int32_t>(aRange->EndOffset()) == aOffset;
|
||||
}
|
||||
|
||||
// Selection::EqualsRangeAtPoint
|
||||
|
|
|
@ -2774,6 +2774,9 @@ nsContentUtils::ComparePoints(nsINode* aParent1, int32_t aOffset1,
|
|||
bool* aDisconnected)
|
||||
{
|
||||
if (aParent1 == aParent2) {
|
||||
// XXX This is odd. aOffset1 and/or aOffset2 may be -1, e.g., it's result
|
||||
// of nsINode::IndexOf(), but this compares such invalid offset with
|
||||
// valid offset.
|
||||
return aOffset1 < aOffset2 ? -1 :
|
||||
aOffset1 > aOffset2 ? 1 :
|
||||
0;
|
||||
|
@ -2824,10 +2827,14 @@ nsContentUtils::ComparePoints(nsINode* aParent1, int32_t aOffset1,
|
|||
|
||||
if (!pos1) {
|
||||
nsINode* child2 = parents2.ElementAt(--pos2);
|
||||
// XXX aOffset1 may be -1 as mentioned above. So, why does this return
|
||||
// it's *before* of the valid DOM point?
|
||||
return aOffset1 <= parent->IndexOf(child2) ? -1 : 1;
|
||||
}
|
||||
|
||||
nsINode* child1 = parents1.ElementAt(--pos1);
|
||||
// XXX aOffset2 may be -1 as mentioned above. So, why does this return it's
|
||||
// *after* of the valid DOM point?
|
||||
return parent->IndexOf(child1) < aOffset2 ? -1 : 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -404,6 +404,13 @@ public:
|
|||
* NOTE! If the two nodes aren't in the same connected subtree,
|
||||
* the result is 1, and the optional aDisconnected parameter
|
||||
* is set to true.
|
||||
*
|
||||
* XXX aOffset1 and aOffset2 should be uint32_t since valid offset value is
|
||||
* between 0 - UINT32_MAX. However, these methods work even with
|
||||
* negative offset values! E.g., when aOffset1 is -1 and aOffset is 0,
|
||||
* these methods return -1. Some root callers depend on this behavior.
|
||||
* On the other hand, nsINode can have ATTRCHILD_ARRAY_MAX_CHILD_COUN
|
||||
* (0x3FFFFF) at most. Therefore, they can be int32_t for now.
|
||||
*/
|
||||
static int32_t ComparePoints(nsINode* aParent1, int32_t aOffset1,
|
||||
nsINode* aParent2, int32_t aOffset2,
|
||||
|
|
|
@ -1569,10 +1569,13 @@ nsHTMLCopyEncoder::IncludeInContext(nsINode *aNode)
|
|||
nsresult
|
||||
nsHTMLCopyEncoder::PromoteRange(nsIDOMRange *inRange)
|
||||
{
|
||||
if (!inRange) return NS_ERROR_NULL_POINTER;
|
||||
RefPtr<nsRange> range = static_cast<nsRange*>(inRange);
|
||||
if (!range) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMNode> startNode, endNode, common;
|
||||
int32_t startOffset, endOffset;
|
||||
uint32_t startOffset, endOffset;
|
||||
|
||||
rv = inRange->GetCommonAncestorContainer(getter_AddRefs(common));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -1590,9 +1593,11 @@ nsHTMLCopyEncoder::PromoteRange(nsIDOMRange *inRange)
|
|||
int32_t opStartOffset, opEndOffset;
|
||||
|
||||
// examine range endpoints.
|
||||
rv = GetPromotedPoint( kStart, startNode, startOffset, address_of(opStartNode), &opStartOffset, common);
|
||||
rv = GetPromotedPoint(kStart, startNode, static_cast<int32_t>(startOffset),
|
||||
address_of(opStartNode), &opStartOffset, common);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = GetPromotedPoint( kEnd, endNode, endOffset, address_of(opEndNode), &opEndOffset, common);
|
||||
rv = GetPromotedPoint(kEnd, endNode, static_cast<int32_t>(endOffset),
|
||||
address_of(opEndNode), &opEndOffset, common);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// if both range endpoints are at the common ancestor, check for possible inclusion of ancestors
|
||||
|
@ -1604,9 +1609,9 @@ nsHTMLCopyEncoder::PromoteRange(nsIDOMRange *inRange)
|
|||
}
|
||||
|
||||
// set the range to the new values
|
||||
rv = inRange->SetStart(opStartNode, opStartOffset);
|
||||
rv = inRange->SetStart(opStartNode, static_cast<uint32_t>(opStartOffset));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = inRange->SetEnd(opEndNode, opEndOffset);
|
||||
rv = inRange->SetEnd(opEndNode, static_cast<uint32_t>(opEndOffset));
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -2512,7 +2512,7 @@ nsFocusManager::GetSelectionLocation(nsIDocument* aDocument,
|
|||
nsCOMPtr<nsIDOMNode> startNode, endNode;
|
||||
bool isCollapsed = false;
|
||||
nsCOMPtr<nsIContent> startContent, endContent;
|
||||
int32_t startOffset = 0;
|
||||
uint32_t startOffset = 0;
|
||||
if (domSelection) {
|
||||
domSelection->GetIsCollapsed(&isCollapsed);
|
||||
nsCOMPtr<nsIDOMRange> domRange;
|
||||
|
@ -2526,7 +2526,6 @@ nsFocusManager::GetSelectionLocation(nsIDocument* aDocument,
|
|||
|
||||
startContent = do_QueryInterface(startNode);
|
||||
if (startContent && startContent->IsElement()) {
|
||||
NS_ASSERTION(startOffset >= 0, "Start offset cannot be negative");
|
||||
childContent = startContent->GetChildAt(startOffset);
|
||||
if (childContent) {
|
||||
startContent = childContent;
|
||||
|
@ -2535,9 +2534,8 @@ nsFocusManager::GetSelectionLocation(nsIDocument* aDocument,
|
|||
|
||||
endContent = do_QueryInterface(endNode);
|
||||
if (endContent && endContent->IsElement()) {
|
||||
int32_t endOffset = 0;
|
||||
uint32_t endOffset = 0;
|
||||
domRange->GetEndOffset(&endOffset);
|
||||
NS_ASSERTION(endOffset >= 0, "End offset cannot be negative");
|
||||
childContent = endContent->GetChildAt(endOffset);
|
||||
if (childContent) {
|
||||
endContent = childContent;
|
||||
|
@ -2565,7 +2563,7 @@ nsFocusManager::GetSelectionLocation(nsIDocument* aDocument,
|
|||
bool isFormControl =
|
||||
startContent->IsNodeOfType(nsINode::eHTML_FORM_CONTROL);
|
||||
|
||||
if (nodeValue.Length() == (uint32_t)startOffset && !isFormControl &&
|
||||
if (nodeValue.Length() == startOffset && !isFormControl &&
|
||||
startContent != aDocument->GetRootElement()) {
|
||||
// Yes, indeed we were at the end of the last node
|
||||
nsCOMPtr<nsIFrameEnumerator> frameTraversal;
|
||||
|
|
|
@ -111,31 +111,37 @@ nsRange::CompareNodeToRange(nsINode* aNode, nsRange* aRange,
|
|||
// so instead represent it by (node,0) and (node,numChildren)
|
||||
parent = aNode;
|
||||
nodeStart = 0;
|
||||
nodeEnd = aNode->GetChildCount();
|
||||
uint32_t childCount = aNode->GetChildCount();
|
||||
MOZ_ASSERT(childCount <= INT32_MAX,
|
||||
"There shouldn't be over INT32_MAX children");
|
||||
nodeEnd = static_cast<int32_t>(childCount);
|
||||
}
|
||||
else {
|
||||
nodeStart = parent->IndexOf(aNode);
|
||||
nodeEnd = nodeStart + 1;
|
||||
MOZ_ASSERT(nodeStart < nodeEnd, "nodeStart shouldn't be INT32_MAX");
|
||||
}
|
||||
|
||||
nsINode* rangeStartContainer = aRange->GetStartContainer();
|
||||
nsINode* rangeEndContainer = aRange->GetEndContainer();
|
||||
int32_t rangeStartOffset = aRange->StartOffset();
|
||||
int32_t rangeEndOffset = aRange->EndOffset();
|
||||
uint32_t rangeStartOffset = aRange->StartOffset();
|
||||
uint32_t rangeEndOffset = aRange->EndOffset();
|
||||
|
||||
// is RANGE(start) <= NODE(start) ?
|
||||
bool disconnected = false;
|
||||
*outNodeBefore = nsContentUtils::ComparePoints(rangeStartContainer,
|
||||
rangeStartOffset,
|
||||
parent, nodeStart,
|
||||
&disconnected) > 0;
|
||||
*outNodeBefore =
|
||||
nsContentUtils::ComparePoints(rangeStartContainer,
|
||||
static_cast<int32_t>(rangeStartOffset),
|
||||
parent, nodeStart,
|
||||
&disconnected) > 0;
|
||||
NS_ENSURE_TRUE(!disconnected, NS_ERROR_DOM_WRONG_DOCUMENT_ERR);
|
||||
|
||||
// is RANGE(end) >= NODE(end) ?
|
||||
*outNodeAfter = nsContentUtils::ComparePoints(rangeEndContainer,
|
||||
rangeEndOffset,
|
||||
parent, nodeEnd,
|
||||
&disconnected) < 0;
|
||||
*outNodeAfter =
|
||||
nsContentUtils::ComparePoints(rangeEndContainer,
|
||||
static_cast<int32_t>(rangeEndOffset),
|
||||
parent, nodeEnd,
|
||||
&disconnected) < 0;
|
||||
NS_ENSURE_TRUE(!disconnected, NS_ERROR_DOM_WRONG_DOCUMENT_ERR);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -164,13 +170,17 @@ struct IsItemInRangeComparator
|
|||
|
||||
int operator()(const nsRange* const aRange) const
|
||||
{
|
||||
int32_t cmp = nsContentUtils::ComparePoints(mNode, mEndOffset,
|
||||
aRange->GetStartContainer(),
|
||||
aRange->StartOffset());
|
||||
int32_t cmp =
|
||||
nsContentUtils::ComparePoints(
|
||||
mNode, static_cast<int32_t>(mEndOffset),
|
||||
aRange->GetStartContainer(),
|
||||
static_cast<int32_t>(aRange->StartOffset()));
|
||||
if (cmp == 1) {
|
||||
cmp = nsContentUtils::ComparePoints(mNode, mStartOffset,
|
||||
aRange->GetEndContainer(),
|
||||
aRange->EndOffset());
|
||||
cmp =
|
||||
nsContentUtils::ComparePoints(
|
||||
mNode, static_cast<int32_t>(mStartOffset),
|
||||
aRange->GetEndContainer(),
|
||||
static_cast<int32_t>(aRange->EndOffset()));
|
||||
if (cmp == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -266,8 +276,8 @@ nsRange::nsRange(nsINode* aNode)
|
|||
|
||||
/* static */
|
||||
nsresult
|
||||
nsRange::CreateRange(nsINode* aStartContainer, int32_t aStartOffset,
|
||||
nsINode* aEndParent, int32_t aEndOffset,
|
||||
nsRange::CreateRange(nsINode* aStartContainer, uint32_t aStartOffset,
|
||||
nsINode* aEndParent, uint32_t aEndOffset,
|
||||
nsRange** aRange)
|
||||
{
|
||||
MOZ_ASSERT(aRange);
|
||||
|
@ -285,8 +295,8 @@ nsRange::CreateRange(nsINode* aStartContainer, int32_t aStartOffset,
|
|||
|
||||
/* static */
|
||||
nsresult
|
||||
nsRange::CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
|
||||
nsIDOMNode* aEndParent, int32_t aEndOffset,
|
||||
nsRange::CreateRange(nsIDOMNode* aStartContainer, uint32_t aStartOffset,
|
||||
nsIDOMNode* aEndParent, uint32_t aEndOffset,
|
||||
nsRange** aRange)
|
||||
{
|
||||
nsCOMPtr<nsINode> startContainer = do_QueryInterface(aStartContainer);
|
||||
|
@ -297,8 +307,8 @@ nsRange::CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
|
|||
|
||||
/* static */
|
||||
nsresult
|
||||
nsRange::CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
|
||||
nsIDOMNode* aEndParent, int32_t aEndOffset,
|
||||
nsRange::CreateRange(nsIDOMNode* aStartContainer, uint32_t aStartOffset,
|
||||
nsIDOMNode* aEndParent, uint32_t aEndOffset,
|
||||
nsIDOMRange** aRange)
|
||||
{
|
||||
RefPtr<nsRange> range;
|
||||
|
@ -456,17 +466,27 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
// again (when the new text node is notified).
|
||||
nsINode* parentNode = aContent->GetParentNode();
|
||||
int32_t index = -1;
|
||||
if (parentNode == mEndContainer && mEndOffset > 0 &&
|
||||
(index = parentNode->IndexOf(aContent)) + 1 == mEndOffset) {
|
||||
newEndNode = mEndContainer;
|
||||
newEndOffset = mEndOffset + 1;
|
||||
mEndOffsetWasIncremented = true;
|
||||
if (parentNode == mEndContainer && mEndOffset > 0) {
|
||||
index = parentNode->IndexOf(aContent);
|
||||
NS_WARNING_ASSERTION(index >= 0,
|
||||
"Shouldn't be called during removing the node or something");
|
||||
if (static_cast<uint32_t>(index + 1) == mEndOffset) {
|
||||
newEndNode = mEndContainer;
|
||||
newEndOffset = mEndOffset + 1;
|
||||
MOZ_ASSERT(IsValidOffset(newEndOffset));
|
||||
mEndOffsetWasIncremented = true;
|
||||
}
|
||||
}
|
||||
if (parentNode == mStartContainer && mStartOffset > 0 &&
|
||||
(index != -1 ? index : parentNode->IndexOf(aContent)) + 1 == mStartOffset) {
|
||||
newStartNode = mStartContainer;
|
||||
newStartOffset = mStartOffset + 1;
|
||||
mStartOffsetWasIncremented = true;
|
||||
if (parentNode == mStartContainer && mStartOffset > 0) {
|
||||
if (index <= 0) {
|
||||
index = parentNode->IndexOf(aContent);
|
||||
}
|
||||
if (static_cast<uint32_t>(index + 1) == mStartOffset) {
|
||||
newStartNode = mStartContainer;
|
||||
newStartOffset = mStartOffset + 1;
|
||||
MOZ_ASSERT(IsValidOffset(newStartOffset));
|
||||
mStartOffsetWasIncremented = true;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (mStartOffsetWasIncremented || mEndOffsetWasIncremented) {
|
||||
|
@ -479,16 +499,15 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
|
||||
// If the changed node contains our start boundary and the change starts
|
||||
// before the boundary we'll need to adjust the offset.
|
||||
if (aContent == mStartContainer &&
|
||||
aInfo->mChangeStart < static_cast<uint32_t>(mStartOffset)) {
|
||||
if (aContent == mStartContainer && aInfo->mChangeStart < mStartOffset) {
|
||||
if (aInfo->mDetails) {
|
||||
// splitText(), aInfo->mDetails->mNextSibling is the new text node
|
||||
NS_ASSERTION(aInfo->mDetails->mType ==
|
||||
CharacterDataChangeInfo::Details::eSplit,
|
||||
"only a split can start before the end");
|
||||
NS_ASSERTION(static_cast<uint32_t>(mStartOffset) <= aInfo->mChangeEnd + 1,
|
||||
NS_ASSERTION(mStartOffset <= aInfo->mChangeEnd + 1,
|
||||
"mStartOffset is beyond the end of this node");
|
||||
newStartOffset = static_cast<uint32_t>(mStartOffset) - aInfo->mChangeStart;
|
||||
newStartOffset = mStartOffset - aInfo->mChangeStart;
|
||||
newStartNode = aInfo->mDetails->mNextSibling;
|
||||
if (MOZ_UNLIKELY(aContent == mRoot)) {
|
||||
newRoot = IsValidBoundary(newStartNode);
|
||||
|
@ -507,7 +526,7 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
// If boundary is inside changed text, position it before change
|
||||
// else adjust start offset for the change in length.
|
||||
newStartNode = mStartContainer;
|
||||
newStartOffset = static_cast<uint32_t>(mStartOffset) <= aInfo->mChangeEnd ?
|
||||
newStartOffset = mStartOffset <= aInfo->mChangeEnd ?
|
||||
aInfo->mChangeStart :
|
||||
mStartOffset + aInfo->mChangeStart - aInfo->mChangeEnd +
|
||||
aInfo->mReplaceLength;
|
||||
|
@ -517,16 +536,15 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
// Do the same thing for the end boundary, except for splitText of a node
|
||||
// with no parent then only switch to the new node if the start boundary
|
||||
// did so too (otherwise the range would end up with disconnected nodes).
|
||||
if (aContent == mEndContainer &&
|
||||
aInfo->mChangeStart < static_cast<uint32_t>(mEndOffset)) {
|
||||
if (aContent == mEndContainer && aInfo->mChangeStart < mEndOffset) {
|
||||
if (aInfo->mDetails && (aContent->GetParentNode() || newStartNode)) {
|
||||
// splitText(), aInfo->mDetails->mNextSibling is the new text node
|
||||
NS_ASSERTION(aInfo->mDetails->mType ==
|
||||
CharacterDataChangeInfo::Details::eSplit,
|
||||
"only a split can start before the end");
|
||||
NS_ASSERTION(static_cast<uint32_t>(mEndOffset) <= aInfo->mChangeEnd + 1,
|
||||
NS_ASSERTION(mEndOffset <= aInfo->mChangeEnd + 1,
|
||||
"mEndOffset is beyond the end of this node");
|
||||
newEndOffset = static_cast<uint32_t>(mEndOffset) - aInfo->mChangeStart;
|
||||
newEndOffset = mEndOffset - aInfo->mChangeStart;
|
||||
newEndNode = aInfo->mDetails->mNextSibling;
|
||||
|
||||
bool isCommonAncestor =
|
||||
|
@ -542,7 +560,7 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
}
|
||||
} else {
|
||||
newEndNode = mEndContainer;
|
||||
newEndOffset = static_cast<uint32_t>(mEndOffset) <= aInfo->mChangeEnd ?
|
||||
newEndOffset = mEndOffset <= aInfo->mChangeEnd ?
|
||||
aInfo->mChangeStart :
|
||||
mEndOffset + aInfo->mChangeStart - aInfo->mChangeEnd +
|
||||
aInfo->mReplaceLength;
|
||||
|
@ -555,14 +573,14 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
// that will be removed
|
||||
nsIContent* removed = aInfo->mDetails->mNextSibling;
|
||||
if (removed == mStartContainer) {
|
||||
newStartOffset = static_cast<uint32_t>(mStartOffset) + aInfo->mChangeStart;
|
||||
newStartOffset = mStartOffset + aInfo->mChangeStart;
|
||||
newStartNode = aContent;
|
||||
if (MOZ_UNLIKELY(removed == mRoot)) {
|
||||
newRoot = IsValidBoundary(newStartNode);
|
||||
}
|
||||
}
|
||||
if (removed == mEndContainer) {
|
||||
newEndOffset = static_cast<uint32_t>(mEndOffset) + aInfo->mChangeStart;
|
||||
newEndOffset = mEndOffset + aInfo->mChangeStart;
|
||||
newEndNode = aContent;
|
||||
if (MOZ_UNLIKELY(removed == mRoot)) {
|
||||
newRoot = IsValidBoundary(newEndNode);
|
||||
|
@ -576,13 +594,13 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
// point before the first child is never affected by normalize().)
|
||||
nsINode* parentNode = aContent->GetParentNode();
|
||||
if (parentNode == mStartContainer && mStartOffset > 0 &&
|
||||
uint32_t(mStartOffset) < parentNode->GetChildCount() &&
|
||||
mStartOffset < parentNode->GetChildCount() &&
|
||||
removed == parentNode->GetChildAt(mStartOffset)) {
|
||||
newStartNode = aContent;
|
||||
newStartOffset = aInfo->mChangeStart;
|
||||
}
|
||||
if (parentNode == mEndContainer && mEndOffset > 0 &&
|
||||
uint32_t(mEndOffset) < parentNode->GetChildCount() &&
|
||||
mEndOffset < parentNode->GetChildCount() &&
|
||||
removed == parentNode->GetChildAt(mEndOffset)) {
|
||||
newEndNode = aContent;
|
||||
newEndOffset = aInfo->mChangeEnd;
|
||||
|
@ -650,14 +668,20 @@ nsRange::ContentInserted(nsIDocument* aDocument,
|
|||
nsINode* container = NODE_FROM(aContainer, aDocument);
|
||||
|
||||
// Adjust position if a sibling was inserted.
|
||||
if (container == mStartContainer && aIndexInContainer < mStartOffset &&
|
||||
if (container == mStartContainer &&
|
||||
(NS_WARN_IF(aIndexInContainer < 0) ||
|
||||
static_cast<uint32_t>(aIndexInContainer) < mStartOffset) &&
|
||||
!mStartOffsetWasIncremented) {
|
||||
++newStartOffset;
|
||||
MOZ_ASSERT(IsValidOffset(newStartOffset));
|
||||
rangeChanged = true;
|
||||
}
|
||||
if (container == mEndContainer && aIndexInContainer < mEndOffset &&
|
||||
if (container == mEndContainer &&
|
||||
(NS_WARN_IF(aIndexInContainer < 0) ||
|
||||
static_cast<uint32_t>(aIndexInContainer) < mEndOffset) &&
|
||||
!mEndOffsetWasIncremented) {
|
||||
++newEndOffset;
|
||||
MOZ_ASSERT(IsValidOffset(newEndOffset));
|
||||
rangeChanged = true;
|
||||
}
|
||||
if (container->IsSelectionDescendant() &&
|
||||
|
@ -705,7 +729,7 @@ nsRange::ContentRemoved(nsIDocument* aDocument,
|
|||
|
||||
// Adjust position if a sibling was removed...
|
||||
if (container == mStartContainer) {
|
||||
if (aIndexInContainer < mStartOffset) {
|
||||
if (aIndexInContainer < static_cast<int32_t>(mStartOffset)) {
|
||||
--newStartOffset;
|
||||
rangeChanged = true;
|
||||
}
|
||||
|
@ -717,7 +741,7 @@ nsRange::ContentRemoved(nsIDocument* aDocument,
|
|||
|
||||
// Do same thing for end boundry.
|
||||
if (container == mEndContainer) {
|
||||
if (aIndexInContainer < mEndOffset) {
|
||||
if (aIndexInContainer < static_cast<int32_t>(mEndOffset)) {
|
||||
--newEndOffset;
|
||||
rangeChanged = true;
|
||||
}
|
||||
|
@ -773,12 +797,15 @@ nsRange::ParentChainChanged(nsIContent *aContent)
|
|||
* Utilities for comparing points: API from nsIDOMRange
|
||||
******************************************************/
|
||||
NS_IMETHODIMP
|
||||
nsRange::IsPointInRange(nsIDOMNode* aContainer, int32_t aOffset, bool* aResult)
|
||||
nsRange::IsPointInRange(nsIDOMNode* aContainer, uint32_t aOffset, bool* aResult)
|
||||
{
|
||||
nsCOMPtr<nsINode> container = do_QueryInterface(aContainer);
|
||||
if (!container) {
|
||||
return NS_ERROR_DOM_NOT_OBJECT_ERR;
|
||||
}
|
||||
if (NS_WARN_IF(!IsValidOffset(aOffset))) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
ErrorResult rv;
|
||||
*aResult = IsPointInRange(*container, aOffset, rv);
|
||||
|
@ -801,7 +828,8 @@ nsRange::IsPointInRange(nsINode& aContainer, uint32_t aOffset, ErrorResult& aRv)
|
|||
// returns -1 if point is before range, 0 if point is in range,
|
||||
// 1 if point is after range.
|
||||
NS_IMETHODIMP
|
||||
nsRange::ComparePoint(nsIDOMNode* aContainer, int32_t aOffset, int16_t* aResult)
|
||||
nsRange::ComparePoint(nsIDOMNode* aContainer, uint32_t aOffset,
|
||||
int16_t* aResult)
|
||||
{
|
||||
nsCOMPtr<nsINode> container = do_QueryInterface(aContainer);
|
||||
NS_ENSURE_TRUE(container, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
||||
|
@ -835,15 +863,18 @@ nsRange::ComparePoint(nsINode& aContainer, uint32_t aOffset, ErrorResult& aRv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t cmp;
|
||||
if ((cmp = nsContentUtils::ComparePoints(&aContainer, aOffset,
|
||||
mStartContainer,
|
||||
mStartOffset)) <= 0) {
|
||||
|
||||
int32_t cmp =
|
||||
nsContentUtils::ComparePoints(&aContainer,
|
||||
static_cast<int32_t>(aOffset),
|
||||
mStartContainer,
|
||||
static_cast<int32_t>(mStartOffset));
|
||||
if (cmp <= 0) {
|
||||
return cmp;
|
||||
}
|
||||
if (nsContentUtils::ComparePoints(mEndContainer, mEndOffset,
|
||||
&aContainer, aOffset) == -1) {
|
||||
if (nsContentUtils::ComparePoints(mEndContainer,
|
||||
static_cast<int32_t>(mEndOffset),
|
||||
&aContainer,
|
||||
static_cast<int32_t>(aOffset)) == -1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -886,12 +917,15 @@ nsRange::IntersectsNode(nsINode& aNode, ErrorResult& aRv)
|
|||
// Steps 6-7.
|
||||
// Note: if disconnected is true, ComparePoints returns 1.
|
||||
bool disconnected = false;
|
||||
bool result = nsContentUtils::ComparePoints(mStartContainer, mStartOffset,
|
||||
parent, nodeIndex + 1,
|
||||
&disconnected) < 0 &&
|
||||
nsContentUtils::ComparePoints(parent, nodeIndex,
|
||||
mEndContainer, mEndOffset,
|
||||
&disconnected) < 0;
|
||||
bool result =
|
||||
nsContentUtils::ComparePoints(mStartContainer,
|
||||
static_cast<int32_t>(mStartOffset),
|
||||
parent, nodeIndex + 1,
|
||||
&disconnected) < 0 &&
|
||||
nsContentUtils::ComparePoints(parent, nodeIndex,
|
||||
mEndContainer,
|
||||
static_cast<int32_t>(mEndOffset),
|
||||
&disconnected) < 0;
|
||||
|
||||
// Step 2.
|
||||
if (disconnected) {
|
||||
|
@ -910,8 +944,8 @@ nsRange::IntersectsNode(nsINode& aNode, ErrorResult& aRv)
|
|||
// Calling DoSetRange with either parent argument null will collapse
|
||||
// the range to have both endpoints point to the other node
|
||||
void
|
||||
nsRange::DoSetRange(nsINode* aStartN, int32_t aStartOffset,
|
||||
nsINode* aEndN, int32_t aEndOffset,
|
||||
nsRange::DoSetRange(nsINode* aStartN, uint32_t aStartOffset,
|
||||
nsINode* aEndN, uint32_t aEndOffset,
|
||||
nsINode* aRoot, bool aNotInsertedYet)
|
||||
{
|
||||
NS_PRECONDITION((aStartN && aEndN && aRoot) ||
|
||||
|
@ -937,6 +971,8 @@ nsRange::DoSetRange(nsINode* aStartN, int32_t aStartOffset,
|
|||
/*For backward compatibility*/
|
||||
aRoot->IsNodeOfType(nsINode::eCONTENT))),
|
||||
"Bad root");
|
||||
MOZ_ASSERT(IsValidOffset(aStartOffset));
|
||||
MOZ_ASSERT(IsValidOffset(aEndOffset));
|
||||
|
||||
if (mRoot != aRoot) {
|
||||
if (mRoot) {
|
||||
|
@ -1059,7 +1095,7 @@ nsRange::GetStartContainer(ErrorResult& aRv) const
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRange::GetStartOffset(int32_t* aStartOffset)
|
||||
nsRange::GetStartOffset(uint32_t* aStartOffset)
|
||||
{
|
||||
if (!mIsPositioned)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
@ -1101,7 +1137,7 @@ nsRange::GetEndContainer(ErrorResult& aRv) const
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRange::GetEndOffset(int32_t* aEndOffset)
|
||||
nsRange::GetEndOffset(uint32_t* aEndOffset)
|
||||
{
|
||||
if (!mIsPositioned)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
@ -1160,10 +1196,10 @@ nsRange::GetCommonAncestorContainer(nsIDOMNode** aCommonParent)
|
|||
|
||||
/* static */
|
||||
bool
|
||||
nsRange::IsValidOffset(nsINode* aNode, int32_t aOffset)
|
||||
nsRange::IsValidOffset(nsINode* aNode, uint32_t aOffset)
|
||||
{
|
||||
return aNode &&
|
||||
aOffset >= 0 &&
|
||||
IsValidOffset(aOffset) &&
|
||||
static_cast<size_t>(aOffset) <= aNode->Length();
|
||||
}
|
||||
|
||||
|
@ -1235,7 +1271,7 @@ nsRange::SetStart(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRange::SetStart(nsIDOMNode* aContainer, int32_t aOffset)
|
||||
nsRange::SetStart(nsIDOMNode* aContainer, uint32_t aOffset)
|
||||
{
|
||||
nsCOMPtr<nsINode> container = do_QueryInterface(aContainer);
|
||||
if (!container) {
|
||||
|
@ -1248,7 +1284,7 @@ nsRange::SetStart(nsIDOMNode* aContainer, int32_t aOffset)
|
|||
}
|
||||
|
||||
/* virtual */ nsresult
|
||||
nsRange::SetStart(nsINode* aContainer, int32_t aOffset)
|
||||
nsRange::SetStart(nsINode* aContainer, uint32_t aOffset)
|
||||
{
|
||||
nsINode* newRoot = IsValidBoundary(aContainer);
|
||||
if (!newRoot) {
|
||||
|
@ -1262,8 +1298,10 @@ nsRange::SetStart(nsINode* aContainer, int32_t aOffset)
|
|||
// Collapse if not positioned yet, if positioned in another doc or
|
||||
// if the new start is after end.
|
||||
if (!mIsPositioned || newRoot != mRoot ||
|
||||
nsContentUtils::ComparePoints(aContainer, aOffset,
|
||||
mEndContainer, mEndOffset) == 1) {
|
||||
nsContentUtils::ComparePoints(aContainer,
|
||||
static_cast<int32_t>(aOffset),
|
||||
mEndContainer,
|
||||
static_cast<int32_t>(mEndOffset)) == 1) {
|
||||
DoSetRange(aContainer, aOffset, aContainer, aOffset, newRoot);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1292,7 +1330,10 @@ nsRange::SetStartBefore(nsINode& aNode, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
AutoInvalidateSelection atEndOfBlock(this);
|
||||
int32_t offset = -1;
|
||||
// If the node is being removed from its parent, GetContainerAndOffsetBefore()
|
||||
// returns nullptr. Then, SetStart() will throw
|
||||
// NS_ERROR_DOM_INVALID_NODE_TYPE_ERR.
|
||||
uint32_t offset = UINT32_MAX;
|
||||
nsINode* container = GetContainerAndOffsetBefore(&aNode, &offset);
|
||||
aRv = SetStart(container, offset);
|
||||
}
|
||||
|
@ -1328,7 +1369,10 @@ nsRange::SetStartAfter(nsINode& aNode, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
AutoInvalidateSelection atEndOfBlock(this);
|
||||
int32_t offset = -1;
|
||||
// If the node is being removed from its parent, GetContainerAndOffsetAfter()
|
||||
// returns nullptr. Then, SetStart() will throw
|
||||
// NS_ERROR_DOM_INVALID_NODE_TYPE_ERR.
|
||||
uint32_t offset = UINT32_MAX;
|
||||
nsINode* container = GetContainerAndOffsetAfter(&aNode, &offset);
|
||||
aRv = SetStart(container, offset);
|
||||
}
|
||||
|
@ -1367,7 +1411,7 @@ nsRange::SetEnd(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRange::SetEnd(nsIDOMNode* aContainer, int32_t aOffset)
|
||||
nsRange::SetEnd(nsIDOMNode* aContainer, uint32_t aOffset)
|
||||
{
|
||||
nsCOMPtr<nsINode> container = do_QueryInterface(aContainer);
|
||||
if (!container) {
|
||||
|
@ -1380,7 +1424,7 @@ nsRange::SetEnd(nsIDOMNode* aContainer, int32_t aOffset)
|
|||
}
|
||||
|
||||
/* virtual */ nsresult
|
||||
nsRange::SetEnd(nsINode* aContainer, int32_t aOffset)
|
||||
nsRange::SetEnd(nsINode* aContainer, uint32_t aOffset)
|
||||
{
|
||||
nsINode* newRoot = IsValidBoundary(aContainer);
|
||||
if (!newRoot) {
|
||||
|
@ -1394,8 +1438,10 @@ nsRange::SetEnd(nsINode* aContainer, int32_t aOffset)
|
|||
// Collapse if not positioned yet, if positioned in another doc or
|
||||
// if the new end is before start.
|
||||
if (!mIsPositioned || newRoot != mRoot ||
|
||||
nsContentUtils::ComparePoints(mStartContainer, mStartOffset,
|
||||
aContainer, aOffset) == 1) {
|
||||
nsContentUtils::ComparePoints(mStartContainer,
|
||||
static_cast<int32_t>(mStartOffset),
|
||||
aContainer,
|
||||
static_cast<int32_t>(aOffset)) == 1) {
|
||||
DoSetRange(aContainer, aOffset, aContainer, aOffset, newRoot);
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1407,8 +1453,8 @@ nsRange::SetEnd(nsINode* aContainer, int32_t aOffset)
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsRange::SetStartAndEnd(nsINode* aStartContainer, int32_t aStartOffset,
|
||||
nsINode* aEndContainer, int32_t aEndOffset)
|
||||
nsRange::SetStartAndEnd(nsINode* aStartContainer, uint32_t aStartOffset,
|
||||
nsINode* aEndContainer, uint32_t aEndOffset)
|
||||
{
|
||||
if (NS_WARN_IF(!aStartContainer) || NS_WARN_IF(!aEndContainer)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
@ -1455,8 +1501,10 @@ nsRange::SetStartAndEnd(nsINode* aStartContainer, int32_t aStartOffset,
|
|||
|
||||
// If the end point is before the start point, this should be collapsed at
|
||||
// the end point.
|
||||
if (nsContentUtils::ComparePoints(aStartContainer, aStartOffset,
|
||||
aEndContainer, aEndOffset) == 1) {
|
||||
if (nsContentUtils::ComparePoints(aStartContainer,
|
||||
static_cast<int32_t>(aStartOffset),
|
||||
aEndContainer,
|
||||
static_cast<int32_t>(aEndOffset)) == 1) {
|
||||
DoSetRange(aEndContainer, aEndOffset,
|
||||
aEndContainer, aEndOffset, newEndRoot);
|
||||
return NS_OK;
|
||||
|
@ -1486,7 +1534,10 @@ nsRange::SetEndBefore(nsINode& aNode, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
AutoInvalidateSelection atEndOfBlock(this);
|
||||
int32_t offset = -1;
|
||||
// If the node is being removed from its parent, GetContainerAndOffsetBefore()
|
||||
// returns nullptr. Then, SetEnd() will throw
|
||||
// NS_ERROR_DOM_INVALID_NODE_TYPE_ERR.
|
||||
uint32_t offset = UINT32_MAX;
|
||||
nsINode* container = GetContainerAndOffsetBefore(&aNode, &offset);
|
||||
aRv = SetEnd(container, offset);
|
||||
}
|
||||
|
@ -1522,7 +1573,10 @@ nsRange::SetEndAfter(nsINode& aNode, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
AutoInvalidateSelection atEndOfBlock(this);
|
||||
int32_t offset = -1;
|
||||
// If the node is being removed from its parent, GetContainerAndOffsetAfter()
|
||||
// returns nullptr. Then, SetEnd() will throw
|
||||
// NS_ERROR_DOM_INVALID_NODE_TYPE_ERR.
|
||||
uint32_t offset = UINT32_MAX;
|
||||
nsINode* container = GetContainerAndOffsetAfter(&aNode, &offset);
|
||||
aRv = SetEnd(container, offset);
|
||||
}
|
||||
|
@ -1602,7 +1656,9 @@ nsRange::SelectNode(nsINode& aNode, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
int32_t index = container->IndexOf(&aNode);
|
||||
if (index < 0) {
|
||||
if (NS_WARN_IF(index < 0) ||
|
||||
!IsValidOffset(static_cast<uint32_t>(index)) ||
|
||||
!IsValidOffset(static_cast<uint32_t>(index) + 1)) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
|
||||
return;
|
||||
}
|
||||
|
@ -2059,9 +2115,9 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
// of Range gravity during our edits!
|
||||
|
||||
nsCOMPtr<nsINode> startContainer = mStartContainer;
|
||||
int32_t startOffset = mStartOffset;
|
||||
uint32_t startOffset = mStartOffset;
|
||||
nsCOMPtr<nsINode> endContainer = mEndContainer;
|
||||
int32_t endOffset = mEndOffset;
|
||||
uint32_t endOffset = mEndOffset;
|
||||
|
||||
if (retval) {
|
||||
// For extractContents(), abort early if there's a doctype (bug 719533).
|
||||
|
@ -2072,10 +2128,12 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
RefPtr<DocumentType> doctype = commonAncestorDocument->GetDoctype();
|
||||
|
||||
if (doctype &&
|
||||
nsContentUtils::ComparePoints(startContainer, startOffset,
|
||||
nsContentUtils::ComparePoints(startContainer,
|
||||
static_cast<int32_t>(startOffset),
|
||||
doctype, 0) < 0 &&
|
||||
nsContentUtils::ComparePoints(doctype, 0,
|
||||
endContainer, endOffset) < 0) {
|
||||
endContainer,
|
||||
static_cast<int32_t>(endOffset)) < 0) {
|
||||
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
||||
}
|
||||
}
|
||||
|
@ -2170,8 +2228,7 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
rv = charData->GetLength(&dataLength);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (dataLength >= (uint32_t)startOffset)
|
||||
{
|
||||
if (dataLength >= startOffset) {
|
||||
nsMutationGuard guard;
|
||||
nsCOMPtr<nsIDOMCharacterData> cutNode;
|
||||
rv = SplitDataNode(charData, startOffset, getter_AddRefs(cutNode));
|
||||
|
@ -2187,22 +2244,17 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
else if (node == endContainer)
|
||||
{
|
||||
// Delete or extract everything before endOffset.
|
||||
|
||||
if (endOffset >= 0)
|
||||
{
|
||||
nsMutationGuard guard;
|
||||
nsCOMPtr<nsIDOMCharacterData> cutNode;
|
||||
/* The Range spec clearly states clones get cut and original nodes
|
||||
remain behind, so use false as the last parameter.
|
||||
*/
|
||||
rv = SplitDataNode(charData, endOffset, getter_AddRefs(cutNode),
|
||||
false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_STATE(!guard.Mutated(1) ||
|
||||
ValidateCurrentNode(this, iter));
|
||||
nodeToResult = do_QueryInterface(cutNode);
|
||||
}
|
||||
|
||||
nsMutationGuard guard;
|
||||
nsCOMPtr<nsIDOMCharacterData> cutNode;
|
||||
/* The Range spec clearly states clones get cut and original nodes
|
||||
remain behind, so use false as the last parameter.
|
||||
*/
|
||||
rv = SplitDataNode(charData, endOffset, getter_AddRefs(cutNode),
|
||||
false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_STATE(!guard.Mutated(1) ||
|
||||
ValidateCurrentNode(this, iter));
|
||||
nodeToResult = do_QueryInterface(cutNode);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
@ -2212,8 +2264,7 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
if (node && node->IsElement() &&
|
||||
((node == endContainer && endOffset == 0) ||
|
||||
(node == startContainer &&
|
||||
int32_t(node->AsElement()->GetChildCount()) == startOffset)))
|
||||
{
|
||||
node->AsElement()->GetChildCount() == startOffset))) {
|
||||
if (retval) {
|
||||
ErrorResult rv;
|
||||
nodeToResult = node->CloneNode(false, rv);
|
||||
|
@ -2358,7 +2409,7 @@ nsRange::CompareBoundaryPoints(uint16_t aHow, nsRange& aOtherRange,
|
|||
}
|
||||
|
||||
nsINode *ourNode, *otherNode;
|
||||
int32_t ourOffset, otherOffset;
|
||||
uint32_t ourOffset, otherOffset;
|
||||
|
||||
switch (aHow) {
|
||||
case nsIDOMRange::START_TO_START:
|
||||
|
@ -2396,8 +2447,10 @@ nsRange::CompareBoundaryPoints(uint16_t aHow, nsRange& aOtherRange,
|
|||
return 0;
|
||||
}
|
||||
|
||||
return nsContentUtils::ComparePoints(ourNode, ourOffset,
|
||||
otherNode, otherOffset);
|
||||
return nsContentUtils::ComparePoints(ourNode,
|
||||
static_cast<int32_t>(ourOffset),
|
||||
otherNode,
|
||||
static_cast<int32_t>(otherOffset));
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
|
@ -2514,8 +2567,7 @@ nsRange::CloneContents(ErrorResult& aRv)
|
|||
bool deepClone = !node->IsElement() ||
|
||||
(!(node == mEndContainer && mEndOffset == 0) &&
|
||||
!(node == mStartContainer &&
|
||||
mStartOffset ==
|
||||
int32_t(node->AsElement()->GetChildCount())));
|
||||
mStartOffset == node->AsElement()->GetChildCount()));
|
||||
|
||||
// Clone the current subtree!
|
||||
|
||||
|
@ -2544,8 +2596,7 @@ nsRange::CloneContents(ErrorResult& aRv)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (dataLength > (uint32_t)mEndOffset)
|
||||
{
|
||||
if (dataLength > mEndOffset) {
|
||||
aRv = charData->DeleteData(mEndOffset, dataLength - mEndOffset);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
|
@ -2702,7 +2753,7 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv)
|
|||
return;
|
||||
}
|
||||
|
||||
int32_t tStartOffset = StartOffset();
|
||||
uint32_t tStartOffset = StartOffset();
|
||||
|
||||
nsCOMPtr<nsINode> tStartContainer = GetStartContainer(aRv);
|
||||
if (aRv.Failed()) {
|
||||
|
@ -2763,18 +2814,20 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv)
|
|||
// We might need to update the end to include the new node (bug 433662).
|
||||
// Ideally we'd only do this if needed, but it's tricky to know when it's
|
||||
// needed in advance (bug 765799).
|
||||
int32_t newOffset;
|
||||
uint32_t newOffset;
|
||||
|
||||
if (referenceNode) {
|
||||
newOffset = IndexOf(referenceNode);
|
||||
int32_t indexInParent = IndexOf(referenceNode);
|
||||
if (NS_WARN_IF(indexInParent < 0)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
newOffset = static_cast<uint32_t>(indexInParent);
|
||||
} else {
|
||||
uint32_t length;
|
||||
aRv = tChildList->GetLength(&length);
|
||||
aRv = tChildList->GetLength(&newOffset);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
newOffset = length;
|
||||
}
|
||||
|
||||
if (aNode.NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
|
||||
|
@ -3120,11 +3173,16 @@ nsRange::CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
|
|||
Sequence<nsString>* aTextList,
|
||||
nsRange* aRange,
|
||||
nsINode* aStartContainer,
|
||||
int32_t aStartOffset,
|
||||
uint32_t aStartOffset,
|
||||
nsINode* aEndContainer,
|
||||
int32_t aEndOffset,
|
||||
uint32_t aEndOffset,
|
||||
bool aClampToEdge, bool aFlushLayout)
|
||||
{
|
||||
// Currently, this method is called with start of end offset of nsRange.
|
||||
// So, they must be between 0 - INT32_MAX.
|
||||
MOZ_ASSERT(IsValidOffset(aStartOffset));
|
||||
MOZ_ASSERT(IsValidOffset(aEndOffset));
|
||||
|
||||
// Hold strong pointers across the flush
|
||||
nsCOMPtr<nsINode> startContainer = aStartContainer;
|
||||
nsCOMPtr<nsINode> endContainer = aEndContainer;
|
||||
|
@ -3155,13 +3213,15 @@ nsRange::CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
|
|||
if (textFrame) {
|
||||
int32_t outOffset;
|
||||
nsIFrame* outFrame;
|
||||
textFrame->GetChildFrameContainingOffset(aStartOffset, false,
|
||||
&outOffset, &outFrame);
|
||||
textFrame->GetChildFrameContainingOffset(
|
||||
static_cast<int32_t>(aStartOffset), false,
|
||||
&outOffset, &outFrame);
|
||||
if (outFrame) {
|
||||
nsIFrame* relativeTo =
|
||||
nsLayoutUtils::GetContainingBlockForClientRect(outFrame);
|
||||
nsRect r = outFrame->GetRectRelativeToSelf();
|
||||
ExtractRectFromOffset(outFrame, aStartOffset, &r, false, aClampToEdge);
|
||||
ExtractRectFromOffset(outFrame, static_cast<int32_t>(aStartOffset),
|
||||
&r, false, aClampToEdge);
|
||||
r.width = 0;
|
||||
r = nsLayoutUtils::TransformFrameRectToAncestor(outFrame, r, relativeTo);
|
||||
aCollector->AddRect(r);
|
||||
|
@ -3180,12 +3240,14 @@ nsRange::CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
|
|||
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
||||
if (node == startContainer) {
|
||||
int32_t offset = startContainer == endContainer ?
|
||||
aEndOffset : content->GetText()->GetLength();
|
||||
GetPartialTextRect(aCollector, aTextList, content, aStartOffset, offset,
|
||||
static_cast<int32_t>(aEndOffset) : content->GetText()->GetLength();
|
||||
GetPartialTextRect(aCollector, aTextList, content,
|
||||
static_cast<int32_t>(aStartOffset), offset,
|
||||
aClampToEdge, aFlushLayout);
|
||||
continue;
|
||||
} else if (node == endContainer) {
|
||||
GetPartialTextRect(aCollector, aTextList, content, 0, aEndOffset,
|
||||
GetPartialTextRect(aCollector, aTextList, content,
|
||||
0, static_cast<int32_t>(aEndOffset),
|
||||
aClampToEdge, aFlushLayout);
|
||||
continue;
|
||||
}
|
||||
|
@ -3560,7 +3622,7 @@ ElementIsVisibleNoFlush(Element* aElement)
|
|||
static void
|
||||
AppendTransformedText(InnerTextAccumulator& aResult,
|
||||
nsGenericDOMDataNode* aTextNode,
|
||||
int32_t aStart, int32_t aEnd)
|
||||
uint32_t aStart, uint32_t aEnd)
|
||||
{
|
||||
nsIFrame* frame = aTextNode->GetPrimaryFrame();
|
||||
if (!IsVisibleAndNotInReplacedElement(frame)) {
|
||||
|
@ -3669,7 +3731,7 @@ nsRange::GetInnerTextNoFlush(DOMString& aValue, ErrorResult& aError,
|
|||
if (aEndContainer->IsNodeOfType(nsINode::eTEXT)) {
|
||||
endState = AT_NODE;
|
||||
} else {
|
||||
if (uint32_t(aEndOffset) < aEndContainer->GetChildCount()) {
|
||||
if (aEndOffset < aEndContainer->GetChildCount()) {
|
||||
endNode = aEndContainer->GetChildAt(aEndOffset);
|
||||
endState = AT_NODE;
|
||||
}
|
||||
|
|
|
@ -47,14 +47,20 @@ class nsRange final : public nsIDOMRange,
|
|||
public:
|
||||
explicit nsRange(nsINode* aNode);
|
||||
|
||||
static nsresult CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
|
||||
nsIDOMNode* aEndContainer, int32_t aEndOffset,
|
||||
static nsresult CreateRange(nsIDOMNode* aStartContainer,
|
||||
uint32_t aStartOffset,
|
||||
nsIDOMNode* aEndContainer,
|
||||
uint32_t aEndOffset,
|
||||
nsRange** aRange);
|
||||
static nsresult CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
|
||||
nsIDOMNode* aEndContainer, int32_t aEndOffset,
|
||||
static nsresult CreateRange(nsIDOMNode* aStartContainer,
|
||||
uint32_t aStartOffset,
|
||||
nsIDOMNode* aEndContainer,
|
||||
uint32_t aEndOffset,
|
||||
nsIDOMRange** aRange);
|
||||
static nsresult CreateRange(nsINode* aStartContainer, int32_t aStartOffset,
|
||||
nsINode* aEndContainer, int32_t aEndOffset,
|
||||
static nsresult CreateRange(nsINode* aStartContainer,
|
||||
uint32_t aStartOffset,
|
||||
nsINode* aEndContainer,
|
||||
uint32_t aEndOffset,
|
||||
nsRange** aRange);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
|
@ -83,12 +89,12 @@ public:
|
|||
return mEndContainer;
|
||||
}
|
||||
|
||||
int32_t StartOffset() const
|
||||
uint32_t StartOffset() const
|
||||
{
|
||||
return mStartOffset;
|
||||
}
|
||||
|
||||
int32_t EndOffset() const
|
||||
uint32_t EndOffset() const
|
||||
{
|
||||
return mEndOffset;
|
||||
}
|
||||
|
@ -147,8 +153,8 @@ public:
|
|||
* When you set both start and end of a range, you should use
|
||||
* SetStartAndEnd() instead.
|
||||
*/
|
||||
nsresult SetStart(nsINode* aContainer, int32_t aOffset);
|
||||
nsresult SetEnd(nsINode* aContainer, int32_t aOffset);
|
||||
nsresult SetStart(nsINode* aContainer, uint32_t aOffset);
|
||||
nsresult SetEnd(nsINode* aContainer, uint32_t aOffset);
|
||||
|
||||
already_AddRefed<nsRange> CloneRange() const;
|
||||
|
||||
|
@ -160,15 +166,15 @@ public:
|
|||
* collapsed at the end point. Similarly, if they are in different root,
|
||||
* the range will be collapsed at the end point.
|
||||
*/
|
||||
nsresult SetStartAndEnd(nsINode* aStartContainer, int32_t aStartOffset,
|
||||
nsINode* aEndContainer, int32_t aEndOffset);
|
||||
nsresult SetStartAndEnd(nsINode* aStartContainer, uint32_t aStartOffset,
|
||||
nsINode* aEndContainer, uint32_t aEndOffset);
|
||||
|
||||
/**
|
||||
* CollapseTo() works similar to call both SetStart() and SetEnd() with
|
||||
* same node and offset. This just calls SetStartAndParent() to set
|
||||
* collapsed range at aContainer and aOffset.
|
||||
*/
|
||||
nsresult CollapseTo(nsINode* aContainer, int32_t aOffset)
|
||||
nsresult CollapseTo(nsINode* aContainer, uint32_t aOffset)
|
||||
{
|
||||
return SetStartAndEnd(aContainer, aOffset, aContainer, aOffset);
|
||||
}
|
||||
|
@ -177,23 +183,36 @@ public:
|
|||
* Retrieves node and offset for setting start or end of a range to
|
||||
* before or after aNode.
|
||||
*/
|
||||
static nsINode* GetContainerAndOffsetAfter(nsINode* aNode, int32_t* aOffset)
|
||||
static nsINode* GetContainerAndOffsetAfter(nsINode* aNode, uint32_t* aOffset)
|
||||
{
|
||||
MOZ_ASSERT(aNode);
|
||||
MOZ_ASSERT(aOffset);
|
||||
*aOffset = 0;
|
||||
nsINode* parentNode = aNode->GetParentNode();
|
||||
*aOffset = parentNode ? parentNode->IndexOf(aNode) : -1;
|
||||
if (*aOffset >= 0) {
|
||||
(*aOffset)++;
|
||||
if (!parentNode) {
|
||||
return nullptr;
|
||||
}
|
||||
int32_t indexInParent = parentNode->IndexOf(aNode);
|
||||
if (NS_WARN_IF(indexInParent < 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
*aOffset = static_cast<uint32_t>(indexInParent) + 1;
|
||||
return parentNode;
|
||||
}
|
||||
static nsINode* GetContainerAndOffsetBefore(nsINode* aNode, int32_t* aOffset)
|
||||
static nsINode* GetContainerAndOffsetBefore(nsINode* aNode, uint32_t* aOffset)
|
||||
{
|
||||
MOZ_ASSERT(aNode);
|
||||
MOZ_ASSERT(aOffset);
|
||||
*aOffset = 0;
|
||||
nsINode* parentNode = aNode->GetParentNode();
|
||||
*aOffset = parentNode ? parentNode->IndexOf(aNode) : -1;
|
||||
if (!parentNode) {
|
||||
return nullptr;
|
||||
}
|
||||
int32_t indexInParent = parentNode->IndexOf(aNode);
|
||||
if (NS_WARN_IF(indexInParent < 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
*aOffset = static_cast<uint32_t>(indexInParent);
|
||||
return parentNode;
|
||||
}
|
||||
|
||||
|
@ -327,9 +346,9 @@ public:
|
|||
mozilla::dom::Sequence<nsString>* aTextList,
|
||||
nsRange* aRange,
|
||||
nsINode* aStartContainer,
|
||||
int32_t aStartOffset,
|
||||
uint32_t aStartOffset,
|
||||
nsINode* aEndContainer,
|
||||
int32_t aEndOffset,
|
||||
uint32_t aEndOffset,
|
||||
bool aClampToEdge, bool aFlushLayout);
|
||||
|
||||
/**
|
||||
|
@ -350,14 +369,25 @@ protected:
|
|||
void RegisterCommonAncestor(nsINode* aNode);
|
||||
void UnregisterCommonAncestor(nsINode* aNode);
|
||||
nsINode* IsValidBoundary(nsINode* aNode);
|
||||
static bool IsValidOffset(nsINode* aNode, int32_t aOffset);
|
||||
|
||||
/**
|
||||
* XXX nsRange should accept 0 - UINT32_MAX as offset. However, users of
|
||||
* nsRange treat offset as int32_t. Additionally, some other internal
|
||||
* APIs like nsINode::IndexOf() use int32_t. Therefore, nsRange should
|
||||
* accept only 0 - INT32_MAX as valid offset for now.
|
||||
*/
|
||||
static bool IsValidOffset(uint32_t aOffset)
|
||||
{
|
||||
return aOffset <= INT32_MAX;
|
||||
}
|
||||
static bool IsValidOffset(nsINode* aNode, uint32_t aOffset);
|
||||
|
||||
// CharacterDataChanged set aNotInsertedYet to true to disable an assertion
|
||||
// and suppress re-registering a range common ancestor node since
|
||||
// the new text node of a splitText hasn't been inserted yet.
|
||||
// CharacterDataChanged does the re-registering when needed.
|
||||
void DoSetRange(nsINode* aStartN, int32_t aStartOffset,
|
||||
nsINode* aEndN, int32_t aEndOffset,
|
||||
void DoSetRange(nsINode* aStartN, uint32_t aStartOffset,
|
||||
nsINode* aEndN, uint32_t aEndOffset,
|
||||
nsINode* aRoot, bool aNotInsertedYet = false);
|
||||
|
||||
/**
|
||||
|
@ -430,8 +460,8 @@ protected:
|
|||
nsCOMPtr<nsINode> mStartContainer;
|
||||
nsCOMPtr<nsINode> mEndContainer;
|
||||
RefPtr<mozilla::dom::Selection> mSelection;
|
||||
int32_t mStartOffset;
|
||||
int32_t mEndOffset;
|
||||
uint32_t mStartOffset;
|
||||
uint32_t mEndOffset;
|
||||
|
||||
bool mIsPositioned : 1;
|
||||
bool mMaySpanAnonymousSubtrees : 1;
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
interface nsIDOMRange : nsISupports
|
||||
{
|
||||
readonly attribute nsIDOMNode startContainer;
|
||||
readonly attribute long startOffset;
|
||||
readonly attribute unsigned long startOffset;
|
||||
readonly attribute nsIDOMNode endContainer;
|
||||
readonly attribute long endOffset;
|
||||
readonly attribute unsigned long endOffset;
|
||||
readonly attribute boolean collapsed;
|
||||
readonly attribute nsIDOMNode commonAncestorContainer;
|
||||
|
||||
void setStart(in nsIDOMNode refNode, in long offset);
|
||||
void setEnd(in nsIDOMNode refNode, in long offset);
|
||||
void setStart(in nsIDOMNode refNode, in unsigned long offset);
|
||||
void setEnd(in nsIDOMNode refNode, in unsigned long offset);
|
||||
void setStartBefore(in nsIDOMNode refNode);
|
||||
void setStartAfter(in nsIDOMNode refNode);
|
||||
void setEndBefore(in nsIDOMNode refNode);
|
||||
|
@ -56,14 +56,14 @@ interface nsIDOMRange : nsISupports
|
|||
// This returns true if parent+offset equals either
|
||||
// of the boundary points or is between them.
|
||||
boolean isPointInRange(in nsIDOMNode parent,
|
||||
in long offset);
|
||||
in unsigned long offset);
|
||||
|
||||
// comparePoint returns
|
||||
// -1 if point is before the start boundary point,
|
||||
// 0 if point is either of the boundary points or between them,
|
||||
// 1 if point is after the end boundary point.
|
||||
// Sort of a strcmp for ranges.
|
||||
short comparePoint(in nsIDOMNode parent, in long offset);
|
||||
short comparePoint(in nsIDOMNode parent, in unsigned long offset);
|
||||
|
||||
/**
|
||||
* Returns whether the range intersects node.
|
||||
|
|
|
@ -5319,7 +5319,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,
|
||||
|
@ -5339,15 +5339,11 @@ EditorBase::GetIMESelectionStartOffsetIn(nsINode* aTextNode)
|
|||
if (NS_WARN_IF(range->GetStartContainer() != 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->GetEndContainer() != aTextNode)) {
|
||||
// ignore the end offset...
|
||||
} else {
|
||||
MOZ_ASSERT(range->EndOffset() >= 0,
|
||||
"start offset shouldn't be negative");
|
||||
minOffset = std::min(minOffset, range->EndOffset());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -458,7 +458,7 @@ HTMLEditRules::AfterEditInner(EditAction action,
|
|||
NS_ENSURE_STATE(selection);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> rangeStartContainer, rangeEndContainer;
|
||||
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) {
|
||||
|
@ -568,8 +568,8 @@ HTMLEditRules::AfterEditInner(EditAction action,
|
|||
action, selection,
|
||||
GetAsDOMNode(mRangeItem->mStartContainer),
|
||||
mRangeItem->mStartOffset,
|
||||
rangeStartContainer, rangeStartOffset,
|
||||
rangeEndContainer, rangeEndOffset);
|
||||
rangeStartContainer, static_cast<int32_t>(rangeStartOffset),
|
||||
rangeEndContainer, static_cast<int32_t>(rangeEndOffset));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// detect empty doc
|
||||
|
@ -5317,9 +5317,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);
|
||||
|
@ -5332,22 +5331,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.
|
||||
|
@ -5357,36 +5356,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.
|
||||
|
@ -5396,24 +5403,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);
|
||||
++newStartOffset; // offset *after* break
|
||||
&offset);
|
||||
// offset *after* break
|
||||
newStartOffset = static_cast<uint32_t>(offset + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8193,7 +8207,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);
|
||||
|
@ -8207,9 +8221,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);
|
||||
|
|
|
@ -2418,22 +2418,20 @@ HTMLEditor::GetSelectedElement(const nsAString& aTagName,
|
|||
NS_ENSURE_STATE(range);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> startContainer;
|
||||
int32_t startOffset, endOffset;
|
||||
nsresult rv = range->GetStartContainer(getter_AddRefs(startContainer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = range->GetStartOffset(&startOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
uint32_t startOffset = range->StartOffset();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> endContainer;
|
||||
rv = range->GetEndContainer(getter_AddRefs(endContainer));
|
||||
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 (startContainer && startContainer == endContainer &&
|
||||
endOffset - startOffset == 1) {
|
||||
nsCOMPtr<nsIDOMNode> selectedNode = GetChildAt(startContainer, startOffset);
|
||||
nsCOMPtr<nsIDOMNode> selectedNode =
|
||||
GetChildAt(startContainer, static_cast<int32_t>(startOffset));
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
if (selectedNode) {
|
||||
selectedNode->GetNodeName(domTagName);
|
||||
|
|
|
@ -141,14 +141,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));
|
||||
}
|
||||
|
|
|
@ -1073,7 +1073,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) {
|
||||
|
|
|
@ -2927,11 +2927,10 @@ HTMLEditor::GetCellFromRange(nsRange* aRange,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(startContainer, NS_ERROR_FAILURE);
|
||||
|
||||
int32_t startOffset;
|
||||
rv = aRange->GetStartOffset(&startOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
uint32_t startOffset = aRange->StartOffset();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> childNode = GetChildAt(startContainer, startOffset);
|
||||
nsCOMPtr<nsIDOMNode> childNode =
|
||||
GetChildAt(startContainer, static_cast<int32_t>(startOffset));
|
||||
// This means selection is probably at a text node (or end of doc?)
|
||||
if (!childNode) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -2942,15 +2941,11 @@ HTMLEditor::GetCellFromRange(nsRange* aRange,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(startContainer, 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 (startContainer == endContainer &&
|
||||
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)
|
||||
|
|
|
@ -241,13 +241,15 @@ ContentIsInTraversalRange(nsRange* aRange, nsIDOMNode* aNextNode, bool aIsPreMod
|
|||
|
||||
nsCOMPtr<nsIDOMNode> sNode;
|
||||
nsCOMPtr<nsIDOMNode> eNode;
|
||||
int32_t sOffset;
|
||||
int32_t eOffset;
|
||||
uint32_t sOffset;
|
||||
uint32_t eOffset;
|
||||
aRange->GetStartContainer(getter_AddRefs(sNode));
|
||||
aRange->GetStartOffset(&sOffset);
|
||||
aRange->GetEndContainer(getter_AddRefs(eNode));
|
||||
aRange->GetEndOffset(&eOffset);
|
||||
return ContentIsInTraversalRange(content, aIsPreMode, sNode, sOffset, eNode, eOffset);
|
||||
return ContentIsInTraversalRange(content, aIsPreMode,
|
||||
sNode, static_cast<int32_t>(sOffset),
|
||||
eNode, static_cast<int32_t>(eOffset));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
|
|
@ -510,7 +510,6 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus,
|
|||
nsCOMPtr<nsIContentIterator> iter;
|
||||
RefPtr<nsRange> range;
|
||||
nsCOMPtr<nsIDOMNode> 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<int32_t>(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<int32_t>(offset), false, getter_AddRefs(range));
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
UNLOCK_DOC(this);
|
||||
|
@ -2377,14 +2380,16 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS
|
|||
nsCOMPtr<nsINode> 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<int32_t>(offset));
|
||||
int32_t e2s1 = nsContentUtils::ComparePoints(eEnd->mNode, eEndOffset,
|
||||
domParent, offset);
|
||||
domParent,
|
||||
static_cast<int32_t>(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<int32_t>(offset) &&
|
||||
static_cast<int32_t>(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<int32_t>(offset) &&
|
||||
static_cast<int32_t>(offset) <= entry->mNodeOffset + entry->mLength) {
|
||||
*aSelStatus = nsITextServicesDocument::eBlockContains;
|
||||
*aSelOffset = entry->mStrOffset + (offset - entry->mNodeOffset);
|
||||
*aSelLength = 0;
|
||||
|
@ -2820,9 +2825,12 @@ nsTextServicesDocument::GetRangeEndPoints(nsRange* aRange,
|
|||
|
||||
NS_ENSURE_TRUE(aStartContainer, 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<int32_t>(offset);
|
||||
|
||||
rv = aRange->GetEndContainer(aEndContainer);
|
||||
|
||||
|
@ -2830,7 +2838,12 @@ nsTextServicesDocument::GetRangeEndPoints(nsRange* aRange,
|
|||
|
||||
NS_ENSURE_TRUE(aEndContainer, NS_ERROR_FAILURE);
|
||||
|
||||
return aRange->GetEndOffset(aEndOffset);
|
||||
rv = aRange->GetEndOffset(&offset);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
*aEndOffset = static_cast<int32_t>(offset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -352,19 +352,18 @@ mozInlineSpellStatus::FinishNavigationEvent(mozInlineSpellWordUtil& aWordUtil)
|
|||
|
||||
NS_ASSERTION(mAnchorRange, "No anchor for navigation!");
|
||||
nsCOMPtr<nsIDOMNode> newAnchorNode, oldAnchorNode;
|
||||
int32_t newAnchorOffset, oldAnchorOffset;
|
||||
|
||||
// get the DOM position of the old caret, the range should be collapsed
|
||||
nsresult rv = mOldNavigationAnchorRange->GetStartContainer(
|
||||
getter_AddRefs(oldAnchorNode));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = mOldNavigationAnchorRange->GetStartOffset(&oldAnchorOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
uint32_t oldAnchorOffset = mOldNavigationAnchorRange->StartOffset();
|
||||
|
||||
// find the word on the old caret position, this is the one that we MAY need
|
||||
// to check
|
||||
RefPtr<nsRange> oldWord;
|
||||
rv = aWordUtil.GetRangeForWord(oldAnchorNode, oldAnchorOffset,
|
||||
rv = aWordUtil.GetRangeForWord(oldAnchorNode,
|
||||
static_cast<int32_t>(oldAnchorOffset),
|
||||
getter_AddRefs(oldWord));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -376,15 +375,16 @@ mozInlineSpellStatus::FinishNavigationEvent(mozInlineSpellWordUtil& aWordUtil)
|
|||
// get the DOM position of the new caret, the range should be collapsed
|
||||
rv = mAnchorRange->GetStartContainer(getter_AddRefs(newAnchorNode));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = mAnchorRange->GetStartOffset(&newAnchorOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
uint32_t newAnchorOffset = mAnchorRange->StartOffset();
|
||||
|
||||
// see if the new cursor position is in the word of the old cursor position
|
||||
bool isInRange = false;
|
||||
if (! mForceNavigationWordCheck) {
|
||||
rv = oldWord->IsPointInRange(newAnchorNode,
|
||||
newAnchorOffset + mNewNavigationPositionOffset,
|
||||
&isInRange);
|
||||
rv = oldWord->IsPointInRange(
|
||||
newAnchorNode,
|
||||
static_cast<int32_t>(
|
||||
newAnchorOffset + mNewNavigationPositionOffset),
|
||||
&isInRange);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
|
@ -417,11 +417,9 @@ mozInlineSpellStatus::FillNoCheckRangeFromAnchor(
|
|||
nsresult rv = mAnchorRange->GetStartContainer(getter_AddRefs(anchorNode));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
int32_t anchorOffset;
|
||||
rv = mAnchorRange->GetStartOffset(&anchorOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return aWordUtil.GetRangeForWord(anchorNode, anchorOffset,
|
||||
uint32_t anchorOffset = mAnchorRange->StartOffset();
|
||||
return aWordUtil.GetRangeForWord(anchorNode,
|
||||
static_cast<int32_t>(anchorOffset),
|
||||
getter_AddRefs(mNoCheckRange));
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1214,7 @@ mozInlineSpellChecker::MakeSpellCheckRange(
|
|||
return rv;
|
||||
}
|
||||
} else {
|
||||
int32_t endOffset = -1;
|
||||
uint32_t endOffset;
|
||||
endNode = nsRange::GetContainerAndOffsetAfter(endNode, &endOffset);
|
||||
rv = range->SetStartAndEnd(startNode, aStartOffset, endNode, endOffset);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
|
|
@ -4795,9 +4795,11 @@ PresShell::ClipListToRange(nsDisplayListBuilder *aBuilder,
|
|||
frame->GetOffsets(frameStartOffset, frameEndOffset);
|
||||
|
||||
int32_t hilightStart =
|
||||
atStart ? std::max(aRange->StartOffset(), frameStartOffset) : frameStartOffset;
|
||||
atStart ? std::max(static_cast<int32_t>(aRange->StartOffset()),
|
||||
frameStartOffset) : frameStartOffset;
|
||||
int32_t hilightEnd =
|
||||
atEnd ? std::min(aRange->EndOffset(), frameEndOffset) : frameEndOffset;
|
||||
atEnd ? std::min(static_cast<int32_t>(aRange->EndOffset()),
|
||||
frameEndOffset) : frameEndOffset;
|
||||
if (hilightStart < hilightEnd) {
|
||||
// determine the location of the start and end edges of the range.
|
||||
nsPoint startPoint, endPoint;
|
||||
|
|
|
@ -1896,7 +1896,7 @@ nsImageFrame::ShouldDisplaySelection()
|
|||
int32_t thisOffset = parentContent->IndexOf(mContent);
|
||||
nsCOMPtr<nsIDOMNode> parentNode = do_QueryInterface(parentContent);
|
||||
nsCOMPtr<nsIDOMNode> rangeNode;
|
||||
int32_t rangeOffset;
|
||||
uint32_t rangeOffset;
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
selection->GetRangeAt(0,getter_AddRefs(range));
|
||||
if (range)
|
||||
|
@ -1904,12 +1904,16 @@ nsImageFrame::ShouldDisplaySelection()
|
|||
range->GetStartContainer(getter_AddRefs(rangeNode));
|
||||
range->GetStartOffset(&rangeOffset);
|
||||
|
||||
if (parentNode && rangeNode && (rangeNode == parentNode) && rangeOffset == thisOffset)
|
||||
{
|
||||
if (parentNode && rangeNode && rangeNode == parentNode &&
|
||||
static_cast<int32_t>(rangeOffset) == thisOffset) {
|
||||
range->GetEndContainer(getter_AddRefs(rangeNode));
|
||||
range->GetEndOffset(&rangeOffset);
|
||||
if ((rangeNode == parentNode) && (rangeOffset == (thisOffset +1))) //+1 since that would mean this whole content is selected only
|
||||
return false; //do not allow nsFrame do draw any further selection
|
||||
// +1 since that would mean this whole content is selected only
|
||||
if (rangeNode == parentNode &&
|
||||
static_cast<int32_t>(rangeOffset) == thisOffset + 1) {
|
||||
// Do not allow nsFrame do draw any further selection
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -601,7 +601,7 @@ nsFind::NextNode(nsIDOMRange* aSearchRange,
|
|||
// beginning/end of the search range.
|
||||
nsCOMPtr<nsIDOMNode> startNode;
|
||||
nsCOMPtr<nsIDOMNode> endNode;
|
||||
int32_t startOffset, endOffset;
|
||||
uint32_t startOffset, endOffset;
|
||||
if (aContinueOk) {
|
||||
#ifdef DEBUG_FIND
|
||||
printf("Match in progress: continuing past endpoint\n");
|
||||
|
@ -637,7 +637,8 @@ nsFind::NextNode(nsIDOMRange* aSearchRange,
|
|||
}
|
||||
}
|
||||
|
||||
rv = InitIterator(startNode, startOffset, endNode, endOffset);
|
||||
rv = InitIterator(startNode, static_cast<int32_t>(startOffset),
|
||||
endNode, static_cast<int32_t>(endOffset));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!aStartPoint) {
|
||||
aStartPoint = aSearchRange;
|
||||
|
@ -657,14 +658,18 @@ nsFind::NextNode(nsIDOMRange* aSearchRange,
|
|||
if (mFindBackward) {
|
||||
aStartPoint->GetEndContainer(getter_AddRefs(node));
|
||||
if (mIterNode.get() == node.get()) {
|
||||
aStartPoint->GetEndOffset(&mIterOffset);
|
||||
uint32_t endOffset;
|
||||
aStartPoint->GetEndOffset(&endOffset);
|
||||
mIterOffset = static_cast<int32_t>(endOffset);
|
||||
} else {
|
||||
mIterOffset = -1; // sign to start from end
|
||||
}
|
||||
} else {
|
||||
aStartPoint->GetStartContainer(getter_AddRefs(node));
|
||||
if (mIterNode.get() == node.get()) {
|
||||
aStartPoint->GetStartOffset(&mIterOffset);
|
||||
uint32_t startOffset;
|
||||
aStartPoint->GetStartOffset(&startOffset);
|
||||
mIterOffset = static_cast<int32_t>(startOffset);
|
||||
} else {
|
||||
mIterOffset = 0;
|
||||
}
|
||||
|
@ -988,7 +993,7 @@ nsFind::Find(const char16_t* aPatText, nsIDOMRange* aSearchRange,
|
|||
|
||||
// Get the end point, so we know when to end searches:
|
||||
nsCOMPtr<nsIDOMNode> endNode;
|
||||
int32_t endOffset;
|
||||
uint32_t endOffset;
|
||||
aEndPoint->GetEndContainer(getter_AddRefs(endNode));
|
||||
aEndPoint->GetEndOffset(&endOffset);
|
||||
|
||||
|
@ -1123,8 +1128,8 @@ nsFind::Find(const char16_t* aPatText, nsIDOMRange* aSearchRange,
|
|||
// Have we gone past the endpoint yet? If we have, and we're not in the
|
||||
// middle of a match, return.
|
||||
if (mIterNode == endNode &&
|
||||
((mFindBackward && findex < endOffset) ||
|
||||
(!mFindBackward && findex > endOffset))) {
|
||||
((mFindBackward && findex < static_cast<int32_t>(endOffset)) ||
|
||||
(!mFindBackward && findex > static_cast<int32_t>(endOffset)))) {
|
||||
ResetAll();
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -516,7 +516,7 @@ nsWebBrowserFind::GetSearchLimits(nsIDOMRange* aSearchRange,
|
|||
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
int32_t offset;
|
||||
uint32_t offset;
|
||||
|
||||
// Forward, not wrapping: SelEnd to DocEnd
|
||||
if (!mFindBackwards && !aWrap) {
|
||||
|
|
|
@ -848,7 +848,7 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
|
|||
getter_AddRefs(mStartPointRange), nullptr);
|
||||
}
|
||||
else {
|
||||
int32_t startOffset;
|
||||
uint32_t startOffset;
|
||||
nsCOMPtr<nsIDOMNode> startNode;
|
||||
if (aFindPrev) {
|
||||
currentSelectionRange->GetStartContainer(getter_AddRefs(startNode));
|
||||
|
@ -886,7 +886,7 @@ nsTypeAheadFind::RangeStartsInsideLink(nsIDOMRange *aRange,
|
|||
nsCOMPtr<nsIDOMNode> startNode;
|
||||
nsCOMPtr<nsIContent> startContent, origContent;
|
||||
aRange->GetStartContainer(getter_AddRefs(startNode));
|
||||
int32_t startOffset;
|
||||
uint32_t startOffset;
|
||||
aRange->GetStartOffset(&startOffset);
|
||||
|
||||
startContent = do_QueryInterface(startNode);
|
||||
|
@ -906,9 +906,10 @@ nsTypeAheadFind::RangeStartsInsideLink(nsIDOMRange *aRange,
|
|||
const nsTextFragment *textFrag = startContent->GetText();
|
||||
if (textFrag) {
|
||||
// look for non whitespace character before start offset
|
||||
for (int32_t index = 0; index < startOffset; index++) {
|
||||
for (uint32_t index = 0; index < startOffset; index++) {
|
||||
// FIXME: take content language into account when deciding whitespace.
|
||||
if (!mozilla::dom::IsSpaceCharacter(textFrag->CharAt(index))) {
|
||||
if (!mozilla::dom::IsSpaceCharacter(
|
||||
textFrag->CharAt(static_cast<int32_t>(index)))) {
|
||||
*aIsStartingLink = false; // not at start of a node
|
||||
|
||||
break;
|
||||
|
@ -1235,12 +1236,14 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell,
|
|||
return true; // Don't need it to be on screen, just in rendering tree
|
||||
|
||||
// Get the next in flow frame that contains the range start
|
||||
int32_t startRangeOffset, startFrameOffset, endFrameOffset;
|
||||
int32_t startFrameOffset, endFrameOffset;
|
||||
uint32_t startRangeOffset;
|
||||
aRange->GetStartOffset(&startRangeOffset);
|
||||
while (true) {
|
||||
frame->GetOffsets(startFrameOffset, endFrameOffset);
|
||||
if (startRangeOffset < endFrameOffset)
|
||||
if (static_cast<int32_t>(startRangeOffset) < endFrameOffset) {
|
||||
break;
|
||||
}
|
||||
|
||||
nsIFrame *nextContinuationFrame = frame->GetNextContinuation();
|
||||
if (nextContinuationFrame)
|
||||
|
|
Загрузка…
Ссылка в новой задаче