Skip to content

Commit

Permalink
Bug 1377989 - part9: Rename aEndParent and aEndNode related to nsRang…
Browse files Browse the repository at this point in the history
…e to aEndContainer r=smaug

MozReview-Commit-ID: 8XJbHfsg2hu

--HG--
extra : rebase_source : 0ee22f0b0cf5fd8c0a8fea610c54be8492436488
  • Loading branch information
masayuki-nakano committed Jul 11, 2017
1 parent 4af6e5d commit 8ac3f65
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 67 deletions.
14 changes: 7 additions & 7 deletions dom/base/nsContentIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ NodeToParentOffset(nsINode* aNode, int32_t* aOffset)
static bool
NodeIsInTraversalRange(nsINode* aNode, bool aIsPreMode,
nsINode* aStartContainer, int32_t aStartOffset,
nsINode* aEndNode, int32_t aEndOffset)
nsINode* aEndContainer, int32_t aEndOffset)
{
if (NS_WARN_IF(!aStartContainer) || NS_WARN_IF(!aEndNode) ||
if (NS_WARN_IF(!aStartContainer) || NS_WARN_IF(!aEndContainer) ||
NS_WARN_IF(!aNode)) {
return false;
}

// If a leaf node contains an end point of the traversal range, it is
// always in the traversal range.
if (aNode == aStartContainer || aNode == aEndNode) {
if (aNode == aStartContainer || aNode == aEndContainer) {
if (aNode->IsNodeOfType(nsINode::eDATA_NODE)) {
return true; // text node or something
}
if (!aNode->HasChildren()) {
MOZ_ASSERT(aNode != aStartContainer || !aStartOffset,
"aStartContainer doesn't have children and not a data node, "
"aStartOffset should be 0");
MOZ_ASSERT(aNode != aEndNode || !aEndOffset,
"aStartContainer doesn't have children and not a data node, "
"aStartOffset should be 0");
MOZ_ASSERT(aNode != aEndContainer || !aEndOffset,
"aEndContainer doesn't have children and not a data node, "
"aEndOffset should be 0");
return true;
}
}
Expand All @@ -84,7 +84,7 @@ NodeIsInTraversalRange(nsINode* aNode, bool aIsPreMode,

return nsContentUtils::ComparePoints(aStartContainer, aStartOffset,
parent, indx) <= 0 &&
nsContentUtils::ComparePoints(aEndNode, aEndOffset,
nsContentUtils::ComparePoints(aEndContainer, aEndOffset,
parent, indx) >= 0;
}

Expand Down
58 changes: 31 additions & 27 deletions dom/base/nsRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,12 @@ nsRange::GetStartOffset(ErrorResult& aRv) const
}

NS_IMETHODIMP
nsRange::GetEndContainer(nsIDOMNode** aEndParent)
nsRange::GetEndContainer(nsIDOMNode** aEndContainer)
{
if (!mIsPositioned)
return NS_ERROR_NOT_INITIALIZED;

return CallQueryInterface(mEndContainer, aEndParent);
return CallQueryInterface(mEndContainer, aEndContainer);
}

nsINode*
Expand Down Expand Up @@ -1388,9 +1388,9 @@ nsRange::SetEnd(nsINode* aContainer, int32_t aOffset)

nsresult
nsRange::SetStartAndEnd(nsINode* aStartContainer, int32_t aStartOffset,
nsINode* aEndParent, int32_t aEndOffset)
nsINode* aEndContainer, int32_t aEndOffset)
{
if (NS_WARN_IF(!aStartContainer) || NS_WARN_IF(!aEndParent)) {
if (NS_WARN_IF(!aStartContainer) || NS_WARN_IF(!aEndContainer)) {
return NS_ERROR_INVALID_ARG;
}

Expand All @@ -1402,46 +1402,49 @@ nsRange::SetStartAndEnd(nsINode* aStartContainer, int32_t aStartOffset,
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}

if (aStartContainer == aEndParent) {
if (!IsValidOffset(aEndParent, aEndOffset)) {
if (aStartContainer == aEndContainer) {
if (!IsValidOffset(aEndContainer, aEndOffset)) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
// If the end offset is less than the start offset, this should be
// collapsed at the end offset.
if (aStartOffset > aEndOffset) {
DoSetRange(aEndParent, aEndOffset, aEndParent, aEndOffset, newStartRoot);
DoSetRange(aEndContainer, aEndOffset,
aEndContainer, aEndOffset, newStartRoot);
} else {
DoSetRange(aStartContainer, aStartOffset,
aEndParent, aEndOffset, newStartRoot);
aEndContainer, aEndOffset, newStartRoot);
}
return NS_OK;
}

nsINode* newEndRoot = IsValidBoundary(aEndParent);
nsINode* newEndRoot = IsValidBoundary(aEndContainer);
if (!newEndRoot) {
return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR;
}
if (!IsValidOffset(aEndParent, aEndOffset)) {
if (!IsValidOffset(aEndContainer, aEndOffset)) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}

// If they have different root, this should be collapsed at the end point.
if (newStartRoot != newEndRoot) {
DoSetRange(aEndParent, aEndOffset, aEndParent, aEndOffset, newEndRoot);
DoSetRange(aEndContainer, aEndOffset,
aEndContainer, aEndOffset, newEndRoot);
return NS_OK;
}

// If the end point is before the start point, this should be collapsed at
// the end point.
if (nsContentUtils::ComparePoints(aStartContainer, aStartOffset,
aEndParent, aEndOffset) == 1) {
DoSetRange(aEndParent, aEndOffset, aEndParent, aEndOffset, newEndRoot);
aEndContainer, aEndOffset) == 1) {
DoSetRange(aEndContainer, aEndOffset,
aEndContainer, aEndOffset, newEndRoot);
return NS_OK;
}

// Otherwise, set the range as specified.
DoSetRange(aStartContainer, aStartOffset,
aEndParent, aEndOffset, newStartRoot);
aEndContainer, aEndOffset, newStartRoot);
return NS_OK;
}

Expand Down Expand Up @@ -1946,13 +1949,13 @@ CollapseRangeAfterDelete(nsRange* aRange)
*
* @param aStartContainer The original node we are trying to split.
* @param aStartOffset The offset at which to split.
* @param aEndNode The second node.
* @param aEndContainer The second node.
* @param aCloneAfterOriginal Set false if the original node should be the
* latter one after split.
*/
static nsresult SplitDataNode(nsIDOMCharacterData* aStartContainer,
uint32_t aStartOffset,
nsIDOMCharacterData** aEndNode,
nsIDOMCharacterData** aEndContainer,
bool aCloneAfterOriginal = true)
{
nsresult rv;
Expand All @@ -1964,7 +1967,7 @@ static nsresult SplitDataNode(nsIDOMCharacterData* aStartContainer,
rv = dataNode->SplitData(aStartOffset, getter_AddRefs(newData),
aCloneAfterOriginal);
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(newData, aEndNode);
return CallQueryInterface(newData, aEndContainer);
}

NS_IMETHODIMP
Expand Down Expand Up @@ -3098,12 +3101,13 @@ nsRange::CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
nsRange* aRange,
nsINode* aStartContainer,
int32_t aStartOffset,
nsINode* aEndParent, int32_t aEndOffset,
nsINode* aEndContainer,
int32_t aEndOffset,
bool aClampToEdge, bool aFlushLayout)
{
// Hold strong pointers across the flush
nsCOMPtr<nsINode> startContainer = aStartContainer;
nsCOMPtr<nsINode> endContainer = aEndParent;
nsCOMPtr<nsINode> endContainer = aEndContainer;

// Flush out layout so our frames are up to date.
if (!aStartContainer->IsInUncomposedDoc()) {
Expand Down Expand Up @@ -3621,14 +3625,14 @@ IsLastNonemptyRowGroupOfTable(nsIFrame* aFrame)
void
nsRange::GetInnerTextNoFlush(DOMString& aValue, ErrorResult& aError,
nsIContent* aStartContainer, uint32_t aStartOffset,
nsIContent* aEndParent, uint32_t aEndOffset)
nsIContent* aEndContainer, uint32_t aEndOffset)
{
InnerTextAccumulator result(aValue);
nsIContent* currentNode = aStartContainer;
TreeTraversalState currentState = AFTER_NODE;
if (aStartContainer->IsNodeOfType(nsINode::eTEXT)) {
auto t = static_cast<nsGenericDOMDataNode*>(aStartContainer);
if (aStartContainer == aEndParent) {
if (aStartContainer == aEndContainer) {
AppendTransformedText(result, t, aStartOffset, aEndOffset);
return;
}
Expand All @@ -3640,13 +3644,13 @@ nsRange::GetInnerTextNoFlush(DOMString& aValue, ErrorResult& aError,
}
}

nsIContent* endNode = aEndParent;
nsIContent* endNode = aEndContainer;
TreeTraversalState endState = AFTER_NODE;
if (aEndParent->IsNodeOfType(nsINode::eTEXT)) {
if (aEndContainer->IsNodeOfType(nsINode::eTEXT)) {
endState = AT_NODE;
} else {
if (uint32_t(aEndOffset) < aEndParent->GetChildCount()) {
endNode = aEndParent->GetChildAt(aEndOffset);
if (uint32_t(aEndOffset) < aEndContainer->GetChildCount()) {
endNode = aEndContainer->GetChildAt(aEndOffset);
endState = AT_NODE;
}
}
Expand Down Expand Up @@ -3708,8 +3712,8 @@ nsRange::GetInnerTextNoFlush(DOMString& aValue, ErrorResult& aError,
}
}

if (aEndParent->IsNodeOfType(nsINode::eTEXT)) {
nsGenericDOMDataNode* t = static_cast<nsGenericDOMDataNode*>(aEndParent);
if (aEndContainer->IsNodeOfType(nsINode::eTEXT)) {
nsGenericDOMDataNode* t = static_cast<nsGenericDOMDataNode*>(aEndContainer);
AppendTransformedText(result, t, 0, aEndOffset);
}
// Do not flush trailing line breaks! Required breaks at the end of the text
Expand Down
13 changes: 7 additions & 6 deletions dom/base/nsRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class nsRange final : public nsIDOMRange,
explicit nsRange(nsINode* aNode);

static nsresult CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
nsIDOMNode* aEndParent, int32_t aEndOffset,
nsIDOMNode* aEndContainer, int32_t aEndOffset,
nsRange** aRange);
static nsresult CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
nsIDOMNode* aEndParent, int32_t aEndOffset,
nsIDOMNode* aEndContainer, int32_t aEndOffset,
nsIDOMRange** aRange);
static nsresult CreateRange(nsINode* aStartContainer, int32_t aStartOffset,
nsINode* aEndParent, int32_t aEndOffset,
nsINode* aEndContainer, int32_t aEndOffset,
nsRange** aRange);

NS_DECL_CYCLE_COLLECTING_ISUPPORTS
Expand Down Expand Up @@ -161,7 +161,7 @@ class nsRange final : public nsIDOMRange,
* the range will be collapsed at the end point.
*/
nsresult SetStartAndEnd(nsINode* aStartContainer, int32_t aStartOffset,
nsINode* aEndParent, int32_t aEndOffset);
nsINode* aEndContainer, int32_t aEndOffset);

/**
* CollapseTo() works similar to call both SetStart() and SetEnd() with
Expand Down Expand Up @@ -272,7 +272,7 @@ class nsRange final : public nsIDOMRange,
mozilla::ErrorResult& aError,
nsIContent* aStartContainer,
uint32_t aStartOffset,
nsIContent* aEndParent,
nsIContent* aEndContainer,
uint32_t aEndOffset);

nsINode* GetParentObject() const { return mOwner; }
Expand Down Expand Up @@ -328,7 +328,8 @@ class nsRange final : public nsIDOMRange,
nsRange* aRange,
nsINode* aStartContainer,
int32_t aStartOffset,
nsINode* aEndParent, int32_t aEndOffset,
nsINode* aEndContainer,
int32_t aEndOffset,
bool aClampToEdge, bool aFlushLayout);

/**
Expand Down
16 changes: 8 additions & 8 deletions editor/libeditor/EditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3862,14 +3862,14 @@ EditorBase::GetEndNodeAndOffset(Selection* aSelection,

nsresult
EditorBase::GetEndNodeAndOffset(Selection* aSelection,
nsINode** aEndNode,
nsINode** aEndContainer,
int32_t* aEndOffset)
{
MOZ_ASSERT(aSelection);
MOZ_ASSERT(aEndNode);
MOZ_ASSERT(aEndContainer);
MOZ_ASSERT(aEndOffset);

*aEndNode = nullptr;
*aEndContainer = nullptr;
*aEndOffset = 0;

NS_ENSURE_TRUE(aSelection->RangeCount(), NS_ERROR_FAILURE);
Expand All @@ -3879,7 +3879,7 @@ EditorBase::GetEndNodeAndOffset(Selection* aSelection,

NS_ENSURE_TRUE(range->IsPositioned(), NS_ERROR_FAILURE);

NS_IF_ADDREF(*aEndNode = range->GetEndContainer());
NS_IF_ADDREF(*aEndContainer = range->GetEndContainer());
*aEndOffset = range->EndOffset();
return NS_OK;
}
Expand Down Expand Up @@ -4664,12 +4664,12 @@ EditorBase::CreateTxnForDeleteRange(nsRange* aRangeToDelete,
nsresult
EditorBase::CreateRange(nsIDOMNode* aStartContainer,
int32_t aStartOffset,
nsIDOMNode* aEndParent,
nsIDOMNode* aEndContainer,
int32_t aEndOffset,
nsRange** aRange)
{
return nsRange::CreateRange(aStartContainer, aStartOffset,
aEndParent, aEndOffset, aRange);
aEndContainer, aEndOffset, aRange);
}

nsresult
Expand Down Expand Up @@ -4818,14 +4818,14 @@ EditorBase::HandleInlineSpellCheck(EditAction action,
int32_t previousSelectedOffset,
nsIDOMNode* aStartContainer,
int32_t aStartOffset,
nsIDOMNode* aEndNode,
nsIDOMNode* aEndContainer,
int32_t aEndOffset)
{
// Have to cast action here because this method is from an IDL
return mInlineSpellChecker ? mInlineSpellChecker->SpellCheckAfterEditorChange(
(int32_t)action, aSelection,
previousSelectedNode, previousSelectedOffset,
aStartContainer, aStartOffset, aEndNode,
aStartContainer, aStartOffset, aEndContainer,
aEndOffset)
: NS_OK;
}
Expand Down
6 changes: 3 additions & 3 deletions editor/libeditor/EditorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ class EditorBase : public nsIEditor
nsIDOMNode** outEndNode,
int32_t* outEndOffset);
static nsresult GetEndNodeAndOffset(Selection* aSelection,
nsINode** aEndNode,
nsINode** aEndContainer,
int32_t* aEndOffset);
#if DEBUG_JOE
static void DumpNode(nsIDOMNode* aNode, int32_t indent = 0);
Expand All @@ -825,7 +825,7 @@ class EditorBase : public nsIEditor
* Used by table cell selection methods.
*/
nsresult CreateRange(nsIDOMNode* aStartContainer, int32_t aStartOffset,
nsIDOMNode* aEndParent, int32_t aEndOffset,
nsIDOMNode* aEndContainer, int32_t aEndOffset,
nsRange** aRange);

/**
Expand Down Expand Up @@ -867,7 +867,7 @@ class EditorBase : public nsIEditor
int32_t previousSelectedOffset,
nsIDOMNode* aStartContainer,
int32_t aStartOffset,
nsIDOMNode* aEndNode,
nsIDOMNode* aEndContainer,
int32_t aEndOffset);

virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() = 0;
Expand Down
2 changes: 1 addition & 1 deletion editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ class HTMLEditor final : public TextEditor
nsTArray<OwningNonNull<nsINode>>& outNodeList,
nsINode* aStartContainer,
int32_t aStartOffset,
nsINode* aEndNode,
nsINode* aEndContainer,
int32_t aEndOffset);
nsresult CreateTagStack(nsTArray<nsString>& aTagStack,
nsIDOMNode* aNode);
Expand Down
6 changes: 3 additions & 3 deletions editor/libeditor/HTMLEditorDataTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2229,21 +2229,21 @@ HTMLEditor::CreateListOfNodesToPaste(
nsTArray<OwningNonNull<nsINode>>& outNodeList,
nsINode* aStartContainer,
int32_t aStartOffset,
nsINode* aEndNode,
nsINode* aEndContainer,
int32_t aEndOffset)
{
// If no info was provided about the boundary between context and stream,
// then assume all is stream.
if (!aStartContainer) {
aStartContainer = &aFragment;
aStartOffset = 0;
aEndNode = &aFragment;
aEndContainer = &aFragment;
aEndOffset = aFragment.Length();
}

RefPtr<nsRange> docFragRange;
nsresult rv = nsRange::CreateRange(aStartContainer, aStartOffset,
aEndNode, aEndOffset,
aEndContainer, aEndOffset,
getter_AddRefs(docFragRange));
MOZ_ASSERT(NS_SUCCEEDED(rv));
NS_ENSURE_SUCCESS(rv, );
Expand Down
Loading

0 comments on commit 8ac3f65

Please sign in to comment.