Bug 1423835 - part 2: Rename EditorDOMPointBase::Container() to EditorDOMPointBase::GetContainer() and add some useful methods to access its container r=m_kato
EditorDOMPointBase::Container() may return nullptr. So, it should be renamed to GetContainer(). Then, the method name becomes longer and a lot of callers access the result directly. So, there should be following methods to make the callers shorter: - GetContainerAsContent() to return the container as nsIContent*. - GetContainerAsElement() to return the container as dom::Element*. - GetContainerAsText() to return the container as dom::Text. - GetContainerAsDOMNode() to return the container as nsIDOMNode*. - CanContainerHaveChildren() to check if the container can have child nodes. - IsInDataNode() to check if the point is in a data node including text node. - IsInTextNode() to check if the point is in a text node. - IsContainerHTMLElement() to check if the container is specific HTML element. - IsContainerAnyOfHTMLElements() to check if the container is one of the specified HTML elements. MozReview-Commit-ID: LkN2WBbCPj0
This commit is contained in:
@@ -24,7 +24,7 @@ SplitNodeTransaction::SplitNodeTransaction(
|
||||
, mStartOfRightNode(aStartOfRightNode)
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(aStartOfRightNode.IsSet());
|
||||
MOZ_DIAGNOSTIC_ASSERT(aStartOfRightNode.Container()->IsContent());
|
||||
MOZ_DIAGNOSTIC_ASSERT(aStartOfRightNode.GetContainerAsContent());
|
||||
}
|
||||
|
||||
SplitNodeTransaction::~SplitNodeTransaction()
|
||||
@@ -55,7 +55,7 @@ SplitNodeTransaction::DoTransaction()
|
||||
ErrorResult error;
|
||||
// Don't use .downcast directly because AsContent has an assertion we want
|
||||
nsCOMPtr<nsINode> clone =
|
||||
mStartOfRightNode.Container()->CloneNode(false, error);
|
||||
mStartOfRightNode.GetContainer()->CloneNode(false, error);
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
@@ -63,10 +63,10 @@ SplitNodeTransaction::DoTransaction()
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
mNewLeftNode = dont_AddRef(clone.forget().take()->AsContent());
|
||||
mEditorBase->MarkNodeDirty(mStartOfRightNode.Container()->AsDOMNode());
|
||||
mEditorBase->MarkNodeDirty(mStartOfRightNode.GetContainerAsDOMNode());
|
||||
|
||||
// Get the parent node
|
||||
mParent = mStartOfRightNode.Container()->GetParentNode();
|
||||
mParent = mStartOfRightNode.GetContainer()->GetParentNode();
|
||||
if (NS_WARN_IF(!mParent)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@@ -114,8 +114,8 @@ SplitNodeTransaction::UndoTransaction()
|
||||
// This assumes Do inserted the new node in front of the prior existing node
|
||||
// XXX Perhaps, we should reset mStartOfRightNode with current first child
|
||||
// of the right node.
|
||||
return mEditorBase->JoinNodesImpl(mStartOfRightNode.Container(), mNewLeftNode,
|
||||
mParent);
|
||||
return mEditorBase->JoinNodesImpl(mStartOfRightNode.GetContainer(),
|
||||
mNewLeftNode, mParent);
|
||||
}
|
||||
|
||||
/* Redo cannot simply resplit the right node, because subsequent transactions
|
||||
@@ -132,8 +132,8 @@ SplitNodeTransaction::RedoTransaction()
|
||||
}
|
||||
|
||||
// First, massage the existing node so it is in its post-split state
|
||||
if (mStartOfRightNode.Container()->IsNodeOfType(nsINode::eTEXT)) {
|
||||
Text* rightNodeAsText = mStartOfRightNode.Container()->GetAsText();
|
||||
if (mStartOfRightNode.IsInTextNode()) {
|
||||
Text* rightNodeAsText = mStartOfRightNode.GetContainerAsText();
|
||||
MOZ_DIAGNOSTIC_ASSERT(rightNodeAsText);
|
||||
nsresult rv =
|
||||
rightNodeAsText->DeleteData(0, mStartOfRightNode.Offset());
|
||||
@@ -141,7 +141,8 @@ SplitNodeTransaction::RedoTransaction()
|
||||
return rv;
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIContent> child = mStartOfRightNode.Container()->GetFirstChild();
|
||||
nsCOMPtr<nsIContent> child =
|
||||
mStartOfRightNode.GetContainer()->GetFirstChild();
|
||||
nsCOMPtr<nsIContent> nextSibling;
|
||||
for (uint32_t i = 0; i < mStartOfRightNode.Offset(); i++) {
|
||||
// XXX This must be bad behavior. Perhaps, we should work with
|
||||
@@ -154,7 +155,7 @@ SplitNodeTransaction::RedoTransaction()
|
||||
}
|
||||
nextSibling = child->GetNextSibling();
|
||||
ErrorResult error;
|
||||
mStartOfRightNode.Container()->RemoveChild(*child, error);
|
||||
mStartOfRightNode.GetContainer()->RemoveChild(*child, error);
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
@@ -167,7 +168,7 @@ SplitNodeTransaction::RedoTransaction()
|
||||
}
|
||||
// Second, re-insert the left node into the tree
|
||||
ErrorResult error;
|
||||
mParent->InsertBefore(*mNewLeftNode, mStartOfRightNode.Container(), error);
|
||||
mParent->InsertBefore(*mNewLeftNode, mStartOfRightNode.GetContainer(), error);
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user