Bug 1423835 - part 3: Rename EditorDOMPointBase::GetChildAtOffset() to EditorDOMPointBase::GetChild() r=m_kato

Different from RangeBoundaryBase, EditorDOMPointBase can store only child node.
I.e., mOffset may be invalid until its Offset() is called.  So,
GetChildAtOffset() isn't good name.  It should be just GetChild().

Similarly, GetNextSiblingOfChildAtOffset() and
GetPreviousSiblingOfChildAtOffset() should be renamed to GetNextSiblingOfChild()
and GetPreviousSiblingOfChild().

MozReview-Commit-ID: WpkPmDwkrL

--HG--
extra : rebase_source : 2be1fcbee129f4c96e9b166be5a924845340708f
This commit is contained in:
Masayuki Nakano 2017-12-07 19:08:56 +09:00
Родитель dacd109e2f
Коммит 6b577ea0fa
13 изменённых файлов: 72 добавлений и 68 удалений

Просмотреть файл

@ -115,15 +115,15 @@ CreateElementTransaction::InsertNewNode(ErrorResult& aError)
}
mPointToInsert.GetContainer()->
InsertBefore(*mNewNode,
mPointToInsert.GetChildAtOffset(),
mPointToInsert.GetChild(),
aError);
NS_WARNING_ASSERTION(!aError.Failed(), "Failed to insert the new node");
return;
}
if (NS_WARN_IF(mPointToInsert.GetChildAtOffset() &&
if (NS_WARN_IF(mPointToInsert.GetChild() &&
mPointToInsert.GetContainer() !=
mPointToInsert.GetChildAtOffset()->GetParentNode())) {
mPointToInsert.GetChild()->GetParentNode())) {
aError.Throw(NS_ERROR_FAILURE);
return;
}

Просмотреть файл

@ -1437,7 +1437,7 @@ EditorBase::CreateNode(nsAtom* aTag,
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillCreateNode(nsDependentAtomString(aTag),
GetAsDOMNode(pointToInsert.GetChildAtOffset()));
GetAsDOMNode(pointToInsert.GetChild()));
}
}
@ -1449,7 +1449,7 @@ EditorBase::CreateNode(nsAtom* aTag,
if (NS_SUCCEEDED(rv)) {
ret = transaction->GetNewNode();
MOZ_ASSERT(ret);
// Now, aPointToInsert may be invalid. I.e., ChildAtOffset() keeps
// Now, aPointToInsert may be invalid. I.e., GetChild() keeps
// referring the next sibling of new node but Offset() refers the
// new node. Let's make refer the new node.
pointToInsert.Set(ret);
@ -1503,7 +1503,7 @@ EditorBase::InsertNode(nsIContent& aContentToInsert,
for (auto& listener : listeners) {
listener->WillInsertNode(
aContentToInsert.AsDOMNode(),
GetAsDOMNode(aPointToInsert.GetNextSiblingOfChildAtOffset()));
GetAsDOMNode(aPointToInsert.GetNextSiblingOfChild()));
}
}
@ -2004,7 +2004,7 @@ EditorBase::MoveChildren(nsIContent& aFirstChild,
}
nsCOMPtr<nsINode> newContainer = aPointToInsert.GetContainer();
nsCOMPtr<nsIContent> nextNode = aPointToInsert.GetChildAtOffset();
nsCOMPtr<nsIContent> nextNode = aPointToInsert.GetChild();
for (size_t i = children.Length(); i > 0; --i) {
nsCOMPtr<nsIContent>& child = children[i - 1];
if (child->GetParentNode() != oldContainer) {
@ -2622,7 +2622,7 @@ EditorBase::FindBetterInsertionPoint(const EditorRawDOMPoint& aPoint)
if (AsHTMLEditor()) {
// Fall back to a slow path that uses GetChildAt() for Thunderbird's
// plaintext editor.
nsIContent* child = aPoint.GetPreviousSiblingOfChildAtOffset();
nsIContent* child = aPoint.GetPreviousSiblingOfChild();
if (child && child->IsNodeOfType(nsINode::eTEXT)) {
if (NS_WARN_IF(child->Length() > INT32_MAX)) {
return aPoint;
@ -2708,11 +2708,11 @@ EditorBase::InsertTextImpl(nsIDocument& aDocument,
if (!pointToInsert.IsInTextNode()) {
nsIContent* child = nullptr;
if (!pointToInsert.IsStartOfContainer() &&
(child = pointToInsert.GetPreviousSiblingOfChildAtOffset()) &&
(child = pointToInsert.GetPreviousSiblingOfChild()) &&
child->IsNodeOfType(nsINode::eTEXT)) {
pointToInsert.Set(child, child->Length());
} else if (!pointToInsert.IsEndOfContainer() &&
(child = pointToInsert.GetChildAtOffset()) &&
(child = pointToInsert.GetChild()) &&
child->IsNodeOfType(nsINode::eTEXT)) {
pointToInsert.Set(child, 0);
}
@ -3152,7 +3152,7 @@ EditorBase::SplitNodeImpl(const EditorDOMPoint& aStartOfRightNode,
}
// Fix the child before mutation observer may touch the DOM tree.
nsIContent* firstChildOfRightNode = aStartOfRightNode.GetChildAtOffset();
nsIContent* firstChildOfRightNode = aStartOfRightNode.GetChild();
parent->InsertBefore(aNewLeftNode, aStartOfRightNode.GetContainer(),
aError);
if (NS_WARN_IF(aError.Failed())) {
@ -3549,8 +3549,8 @@ EditorBase::GetPreviousNodeInternal(const EditorRawDOMPoint& aPoint,
}
// else look before the child at 'aOffset'
if (aPoint.GetChildAtOffset()) {
return GetPreviousNodeInternal(*aPoint.GetChildAtOffset(),
if (aPoint.GetChild()) {
return GetPreviousNodeInternal(*aPoint.GetChild(),
aFindEditableNode, aNoBlockCrossing);
}
@ -3603,16 +3603,15 @@ EditorBase::GetNextNodeInternal(const EditorRawDOMPoint& aPoint,
}
}
// look at the child at 'aOffset'
if (point.GetChildAtOffset()) {
if (aNoBlockCrossing && IsBlockNode(point.GetChildAtOffset())) {
return point.GetChildAtOffset();
if (point.GetChild()) {
if (aNoBlockCrossing && IsBlockNode(point.GetChild())) {
return point.GetChild();
}
nsIContent* leftMostNode =
GetLeftmostChild(point.GetChildAtOffset(), aNoBlockCrossing);
GetLeftmostChild(point.GetChild(), aNoBlockCrossing);
if (!leftMostNode) {
return point.GetChildAtOffset();
return point.GetChild();
}
if (!IsDescendantOfEditorRoot(leftMostNode)) {

Просмотреть файл

@ -398,7 +398,7 @@ public:
/**
* MoveAllChildren() moves all children of aContainer to before
* aPointToInsert.GetChildAtOffset().
* aPointToInsert.GetChild().
* See explanation of MoveChildren() for the detail of the behavior.
*
* @param aContainer The container node whose all children should
@ -414,7 +414,7 @@ public:
/**
* MovePreviousSiblings() moves all siblings before aChild (i.e., aChild
* won't be moved) to before aPointToInsert.GetChildAtOffset().
* won't be moved) to before aPointToInsert.GetChild().
* See explanation of MoveChildren() for the detail of the behavior.
*
* @param aChild The node which is next sibling of the last
@ -430,7 +430,7 @@ public:
/**
* MoveChildren() moves all children between aFirstChild and aLastChild to
* before aPointToInsert.GetChildAtOffset().
* before aPointToInsert.GetChild().
* If some children are moved to different container while this method
* moves other children, they are just ignored.
* If the child node referred by aPointToInsert is moved to different
@ -974,7 +974,7 @@ public:
* // Do something...
* DebugOnly<bool> advanced = point.Advanced();
* MOZ_ASSERT(advanced);
* point.Set(point.GetChildAtOffset());
* point.Set(point.GetChild());
* }
*
* On the other hand, the methods taking nsINode behavior must be what

Просмотреть файл

@ -39,9 +39,9 @@ class EditorDOMPointBase;
* starts to refer the child node or offset in the container. In this case,
* the other information hasn't been initialized due to performance reason.
* When you retrieve the other information with calling Offset() or
* GetChildAtOffset(), the other information is computed with the current
* DOM tree. Therefore, e.g., in the following case, the other information
* may be different:
* GetChild(), the other information is computed with the current DOM tree.
* Therefore, e.g., in the following case, the other information may be
* different:
*
* EditorDOMPoint pointA(container1, childNode1);
* EditorDOMPoint pointB(container1, childNode1);
@ -53,11 +53,10 @@ class EditorDOMPointBase;
*
* EditorDOMPoint pointA(container1, 5);
* EditorDOMPoint pointB(container1, 5);
* Unused << pointA.GetChildAtOffset(); // The child is computed now.
* Unused << pointA.GetChild(); // The child is computed now.
* container1->RemoveChild(childNode1->GetFirstChild());
* Unused << pointB.GetChildAtOffset(); // Now, pointB.GetChildAtOffset() equals
* // pointA.GetChildAtOffset()->
* // GetPreviousSibling().
* Unused << pointB.GetChild(); // Now, pointB.GetChild() equals
* // pointA.GetChild()->GetPreviousSibling().
*
* So, when you initialize an instance only with one information, you need to
* be careful when you access the other information after changing the DOM tree.
@ -255,8 +254,13 @@ public:
return mParent && mParent->IsAnyOfHTMLElements(aFirst, aArgs...);
}
/**
* GetChild() returns a child node which is pointed by the instance.
* If mChild hasn't been initialized yet, this computes the child node
* from mParent and mOffset with *current* DOM tree.
*/
nsIContent*
GetChildAtOffset() const
GetChild() const
{
if (!mParent || !mParent->IsContainerNode()) {
return nullptr;
@ -270,12 +274,14 @@ public:
}
/**
* GetNextSiblingOfChildOffset() returns next sibling of a child at offset.
* GetNextSiblingOfChild() returns next sibling of the child node.
* If this refers after the last child or the container cannot have children,
* this returns nullptr with warning.
* If mChild hasn't been initialized yet, this computes the child node
* from mParent and mOffset with *current* DOM tree.
*/
nsIContent*
GetNextSiblingOfChildAtOffset() const
GetNextSiblingOfChild() const
{
if (NS_WARN_IF(!mParent) || NS_WARN_IF(!mParent->IsContainerNode())) {
return nullptr;
@ -295,12 +301,14 @@ public:
}
/**
* GetPreviousSiblingOfChildAtOffset() returns previous sibling of a child
* GetPreviousSiblingOfChild() returns previous sibling of a child
* at offset. If this refers the first child or the container cannot have
* children, this returns nullptr with warning.
* If mChild hasn't been initialized yet, this computes the child node
* from mParent and mOffset with *current* DOM tree.
*/
nsIContent*
GetPreviousSiblingOfChildAtOffset() const
GetPreviousSiblingOfChild() const
{
if (NS_WARN_IF(!mParent) || NS_WARN_IF(!mParent->IsContainerNode())) {
return nullptr;
@ -785,7 +793,7 @@ public:
{
MOZ_ASSERT(aPoint.IsSetAndValid());
MOZ_ASSERT(mPoint.CanContainerHaveChildren());
mChild = mPoint.GetChildAtOffset();
mChild = mPoint.GetChild();
}
~AutoEditorDOMPointOffsetInvalidator()

Просмотреть файл

@ -176,7 +176,7 @@ public:
nsIContent* GetRightNode() const
{
if (mGivenSplitPoint.IsSet()) {
return mGivenSplitPoint.GetChildAtOffset();
return mGivenSplitPoint.GetChild();
}
return mPreviousNode && !mNextNode ? mPreviousNode : mNextNode;
}
@ -188,7 +188,7 @@ public:
{
if (mGivenSplitPoint.IsSet()) {
return mGivenSplitPoint.IsEndOfContainer() ?
mGivenSplitPoint.GetChildAtOffset() : nullptr;
mGivenSplitPoint.GetChild() : nullptr;
}
return mPreviousNode;
}
@ -200,7 +200,7 @@ public:
{
if (mGivenSplitPoint.IsSet()) {
return !mGivenSplitPoint.IsEndOfContainer() ?
mGivenSplitPoint.GetChildAtOffset() : nullptr;
mGivenSplitPoint.GetChild() : nullptr;
}
return mNextNode;
}

Просмотреть файл

@ -5057,9 +5057,8 @@ HTMLEditRules::WillAlign(Selection& aSelection,
// putting our div is not a block, then the br we found is in same block
// we are, so it's safe to consume it.
nsCOMPtr<nsIContent> sibling;
if (pointToInsertDiv.GetChildAtOffset()) {
sibling =
htmlEditor->GetNextHTMLSibling(pointToInsertDiv.GetChildAtOffset());
if (pointToInsertDiv.GetChild()) {
sibling = htmlEditor->GetNextHTMLSibling(pointToInsertDiv.GetChild());
}
if (sibling && !IsBlockNode(*sibling)) {
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertDiv);
@ -7561,7 +7560,7 @@ HTMLEditRules::MaybeSplitAncestorsForInsert(
pointToInsert.Set(pointToInsert.GetContainer())) {
// We cannot split active editing host and its ancestor. So, there is
// no element to contain the specified element.
if (NS_WARN_IF(pointToInsert.GetChildAtOffset() == host)) {
if (NS_WARN_IF(pointToInsert.GetChild() == host)) {
return SplitNodeResult(NS_ERROR_FAILURE);
}
@ -7581,7 +7580,7 @@ HTMLEditRules::MaybeSplitAncestorsForInsert(
}
SplitNodeResult splitNodeResult =
htmlEditor->SplitNodeDeep(*pointToInsert.GetChildAtOffset(),
htmlEditor->SplitNodeDeep(*pointToInsert.GetChild(),
aStartOfDeepestRightNode,
SplitAtEdges::eAllowToCreateEmptyContainer);
NS_WARNING_ASSERTION(splitNodeResult.Succeeded(),
@ -7987,9 +7986,8 @@ HTMLEditRules::CheckInterlinePosition(Selection& aSelection)
}
// Are we after a block? If so try set caret to following content
if (atStartOfSelection.GetChildAtOffset()) {
node =
htmlEditor->GetPriorHTMLSibling(atStartOfSelection.GetChildAtOffset());
if (atStartOfSelection.GetChild()) {
node = htmlEditor->GetPriorHTMLSibling(atStartOfSelection.GetChild());
} else {
node = nullptr;
}
@ -7999,9 +7997,8 @@ HTMLEditRules::CheckInterlinePosition(Selection& aSelection)
}
// Are we before a block? If so try set caret to prior content
if (atStartOfSelection.GetChildAtOffset()) {
node =
htmlEditor->GetNextHTMLSibling(atStartOfSelection.GetChildAtOffset());
if (atStartOfSelection.GetChild()) {
node = htmlEditor->GetNextHTMLSibling(atStartOfSelection.GetChild());
} else {
node = nullptr;
}

Просмотреть файл

@ -1555,9 +1555,9 @@ HTMLEditor::InsertNodeIntoProperAncestor(
if (pointToInsert != aPointToInsert) {
// We need to split some levels above the original selection parent.
MOZ_ASSERT(pointToInsert.GetChildAtOffset());
MOZ_ASSERT(pointToInsert.GetChild());
SplitNodeResult splitNodeResult =
SplitNodeDeep(*pointToInsert.GetChildAtOffset(),
SplitNodeDeep(*pointToInsert.GetChild(),
aPointToInsert, aSplitAtEdges);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return EditorDOMPoint();
@ -1943,7 +1943,7 @@ HTMLEditor::MakeOrChangeList(const nsAString& aListType,
if (pointToInsertList.GetContainer() != atStartOfSelection.GetContainer()) {
// We need to split up to the child of parent.
SplitNodeResult splitNodeResult =
SplitNodeDeep(*pointToInsertList.GetChildAtOffset(),
SplitNodeDeep(*pointToInsertList.GetChild(),
atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
@ -2093,7 +2093,7 @@ HTMLEditor::InsertBasicBlock(const nsAString& aBlockType)
atStartOfSelection.GetContainer()) {
// We need to split up to the child of the point to insert a block.
SplitNodeResult splitBlockResult =
SplitNodeDeep(*pointToInsertBlock.GetChildAtOffset(),
SplitNodeDeep(*pointToInsertBlock.GetChild(),
atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitBlockResult.Failed())) {
@ -2176,7 +2176,7 @@ HTMLEditor::Indent(const nsAString& aIndent)
atStartOfSelection.GetContainer()) {
// We need to split up to the child of parent.
SplitNodeResult splitBlockquoteResult =
SplitNodeDeep(*pointToInsertBlockquote.GetChildAtOffset(),
SplitNodeDeep(*pointToInsertBlockquote.GetChild(),
atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitBlockquoteResult.Failed())) {
@ -2256,7 +2256,7 @@ HTMLEditor::GetElementOrParentByTagName(const nsAString& aTagName,
// Try to get the actual selected node
if (atAnchor.GetContainer()->HasChildNodes() &&
atAnchor.GetContainerAsContent()) {
node = atAnchor.GetChildAtOffset();
node = atAnchor.GetChild();
}
// Anchor node is probably a text node - just use that
if (!node) {

Просмотреть файл

@ -423,7 +423,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
MOZ_ASSERT(pointToInsert.GetContainer()->
GetChildAt(pointToInsert.Offset()) ==
pointToInsert.GetChildAtOffset());
pointToInsert.GetChild());
// Loop over the node list and paste the nodes:
nsCOMPtr<nsINode> parentBlock =

Просмотреть файл

@ -32,7 +32,7 @@ InsertNodeTransaction::InsertNodeTransaction(
{
MOZ_ASSERT(mPointToInsert.IsSetAndValid());
// Ensure mPointToInsert stores child at offset.
Unused << mPointToInsert.GetChildAtOffset();
Unused << mPointToInsert.GetChild();
}
InsertNodeTransaction::~InsertNodeTransaction()
@ -61,8 +61,8 @@ InsertNodeTransaction::DoTransaction()
if (!mPointToInsert.IsSetAndValid()) {
// It seems that DOM tree has been changed after first DoTransaction()
// and current RedoTranaction() call.
if (mPointToInsert.GetChildAtOffset()) {
EditorDOMPoint newPointToInsert(mPointToInsert.GetChildAtOffset());
if (mPointToInsert.GetChild()) {
EditorDOMPoint newPointToInsert(mPointToInsert.GetChild());
if (!newPointToInsert.IsSet()) {
// The insertion point has been removed from the DOM tree.
// In this case, we should append the node to the container instead.
@ -84,7 +84,7 @@ InsertNodeTransaction::DoTransaction()
ErrorResult error;
mPointToInsert.GetContainer()->InsertBefore(*mContentToInsert,
mPointToInsert.GetChildAtOffset(),
mPointToInsert.GetChild(),
error);
error.WouldReportJSException();
if (NS_WARN_IF(error.Failed())) {

Просмотреть файл

@ -146,7 +146,7 @@ SplitNodeTransaction::RedoTransaction()
nsCOMPtr<nsIContent> nextSibling;
for (uint32_t i = 0; i < mStartOfRightNode.Offset(); i++) {
// XXX This must be bad behavior. Perhaps, we should work with
// mStartOfRightNode::GetChildAtOffset(). Even if some children
// mStartOfRightNode::GetChild(). Even if some children
// before the right node have been inserted or removed, we should
// move all children before the right node because user must focus
// on the right node, so, it must be the expected behavior.

Просмотреть файл

@ -782,9 +782,9 @@ TextEditRules::WillInsertText(EditAction aAction,
!outString->IsEmpty() && outString->Last() == nsCRT::LF;
aSelection->SetInterlinePosition(endsWithLF);
MOZ_ASSERT(!pointAfterStringInserted.GetChildAtOffset(),
MOZ_ASSERT(!pointAfterStringInserted.GetChild(),
"After inserting text into a text node, pointAfterStringInserted."
"GetChildAtOffset() should be nullptr");
"GetChild() should be nullptr");
IgnoredErrorResult error;
aSelection->Collapse(pointAfterStringInserted, error);
if (error.Failed()) {

Просмотреть файл

@ -785,9 +785,9 @@ TextEditor::InsertLineBreak()
}
if (NS_SUCCEEDED(rv)) {
// set the selection to the correct location
MOZ_ASSERT(!pointAfterInsertedLineBreak.GetChildAtOffset(),
MOZ_ASSERT(!pointAfterInsertedLineBreak.GetChild(),
"After inserting text into a text node, pointAfterInsertedLineBreak."
"GetChildAtOffset() should be nullptr");
"GetChild() should be nullptr");
rv = selection->Collapse(pointAfterInsertedLineBreak);
if (NS_SUCCEEDED(rv)) {
// see if we're at the end of the editor range

Просмотреть файл

@ -1096,7 +1096,7 @@ WSRunObject::GetPreviousWSNode(const EditorDOMPoint& aPoint,
return nullptr;
}
nsCOMPtr<nsIContent> priorNode = aPoint.GetPreviousSiblingOfChildAtOffset();
nsCOMPtr<nsIContent> priorNode = aPoint.GetPreviousSiblingOfChild();
if (NS_WARN_IF(!priorNode)) {
return nullptr;
}
@ -1175,7 +1175,7 @@ WSRunObject::GetNextWSNode(const EditorDOMPoint& aPoint,
return nullptr;
}
nsCOMPtr<nsIContent> nextNode = aPoint.GetChildAtOffset();
nsCOMPtr<nsIContent> nextNode = aPoint.GetChild();
if (!nextNode) {
if (aPoint.GetContainer() == aBlockParent) {
// We are at end of the block.