Bug 1190172 part 11 - Clean up nsHTMLEditRules::IsEmptyBlock; r=ehsan

--HG--
extra : rebase_source : 43174f4b1874d3ada612683d9c33cc4280e864d8
This commit is contained in:
Aryeh Gregor 2016-04-19 06:56:00 +02:00
Родитель b8c3a7a9ba
Коммит f88d4daee6
2 изменённых файлов: 21 добавлений и 26 удалений

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

@ -1556,7 +1556,7 @@ nsHTMLEditRules::WillInsertBreak(Selection& aSelection, bool* aCancel,
// "Text" is deleted leaving an empty block. We want to put in one br to // "Text" is deleted leaving an empty block. We want to put in one br to
// make block have a line. Then code further below will put in a second br.) // make block have a line. Then code further below will put in a second br.)
bool isEmpty; bool isEmpty;
IsEmptyBlock(GetAsDOMNode(blockParent), &isEmpty); IsEmptyBlock(*blockParent, &isEmpty);
if (isEmpty) { if (isEmpty) {
nsCOMPtr<Element> br = mHTMLEditor->CreateBR(blockParent, nsCOMPtr<Element> br = mHTMLEditor->CreateBR(blockParent,
blockParent->Length()); blockParent->Length());
@ -4489,29 +4489,24 @@ nsHTMLEditRules::CreateStyleForInsertText(Selection& aSelection,
} }
/////////////////////////////////////////////////////////////////////////// /**
// IsEmptyBlock: figure out if aNode is (or is inside) an empty block. * Figure out if aNode is (or is inside) an empty block. A block can have
// A block can have children and still be considered empty, * children and still be considered empty, if the children are empty or
// if the children are empty or non-editable. * non-editable.
// */
nsresult nsresult
nsHTMLEditRules::IsEmptyBlock(nsIDOMNode *aNode, nsHTMLEditRules::IsEmptyBlock(Element& aNode,
bool *outIsEmptyBlock, bool* aOutIsEmptyBlock,
bool aMozBRDoesntCount, MozBRCounts aMozBRCounts)
bool aListItemsNotEmpty)
{ {
NS_ENSURE_TRUE(aNode && outIsEmptyBlock, NS_ERROR_NULL_POINTER); MOZ_ASSERT(aOutIsEmptyBlock);
*outIsEmptyBlock = true; *aOutIsEmptyBlock = true;
// nsresult res = NS_OK; NS_ENSURE_TRUE(IsBlockNode(aNode.AsDOMNode()), NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMNode> nodeToTest;
if (IsBlockNode(aNode)) nodeToTest = do_QueryInterface(aNode);
// else nsCOMPtr<nsIDOMElement> block;
// looks like I forgot to finish this. Wonder what I was going to do?
NS_ENSURE_TRUE(nodeToTest, NS_ERROR_NULL_POINTER); return mHTMLEditor->IsEmptyNode(aNode.AsDOMNode(), aOutIsEmptyBlock,
return mHTMLEditor->IsEmptyNode(nodeToTest, outIsEmptyBlock, aMozBRCounts == MozBRCounts::yes ? false
aMozBRDoesntCount, aListItemsNotEmpty); : true);
} }
@ -6289,7 +6284,7 @@ nsHTMLEditRules::ReturnInHeader(Selection& aSelection,
// If the new (righthand) header node is empty, delete it // If the new (righthand) header node is empty, delete it
bool isEmpty; bool isEmpty;
res = IsEmptyBlock(aHeader.AsDOMNode(), &isEmpty, true); res = IsEmptyBlock(aHeader, &isEmpty, MozBRCounts::no);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
if (isEmpty) { if (isEmpty) {
res = mHTMLEditor->DeleteNode(&aHeader); res = mHTMLEditor->DeleteNode(&aHeader);
@ -6542,7 +6537,7 @@ nsHTMLEditRules::ReturnInListItem(Selection& aSelection,
// only if prefs say it's okay and if the parent isn't the active editing // only if prefs say it's okay and if the parent isn't the active editing
// host. // host.
bool isEmpty; bool isEmpty;
nsresult res = IsEmptyBlock(aListItem.AsDOMNode(), &isEmpty, true, false); nsresult res = IsEmptyBlock(aListItem, &isEmpty, MozBRCounts::no);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
if (isEmpty && root != list && mReturnInEmptyLIKillsList) { if (isEmpty && root != list && mReturnInEmptyLIKillsList) {
// Get the list offset now -- before we might eventually split the list // Get the list offset now -- before we might eventually split the list

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

@ -248,10 +248,10 @@ protected:
nsresult CreateStyleForInsertText(mozilla::dom::Selection& aSelection, nsresult CreateStyleForInsertText(mozilla::dom::Selection& aSelection,
nsIDocument& aDoc); nsIDocument& aDoc);
nsresult IsEmptyBlock(nsIDOMNode *aNode, enum class MozBRCounts { yes, no };
bool *outIsEmptyBlock, nsresult IsEmptyBlock(mozilla::dom::Element& aNode,
bool aMozBRDoesntCount = false, bool* aOutIsEmptyBlock,
bool aListItemsNotEmpty = false); MozBRCounts aMozBRCounts = MozBRCounts::yes);
nsresult CheckForEmptyBlock(nsINode* aStartNode, nsresult CheckForEmptyBlock(nsINode* aStartNode,
mozilla::dom::Element* aBodyNode, mozilla::dom::Element* aBodyNode,
mozilla::dom::Selection* aSelection, mozilla::dom::Selection* aSelection,