diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 4930c446486..5e821a7c41e 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -4868,10 +4868,21 @@ nsHTMLEditor::IsEmptyNode( nsIDOMNode *aNode, bool aSafeToAskFrames) { nsCOMPtr node = do_QueryInterface(aNode); - NS_ENSURE_TRUE(node && outIsEmptyNode, NS_ERROR_NULL_POINTER); + return IsEmptyNode(node, outIsEmptyNode, aSingleBRDoesntCount, + aListOrCellNotEmpty, aSafeToAskFrames); +} + +nsresult +nsHTMLEditor::IsEmptyNode(nsINode* aNode, + bool* outIsEmptyNode, + bool aSingleBRDoesntCount, + bool aListOrCellNotEmpty, + bool aSafeToAskFrames) +{ + NS_ENSURE_TRUE(aNode && outIsEmptyNode, NS_ERROR_NULL_POINTER); *outIsEmptyNode = true; bool seenBR = false; - return IsEmptyNodeImpl(node, outIsEmptyNode, aSingleBRDoesntCount, + return IsEmptyNodeImpl(aNode, outIsEmptyNode, aSingleBRDoesntCount, aListOrCellNotEmpty, aSafeToAskFrames, &seenBR); } diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index d88248702b4..1b1362c06f7 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -395,6 +395,10 @@ public: bool aMozBRDoesntCount = false, bool aListOrCellNotEmpty = false, bool aSafeToAskFrames = false); + nsresult IsEmptyNode(nsINode* aNode, bool* outIsEmptyBlock, + bool aMozBRDoesntCount = false, + bool aListOrCellNotEmpty = false, + bool aSafeToAskFrames = false); nsresult IsEmptyNodeImpl(nsINode* aNode, bool *outIsEmptyBlock, bool aMozBRDoesntCount, diff --git a/editor/libeditor/html/nsTableEditor.cpp b/editor/libeditor/html/nsTableEditor.cpp index a724b9bb452..eadacc0f2c8 100644 --- a/editor/libeditor/html/nsTableEditor.cpp +++ b/editor/libeditor/html/nsTableEditor.cpp @@ -62,7 +62,9 @@ #include "nsHTMLEditUtils.h" #include "nsLayoutErrors.h" +#include "mozilla/dom/Element.h" +using namespace mozilla; /*************************************************************************** * stack based helper class for restoring selection after table edit @@ -3441,31 +3443,28 @@ nsHTMLEditor::AllCellsInColumnSelected(nsIDOMElement *aTable, PRInt32 aColIndex, bool nsHTMLEditor::IsEmptyCell(nsIDOMElement *aCell) { - nsCOMPtr cellChild; + nsCOMPtr cell = do_QueryInterface(aCell); // Check if target only contains empty text node or
- nsresult res = aCell->GetFirstChild(getter_AddRefs(cellChild)); - NS_ENSURE_SUCCESS(res, false); - - if (cellChild) - { - nsCOMPtr nextChild; - res = cellChild->GetNextSibling(getter_AddRefs(nextChild)); - NS_ENSURE_SUCCESS(res, false); - if (!nextChild) - { - // We insert a single break into a cell by default - // to have some place to locate a cursor -- it is dispensable - bool isEmpty = nsTextEditUtils::IsBreak(cellChild); - // Or check if no real content - if (!isEmpty) - { - res = IsEmptyNode(cellChild, &isEmpty, false, false); - NS_ENSURE_SUCCESS(res, false); - } - - return isEmpty; - } + nsCOMPtr cellChild = cell->GetFirstChild(); + if (!cellChild) { + return false; } - return false; + + nsCOMPtr nextChild = cellChild->GetNextSibling(); + if (nextChild) { + return false; + } + + // We insert a single break into a cell by default + // to have some place to locate a cursor -- it is dispensable + if (cellChild->IsElement() && cellChild->AsElement()->IsHTML(nsGkAtoms::br)) { + return true; + } + + bool isEmpty; + // Or check if no real content + nsresult rv = IsEmptyNode(cellChild, &isEmpty, false, false); + NS_ENSURE_SUCCESS(rv, false); + return isEmpty; }