зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1455676 part 7. Remove nsIDOMNode usage from layout/inspector/. r=qdot
This commit is contained in:
Родитель
0a370c0291
Коммит
54fad5efa0
|
@ -85,7 +85,7 @@ inDeepTreeWalker::SetShowDocumentsAsNodes(bool aShowDocumentsAsNodes)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::Init(nsIDOMNode* aRoot, uint32_t aWhatToShow)
|
||||
inDeepTreeWalker::Init(nsINode* aRoot, uint32_t aWhatToShow)
|
||||
{
|
||||
if (!aRoot) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
@ -101,7 +101,7 @@ inDeepTreeWalker::Init(nsIDOMNode* aRoot, uint32_t aWhatToShow)
|
|||
////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::GetRoot(nsIDOMNode** aRoot)
|
||||
inDeepTreeWalker::GetRoot(nsINode** aRoot)
|
||||
{
|
||||
*aRoot = mRoot;
|
||||
NS_IF_ADDREF(*aRoot);
|
||||
|
@ -116,14 +116,14 @@ inDeepTreeWalker::GetWhatToShow(uint32_t* aWhatToShow)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::GetCurrentNode(nsIDOMNode** aCurrentNode)
|
||||
inDeepTreeWalker::GetCurrentNode(nsINode** aCurrentNode)
|
||||
{
|
||||
*aCurrentNode = mCurrentNode;
|
||||
NS_IF_ADDREF(*aCurrentNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDOMNode>
|
||||
already_AddRefed<nsINode>
|
||||
inDeepTreeWalker::GetParent()
|
||||
{
|
||||
MOZ_ASSERT(mCurrentNode);
|
||||
|
@ -132,12 +132,8 @@ inDeepTreeWalker::GetParent()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> currentNode = do_QueryInterface(mCurrentNode);
|
||||
nsCOMPtr<nsINode> root = do_QueryInterface(mRoot);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
nsINode* parentNode =
|
||||
InspectorUtils::GetParentForNode(*currentNode, mShowAnonymousContent);
|
||||
InspectorUtils::GetParentForNode(*mCurrentNode, mShowAnonymousContent);
|
||||
|
||||
uint16_t nodeType = 0;
|
||||
if (parentNode) {
|
||||
|
@ -147,17 +143,16 @@ inDeepTreeWalker::GetParent()
|
|||
// from the walk.
|
||||
if (!mShowDocumentsAsNodes &&
|
||||
nodeType == nsINode::DOCUMENT_NODE &&
|
||||
parentNode != root) {
|
||||
parentNode != mRoot) {
|
||||
parentNode =
|
||||
InspectorUtils::GetParentForNode(*parentNode, mShowAnonymousContent);
|
||||
}
|
||||
|
||||
parent = do_QueryInterface(parentNode);
|
||||
return parent.forget();
|
||||
return do_AddRef(parentNode);
|
||||
}
|
||||
|
||||
static already_AddRefed<nsINodeList>
|
||||
GetChildren(nsIDOMNode* aParent,
|
||||
GetChildren(nsINode* aParent,
|
||||
bool aShowAnonymousContent,
|
||||
bool aShowSubDocuments)
|
||||
{
|
||||
|
@ -165,8 +160,7 @@ GetChildren(nsIDOMNode* aParent,
|
|||
|
||||
nsCOMPtr<nsINodeList> ret;
|
||||
if (aShowSubDocuments) {
|
||||
nsCOMPtr<nsIDOMNode> domdoc =
|
||||
do_QueryInterface(inLayoutUtils::GetSubDocumentFor(aParent));
|
||||
nsIDocument* domdoc = inLayoutUtils::GetSubDocumentFor(aParent);
|
||||
if (domdoc) {
|
||||
aParent = domdoc;
|
||||
}
|
||||
|
@ -179,15 +173,13 @@ GetChildren(nsIDOMNode* aParent,
|
|||
// If it's not a content, then it's a document (or an attribute but we can ignore that
|
||||
// case here). If aShowAnonymousContent is false we also want to fall back to ChildNodes
|
||||
// so we can skip any native anon content that GetChildren would return.
|
||||
nsCOMPtr<nsINode> parentNode = do_QueryInterface(aParent);
|
||||
MOZ_ASSERT(parentNode);
|
||||
ret = parentNode->ChildNodes();
|
||||
ret = aParent->ChildNodes();
|
||||
}
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode)
|
||||
inDeepTreeWalker::SetCurrentNode(nsINode* aCurrentNode)
|
||||
{
|
||||
// mCurrentNode can only be null if init either failed, or has not been
|
||||
// called yet.
|
||||
|
@ -198,8 +190,7 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode)
|
|||
// If Document nodes are skipped by the walk, we should not allow
|
||||
// one to set one as the current node either.
|
||||
if (!mShowDocumentsAsNodes) {
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aCurrentNode);
|
||||
if (node->NodeType() == nsINode::DOCUMENT_NODE) {
|
||||
if (aCurrentNode->NodeType() == nsINode::DOCUMENT_NODE) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +200,7 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode)
|
|||
|
||||
|
||||
nsresult
|
||||
inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode,
|
||||
inDeepTreeWalker::SetCurrentNode(nsINode* aCurrentNode,
|
||||
nsINodeList* aSiblings)
|
||||
{
|
||||
MOZ_ASSERT(aCurrentNode);
|
||||
|
@ -217,7 +208,7 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode,
|
|||
// We want to store the original state so in case of error
|
||||
// we can restore that.
|
||||
nsCOMPtr<nsINodeList> tmpSiblings = mSiblings;
|
||||
nsCOMPtr<nsIDOMNode> tmpCurrent = mCurrentNode;
|
||||
nsCOMPtr<nsINode> tmpCurrent = mCurrentNode;
|
||||
mSiblings = aSiblings;
|
||||
mCurrentNode = aCurrentNode;
|
||||
|
||||
|
@ -228,9 +219,8 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode,
|
|||
// from the iframe accidentally here, so let's just skip this
|
||||
// part for document nodes, they should never have siblings.
|
||||
if (!mSiblings) {
|
||||
nsCOMPtr<nsINode> currentNode = do_QueryInterface(aCurrentNode);
|
||||
if (currentNode->NodeType() != nsINode::DOCUMENT_NODE) {
|
||||
nsCOMPtr<nsIDOMNode> parent = GetParent();
|
||||
if (aCurrentNode->NodeType() != nsINode::DOCUMENT_NODE) {
|
||||
nsCOMPtr<nsINode> parent = GetParent();
|
||||
if (parent) {
|
||||
mSiblings = GetChildren(parent,
|
||||
mShowAnonymousContent,
|
||||
|
@ -263,14 +253,14 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::ParentNode(nsIDOMNode** _retval)
|
||||
inDeepTreeWalker::ParentNode(nsINode** _retval)
|
||||
{
|
||||
*_retval = nullptr;
|
||||
if (!mCurrentNode || mCurrentNode == mRoot) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent = GetParent();
|
||||
nsCOMPtr<nsINode> parent = GetParent();
|
||||
|
||||
if (!parent) {
|
||||
return NS_OK;
|
||||
|
@ -286,7 +276,7 @@ inDeepTreeWalker::ParentNode(nsIDOMNode** _retval)
|
|||
// FirstChild and LastChild are very similar methods, this is the generic
|
||||
// version for internal use. With aReverse = true it returns the LastChild.
|
||||
nsresult
|
||||
inDeepTreeWalker::EdgeChild(nsIDOMNode** _retval, bool aFront)
|
||||
inDeepTreeWalker::EdgeChild(nsINode** _retval, bool aFront)
|
||||
{
|
||||
if (!mCurrentNode) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -294,13 +284,12 @@ inDeepTreeWalker::EdgeChild(nsIDOMNode** _retval, bool aFront)
|
|||
|
||||
*_retval = nullptr;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> echild;
|
||||
nsCOMPtr<nsINode> echild;
|
||||
if (mShowSubDocuments && mShowDocumentsAsNodes) {
|
||||
// GetChildren below, will skip the document node from
|
||||
// the walk. But if mShowDocumentsAsNodes is set to true
|
||||
// we want to include the (sub)document itself too.
|
||||
echild =
|
||||
do_QueryInterface(inLayoutUtils::GetSubDocumentFor(mCurrentNode));
|
||||
echild = inLayoutUtils::GetSubDocumentFor(mCurrentNode);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINodeList> children;
|
||||
|
@ -309,8 +298,7 @@ inDeepTreeWalker::EdgeChild(nsIDOMNode** _retval, bool aFront)
|
|||
mShowAnonymousContent,
|
||||
mShowSubDocuments);
|
||||
if (children && children->Length() > 0) {
|
||||
nsINode* childNode = children->Item(aFront ? 0 : children->Length() - 1);
|
||||
echild = childNode ? childNode->AsDOMNode() : nullptr;
|
||||
echild = children->Item(aFront ? 0 : children->Length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,19 +312,19 @@ inDeepTreeWalker::EdgeChild(nsIDOMNode** _retval, bool aFront)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::FirstChild(nsIDOMNode** _retval)
|
||||
inDeepTreeWalker::FirstChild(nsINode** _retval)
|
||||
{
|
||||
return EdgeChild(_retval, /* aFront = */ true);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::LastChild(nsIDOMNode **_retval)
|
||||
inDeepTreeWalker::LastChild(nsINode **_retval)
|
||||
{
|
||||
return EdgeChild(_retval, /* aFront = */ false);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::PreviousSibling(nsIDOMNode **_retval)
|
||||
inDeepTreeWalker::PreviousSibling(nsINode **_retval)
|
||||
{
|
||||
*_retval = nullptr;
|
||||
if (!mCurrentNode || !mSiblings || mCurrentIndex < 1) {
|
||||
|
@ -344,13 +332,13 @@ inDeepTreeWalker::PreviousSibling(nsIDOMNode **_retval)
|
|||
}
|
||||
|
||||
nsIContent* prev = mSiblings->Item(--mCurrentIndex);
|
||||
mCurrentNode = prev->AsDOMNode();
|
||||
mCurrentNode = prev;
|
||||
NS_ADDREF(*_retval = mCurrentNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::NextSibling(nsIDOMNode **_retval)
|
||||
inDeepTreeWalker::NextSibling(nsINode **_retval)
|
||||
{
|
||||
*_retval = nullptr;
|
||||
if (!mCurrentNode || !mSiblings ||
|
||||
|
@ -359,13 +347,13 @@ inDeepTreeWalker::NextSibling(nsIDOMNode **_retval)
|
|||
}
|
||||
|
||||
nsIContent* next = mSiblings->Item(++mCurrentIndex);
|
||||
mCurrentNode = next->AsDOMNode();
|
||||
mCurrentNode = next;
|
||||
NS_ADDREF(*_retval = mCurrentNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::PreviousNode(nsIDOMNode **_retval)
|
||||
inDeepTreeWalker::PreviousNode(nsINode **_retval)
|
||||
{
|
||||
if (!mCurrentNode || mCurrentNode == mRoot) {
|
||||
// Nowhere to go from here
|
||||
|
@ -373,7 +361,7 @@ inDeepTreeWalker::PreviousNode(nsIDOMNode **_retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsINode> node;
|
||||
PreviousSibling(getter_AddRefs(node));
|
||||
|
||||
if (!node) {
|
||||
|
@ -394,7 +382,7 @@ inDeepTreeWalker::PreviousNode(nsIDOMNode **_retval)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::NextNode(nsIDOMNode **_retval)
|
||||
inDeepTreeWalker::NextNode(nsINode **_retval)
|
||||
{
|
||||
if (!mCurrentNode) {
|
||||
return NS_OK;
|
||||
|
@ -410,7 +398,7 @@ inDeepTreeWalker::NextNode(nsIDOMNode **_retval)
|
|||
// Now keep trying next siblings up the parent chain, but if we
|
||||
// discover there's nothing else restore our state.
|
||||
#ifdef DEBUG
|
||||
nsIDOMNode* origCurrentNode = mCurrentNode;
|
||||
nsINode* origCurrentNode = mCurrentNode;
|
||||
#endif
|
||||
uint32_t lastChildCallsToMake = 0;
|
||||
while (1) {
|
||||
|
@ -420,12 +408,12 @@ inDeepTreeWalker::NextNode(nsIDOMNode **_retval)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
nsCOMPtr<nsINode> parent;
|
||||
ParentNode(getter_AddRefs(parent));
|
||||
if (!parent) {
|
||||
// Nowhere else to go; we're done. Restore our state.
|
||||
while (lastChildCallsToMake--) {
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
nsCOMPtr<nsINode> dummy;
|
||||
LastChild(getter_AddRefs(dummy));
|
||||
}
|
||||
NS_ASSERTION(mCurrentNode == origCurrentNode,
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "inIDeepTreeWalker.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
class nsINodeList;
|
||||
|
@ -23,13 +23,13 @@ public:
|
|||
|
||||
inDeepTreeWalker();
|
||||
|
||||
nsresult SetCurrentNode(nsIDOMNode* aCurrentNode,
|
||||
nsresult SetCurrentNode(nsINode* aCurrentNode,
|
||||
nsINodeList* aSiblings);
|
||||
protected:
|
||||
virtual ~inDeepTreeWalker();
|
||||
|
||||
already_AddRefed<nsIDOMNode> GetParent();
|
||||
nsresult EdgeChild(nsIDOMNode** _retval, bool aReverse);
|
||||
already_AddRefed<nsINode> GetParent();
|
||||
nsresult EdgeChild(nsINode** _retval, bool aReverse);
|
||||
|
||||
bool mShowAnonymousContent;
|
||||
bool mShowSubDocuments;
|
||||
|
@ -37,8 +37,8 @@ protected:
|
|||
|
||||
// The root node. previousNode and parentNode will return
|
||||
// null from here.
|
||||
nsCOMPtr<nsIDOMNode> mRoot;
|
||||
nsCOMPtr<nsIDOMNode> mCurrentNode;
|
||||
nsCOMPtr<nsINode> mRoot;
|
||||
nsCOMPtr<nsINode> mCurrentNode;
|
||||
|
||||
// We cache the siblings of mCurrentNode as a list of nodes.
|
||||
// Notes: normally siblings are all the children of the parent
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMNode;
|
||||
webidl Node;
|
||||
|
||||
// Note: the iterator does not handle DOM mutations gracefully. So if
|
||||
// the underlying DOM we are iterating over is changed, the behavior
|
||||
|
@ -22,7 +22,7 @@ interface inIDeepTreeWalker : nsISupports
|
|||
// by setting this flag to true this behavior can be altered.
|
||||
attribute boolean showDocumentsAsNodes;
|
||||
|
||||
void init(in nsIDOMNode aRoot, in unsigned long aWhatToShow);
|
||||
void init(in Node aRoot, in unsigned long aWhatToShow);
|
||||
|
||||
// Methods and attributes that look like TreeWalker.
|
||||
// Note: normally parentNode cannot go further up on the tree once it reached
|
||||
|
@ -30,16 +30,16 @@ interface inIDeepTreeWalker : nsISupports
|
|||
// is set to a node that does not have the root as its ancestor the walk can be
|
||||
// continued from there, and once we reach a node that is 'under' the root, the
|
||||
// limitation for the parentNode will work again.
|
||||
readonly attribute nsIDOMNode root;
|
||||
readonly attribute Node root;
|
||||
readonly attribute unsigned long whatToShow;
|
||||
attribute nsIDOMNode currentNode;
|
||||
attribute Node currentNode;
|
||||
|
||||
nsIDOMNode parentNode();
|
||||
nsIDOMNode firstChild();
|
||||
nsIDOMNode lastChild();
|
||||
nsIDOMNode previousSibling();
|
||||
nsIDOMNode nextSibling();
|
||||
nsIDOMNode previousNode();
|
||||
nsIDOMNode nextNode();
|
||||
Node parentNode();
|
||||
Node firstChild();
|
||||
Node lastChild();
|
||||
Node previousSibling();
|
||||
Node nextSibling();
|
||||
Node previousNode();
|
||||
Node nextNode();
|
||||
};
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ inLayoutUtils::GetEventStateManagerFor(Element& aElement)
|
|||
}
|
||||
|
||||
nsIDocument*
|
||||
inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode)
|
||||
inLayoutUtils::GetSubDocumentFor(nsINode* aNode)
|
||||
{
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
||||
if (content) {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#define __inLayoutUtils_h__
|
||||
|
||||
class nsIDocument;
|
||||
class nsIDOMNode;
|
||||
class nsINode;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -23,7 +22,7 @@ class inLayoutUtils
|
|||
public:
|
||||
static mozilla::EventStateManager* GetEventStateManagerFor(
|
||||
mozilla::dom::Element& aElement);
|
||||
static nsIDocument* GetSubDocumentFor(nsIDOMNode* aNode);
|
||||
static nsIDocument* GetSubDocumentFor(nsINode* aNode);
|
||||
static nsINode* GetContainerFor(const nsIDocument& aDoc);
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче