Skip to content

Commit

Permalink
Bug 1003808 part 2 - Clean up nsEditorUtils::IsDescendantOf; r=ehsan
Browse files Browse the repository at this point in the history
  • Loading branch information
ayg committed Apr 28, 2014
1 parent f55311b commit 8344d42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
47 changes: 22 additions & 25 deletions editor/libeditor/base/nsEditorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,38 +138,35 @@ nsDOMSubtreeIterator::Init(nsIDOMRange* aRange)
* some general purpose editor utils
*****************************************************************************/

bool
nsEditorUtils::IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t *aOffset)
bool
nsEditorUtils::IsDescendantOf(nsINode* aNode, nsINode* aParent, int32_t* aOffset)
{
NS_ENSURE_TRUE(aNode || aParent, false);
if (aNode == aParent) return false;

nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(aNode);
nsresult res;

do
{
res = node->GetParentNode(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(res, false);
if (parent == aParent)
{
if (aOffset)
{
nsCOMPtr<nsIContent> pCon(do_QueryInterface(parent));
nsCOMPtr<nsIContent> cCon(do_QueryInterface(node));
if (pCon)
{
*aOffset = pCon->IndexOf(cCon);
}
MOZ_ASSERT(aNode && aParent);
if (aNode == aParent) {
return false;
}

for (nsCOMPtr<nsINode> node = aNode; node; node = node->GetParentNode()) {
if (node->GetParentNode() == aParent) {
if (aOffset) {
*aOffset = aParent->IndexOf(node);
}
return true;
}
node = parent;
} while (parent);

}

return false;
}

bool
nsEditorUtils::IsDescendantOf(nsIDOMNode* aNode, nsIDOMNode* aParent, int32_t* aOffset)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
NS_ENSURE_TRUE(node && parent, false);
return IsDescendantOf(node, parent, aOffset);
}

bool
nsEditorUtils::IsLeafNode(nsIDOMNode *aNode)
{
Expand Down
1 change: 1 addition & 0 deletions editor/libeditor/base/nsEditorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ struct MOZ_STACK_CLASS DOMPoint
class nsEditorUtils
{
public:
static bool IsDescendantOf(nsINode* aNode, nsINode* aParent, int32_t* aOffset = 0);
static bool IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t *aOffset = 0);
static bool IsLeafNode(nsIDOMNode *aNode);
};
Expand Down

0 comments on commit 8344d42

Please sign in to comment.