From: L. David Baron Expose DocumentViewerImpl::CallChildren with an API that fills an array. (Bug 747231, patch 3) diff --git a/docshell/base/nsIMarkupDocumentViewer.idl b/docshell/base/nsIMarkupDocumentViewer.idl --- a/docshell/base/nsIMarkupDocumentViewer.idl +++ b/docshell/base/nsIMarkupDocumentViewer.idl @@ -33,31 +33,35 @@ * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ /** - * The nsIContentViewerEdit - */ - -/** * The nsIMarkupDocumentViewer * This interface describes the properties of a content viewer * for a markup document - HTML or XML */ #include "nsISupports.idl" interface nsIDOMNode; +%{C++ +#include "nsCOMPtr.h" +#include "nsTArray.h" +%} -[scriptable, uuid(79286cd6-8293-4def-ba26-76422efc3d2a)] +interface nsIMarkupDocumentViewer; + +[ref] native nsIMarkupDocumentViewerTArray(nsTArray >); + +[scriptable, uuid(1016d5e8-690f-4d97-8ac5-d50ffa341c46)] interface nsIMarkupDocumentViewer : nsISupports { /* Scrolls to a given DOM content node. */ void scrollToNode(in nsIDOMNode node); @@ -142,12 +146,18 @@ interface nsIMarkupDocumentViewer : nsIS */ attribute octet bidiSupport; /** * Use this attribute to access all the Bidi options in one operation */ attribute PRUint32 bidiOptions; - /** The minimum font size */ - attribute long minFontSize; + /** The minimum font size */ + attribute long minFontSize; + + /** + * Append |this| and all of its descendants to the given array, + * in depth-first pre-order traversal. + */ + [noscript] void appendSubtree(in nsIMarkupDocumentViewerTArray array); }; diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -3248,16 +3248,31 @@ NS_IMETHODIMP DocumentViewerImpl::GetBid *aBidiOptions = mPresContext->GetBidi(); } else *aBidiOptions = IBMBIDI_DEFAULT_BIDI_OPTIONS; } return NS_OK; } +static void +AppendChildSubtree(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + nsTArray >& array = + *static_cast >*>(aClosure); + aChild->AppendSubtree(array); +} + +NS_IMETHODIMP DocumentViewerImpl::AppendSubtree(nsTArray >& aArray) +{ + aArray.AppendElement(this); + CallChildren(AppendChildSubtree, &aArray); + return NS_OK; +} + NS_IMETHODIMP DocumentViewerImpl::SizeToContent() { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); // Skip doing this on docshell-less documents for now nsCOMPtr docShellAsItem(do_QueryReferent(mContainer)); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_NOT_AVAILABLE);