Bug 1413181 - part 6: Rename mozilla::EditorBase::EmptyContainers enum class to mozilla::SplitAtEdges for making its values clearer r=m_kato

EmptyContainers::yes and EmptyContainers::no are not so clear name what they
mean.

They means whether NodeSplitDeep() creates or won't create empty nodes when
split point is at start edge or end edge of an element.

This patch renames them to SplitAtEdges::eDoNotCreateEmptyContainer and
SplitAtEdges::eAllowToCreateEmptyContainer and make
HTMLEditor::InsertNodeAtPoint() use it instead of an bool argument.

Additionally, the argument of NodeSplitDeep() is now not optional because
this difference is really important when you read around the callers.

MozReview-Commit-ID: 9hpMRkVDvCg

--HG--
extra : rebase_source : ee892361d66c9c9c5ed45ee9d3321474257ac417
This commit is contained in:
Masayuki Nakano 2017-11-13 14:35:16 +09:00
Родитель d94b3f0152
Коммит bf54c638b2
7 изменённых файлов: 83 добавлений и 48 удалений

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

@ -4060,7 +4060,7 @@ int32_t
EditorBase::SplitNodeDeep(nsIContent& aNode,
nsIContent& aSplitPointParent,
int32_t aSplitPointOffset,
EmptyContainers aEmptyContainers,
SplitAtEdges aSplitAtEdges,
nsIContent** aOutLeftNode,
nsIContent** aOutRightNode,
nsCOMPtr<nsIContent>* ioChildAtSplitPointOffset)
@ -4079,7 +4079,7 @@ EditorBase::SplitNodeDeep(nsIContent& aNode,
bool didSplit = false;
if ((aEmptyContainers == EmptyContainers::yes &&
if ((aSplitAtEdges == SplitAtEdges::eAllowToCreateEmptyContainer &&
!nodeToSplit->GetAsText()) ||
(offset && offset != (int32_t)nodeToSplit->Length())) {
didSplit = true;

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

@ -209,6 +209,23 @@ private:
#define kMOZEditorBogusNodeAttrAtom nsGkAtoms::mozeditorbogusnode
#define kMOZEditorBogusNodeValue NS_LITERAL_STRING("TRUE")
/**
* SplitAtEdges is for EditorBase::SplitNodeDeep(),
* HTMLEditor::InsertNodeAtPoint()
*/
enum class SplitAtEdges
{
// EditorBase::SplitNodeDeep() won't split container element nodes at
// their edges. I.e., when split point is start or end of container,
// it won't be split.
eDoNotCreateEmptyContainer,
// EditorBase::SplitNodeDeep() always splits containers even if the split
// point is at edge of a container. E.g., if split point is start of an
// inline element, empty inline element is created as a new left node.
eAllowToCreateEmptyContainer
};
/**
* Implementation of an editor object. it will be the controller/focal point
* for the main editor services. i.e. the GUIManager, publishing, transaction
@ -1130,11 +1147,9 @@ public:
nsresult IsPreformatted(nsIDOMNode* aNode, bool* aResult);
enum class EmptyContainers { no, yes };
int32_t SplitNodeDeep(nsIContent& aNode, nsIContent& aSplitPointParent,
int32_t aSplitPointOffset,
EmptyContainers aEmptyContainers =
EmptyContainers::yes,
SplitAtEdges aSplitAtEdges,
nsIContent** outLeftNode = nullptr,
nsIContent** outRightNode = nullptr,
nsCOMPtr<nsIContent>* ioChildAtSplitPointOffset =

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

@ -1857,9 +1857,9 @@ HTMLEditRules::StandardBreakImpl(nsINode& aNode,
nsCOMPtr<Element> linkNode = do_QueryInterface(linkDOMNode);
NS_ENSURE_STATE(linkNode || !linkDOMNode);
nsCOMPtr<nsINode> linkParent = linkNode->GetParentNode();
aOffset = htmlEditor->SplitNodeDeep(*linkNode, *node->AsContent(),
aOffset,
HTMLEditor::EmptyContainers::no);
aOffset =
htmlEditor->SplitNodeDeep(*linkNode, *node->AsContent(), aOffset,
SplitAtEdges::eDoNotCreateEmptyContainer);
NS_ENSURE_STATE(aOffset != -1);
node = linkParent;
}
@ -1967,9 +1967,11 @@ HTMLEditRules::SplitMailCites(Selection* aSelection,
NS_ENSURE_STATE(mHTMLEditor);
NS_ENSURE_STATE(selNode->IsContent());
int32_t newOffset = mHTMLEditor->SplitNodeDeep(*citeNode,
*selNode->AsContent(), selOffset, HTMLEditor::EmptyContainers::no,
getter_AddRefs(leftCite), getter_AddRefs(rightCite));
int32_t newOffset =
mHTMLEditor->SplitNodeDeep(*citeNode, *selNode->AsContent(), selOffset,
SplitAtEdges::eDoNotCreateEmptyContainer,
getter_AddRefs(leftCite),
getter_AddRefs(rightCite));
NS_ENSURE_STATE(newOffset != -1);
// Add an invisible <br> to the end of the left part if it was a <span> of
@ -3840,9 +3842,9 @@ HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
NS_ENSURE_SUCCESS(rv, rv);
}
// Do the splits!
offset = htmlEditor->SplitNodeDeep(curBlock, *container->AsContent(),
offset,
HTMLEditor::EmptyContainers::no);
offset =
htmlEditor->SplitNodeDeep(curBlock, *container->AsContent(), offset,
SplitAtEdges::eDoNotCreateEmptyContainer);
NS_ENSURE_STATE(offset != -1);
// Put a br at the split point
brNode = htmlEditor->CreateBR(curBlock->GetParentNode(), offset);
@ -4716,7 +4718,7 @@ HTMLEditRules::SplitBlock(Element& aBlock,
// Do the splits!
nsCOMPtr<nsIContent> newMiddleNode1;
htmlEditor->SplitNodeDeep(aBlock, startParent, startOffset,
HTMLEditor::EmptyContainers::no,
SplitAtEdges::eDoNotCreateEmptyContainer,
aOutLeftNode, getter_AddRefs(newMiddleNode1));
// Get split point location
@ -4727,7 +4729,7 @@ HTMLEditRules::SplitBlock(Element& aBlock,
// Do the splits!
nsCOMPtr<nsIContent> newMiddleNode2;
htmlEditor->SplitNodeDeep(aBlock, endParent, endOffset,
HTMLEditor::EmptyContainers::no,
SplitAtEdges::eDoNotCreateEmptyContainer,
getter_AddRefs(newMiddleNode2), aOutRightNode);
if (aOutMiddleNode) {
@ -4851,7 +4853,9 @@ HTMLEditRules::CreateStyleForInsertText(Selection& aSelection,
if (RefPtr<Text> text = node->GetAsText()) {
// if we are in a text node, split it
NS_ENSURE_STATE(mHTMLEditor);
offset = mHTMLEditor->SplitNodeDeep(*text, *text, offset);
offset =
mHTMLEditor->SplitNodeDeep(*text, *text, offset,
SplitAtEdges::eAllowToCreateEmptyContainer);
NS_ENSURE_STATE(offset != -1);
node = node->GetParentNode();
}
@ -6406,7 +6410,7 @@ HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& item)
int32_t resultEndOffset =
mHTMLEditor->SplitNodeDeep(*endInline, *item.mEndContainer->AsContent(),
item.mEndOffset,
EditorBase::EmptyContainers::no);
SplitAtEdges::eDoNotCreateEmptyContainer);
NS_ENSURE_TRUE(resultEndOffset != -1, NS_ERROR_FAILURE);
// reset range
item.mEndContainer = resultEndNode;
@ -6423,7 +6427,7 @@ HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& item)
mHTMLEditor->SplitNodeDeep(*startInline,
*item.mStartContainer->AsContent(),
item.mStartOffset,
EditorBase::EmptyContainers::no);
SplitAtEdges::eDoNotCreateEmptyContainer);
NS_ENSURE_TRUE(resultStartOffset != -1, NS_ERROR_FAILURE);
// reset range
item.mStartContainer = resultStartNode;
@ -6467,7 +6471,7 @@ HTMLEditRules::BustUpInlinesAtBRs(
int32_t resultOffset =
htmlEditor->SplitNodeDeep(*splitDeepNode, splitParentNode, splitOffset,
HTMLEditor::EmptyContainers::yes,
SplitAtEdges::eAllowToCreateEmptyContainer,
getter_AddRefs(leftNode),
getter_AddRefs(rightNode));
NS_ENSURE_STATE(resultOffset != -1);
@ -6678,7 +6682,8 @@ HTMLEditRules::ReturnInHeader(Selection& aSelection,
// Split the header
NS_ENSURE_STATE(node->IsContent());
htmlEditor->SplitNodeDeep(aHeader, *node->AsContent(), aOffset);
htmlEditor->SplitNodeDeep(aHeader, *node->AsContent(), aOffset,
SplitAtEdges::eAllowToCreateEmptyContainer);
// If the left-hand heading is empty, put a mozbr in it
nsCOMPtr<nsIContent> prevItem = htmlEditor->GetPriorHTMLSibling(&aHeader);
@ -6897,7 +6902,7 @@ HTMLEditRules::SplitParagraph(Selection& aSelection,
NS_ENSURE_STATE(selNode->IsContent());
int32_t offset =
htmlEditor->SplitNodeDeep(aParentDivOrP, *selNode->AsContent(), selOffset,
HTMLEditor::EmptyContainers::yes,
SplitAtEdges::eAllowToCreateEmptyContainer,
getter_AddRefs(leftPara),
getter_AddRefs(rightPara));
if (NS_WARN_IF(offset == -1)) {
@ -7020,7 +7025,8 @@ HTMLEditRules::ReturnInListItem(Selection& aSelection,
NS_ENSURE_SUCCESS(rv, rv);
// Now split list item
NS_ENSURE_STATE(selNode->IsContent());
htmlEditor->SplitNodeDeep(aListItem, *selNode->AsContent(), aOffset);
htmlEditor->SplitNodeDeep(aListItem, *selNode->AsContent(), aOffset,
SplitAtEdges::eAllowToCreateEmptyContainer);
// Hack: until I can change the damaged doc range code back to being
// extra-inclusive, I have to manually detect certain list items that may be
@ -7452,12 +7458,11 @@ HTMLEditRules::SplitAsNeeded(nsAtom& aTag,
if (splitNode && splitNode->IsContent() && inOutParent->IsContent()) {
// We found a place for block, but above inOutParent. We need to split.
NS_ENSURE_STATE(mHTMLEditor);
int32_t offset = mHTMLEditor->SplitNodeDeep(*splitNode->AsContent(),
*inOutParent->AsContent(),
inOutOffset,
EditorBase::EmptyContainers::yes,
nullptr, nullptr,
inOutChildAtOffset);
int32_t offset =
mHTMLEditor->SplitNodeDeep(*splitNode->AsContent(),
*inOutParent->AsContent(), inOutOffset,
SplitAtEdges::eAllowToCreateEmptyContainer,
nullptr, nullptr, inOutChildAtOffset);
NS_ENSURE_STATE(offset != -1);
inOutParent = tagParent;
inOutOffset = offset;

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

@ -1522,7 +1522,8 @@ HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
&offsetForInsert);
rv = InsertNodeAtPoint(node, address_of(parentSelectedDOMNode),
&offsetForInsert, false);
&offsetForInsert,
SplitAtEdges::eAllowToCreateEmptyContainer);
NS_ENSURE_SUCCESS(rv, rv);
// Set caret after element, but check for special case
// of inserting table-related elements: set in first cell instead
@ -1564,14 +1565,14 @@ HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
* @param aNode Node to insert.
* @param ioParent Insertion parent.
* @param ioOffset Insertion offset.
* @param aNoEmptyNodes Splitting can result in empty nodes?
* @param aSplitAtEdges Splitting can result in empty nodes?
* @param ioChildAtOffset Child node at insertion offset (optional).
*/
nsresult
HTMLEditor::InsertNodeAtPoint(nsIDOMNode* aNode,
nsCOMPtr<nsIDOMNode>* ioParent,
int32_t* ioOffset,
bool aNoEmptyNodes,
SplitAtEdges aSplitAtEdges,
nsCOMPtr<nsIDOMNode>* ioChildAtOffset)
{
nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
@ -1624,8 +1625,7 @@ HTMLEditor::InsertNodeAtPoint(nsIDOMNode* aNode,
}
// we need to split some levels above the original selection parent
int32_t offset = SplitNodeDeep(*topChild, *origParent, *ioOffset,
aNoEmptyNodes ? EmptyContainers::no
: EmptyContainers::yes,
aSplitAtEdges,
nullptr, nullptr, address_of(child));
NS_ENSURE_STATE(offset != -1);
*ioParent = GetAsDOMNode(parent);
@ -2003,7 +2003,8 @@ HTMLEditor::MakeOrChangeList(const nsAString& aListType,
if (parent != node) {
// we need to split up to the child of parent
offset = SplitNodeDeep(*topChild, *node, offset,
EmptyContainers::yes, nullptr, nullptr,
SplitAtEdges::eAllowToCreateEmptyContainer,
nullptr, nullptr,
address_of(child));
NS_ENSURE_STATE(offset != -1);
}
@ -2148,7 +2149,8 @@ HTMLEditor::InsertBasicBlock(const nsAString& aBlockType)
if (parent != node) {
// we need to split up to the child of parent
offset = SplitNodeDeep(*topChild, *node, offset,
EmptyContainers::yes, nullptr, nullptr,
SplitAtEdges::eAllowToCreateEmptyContainer,
nullptr, nullptr,
address_of(child));
NS_ENSURE_STATE(offset != -1);
}
@ -2224,7 +2226,8 @@ HTMLEditor::Indent(const nsAString& aIndent)
if (parent != node) {
// we need to split up to the child of parent
offset = SplitNodeDeep(*topChild, *node, offset,
EmptyContainers::yes, nullptr, nullptr,
SplitAtEdges::eAllowToCreateEmptyContainer,
nullptr, nullptr,
address_of(child));
NS_ENSURE_STATE(offset != -1);
}

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

@ -341,7 +341,7 @@ public:
nsresult InsertNodeAtPoint(nsIDOMNode* aNode,
nsCOMPtr<nsIDOMNode>* ioParent,
int32_t* ioOffset,
bool aNoEmptyNodes,
SplitAtEdges aSplitAtEdges,
nsCOMPtr<nsIDOMNode>* ioChildAtOffset = nullptr);
/**

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

@ -358,8 +358,9 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
if (IsTextNode(parentNode)) {
nsCOMPtr<nsIContent> parentContent = do_QueryInterface(parentNode);
NS_ENSURE_STATE(parentContent || !parentNode);
offsetOfNewNode = SplitNodeDeep(*parentContent, *parentContent,
offsetOfNewNode);
offsetOfNewNode =
SplitNodeDeep(*parentContent, *parentContent, offsetOfNewNode,
SplitAtEdges::eAllowToCreateEmptyContainer);
NS_ENSURE_STATE(offsetOfNewNode != -1);
nsCOMPtr<nsIDOMNode> temp;
rv = parentNode->GetParentNode(getter_AddRefs(temp));
@ -446,7 +447,9 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
nsCOMPtr<nsIDOMNode> child;
curNode->GetFirstChild(getter_AddRefs(child));
while (child) {
rv = InsertNodeAtPoint(child, address_of(parentNode), &offsetOfNewNode, true);
rv = InsertNodeAtPoint(child, address_of(parentNode),
&offsetOfNewNode,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_FAILED(rv)) {
break;
}
@ -485,7 +488,9 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
}
}
}
rv = InsertNodeAtPoint(child, address_of(parentNode), &offsetOfNewNode, true);
rv = InsertNodeAtPoint(child, address_of(parentNode),
&offsetOfNewNode,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_FAILED(rv)) {
break;
}
@ -504,7 +509,9 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
nsCOMPtr<nsIDOMNode> child;
curNode->GetFirstChild(getter_AddRefs(child));
while (child) {
rv = InsertNodeAtPoint(child, address_of(parentNode), &offsetOfNewNode, true);
rv = InsertNodeAtPoint(child, address_of(parentNode),
&offsetOfNewNode,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_FAILED(rv)) {
break;
}
@ -519,7 +526,9 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
if (!bDidInsert || NS_FAILED(rv)) {
// try to insert
rv = InsertNodeAtPoint(curNode, address_of(parentNode), &offsetOfNewNode, true);
rv = InsertNodeAtPoint(curNode, address_of(parentNode),
&offsetOfNewNode,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_SUCCEEDED(rv)) {
bDidInsert = true;
lastInsertNode = curNode;
@ -531,7 +540,9 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
while (NS_FAILED(rv) && curNode) {
curNode->GetParentNode(getter_AddRefs(parent));
if (parent && !TextEditUtils::IsBody(parent)) {
rv = InsertNodeAtPoint(parent, address_of(parentNode), &offsetOfNewNode, true,
rv = InsertNodeAtPoint(parent, address_of(parentNode),
&offsetOfNewNode,
SplitAtEdges::eDoNotCreateEmptyContainer,
address_of(lastInsertNode));
if (NS_SUCCEEDED(rv)) {
bDidInsert = true;
@ -640,7 +651,8 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
NS_ENSURE_STATE(selContent || !selNode);
nsCOMPtr<nsIContent> leftLink;
SplitNodeDeep(*linkContent, *selContent, selOffset,
EmptyContainers::no, getter_AddRefs(leftLink));
SplitAtEdges::eDoNotCreateEmptyContainer,
getter_AddRefs(leftLink));
if (leftLink) {
EditorRawDOMPoint afterLeftLink(leftLink);
if (afterLeftLink.AdvanceOffset()) {

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

@ -554,8 +554,8 @@ HTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode,
isSet) {
// Found a style node we need to split
int32_t offset = SplitNodeDeep(*node, *(*aNode)->AsContent(), *aOffset,
EmptyContainers::yes, aOutLeftNode,
aOutRightNode);
SplitAtEdges::eAllowToCreateEmptyContainer,
aOutLeftNode, aOutRightNode);
NS_ENSURE_TRUE(offset != -1, NS_ERROR_FAILURE);
// reset startNode/startOffset
*aNode = node->GetParent();