--- a/editor/libeditor/CreateElementTransaction.cpp
+++ b/editor/libeditor/CreateElementTransaction.cpp
@@ -104,49 +104,50 @@ CreateElementTransaction::DoTransaction(
return NS_OK;
}
void
CreateElementTransaction::InsertNewNode(ErrorResult& aError)
{
if (mPointToInsert.IsSetAndValid()) {
if (mPointToInsert.IsEndOfContainer()) {
- mPointToInsert.Container()->AppendChild(*mNewNode, aError);
+ mPointToInsert.GetContainer()->AppendChild(*mNewNode, aError);
NS_WARNING_ASSERTION(!aError.Failed(), "Failed to append the new node");
return;
}
- mPointToInsert.Container()->InsertBefore(*mNewNode,
- mPointToInsert.GetChildAtOffset(),
- aError);
+ mPointToInsert.GetContainer()->
+ InsertBefore(*mNewNode,
+ mPointToInsert.GetChildAtOffset(),
+ aError);
NS_WARNING_ASSERTION(!aError.Failed(), "Failed to insert the new node");
return;
}
if (NS_WARN_IF(mPointToInsert.GetChildAtOffset() &&
- mPointToInsert.Container() !=
+ mPointToInsert.GetContainer() !=
mPointToInsert.GetChildAtOffset()->GetParentNode())) {
aError.Throw(NS_ERROR_FAILURE);
return;
}
// If mPointToInsert has only offset and it's not valid, we need to treat
// it as pointing end of the container.
- mPointToInsert.Container()->AppendChild(*mNewNode, aError);
+ mPointToInsert.GetContainer()->AppendChild(*mNewNode, aError);
NS_WARNING_ASSERTION(!aError.Failed(), "Failed to append the new node");
}
NS_IMETHODIMP
CreateElementTransaction::UndoTransaction()
{
if (NS_WARN_IF(!mEditorBase) || NS_WARN_IF(!mPointToInsert.IsSet())) {
return NS_ERROR_NOT_INITIALIZED;
}
ErrorResult error;
- mPointToInsert.Container()->RemoveChild(*mNewNode, error);
+ mPointToInsert.GetContainer()->RemoveChild(*mNewNode, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
NS_IMETHODIMP
CreateElementTransaction::RedoTransaction()
--- a/editor/libeditor/DeleteRangeTransaction.h
+++ b/editor/libeditor/DeleteRangeTransaction.h
@@ -73,18 +73,18 @@ protected:
*/
nsresult CreateTxnsToDeleteBetween(const RawRangeBoundary& aStart,
const RawRangeBoundary& aEnd);
nsresult CreateTxnsToDeleteNodesBetween(nsRange* aRangeToDelete);
/**
* CreateTxnsToDeleteContent() creates a DeleteTextTransaction to delete
- * text between start of aPoint.Container() and aPoint or aPoint and end of
- * aPoint.Container() and appends the created transaction to the array.
+ * text between start of aPoint.GetContainer() and aPoint or aPoint and end of
+ * aPoint.GetContainer() and appends the created transaction to the array.
*
* @param aPoint Must be set and valid point. If the container is not
* a data node, this method does nothing.
* @param aAction If nsIEditor::eNext, this method creates a transaction
* to delete text from aPoint to the end of the data node.
* Otherwise, this method creates a transaction to delete
* text from start of the data node to aPoint.
* @return Returns NS_OK in most cases.
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1450,17 +1450,17 @@ EditorBase::CreateNode(nsAtom* aTag,
ret = transaction->GetNewNode();
MOZ_ASSERT(ret);
// Now, aPointToInsert may be invalid. I.e., ChildAtOffset() keeps
// referring the next sibling of new node but Offset() refers the
// new node. Let's make refer the new node.
pointToInsert.Set(ret);
}
- mRangeUpdater.SelAdjCreateNode(pointToInsert.Container(), offset);
+ mRangeUpdater.SelAdjCreateNode(pointToInsert.GetContainer(), offset);
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->DidCreateNode(nsDependentAtomString(aTag),
GetAsDOMNode(ret), rv);
}
}
@@ -1506,17 +1506,17 @@ EditorBase::InsertNode(nsIContent& aCont
GetAsDOMNode(aPointToInsert.GetNextSiblingOfChildAtOffset()));
}
}
RefPtr<InsertNodeTransaction> transaction =
CreateTxnForInsertNode(aContentToInsert, aPointToInsert);
nsresult rv = DoTransaction(transaction);
- mRangeUpdater.SelAdjInsertNode(aPointToInsert.Container(),
+ mRangeUpdater.SelAdjInsertNode(aPointToInsert.GetContainer(),
aPointToInsert.Offset());
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->DidInsertNode(aContentToInsert.AsDOMNode(), rv);
}
}
@@ -1546,52 +1546,52 @@ EditorBase::SplitNode(nsIDOMNode* aNode,
return NS_OK;
}
already_AddRefed<nsIContent>
EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
ErrorResult& aError)
{
if (NS_WARN_IF(!aStartOfRightNode.IsSet()) ||
- NS_WARN_IF(!aStartOfRightNode.Container()->IsContent())) {
+ NS_WARN_IF(!aStartOfRightNode.GetContainerAsContent())) {
aError.Throw(NS_ERROR_INVALID_ARG);
return nullptr;
}
MOZ_ASSERT(aStartOfRightNode.IsSetAndValid());
AutoRules beginRulesSniffing(this, EditAction::splitNode, nsIEditor::eNext);
// Different from CreateNode(), we need offset at start of right node only
// for WillSplitNode() since the offset is always same as the length of new
// left node.
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
// XXX Unfortunately, we need to compute offset here because the container
// may be a data node like text node. However, nobody implements this
// method actually. So, we should get rid of this in a follow up bug.
- listener->WillSplitNode(aStartOfRightNode.Container()->AsDOMNode(),
+ listener->WillSplitNode(aStartOfRightNode.GetContainerAsDOMNode(),
aStartOfRightNode.Offset());
}
}
RefPtr<SplitNodeTransaction> transaction =
CreateTxnForSplitNode(aStartOfRightNode);
aError = DoTransaction(transaction);
nsCOMPtr<nsIContent> newNode = transaction->GetNewNode();
NS_WARNING_ASSERTION(newNode, "Failed to create a new left node");
- mRangeUpdater.SelAdjSplitNode(*aStartOfRightNode.Container()->AsContent(),
+ mRangeUpdater.SelAdjSplitNode(*aStartOfRightNode.GetContainerAsContent(),
newNode);
{
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
- listener->DidSplitNode(aStartOfRightNode.Container()->AsDOMNode(),
+ listener->DidSplitNode(aStartOfRightNode.GetContainerAsDOMNode(),
GetAsDOMNode(newNode));
}
}
if (NS_WARN_IF(aError.Failed())) {
return nullptr;
}
@@ -1780,33 +1780,34 @@ EditorBase::RemoveContainer(nsIContent*
EditorDOMPoint pointToInsertChildren(aNode);
if (NS_WARN_IF(!pointToInsertChildren.IsSet())) {
return NS_ERROR_FAILURE;
}
// Notify our internal selection state listener.
AutoRemoveContainerSelNotify selNotify(mRangeUpdater, aNode,
- pointToInsertChildren.Container(),
+ pointToInsertChildren.GetContainer(),
pointToInsertChildren.Offset(),
aNode->GetChildCount());
// Move all children from aNode to its parent.
while (aNode->HasChildren()) {
nsCOMPtr<nsIContent> child = aNode->GetLastChild();
nsresult rv = DeleteNode(child);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Insert the last child before the previous last child. So, we need to
// use offset here because previous child might have been moved to
// container.
- rv = InsertNode(*child, EditorRawDOMPoint(pointToInsertChildren.Container(),
- pointToInsertChildren.Offset()));
+ rv = InsertNode(*child,
+ EditorRawDOMPoint(pointToInsertChildren.GetContainer(),
+ pointToInsertChildren.Offset()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return DeleteNode(aNode);
}
@@ -1976,17 +1977,17 @@ void
EditorBase::MoveChildren(nsIContent& aFirstChild,
nsIContent& aLastChild,
const EditorRawDOMPoint& aPointToInsert,
ErrorResult& aError)
{
nsCOMPtr<nsINode> oldContainer = aFirstChild.GetParentNode();
if (NS_WARN_IF(oldContainer != aLastChild.GetParentNode()) ||
NS_WARN_IF(!aPointToInsert.IsSet()) ||
- NS_WARN_IF(!aPointToInsert.Container()->IsContainerNode())) {
+ NS_WARN_IF(!aPointToInsert.CanContainerHaveChildren())) {
aError.Throw(NS_ERROR_INVALID_ARG);
return;
}
// First, store all children which should be moved to the new container.
AutoTArray<nsCOMPtr<nsIContent>, 10> children;
for (nsIContent* child = &aFirstChild;
child;
@@ -1997,17 +1998,17 @@ EditorBase::MoveChildren(nsIContent& aFi
}
}
if (NS_WARN_IF(children.LastElement() != &aLastChild)) {
aError.Throw(NS_ERROR_INVALID_ARG);
return;
}
- nsCOMPtr<nsINode> newContainer = aPointToInsert.Container();
+ nsCOMPtr<nsINode> newContainer = aPointToInsert.GetContainer();
nsCOMPtr<nsIContent> nextNode = aPointToInsert.GetChildAtOffset();
for (size_t i = children.Length(); i > 0; --i) {
nsCOMPtr<nsIContent>& child = children[i - 1];
if (child->GetParentNode() != oldContainer) {
// If the child has been moved to different container, we shouldn't
// touch it.
continue;
}
@@ -2016,17 +2017,17 @@ EditorBase::MoveChildren(nsIContent& aFi
return;
}
if (nextNode) {
// If we're not appending the children to the new container, we should
// check if referring next node of insertion point is still in the new
// container.
EditorRawDOMPoint pointToInsert(nextNode);
if (NS_WARN_IF(!pointToInsert.IsSet()) ||
- NS_WARN_IF(pointToInsert.Container() != newContainer)) {
+ NS_WARN_IF(pointToInsert.GetContainer() != newContainer)) {
// The next node of insertion point has been moved by mutation observer.
// Let's stop moving the remaining nodes.
// XXX Or should we move remaining children after the last moved child?
aError.Throw(NS_ERROR_FAILURE);
return;
}
}
newContainer->InsertBefore(*child, nextNode, aError);
@@ -2585,38 +2586,38 @@ EditorRawDOMPoint
EditorBase::FindBetterInsertionPoint(const EditorRawDOMPoint& aPoint)
{
if (NS_WARN_IF(!aPoint.IsSet())) {
return aPoint;
}
MOZ_ASSERT(aPoint.IsSetAndValid());
- if (aPoint.Container()->IsNodeOfType(nsINode::eTEXT)) {
+ if (aPoint.IsInTextNode()) {
// There is no "better" insertion point.
return aPoint;
}
if (!IsPlaintextEditor()) {
// We cannot find "better" insertion point in HTML editor.
// WARNING: When you add some code to find better node in HTML editor,
// you need to call this before calling InsertTextImpl() in
// HTMLEditRules.
return aPoint;
}
nsCOMPtr<nsINode> root = GetRoot();
- if (aPoint.Container() == root) {
+ if (aPoint.GetContainer() == root) {
// In some cases, aNode is the anonymous DIV, and offset is 0. To avoid
// injecting unneeded text nodes, we first look to see if we have one
// available. In that case, we'll just adjust node and offset accordingly.
if (aPoint.IsStartOfContainer() &&
- aPoint.Container()->HasChildren() &&
- aPoint.Container()->GetFirstChild()->IsNodeOfType(nsINode::eTEXT)) {
- return EditorRawDOMPoint(aPoint.Container()->GetFirstChild(), 0);
+ aPoint.GetContainer()->HasChildren() &&
+ aPoint.GetContainer()->GetFirstChild()->IsNodeOfType(nsINode::eTEXT)) {
+ return EditorRawDOMPoint(aPoint.GetContainer()->GetFirstChild(), 0);
}
// In some other cases, aNode is the anonymous DIV, and offset points to the
// terminating mozBR. In that case, we'll adjust aInOutNode and
// aInOutOffset to the preceding text node, if any.
if (!aPoint.IsStartOfContainer()) {
if (AsHTMLEditor()) {
// Fall back to a slow path that uses GetChildAt() for Thunderbird's
@@ -2626,47 +2627,47 @@ EditorBase::FindBetterInsertionPoint(con
if (NS_WARN_IF(child->Length() > INT32_MAX)) {
return aPoint;
}
return EditorRawDOMPoint(child, child->Length());
}
} else {
// If we're in a real plaintext editor, use a fast path that avoids
// calling GetChildAt() which may perform a linear search.
- nsIContent* child = aPoint.Container()->GetLastChild();
+ nsIContent* child = aPoint.GetContainer()->GetLastChild();
while (child) {
if (child->IsNodeOfType(nsINode::eTEXT)) {
if (NS_WARN_IF(child->Length() > INT32_MAX)) {
return aPoint;
}
return EditorRawDOMPoint(child, child->Length());
}
child = child->GetPreviousSibling();
}
}
}
}
// Sometimes, aNode is the mozBR element itself. In that case, we'll adjust
// the insertion point to the previous text node, if one exists, or to the
// parent anonymous DIV.
- if (TextEditUtils::IsMozBR(aPoint.Container()) &&
+ if (TextEditUtils::IsMozBR(aPoint.GetContainer()) &&
aPoint.IsStartOfContainer()) {
- nsIContent* previousSibling = aPoint.Container()->GetPreviousSibling();
+ nsIContent* previousSibling = aPoint.GetContainer()->GetPreviousSibling();
if (previousSibling && previousSibling->IsNodeOfType(nsINode::eTEXT)) {
if (NS_WARN_IF(previousSibling->Length() > INT32_MAX)) {
return aPoint;
}
return EditorRawDOMPoint(previousSibling, previousSibling->Length());
}
- nsINode* parentOfContainer = aPoint.Container()->GetParentNode();
+ nsINode* parentOfContainer = aPoint.GetContainer()->GetParentNode();
if (parentOfContainer && parentOfContainer == root) {
return EditorRawDOMPoint(parentOfContainer,
- aPoint.Container()->AsContent(), 0);
+ aPoint.GetContainerAsContent(), 0);
}
}
return aPoint;
}
nsresult
EditorBase::InsertTextImpl(nsIDocument& aDocument,
@@ -2699,67 +2700,67 @@ EditorBase::InsertTextImpl(nsIDocument&
}
// In some cases, the node may be the anonymous div elemnt or a mozBR
// element. Let's try to look for better insertion point in the nearest
// text node if there is.
EditorRawDOMPoint pointToInsert = FindBetterInsertionPoint(aPointToInsert);
// If a neighboring text node already exists, use that
- if (!pointToInsert.Container()->IsNodeOfType(nsINode::eTEXT)) {
+ if (!pointToInsert.IsInTextNode()) {
nsIContent* child = nullptr;
if (!pointToInsert.IsStartOfContainer() &&
(child = pointToInsert.GetPreviousSiblingOfChildAtOffset()) &&
child->IsNodeOfType(nsINode::eTEXT)) {
- pointToInsert.SetToEndOf(child);
+ pointToInsert.Set(child, child->Length());
} else if (!pointToInsert.IsEndOfContainer() &&
(child = pointToInsert.GetChildAtOffset()) &&
child->IsNodeOfType(nsINode::eTEXT)) {
pointToInsert.Set(child, 0);
}
}
if (ShouldHandleIMEComposition()) {
CheckedInt<int32_t> newOffset;
- if (!pointToInsert.Container()->IsNodeOfType(nsINode::eTEXT)) {
+ if (!pointToInsert.IsInTextNode()) {
// create a text node
RefPtr<nsTextNode> newNode =
EditorBase::CreateTextNode(aDocument, EmptyString());
// then we insert it into the dom tree
nsresult rv = InsertNode(*newNode, pointToInsert);
NS_ENSURE_SUCCESS(rv, rv);
pointToInsert.Set(newNode, 0);
newOffset = lengthToInsert;
} else {
newOffset = lengthToInsert + pointToInsert.Offset();
NS_ENSURE_TRUE(newOffset.isValid(), NS_ERROR_FAILURE);
}
nsresult rv =
InsertTextIntoTextNodeImpl(aStringToInsert,
- *pointToInsert.Container()->GetAsText(),
+ *pointToInsert.GetContainerAsText(),
pointToInsert.Offset());
NS_ENSURE_SUCCESS(rv, rv);
if (aPointAfterInsertedString) {
- aPointAfterInsertedString->Set(pointToInsert.Container(),
+ aPointAfterInsertedString->Set(pointToInsert.GetContainer(),
newOffset.value());
}
return NS_OK;
}
- if (pointToInsert.Container()->IsNodeOfType(nsINode::eTEXT)) {
+ if (pointToInsert.IsInTextNode()) {
CheckedInt<int32_t> newOffset = lengthToInsert + pointToInsert.Offset();
NS_ENSURE_TRUE(newOffset.isValid(), NS_ERROR_FAILURE);
// we are inserting text into an existing text node.
nsresult rv =
InsertTextIntoTextNodeImpl(aStringToInsert,
- *pointToInsert.Container()->GetAsText(),
+ *pointToInsert.GetContainerAsText(),
pointToInsert.Offset());
NS_ENSURE_SUCCESS(rv, rv);
if (aPointAfterInsertedString) {
- aPointAfterInsertedString->Set(pointToInsert.Container(),
+ aPointAfterInsertedString->Set(pointToInsert.GetContainer(),
newOffset.value());
}
return NS_OK;
}
// we are inserting text into a non-text node. first we have to create a
// textnode (this also populates it with the text)
RefPtr<nsTextNode> newNode =
@@ -3139,54 +3140,54 @@ EditorBase::SplitNodeImpl(const EditorDO
range.mStartOffset = r->StartOffset();
range.mEndContainer = r->GetEndContainer();
range.mEndOffset = r->EndOffset();
savedRanges.AppendElement(range);
}
}
- nsCOMPtr<nsINode> parent = aStartOfRightNode.Container()->GetParentNode();
+ nsCOMPtr<nsINode> parent = aStartOfRightNode.GetContainer()->GetParentNode();
if (NS_WARN_IF(!parent)) {
aError.Throw(NS_ERROR_FAILURE);
return;
}
// Fix the child before mutation observer may touch the DOM tree.
nsIContent* firstChildOfRightNode = aStartOfRightNode.GetChildAtOffset();
- parent->InsertBefore(aNewLeftNode, aStartOfRightNode.Container(),
+ parent->InsertBefore(aNewLeftNode, aStartOfRightNode.GetContainer(),
aError);
if (NS_WARN_IF(aError.Failed())) {
return;
}
// At this point, the existing right node has all the children. Move all
// the children which are before aStartOfRightNode.
if (!aStartOfRightNode.IsStartOfContainer()) {
// If it's a text node, just shuffle around some text
- Text* rightAsText = aStartOfRightNode.Container()->GetAsText();
+ Text* rightAsText = aStartOfRightNode.GetContainerAsText();
Text* leftAsText = aNewLeftNode.GetAsText();
if (rightAsText && leftAsText) {
// Fix right node
nsAutoString leftText;
rightAsText->SubstringData(0, aStartOfRightNode.Offset(),
leftText);
rightAsText->DeleteData(0, aStartOfRightNode.Offset());
// Fix left node
leftAsText->GetAsText()->SetData(leftText);
} else {
MOZ_DIAGNOSTIC_ASSERT(!rightAsText && !leftAsText);
// Otherwise it's an interior node, so shuffle around the children. Go
// through list backwards so deletes don't interfere with the iteration.
if (!firstChildOfRightNode) {
- MoveAllChildren(*aStartOfRightNode.Container(),
+ MoveAllChildren(*aStartOfRightNode.GetContainer(),
EditorRawDOMPoint(&aNewLeftNode, 0), aError);
NS_WARNING_ASSERTION(!aError.Failed(),
"Failed to move all children from the right node to the left node");
- } else if (NS_WARN_IF(aStartOfRightNode.Container() !=
+ } else if (NS_WARN_IF(aStartOfRightNode.GetContainer() !=
firstChildOfRightNode->GetParentNode())) {
// firstChildOfRightNode has been moved by mutation observer.
// In this case, we what should we do? Use offset? But we cannot
// check if the offset is still expected.
} else {
MovePreviousSiblings(*firstChildOfRightNode,
EditorRawDOMPoint(&aNewLeftNode, 0), aError);
NS_WARNING_ASSERTION(!aError.Failed(),
@@ -3229,26 +3230,26 @@ EditorBase::SplitNodeImpl(const EditorDO
if (shouldSetSelection &&
range.mSelection->Type() == SelectionType::eNormal) {
// If the editor should adjust the selection, don't bother restoring
// the ranges for the normal selection here.
continue;
}
// Split the selection into existing node and new node.
- if (range.mStartContainer == aStartOfRightNode.Container()) {
+ if (range.mStartContainer == aStartOfRightNode.GetContainer()) {
if (static_cast<uint32_t>(range.mStartOffset) <
aStartOfRightNode.Offset()) {
range.mStartContainer = &aNewLeftNode;
} else {
range.mStartOffset -= aStartOfRightNode.Offset();
}
}
- if (range.mEndContainer == aStartOfRightNode.Container()) {
+ if (range.mEndContainer == aStartOfRightNode.GetContainer()) {
if (static_cast<uint32_t>(range.mEndOffset) <
aStartOfRightNode.Offset()) {
range.mEndContainer = &aNewLeftNode;
} else {
range.mEndOffset -= aStartOfRightNode.Offset();
}
}
@@ -3527,43 +3528,41 @@ EditorBase::GetPreviousNodeInternal(nsIN
}
nsIContent*
EditorBase::GetPreviousNodeInternal(const EditorRawDOMPoint& aPoint,
bool aFindEditableNode,
bool aNoBlockCrossing)
{
MOZ_ASSERT(aPoint.IsSetAndValid());
- NS_WARNING_ASSERTION(!aPoint.Container()->IsNodeOfType(nsINode::eDATA_NODE) ||
- aPoint.Container()->IsNodeOfType(nsINode::eTEXT),
+ NS_WARNING_ASSERTION(!aPoint.IsInDataNode() || aPoint.IsInTextNode(),
"GetPreviousNodeInternal() doesn't assume that the start point is a "
"data node except text node");
// If we are at the beginning of the node, or it is a text node, then just
// look before it.
- if (aPoint.IsStartOfContainer() ||
- aPoint.Container()->IsNodeOfType(nsINode::eTEXT)) {
- if (aNoBlockCrossing && IsBlockNode(aPoint.Container())) {
+ if (aPoint.IsStartOfContainer() || aPoint.IsInTextNode()) {
+ if (aNoBlockCrossing && IsBlockNode(aPoint.GetContainer())) {
// If we aren't allowed to cross blocks, don't look before this block.
return nullptr;
}
- return GetPreviousNodeInternal(*aPoint.Container(),
+ return GetPreviousNodeInternal(*aPoint.GetContainer(),
aFindEditableNode, aNoBlockCrossing);
}
// else look before the child at 'aOffset'
if (aPoint.GetChildAtOffset()) {
return GetPreviousNodeInternal(*aPoint.GetChildAtOffset(),
aFindEditableNode, aNoBlockCrossing);
}
// unless there isn't one, in which case we are at the end of the node
// and want the deep-right child.
nsIContent* rightMostNode =
- GetRightmostChild(aPoint.Container(), aNoBlockCrossing);
+ GetRightmostChild(aPoint.GetContainer(), aNoBlockCrossing);
if (!rightMostNode) {
return nullptr;
}
if (!aFindEditableNode || IsEditable(rightMostNode)) {
return rightMostNode;
}
@@ -3584,26 +3583,25 @@ EditorBase::GetNextNodeInternal(nsINode&
}
nsIContent*
EditorBase::GetNextNodeInternal(const EditorRawDOMPoint& aPoint,
bool aFindEditableNode,
bool aNoBlockCrossing)
{
MOZ_ASSERT(aPoint.IsSetAndValid());
- NS_WARNING_ASSERTION(!aPoint.Container()->IsNodeOfType(nsINode::eDATA_NODE) ||
- aPoint.Container()->IsNodeOfType(nsINode::eTEXT),
+ NS_WARNING_ASSERTION(!aPoint.IsInDataNode() || aPoint.IsInTextNode(),
"GetNextNodeInternal() doesn't assume that the start point is a "
"data node except text node");
EditorRawDOMPoint point(aPoint);
// if the container is a text node, use its location instead
- if (point.Container()->IsNodeOfType(nsINode::eTEXT)) {
- point.Set(point.Container());
+ if (point.IsInTextNode()) {
+ point.Set(point.GetContainer());
bool advanced = point.AdvanceOffset();
if (NS_WARN_IF(!advanced)) {
return nullptr;
}
}
// look at the child at 'aOffset'
if (point.GetChildAtOffset()) {
@@ -3627,22 +3625,22 @@ EditorBase::GetNextNodeInternal(const Ed
// restart the search from the non-editable node we just found
return GetNextNodeInternal(*leftMostNode,
aFindEditableNode, aNoBlockCrossing);
}
// unless there isn't one, in which case we are at the end of the node
// and want the next one.
- if (aNoBlockCrossing && IsBlockNode(point.Container())) {
+ if (aNoBlockCrossing && IsBlockNode(point.GetContainer())) {
// don't cross out of parent block
return nullptr;
}
- return GetNextNodeInternal(*point.Container(),
+ return GetNextNodeInternal(*point.GetContainer(),
aFindEditableNode, aNoBlockCrossing);
}
nsIContent*
EditorBase::FindNextLeafNode(nsINode* aCurrentNode,
bool aGoForward,
bool bNoBlockCrossing)
{
@@ -4053,17 +4051,17 @@ EditorBase::GetStartNodeAndOffset(Select
*aStartContainer = nullptr;
*aStartOffset = 0;
EditorRawDOMPoint point = EditorBase::GetStartPoint(aSelection);
if (!point.IsSet()) {
return NS_ERROR_FAILURE;
}
- NS_ADDREF(*aStartContainer = point.Container());
+ NS_ADDREF(*aStartContainer = point.GetContainer());
*aStartOffset = point.Offset();
return NS_OK;
}
// static
EditorRawDOMPoint
EditorBase::GetStartPoint(Selection* aSelection)
{
@@ -4118,17 +4116,17 @@ EditorBase::GetEndNodeAndOffset(Selectio
*aEndContainer = nullptr;
*aEndOffset = 0;
EditorRawDOMPoint point = EditorBase::GetEndPoint(aSelection);
if (!point.IsSet()) {
return NS_ERROR_FAILURE;
}
- NS_ADDREF(*aEndContainer = point.Container());
+ NS_ADDREF(*aEndContainer = point.GetContainer());
*aEndOffset = point.Offset();
return NS_OK;
}
// static
EditorRawDOMPoint
EditorBase::GetEndPoint(Selection* aSelection)
{
@@ -4214,48 +4212,49 @@ EditorBase::IsPreformatted(nsIDOMNode* a
}
SplitNodeResult
EditorBase::SplitNodeDeep(nsIContent& aMostAncestorToSplit,
const EditorRawDOMPoint& aStartOfDeepestRightNode,
SplitAtEdges aSplitAtEdges)
{
MOZ_ASSERT(aStartOfDeepestRightNode.IsSetAndValid());
- MOZ_ASSERT(aStartOfDeepestRightNode.Container() == &aMostAncestorToSplit ||
- EditorUtils::IsDescendantOf(*aStartOfDeepestRightNode.Container(),
- aMostAncestorToSplit));
+ MOZ_ASSERT(aStartOfDeepestRightNode.GetContainer() == &aMostAncestorToSplit ||
+ EditorUtils::IsDescendantOf(
+ *aStartOfDeepestRightNode.GetContainer(),
+ aMostAncestorToSplit));
if (NS_WARN_IF(!aStartOfDeepestRightNode.IsSet())) {
return SplitNodeResult(NS_ERROR_INVALID_ARG);
}
nsCOMPtr<nsIContent> newLeftNodeOfMostAncestor;
EditorDOMPoint atStartOfRightNode(aStartOfDeepestRightNode);
while (true) {
// If we meet an orphan node before meeting aMostAncestorToSplit, we need
// to stop splitting. This is a bug of the caller.
- if (NS_WARN_IF(atStartOfRightNode.Container() != &aMostAncestorToSplit &&
- !atStartOfRightNode.Container()->GetParent())) {
+ if (NS_WARN_IF(atStartOfRightNode.GetContainer() != &aMostAncestorToSplit &&
+ !atStartOfRightNode.GetContainer()->GetParent())) {
return SplitNodeResult(NS_ERROR_FAILURE);
}
// Need to insert rules code call here to do things like not split a list
// if you are after the last <li> or before the first, etc. For now we
// just have some smarts about unneccessarily splitting text nodes, which
// should be universal enough to put straight in this EditorBase routine.
- if (NS_WARN_IF(!atStartOfRightNode.Container()->IsContent())) {
+ if (NS_WARN_IF(!atStartOfRightNode.GetContainerAsContent())) {
return SplitNodeResult(NS_ERROR_FAILURE);
}
- nsIContent* currentRightNode = atStartOfRightNode.Container()->AsContent();
+ nsIContent* currentRightNode = atStartOfRightNode.GetContainerAsContent();
// If the split point is middle of the node or the node is not a text node
// and we're allowed to create empty element node, split it.
if ((aSplitAtEdges == SplitAtEdges::eAllowToCreateEmptyContainer &&
- !atStartOfRightNode.Container()->GetAsText()) ||
+ !atStartOfRightNode.GetContainerAsText()) ||
(!atStartOfRightNode.IsStartOfContainer() &&
!atStartOfRightNode.IsEndOfContainer())) {
IgnoredErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
SplitNode(atStartOfRightNode.AsRaw(), error);
if (NS_WARN_IF(error.Failed())) {
return SplitNodeResult(NS_ERROR_FAILURE);
}
@@ -4542,40 +4541,39 @@ EditorBase::DeleteSelectionAndPrepareToC
MOZ_ASSERT(selection->GetAnchorFocusRange() &&
selection->GetAnchorFocusRange()->Collapsed(),
"Selection not collapsed after delete");
}
// If the selection is a chardata node, split it if necessary and compute
// where to put the new node
EditorDOMPoint atAnchor(selection->AnchorRef());
- if (NS_WARN_IF(!atAnchor.IsSet()) ||
- !atAnchor.Container()->IsNodeOfType(nsINode::eDATA_NODE)) {
+ if (NS_WARN_IF(!atAnchor.IsSet()) || !atAnchor.IsInDataNode()) {
return NS_OK;
}
- if (NS_WARN_IF(!atAnchor.Container()->GetParentNode())) {
+ if (NS_WARN_IF(!atAnchor.GetContainer()->GetParentNode())) {
return NS_ERROR_FAILURE;
}
if (atAnchor.IsStartOfContainer()) {
- EditorRawDOMPoint atAnchorContainer(atAnchor.Container());
+ EditorRawDOMPoint atAnchorContainer(atAnchor.GetContainer());
if (NS_WARN_IF(!atAnchorContainer.IsSetAndValid())) {
return NS_ERROR_FAILURE;
}
ErrorResult error;
selection->Collapse(atAnchorContainer, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
if (atAnchor.IsEndOfContainer()) {
- EditorRawDOMPoint afterAnchorContainer(atAnchor.Container());
+ EditorRawDOMPoint afterAnchorContainer(atAnchor.GetContainer());
if (NS_WARN_IF(!afterAnchorContainer.AdvanceOffset())) {
return NS_ERROR_FAILURE;
}
ErrorResult error;
selection->Collapse(afterAnchorContainer, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
@@ -4583,17 +4581,17 @@ EditorBase::DeleteSelectionAndPrepareToC
}
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode = SplitNode(atAnchor.AsRaw(), error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
- EditorRawDOMPoint atRightNode(atAnchor.Container());
+ EditorRawDOMPoint atRightNode(atAnchor.GetContainer());
if (NS_WARN_IF(!atRightNode.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(atRightNode.IsSetAndValid());
selection->Collapse(atRightNode, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
@@ -5247,17 +5245,17 @@ EditorBase::InitializeSelection(nsIDOMEv
if (mComposition && !mIMETextNode && mIMETextLength) {
// We need to look for the new mIMETextNode from current selection.
// XXX If selection is changed during reframe, this doesn't work well!
nsRange* firstRange = selection->GetRangeAt(0);
NS_ENSURE_TRUE(firstRange, NS_ERROR_FAILURE);
EditorRawDOMPoint atStartOfFirstRange(firstRange->StartRef());
EditorRawDOMPoint betterInsertionPoint =
FindBetterInsertionPoint(atStartOfFirstRange);
- Text* textNode = betterInsertionPoint.Container()->GetAsText();
+ Text* textNode = betterInsertionPoint.GetContainerAsText();
MOZ_ASSERT(textNode,
"There must be text node if mIMETextLength is larger than 0");
if (textNode) {
MOZ_ASSERT(textNode->Length() >= mIMETextOffset + mIMETextLength,
"The text node must be different from the old mIMETextNode");
CompositionTransaction::SetIMESelection(*this, textNode, mIMETextOffset,
mIMETextLength,
mComposition->GetRanges());
--- a/editor/libeditor/EditorDOMPoint.h
+++ b/editor/libeditor/EditorDOMPoint.h
@@ -5,18 +5,22 @@
#ifndef mozilla_EditorDOMPoint_h
#define mozilla_EditorDOMPoint_h
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/RangeBoundary.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/Text.h"
+#include "nsAtom.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
+#include "nsIDOMNode.h"
#include "nsINode.h"
namespace mozilla {
template<typename ParentType, typename ChildType>
class EditorDOMPointBase;
/**
@@ -161,25 +165,102 @@ public:
MOZ_IMPLICIT EditorDOMPointBase(const EditorDOMPointBase<PT, CT>& aOther)
: mParent(aOther.mParent)
, mChild(aOther.mChild)
, mOffset(aOther.mOffset)
, mIsChildInitialized(aOther.mIsChildInitialized)
{
}
- // Following methods are just copy of same methods of RangeBoudnaryBase.
-
+ /**
+ * GetContainer() returns the container node at the point.
+ * GetContainerAs*() returns the container node as specific type.
+ */
nsINode*
- Container() const
+ GetContainer() const
{
return mParent;
}
nsIContent*
+ GetContainerAsContent() const
+ {
+ return mParent && mParent->IsContent() ? mParent->AsContent() : nullptr;
+ }
+
+ dom::Element*
+ GetContainerAsElement() const
+ {
+ return mParent && mParent->IsElement() ? mParent->AsElement() : nullptr;
+ }
+
+ dom::Text*
+ GetContainerAsText() const
+ {
+ return mParent ? mParent->GetAsText() : nullptr;
+ }
+
+ nsIDOMNode*
+ GetContainerAsDOMNode() const
+ {
+ return mParent ? mParent->AsDOMNode() : nullptr;
+ }
+
+ /**
+ * CanContainerHaveChildren() returns true if the container node can have
+ * child nodes. Otherwise, e.g., when the container is a text node, returns
+ * false.
+ */
+ bool
+ CanContainerHaveChildren() const
+ {
+ return mParent && mParent->IsContainerNode();
+ }
+
+ /**
+ * IsInDataNode() returns true if the container node is a data node including
+ * text node.
+ */
+ bool
+ IsInDataNode() const
+ {
+ return mParent && mParent->IsNodeOfType(nsINode::eDATA_NODE);
+ }
+
+ /**
+ * IsInTextNode() returns true if the container node is a text node.
+ */
+ bool
+ IsInTextNode() const
+ {
+ return mParent && mParent->IsNodeOfType(nsINode::eTEXT);
+ }
+
+ /**
+ * IsContainerHTMLElement() returns true if the container node is an HTML
+ * element node and its node name is aTag.
+ */
+ bool
+ IsContainerHTMLElement(nsAtom* aTag) const
+ {
+ return mParent && mParent->IsHTMLElement(aTag);
+ }
+
+ /**
+ * IsContainerAnyOfHTMLElements() returns true if the container node is an
+ * HTML element node and its node name is one of the arguments.
+ */
+ template<typename First, typename... Args>
+ bool
+ IsContainerAnyOfHTMLElements(First aFirst, Args... aArgs) const
+ {
+ return mParent && mParent->IsAnyOfHTMLElements(aFirst, aArgs...);
+ }
+
+ nsIContent*
GetChildAtOffset() const
{
if (!mParent || !mParent->IsContainerNode()) {
return nullptr;
}
if (mIsChildInitialized) {
return mChild;
}
@@ -698,17 +779,17 @@ ImplCycleCollectionTraverse(nsCycleColle
*/
class MOZ_STACK_CLASS AutoEditorDOMPointOffsetInvalidator final
{
public:
explicit AutoEditorDOMPointOffsetInvalidator(EditorDOMPoint& aPoint)
: mPoint(aPoint)
{
MOZ_ASSERT(aPoint.IsSetAndValid());
- MOZ_ASSERT(mPoint.Container()->IsContainerNode());
+ MOZ_ASSERT(mPoint.CanContainerHaveChildren());
mChild = mPoint.GetChildAtOffset();
}
~AutoEditorDOMPointOffsetInvalidator()
{
InvalidateOffset();
}
@@ -717,17 +798,17 @@ public:
*/
void InvalidateOffset()
{
if (mChild) {
mPoint.Set(mChild);
} else {
// If the point referred after the last child, let's keep referring
// after current last node of the old container.
- mPoint.SetToEndOf(mPoint.Container());
+ mPoint.SetToEndOf(mPoint.GetContainer());
}
}
private:
EditorDOMPoint& mPoint;
// Needs to store child node by ourselves because EditorDOMPoint stores
// child node with mRef which is previous sibling of current child node.
// Therefore, we cannot keep referring it if it's first child.
@@ -765,17 +846,17 @@ public:
InvalidateChild();
}
/**
* Manually, invalidate child of the given point.
*/
void InvalidateChild()
{
- mPoint.Set(mPoint.Container(), mPoint.Offset());
+ mPoint.Set(mPoint.GetContainer(), mPoint.Offset());
}
private:
EditorDOMPoint& mPoint;
AutoEditorDOMPointChildInvalidator() = delete;
AutoEditorDOMPointChildInvalidator(
const AutoEditorDOMPointChildInvalidator& aOther) = delete;
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -858,22 +858,22 @@ HTMLEditRules::GetAlignment(bool* aMixed
EditorRawDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(atStartOfSelection.IsSetAndValid());
// Is the selection collapsed?
nsCOMPtr<nsINode> nodeToExamine;
- if (selection->Collapsed() || atStartOfSelection.Container()->GetAsText()) {
+ if (selection->Collapsed() || atStartOfSelection.GetContainerAsText()) {
// If selection is collapsed, we want to look at the container of selection
// start and its ancestors for divs with alignment on them. If we are in a
// text node, then that is the node of interest.
- nodeToExamine = atStartOfSelection.Container();
- } else if (atStartOfSelection.Container()->IsHTMLElement(nsGkAtoms::html) &&
+ nodeToExamine = atStartOfSelection.GetContainer();
+ } else if (atStartOfSelection.IsContainerHTMLElement(nsGkAtoms::html) &&
atStartOfSelection.Offset() == static_cast<uint32_t>(rootOffset)) {
// If we have selected the body, let's look at the first editable node
nodeToExamine = htmlEditor->GetNextEditableNode(atStartOfSelection);
} else {
nsTArray<RefPtr<nsRange>> arrayOfRanges;
GetPromotedRanges(selection, arrayOfRanges, EditAction::align);
// Use these ranges to construct a list of nodes to act on.
@@ -1261,17 +1261,17 @@ HTMLEditRules::WillInsert(Selection& aSe
}
MOZ_ASSERT(atStartOfSelection.IsSetAndValid());
// Get prior node
nsCOMPtr<nsIContent> priorNode =
htmlEditor->GetPreviousEditableHTMLNode(atStartOfSelection);
if (priorNode && TextEditUtils::IsMozBR(priorNode)) {
RefPtr<Element> block1 =
- htmlEditor->GetBlock(*atStartOfSelection.Container());
+ htmlEditor->GetBlock(*atStartOfSelection.GetContainer());
RefPtr<Element> block2 = htmlEditor->GetBlockNodeParent(priorNode);
if (block1 && block1 == block2) {
// If we are here then the selection is right after a mozBR that is in
// the same block as the selection. We need to move the selection start
// to be before the mozBR.
EditorRawDOMPoint point(priorNode);
nsresult rv = aSelection.Collapse(point.AsRaw());
@@ -1341,61 +1341,61 @@ HTMLEditRules::WillInsertText(EditAction
EditorDOMPoint pointToInsert(firstRange->StartRef());
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(pointToInsert.IsSetAndValid());
// dont put text in places that can't have it
if (NS_WARN_IF(!mHTMLEditor) ||
- (!EditorBase::IsTextNode(pointToInsert.Container()) &&
- !mHTMLEditor->CanContainTag(*pointToInsert.Container(),
+ (!EditorBase::IsTextNode(pointToInsert.GetContainer()) &&
+ !mHTMLEditor->CanContainTag(*pointToInsert.GetContainer(),
*nsGkAtoms::textTagName))) {
return NS_ERROR_FAILURE;
}
if (aAction == EditAction::insertIMEText) {
// Right now the WSRunObject code bails on empty strings, but IME needs
// the InsertTextImpl() call to still happen since empty strings are meaningful there.
NS_ENSURE_STATE(mHTMLEditor);
// If there is one or more IME selections, its minimum offset should be
// the insertion point.
int32_t IMESelectionOffset =
- mHTMLEditor->GetIMESelectionStartOffsetIn(pointToInsert.Container());
+ mHTMLEditor->GetIMESelectionStartOffsetIn(pointToInsert.GetContainer());
if (IMESelectionOffset >= 0) {
- pointToInsert.Set(pointToInsert.Container(), IMESelectionOffset);
+ pointToInsert.Set(pointToInsert.GetContainer(), IMESelectionOffset);
}
if (inString->IsEmpty()) {
rv = mHTMLEditor->InsertTextImpl(*doc, *inString, pointToInsert.AsRaw());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
WSRunObject wsObj(mHTMLEditor,
- pointToInsert.Container(), pointToInsert.Offset());
+ pointToInsert.GetContainer(), pointToInsert.Offset());
rv = wsObj.InsertText(*doc, *inString, pointToInsert.AsRaw());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
// aAction == kInsertText
// find where we are
EditorDOMPoint currentPoint(pointToInsert);
// is our text going to be PREformatted?
// We remember this so that we know how to handle tabs.
bool isPRE;
NS_ENSURE_STATE(mHTMLEditor);
- rv = mHTMLEditor->IsPreformatted(GetAsDOMNode(pointToInsert.Container()),
+ rv = mHTMLEditor->IsPreformatted(GetAsDOMNode(pointToInsert.GetContainer()),
&isPRE);
NS_ENSURE_SUCCESS(rv, rv);
// turn off the edit listener: we know how to
// build the "doc changed range" ourselves, and it's
// must faster to do it once here than to track all
// the changes one at a time.
AutoLockListener lockit(&mListenerEnabled);
@@ -1441,17 +1441,17 @@ HTMLEditRules::WillInsertText(EditAction
nsCOMPtr<Element> br =
mHTMLEditor->CreateBRImpl(*aSelection, currentPoint.AsRaw(),
nsIEditor::eNone);
NS_ENSURE_STATE(br);
pos++;
if (br->GetNextSibling()) {
pointToInsert.Set(br->GetNextSibling());
} else {
- pointToInsert.SetToEndOf(currentPoint.Container());
+ pointToInsert.SetToEndOf(currentPoint.GetContainer());
}
// XXX In most cases, pointToInsert and currentPoint are same here.
// But if the <br> element has been moved to different point by
// mutation observer, those points become different.
currentPoint.Set(br);
DebugOnly<bool> advanced = currentPoint.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the new <br> element");
@@ -1486,17 +1486,17 @@ HTMLEditRules::WillInsertText(EditAction
}
} else {
subStrLen = tString.Length() - oldPos;
pos = tString.Length();
}
nsDependentSubstring subStr(tString, oldPos, subStrLen);
NS_ENSURE_STATE(mHTMLEditor);
- WSRunObject wsObj(mHTMLEditor, currentPoint.Container(),
+ WSRunObject wsObj(mHTMLEditor, currentPoint.GetContainer(),
currentPoint.Offset());
// is it a tab?
if (subStr.Equals(tabStr)) {
EditorRawDOMPoint pointAfterInsertedSpaces;
rv = wsObj.InsertText(*doc, spacesStr, currentPoint.AsRaw(),
&pointAfterInsertedSpaces);
if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -1513,17 +1513,17 @@ HTMLEditRules::WillInsertText(EditAction
nsIEditor::eNone);
if (NS_WARN_IF(!newBRElement)) {
return NS_ERROR_FAILURE;
}
pos++;
if (newBRElement->GetNextSibling()) {
pointToInsert.Set(newBRElement->GetNextSibling());
} else {
- pointToInsert.SetToEndOf(currentPoint.Container());
+ pointToInsert.SetToEndOf(currentPoint.GetContainer());
}
currentPoint.Set(newBRElement);
DebugOnly<bool> advanced = currentPoint.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the new <br> node");
// XXX If the newBRElement has been moved or removed by mutation
// observer, we hit this assert. We need to check if
// newBRElement is in expected point, though, we must have
@@ -1555,17 +1555,17 @@ HTMLEditRules::WillInsertText(EditAction
NS_WARNING("Failed to collapse at current point");
error.SuppressException();
}
}
// manually update the doc changed range so that AfterEdit will clean up
// the correct portion of the document.
if (!mDocChangeRange) {
- mDocChangeRange = new nsRange(pointToInsert.Container());
+ mDocChangeRange = new nsRange(pointToInsert.GetContainer());
}
if (currentPoint.IsSet()) {
rv = mDocChangeRange->SetStartAndEnd(pointToInsert.AsRaw(),
currentPoint.AsRaw());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@@ -1672,34 +1672,34 @@ HTMLEditRules::WillInsertBreak(Selection
EditorDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(atStartOfSelection.IsSetAndValid());
// Do nothing if the node is read-only
- if (!htmlEditor->IsModifiableNode(atStartOfSelection.Container())) {
+ if (!htmlEditor->IsModifiableNode(atStartOfSelection.GetContainer())) {
*aCancel = true;
return NS_OK;
}
// If the active editing host is an inline element, or if the active editing
// host is the block parent itself and we're configured to use <br> as a
// paragraph separator, just append a <br>.
nsCOMPtr<Element> host = htmlEditor->GetActiveEditingHost();
if (NS_WARN_IF(!host)) {
return NS_ERROR_FAILURE;
}
// Look for the nearest parent block. However, don't return error even if
// there is no block parent here because in such case, i.e., editing host
// is an inline element, we should insert <br> simply.
RefPtr<Element> blockParent =
- HTMLEditor::GetBlock(*atStartOfSelection.Container(), host);
+ HTMLEditor::GetBlock(*atStartOfSelection.GetContainer(), host);
ParagraphSeparator separator = htmlEditor->GetDefaultParagraphSeparator();
bool insertBRElement;
// If there is no block parent in the editing host, i.e., the editing host
// itself is also a non-block element, we should insert a <br> element.
if (!blockParent) {
// XXX Chromium checks if the CSS box of the editing host is block.
insertBRElement = true;
@@ -1726,17 +1726,17 @@ HTMLEditRules::WillInsertBreak(Selection
blockAncestor = HTMLEditor::GetBlockNodeParent(blockAncestor, host)) {
insertBRElement = !CanContainParagraph(*blockAncestor);
}
}
// If we cannot insert a <p>/<div> element at the selection, we should insert
// a <br> element instead.
if (insertBRElement) {
- nsresult rv = StandardBreakImpl(*atStartOfSelection.Container(),
+ nsresult rv = StandardBreakImpl(*atStartOfSelection.GetContainer(),
atStartOfSelection.Offset(), aSelection);
NS_ENSURE_SUCCESS(rv, rv);
*aHandled = true;
return NS_OK;
}
if (host == blockParent && separator != ParagraphSeparator::br) {
// Insert a new block first
@@ -1755,23 +1755,24 @@ HTMLEditRules::WillInsertBreak(Selection
}
atStartOfSelection = firstRange->StartRef();
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(atStartOfSelection.IsSetAndValid());
- blockParent = mHTMLEditor->GetBlock(*atStartOfSelection.Container(), host);
+ blockParent =
+ mHTMLEditor->GetBlock(*atStartOfSelection.GetContainer(), host);
if (NS_WARN_IF(!blockParent)) {
return NS_ERROR_UNEXPECTED;
}
if (NS_WARN_IF(blockParent == host)) {
// Didn't create a new block for some reason, fall back to <br>
- rv = StandardBreakImpl(*atStartOfSelection.Container(),
+ rv = StandardBreakImpl(*atStartOfSelection.GetContainer(),
atStartOfSelection.Offset(), aSelection);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
*aHandled = true;
return NS_OK;
}
}
@@ -1785,25 +1786,25 @@ HTMLEditRules::WillInsertBreak(Selection
if (isEmpty) {
nsCOMPtr<Element> br = htmlEditor->CreateBR(blockParent,
blockParent->Length());
NS_ENSURE_STATE(br);
}
nsCOMPtr<Element> listItem = IsInListItem(blockParent);
if (listItem && listItem != host) {
- ReturnInListItem(aSelection, *listItem, *atStartOfSelection.Container(),
+ ReturnInListItem(aSelection, *listItem, *atStartOfSelection.GetContainer(),
atStartOfSelection.Offset());
*aHandled = true;
return NS_OK;
}
if (HTMLEditUtils::IsHeader(*blockParent)) {
// Headers: close (or split) header
- ReturnInHeader(aSelection, *blockParent, *atStartOfSelection.Container(),
+ ReturnInHeader(aSelection, *blockParent, *atStartOfSelection.GetContainer(),
atStartOfSelection.Offset());
*aHandled = true;
return NS_OK;
}
// XXX Ideally, we should take same behavior with both <p> container and
// <div> container. However, we are still using <br> as default
// paragraph separator (non-standard) and we've split only <p> container
@@ -1823,17 +1824,17 @@ HTMLEditRules::WillInsertBreak(Selection
*aHandled = result.Handled();
*aCancel = result.Canceled();
// Fall through, we may not have handled it in ReturnInParagraph()
}
// If not already handled then do the standard thing
if (!(*aHandled)) {
*aHandled = true;
- return StandardBreakImpl(*atStartOfSelection.Container(),
+ return StandardBreakImpl(*atStartOfSelection.GetContainer(),
atStartOfSelection.Offset(), aSelection);
}
return NS_OK;
}
nsresult
HTMLEditRules::StandardBreakImpl(nsINode& aNode,
int32_t aOffset,
@@ -1872,17 +1873,17 @@ HTMLEditRules::StandardBreakImpl(nsINode
NS_ENSURE_STATE(linkNode || !linkDOMNode);
SplitNodeResult splitLinkNodeResult =
htmlEditor->SplitNodeDeep(*linkNode, EditorRawDOMPoint(node, aOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(splitLinkNodeResult.Failed())) {
return splitLinkNodeResult.Rv();
}
EditorRawDOMPoint splitPoint(splitLinkNodeResult.SplitPoint());
- node = splitPoint.Container();
+ node = splitPoint.GetContainer();
aOffset = splitPoint.Offset();
}
brNode =
wsObj.InsertBreak(aSelection, EditorRawDOMPoint(node, aOffset),
nsIEditor::eNone);
if (NS_WARN_IF(!brNode)) {
return NS_ERROR_FAILURE;
}
@@ -2019,32 +2020,32 @@ HTMLEditRules::SplitMailCites(Selection*
}
// In most cases, <br> should be inserted after current cite. However, if
// left cite hasn't been created because the split point was start of the
// cite node, <br> should be inserted before the current cite.
EditorRawDOMPoint pointToInsertBrNode(splitCiteNodeResult.SplitPoint());
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<Element> brNode =
- mHTMLEditor->CreateBR(pointToInsertBrNode.Container(),
+ mHTMLEditor->CreateBR(pointToInsertBrNode.GetContainer(),
pointToInsertBrNode.Offset());
NS_ENSURE_STATE(brNode);
// Now, offset of pointToInsertBrNode is invalid. Let's clear it.
pointToInsertBrNode.Clear();
// Want selection before the break, and on same line.
EditorRawDOMPoint atBrNode(brNode);
aSelection->SetInterlinePosition(true);
ErrorResult error;
aSelection->Collapse(atBrNode, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
- selNode = atBrNode.Container();
+ selNode = atBrNode.GetContainer();
selOffset = atBrNode.Offset();
// if citeNode wasn't a block, we might also want another break before it.
// We need to examine the content both before the br we just added and also
// just after it. If we don't have another br or block boundary adjacent,
// then we will need a 2nd br added to achieve blank line that user expects.
if (IsInlineNode(*citeNode)) {
NS_ENSURE_STATE(mHTMLEditor);
@@ -3010,32 +3011,32 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
return EditActionIgnored(rv);
}
{
// We can't just track rightBlock because it's an Element.
AutoTrackDOMPoint tracker(htmlEditor->mRangeUpdater, &atRightBlockChild);
rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
WSRunObject::kAfterBlock,
- atRightBlockChild.Container(),
+ atRightBlockChild.GetContainer(),
atRightBlockChild.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
}
// XXX AutoTrackDOMPoint instance, tracker, hasn't been destroyed here.
// Do we really need to do update rightBlock here??
- MOZ_ASSERT(rightBlock == atRightBlockChild.Container());
- if (atRightBlockChild.Container()->IsElement()) {
- rightBlock = atRightBlockChild.Container()->AsElement();
+ MOZ_ASSERT(rightBlock == atRightBlockChild.GetContainer());
+ if (atRightBlockChild.GetContainerAsElement()) {
+ rightBlock = atRightBlockChild.GetContainerAsElement();
} else {
- if (NS_WARN_IF(!atRightBlockChild.Container()->GetParentElement())) {
+ if (NS_WARN_IF(!atRightBlockChild.GetContainer()->GetParentElement())) {
return EditActionIgnored(NS_ERROR_UNEXPECTED);
}
- rightBlock = atRightBlockChild.Container()->GetParentElement();
+ rightBlock = atRightBlockChild.GetContainer()->GetParentElement();
}
}
// Do br adjustment.
nsCOMPtr<Element> brNode =
CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
EditActionResult ret(NS_OK);
if (NS_WARN_IF(mergeLists)) {
@@ -3095,24 +3096,24 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
WSRunObject::kBeforeBlock,
leftBlock, leftBlockChild.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
}
// XXX AutoTrackDOMPoint instance, tracker, hasn't been destroyed here.
// Do we really need to do update rightBlock here??
- MOZ_DIAGNOSTIC_ASSERT(leftBlock == leftBlockChild.Container());
- if (leftBlockChild.Container()->IsElement()) {
- leftBlock = leftBlockChild.Container()->AsElement();
+ MOZ_DIAGNOSTIC_ASSERT(leftBlock == leftBlockChild.GetContainer());
+ if (leftBlockChild.GetContainerAsElement()) {
+ leftBlock = leftBlockChild.GetContainerAsElement();
} else {
- if (NS_WARN_IF(!leftBlockChild.Container()->GetParentElement())) {
+ if (NS_WARN_IF(!leftBlockChild.GetContainer()->GetParentElement())) {
return EditActionIgnored(NS_ERROR_UNEXPECTED);
}
- leftBlock = leftBlockChild.Container()->GetParentElement();
+ leftBlock = leftBlockChild.GetContainer()->GetParentElement();
}
}
// Do br adjustment.
nsCOMPtr<Element> brNode =
CheckForInvisibleBR(*leftBlock, BRLocation::beforeBlock,
leftBlockChild.Offset());
EditActionResult ret(NS_OK);
if (mergeLists) {
@@ -3153,17 +3154,18 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
}
// Because we don't want the moving content to receive the style of the
// previous content, we split the previous content's style.
nsCOMPtr<Element> editorRoot = htmlEditor->GetEditorRoot();
if (!editorRoot || &aLeftNode != editorRoot) {
nsCOMPtr<nsIContent> splittedPreviousContent;
- nsCOMPtr<nsINode> previousContentParent = previousContent.Container();
+ nsCOMPtr<nsINode> previousContentParent =
+ previousContent.GetContainer();
int32_t previousContentOffset = previousContent.Offset();
rv = htmlEditor->SplitStyleAbovePoint(
address_of(previousContentParent),
&previousContentOffset,
nullptr, nullptr, nullptr,
getter_AddRefs(splittedPreviousContent));
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionIgnored(rv);
@@ -3175,17 +3177,17 @@ HTMLEditRules::TryToJoinBlocks(nsIConten
previousContent.Set(previousContentParent, previousContentOffset);
}
}
if (NS_WARN_IF(!previousContent.IsSet())) {
return EditActionIgnored(NS_ERROR_NULL_POINTER);
}
- ret |= MoveBlock(*previousContent.Container()->AsElement(), *rightBlock,
+ ret |= MoveBlock(*previousContent.GetContainerAsElement(), *rightBlock,
previousContent.Offset(), 0);
if (NS_WARN_IF(ret.Failed())) {
return ret;
}
}
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
ret.MarkAsHandled();
}
@@ -3498,17 +3500,17 @@ HTMLEditRules::WillMakeList(Selection* a
}
EditorDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
// Make sure we can put a list here.
- if (!htmlEditor->CanContainTag(*atStartOfSelection.Container(),
+ if (!htmlEditor->CanContainTag(*atStartOfSelection.GetContainer(),
listType)) {
*aCancel = true;
return NS_OK;
}
SplitNodeResult splitAtSelectionStartResult =
MaybeSplitAncestorsForInsert(listType, atStartOfSelection.AsRaw());
if (NS_WARN_IF(splitAtSelectionStartResult.Failed())) {
@@ -3601,49 +3603,49 @@ HTMLEditRules::WillMakeList(Selection* a
}
EditorRawDOMPoint atCurNode(curNode);
if (NS_WARN_IF(!atCurNode.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(atCurNode.IsSetAndValid());
if (HTMLEditUtils::IsListItem(curNode)) {
- if (!atCurNode.Container()->IsHTMLElement(listType)) {
+ if (!atCurNode.IsContainerHTMLElement(listType)) {
// list item is in wrong type of list. if we don't have a curList,
// split the old list and make a new list of correct type.
if (!curList || EditorUtils::IsDescendantOf(*curNode, *curList)) {
- if (NS_WARN_IF(!atCurNode.Container()->IsContent())) {
+ if (NS_WARN_IF(!atCurNode.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
}
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
htmlEditor->SplitNode(atCurNode, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
newBlock = newLeftNode ? newLeftNode->AsElement() : nullptr;
- EditorRawDOMPoint atParentOfCurNode(atCurNode.Container());
+ EditorRawDOMPoint atParentOfCurNode(atCurNode.GetContainer());
curList = htmlEditor->CreateNode(listType, atParentOfCurNode);
NS_ENSURE_STATE(curList);
}
// move list item to new list
rv = htmlEditor->MoveNode(curNode, curList, -1);
NS_ENSURE_SUCCESS(rv, rv);
// convert list item type if needed
if (!curNode->IsHTMLElement(itemType)) {
newBlock = htmlEditor->ReplaceContainer(curNode->AsElement(),
itemType);
NS_ENSURE_STATE(newBlock);
}
} else {
// item is in right type of list. But we might still have to move it.
// and we might need to convert list item types.
if (!curList) {
- curList = atCurNode.Container()->AsElement();
- } else if (atCurNode.Container() != curList) {
+ curList = atCurNode.GetContainerAsElement();
+ } else if (atCurNode.GetContainer() != curList) {
// move list item to new list
rv = htmlEditor->MoveNode(curNode, curList, -1);
NS_ENSURE_SUCCESS(rv, rv);
}
if (!curNode->IsHTMLElement(itemType)) {
newBlock = htmlEditor->ReplaceContainer(curNode->AsElement(),
itemType);
NS_ENSURE_STATE(newBlock);
@@ -3847,17 +3849,17 @@ HTMLEditRules::MakeBasicBlock(Selection&
return NS_ERROR_FAILURE;
}
EditorDOMPoint pointToInsertBlock(firstRange->StartRef());
if (&blockType == nsGkAtoms::normal ||
&blockType == nsGkAtoms::_empty) {
// We are removing blocks (going to "body text")
RefPtr<Element> curBlock =
- htmlEditor->GetBlock(*pointToInsertBlock.Container());
+ htmlEditor->GetBlock(*pointToInsertBlock.GetContainer());
if (NS_WARN_IF(!curBlock)) {
return NS_ERROR_FAILURE;
}
if (!HTMLEditUtils::IsFormatNode(curBlock)) {
return NS_OK;
}
// If the first editable node after selection is a br, consume it.
@@ -3874,17 +3876,17 @@ HTMLEditRules::MakeBasicBlock(Selection&
SplitNodeResult splitNodeResult =
htmlEditor->SplitNodeDeep(*curBlock, pointToInsertBlock.AsRaw(),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
EditorRawDOMPoint pointToInsertBrNode(splitNodeResult.SplitPoint());
// Put a br at the split point
- brNode = htmlEditor->CreateBR(pointToInsertBrNode.Container(),
+ brNode = htmlEditor->CreateBR(pointToInsertBrNode.GetContainer(),
pointToInsertBrNode.Offset());
NS_ENSURE_STATE(brNode);
// Put selection at the split point
EditorRawDOMPoint atBrNode(brNode);
ErrorResult error;
aSelection.Collapse(atBrNode, error);
// Don't restore the selection
selectionRestorer.Abort();
@@ -4097,54 +4099,55 @@ HTMLEditRules::WillCSSIndent(Selection*
}
// Ignore all non-editable nodes. Leave them be.
if (!htmlEditor->IsEditable(curNode)) {
continue;
}
// some logic for putting list items into nested lists...
- if (HTMLEditUtils::IsList(atCurNode.Container())) {
+ if (HTMLEditUtils::IsList(atCurNode.GetContainer())) {
// Check for whether we should join a list that follows curNode.
// We do this if the next element is a list, and the list is of the
// same type (li/ol) as curNode was a part it.
sibling = htmlEditor->GetNextHTMLSibling(curNode);
if (sibling && HTMLEditUtils::IsList(sibling) &&
- atCurNode.Container()->NodeInfo()->NameAtom() ==
+ atCurNode.GetContainer()->NodeInfo()->NameAtom() ==
sibling->NodeInfo()->NameAtom() &&
- atCurNode.Container()->NodeInfo()->NamespaceID() ==
+ atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) {
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, 0);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
// Check for whether we should join a list that preceeds curNode.
// We do this if the previous element is a list, and the list is of
// the same type (li/ol) as curNode was a part of.
sibling = htmlEditor->GetPriorHTMLSibling(curNode);
if (sibling && HTMLEditUtils::IsList(sibling) &&
- atCurNode.Container()->NodeInfo()->NameAtom() ==
+ atCurNode.GetContainer()->NodeInfo()->NameAtom() ==
sibling->NodeInfo()->NameAtom() &&
- atCurNode.Container()->NodeInfo()->NamespaceID() ==
+ atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) {
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, -1);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
// check to see if curList is still appropriate. Which it is if
// curNode is still right after it in the same list.
sibling = nullptr;
if (curList) {
sibling = htmlEditor->GetPriorHTMLSibling(curNode);
}
if (!curList || (sibling && sibling != curList)) {
- nsAtom* containerName = atCurNode.Container()->NodeInfo()->NameAtom();
+ nsAtom* containerName =
+ atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atCurNode.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
curList = htmlEditor->CreateNode(containerName,
splitNodeResult.SplitPoint());
@@ -4166,17 +4169,17 @@ HTMLEditRules::WillCSSIndent(Selection*
if (IsBlockNode(*curNode)) {
ChangeIndentation(*curNode->AsElement(), Change::plus);
curQuote = nullptr;
continue;
}
if (!curQuote) {
// First, check that our element can contain a div.
- if (!htmlEditor->CanContainTag(*atCurNode.Container(),
+ if (!htmlEditor->CanContainTag(*atCurNode.GetContainer(),
*nsGkAtoms::div)) {
return NS_OK; // cancelled
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
@@ -4294,54 +4297,55 @@ HTMLEditRules::WillHTMLIndent(Selection*
}
// Ignore all non-editable nodes. Leave them be.
if (!htmlEditor->IsEditable(curNode)) {
continue;
}
// some logic for putting list items into nested lists...
- if (HTMLEditUtils::IsList(atCurNode.Container())) {
+ if (HTMLEditUtils::IsList(atCurNode.GetContainer())) {
// Check for whether we should join a list that follows curNode.
// We do this if the next element is a list, and the list is of the
// same type (li/ol) as curNode was a part it.
sibling = htmlEditor->GetNextHTMLSibling(curNode);
if (sibling && HTMLEditUtils::IsList(sibling) &&
- atCurNode.Container()->NodeInfo()->NameAtom() ==
+ atCurNode.GetContainer()->NodeInfo()->NameAtom() ==
sibling->NodeInfo()->NameAtom() &&
- atCurNode.Container()->NodeInfo()->NamespaceID() ==
+ atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) {
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, 0);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
// Check for whether we should join a list that preceeds curNode.
// We do this if the previous element is a list, and the list is of
// the same type (li/ol) as curNode was a part of.
sibling = htmlEditor->GetPriorHTMLSibling(curNode);
if (sibling && HTMLEditUtils::IsList(sibling) &&
- atCurNode.Container()->NodeInfo()->NameAtom() ==
+ atCurNode.GetContainer()->NodeInfo()->NameAtom() ==
sibling->NodeInfo()->NameAtom() &&
- atCurNode.Container()->NodeInfo()->NamespaceID() ==
+ atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
sibling->NodeInfo()->NamespaceID()) {
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, -1);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
// check to see if curList is still appropriate. Which it is if
// curNode is still right after it in the same list.
sibling = nullptr;
if (curList) {
sibling = htmlEditor->GetPriorHTMLSibling(curNode);
}
if (!curList || (sibling && sibling != curList)) {
- nsAtom* containerName = atCurNode.Container()->NodeInfo()->NameAtom();
+ nsAtom* containerName =
+ atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atCurNode.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
curList =
htmlEditor->CreateNode(containerName, splitNodeResult.SplitPoint());
@@ -4379,17 +4383,18 @@ HTMLEditRules::WillHTMLIndent(Selection*
sibling = htmlEditor->GetPriorHTMLSibling(listItem);
}
if (!curList || (sibling && sibling != curList)) {
EditorDOMPoint atListItem(listItem);
if (NS_WARN_IF(!listItem)) {
return NS_ERROR_FAILURE;
}
- nsAtom* containerName = atListItem.Container()->NodeInfo()->NameAtom();
+ nsAtom* containerName =
+ atListItem.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atListItem.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
curList = htmlEditor->CreateNode(containerName,
splitNodeResult.SplitPoint());
@@ -4410,17 +4415,17 @@ HTMLEditRules::WillHTMLIndent(Selection*
// One reason it might not go in prio blockquote is if we are now
// in a different table cell.
if (curQuote && InDifferentTableElements(curQuote, curNode)) {
curQuote = nullptr;
}
if (!curQuote) {
// First, check that our element can contain a blockquote.
- if (!htmlEditor->CanContainTag(*atCurNode.Container(),
+ if (!htmlEditor->CanContainTag(*atCurNode.GetContainer(),
*nsGkAtoms::blockquote)) {
return NS_OK; // cancelled
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::blockquote, atCurNode.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
@@ -4886,17 +4891,17 @@ HTMLEditRules::CreateStyleForInsertText(
// if we are in a text node, split it
SplitNodeResult splitTextNodeResult =
mHTMLEditor->SplitNodeDeep(*text, EditorRawDOMPoint(text, offset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitTextNodeResult.Failed())) {
return splitTextNodeResult.Rv();
}
EditorRawDOMPoint splitPoint(splitTextNodeResult.SplitPoint());
- node = splitPoint.Container();
+ node = splitPoint.GetContainer();
offset = splitPoint.Offset();
}
if (!mHTMLEditor->IsContainer(node)) {
return NS_OK;
}
OwningNonNull<Text> newNode =
EditorBase::CreateTextNode(aDoc, EmptyString());
NS_ENSURE_STATE(mHTMLEditor);
@@ -5121,19 +5126,19 @@ HTMLEditRules::WillAlign(Selection& aSel
if (NS_WARN_IF(!atCurNode.IsSet())) {
continue;
}
// Skip insignificant formatting text nodes to prevent unnecessary
// structure splitting!
bool isEmptyTextNode = false;
if (curNode->GetAsText() &&
- ((HTMLEditUtils::IsTableElement(atCurNode.Container()) &&
- !HTMLEditUtils::IsTableCellOrCaption(*atCurNode.Container())) ||
- HTMLEditUtils::IsList(atCurNode.Container()) ||
+ ((HTMLEditUtils::IsTableElement(atCurNode.GetContainer()) &&
+ !HTMLEditUtils::IsTableCellOrCaption(*atCurNode.GetContainer())) ||
+ HTMLEditUtils::IsList(atCurNode.GetContainer()) ||
(NS_SUCCEEDED(htmlEditor->IsEmptyNode(curNode, &isEmptyTextNode)) &&
isEmptyTextNode))) {
continue;
}
// If it's a list item, or a list inside a list, forget any "current" div,
// and instead put divs inside the appropriate block (td, li, etc.)
if (HTMLEditUtils::IsListItem(curNode) ||
@@ -5143,32 +5148,33 @@ HTMLEditRules::WillAlign(Selection& aSel
NS_ENSURE_SUCCESS(rv, rv);
if (useCSS) {
htmlEditor->mCSSEditUtils->SetCSSEquivalentToHTMLStyle(
curNode->AsElement(), nullptr,
nsGkAtoms::align, &aAlignType, false);
curDiv = nullptr;
continue;
}
- if (HTMLEditUtils::IsList(atCurNode.Container())) {
+ if (HTMLEditUtils::IsList(atCurNode.GetContainer())) {
// If we don't use CSS, add a contraint to list element: they have to
// be inside another list, i.e., >= second level of nesting
rv = AlignInnerBlocks(*curNode, &aAlignType);
NS_ENSURE_SUCCESS(rv, rv);
curDiv = nullptr;
continue;
}
// Clear out curDiv so that we don't put nodes after this one into it
}
// Need to make a div to put things in if we haven't already, or if this
// node doesn't go in div we used earlier.
if (!curDiv || transitionList[indexOfTransitionList]) {
// First, check that our element can contain a div.
- if (!htmlEditor->CanContainTag(*atCurNode.Container(), *nsGkAtoms::div)) {
+ if (!htmlEditor->CanContainTag(*atCurNode.GetContainer(),
+ *nsGkAtoms::div)) {
// Cancelled
return NS_OK;
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
@@ -5810,22 +5816,22 @@ HTMLEditRules::GetPromotedPoint(RulesEnd
}
EditorDOMPoint point(&aNode, aOffset);
// else not a text section. In this case we want to see if we should grab
// any adjacent inline nodes and/or parents and other ancestors
if (aWhere == kStart) {
// some special casing for text nodes
- if (point.Container()->IsNodeOfType(nsINode::eTEXT)) {
- if (!point.Container()->GetParentNode()) {
+ if (point.IsInTextNode()) {
+ if (!point.GetContainer()->GetParentNode()) {
// Okay, can't promote any further
return point;
}
- point.Set(point.Container());
+ point.Set(point.GetContainer());
}
// look back through any further inline nodes that aren't across a <br>
// from us, and that are enclosed in the same block.
nsCOMPtr<nsINode> priorNode =
htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
while (priorNode && priorNode->GetParentNode() &&
@@ -5836,57 +5842,57 @@ HTMLEditRules::GetPromotedPoint(RulesEnd
}
// finding the real start for this point. look up the tree for as long as
// we are the first node in the container, and as long as we haven't hit
// the body node.
nsCOMPtr<nsIContent> nearNode =
htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
while (!nearNode &&
- !point.Container()->IsHTMLElement(nsGkAtoms::body) &&
- point.Container()->GetParentNode()) {
+ !point.IsContainerHTMLElement(nsGkAtoms::body) &&
+ point.GetContainer()->GetParentNode()) {
// some cutoffs are here: we don't need to also include them in the
// aWhere == kEnd case. as long as they are in one or the other it will
// work. special case for outdent: don't keep looking up if we have
// found a blockquote element to act on
if (actionID == EditAction::outdent &&
- point.Container()->IsHTMLElement(nsGkAtoms::blockquote)) {
+ point.IsContainerHTMLElement(nsGkAtoms::blockquote)) {
break;
}
// Don't walk past the editable section. Note that we need to check
// before walking up to a parent because we need to return the parent
// object, so the parent itself might not be in the editable area, but
// it's OK if we're not performing a block-level action.
bool blockLevelAction = actionID == EditAction::indent ||
actionID == EditAction::outdent ||
actionID == EditAction::align ||
actionID == EditAction::makeBasicBlock;
if (!htmlEditor->IsDescendantOfEditorRoot(
- point.Container()->GetParentNode()) &&
+ point.GetContainer()->GetParentNode()) &&
(blockLevelAction ||
- !htmlEditor->IsDescendantOfEditorRoot(point.Container()))) {
+ !htmlEditor->IsDescendantOfEditorRoot(point.GetContainer()))) {
break;
}
- point.Set(point.Container());
+ point.Set(point.GetContainer());
nearNode = htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
}
return point;
}
// aWhere == kEnd
// some special casing for text nodes
- if (point.Container()->IsNodeOfType(nsINode::eTEXT)) {
- if (!point.Container()->GetParentNode()) {
+ if (point.IsInTextNode()) {
+ if (!point.GetContainer()->GetParentNode()) {
// Okay, can't promote any further
return point;
}
// want to be after the text node
- point.Set(point.Container());
+ point.Set(point.GetContainer());
DebugOnly<bool> advanced = point.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the text node");
}
// look ahead through any further inline nodes that aren't across a <br> from
// us, and that are enclosed in the same block.
nsCOMPtr<nsIContent> nextNode =
@@ -5922,28 +5928,28 @@ HTMLEditRules::GetPromotedPoint(RulesEnd
}
// finding the real end for this point. look up the tree for as long as we
// are the last node in the container, and as long as we haven't hit the body
// node.
nsCOMPtr<nsIContent> nearNode =
htmlEditor->GetNextEditableHTMLNodeInBlock(point.AsRaw());
while (!nearNode &&
- !point.Container()->IsHTMLElement(nsGkAtoms::body) &&
- point.Container()->GetParentNode()) {
+ !point.IsContainerHTMLElement(nsGkAtoms::body) &&
+ point.GetContainer()->GetParentNode()) {
// Don't walk past the editable section. Note that we need to check before
// walking up to a parent because we need to return the parent object, so
// the parent itself might not be in the editable area, but it's OK.
- if (!htmlEditor->IsDescendantOfEditorRoot(point.Container()) &&
+ if (!htmlEditor->IsDescendantOfEditorRoot(point.GetContainer()) &&
!htmlEditor->IsDescendantOfEditorRoot(
- point.Container()->GetParentNode())) {
+ point.GetContainer()->GetParentNode())) {
break;
}
- point.Set(point.Container());
+ point.Set(point.GetContainer());
if (NS_WARN_IF(!point.AdvanceOffset())) {
break;
}
nearNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point.AsRaw());
}
return point;
}
@@ -6091,34 +6097,33 @@ HTMLEditRules::GetNodesForOperation(
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
if (aTouchContent == TouchContent::yes) {
// Split text nodes. This is necessary, since GetPromotedPoint() may return a
// range ending in a text node in case where part of a pre-formatted
// elements needs to be moved.
for (RefPtr<nsRange>& range : aArrayOfRanges) {
EditorDOMPoint atEnd(range->EndRef());
- if (NS_WARN_IF(!atEnd.IsSet()) ||
- !atEnd.Container()->IsNodeOfType(nsINode::eTEXT)) {
+ if (NS_WARN_IF(!atEnd.IsSet()) || !atEnd.IsInTextNode()) {
continue;
}
if (!atEnd.IsStartOfContainer() && !atEnd.IsEndOfContainer()) {
// Split the text node.
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
htmlEditor->SplitNode(atEnd.AsRaw(), error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
// Correct the range.
// The new end parent becomes the parent node of the text.
// XXX We want nsRange::SetEnd(const RawRangeBoundary&)
- EditorRawDOMPoint atContainerOfSplitNode(atEnd.Container());
+ EditorRawDOMPoint atContainerOfSplitNode(atEnd.GetContainer());
range->SetEnd(atContainerOfSplitNode, error);
if (NS_WARN_IF(error.Failed())) {
error.SuppressException();
}
}
}
}
@@ -6465,17 +6470,17 @@ HTMLEditRules::BustUpInlinesAtRangeEndpo
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(splitEndInlineResult.Failed())) {
return splitEndInlineResult.Rv();
}
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint splitPointAtEnd(splitEndInlineResult.SplitPoint());
- item.mEndContainer = splitPointAtEnd.Container();
+ item.mEndContainer = splitPointAtEnd.GetContainer();
item.mEndOffset = splitPointAtEnd.Offset();
}
nsCOMPtr<nsIContent> startInline =
GetHighestInlineParent(*item.mStartContainer);
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_FAILURE;
}
@@ -6489,17 +6494,17 @@ HTMLEditRules::BustUpInlinesAtRangeEndpo
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(splitStartInlineResult.Failed())) {
return splitStartInlineResult.Rv();
}
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint splitPointAtStart(splitStartInlineResult.SplitPoint());
- item.mStartContainer = splitPointAtStart.Container();
+ item.mStartContainer = splitPointAtStart.GetContainer();
item.mStartOffset = splitPointAtStart.Offset();
}
return NS_OK;
}
nsresult
HTMLEditRules::BustUpInlinesAtBRs(
@@ -6541,17 +6546,17 @@ HTMLEditRules::BustUpInlinesAtBRs(
// beginning of inline container, in which case SplitNodeDeep would not
// actually split anything
aOutArrayOfNodes.AppendElement(*splitNodeResult.GetPreviousNode());
}
// Move break outside of container and also put in node list
EditorRawDOMPoint atNextNode(splitNodeResult.GetNextNode());
nsresult rv =
- htmlEditor->MoveNode(brNode->AsContent(), atNextNode.Container(),
+ htmlEditor->MoveNode(brNode->AsContent(), atNextNode.GetContainer(),
atNextNode.Offset());
NS_ENSURE_SUCCESS(rv, rv);
aOutArrayOfNodes.AppendElement(*brNode);
nextNode = splitNodeResult.GetNextNode();
}
// Now tack on remaining next node.
@@ -6608,17 +6613,17 @@ HTMLEditRules::GetNodesFromPoint(
const EditorDOMPoint& aPoint,
EditAction aOperation,
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
TouchContent aTouchContent)
{
if (NS_WARN_IF(!aPoint.IsSet())) {
return NS_ERROR_INVALID_ARG;
}
- RefPtr<nsRange> range = new nsRange(aPoint.Container());
+ RefPtr<nsRange> range = new nsRange(aPoint.GetContainer());
IgnoredErrorResult error;
range->SetStart(aPoint, error);
if (NS_WARN_IF(error.Failed())) {
MOZ_ASSERT(!error.Failed());
}
// Expand the range to include adjacent inlines
PromoteRange(*range, aOperation);
@@ -6845,38 +6850,40 @@ HTMLEditRules::ReturnInParagraph(Selecti
bool splitAfterNewBR = false;
nsCOMPtr<nsIContent> brNode;
EditorDOMPoint pointToSplitParentDivOrP(atStartOfSelection);
EditorRawDOMPoint pointToInsertBR;
if (doesCRCreateNewP &&
- atStartOfSelection.Container() == &aParentDivOrP) {
+ atStartOfSelection.GetContainer() == &aParentDivOrP) {
// We are at the edges of the block, so, we don't need to create new <br>.
brNode = nullptr;
- } else if (EditorBase::IsTextNode(atStartOfSelection.Container())) {
+ } else if (atStartOfSelection.IsInTextNode()) {
// at beginning of text node?
if (atStartOfSelection.IsStartOfContainer()) {
// is there a BR prior to it?
- brNode = htmlEditor->GetPriorHTMLSibling(atStartOfSelection.Container());
+ brNode =
+ htmlEditor->GetPriorHTMLSibling(atStartOfSelection.GetContainer());
if (!brNode ||
!htmlEditor->IsVisibleBRElement(brNode) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(brNode))) {
- pointToInsertBR.Set(atStartOfSelection.Container());
+ pointToInsertBR.Set(atStartOfSelection.GetContainer());
brNode = nullptr;
}
} else if (atStartOfSelection.IsEndOfContainer()) {
// we're at the end of text node...
// is there a BR after to it?
- brNode = htmlEditor->GetNextHTMLSibling(atStartOfSelection.Container());
+ brNode =
+ htmlEditor->GetNextHTMLSibling(atStartOfSelection.GetContainer());
if (!brNode ||
!htmlEditor->IsVisibleBRElement(brNode) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(brNode))) {
- pointToInsertBR.Set(atStartOfSelection.Container());
+ pointToInsertBR.Set(atStartOfSelection.GetContainer());
DebugOnly<bool> advanced = pointToInsertBR.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the container of selection start");
brNode = nullptr;
}
} else {
if (doesCRCreateNewP) {
ErrorResult error;
@@ -6885,17 +6892,17 @@ HTMLEditRules::ReturnInParagraph(Selecti
if (NS_WARN_IF(error.Failed())) {
return EditActionResult(error.StealNSResult());
}
pointToSplitParentDivOrP.SetToEndOf(newLeftDivOrP);
}
// We need to put new <br> after the left node if given node was split
// above.
- pointToInsertBR.Set(pointToSplitParentDivOrP.Container());
+ pointToInsertBR.Set(pointToSplitParentDivOrP.GetContainer());
DebugOnly<bool> advanced = pointToInsertBR.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the container of selection start");
}
} else {
// not in a text node.
// is there a BR prior to it?
nsCOMPtr<nsIContent> nearNode;
@@ -6922,17 +6929,17 @@ HTMLEditRules::ReturnInParagraph(Selecti
return EditActionResult(NS_ERROR_NOT_AVAILABLE);
}
// if CR does not create a new P, default to BR creation
if (NS_WARN_IF(!doesCRCreateNewP)) {
return EditActionResult(NS_OK);
}
- brNode = htmlEditor->CreateBR(pointToInsertBR.Container(),
+ brNode = htmlEditor->CreateBR(pointToInsertBR.GetContainer(),
pointToInsertBR.Offset());
if (splitAfterNewBR) {
// We split the parent after the br we've just inserted.
pointToSplitParentDivOrP.Set(brNode);
DebugOnly<bool> advanced = pointToSplitParentDivOrP.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the new <br>");
}
@@ -6956,17 +6963,17 @@ HTMLEditRules::SplitParagraph(Selection&
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_NOT_AVAILABLE;
}
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor;
// split para
// get ws code to adjust any ws
- nsCOMPtr<nsINode> selNode = aStartOfRightNode.Container();
+ nsCOMPtr<nsINode> selNode = aStartOfRightNode.GetContainer();
int32_t selOffset = aStartOfRightNode.Offset();
nsresult rv =
WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
address_of(selNode), &selOffset);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_WARN_IF(!selNode->IsContent())) {
return NS_ERROR_FAILURE;
}
@@ -7063,20 +7070,20 @@ HTMLEditRules::ReturnInListItem(Selectio
}
}
// Are we in a sublist?
EditorRawDOMPoint atNextSiblingOfLeftList(leftListNode);
DebugOnly<bool> advanced = atNextSiblingOfLeftList.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the right list node");
- if (HTMLEditUtils::IsList(atNextSiblingOfLeftList.Container())) {
+ if (HTMLEditUtils::IsList(atNextSiblingOfLeftList.GetContainer())) {
// If so, move item out of this list and into the grandparent list
rv = htmlEditor->MoveNode(&aListItem,
- atNextSiblingOfLeftList.Container(),
+ atNextSiblingOfLeftList.GetContainer(),
atNextSiblingOfLeftList.Offset());
NS_ENSURE_SUCCESS(rv, rv);
rv = aSelection.Collapse(&aListItem, 0);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// Otherwise kill this item
rv = htmlEditor->DeleteNode(&aListItem);
NS_ENSURE_SUCCESS(rv, rv);
@@ -7537,43 +7544,44 @@ HTMLEditRules::MaybeSplitAncestorsForIns
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
RefPtr<Element> host = htmlEditor->GetActiveEditingHost();
if (NS_WARN_IF(!host)) {
return SplitNodeResult(NS_ERROR_FAILURE);
}
// The point must be descendant of editing host.
- if (NS_WARN_IF(aStartOfDeepestRightNode.Container() != host &&
+ if (NS_WARN_IF(aStartOfDeepestRightNode.GetContainer() != host &&
!EditorUtils::IsDescendantOf(
- *aStartOfDeepestRightNode.Container(), *host))) {
+ *aStartOfDeepestRightNode.GetContainer(), *host))) {
return SplitNodeResult(NS_ERROR_INVALID_ARG);
}
// Look for a node that can legally contain the tag.
EditorRawDOMPoint pointToInsert(aStartOfDeepestRightNode);
- for (; pointToInsert.IsSet(); pointToInsert.Set(pointToInsert.Container())) {
+ for (; pointToInsert.IsSet();
+ 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)) {
return SplitNodeResult(NS_ERROR_FAILURE);
}
- if (htmlEditor->CanContainTag(*pointToInsert.Container(), aTag)) {
+ if (htmlEditor->CanContainTag(*pointToInsert.GetContainer(), aTag)) {
// Found an ancestor node which can contain the element.
break;
}
}
MOZ_DIAGNOSTIC_ASSERT(pointToInsert.IsSet());
// If the point itself can contain the tag, we don't need to split any
// ancestor nodes. In this case, we should return the given split point
// as is.
- if (pointToInsert.Container() == aStartOfDeepestRightNode.Container()) {
+ if (pointToInsert.GetContainer() == aStartOfDeepestRightNode.GetContainer()) {
return SplitNodeResult(aStartOfDeepestRightNode);
}
SplitNodeResult splitNodeResult =
htmlEditor->SplitNodeDeep(*pointToInsert.GetChildAtOffset(),
aStartOfDeepestRightNode,
SplitAtEdges::eAllowToCreateEmptyContainer);
NS_WARNING_ASSERTION(splitNodeResult.Succeeded(),
@@ -8018,82 +8026,83 @@ HTMLEditRules::AdjustSelection(Selection
// get the (collapsed) selection location
EditorDOMPoint point(EditorBase::GetStartPoint(aSelection));
if (NS_WARN_IF(!point.IsSet())) {
return NS_ERROR_FAILURE;
}
// are we in an editable node?
NS_ENSURE_STATE(mHTMLEditor);
- while (!mHTMLEditor->IsEditable(point.Container())) {
+ while (!mHTMLEditor->IsEditable(point.GetContainer())) {
// scan up the tree until we find an editable place to be
- point.Set(point.Container());
+ point.Set(point.GetContainer());
if (NS_WARN_IF(!point.IsSet())) {
return NS_ERROR_FAILURE;
}
}
// make sure we aren't in an empty block - user will see no cursor. If this
// is happening, put a <br> in the block if allowed.
NS_ENSURE_STATE(mHTMLEditor);
- nsCOMPtr<Element> theblock = mHTMLEditor->GetBlock(*point.Container());
+ nsCOMPtr<Element> theblock = mHTMLEditor->GetBlock(*point.GetContainer());
if (theblock && mHTMLEditor->IsEditable(theblock)) {
bool bIsEmptyNode;
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv =
mHTMLEditor->IsEmptyNode(theblock, &bIsEmptyNode, false, false);
NS_ENSURE_SUCCESS(rv, rv);
// check if br can go into the destination node
NS_ENSURE_STATE(mHTMLEditor);
if (bIsEmptyNode &&
- mHTMLEditor->CanContainTag(*point.Container(), *nsGkAtoms::br)) {
+ mHTMLEditor->CanContainTag(*point.GetContainer(), *nsGkAtoms::br)) {
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<Element> rootNode = mHTMLEditor->GetRoot();
NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
- if (point.Container() == rootNode) {
+ if (point.GetContainer() == rootNode) {
// Our root node is completely empty. Don't add a <br> here.
// AfterEditInner() will add one for us when it calls
// CreateBogusNodeIfNeeded()!
return NS_OK;
}
// we know we can skip the rest of this routine given the cirumstance
- return CreateMozBR(*point.Container(), point.Offset());
+ return CreateMozBR(*point.GetContainer(), point.Offset());
}
}
// are we in a text node?
- if (EditorBase::IsTextNode(point.Container())) {
+ if (point.IsInTextNode()) {
return NS_OK; // we LIKE it when we are in a text node. that RULZ
}
// do we need to insert a special mozBR? We do if we are:
// 1) prior node is in same block where selection is AND
// 2) prior node is a br AND
// 3) that br is not visible
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIContent> nearNode =
mHTMLEditor->GetPreviousEditableHTMLNode(point.AsRaw());
if (nearNode) {
// is nearNode also a descendant of same block?
NS_ENSURE_STATE(mHTMLEditor);
- nsCOMPtr<Element> block = mHTMLEditor->GetBlock(*point.Container());
+ nsCOMPtr<Element> block = mHTMLEditor->GetBlock(*point.GetContainer());
nsCOMPtr<Element> nearBlock = mHTMLEditor->GetBlockNodeParent(nearNode);
if (block && block == nearBlock) {
if (nearNode && TextEditUtils::IsBreak(nearNode)) {
NS_ENSURE_STATE(mHTMLEditor);
if (!mHTMLEditor->IsVisibleBRElement(nearNode)) {
// need to insert special moz BR. Why? Because if we don't
// the user will see no new line for the break. Also, things
// like table cells won't grow in height.
RefPtr<Element> br;
nsresult rv =
- CreateMozBR(*point.Container(), point.Offset(), getter_AddRefs(br));
+ CreateMozBR(*point.GetContainer(), point.Offset(),
+ getter_AddRefs(br));
NS_ENSURE_SUCCESS(rv, rv);
point.Set(br);
// selection stays *before* moz-br, sticking to it
aSelection->SetInterlinePosition(true);
ErrorResult error;
aSelection->Collapse(point.AsRaw(), error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
@@ -8190,17 +8199,17 @@ HTMLEditRules::FindNearEditableNode(cons
nearNode = htmlEditor->GetNextEditableHTMLNode(*nearNode);
if (NS_WARN_IF(!nearNode)) {
return nullptr;
}
}
}
// don't cross any table elements
- if (InDifferentTableElements(nearNode, aPoint.Container())) {
+ if (InDifferentTableElements(nearNode, aPoint.GetContainer())) {
return nullptr;
}
// otherwise, ok, we have found a good spot to put the selection
return nearNode;
}
bool
@@ -8524,22 +8533,22 @@ HTMLEditRules::PopListItem(nsIContent& a
// Enter twice at a list item breaks the parent list node.
if (!bIsFirstListItem) {
DebugOnly<bool> advanced = pointToInsertListItem.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to right list node");
}
nsresult rv =
- mHTMLEditor->MoveNode(&aListItem, pointToInsertListItem.Container(),
+ mHTMLEditor->MoveNode(&aListItem, pointToInsertListItem.GetContainer(),
pointToInsertListItem.Offset());
NS_ENSURE_SUCCESS(rv, rv);
// unwrap list item contents if they are no longer in a list
- if (!HTMLEditUtils::IsList(pointToInsertListItem.Container()) &&
+ if (!HTMLEditUtils::IsList(pointToInsertListItem.GetContainer()) &&
HTMLEditUtils::IsListItem(&aListItem)) {
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->RemoveBlockContainer(*aListItem.AsElement());
NS_ENSURE_SUCCESS(rv, rv);
if (aOutOfList) {
*aOutOfList = true;
}
}
@@ -9277,25 +9286,26 @@ HTMLEditRules::WillAbsolutePosition(Sele
// Ignore all non-editable nodes. Leave them be.
if (!htmlEditor->IsEditable(curNode)) {
continue;
}
nsCOMPtr<nsIContent> sibling;
// Some logic for putting list items into nested lists...
- if (HTMLEditUtils::IsList(atCurNode.Container())) {
+ if (HTMLEditUtils::IsList(atCurNode.GetContainer())) {
// Check to see if curList is still appropriate. Which it is if curNode
// is still right after it in the same list.
if (curList) {
sibling = htmlEditor->GetPriorHTMLSibling(curNode);
}
if (!curList || (sibling && sibling != curList)) {
- nsAtom* containerName = atCurNode.Container()->NodeInfo()->NameAtom();
+ nsAtom* containerName =
+ atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atCurNode.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
if (!curPositionedDiv) {
curPositionedDiv =
@@ -9335,25 +9345,26 @@ HTMLEditRules::WillAbsolutePosition(Sele
sibling = htmlEditor->GetPriorHTMLSibling(listItem);
}
if (!curList || (sibling && sibling != curList)) {
EditorDOMPoint atListItem(listItem);
if (NS_WARN_IF(!atListItem.IsSet())) {
return NS_ERROR_FAILURE;
}
- nsAtom* containerName = atListItem.Container()->NodeInfo()->NameAtom();
+ nsAtom* containerName =
+ atListItem.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atListItem.AsRaw());
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
if (!curPositionedDiv) {
- EditorRawDOMPoint atListItemParent(atListItem.Container());
+ EditorRawDOMPoint atListItemParent(atListItem.GetContainer());
curPositionedDiv =
htmlEditor->CreateNode(nsGkAtoms::div, atListItemParent);
mNewBlock = curPositionedDiv;
}
EditorRawDOMPoint atEndOfCurPositionedDiv;
atEndOfCurPositionedDiv.SetToEndOf(curPositionedDiv);
curList =
htmlEditor->CreateNode(containerName, atEndOfCurPositionedDiv);
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1365,42 +1365,43 @@ HTMLEditor::GetBetterInsertionPointFor(n
}
// If the node to insert is not a block level element, we can insert it
// at any point.
if (!IsBlockNode(&aNodeToInsert)) {
return aPointToInsert;
}
- WSRunObject wsObj(this, aPointToInsert.Container(), aPointToInsert.Offset());
+ WSRunObject wsObj(this, aPointToInsert.GetContainer(),
+ aPointToInsert.Offset());
// If the insertion position is after the last visible item in a line,
// i.e., the insertion position is just before a visible line break <br>,
// we want to skip to the position just after the line break (see bug 68767).
nsCOMPtr<nsINode> nextVisibleNode;
int32_t nextVisibleOffset = 0;
WSType nextVisibleType;
- wsObj.NextVisibleNode(aPointToInsert.Container(), aPointToInsert.Offset(),
+ wsObj.NextVisibleNode(aPointToInsert.GetContainer(), aPointToInsert.Offset(),
address_of(nextVisibleNode),
&nextVisibleOffset, &nextVisibleType);
// So, if the next visible node isn't a <br> element, we can insert the block
// level element to the point.
if (!nextVisibleNode ||
!(nextVisibleType & WSType::br)) {
return aPointToInsert;
}
// However, we must not skip next <br> element when the caret appears to be
// positioned at the beginning of a block, in that case skipping the <br>
// would not insert the <br> at the caret position, but after the current
// empty line.
nsCOMPtr<nsINode> previousVisibleNode;
int32_t previousVisibleOffset = 0;
WSType previousVisibleType;
- wsObj.PriorVisibleNode(aPointToInsert.Container(), aPointToInsert.Offset(),
+ wsObj.PriorVisibleNode(aPointToInsert.GetContainer(), aPointToInsert.Offset(),
address_of(previousVisibleNode),
&previousVisibleOffset, &previousVisibleType);
// So, if there is no previous visible node,
// or, if both nodes of the insertion point is <br> elements,
// or, if the previous visible node is different block,
// we need to skip the following <br>. So, otherwise, we can insert the
// block at the insertion point.
if (!previousVisibleNode ||
@@ -1524,31 +1525,31 @@ HTMLEditor::InsertNodeIntoProperAncestor
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return EditorDOMPoint();
}
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
// Search up the parent chain to find a suitable container.
EditorDOMPoint pointToInsert(aPointToInsert);
MOZ_ASSERT(pointToInsert.IsSet());
- while (!CanContain(*pointToInsert.Container(), aNode)) {
+ while (!CanContain(*pointToInsert.GetContainer(), aNode)) {
// If the current parent is a root (body or table element)
// then go no further - we can't insert.
- if (pointToInsert.Container()->IsHTMLElement(nsGkAtoms::body) ||
- HTMLEditUtils::IsTableElement(pointToInsert.Container())) {
+ if (pointToInsert.IsContainerHTMLElement(nsGkAtoms::body) ||
+ HTMLEditUtils::IsTableElement(pointToInsert.GetContainer())) {
return EditorDOMPoint();
}
// Get the next point.
- pointToInsert.Set(pointToInsert.Container());
+ pointToInsert.Set(pointToInsert.GetContainer());
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return EditorDOMPoint();
}
- if (!IsEditable(pointToInsert.Container())) {
+ if (!IsEditable(pointToInsert.GetContainer())) {
// There's no suitable place to put the node in this editing host. Maybe
// someone is trying to put block content in a span. So just put it
// where we were originally asked.
pointToInsert = aPointToInsert;
break;
}
}
@@ -1918,33 +1919,33 @@ HTMLEditor::MakeOrChangeList(const nsASt
if (!handled && selection->Collapsed()) {
nsRange* firstRange = selection->GetRangeAt(0);
if (NS_WARN_IF(!firstRange)) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet()) ||
- NS_WARN_IF(!atStartOfSelection.Container()->IsContent())) {
+ NS_WARN_IF(!atStartOfSelection.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
}
// Have to find a place to put the list.
EditorDOMPoint pointToInsertList(atStartOfSelection);
RefPtr<nsAtom> listAtom = NS_Atomize(aListType);
- while (!CanContainTag(*pointToInsertList.Container(), *listAtom)) {
- pointToInsertList.Set(pointToInsertList.Container());
+ while (!CanContainTag(*pointToInsertList.GetContainer(), *listAtom)) {
+ pointToInsertList.Set(pointToInsertList.GetContainer());
if (NS_WARN_IF(!pointToInsertList.IsSet()) ||
- NS_WARN_IF(!pointToInsertList.Container()->IsContent())) {
+ NS_WARN_IF(!pointToInsertList.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
}
}
- if (pointToInsertList.Container() != atStartOfSelection.Container()) {
+ if (pointToInsertList.GetContainer() != atStartOfSelection.GetContainer()) {
// We need to split up to the child of parent.
SplitNodeResult splitNodeResult =
SplitNodeDeep(*pointToInsertList.GetChildAtOffset(),
atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@@ -2067,33 +2068,34 @@ HTMLEditor::InsertBasicBlock(const nsASt
if (!handled && selection->Collapsed()) {
nsRange* firstRange = selection->GetRangeAt(0);
if (NS_WARN_IF(!firstRange)) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet()) ||
- NS_WARN_IF(!atStartOfSelection.Container()->IsContent())) {
+ NS_WARN_IF(!atStartOfSelection.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
}
// Have to find a place to put the block.
EditorDOMPoint pointToInsertBlock(atStartOfSelection);
RefPtr<nsAtom> blockAtom = NS_Atomize(aBlockType);
- while (!CanContainTag(*pointToInsertBlock.Container(), *blockAtom)) {
- pointToInsertBlock.Set(pointToInsertBlock.Container());
+ while (!CanContainTag(*pointToInsertBlock.GetContainer(), *blockAtom)) {
+ pointToInsertBlock.Set(pointToInsertBlock.GetContainer());
if (NS_WARN_IF(!pointToInsertBlock.IsSet()) ||
- NS_WARN_IF(!pointToInsertBlock.Container()->IsContent())) {
+ NS_WARN_IF(!pointToInsertBlock.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
}
}
- if (pointToInsertBlock.Container() != atStartOfSelection.Container()) {
+ if (pointToInsertBlock.GetContainer() !=
+ atStartOfSelection.GetContainer()) {
// We need to split up to the child of the point to insert a block.
SplitNodeResult splitBlockResult =
SplitNodeDeep(*pointToInsertBlock.GetChildAtOffset(),
atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitBlockResult.Failed())) {
return splitBlockResult.Rv();
}
@@ -2149,34 +2151,34 @@ HTMLEditor::Indent(const nsAString& aInd
if (!handled && selection->Collapsed() && aIndent.EqualsLiteral("indent")) {
nsRange* firstRange = selection->GetRangeAt(0);
if (NS_WARN_IF(!firstRange)) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet()) ||
- NS_WARN_IF(!atStartOfSelection.Container()->IsContent())) {
+ NS_WARN_IF(!atStartOfSelection.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
}
// Have to find a place to put the blockquote.
EditorDOMPoint pointToInsertBlockquote(atStartOfSelection);
- while (!CanContainTag(*pointToInsertBlockquote.Container(),
+ while (!CanContainTag(*pointToInsertBlockquote.GetContainer(),
*nsGkAtoms::blockquote)) {
- pointToInsertBlockquote.Set(pointToInsertBlockquote.Container());
+ pointToInsertBlockquote.Set(pointToInsertBlockquote.GetContainer());
if (NS_WARN_IF(!pointToInsertBlockquote.IsSet()) ||
- NS_WARN_IF(!pointToInsertBlockquote.Container()->IsContent())) {
+ NS_WARN_IF(!pointToInsertBlockquote.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
}
}
- if (pointToInsertBlockquote.Container() !=
- atStartOfSelection.Container()) {
+ if (pointToInsertBlockquote.GetContainer() !=
+ atStartOfSelection.GetContainer()) {
// We need to split up to the child of parent.
SplitNodeResult splitBlockquoteResult =
SplitNodeDeep(*pointToInsertBlockquote.GetChildAtOffset(),
atStartOfSelection,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitBlockquoteResult.Failed())) {
return splitBlockquoteResult.Rv();
}
@@ -2247,23 +2249,23 @@ HTMLEditor::GetElementOrParentByTagName(
}
const EditorDOMPoint atAnchor(selection->AnchorRef());
if (NS_WARN_IF(!atAnchor.IsSet())) {
return nullptr;
}
// Try to get the actual selected node
- if (atAnchor.Container()->HasChildNodes() &&
- atAnchor.Container()->IsContent()) {
+ if (atAnchor.GetContainer()->HasChildNodes() &&
+ atAnchor.GetContainerAsContent()) {
node = atAnchor.GetChildAtOffset();
}
// Anchor node is probably a text node - just use that
if (!node) {
- node = atAnchor.Container();
+ node = atAnchor.GetContainer();
}
}
nsCOMPtr<Element> current;
if (node->IsElement()) {
current = node->AsElement();
} else if (node->GetParentElement()) {
current = node->GetParentElement();
@@ -3136,17 +3138,17 @@ HTMLEditor::InsertTextImpl(nsIDocument&
const EditorRawDOMPoint& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return NS_ERROR_INVALID_ARG;
}
// Do nothing if the node is read-only
- if (!IsModifiableNode(aPointToInsert.Container())) {
+ if (!IsModifiableNode(aPointToInsert.GetContainer())) {
return NS_ERROR_FAILURE;
}
return EditorBase::InsertTextImpl(aDocument, aStringToInsert, aPointToInsert,
aPointAfterInsertedString);
}
void
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -338,21 +338,22 @@ public:
// Utility Routines, not part of public API
NS_IMETHOD TypedText(const nsAString& aString,
ETypingAction aAction) override;
/**
* InsertNodeIntoProperAncestor() attempts to insert aNode into the document,
* at aPointToInsert. Checks with strict dtd to see if containment is
* allowed. If not allowed, will attempt to find a parent in the parent
- * hierarchy of aPointToInsert.Container() that will accept aNode as a child.
- * If such a parent is found, will split the document tree from aPointToInsert
- * up to parent, and then insert aNode. aPointToInsert is then adjusted to
- * point to the actual location that aNode was inserted at. aSplitAtEdges
- * specifies if the splitting process is allowed to result in empty nodes.
+ * hierarchy of aPointToInsert.GetContainer() that will accept aNode as a
+ * child. If such a parent is found, will split the document tree from
+ * aPointToInsert up to parent, and then insert aNode. aPointToInsert is then
+ * adjusted to point to the actual location that aNode was inserted at.
+ * aSplitAtEdges specifies if the splitting process is allowed to result in
+ * empty nodes.
*
* @param aNode Node to insert.
* @param aPointToInsert Insertion point.
* @param aSplitAtEdges Splitting can result in empty nodes?
* @return Returns inserted point if succeeded.
* Otherwise, the result is not set.
*/
EditorDOMPoint
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -146,21 +146,22 @@ HTMLEditor::LoadHTML(const nsAString& aI
rv = InsertNode(*contentToInsert, pointToInsert.AsRaw());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// XXX If the inserted node has been moved by mutation observer,
// incrementing offset will cause odd result. Next new node
// will be inserted after existing node and the offset will be
// overflown from the container node.
- pointToInsert.Set(pointToInsert.Container(), pointToInsert.Offset() + 1);
+ pointToInsert.Set(pointToInsert.GetContainer(),
+ pointToInsert.Offset() + 1);
if (NS_WARN_IF(!pointToInsert.Offset())) {
// Append the remaining children to the container if offset is
// overflown.
- pointToInsert.SetToEndOf(pointToInsert.Container());
+ pointToInsert.SetToEndOf(pointToInsert.GetContainer());
}
}
}
return rules->DidDoAction(selection, &ruleInfo, rv);
}
NS_IMETHODIMP
@@ -349,32 +350,33 @@ HTMLEditor::DoInsertHTMLWithContext(cons
GetBetterInsertionPointFor(nodeList[0], GetStartPoint(selection));
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
}
// if there are any invisible br's after our insertion point, remove them.
// this is because if there is a br at end of what we paste, it will make
// the invisible br visible.
- WSRunObject wsObj(this, pointToInsert.Container(), pointToInsert.Offset());
+ WSRunObject wsObj(this, pointToInsert.GetContainer(),
+ pointToInsert.Offset());
if (wsObj.mEndReasonNode &&
TextEditUtils::IsBreak(wsObj.mEndReasonNode) &&
!IsVisibleBRElement(wsObj.mEndReasonNode)) {
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
rv = DeleteNode(wsObj.mEndReasonNode);
NS_ENSURE_SUCCESS(rv, rv);
}
// Remember if we are in a link.
- bool bStartedInLink = IsInLink(pointToInsert.Container()->AsDOMNode());
+ bool bStartedInLink = IsInLink(pointToInsert.GetContainerAsDOMNode());
// Are we in a text node? If so, split it.
- if (IsTextNode(pointToInsert.Container())) {
+ if (pointToInsert.IsInTextNode()) {
SplitNodeResult splitNodeResult =
- SplitNodeDeep(*pointToInsert.Container()->AsContent(),
+ SplitNodeDeep(*pointToInsert.GetContainerAsContent(),
pointToInsert.AsRaw(),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
pointToInsert = splitNodeResult.SplitPoint();
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
@@ -414,24 +416,25 @@ HTMLEditor::DoInsertHTMLWithContext(cons
}
// don't orphan partial list or table structure
if (highWaterMark >= 0) {
ReplaceOrphanedStructure(StartOrEnd::end, nodeList,
endListAndTableArray, highWaterMark);
}
- MOZ_ASSERT(pointToInsert.Container()->GetChildAt(pointToInsert.Offset()) ==
+ MOZ_ASSERT(pointToInsert.GetContainer()->
+ GetChildAt(pointToInsert.Offset()) ==
pointToInsert.GetChildAtOffset());
// Loop over the node list and paste the nodes:
nsCOMPtr<nsINode> parentBlock =
- IsBlockNode(pointToInsert.Container()) ?
- pointToInsert.Container() :
- GetBlockNodeParent(pointToInsert.Container());
+ IsBlockNode(pointToInsert.GetContainer()) ?
+ pointToInsert.GetContainer() :
+ GetBlockNodeParent(pointToInsert.GetContainer());
nsCOMPtr<nsIContent> lastInsertNode;
nsCOMPtr<nsINode> insertedContextParent;
for (OwningNonNull<nsINode>& curNode : nodeList) {
if (NS_WARN_IF(curNode == fragmentAsNodeNode) ||
NS_WARN_IF(TextEditUtils::IsBody(curNode))) {
return NS_ERROR_FAILURE;
}
@@ -445,19 +448,19 @@ HTMLEditor::DoInsertHTMLWithContext(cons
}
}
// give the user a hand on table element insertion. if they have
// a table or table row on the clipboard, and are trying to insert
// into a table or table row, insert the appropriate children instead.
bool bDidInsert = false;
if (HTMLEditUtils::IsTableRow(curNode) &&
- HTMLEditUtils::IsTableRow(pointToInsert.Container()) &&
+ HTMLEditUtils::IsTableRow(pointToInsert.GetContainer()) &&
(HTMLEditUtils::IsTable(curNode) ||
- HTMLEditUtils::IsTable(pointToInsert.Container()))) {
+ HTMLEditUtils::IsTable(pointToInsert.GetContainer()))) {
for (nsCOMPtr<nsIContent> firstChild = curNode->GetFirstChild();
firstChild;
firstChild = curNode->GetFirstChild()) {
EditorDOMPoint insertedPoint =
InsertNodeIntoProperAncestor(
*firstChild, pointToInsert.AsRaw(),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!insertedPoint.IsSet())) {
@@ -471,34 +474,35 @@ HTMLEditor::DoInsertHTMLWithContext(cons
"Failed to advance offset from inserted point");
}
}
// give the user a hand on list insertion. if they have
// a list on the clipboard, and are trying to insert
// into a list or list item, insert the appropriate children instead,
// ie, merge the lists instead of pasting in a sublist.
else if (HTMLEditUtils::IsList(curNode) &&
- (HTMLEditUtils::IsList(pointToInsert.Container()) ||
- HTMLEditUtils::IsListItem(pointToInsert.Container()))) {
+ (HTMLEditUtils::IsList(pointToInsert.GetContainer()) ||
+ HTMLEditUtils::IsListItem(pointToInsert.GetContainer()))) {
for (nsCOMPtr<nsIContent> firstChild = curNode->GetFirstChild();
firstChild;
firstChild = curNode->GetFirstChild()) {
if (HTMLEditUtils::IsListItem(firstChild) ||
HTMLEditUtils::IsList(firstChild)) {
// Check if we are pasting into empty list item. If so
// delete it and paste into parent list instead.
- if (HTMLEditUtils::IsListItem(pointToInsert.Container())) {
+ if (HTMLEditUtils::IsListItem(pointToInsert.GetContainer())) {
bool isEmpty;
- rv = IsEmptyNode(pointToInsert.Container(), &isEmpty, true);
+ rv = IsEmptyNode(pointToInsert.GetContainer(), &isEmpty, true);
if (NS_SUCCEEDED(rv) && isEmpty) {
- if (NS_WARN_IF(!pointToInsert.Container()->GetParentNode())) {
+ if (NS_WARN_IF(!pointToInsert.GetContainer()->
+ GetParentNode())) {
// Is it an orphan node?
} else {
- DeleteNode(pointToInsert.Container());
- pointToInsert.Set(pointToInsert.Container());
+ DeleteNode(pointToInsert.GetContainer());
+ pointToInsert.Set(pointToInsert.GetContainer());
}
}
}
EditorDOMPoint insertedPoint =
InsertNodeIntoProperAncestor(
*firstChild, pointToInsert.AsRaw(),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!insertedPoint.IsSet())) {
@@ -613,17 +617,17 @@ HTMLEditor::DoInsertHTMLWithContext(cons
} else {
// We need to find a container for selection. Look up.
EditorRawDOMPoint pointAtContainer(selNode);
if (NS_WARN_IF(!pointAtContainer.IsSet())) {
return NS_ERROR_FAILURE;
}
// The container might be null in case a mutation listener removed
// the stuff we just inserted from the DOM.
- selNode = pointAtContainer.Container();
+ selNode = pointAtContainer.GetContainer();
// Want to be *after* last leaf node in paste.
selOffset = pointAtContainer.Offset() + 1;
}
// make sure we don't end up with selection collapsed after an invisible break node
WSRunObject wsRunObj(this, selNode, selOffset);
nsCOMPtr<nsINode> visNode;
int32_t outVisOffset=0;
@@ -634,30 +638,30 @@ HTMLEditor::DoInsertHTMLWithContext(cons
// we are after a break. Is it visible? Despite the name,
// PriorVisibleNode does not make that determination for breaks.
// It also may not return the break in visNode. We have to pull it
// out of the WSRunObject's state.
if (!IsVisibleBRElement(wsRunObj.mStartReasonNode)) {
// don't leave selection past an invisible break;
// reset {selNode,selOffset} to point before break
EditorRawDOMPoint atStartReasonNode(wsRunObj.mStartReasonNode);
- selNode = atStartReasonNode.Container();
+ selNode = atStartReasonNode.GetContainer();
selOffset = atStartReasonNode.Offset();
// we want to be inside any inline style prior to break
WSRunObject wsRunObj(this, selNode, selOffset);
wsRunObj.PriorVisibleNode(selNode, selOffset, address_of(visNode),
&outVisOffset, &visType);
if (visType == WSType::text || visType == WSType::normalWS) {
selNode = visNode;
selOffset = outVisOffset; // PriorVisibleNode already set offset to _after_ the text or ws
} else if (visType == WSType::special) {
// prior visible thing is an image or some other non-text thingy.
// We want to be right after it.
atStartReasonNode.Set(wsRunObj.mStartReasonNode);
- selNode = atStartReasonNode.Container();
+ selNode = atStartReasonNode.GetContainer();
selOffset = atStartReasonNode.Offset() + 1;
}
}
}
selection->Collapse(selNode, selOffset);
// if we just pasted a link, discontinue link style
nsCOMPtr<nsIDOMNode> link;
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -562,17 +562,17 @@ HTMLEditor::SplitStyleAbovePoint(nsCOMPt
// Found a style node we need to split
SplitNodeResult splitNodeResult =
SplitNodeDeep(*node, EditorRawDOMPoint(*aNode, *aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
NS_WARNING_ASSERTION(splitNodeResult.Succeeded(),
"Failed to split the node");
EditorRawDOMPoint atRightNode(splitNodeResult.SplitPoint());
- *aNode = atRightNode.Container();
+ *aNode = atRightNode.GetContainer();
*aOffset = atRightNode.Offset();
if (aOutLeftNode) {
NS_IF_ADDREF(*aOutLeftNode = splitNodeResult.GetPreviousNode());
}
if (aOutRightNode) {
NS_IF_ADDREF(*aOutRightNode = splitNodeResult.GetNextNode());
}
}
--- a/editor/libeditor/InsertNodeTransaction.cpp
+++ b/editor/libeditor/InsertNodeTransaction.cpp
@@ -61,36 +61,36 @@ 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 (!newPointToInsert.IsSet()) {
// The insertion point has been removed from the DOM tree.
// In this case, we should append the node to the container instead.
- newPointToInsert.SetToEndOf(mPointToInsert.Container());
+ newPointToInsert.SetToEndOf(mPointToInsert.GetContainer());
if (NS_WARN_IF(!newPointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
}
}
mPointToInsert = newPointToInsert;
} else {
- mPointToInsert.SetToEndOf(mPointToInsert.Container());
+ mPointToInsert.SetToEndOf(mPointToInsert.GetContainer());
if (NS_WARN_IF(!mPointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
}
}
}
mEditorBase->MarkNodeDirty(GetAsDOMNode(mContentToInsert));
ErrorResult error;
- mPointToInsert.Container()->InsertBefore(*mContentToInsert,
- mPointToInsert.GetChildAtOffset(),
- error);
+ mPointToInsert.GetContainer()->InsertBefore(*mContentToInsert,
+ mPointToInsert.GetChildAtOffset(),
+ error);
error.WouldReportJSException();
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
// Only set selection to insertion point if editor gives permission
if (mEditorBase->GetShouldTxnSetSelection()) {
RefPtr<Selection> selection = mEditorBase->GetSelection();
@@ -115,17 +115,17 @@ InsertNodeTransaction::UndoTransaction()
{
if (NS_WARN_IF(!mContentToInsert) ||
NS_WARN_IF(!mPointToInsert.IsSet())) {
return NS_ERROR_NOT_INITIALIZED;
}
// XXX If the inserted node has been moved to different container node or
// just removed from the DOM tree, this always fails.
ErrorResult error;
- mPointToInsert.Container()->RemoveChild(*mContentToInsert, error);
+ mPointToInsert.GetContainer()->RemoveChild(*mContentToInsert, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
NS_IMETHODIMP
InsertNodeTransaction::GetTxnDescription(nsAString& aString)
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -315,17 +315,18 @@ RangeUpdater::SelAdjSplitNode(nsIContent
}
size_t count = mArray.Length();
if (!count) {
return NS_OK;
}
EditorRawDOMPoint atLeftNode(aNewLeftNode);
- nsresult rv = SelAdjInsertNode(atLeftNode.Container(), atLeftNode.Offset());
+ nsresult rv =
+ SelAdjInsertNode(atLeftNode.GetContainer(), atLeftNode.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// If point in the ranges is in left node, change its container to the left
// node. If point in the ranges is in right node, subtract numbers of
// children moved to left node from the offset.
int32_t lengthOfLeftNode = aNewLeftNode->Length();
--- a/editor/libeditor/SelectionState.h
+++ b/editor/libeditor/SelectionState.h
@@ -220,18 +220,18 @@ public:
EditorDOMPoint* aPoint)
: mRangeUpdater(aRangeUpdater)
, mNode(nullptr)
, mDOMNode(nullptr)
, mOffset(nullptr)
, mPoint(aPoint)
{
mRangeItem = new RangeItem();
- mRangeItem->mStartContainer = mPoint->Container();
- mRangeItem->mEndContainer = mPoint->Container();
+ mRangeItem->mStartContainer = mPoint->GetContainer();
+ mRangeItem->mEndContainer = mPoint->GetContainer();
mRangeItem->mStartOffset = mPoint->Offset();
mRangeItem->mEndOffset = mPoint->Offset();
mRangeUpdater.RegisterRangeItem(mRangeItem);
}
~AutoTrackDOMPoint()
{
mRangeUpdater.DropRangeItem(mRangeItem);
--- a/editor/libeditor/SplitNodeTransaction.cpp
+++ b/editor/libeditor/SplitNodeTransaction.cpp
@@ -19,17 +19,17 @@ using namespace dom;
SplitNodeTransaction::SplitNodeTransaction(
EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode)
: mEditorBase(&aEditorBase)
, mStartOfRightNode(aStartOfRightNode)
{
MOZ_DIAGNOSTIC_ASSERT(aStartOfRightNode.IsSet());
- MOZ_DIAGNOSTIC_ASSERT(aStartOfRightNode.Container()->IsContent());
+ MOZ_DIAGNOSTIC_ASSERT(aStartOfRightNode.GetContainerAsContent());
}
SplitNodeTransaction::~SplitNodeTransaction()
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(SplitNodeTransaction, EditTransactionBase,
mEditorBase,
@@ -50,28 +50,28 @@ SplitNodeTransaction::DoTransaction()
return NS_ERROR_NOT_INITIALIZED;
}
MOZ_ASSERT(mStartOfRightNode.IsSetAndValid());
// Create a new node
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();
}
if (NS_WARN_IF(!clone)) {
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;
}
// Insert the new node
mEditorBase->SplitNodeImpl(EditorDOMPoint(mStartOfRightNode),
*mNewLeftNode, error);
// XXX Really odd. The result of SplitNodeImpl() is respected only when
@@ -109,70 +109,71 @@ SplitNodeTransaction::UndoTransaction()
NS_WARN_IF(!mParent) ||
NS_WARN_IF(!mStartOfRightNode.IsSet())) {
return NS_ERROR_NOT_INITIALIZED;
}
// 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
* on the redo stack may depend on the left node existing in its previous
* state.
*/
NS_IMETHODIMP
SplitNodeTransaction::RedoTransaction()
{
if (NS_WARN_IF(!mNewLeftNode) ||
NS_WARN_IF(!mParent) ||
NS_WARN_IF(!mStartOfRightNode.IsSet())) {
return NS_ERROR_NOT_INITIALIZED;
}
// 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());
if (NS_WARN_IF(NS_FAILED(rv))) {
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
// mStartOfRightNode::GetChildAtOffset(). 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.
if (NS_WARN_IF(!child)) {
return NS_ERROR_NULL_POINTER;
}
nextSibling = child->GetNextSibling();
ErrorResult error;
- mStartOfRightNode.Container()->RemoveChild(*child, error);
+ mStartOfRightNode.GetContainer()->RemoveChild(*child, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
mNewLeftNode->AppendChild(*child, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
child = nextSibling;
}
}
// 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();
}
return NS_OK;
}
NS_IMETHODIMP
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -731,18 +731,18 @@ TextEditRules::WillInsertText(EditAction
NS_ENSURE_STATE(aSelection->GetRangeAt(0));
EditorRawDOMPoint atStartOfSelection(aSelection->GetRangeAt(0)->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSetAndValid())) {
return NS_ERROR_FAILURE;
}
// don't put text in places that can't have it
NS_ENSURE_STATE(mTextEditor);
- if (!EditorBase::IsTextNode(atStartOfSelection.Container()) &&
- !mTextEditor->CanContainTag(*atStartOfSelection.Container(),
+ if (!atStartOfSelection.IsInTextNode() &&
+ !mTextEditor->CanContainTag(*atStartOfSelection.GetContainer(),
*nsGkAtoms::textTagName)) {
return NS_ERROR_FAILURE;
}
// we need to get the doc
NS_ENSURE_STATE(mTextEditor);
nsCOMPtr<nsIDocument> doc = mTextEditor->GetDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
@@ -751,19 +751,19 @@ TextEditRules::WillInsertText(EditAction
NS_ENSURE_STATE(mTextEditor);
// Find better insertion point to insert text.
EditorRawDOMPoint betterInsertionPoint =
mTextEditor->FindBetterInsertionPoint(atStartOfSelection);
// If there is one or more IME selections, its minimum offset should be
// the insertion point.
int32_t IMESelectionOffset =
mTextEditor->GetIMESelectionStartOffsetIn(
- betterInsertionPoint.Container());
+ betterInsertionPoint.GetContainer());
if (IMESelectionOffset >= 0) {
- betterInsertionPoint.Set(betterInsertionPoint.Container(),
+ betterInsertionPoint.Set(betterInsertionPoint.GetContainer(),
IMESelectionOffset);
}
rv = mTextEditor->InsertTextImpl(*doc, *outString, betterInsertionPoint);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// aAction == EditAction::insertText
// don't change my selection in subtransactions
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -435,27 +435,27 @@ TextEditor::CreateBRImpl(Selection& aSel
EDirection aSelect)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return nullptr;
}
// We need to insert a <br> node.
RefPtr<Element> newBRElement;
- if (IsTextNode(aPointToInsert.Container())) {
+ if (aPointToInsert.IsInTextNode()) {
EditorDOMPoint pointInContainer;
if (aPointToInsert.IsStartOfContainer()) {
// Insert before the text node.
- pointInContainer.Set(aPointToInsert.Container());
+ pointInContainer.Set(aPointToInsert.GetContainer());
if (NS_WARN_IF(!pointInContainer.IsSet())) {
return nullptr;
}
} else if (aPointToInsert.IsEndOfContainer()) {
// Insert after the text node.
- pointInContainer.Set(aPointToInsert.Container());
+ pointInContainer.Set(aPointToInsert.GetContainer());
if (NS_WARN_IF(!pointInContainer.IsSet())) {
return nullptr;
}
DebugOnly<bool> advanced = pointInContainer.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the text node");
} else {
MOZ_DIAGNOSTIC_ASSERT(aPointToInsert.IsSetAndValid());
@@ -463,17 +463,17 @@ TextEditor::CreateBRImpl(Selection& aSel
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode = SplitNode(aPointToInsert, error);
if (NS_WARN_IF(error.Failed())) {
error.SuppressException();
return nullptr;
}
Unused << newLeftNode;
// Insert new <br> before the right node.
- pointInContainer.Set(aPointToInsert.Container());
+ pointInContainer.Set(aPointToInsert.GetContainer());
}
// Create a <br> node.
newBRElement = CreateNode(nsGkAtoms::br, pointInContainer.AsRaw());
if (NS_WARN_IF(!newBRElement)) {
return nullptr;
}
} else {
newBRElement = CreateNode(nsGkAtoms::br, aPointToInsert);
@@ -579,19 +579,19 @@ TextEditor::ExtendSelectionForDelete(Sel
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
// node might be anonymous DIV, so we find better text node
EditorRawDOMPoint insertionPoint =
FindBetterInsertionPoint(atStartOfSelection);
- if (IsTextNode(insertionPoint.Container())) {
+ if (insertionPoint.IsInTextNode()) {
const nsTextFragment* data =
- insertionPoint.Container()->GetAsText()->GetText();
+ insertionPoint.GetContainerAsText()->GetText();
uint32_t offset = insertionPoint.Offset();
if ((offset > 1 &&
NS_IS_LOW_SURROGATE(data->CharAt(offset - 1)) &&
NS_IS_HIGH_SURROGATE(data->CharAt(offset - 2))) ||
(offset > 0 &&
gfxFontUtils::IsVarSelector(data->CharAt(offset - 1)))) {
nsresult rv = selCont->CharacterExtendForBackspace();
if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -758,18 +758,19 @@ TextEditor::InsertLineBreak()
EditorRawDOMPoint pointToInsert(firstRange->StartRef());
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(pointToInsert.IsSetAndValid());
// don't put text in places that can't have it
- if (!IsTextNode(pointToInsert.Container()) &&
- !CanContainTag(*pointToInsert.Container(), *nsGkAtoms::textTagName)) {
+ if (!pointToInsert.IsInTextNode() &&
+ !CanContainTag(*pointToInsert.GetContainer(),
+ *nsGkAtoms::textTagName)) {
return NS_ERROR_FAILURE;
}
// we need to get the doc
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
// don't change my selection in subtransactions
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -288,17 +288,17 @@ WSRunObject::InsertText(nsIDocument& aDo
// would become significant after text inserted.
nsresult rv = DeleteRange(pointToInsert.AsRaw(), afterRun->EndPoint());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else if (afterRun->mType == WSType::normalWS) {
// Try to change an nbsp to a space, if possible, just to prevent nbsp
// proliferation
- nsresult rv = CheckLeadingNBSP(afterRun, pointToInsert.Container(),
+ nsresult rv = CheckLeadingNBSP(afterRun, pointToInsert.GetContainer(),
pointToInsert.Offset());
NS_ENSURE_SUCCESS(rv, rv);
}
// Handle any changes needed to ws run before inserted text
if (!beforeRun || beforeRun->mType & WSType::leadingWS) {
// Don't need to do anything. Just insert text. ws won't change.
} else if (beforeRun->mType & WSType::trailingWS) {
@@ -690,17 +690,17 @@ WSRunObject::GetWSNodes()
}
}
while (!mStartNode) {
// we haven't found the start of ws yet. Keep looking
nsCOMPtr<nsIContent> priorNode = GetPreviousWSNode(start, wsBoundingParent);
if (priorNode) {
if (IsBlockNode(priorNode)) {
- mStartNode = start.Container();
+ mStartNode = start.GetContainer();
mStartOffset = start.Offset();
mStartReason = WSType::otherBlock;
mStartReasonNode = priorNode;
} else if (priorNode->IsNodeOfType(nsINode::eTEXT) &&
priorNode->IsEditable()) {
RefPtr<Text> textNode = priorNode->GetAsText();
mNodeArray.InsertElementAt(0, textNode);
const nsTextFragment *textFrag;
@@ -739,28 +739,28 @@ WSRunObject::GetWSNodes()
}
}
start.Set(textNode, pos);
}
}
} else {
// it's a break or a special node, like <img>, that is not a block and not
// a break but still serves as a terminator to ws runs.
- mStartNode = start.Container();
+ mStartNode = start.GetContainer();
mStartOffset = start.Offset();
if (TextEditUtils::IsBreak(priorNode)) {
mStartReason = WSType::br;
} else {
mStartReason = WSType::special;
}
mStartReasonNode = priorNode;
}
} else {
// no prior node means we exhausted wsBoundingParent
- mStartNode = start.Container();
+ mStartNode = start.GetContainer();
mStartOffset = start.Offset();
mStartReason = WSType::thisBlock;
mStartReasonNode = wsBoundingParent;
}
}
// then look ahead to find following ws nodes
if (RefPtr<Text> textNode = mNode->GetAsText()) {
@@ -799,17 +799,17 @@ WSRunObject::GetWSNodes()
}
while (!mEndNode) {
// we haven't found the end of ws yet. Keep looking
nsCOMPtr<nsIContent> nextNode = GetNextWSNode(end, wsBoundingParent);
if (nextNode) {
if (IsBlockNode(nextNode)) {
// we encountered a new block. therefore no more ws.
- mEndNode = end.Container();
+ mEndNode = end.GetContainer();
mEndOffset = end.Offset();
mEndReason = WSType::otherBlock;
mEndReasonNode = nextNode;
} else if (nextNode->IsNodeOfType(nsINode::eTEXT) &&
nextNode->IsEditable()) {
RefPtr<Text> textNode = nextNode->GetAsText();
mNodeArray.AppendElement(textNode);
const nsTextFragment *textFrag;
@@ -849,28 +849,28 @@ WSRunObject::GetWSNodes()
}
end.Set(textNode, pos + 1);
}
}
} else {
// we encountered a break or a special node, like <img>,
// that is not a block and not a break but still
// serves as a terminator to ws runs.
- mEndNode = end.Container();
+ mEndNode = end.GetContainer();
mEndOffset = end.Offset();
if (TextEditUtils::IsBreak(nextNode)) {
mEndReason = WSType::br;
} else {
mEndReason = WSType::special;
}
mEndReasonNode = nextNode;
}
} else {
// no next node means we exhausted wsBoundingParent
- mEndNode = end.Container();
+ mEndNode = end.GetContainer();
mEndOffset = end.Offset();
mEndReason = WSType::thisBlock;
mEndReasonNode = wsBoundingParent;
}
}
return NS_OK;
}
@@ -1070,34 +1070,34 @@ nsIContent*
WSRunObject::GetPreviousWSNode(const EditorDOMPoint& aPoint,
nsINode* aBlockParent)
{
// Can't really recycle various getnext/prior routines because we
// have special needs here. Need to step into inline containers but
// not block containers.
MOZ_ASSERT(aPoint.IsSet() && aBlockParent);
- if (aPoint.Container()->NodeType() == nsIDOMNode::TEXT_NODE) {
- return GetPreviousWSNodeInner(aPoint.Container(), aBlockParent);
+ if (aPoint.IsInTextNode()) {
+ return GetPreviousWSNodeInner(aPoint.GetContainer(), aBlockParent);
}
- if (!mHTMLEditor->IsContainer(aPoint.Container())) {
- return GetPreviousWSNodeInner(aPoint.Container(), aBlockParent);
+ if (!mHTMLEditor->IsContainer(aPoint.GetContainer())) {
+ return GetPreviousWSNodeInner(aPoint.GetContainer(), aBlockParent);
}
if (!aPoint.Offset()) {
- if (aPoint.Container() == aBlockParent) {
+ if (aPoint.GetContainer() == aBlockParent) {
// We are at start of the block.
return nullptr;
}
// We are at start of non-block container
- return GetPreviousWSNodeInner(aPoint.Container(), aBlockParent);
+ return GetPreviousWSNodeInner(aPoint.GetContainer(), aBlockParent);
}
- if (NS_WARN_IF(!aPoint.Container()->IsContent())) {
+ if (NS_WARN_IF(!aPoint.GetContainerAsContent())) {
return nullptr;
}
nsCOMPtr<nsIContent> priorNode = aPoint.GetPreviousSiblingOfChildAtOffset();
if (NS_WARN_IF(!priorNode)) {
return nullptr;
}
@@ -1159,36 +1159,36 @@ nsIContent*
WSRunObject::GetNextWSNode(const EditorDOMPoint& aPoint,
nsINode* aBlockParent)
{
// Can't really recycle various getnext/prior routines because we have
// special needs here. Need to step into inline containers but not block
// containers.
MOZ_ASSERT(aPoint.IsSet() && aBlockParent);
- if (aPoint.Container()->NodeType() == nsIDOMNode::TEXT_NODE) {
- return GetNextWSNodeInner(aPoint.Container(), aBlockParent);
+ if (aPoint.IsInTextNode()) {
+ return GetNextWSNodeInner(aPoint.GetContainer(), aBlockParent);
}
- if (!mHTMLEditor->IsContainer(aPoint.Container())) {
- return GetNextWSNodeInner(aPoint.Container(), aBlockParent);
+ if (!mHTMLEditor->IsContainer(aPoint.GetContainer())) {
+ return GetNextWSNodeInner(aPoint.GetContainer(), aBlockParent);
}
- if (NS_WARN_IF(!aPoint.Container()->IsContent())) {
+ if (NS_WARN_IF(!aPoint.GetContainerAsContent())) {
return nullptr;
}
nsCOMPtr<nsIContent> nextNode = aPoint.GetChildAtOffset();
if (!nextNode) {
- if (aPoint.Container() == aBlockParent) {
+ if (aPoint.GetContainer() == aBlockParent) {
// We are at end of the block.
return nullptr;
}
// We are at end of non-block container
- return GetNextWSNodeInner(aPoint.Container(), aBlockParent);
+ return GetNextWSNodeInner(aPoint.GetContainer(), aBlockParent);
}
// We have a next node. If it's a block, return it.
if (IsBlockNode(nextNode)) {
return nextNode;
}
if (mHTMLEditor->IsContainer(nextNode)) {
// else if it's a container, get deep leftmost child
@@ -1320,58 +1320,58 @@ WSRunObject::DeleteRange(const EditorRaw
// MOOSE: this routine needs to be modified to preserve the integrity of the
// wsFragment info.
if (aStartPoint == aEndPoint) {
// Nothing to delete
return NS_OK;
}
- if (aStartPoint.Container() == aEndPoint.Container() &&
- aStartPoint.Container()->GetAsText()) {
- return mHTMLEditor->DeleteText(*aStartPoint.Container()->GetAsText(),
+ if (aStartPoint.GetContainer() == aEndPoint.GetContainer() &&
+ aStartPoint.IsInTextNode()) {
+ return mHTMLEditor->DeleteText(*aStartPoint.GetContainerAsText(),
aStartPoint.Offset(),
aEndPoint.Offset() - aStartPoint.Offset());
}
RefPtr<nsRange> range;
int32_t count = mNodeArray.Length();
- int32_t idx = mNodeArray.IndexOf(aStartPoint.Container());
+ int32_t idx = mNodeArray.IndexOf(aStartPoint.GetContainer());
if (idx == -1) {
// If our starting point wasn't one of our ws text nodes, then just go
// through them from the beginning.
idx = 0;
}
for (; idx < count; idx++) {
RefPtr<Text> node = mNodeArray[idx];
if (!node) {
// We ran out of ws nodes; must have been deleting to end
return NS_OK;
}
- if (node == aStartPoint.Container()) {
+ if (node == aStartPoint.GetContainer()) {
if (!aStartPoint.IsEndOfContainer()) {
nsresult rv =
mHTMLEditor->DeleteText(*node, aStartPoint.Offset(),
- aStartPoint.Container()->Length() -
+ aStartPoint.GetContainer()->Length() -
aStartPoint.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
- } else if (node == aEndPoint.Container()) {
+ } else if (node == aEndPoint.GetContainer()) {
if (!aEndPoint.IsStartOfContainer()) {
nsresult rv = mHTMLEditor->DeleteText(*node, 0, aEndPoint.Offset());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
break;
} else {
if (!range) {
- range = new nsRange(aStartPoint.Container());
+ range = new nsRange(aStartPoint.GetContainer());
nsresult rv = range->SetStartAndEnd(aStartPoint, aEndPoint);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
bool nodeBefore, nodeAfter;
nsresult rv =
nsRange::CompareNodeToRange(node, range, &nodeBefore, &nodeAfter);
@@ -1395,31 +1395,31 @@ WSRunObject::DeleteRange(const EditorRaw
return NS_OK;
}
WSRunObject::WSPoint
WSRunObject::GetNextCharPoint(const EditorRawDOMPoint& aPoint)
{
MOZ_ASSERT(aPoint.IsSetAndValid());
- int32_t idx = mNodeArray.IndexOf(aPoint.Container());
+ int32_t idx = mNodeArray.IndexOf(aPoint.GetContainer());
if (idx == -1) {
// Use range comparisons to get next text node which is in mNodeArray.
return GetNextCharPointInternal(aPoint);
}
// Use WSPoint version of GetNextCharPoint()
return GetNextCharPoint(WSPoint(mNodeArray[idx], aPoint.Offset(), 0));
}
WSRunObject::WSPoint
WSRunObject::GetPreviousCharPoint(const EditorRawDOMPoint& aPoint)
{
MOZ_ASSERT(aPoint.IsSetAndValid());
- int32_t idx = mNodeArray.IndexOf(aPoint.Container());
+ int32_t idx = mNodeArray.IndexOf(aPoint.GetContainer());
if (idx == -1) {
// Use range comparisons to get previous text node which is in mNodeArray.
return GetPreviousCharPointInternal(aPoint);
}
// Use WSPoint version of GetPreviousCharPoint()
return GetPreviousCharPoint(WSPoint(mNodeArray[idx], aPoint.Offset(), 0));
}
@@ -1636,17 +1636,17 @@ WSRunObject::GetCharAt(Text* aTextNode,
return 0;
}
return aTextNode->GetText()->CharAt(aOffset);
}
WSRunObject::WSPoint
WSRunObject::GetNextCharPointInternal(const EditorRawDOMPoint& aPoint)
{
- // Note: only to be called if aPoint.Container() is not a ws node.
+ // Note: only to be called if aPoint.GetContainer() is not a ws node.
// Binary search on wsnodes
uint32_t numNodes = mNodeArray.Length();
if (!numNodes) {
// Do nothing if there are no nodes to search
WSPoint outPoint;
return outPoint;