Skip to content

Commit

Permalink
Bug 718170 - Part c: Use nsINode in IsEmptyCell; r=ehsan
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Jan 25, 2012
1 parent 0ee0b0b commit b4f8648
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
15 changes: 13 additions & 2 deletions editor/libeditor/html/nsHTMLEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4868,10 +4868,21 @@ nsHTMLEditor::IsEmptyNode( nsIDOMNode *aNode,
bool aSafeToAskFrames)
{
nsCOMPtr<nsINode> 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);
}

Expand Down
4 changes: 4 additions & 0 deletions editor/libeditor/html/nsHTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ class nsHTMLEditor : public nsPlaintextEditor,
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,
Expand Down
43 changes: 21 additions & 22 deletions editor/libeditor/html/nsTableEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3441,31 +3443,28 @@ nsHTMLEditor::AllCellsInColumnSelected(nsIDOMElement *aTable, PRInt32 aColIndex,
bool
nsHTMLEditor::IsEmptyCell(nsIDOMElement *aCell)
{
nsCOMPtr<nsIDOMNode> cellChild;
nsCOMPtr<dom::Element> cell = do_QueryInterface(aCell);

// Check if target only contains empty text node or <br>
nsresult res = aCell->GetFirstChild(getter_AddRefs(cellChild));
NS_ENSURE_SUCCESS(res, false);
nsCOMPtr<nsINode> cellChild = cell->GetFirstChild();
if (!cellChild) {
return false;
}

if (cellChild)
{
nsCOMPtr<nsIDOMNode> 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);
}
nsCOMPtr<nsINode> nextChild = cellChild->GetNextSibling();
if (nextChild) {
return false;
}

return isEmpty;
}
// 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;
}
return false;

bool isEmpty;
// Or check if no real content
nsresult rv = IsEmptyNode(cellChild, &isEmpty, false, false);
NS_ENSURE_SUCCESS(rv, false);
return isEmpty;
}

0 comments on commit b4f8648

Please sign in to comment.