mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Show #document nodes in iframes. Fix up various code that assumed they would
_not_ be shown. Minor cleanup of various sorts (nsCOMArray, etc). Bug 201585, r=caillon, sr=alecf
This commit is contained in:
parent
224244de18
commit
e5aa92e533
@ -45,6 +45,7 @@ interface nsIDOMCharacterData;
|
||||
interface nsIDOMElement;
|
||||
interface nsIDOMDocument;
|
||||
interface nsIDOMCSSStyleRule;
|
||||
interface nsIDOMNode;
|
||||
|
||||
[scriptable, uuid(FFFFD059-13D1-4ef7-ACB1-91188C6E31DD)]
|
||||
interface inIDOMUtils : nsISupports
|
||||
@ -55,6 +56,11 @@ interface inIDOMUtils : nsISupports
|
||||
|
||||
// DOM Node utilities
|
||||
boolean isIgnorableWhitespace(in nsIDOMCharacterData aDataNode);
|
||||
// Returns the "parent" of a node. The parent of a document node is the
|
||||
// frame/iframe containing that document. aShowingAnonymousContent says
|
||||
// whether we are showing anonymous content.
|
||||
nsIDOMNode getParentForNode(in nsIDOMNode aNode,
|
||||
in boolean aShowingAnonymousContent);
|
||||
|
||||
// XBL utilities
|
||||
nsISimpleEnumerator getBindingURLs(in nsIDOMElement aElement);
|
||||
|
@ -120,6 +120,37 @@ inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::GetParentForNode(nsIDOMNode* aNode,
|
||||
PRBool aShowingAnonymousContent,
|
||||
nsIDOMNode** aParent)
|
||||
{
|
||||
// First do the special cases -- document nodes and anonymous content
|
||||
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aNode));
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
|
||||
if (doc) {
|
||||
parent = inLayoutUtils::GetContainerFor(doc);
|
||||
} else if (aShowingAnonymousContent) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
||||
nsCOMPtr<nsIContent> bparent;
|
||||
nsCOMPtr<nsIBindingManager> bindingManager = inLayoutUtils::GetBindingManagerFor(aNode);
|
||||
if (bindingManager) {
|
||||
bindingManager->GetInsertionParent(content, getter_AddRefs(bparent));
|
||||
}
|
||||
|
||||
parent = do_QueryInterface(bparent);
|
||||
}
|
||||
|
||||
if (!parent) {
|
||||
// Ok, just get the normal DOM parent node
|
||||
aNode->GetParentNode(getter_AddRefs(parent));
|
||||
}
|
||||
|
||||
NS_IF_ADDREF(*aParent = parent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::GetStyleRules(nsIDOMElement *aElement, nsISupportsArray **_retval)
|
||||
{
|
||||
|
@ -773,7 +773,14 @@ inDOMView::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, nsICo
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMNode> childDOMNode(do_QueryInterface(aChild));
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
GetRealParent(childDOMNode, getter_AddRefs(parent));
|
||||
if (!mDOMUtils) {
|
||||
mDOMUtils = do_GetService("@mozilla.org/inspector/dom-utils;1");
|
||||
if (!mDOMUtils) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
mDOMUtils->GetParentForNode(childDOMNode, mShowAnonymous,
|
||||
getter_AddRefs(parent));
|
||||
|
||||
// find the inDOMViewNode for the parent of the inserted content
|
||||
PRInt32 parentRow = 0;
|
||||
@ -912,11 +919,9 @@ inDOMView::CreateNode(nsIDOMNode* aNode, inDOMViewNode* aParent)
|
||||
viewNode->level = aParent ? aParent->level+1 : 0;
|
||||
viewNode->parent = aParent;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> grandKids;
|
||||
GetChildNodesFor(aNode, getter_AddRefs(grandKids));
|
||||
PRUint32 grandKidLength;
|
||||
grandKids->Count(&grandKidLength);
|
||||
viewNode->isContainer = grandKidLength > 0;
|
||||
nsCOMArray<nsIDOMNode> grandKids;
|
||||
GetChildNodesFor(aNode, grandKids);
|
||||
viewNode->isContainer = (grandKids.Count() > 0);
|
||||
return viewNode;
|
||||
}
|
||||
|
||||
@ -1001,20 +1006,18 @@ inDOMView::ExpandNode(PRInt32 aRow)
|
||||
inDOMViewNode* node = nsnull;
|
||||
RowToNode(aRow, &node);
|
||||
|
||||
nsCOMPtr<nsISupportsArray> kids;
|
||||
inDOMView::GetChildNodesFor(node ? node->node : mRootNode, getter_AddRefs(kids));
|
||||
PRUint32 kidCount;
|
||||
kids->Count(&kidCount);
|
||||
nsCOMArray<nsIDOMNode> kids;
|
||||
GetChildNodesFor(node ? node->node : mRootNode,
|
||||
kids);
|
||||
PRInt32 kidCount = kids.Count();
|
||||
|
||||
nsVoidArray list(kidCount);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> kid;
|
||||
inDOMViewNode* newNode = nsnull;
|
||||
inDOMViewNode* prevNode = nsnull;
|
||||
|
||||
for (PRUint32 i = 0; i < kidCount; ++i) {
|
||||
kids->GetElementAt(i, getter_AddRefs(kid));
|
||||
newNode = CreateNode(kid, node);
|
||||
for (PRInt32 i = 0; i < kidCount; ++i) {
|
||||
newNode = CreateNode(kids[i], node);
|
||||
list.ReplaceElementAt(newNode, i);
|
||||
|
||||
if (prevNode)
|
||||
@ -1148,32 +1151,18 @@ inDOMView::GetLastDescendantOf(inDOMViewNode* aNode, PRInt32 aRow, PRInt32* aRes
|
||||
//////// DOM UTILITIES
|
||||
|
||||
nsresult
|
||||
inDOMView::GetChildNodesFor(nsIDOMNode* aNode, nsISupportsArray **aResult)
|
||||
inDOMView::GetChildNodesFor(nsIDOMNode* aNode, nsCOMArray<nsIDOMNode>& aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsISupportsArray* result;
|
||||
if (NS_FAILED(rv = NS_NewISupportsArray(&result)))
|
||||
return rv;
|
||||
|
||||
// Need to do this test to prevent unfortunate NYI assertion
|
||||
// on nsXULAttribute::GetChildNodes
|
||||
nsCOMPtr<nsIDOMAttr> attr = do_QueryInterface(aNode, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
nsCOMPtr<nsIDOMAttr> attr = do_QueryInterface(aNode);
|
||||
if (!attr) {
|
||||
// attribute nodes
|
||||
if (mWhatToShow & nsIDOMNodeFilter::SHOW_ATTRIBUTE) {
|
||||
nsCOMPtr<nsIDOMNamedNodeMap> attrs;
|
||||
rv = aNode->GetAttributes(getter_AddRefs(attrs));
|
||||
if (attrs)
|
||||
AppendAttrsToArray(attrs, result);
|
||||
}
|
||||
|
||||
if (mShowSubDocuments) {
|
||||
nsCOMPtr<nsIDOMDocument> domdoc = inLayoutUtils::GetSubDocumentFor(aNode);
|
||||
if (domdoc) {
|
||||
nsCOMPtr<nsIDOMNodeList> kids;
|
||||
rv = domdoc->GetChildNodes(getter_AddRefs(kids));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
AppendKidsToArray(kids, result);
|
||||
aNode->GetAttributes(getter_AddRefs(attrs));
|
||||
if (attrs) {
|
||||
AppendAttrsToArray(attrs, aResult);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1181,60 +1170,35 @@ inDOMView::GetChildNodesFor(nsIDOMNode* aNode, nsISupportsArray **aResult)
|
||||
// try to get the anonymous content
|
||||
nsCOMPtr<nsIDOMNodeList> kids;
|
||||
if (mShowAnonymous) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode, &rv);
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
||||
if (content) {
|
||||
nsCOMPtr<nsIBindingManager> bindingManager = inLayoutUtils::GetBindingManagerFor(aNode);
|
||||
if (bindingManager) {
|
||||
bindingManager->GetAnonymousNodesFor(content, getter_AddRefs(kids));
|
||||
if (!kids)
|
||||
if (!kids) {
|
||||
bindingManager->GetContentListFor(content, getter_AddRefs(kids));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!kids)
|
||||
rv = aNode->GetChildNodes(getter_AddRefs(kids));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
AppendKidsToArray(kids, result);
|
||||
if (!kids) {
|
||||
aNode->GetChildNodes(getter_AddRefs(kids));
|
||||
}
|
||||
if (kids) {
|
||||
AppendKidsToArray(kids, aResult);
|
||||
}
|
||||
}
|
||||
|
||||
if (mShowSubDocuments) {
|
||||
nsCOMPtr<nsIDOMNode> domdoc =
|
||||
do_QueryInterface(inLayoutUtils::GetSubDocumentFor(aNode));
|
||||
if (domdoc) {
|
||||
aResult.AppendObject(domdoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aResult = result;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inDOMView::GetRealParent(nsIDOMNode* aNode, nsIDOMNode** aParent)
|
||||
{
|
||||
if (mShowSubDocuments && inLayoutUtils::IsDocumentElement(aNode)) {
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
aNode->GetOwnerDocument(getter_AddRefs(doc));
|
||||
nsCOMPtr<nsIDOMNode> node = inLayoutUtils::GetContainerFor(doc);
|
||||
if (node)
|
||||
*aParent = node;
|
||||
}
|
||||
|
||||
if (mShowAnonymous && !*aParent) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
||||
nsCOMPtr<nsIContent> bparent;
|
||||
nsCOMPtr<nsIBindingManager> bindingManager = inLayoutUtils::GetBindingManagerFor(aNode);
|
||||
if (bindingManager)
|
||||
bindingManager->GetInsertionParent(content, getter_AddRefs(bparent));
|
||||
|
||||
if (bparent) {
|
||||
nsCOMPtr<nsIDOMNode> parent = do_QueryInterface(bparent);
|
||||
*aParent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*aParent) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
aNode->GetParentNode(getter_AddRefs(node));
|
||||
*aParent = node;
|
||||
}
|
||||
|
||||
NS_IF_ADDREF(*aParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1248,7 +1212,8 @@ inDOMView::GetRealPreviousSibling(nsIDOMNode* aNode, nsIDOMNode* aRealParent, ns
|
||||
}
|
||||
|
||||
nsresult
|
||||
inDOMView::AppendKidsToArray(nsIDOMNodeList* aKids, nsISupportsArray* aArray)
|
||||
inDOMView::AppendKidsToArray(nsIDOMNodeList* aKids,
|
||||
nsCOMArray<nsIDOMNode>& aArray)
|
||||
{
|
||||
PRUint32 l = 0;
|
||||
aKids->GetLength(&l);
|
||||
@ -1287,7 +1252,7 @@ inDOMView::AppendKidsToArray(nsIDOMNodeList* aKids, nsISupportsArray* aArray)
|
||||
}
|
||||
}
|
||||
|
||||
aArray->AppendElement(kid);
|
||||
aArray.AppendObject(kid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1295,14 +1260,15 @@ inDOMView::AppendKidsToArray(nsIDOMNodeList* aKids, nsISupportsArray* aArray)
|
||||
}
|
||||
|
||||
nsresult
|
||||
inDOMView::AppendAttrsToArray(nsIDOMNamedNodeMap* aKids, nsISupportsArray* aArray)
|
||||
inDOMView::AppendAttrsToArray(nsIDOMNamedNodeMap* aKids,
|
||||
nsCOMArray<nsIDOMNode>& aArray)
|
||||
{
|
||||
PRUint32 l = 0;
|
||||
aKids->GetLength(&l);
|
||||
nsCOMPtr<nsIDOMNode> kid;
|
||||
for (PRUint32 i = 0; i < l; ++i) {
|
||||
aKids->Item(i, getter_AddRefs(kid));
|
||||
aArray->AppendElement(kid);
|
||||
aArray.AppendObject(kid);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
class inDOMViewNode;
|
||||
|
||||
@ -56,12 +57,12 @@ class inDOMView : public inIDOMView,
|
||||
public nsIDocumentObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_INIDOMVIEW
|
||||
NS_DECL_NSITREEVIEW
|
||||
|
||||
inDOMView();
|
||||
virtual ~inDOMView();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_INIDOMVIEW
|
||||
NS_DECL_NSITREEVIEW
|
||||
|
||||
inDOMView();
|
||||
virtual ~inDOMView();
|
||||
|
||||
// nsIDocumentObserver
|
||||
NS_DECL_NSIDOCUMENTOBSERVER
|
||||
@ -117,12 +118,11 @@ protected:
|
||||
void RemoveLink(inDOMViewNode* aNode);
|
||||
void ReplaceLink(inDOMViewNode* aNewNode, inDOMViewNode* aOldNode);
|
||||
|
||||
nsresult GetChildNodesFor(nsIDOMNode* aNode, nsISupportsArray **aResult);
|
||||
nsresult AppendKidsToArray(nsIDOMNodeList* aKids, nsISupportsArray* aArray);
|
||||
nsresult AppendAttrsToArray(nsIDOMNamedNodeMap* aKids, nsISupportsArray* aArray);
|
||||
nsresult GetChildNodesFor(nsIDOMNode* aNode, nsCOMArray<nsIDOMNode>& aResult);
|
||||
nsresult AppendKidsToArray(nsIDOMNodeList* aKids, nsCOMArray<nsIDOMNode>& aArray);
|
||||
nsresult AppendAttrsToArray(nsIDOMNamedNodeMap* aKids, nsCOMArray<nsIDOMNode>& aArray);
|
||||
nsresult GetFirstDescendantOf(inDOMViewNode* aNode, PRInt32 aRow, PRInt32* aResult);
|
||||
nsresult GetLastDescendantOf(inDOMViewNode* aNode, PRInt32 aRow, PRInt32* aResult);
|
||||
nsresult GetRealParent(nsIDOMNode* aNode, nsIDOMNode** aParent);
|
||||
nsresult GetRealPreviousSibling(nsIDOMNode* aNode, nsIDOMNode* aRealParent, nsIDOMNode** aSibling);
|
||||
};
|
||||
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMNodeFilter.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIServiceManagerUtils.h"
|
||||
#include "inIDOMUtils.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* This implementation does not currently operaate according to the W3C spec.
|
||||
@ -163,39 +165,20 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode)
|
||||
NS_IMETHODIMP
|
||||
inDeepTreeWalker::ParentNode(nsIDOMNode** _retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
if (!mCurrentNode) return NS_OK;
|
||||
|
||||
if (mShowSubDocuments && inLayoutUtils::IsDocumentElement(mCurrentNode)) {
|
||||
nsCOMPtr<nsIDOMDocument> doc;
|
||||
mCurrentNode->GetOwnerDocument(getter_AddRefs(doc));
|
||||
nsCOMPtr<nsIDOMNode> node = inLayoutUtils::GetContainerFor(doc);
|
||||
if (node)
|
||||
*_retval = node;
|
||||
}
|
||||
|
||||
if (mShowAnonymousContent && !*_retval) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mCurrentNode);
|
||||
nsCOMPtr<nsIContent> bparent;
|
||||
nsCOMPtr<nsIBindingManager> bindingManager = inLayoutUtils::GetBindingManagerFor(mCurrentNode);
|
||||
if (bindingManager)
|
||||
bindingManager->GetInsertionParent(content, getter_AddRefs(bparent));
|
||||
|
||||
if (bparent) {
|
||||
nsCOMPtr<nsIDOMNode> parent = do_QueryInterface(bparent);
|
||||
*_retval = parent;
|
||||
if (!mDOMUtils) {
|
||||
mDOMUtils = do_GetService("@mozilla.org/inspector/dom-utils;1");
|
||||
if (!mDOMUtils) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*_retval) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
mCurrentNode->GetParentNode(getter_AddRefs(node));
|
||||
*_retval = node;
|
||||
}
|
||||
|
||||
nsresult rv = mDOMUtils->GetParentForNode(mCurrentNode, mShowAnonymousContent,
|
||||
_retval);
|
||||
mCurrentNode = *_retval;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -45,6 +45,8 @@
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class inIDOMUtils;
|
||||
|
||||
class inDeepTreeWalker : public inIDeepTreeWalker
|
||||
{
|
||||
public:
|
||||
@ -65,6 +67,7 @@ protected:
|
||||
PRUint32 mWhatToShow;
|
||||
|
||||
nsAutoVoidArray mStack;
|
||||
nsCOMPtr<inIDOMUtils> mDOMUtils;
|
||||
};
|
||||
|
||||
#endif // __inDeepTreeWalker_h___
|
||||
|
@ -287,20 +287,3 @@ inLayoutUtils::GetContainerFor(nsIDOMDocument* aDoc)
|
||||
return elem;
|
||||
}
|
||||
|
||||
PRBool
|
||||
inLayoutUtils::IsDocumentElement(nsIDOMNode* aNode)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
aNode->GetParentNode(getter_AddRefs(parent));
|
||||
if (parent) {
|
||||
PRUint16 nodeType;
|
||||
parent->GetNodeType(&nodeType);
|
||||
if (nodeType == nsIDOMNode::DOCUMENT_NODE)
|
||||
result = PR_TRUE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,6 @@ public:
|
||||
static nsIBindingManager* GetBindingManagerFor(nsIDOMNode* aNode);
|
||||
static nsIDOMDocument* GetSubDocumentFor(nsIDOMNode* aNode);
|
||||
static nsIDOMNode* GetContainerFor(nsIDOMDocument* aDoc);
|
||||
static PRBool IsDocumentElement(nsIDOMNode* aNode);
|
||||
/**
|
||||
* This function returns the offset of a frame with respect to the
|
||||
* root view of the aPresContext's viewmanager (for use by
|
||||
|
@ -73,7 +73,7 @@ function PseudoClassDialog()
|
||||
this.mOpener = window.opener.viewer;
|
||||
this.mSubject = window.arguments[0];
|
||||
|
||||
this.mDOMUtils = XPCU.createInstance("@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
||||
this.mDOMUtils = XPCU.getService("@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
||||
}
|
||||
|
||||
PseudoClassDialog.prototype =
|
||||
|
@ -326,7 +326,7 @@ function doesQI(aObject, aInterface)
|
||||
|
||||
function StyleRuleView(aObject)
|
||||
{
|
||||
this.mDOMUtils = XPCU.createInstance("@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
||||
this.mDOMUtils = XPCU.getService("@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
||||
if (doesQI(aObject, "nsIDOMCSSStyleSheet")) {
|
||||
this.mSheetRules = aObject.cssRules;
|
||||
} else {
|
||||
|
@ -71,7 +71,7 @@ function XBLBindings()
|
||||
{
|
||||
this.mURL = window.location;
|
||||
this.mObsMan = new ObserverManager(this);
|
||||
this.mDOMUtils = XPCU.createInstance("@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
||||
this.mDOMUtils = XPCU.getService("@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
||||
|
||||
this.mContentTree = document.getElementById("olContent");
|
||||
this.mMethodTree = document.getElementById("olMethods");
|
||||
|
Loading…
Reference in New Issue
Block a user