Bug 1451672 - part 15: Rename EditorBase::RemoveContainer() and HTMLEditor::RemoveBlockContainer() with "WithTransaction" postfix and make their argument |Element&| r=m_kato

MozReview-Commit-ID: 2toj48mqHM9

--HG--
extra : rebase_source : 621cb7a3137137dab45c311836b8304e7bd772f2
This commit is contained in:
Masayuki Nakano 2018-04-12 22:23:04 +09:00
Родитель b7fe9939db
Коммит 71964e6004
8 изменённых файлов: 81 добавлений и 58 удалений

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

@ -583,7 +583,7 @@ CSSEditUtils::RemoveCSSInlineStyle(nsINode& aNode,
return NS_OK;
}
return mHTMLEditor->RemoveContainer(element);
return mHTMLEditor->RemoveContainerWithTransaction(*element);
}
// Answers true if the property can be removed by setting a "none" CSS value

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

@ -1728,29 +1728,23 @@ EditorBase::ReplaceContainerWithTransactionInternal(
return newContainer.forget();
}
/**
* RemoveContainer() removes inNode, reparenting its children (if any) into the
* parent of inNode.
*/
nsresult
EditorBase::RemoveContainer(nsIContent* aNode)
EditorBase::RemoveContainerWithTransaction(Element& aElement)
{
MOZ_ASSERT(aNode);
EditorDOMPoint pointToInsertChildren(aNode);
EditorDOMPoint pointToInsertChildren(&aElement);
if (NS_WARN_IF(!pointToInsertChildren.IsSet())) {
return NS_ERROR_FAILURE;
}
// Notify our internal selection state listener.
AutoRemoveContainerSelNotify selNotify(mRangeUpdater, aNode,
AutoRemoveContainerSelNotify selNotify(mRangeUpdater, &aElement,
pointToInsertChildren.GetContainer(),
pointToInsertChildren.Offset(),
aNode->GetChildCount());
aElement.GetChildCount());
// Move all children from aNode to its parent.
while (aNode->HasChildren()) {
nsCOMPtr<nsIContent> child = aNode->GetLastChild();
while (aElement.HasChildren()) {
nsCOMPtr<nsIContent> child = aElement.GetLastChild();
if (NS_WARN_IF(!child)) {
return NS_ERROR_FAILURE;
}
@ -1771,7 +1765,7 @@ EditorBase::RemoveContainer(nsIContent* aNode)
}
}
nsresult rv = DeleteNodeWithTransaction(*aNode);
nsresult rv = DeleteNodeWithTransaction(aElement);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -427,7 +427,14 @@ public:
void CloneAttributes(Element* aDest, Element* aSource);
nsresult RemoveContainer(nsIContent* aNode);
/**
* RemoveContainerWithTransaction() removes aElement from the DOM tree and
* moves all its children to the parent of aElement.
*
* @param aElement The element to be removed.
*/
nsresult RemoveContainerWithTransaction(Element& aElement);
already_AddRefed<Element> InsertContainerAbove(nsIContent* aNode,
nsAtom* aNodeType,
nsAtom* aAttribute = nullptr,

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

@ -528,7 +528,7 @@ HTMLEditor::SetPositionToStatic(Element& aElement)
NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
nsresult rv = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement);
NS_ENSURE_SUCCESS(rv, rv);
rv = RemoveContainer(&aElement);
rv = RemoveContainerWithTransaction(aElement);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;

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

@ -3707,7 +3707,7 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
for (uint32_t i = 0; i < listCount; i++) {
// here's where we actually figure out what to do
nsCOMPtr<Element> newBlock;
RefPtr<Element> newBlock;
NS_ENSURE_STATE(arrayOfNodes[i]->IsContent());
OwningNonNull<nsIContent> curNode = *arrayOfNodes[i]->AsContent();
@ -3734,16 +3734,16 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
// do we have a curList already?
if (curList && !EditorUtils::IsDescendantOf(*curNode, *curList)) {
// move all of our children into curList. cheezy way to do it: move
// whole list and then RemoveContainer() on the list. ConvertListType
// first: that routine handles converting the list item types, if
// needed
// whole list and then RemoveContainerWithTransaction() on the list.
// ConvertListType first: that routine handles converting the list
// item types, if needed.
rv = htmlEditor->MoveNode(curNode, curList, -1);
NS_ENSURE_SUCCESS(rv, rv);
newBlock = ConvertListType(curNode->AsElement(), listType, itemType);
if (NS_WARN_IF(!newBlock)) {
return NS_ERROR_FAILURE;
}
rv = htmlEditor->RemoveBlockContainer(*newBlock);
rv = htmlEditor->RemoveBlockContainerWithTransaction(*newBlock);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// replace list with new list type
@ -3841,7 +3841,7 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
prevListItem = nullptr;
int32_t j = i + 1;
GetInnerContent(*curNode, arrayOfNodes, &j);
rv = htmlEditor->RemoveContainer(curNode);
rv = htmlEditor->RemoveContainerWithTransaction(*curNode->AsElement());
NS_ENSURE_SUCCESS(rv, rv);
listCount = arrayOfNodes.Length();
continue;
@ -4725,8 +4725,11 @@ HTMLEditRules::WillOutdent(Selection& aSelection,
lastBQChild = nullptr;
curBlockQuoteIsIndentedWithCSS = false;
}
rv = htmlEditor->RemoveBlockContainer(curNode);
NS_ENSURE_SUCCESS(rv, rv);
rv = htmlEditor->RemoveBlockContainerWithTransaction(
*curNode->AsElement());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
continue;
}
// Is it a block with a 'margin' property?
@ -4828,8 +4831,11 @@ HTMLEditRules::WillOutdent(Selection& aSelection,
// Move node out of list
if (HTMLEditUtils::IsList(curNode)) {
// Just unwrap this sublist
rv = htmlEditor->RemoveBlockContainer(curNode);
NS_ENSURE_SUCCESS(rv, rv);
rv = htmlEditor->RemoveBlockContainerWithTransaction(
*curNode->AsElement());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// handled list item case above
} else if (HTMLEditUtils::IsList(curNode)) {
@ -4856,8 +4862,11 @@ HTMLEditRules::WillOutdent(Selection& aSelection,
child = curNode->GetLastChild();
}
// Delete the now-empty list
rv = htmlEditor->RemoveBlockContainer(curNode);
NS_ENSURE_SUCCESS(rv, rv);
rv = htmlEditor->RemoveBlockContainerWithTransaction(
*curNode->AsElement());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else if (useCSS) {
nsCOMPtr<Element> element;
if (curNode->GetAsText()) {
@ -4926,7 +4935,7 @@ HTMLEditRules::RemovePartOfBlock(Element& aBlock,
// Get rid of part of blockquote we are outdenting
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv = mHTMLEditor->RemoveBlockContainer(aBlock);
nsresult rv = mHTMLEditor->RemoveBlockContainerWithTransaction(aBlock);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -4997,11 +5006,15 @@ HTMLEditRules::OutdentPartOfBlock(Element& aBlock,
SplitBlock(aBlock, aStartChild, aEndChild, aOutLeftNode, aOutRightNode,
getter_AddRefs(middleNode));
NS_ENSURE_STATE(middleNode);
if (NS_WARN_IF(!middleNode) || NS_WARN_IF(!middleNode->IsElement())) {
return NS_ERROR_FAILURE;
}
if (!aIsBlockIndentedWithCSS) {
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv = mHTMLEditor->RemoveBlockContainer(*middleNode);
nsresult rv =
mHTMLEditor->RemoveBlockContainerWithTransaction(
*middleNode->AsElement());
NS_ENSURE_SUCCESS(rv, rv);
} else if (middleNode->IsElement()) {
// We do nothing if middleNode isn't an element
@ -7653,7 +7666,8 @@ HTMLEditRules::RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray)
continue;
}
// Remove current block
nsresult rv = htmlEditor->RemoveBlockContainer(*curNode->AsContent());
nsresult rv =
htmlEditor->RemoveBlockContainerWithTransaction(*curNode->AsElement());
NS_ENSURE_SUCCESS(rv, rv);
} else if (curNode->IsAnyOfHTMLElements(nsGkAtoms::table,
nsGkAtoms::tr,
@ -8886,7 +8900,8 @@ HTMLEditRules::PopListItem(nsIContent& aListItem,
if (!HTMLEditUtils::IsList(pointToInsertListItem.GetContainer()) &&
HTMLEditUtils::IsListItem(&aListItem)) {
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->RemoveBlockContainer(*aListItem.AsElement());
rv = mHTMLEditor->RemoveBlockContainerWithTransaction(
*aListItem.AsElement());
NS_ENSURE_SUCCESS(rv, rv);
if (aOutOfList) {
*aOutOfList = true;
@ -8923,7 +8938,7 @@ HTMLEditRules::RemoveListStructure(Element& aList)
}
// Delete the now-empty list
nsresult rv = htmlEditor->RemoveBlockContainer(aList);
nsresult rv = htmlEditor->RemoveBlockContainerWithTransaction(aList);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -9275,7 +9290,7 @@ HTMLEditRules::RemoveAlignment(nsINode& aNode,
// now remove the CENTER container
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->RemoveContainer(child->AsElement());
rv = mHTMLEditor->RemoveContainerWithTransaction(*child->AsElement());
NS_ENSURE_SUCCESS(rv, rv);
} else if (IsBlockNode(*child) || child->IsHTMLElement(nsGkAtoms::hr)) {
// the current node is a block element
@ -9471,7 +9486,7 @@ HTMLEditRules::ChangeIndentation(Element& aElement,
return NS_OK;
}
nsresult rv = htmlEditor->RemoveContainer(&aElement);
nsresult rv = htmlEditor->RemoveContainerWithTransaction(aElement);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

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

@ -3742,7 +3742,7 @@ HTMLEditor::SetSelectionAtDocumentStart(Selection* aSelection)
* addition, insert any br's needed to preserve identity of removed block.
*/
nsresult
HTMLEditor::RemoveBlockContainer(nsIContent& aNode)
HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement)
{
// Two possibilities: the container could be empty of editable content. If
// that is the case, we need to compare what is before and after aNode to
@ -3752,7 +3752,7 @@ HTMLEditor::RemoveBlockContainer(nsIContent& aNode)
// sibling and first child to determine if we need a leading br, and compare
// following sibling and last child to determine if we need a trailing br.
nsCOMPtr<nsIContent> child = GetFirstEditableChild(aNode);
nsCOMPtr<nsIContent> child = GetFirstEditableChild(aElement);
if (child) {
// The case of aNode not being empty. We need a br at start unless:
@ -3761,11 +3761,11 @@ HTMLEditor::RemoveBlockContainer(nsIContent& aNode)
// 3) first child of aNode is a block OR
// 4) either is null
nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(&aNode);
nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(&aElement);
if (sibling && !IsBlockNode(sibling) &&
!sibling->IsHTMLElement(nsGkAtoms::br) && !IsBlockNode(child)) {
// Insert br node
RefPtr<Element> brElement = CreateBR(EditorRawDOMPoint(&aNode, 0));
RefPtr<Element> brElement = CreateBR(EditorRawDOMPoint(&aElement, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -3777,14 +3777,14 @@ HTMLEditor::RemoveBlockContainer(nsIContent& aNode)
// 3) last child of aNode is a br OR
// 4) either is null
sibling = GetNextHTMLSibling(&aNode);
sibling = GetNextHTMLSibling(&aElement);
if (sibling && !IsBlockNode(sibling)) {
child = GetLastEditableChild(aNode);
child = GetLastEditableChild(aElement);
MOZ_ASSERT(child, "aNode has first editable child but not last?");
if (!IsBlockNode(child) && !child->IsHTMLElement(nsGkAtoms::br)) {
// Insert br node
EditorRawDOMPoint endOfNode;
endOfNode.SetToEndOf(&aNode);
endOfNode.SetToEndOf(&aElement);
RefPtr<Element> brElement = CreateBR(endOfNode);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
@ -3798,14 +3798,14 @@ HTMLEditor::RemoveBlockContainer(nsIContent& aNode)
// 3) following sibling of aNode is a block, OR
// 4) following sibling of aNode is a br OR
// 5) either is null
nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(&aNode);
nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(&aElement);
if (sibling && !IsBlockNode(sibling) &&
!sibling->IsHTMLElement(nsGkAtoms::br)) {
sibling = GetNextHTMLSibling(&aNode);
sibling = GetNextHTMLSibling(&aElement);
if (sibling && !IsBlockNode(sibling) &&
!sibling->IsHTMLElement(nsGkAtoms::br)) {
// Insert br node
RefPtr<Element> brElement = CreateBR(EditorRawDOMPoint(&aNode, 0));
RefPtr<Element> brElement = CreateBR(EditorRawDOMPoint(&aElement, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -3814,9 +3814,10 @@ HTMLEditor::RemoveBlockContainer(nsIContent& aNode)
}
// Now remove container
nsresult rv = RemoveContainer(&aNode);
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv = RemoveContainerWithTransaction(aElement);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}

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

@ -946,7 +946,15 @@ protected:
bool IsAtEndOfNode(nsINode& aNode, int32_t aOffset);
bool IsOnlyAttribute(const Element* aElement, nsAtom* aAttribute);
nsresult RemoveBlockContainer(nsIContent& aNode);
/**
* RemoveBlockContainerWithTransaction() removes aElement from the DOM tree
* but moves its all children to its parent node and if its parent needs <br>
* element to have at least one line-height, this inserts <br> element
* automatically.
*
* @param aElement Block element to be removed.
*/
nsresult RemoveBlockContainerWithTransaction(Element& aElement);
nsIContent* GetPriorHTMLSibling(nsINode* aNode);

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

@ -689,7 +689,7 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
nsAtom* aAttribute,
const bool aChildrenOnly /* = false */)
{
if (aNode.GetAsText()) {
if (!aNode.IsElement()) {
return NS_OK;
}
@ -717,10 +717,8 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
// remove any matching inlinestyles entirely
if (!aAttribute) {
bool hasStyleAttr =
aNode.IsElement() &&
aNode.AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::style);
bool hasClassAttr =
aNode.IsElement() &&
aNode.AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::_class);
if (aProperty && (hasStyleAttr || hasClassAttr)) {
// aNode carries inline styles or a class attribute so we can't
@ -744,7 +742,7 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
return rv;
}
}
nsresult rv = RemoveContainer(&aNode);
nsresult rv = RemoveContainerWithTransaction(*aNode.AsElement());
NS_ENSURE_SUCCESS(rv, rv);
} else if (aNode.IsElement()) {
// otherwise we just want to eliminate the attribute
@ -752,7 +750,7 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
// if this matching attribute is the ONLY one on the node,
// then remove the whole node. Otherwise just nix the attribute.
if (IsOnlyAttribute(aNode.AsElement(), aAttribute)) {
nsresult rv = RemoveContainer(&aNode);
nsresult rv = RemoveContainerWithTransaction(*aNode.AsElement());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -802,7 +800,7 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
aNode.IsHTMLElement(nsGkAtoms::small)) &&
aAttribute == nsGkAtoms::size) {
// if we are setting font size, remove any nested bigs and smalls
return RemoveContainer(&aNode);
return RemoveContainerWithTransaction(*aNode.AsElement());
}
return NS_OK;
}
@ -1600,7 +1598,7 @@ HTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange,
nsresult rv = RelativeFontChangeHelper(aSizeChange, aNode);
NS_ENSURE_SUCCESS(rv, rv);
// in that case, just remove this node and pull up the children
return RemoveContainer(aNode);
return RemoveContainerWithTransaction(*aNode->AsElement());
}
// can it be put inside a "big" or "small"?
@ -1763,7 +1761,7 @@ HTMLEditor::RemoveElementIfNoStyleOrIdOrClass(Element& aElement)
return NS_OK;
}
return RemoveContainer(&aElement);
return RemoveContainerWithTransaction(aElement);
}
} // namespace mozilla