diff --git a/mozilla/extensions/layout-debug/Makefile.in b/mozilla/extensions/layout-debug/Makefile.in index f8e74a91bd9..d5394bd4a8f 100644 --- a/mozilla/extensions/layout-debug/Makefile.in +++ b/mozilla/extensions/layout-debug/Makefile.in @@ -26,7 +26,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS += public src idl plugin +DIRS += public src idl include $(topsrcdir)/config/rules.mk diff --git a/mozilla/extensions/layout-debug/idl/MANIFEST_IDL b/mozilla/extensions/layout-debug/idl/MANIFEST_IDL index 68160cbe026..8a19c505846 100644 --- a/mozilla/extensions/layout-debug/idl/MANIFEST_IDL +++ b/mozilla/extensions/layout-debug/idl/MANIFEST_IDL @@ -1,4 +1,4 @@ # # This is a list of local files which get copied to the mozilla:dist:idl directory # -nsIDebugObject.idl +nsIFrameDebugObject.idl diff --git a/mozilla/extensions/layout-debug/idl/Makefile.in b/mozilla/extensions/layout-debug/idl/Makefile.in index 6fca11f62dd..fb3a4610cd8 100644 --- a/mozilla/extensions/layout-debug/idl/Makefile.in +++ b/mozilla/extensions/layout-debug/idl/Makefile.in @@ -26,11 +26,11 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -MODULE = debug +MODULE = layout_debug DEFINES=-D_IMPL_NS_UI XPIDLSRCS = \ - nsIDebugObject.idl \ + nsIFrameDebugObject.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/extensions/layout-debug/idl/nsIDebugObject.idl b/mozilla/extensions/layout-debug/idl/nsIDebugObject.idl deleted file mode 100644 index 9ba8aa4487c..00000000000 --- a/mozilla/extensions/layout-debug/idl/nsIDebugObject.idl +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Don Cone - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -[scriptable, uuid(1B4CD090-0531-11d6-A876-00105A183419)] -interface nsIDebugObject : nsISupports -{ - - /** - * creates a directory.. only locally - * @param - * @param - */ - void CreateDirectory(in wstring aDirectoryPath, in unsigned long aFlags); - - - void OutputTextToFile(in boolean aNewFile,in wstring aFilePath, in wstring aFileName, in wstring aOutputString); - - /** - * Dumps the content of a window - * @param - * @param - */ - void DumpContent(in nsISupports aUrlToDump,in wstring aFilePath,in wstring aFileName, in unsigned long aFlags); - - /** - * Compares the contents of frame model files - * @param - * @param - */ - void CompareFrameModels(in wstring aBasePath,in wstring aVerPath,in wstring aBaseFile,in wstring aVerFile, in unsigned long aFlags); - - - /** - * Printing Runtime Error Checking - */ - const short PRT_RUNTIME_NONE = 0; - const short PRT_RUNTIME_CHECKFORPRINTERS = 1; - const short PRT_RUNTIME_CREATEPRTSESSION = 2; - const short PRT_RUNTIME_INITPRTOBJ = 3; - const short PRT_RUNTIME_CREATESPECFACTORY = 4; - const short PRT_RUNTIME_NOPROMPTSERVICE = 5; - const short PRT_RUNTIME_NODEVSPEC = 6; - const short PRT_RUNTIME_NEXTPAGE = 7; - const short PRT_RUNTIME_REFLOWDOCLIST = 8; - const short PRT_RUNTIME_PREPAREDOC = 9; - const short PRT_RUNTIME_BEGINDOC = 10; - - attribute boolean doRuntimeTests; // indicates whether the runtime test will be run - attribute short testId; // id of test to run - attribute boolean printAsIs; // print asis when printing to a file - attribute wstring printFileName; // name of output file - -}; - - -%{ C++ - -%} diff --git a/mozilla/extensions/layout-debug/idl/nsIFrameDebugObject.idl b/mozilla/extensions/layout-debug/idl/nsIFrameDebugObject.idl new file mode 100644 index 00000000000..4eff5075737 --- /dev/null +++ b/mozilla/extensions/layout-debug/idl/nsIFrameDebugObject.idl @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Don Cone + * Sion Fraser + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsIDOMWindow; +interface nsILocalFile; + +[scriptable, uuid(1B4CD090-0531-11d6-A876-00105A183419)] +interface nsIFrameDebugObject : nsISupports +{ + + /** + * Output the given string to a file, optionally truncating the file first. + * @param aFile the file to output to + * @param aTruncateFile whether to trunate the file first + * @param aOutputString the string to write out + */ + void outputTextToFile(in nsILocalFile aFile, in boolean aTruncateFile, in string aOutputString); + + /** + * Dumps the content of a window + * @param aWindowToDump the window to dump (may be an iframe etc) + * @param aFile the file to dump to. It will be created if necessary, otherwise + truncated. If nil, write to stdout. + * @param aFlagsMask some flags that determine what to dump + * @param aFlagsMask some flags that determine what to dump + * @param aResult a status value indicating whether the dump happened, + whether the page was still loading, or whether some other error happened. + */ + const short DUMP_FLAGS_MASK_DEFAULT = 0; + const short DUMP_FLAGS_MASK_DUMP_STYLE = 1; + + const long DUMP_RESULT_COMPLETED = 0; // loaded OK + const long DUMP_RESULT_LOADING = 1; // still loading + const long DUMP_RESULT_ERROR = 2; // an error occurred + + long dumpFrameModel(in nsIDOMWindow aWindowToDump, in nsILocalFile aFile, in unsigned long aFlagsMask); + + /** + * Compares the contents of frame model files + * @param aBaseFile the baseline file, opened with read permissions + * @param aVerFile file containing the results to verify, opened with read permissions + * @param aFlags flags specifying output verbosity + * @param aResult result of the comparison: zero if the files are same, non-zero if different + */ + const short COMPARE_FLAGS_VERBOSE = 0; + const short COMPARE_FLAGS_BRIEF = 1; + long compareFrameModels(in nsILocalFile aBaseFile, in nsILocalFile aVerFile, in unsigned long aFlags); + + /** + * Methods to dump various types of data. In all casese, if aDestFile is nil, + * data is written to stdout. + */ + + void dumpContent(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + + void dumpFrames(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpViews(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpWebShells(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpStyleSheets(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpStyleContexts(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpReflowStats(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + + /** + * Turn reflow stats on or off for the given window. Requires that + * you built with MOZ_REFLOW_PERF=1 + */ + void setShowReflowStats(in nsIDOMWindow aWindow, in boolean inShow); + + attribute boolean showFrameBorders; // whether to show frame borders + attribute boolean showEventTargetFrameBorder; // whether to show event target frame borders + +}; + diff --git a/mozilla/extensions/layout-debug/mac/DbgPrefixCarbon.h b/mozilla/extensions/layout-debug/mac/DbgPrefixCarbon.h index 9690d783322..4574a4b4791 100644 --- a/mozilla/extensions/layout-debug/mac/DbgPrefixCarbon.h +++ b/mozilla/extensions/layout-debug/mac/DbgPrefixCarbon.h @@ -1,10 +1,2 @@ -#define XP_MAC 1 -#define TARGET_CARBON 1 -#define DEBUG 1 - -/* Read the common configuration file */ -#ifndef MacConfigInclude_h_ -#include "MacConfigInclude.h" -#endif - +#include "MacPrefix_debug.h" diff --git a/mozilla/extensions/layout-debug/public/MANIFEST b/mozilla/extensions/layout-debug/public/MANIFEST index a94ab6b6904..4dbce8036bd 100644 --- a/mozilla/extensions/layout-debug/public/MANIFEST +++ b/mozilla/extensions/layout-debug/public/MANIFEST @@ -1,4 +1,4 @@ # # This is a list of local files which get copied to the mozilla:dist:layout-debug directory # -nsDebugCIID.h +nsLayoutDebugCIID.h diff --git a/mozilla/extensions/layout-debug/public/Makefile.in b/mozilla/extensions/layout-debug/public/Makefile.in index 7adff31ab0b..92953577c89 100644 --- a/mozilla/extensions/layout-debug/public/Makefile.in +++ b/mozilla/extensions/layout-debug/public/Makefile.in @@ -26,10 +26,10 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -MODULE = debug +MODULE = layout_debug EXPORTS = \ - nsDebugCIID.h \ + nsLayoutDebugCIID.h \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/extensions/layout-debug/public/nsDebugCIID.h b/mozilla/extensions/layout-debug/public/nsLayoutDebugCIID.h similarity index 89% rename from mozilla/extensions/layout-debug/public/nsDebugCIID.h rename to mozilla/extensions/layout-debug/public/nsLayoutDebugCIID.h index 257d88b14b0..928bc41bcd3 100644 --- a/mozilla/extensions/layout-debug/public/nsDebugCIID.h +++ b/mozilla/extensions/layout-debug/public/nsLayoutDebugCIID.h @@ -36,15 +36,16 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef nsDebugCIID_h__ -#define nsDebugCIID_h__ +#ifndef nsFrameDebugCIID_h__ +#define nsFrameDebugCIID_h__ #include "nsISupports.h" #include "nsIFactory.h" #include "nsIComponentManager.h" -#define NS_DEGUG_OBJECT_CID \ -{ 0xb0186a40, 0x5de, 0x11d6, \ -{ 0xa8, 0x76, 0x0, 0x10, 0x5a, 0x18, 0x34, 0x19 } } +#define NS_FRAME_DEBUG_OBJECT_CID \ +{ 0x698c54f4, 0x4ea9, 0x11d7, \ +{ 0x85, 0x9f, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 } } + +#endif // nsFrameDebugCIID_h__ -#endif diff --git a/mozilla/extensions/layout-debug/src/Makefile.in b/mozilla/extensions/layout-debug/src/Makefile.in index b38ede8bd8a..930ac585202 100644 --- a/mozilla/extensions/layout-debug/src/Makefile.in +++ b/mozilla/extensions/layout-debug/src/Makefile.in @@ -26,11 +26,11 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -MODULE = debug +MODULE = layout_debug LIBRARY_NAME = gkdebug EXPORT_LIBRARY = 1 IS_COMPONENT = 1 -MODULE_NAME = nsDebugModule +MODULE_NAME = nsLayoutDebugModule REQUIRES= xpcom \ string \ diff --git a/mozilla/extensions/layout-debug/src/nsDebugFactory.cpp b/mozilla/extensions/layout-debug/src/nsDebugFactory.cpp index 487aa15d871..ea6a2edafb9 100644 --- a/mozilla/extensions/layout-debug/src/nsDebugFactory.cpp +++ b/mozilla/extensions/layout-debug/src/nsDebugFactory.cpp @@ -37,7 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nscore.h" -#include "nsDebugCIID.h" +#include "nsLayoutDebugCIID.h" #include "nsIFactory.h" #include "nsISupports.h" #include "nsDebugObject.h" @@ -49,13 +49,13 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDebugObject) -static nsModuleComponentInfo components[] = +static const nsModuleComponentInfo components[] = { { "nsDebugObject", - NS_DEGUG_OBJECT_CID, - "@mozilla.org/debug/debugobject;1", + NS_FRAME_DEBUG_OBJECT_CID, + "@mozilla.org/layout_debug/framedebugobject;1", nsDebugObjectConstructor } }; -NS_IMPL_NSGETMODULE(nsDebugModule, components) +NS_IMPL_NSGETMODULE(nsLayoutDebugModule, components) diff --git a/mozilla/extensions/layout-debug/src/nsDebugObject.cpp b/mozilla/extensions/layout-debug/src/nsDebugObject.cpp index dc49ba842ea..8f418ed8026 100644 --- a/mozilla/extensions/layout-debug/src/nsDebugObject.cpp +++ b/mozilla/extensions/layout-debug/src/nsDebugObject.cpp @@ -42,13 +42,14 @@ #include "nsXPIDLString.h" #include "nsReadableUtils.h" -#include "nsIFileSpec.h" #include "nsIWindowWatcher.h" #include "nsVoidArray.h" #include "prmem.h" #include "nsIDocShellTreeItem.h" +#include "nsIDocShellTreeNode.h" #include "nsIDOMWindowInternal.h" #include "nsIPresShell.h" +#include "nsIDocument.h" #include "nsIDOMDocument.h" #include "nsIURI.h" #include "nsIDOMHTMLDocument.h" @@ -61,266 +62,614 @@ #include "nsIFrameUtil.h" #include "nsLayoutCID.h" #include "nsNetUtil.h" -#include "nsIFile.h" +#include "nsILocalFile.h" +#include "nsIPrefService.h" +#include "nsIViewManager.h" +#include "nsIView.h" +#include "nsIStyleSet.h" -NS_IMPL_ISUPPORTS1(nsDebugObject, nsIDebugObject) -static NS_DEFINE_IID(kFrameUtilCID, NS_FRAME_UTIL_CID); -static NS_DEFINE_IID(kIFrameUtilIID, NS_IFRAME_UTIL_IID); -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ -nsDebugObject::nsDebugObject() : - mRuntimeTestIsOn(PR_FALSE), - mPrintAsIs(PR_FALSE), - mRuntimeTestId(nsIDebugObject::PRT_RUNTIME_NONE), - mFileName(nsnull) +static NS_DEFINE_CID(kFrameUtilCID, NS_FRAME_UTIL_CID); +static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID); + + +nsDebugObject::nsDebugObject() { } -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ nsDebugObject::~nsDebugObject() { - if (mFileName) { - nsMemory::Free(mFileName); - } } -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ -NS_IMETHODIMP -nsDebugObject::CreateDirectory( const PRUnichar *aFilePath, PRUint32 aFlags) -{ - nsresult rv,result = NS_ERROR_FAILURE; - PRBool exists = PR_TRUE; +NS_IMPL_ISUPPORTS1(nsDebugObject, nsIFrameDebugObject) - nsCString dirStr; - dirStr.AssignWithConversion(aFilePath); - nsCOMPtr localFile; - rv = NS_GetFileFromURLSpec(dirStr, getter_AddRefs(localFile)); - if ( NS_SUCCEEDED(rv) ) { - rv = localFile->Exists(&exists); - if (!exists){ - rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0600); - if (NS_FAILED(rv)) { - printf("Failed to create directory [%s]\n", NS_LossyConvertUCS2toASCII(nsAutoString(aFilePath)).get()); - } - } else { - printf("OK - Directory Exists [%s]\n", NS_LossyConvertUCS2toASCII(nsAutoString(aFilePath)).get()); - } - } else { - printf("Failed to init path for local file in CreateDirectory [%s]\n", NS_LossyConvertUCS2toASCII(nsAutoString(aFilePath)).get()); - } - - return result; -} - -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ NS_IMETHODIMP -nsDebugObject::OutputTextToFile(PRBool aNewFile, const PRUnichar *aFilePath, const PRUnichar *aFileName, const PRUnichar *aOutputString) +nsDebugObject::OutputTextToFile(nsILocalFile *aFile, PRBool aTruncateFile, const char *aOutputString) { - nsresult result = NS_ERROR_FAILURE; - nsCAutoString outputPath; - outputPath.AssignWithConversion(aFilePath); - outputPath.AppendWithConversion(aFileName); - char* filePath = ToNewCString(outputPath); - FILE* fp; - - if ( aNewFile ) { - fp = fopen(filePath, "wt"); - } else { - fp = fopen(filePath, "at"); + NS_ENSURE_ARG(aOutputString); + + FILE* fp = stdout; + if (aFile) + { + const char* options = (aTruncateFile) ? "wt" : "at"; + nsresult rv = aFile->OpenANSIFileDesc(options, &fp); + if (NS_FAILED(rv)) return rv; } - if ( fp ) { - nsCAutoString outputString; - outputString.AssignWithConversion(aOutputString); - char* theOutput = ToNewCString(outputString); - fprintf(fp,theOutput); - fprintf(fp,"\n"); + fprintf(fp, aOutputString); + fprintf(fp, "\n"); + if (fp != stdout) fclose(fp); - delete filePath; - } - return result; + return NS_OK; } - -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ NS_IMETHODIMP -nsDebugObject::DumpContent(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags) +nsDebugObject::DumpFrameModel(nsIDOMWindow *aWindowToDump, nsILocalFile *aDestFile, PRUint32 aFlagsMask, PRInt32 *aResult) { -nsresult result = NS_ERROR_NOT_AVAILABLE; -PRUint32 busyFlags; -PRBool stillLoading; + NS_ENSURE_ARG(aWindowToDump); + NS_ENSURE_ARG_POINTER(aResult); - nsCOMPtr theInternWindow(do_QueryInterface(aWindow)); - if (theInternWindow) { + nsresult rv = NS_ERROR_NOT_AVAILABLE; + PRUint32 busyFlags; + PRBool stillLoading; + + *aResult = DUMP_RESULT_ERROR; + + nsCOMPtr docShell; + rv = GetDocShellFromWindow(aWindowToDump, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + // find out if the document is loaded + docShell->GetBusyFlags(&busyFlags); + stillLoading = busyFlags && (nsIDocShell::BUSY_FLAGS_BUSY | nsIDocShell::BUSY_FLAGS_PAGE_LOADING); + if (stillLoading) + { + *aResult = DUMP_RESULT_LOADING; + return NS_OK; + } + + nsCOMPtr presShell; + docShell->GetPresShell(getter_AddRefs(presShell)); + + nsIFrame* root; + presShell->GetRootFrame(&root); + + nsIFrameDebug* fdbg; + rv = CallQueryInterface(root, &fdbg); + if (NS_FAILED(rv)) return rv; + + PRBool dumpStyle = (aFlagsMask & DUMP_FLAGS_MASK_DUMP_STYLE) != 0; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); + + fdbg->DumpRegressionData(presContext, fp, 0, dumpStyle); + if (fp != stdout) + fclose(fp); + + *aResult = DUMP_RESULT_COMPLETED; + return NS_OK; +} + +/* void dumpContent (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpContent(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + DumpContentRecurse(docShell, fp); + DumpMultipleWebShells(aWindow, fp); + + if (fp != stdout) + fclose(fp); + return NS_OK; +} + +/* void dumpFrames (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpFrames(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + DumpFramesRecurse(docShell, fp); + DumpMultipleWebShells(aWindow, fp); + + if (fp != stdout) + fclose(fp); + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::DumpViews(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + DumpViewsRecurse(docShell, fp); + DumpMultipleWebShells(aWindow, fp); + + if (fp != stdout) + fclose(fp); + return NS_OK; +} + +/* void dumpWebShells (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpWebShells(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + nsCOMPtr shellAsItem(do_QueryInterface(docShell)); + if (!shellAsItem) return NS_ERROR_FAILURE; + + FILE* outFile = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &outFile); + if (NS_FAILED(rv)) return rv; + } + + DumpAWebShell(shellAsItem, outFile); + if (outFile != stdout) + fclose(outFile); + + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::DumpStyleSheets(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + + FILE* outFile = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &outFile); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr styleSet; + presShell->GetStyleSet(getter_AddRefs(styleSet)); + if (styleSet) + styleSet->List(outFile); + else + fputs("null style set\n", outFile); + + if (outFile != stdout) + fclose(outFile); + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::DumpStyleContexts(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + + FILE* outFile = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &outFile); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr styleSet; + presShell->GetStyleSet(getter_AddRefs(styleSet)); + if (styleSet) + { + nsIFrame* root; + presShell->GetRootFrame(&root); + if (root) + fputs("null root frame\n", outFile); + else + styleSet->ListContexts(root, outFile); + } + else + fputs("null style set\n", outFile); + + if (outFile != stdout) + fclose(outFile); + return NS_OK; +} + +/* void dumpReflowStats (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpReflowStats(nsIDOMWindow *aWindow, nsILocalFile* /* aDestFile */) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + +#ifdef MOZ_REFLOW_PERF + presShell->DumpReflows(); +#else + fprintf(stdout, "***********************************\n"); + fprintf(stdout, "Sorry, you haven't built with MOZ_REFLOW_PERF=1\n"); + fprintf(stdout, "***********************************\n"); +#endif + + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::CompareFrameModels(nsILocalFile *aBaseFile, nsILocalFile *aVerFile, PRUint32 aFlags, PRInt32 *aResult) +{ + NS_ENSURE_ARG(aBaseFile); + NS_ENSURE_ARG(aVerFile); + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = NS_OK; + + nsresult rv; + FILE* baseFile; + rv = aBaseFile->OpenANSIFileDesc("r", &baseFile); + if (NS_FAILED(rv)) return rv; + + FILE* verFile; + rv = aVerFile->OpenANSIFileDesc("r", &verFile); + if (NS_FAILED(rv)) { + fclose(baseFile); + return rv; + } + + nsCOMPtr frameUtil = do_CreateInstance(kFrameUtilCID, &rv); + if (NS_SUCCEEDED(rv)) + { + PRInt32 outputLevel = (aFlags == COMPARE_FLAGS_VERBOSE) ? 0 : 1; + rv = frameUtil->CompareRegressionData(baseFile, verFile, outputLevel); + } + fclose(verFile); + fclose(baseFile); + + *aResult = NS_FAILED(rv); + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::GetShowFrameBorders(PRBool *aShowFrameBorders) +{ + NS_ENSURE_ARG_POINTER(aShowFrameBorders); + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + return mLayoutDebugger->GetShowFrameBorders(aShowFrameBorders); +} + +NS_IMETHODIMP +nsDebugObject::SetShowFrameBorders(PRBool aShowFrameBorders) +{ + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + nsresult rv = mLayoutDebugger->SetShowFrameBorders(aShowFrameBorders); + RefreshAllWindows(); + return rv; +} + +NS_IMETHODIMP +nsDebugObject::GetShowEventTargetFrameBorder(PRBool *aShowEventTargetFrameBorder) +{ + NS_ENSURE_ARG_POINTER(aShowEventTargetFrameBorder); + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + return mLayoutDebugger->GetShowEventTargetFrameBorder(aShowEventTargetFrameBorder); +} + +NS_IMETHODIMP +nsDebugObject::SetShowEventTargetFrameBorder(PRBool aShowEventTargetFrameBorder) +{ + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + nsresult rv = mLayoutDebugger->SetShowEventTargetFrameBorder(aShowEventTargetFrameBorder); + RefreshAllWindows(); + return rv; +} + +NS_IMETHODIMP +nsDebugObject::SetShowReflowStats(nsIDOMWindow *aWindow, PRBool inShow) +{ + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + +#ifdef MOZ_REFLOW_PERF + presShell->SetPaintFrameCount(inShow); +#else + printf("***********************************************\n"); + printf("Sorry, you haven't built with MOZ_REFLOW_PERF=1\n"); + printf("***********************************************\n"); +#endif + + return NS_OK; +} + +nsresult +nsDebugObject::EnsureLayoutDebugger() +{ + if (!mLayoutDebugger) + { + nsresult rv; + mLayoutDebugger = do_CreateInstance(kLayoutDebuggerCID, &rv); + if (NS_FAILED(rv)) + return rv; + } + + return NS_OK; +} + +nsresult +nsDebugObject::RefreshAllWindows() +{ + nsresult rv; + // hack. Toggle the underline links pref to get stuff to redisplay + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) + { + PRBool underlineLinksPref; + rv = prefBranch->GetBoolPref("browser.underline_anchors", &underlineLinksPref); + if (NS_SUCCEEDED(rv)) + { + prefBranch->SetBoolPref("browser.underline_anchors", !underlineLinksPref); + prefBranch->SetBoolPref("browser.underline_anchors", underlineLinksPref); + } + } + return NS_OK; +} + + +nsresult +nsDebugObject::GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell** outShell) +{ + nsCOMPtr scriptObj(do_QueryInterface(inWindow)); + if (!scriptObj) return NS_ERROR_FAILURE; + + return scriptObj->GetDocShell(outShell); +} + + +nsresult +nsDebugObject::GetPresShellFromWindow(nsIDOMWindow* inWindow, nsIPresShell** outShell) +{ + nsCOMPtr docShell; + GetDocShellFromWindow(inWindow, getter_AddRefs(docShell)); + if (!docShell) return NS_ERROR_FAILURE; + + nsresult rv = docShell->GetPresShell(outShell); + if (NS_FAILED(rv)) return rv; + if (!*outShell) return NS_ERROR_FAILURE; + + return NS_OK; +} + +#if 0 +#pragma mark - +#endif + +void +nsDebugObject::DumpMultipleWebShells(nsIDOMWindow* aWindow, FILE* aOut) +{ + nsCOMPtr docShell; + GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (!docShell) return; + + PRInt32 count; + nsCOMPtr docShellAsNode(do_QueryInterface(docShell)); + if (docShellAsNode) { + docShellAsNode->GetChildCount(&count); + if (count > 0) { + nsCOMPtr docShellAsStupidItem(do_QueryInterface(docShell)); + fprintf(aOut, "webshells= \n"); + DumpAWebShell(docShellAsStupidItem, aOut); + } + } +} + + +void +nsDebugObject::DumpAWebShell(nsIDocShellTreeItem* aShellItem, FILE* aOut, PRInt32 aIndent) +{ + nsXPIDLString name; + nsAutoString str; + nsCOMPtr parent; + PRInt32 i; + + for (i = aIndent; --i >= 0; ) fprintf(aOut, " "); + + fprintf(aOut, "%p '", aShellItem); + aShellItem->GetName(getter_Copies(name)); + aShellItem->GetSameTypeParent(getter_AddRefs(parent)); + str.Assign(name); + fputs(NS_LossyConvertUCS2toASCII(str).get(), aOut); + fprintf(aOut, "' parent=%p <\n", parent.get()); + + aIndent++; + nsCOMPtr shellAsNode(do_QueryInterface(aShellItem)); + + PRInt32 numChildren; + shellAsNode->GetChildCount(&numChildren); + for (i = 0; i < numChildren; i++) { + nsCOMPtr child; + shellAsNode->GetChildAt(i, getter_AddRefs(child)); + if (child) { + DumpAWebShell(child, aOut, aIndent); + } + } + aIndent--; + for (i = aIndent; --i >= 0; ) fprintf(aOut, " "); + fputs(">\n", aOut); +} + + +void +nsDebugObject::DumpContentRecurse(nsIDocShell* inDocShell, FILE* inDestFile) +{ + if (inDocShell) + { + fprintf(inDestFile, "docshell=%p \n", inDocShell); nsCOMPtr presShell; - if (theInternWindow != nsnull) { - nsIFrameDebug* fdbg; - nsIFrame* root; - nsIPresContext *thePC; - - nsCOMPtr scriptObj(do_QueryInterface(theInternWindow)); - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); - - // find out if the document is loaded - docShell->GetBusyFlags(&busyFlags); - stillLoading = busyFlags && (nsIDocShell::BUSY_FLAGS_BUSY | nsIDocShell::BUSY_FLAGS_PAGE_LOADING); - - if ( !stillLoading ) { - docShell->GetPresShell(getter_AddRefs(presShell)); - presShell->GetRootFrame(&root); - if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { - // create the string for the output - nsCAutoString outputPath; - outputPath.AssignWithConversion(aFilePath); - outputPath.AppendWithConversion(aFileName); - char* filePath = ToNewCString(outputPath); - PRBool dumpStyle=PR_FALSE; - - if(aFlags){ - dumpStyle = PR_TRUE; - } - - FILE* fp = fopen(filePath, "wt"); - - if ( fp ) { - presShell->GetPresContext(&thePC); - - fdbg->DumpRegressionData(thePC, fp, 0, dumpStyle); - fclose(fp); - delete filePath; - result = NS_OK; // the document is now loaded, and the frames are dumped. - } else { - - result = NS_ERROR_FILE_INVALID_PATH; - } - } + inDocShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) + { + nsCOMPtr doc; + presShell->GetDocument(getter_AddRefs(doc)); + if (doc) + { + nsCOMPtr root; + doc->GetRootContent(getter_AddRefs(root)); + if (root) + root->List(inDestFile); } } - } - - return result; -} - -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ -NS_IMETHODIMP -nsDebugObject::CompareFrameModels(const PRUnichar *aBasePath, const PRUnichar *aVerifyPath, - const PRUnichar *aBaseLineFileName, const PRUnichar *aVerifyFileName, PRUint32 aFlags) -{ -nsresult result = NS_ERROR_FAILURE; -nsCAutoString tempString; -nsCAutoString verifyFile; -char* baselineFilePath; -char* verifyFilePath; -FILE *bp,*vp; - - - tempString.AssignWithConversion(aBasePath); - tempString.AppendWithConversion(aBaseLineFileName); - baselineFilePath = ToNewCString(tempString); - - tempString.AssignWithConversion(aVerifyPath); - tempString.AppendWithConversion(aVerifyFileName); - verifyFilePath = ToNewCString(tempString); - - bp = fopen(baselineFilePath, "rt"); - if (bp) { - vp = fopen(verifyFilePath, "rt"); - if (vp) { - nsIFrameUtil* fu; - nsresult rv = nsComponentManager::CreateInstance(kFrameUtilCID, nsnull, - kIFrameUtilIID, (void **)&fu); - if (NS_SUCCEEDED(rv)) { - result = fu->CompareRegressionData(bp,vp,1); - } - fclose(vp); + else + { + fputs("null pres shell\n", inDestFile); + } + + // dump the frames of the sub documents + nsCOMPtr docShellAsNode(do_QueryInterface(inDocShell)); + PRInt32 numChildren; + docShellAsNode->GetChildCount(&numChildren); + for (PRInt32 i = 0; i < numChildren; i++) + { + nsCOMPtr child; + docShellAsNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + if (child) + DumpContentRecurse(childAsShell, inDestFile); } - fclose(bp); } - delete baselineFilePath; - delete verifyFilePath; - - return result; } -/* attribute boolean doRuntimeTests; */ -NS_IMETHODIMP -nsDebugObject::GetDoRuntimeTests(PRBool *aDoRuntimeTests) -{ - NS_ENSURE_ARG_POINTER(aDoRuntimeTests); - *aDoRuntimeTests = mRuntimeTestIsOn; - return NS_OK; -} -NS_IMETHODIMP -nsDebugObject::SetDoRuntimeTests(PRBool aDoRuntimeTests) -{ - mRuntimeTestIsOn = aDoRuntimeTests; - return NS_OK; -} -/* attribute short testId; */ -NS_IMETHODIMP -nsDebugObject::GetTestId(PRInt16 *aTestId) +void +nsDebugObject::DumpFramesRecurse(nsIDocShell* aDocShell, FILE* inDestFile) { - NS_ENSURE_ARG_POINTER(aTestId); - *aTestId = mRuntimeTestId; - return NS_OK; -} -NS_IMETHODIMP -nsDebugObject::SetTestId(PRInt16 aTestId) -{ - mRuntimeTestId = aTestId; - return NS_OK; -} + if (aDocShell) + { + fprintf(inDestFile, "webshell=%p \n", aDocShell); + + nsCOMPtr presShell; + aDocShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) + { + nsIFrame* root; + presShell->GetRootFrame(&root); + if (root) + { + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); -/* attribute boolean printAsIs; */ -NS_IMETHODIMP -nsDebugObject::GetPrintAsIs(PRBool *aPrintAsIs) -{ - NS_ENSURE_ARG_POINTER(aPrintAsIs); - *aPrintAsIs = mPrintAsIs; - return NS_OK; -} -NS_IMETHODIMP -nsDebugObject::SetPrintAsIs(PRBool aPrintAsIs) -{ - mPrintAsIs = aPrintAsIs; - return NS_OK; -} + nsIFrameDebug* fdbg; + if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) + fdbg->List(presContext, inDestFile, 0); + } + } + else + { + fputs("null pres shell\n", inDestFile); + } -/* attribute wstring printFileName; */ -NS_IMETHODIMP nsDebugObject::GetPrintFileName(PRUnichar * *aPrintFileName) -{ - *aPrintFileName = nsCRT::strdup(mFileName); - return NS_OK; -} -NS_IMETHODIMP nsDebugObject::SetPrintFileName(const PRUnichar * aPrintFileName) -{ - if (mFileName) { - nsMemory::Free(mFileName); + // dump the frames of the sub documents + nsCOMPtr docShellAsNode(do_QueryInterface(aDocShell)); + PRInt32 numChildren; + docShellAsNode->GetChildCount(&numChildren); + for (PRInt32 i = 0; i < numChildren; i++) + { + nsCOMPtr child; + docShellAsNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + if (childAsShell) + DumpFramesRecurse(childAsShell, inDestFile); + } } - mFileName = nsCRT::strdup(aPrintFileName); - return NS_OK; } + +void +nsDebugObject::DumpViewsRecurse(nsIDocShell* aDocShell, FILE* inDestFile) +{ + if (aDocShell) + { + fprintf(inDestFile, "webshell=%p \n", aDocShell); + + nsCOMPtr presShell; + aDocShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) + { + nsCOMPtr vm; + presShell->GetViewManager(getter_AddRefs(vm)); + if (vm) + { + nsIView* root; + vm->GetRootView(root); + if (root) + root->List(inDestFile); + } + } + else + { + fputs("null pres shell\n", inDestFile); + } + + // dump the frames of the sub documents + nsCOMPtr docShellAsNode(do_QueryInterface(aDocShell)); + PRInt32 numChildren; + docShellAsNode->GetChildCount(&numChildren); + for (PRInt32 i = 0; i < numChildren; i++) + { + nsCOMPtr child; + docShellAsNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + if (childAsShell) + DumpViewsRecurse(childAsShell, inDestFile); + } + } +} + diff --git a/mozilla/extensions/layout-debug/src/nsDebugObject.h b/mozilla/extensions/layout-debug/src/nsDebugObject.h index 6b00725313b..524fc0a7c3e 100644 --- a/mozilla/extensions/layout-debug/src/nsDebugObject.h +++ b/mozilla/extensions/layout-debug/src/nsDebugObject.h @@ -22,25 +22,46 @@ #ifndef nsDebugObject_h__ #define nsDebugObject_h__ -#include "nsIDebugObject.h" +#include "nsCOMPtr.h" + +#include "nsIFrameDebugObject.h" +#include "nsILayoutDebugger.h" + +class nsIDOMWindow; +class nsIPresShell; +class nsIDocShell; +class nsIDocShellTreeItem; //***************************************************************************** //*** nsDebugObject //***************************************************************************** -class nsDebugObject : public nsIDebugObject +class nsDebugObject : public nsIFrameDebugObject { public: NS_DECL_ISUPPORTS - NS_DECL_NSIDEBUGOBJECT + NS_DECL_NSIFRAMEDEBUGOBJECT nsDebugObject(); virtual ~nsDebugObject(); protected: - PRBool mRuntimeTestIsOn; - PRBool mPrintAsIs; - PRInt16 mRuntimeTestId; - PRUnichar* mFileName; + + nsresult EnsureLayoutDebugger(); + nsresult RefreshAllWindows(); + + nsresult GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell** outShell); + nsresult GetPresShellFromWindow(nsIDOMWindow* inWindow, nsIPresShell** outShell); + + void DumpAWebShell(nsIDocShellTreeItem* inShellItem, FILE* inDestFile, PRInt32 inIndent = 0); + void DumpMultipleWebShells(nsIDOMWindow* inWindow, FILE* inDestFile); + void DumpContentRecurse(nsIDocShell* inDocShell, FILE* inDestFile); + void DumpFramesRecurse(nsIDocShell* aDocShell, FILE* inDestFile); + void DumpViewsRecurse(nsIDocShell* aDocShell, FILE* inDestFile); + +protected: + + nsCOMPtr mLayoutDebugger; + }; diff --git a/mozilla/extensions/layout-debug/src/nsILayoutRegressionTester.idl b/mozilla/extensions/layout-debug/src/nsILayoutRegressionTester.idl new file mode 100644 index 00000000000..4eff5075737 --- /dev/null +++ b/mozilla/extensions/layout-debug/src/nsILayoutRegressionTester.idl @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Don Cone + * Sion Fraser + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsIDOMWindow; +interface nsILocalFile; + +[scriptable, uuid(1B4CD090-0531-11d6-A876-00105A183419)] +interface nsIFrameDebugObject : nsISupports +{ + + /** + * Output the given string to a file, optionally truncating the file first. + * @param aFile the file to output to + * @param aTruncateFile whether to trunate the file first + * @param aOutputString the string to write out + */ + void outputTextToFile(in nsILocalFile aFile, in boolean aTruncateFile, in string aOutputString); + + /** + * Dumps the content of a window + * @param aWindowToDump the window to dump (may be an iframe etc) + * @param aFile the file to dump to. It will be created if necessary, otherwise + truncated. If nil, write to stdout. + * @param aFlagsMask some flags that determine what to dump + * @param aFlagsMask some flags that determine what to dump + * @param aResult a status value indicating whether the dump happened, + whether the page was still loading, or whether some other error happened. + */ + const short DUMP_FLAGS_MASK_DEFAULT = 0; + const short DUMP_FLAGS_MASK_DUMP_STYLE = 1; + + const long DUMP_RESULT_COMPLETED = 0; // loaded OK + const long DUMP_RESULT_LOADING = 1; // still loading + const long DUMP_RESULT_ERROR = 2; // an error occurred + + long dumpFrameModel(in nsIDOMWindow aWindowToDump, in nsILocalFile aFile, in unsigned long aFlagsMask); + + /** + * Compares the contents of frame model files + * @param aBaseFile the baseline file, opened with read permissions + * @param aVerFile file containing the results to verify, opened with read permissions + * @param aFlags flags specifying output verbosity + * @param aResult result of the comparison: zero if the files are same, non-zero if different + */ + const short COMPARE_FLAGS_VERBOSE = 0; + const short COMPARE_FLAGS_BRIEF = 1; + long compareFrameModels(in nsILocalFile aBaseFile, in nsILocalFile aVerFile, in unsigned long aFlags); + + /** + * Methods to dump various types of data. In all casese, if aDestFile is nil, + * data is written to stdout. + */ + + void dumpContent(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + + void dumpFrames(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpViews(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpWebShells(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpStyleSheets(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpStyleContexts(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + void dumpReflowStats(in nsIDOMWindow aWindow, in nsILocalFile aDestFile); + + /** + * Turn reflow stats on or off for the given window. Requires that + * you built with MOZ_REFLOW_PERF=1 + */ + void setShowReflowStats(in nsIDOMWindow aWindow, in boolean inShow); + + attribute boolean showFrameBorders; // whether to show frame borders + attribute boolean showEventTargetFrameBorder; // whether to show event target frame borders + +}; + diff --git a/mozilla/extensions/layout-debug/src/nsLayoutDebugCIID.h b/mozilla/extensions/layout-debug/src/nsLayoutDebugCIID.h new file mode 100644 index 00000000000..928bc41bcd3 --- /dev/null +++ b/mozilla/extensions/layout-debug/src/nsLayoutDebugCIID.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsFrameDebugCIID_h__ +#define nsFrameDebugCIID_h__ + +#include "nsISupports.h" +#include "nsIFactory.h" +#include "nsIComponentManager.h" + +#define NS_FRAME_DEBUG_OBJECT_CID \ +{ 0x698c54f4, 0x4ea9, 0x11d7, \ +{ 0x85, 0x9f, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 } } + +#endif // nsFrameDebugCIID_h__ + diff --git a/mozilla/extensions/layout-debug/src/nsRegressionTester.cpp b/mozilla/extensions/layout-debug/src/nsRegressionTester.cpp index dc49ba842ea..8f418ed8026 100644 --- a/mozilla/extensions/layout-debug/src/nsRegressionTester.cpp +++ b/mozilla/extensions/layout-debug/src/nsRegressionTester.cpp @@ -42,13 +42,14 @@ #include "nsXPIDLString.h" #include "nsReadableUtils.h" -#include "nsIFileSpec.h" #include "nsIWindowWatcher.h" #include "nsVoidArray.h" #include "prmem.h" #include "nsIDocShellTreeItem.h" +#include "nsIDocShellTreeNode.h" #include "nsIDOMWindowInternal.h" #include "nsIPresShell.h" +#include "nsIDocument.h" #include "nsIDOMDocument.h" #include "nsIURI.h" #include "nsIDOMHTMLDocument.h" @@ -61,266 +62,614 @@ #include "nsIFrameUtil.h" #include "nsLayoutCID.h" #include "nsNetUtil.h" -#include "nsIFile.h" +#include "nsILocalFile.h" +#include "nsIPrefService.h" +#include "nsIViewManager.h" +#include "nsIView.h" +#include "nsIStyleSet.h" -NS_IMPL_ISUPPORTS1(nsDebugObject, nsIDebugObject) -static NS_DEFINE_IID(kFrameUtilCID, NS_FRAME_UTIL_CID); -static NS_DEFINE_IID(kIFrameUtilIID, NS_IFRAME_UTIL_IID); -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ -nsDebugObject::nsDebugObject() : - mRuntimeTestIsOn(PR_FALSE), - mPrintAsIs(PR_FALSE), - mRuntimeTestId(nsIDebugObject::PRT_RUNTIME_NONE), - mFileName(nsnull) +static NS_DEFINE_CID(kFrameUtilCID, NS_FRAME_UTIL_CID); +static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID); + + +nsDebugObject::nsDebugObject() { } -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ nsDebugObject::~nsDebugObject() { - if (mFileName) { - nsMemory::Free(mFileName); - } } -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ -NS_IMETHODIMP -nsDebugObject::CreateDirectory( const PRUnichar *aFilePath, PRUint32 aFlags) -{ - nsresult rv,result = NS_ERROR_FAILURE; - PRBool exists = PR_TRUE; +NS_IMPL_ISUPPORTS1(nsDebugObject, nsIFrameDebugObject) - nsCString dirStr; - dirStr.AssignWithConversion(aFilePath); - nsCOMPtr localFile; - rv = NS_GetFileFromURLSpec(dirStr, getter_AddRefs(localFile)); - if ( NS_SUCCEEDED(rv) ) { - rv = localFile->Exists(&exists); - if (!exists){ - rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0600); - if (NS_FAILED(rv)) { - printf("Failed to create directory [%s]\n", NS_LossyConvertUCS2toASCII(nsAutoString(aFilePath)).get()); - } - } else { - printf("OK - Directory Exists [%s]\n", NS_LossyConvertUCS2toASCII(nsAutoString(aFilePath)).get()); - } - } else { - printf("Failed to init path for local file in CreateDirectory [%s]\n", NS_LossyConvertUCS2toASCII(nsAutoString(aFilePath)).get()); - } - - return result; -} - -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ NS_IMETHODIMP -nsDebugObject::OutputTextToFile(PRBool aNewFile, const PRUnichar *aFilePath, const PRUnichar *aFileName, const PRUnichar *aOutputString) +nsDebugObject::OutputTextToFile(nsILocalFile *aFile, PRBool aTruncateFile, const char *aOutputString) { - nsresult result = NS_ERROR_FAILURE; - nsCAutoString outputPath; - outputPath.AssignWithConversion(aFilePath); - outputPath.AppendWithConversion(aFileName); - char* filePath = ToNewCString(outputPath); - FILE* fp; - - if ( aNewFile ) { - fp = fopen(filePath, "wt"); - } else { - fp = fopen(filePath, "at"); + NS_ENSURE_ARG(aOutputString); + + FILE* fp = stdout; + if (aFile) + { + const char* options = (aTruncateFile) ? "wt" : "at"; + nsresult rv = aFile->OpenANSIFileDesc(options, &fp); + if (NS_FAILED(rv)) return rv; } - if ( fp ) { - nsCAutoString outputString; - outputString.AssignWithConversion(aOutputString); - char* theOutput = ToNewCString(outputString); - fprintf(fp,theOutput); - fprintf(fp,"\n"); + fprintf(fp, aOutputString); + fprintf(fp, "\n"); + if (fp != stdout) fclose(fp); - delete filePath; - } - return result; + return NS_OK; } - -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ NS_IMETHODIMP -nsDebugObject::DumpContent(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags) +nsDebugObject::DumpFrameModel(nsIDOMWindow *aWindowToDump, nsILocalFile *aDestFile, PRUint32 aFlagsMask, PRInt32 *aResult) { -nsresult result = NS_ERROR_NOT_AVAILABLE; -PRUint32 busyFlags; -PRBool stillLoading; + NS_ENSURE_ARG(aWindowToDump); + NS_ENSURE_ARG_POINTER(aResult); - nsCOMPtr theInternWindow(do_QueryInterface(aWindow)); - if (theInternWindow) { + nsresult rv = NS_ERROR_NOT_AVAILABLE; + PRUint32 busyFlags; + PRBool stillLoading; + + *aResult = DUMP_RESULT_ERROR; + + nsCOMPtr docShell; + rv = GetDocShellFromWindow(aWindowToDump, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + // find out if the document is loaded + docShell->GetBusyFlags(&busyFlags); + stillLoading = busyFlags && (nsIDocShell::BUSY_FLAGS_BUSY | nsIDocShell::BUSY_FLAGS_PAGE_LOADING); + if (stillLoading) + { + *aResult = DUMP_RESULT_LOADING; + return NS_OK; + } + + nsCOMPtr presShell; + docShell->GetPresShell(getter_AddRefs(presShell)); + + nsIFrame* root; + presShell->GetRootFrame(&root); + + nsIFrameDebug* fdbg; + rv = CallQueryInterface(root, &fdbg); + if (NS_FAILED(rv)) return rv; + + PRBool dumpStyle = (aFlagsMask & DUMP_FLAGS_MASK_DUMP_STYLE) != 0; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); + + fdbg->DumpRegressionData(presContext, fp, 0, dumpStyle); + if (fp != stdout) + fclose(fp); + + *aResult = DUMP_RESULT_COMPLETED; + return NS_OK; +} + +/* void dumpContent (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpContent(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + DumpContentRecurse(docShell, fp); + DumpMultipleWebShells(aWindow, fp); + + if (fp != stdout) + fclose(fp); + return NS_OK; +} + +/* void dumpFrames (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpFrames(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + DumpFramesRecurse(docShell, fp); + DumpMultipleWebShells(aWindow, fp); + + if (fp != stdout) + fclose(fp); + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::DumpViews(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (NS_FAILED(rv)) return rv; + + FILE* fp = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &fp); + if (NS_FAILED(rv)) return rv; + } + + DumpViewsRecurse(docShell, fp); + DumpMultipleWebShells(aWindow, fp); + + if (fp != stdout) + fclose(fp); + return NS_OK; +} + +/* void dumpWebShells (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpWebShells(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr docShell; + nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + nsCOMPtr shellAsItem(do_QueryInterface(docShell)); + if (!shellAsItem) return NS_ERROR_FAILURE; + + FILE* outFile = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &outFile); + if (NS_FAILED(rv)) return rv; + } + + DumpAWebShell(shellAsItem, outFile); + if (outFile != stdout) + fclose(outFile); + + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::DumpStyleSheets(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + + FILE* outFile = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &outFile); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr styleSet; + presShell->GetStyleSet(getter_AddRefs(styleSet)); + if (styleSet) + styleSet->List(outFile); + else + fputs("null style set\n", outFile); + + if (outFile != stdout) + fclose(outFile); + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::DumpStyleContexts(nsIDOMWindow *aWindow, nsILocalFile *aDestFile) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + + FILE* outFile = stdout; + if (aDestFile) + { + rv = aDestFile->OpenANSIFileDesc("w", &outFile); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr styleSet; + presShell->GetStyleSet(getter_AddRefs(styleSet)); + if (styleSet) + { + nsIFrame* root; + presShell->GetRootFrame(&root); + if (root) + fputs("null root frame\n", outFile); + else + styleSet->ListContexts(root, outFile); + } + else + fputs("null style set\n", outFile); + + if (outFile != stdout) + fclose(outFile); + return NS_OK; +} + +/* void dumpReflowStats (in nsIDOMWindow aWindow, in nsILocalFile aDestFile); */ +NS_IMETHODIMP +nsDebugObject::DumpReflowStats(nsIDOMWindow *aWindow, nsILocalFile* /* aDestFile */) +{ + NS_ENSURE_ARG(aWindow); + + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + +#ifdef MOZ_REFLOW_PERF + presShell->DumpReflows(); +#else + fprintf(stdout, "***********************************\n"); + fprintf(stdout, "Sorry, you haven't built with MOZ_REFLOW_PERF=1\n"); + fprintf(stdout, "***********************************\n"); +#endif + + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::CompareFrameModels(nsILocalFile *aBaseFile, nsILocalFile *aVerFile, PRUint32 aFlags, PRInt32 *aResult) +{ + NS_ENSURE_ARG(aBaseFile); + NS_ENSURE_ARG(aVerFile); + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = NS_OK; + + nsresult rv; + FILE* baseFile; + rv = aBaseFile->OpenANSIFileDesc("r", &baseFile); + if (NS_FAILED(rv)) return rv; + + FILE* verFile; + rv = aVerFile->OpenANSIFileDesc("r", &verFile); + if (NS_FAILED(rv)) { + fclose(baseFile); + return rv; + } + + nsCOMPtr frameUtil = do_CreateInstance(kFrameUtilCID, &rv); + if (NS_SUCCEEDED(rv)) + { + PRInt32 outputLevel = (aFlags == COMPARE_FLAGS_VERBOSE) ? 0 : 1; + rv = frameUtil->CompareRegressionData(baseFile, verFile, outputLevel); + } + fclose(verFile); + fclose(baseFile); + + *aResult = NS_FAILED(rv); + return NS_OK; +} + +NS_IMETHODIMP +nsDebugObject::GetShowFrameBorders(PRBool *aShowFrameBorders) +{ + NS_ENSURE_ARG_POINTER(aShowFrameBorders); + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + return mLayoutDebugger->GetShowFrameBorders(aShowFrameBorders); +} + +NS_IMETHODIMP +nsDebugObject::SetShowFrameBorders(PRBool aShowFrameBorders) +{ + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + nsresult rv = mLayoutDebugger->SetShowFrameBorders(aShowFrameBorders); + RefreshAllWindows(); + return rv; +} + +NS_IMETHODIMP +nsDebugObject::GetShowEventTargetFrameBorder(PRBool *aShowEventTargetFrameBorder) +{ + NS_ENSURE_ARG_POINTER(aShowEventTargetFrameBorder); + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + return mLayoutDebugger->GetShowEventTargetFrameBorder(aShowEventTargetFrameBorder); +} + +NS_IMETHODIMP +nsDebugObject::SetShowEventTargetFrameBorder(PRBool aShowEventTargetFrameBorder) +{ + NS_ENSURE_SUCCESS(EnsureLayoutDebugger(), NS_ERROR_FAILURE); + nsresult rv = mLayoutDebugger->SetShowEventTargetFrameBorder(aShowEventTargetFrameBorder); + RefreshAllWindows(); + return rv; +} + +NS_IMETHODIMP +nsDebugObject::SetShowReflowStats(nsIDOMWindow *aWindow, PRBool inShow) +{ + nsCOMPtr presShell; + nsresult rv = GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); + if (NS_FAILED(rv)) return rv; + +#ifdef MOZ_REFLOW_PERF + presShell->SetPaintFrameCount(inShow); +#else + printf("***********************************************\n"); + printf("Sorry, you haven't built with MOZ_REFLOW_PERF=1\n"); + printf("***********************************************\n"); +#endif + + return NS_OK; +} + +nsresult +nsDebugObject::EnsureLayoutDebugger() +{ + if (!mLayoutDebugger) + { + nsresult rv; + mLayoutDebugger = do_CreateInstance(kLayoutDebuggerCID, &rv); + if (NS_FAILED(rv)) + return rv; + } + + return NS_OK; +} + +nsresult +nsDebugObject::RefreshAllWindows() +{ + nsresult rv; + // hack. Toggle the underline links pref to get stuff to redisplay + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) + { + PRBool underlineLinksPref; + rv = prefBranch->GetBoolPref("browser.underline_anchors", &underlineLinksPref); + if (NS_SUCCEEDED(rv)) + { + prefBranch->SetBoolPref("browser.underline_anchors", !underlineLinksPref); + prefBranch->SetBoolPref("browser.underline_anchors", underlineLinksPref); + } + } + return NS_OK; +} + + +nsresult +nsDebugObject::GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell** outShell) +{ + nsCOMPtr scriptObj(do_QueryInterface(inWindow)); + if (!scriptObj) return NS_ERROR_FAILURE; + + return scriptObj->GetDocShell(outShell); +} + + +nsresult +nsDebugObject::GetPresShellFromWindow(nsIDOMWindow* inWindow, nsIPresShell** outShell) +{ + nsCOMPtr docShell; + GetDocShellFromWindow(inWindow, getter_AddRefs(docShell)); + if (!docShell) return NS_ERROR_FAILURE; + + nsresult rv = docShell->GetPresShell(outShell); + if (NS_FAILED(rv)) return rv; + if (!*outShell) return NS_ERROR_FAILURE; + + return NS_OK; +} + +#if 0 +#pragma mark - +#endif + +void +nsDebugObject::DumpMultipleWebShells(nsIDOMWindow* aWindow, FILE* aOut) +{ + nsCOMPtr docShell; + GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + if (!docShell) return; + + PRInt32 count; + nsCOMPtr docShellAsNode(do_QueryInterface(docShell)); + if (docShellAsNode) { + docShellAsNode->GetChildCount(&count); + if (count > 0) { + nsCOMPtr docShellAsStupidItem(do_QueryInterface(docShell)); + fprintf(aOut, "webshells= \n"); + DumpAWebShell(docShellAsStupidItem, aOut); + } + } +} + + +void +nsDebugObject::DumpAWebShell(nsIDocShellTreeItem* aShellItem, FILE* aOut, PRInt32 aIndent) +{ + nsXPIDLString name; + nsAutoString str; + nsCOMPtr parent; + PRInt32 i; + + for (i = aIndent; --i >= 0; ) fprintf(aOut, " "); + + fprintf(aOut, "%p '", aShellItem); + aShellItem->GetName(getter_Copies(name)); + aShellItem->GetSameTypeParent(getter_AddRefs(parent)); + str.Assign(name); + fputs(NS_LossyConvertUCS2toASCII(str).get(), aOut); + fprintf(aOut, "' parent=%p <\n", parent.get()); + + aIndent++; + nsCOMPtr shellAsNode(do_QueryInterface(aShellItem)); + + PRInt32 numChildren; + shellAsNode->GetChildCount(&numChildren); + for (i = 0; i < numChildren; i++) { + nsCOMPtr child; + shellAsNode->GetChildAt(i, getter_AddRefs(child)); + if (child) { + DumpAWebShell(child, aOut, aIndent); + } + } + aIndent--; + for (i = aIndent; --i >= 0; ) fprintf(aOut, " "); + fputs(">\n", aOut); +} + + +void +nsDebugObject::DumpContentRecurse(nsIDocShell* inDocShell, FILE* inDestFile) +{ + if (inDocShell) + { + fprintf(inDestFile, "docshell=%p \n", inDocShell); nsCOMPtr presShell; - if (theInternWindow != nsnull) { - nsIFrameDebug* fdbg; - nsIFrame* root; - nsIPresContext *thePC; - - nsCOMPtr scriptObj(do_QueryInterface(theInternWindow)); - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); - - // find out if the document is loaded - docShell->GetBusyFlags(&busyFlags); - stillLoading = busyFlags && (nsIDocShell::BUSY_FLAGS_BUSY | nsIDocShell::BUSY_FLAGS_PAGE_LOADING); - - if ( !stillLoading ) { - docShell->GetPresShell(getter_AddRefs(presShell)); - presShell->GetRootFrame(&root); - if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { - // create the string for the output - nsCAutoString outputPath; - outputPath.AssignWithConversion(aFilePath); - outputPath.AppendWithConversion(aFileName); - char* filePath = ToNewCString(outputPath); - PRBool dumpStyle=PR_FALSE; - - if(aFlags){ - dumpStyle = PR_TRUE; - } - - FILE* fp = fopen(filePath, "wt"); - - if ( fp ) { - presShell->GetPresContext(&thePC); - - fdbg->DumpRegressionData(thePC, fp, 0, dumpStyle); - fclose(fp); - delete filePath; - result = NS_OK; // the document is now loaded, and the frames are dumped. - } else { - - result = NS_ERROR_FILE_INVALID_PATH; - } - } + inDocShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) + { + nsCOMPtr doc; + presShell->GetDocument(getter_AddRefs(doc)); + if (doc) + { + nsCOMPtr root; + doc->GetRootContent(getter_AddRefs(root)); + if (root) + root->List(inDestFile); } } - } - - return result; -} - -/** --------------------------------------------------- - * See documentation in nsDebugObject.h - * @update 5/16/02 dwc - */ -NS_IMETHODIMP -nsDebugObject::CompareFrameModels(const PRUnichar *aBasePath, const PRUnichar *aVerifyPath, - const PRUnichar *aBaseLineFileName, const PRUnichar *aVerifyFileName, PRUint32 aFlags) -{ -nsresult result = NS_ERROR_FAILURE; -nsCAutoString tempString; -nsCAutoString verifyFile; -char* baselineFilePath; -char* verifyFilePath; -FILE *bp,*vp; - - - tempString.AssignWithConversion(aBasePath); - tempString.AppendWithConversion(aBaseLineFileName); - baselineFilePath = ToNewCString(tempString); - - tempString.AssignWithConversion(aVerifyPath); - tempString.AppendWithConversion(aVerifyFileName); - verifyFilePath = ToNewCString(tempString); - - bp = fopen(baselineFilePath, "rt"); - if (bp) { - vp = fopen(verifyFilePath, "rt"); - if (vp) { - nsIFrameUtil* fu; - nsresult rv = nsComponentManager::CreateInstance(kFrameUtilCID, nsnull, - kIFrameUtilIID, (void **)&fu); - if (NS_SUCCEEDED(rv)) { - result = fu->CompareRegressionData(bp,vp,1); - } - fclose(vp); + else + { + fputs("null pres shell\n", inDestFile); + } + + // dump the frames of the sub documents + nsCOMPtr docShellAsNode(do_QueryInterface(inDocShell)); + PRInt32 numChildren; + docShellAsNode->GetChildCount(&numChildren); + for (PRInt32 i = 0; i < numChildren; i++) + { + nsCOMPtr child; + docShellAsNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + if (child) + DumpContentRecurse(childAsShell, inDestFile); } - fclose(bp); } - delete baselineFilePath; - delete verifyFilePath; - - return result; } -/* attribute boolean doRuntimeTests; */ -NS_IMETHODIMP -nsDebugObject::GetDoRuntimeTests(PRBool *aDoRuntimeTests) -{ - NS_ENSURE_ARG_POINTER(aDoRuntimeTests); - *aDoRuntimeTests = mRuntimeTestIsOn; - return NS_OK; -} -NS_IMETHODIMP -nsDebugObject::SetDoRuntimeTests(PRBool aDoRuntimeTests) -{ - mRuntimeTestIsOn = aDoRuntimeTests; - return NS_OK; -} -/* attribute short testId; */ -NS_IMETHODIMP -nsDebugObject::GetTestId(PRInt16 *aTestId) +void +nsDebugObject::DumpFramesRecurse(nsIDocShell* aDocShell, FILE* inDestFile) { - NS_ENSURE_ARG_POINTER(aTestId); - *aTestId = mRuntimeTestId; - return NS_OK; -} -NS_IMETHODIMP -nsDebugObject::SetTestId(PRInt16 aTestId) -{ - mRuntimeTestId = aTestId; - return NS_OK; -} + if (aDocShell) + { + fprintf(inDestFile, "webshell=%p \n", aDocShell); + + nsCOMPtr presShell; + aDocShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) + { + nsIFrame* root; + presShell->GetRootFrame(&root); + if (root) + { + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); -/* attribute boolean printAsIs; */ -NS_IMETHODIMP -nsDebugObject::GetPrintAsIs(PRBool *aPrintAsIs) -{ - NS_ENSURE_ARG_POINTER(aPrintAsIs); - *aPrintAsIs = mPrintAsIs; - return NS_OK; -} -NS_IMETHODIMP -nsDebugObject::SetPrintAsIs(PRBool aPrintAsIs) -{ - mPrintAsIs = aPrintAsIs; - return NS_OK; -} + nsIFrameDebug* fdbg; + if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) + fdbg->List(presContext, inDestFile, 0); + } + } + else + { + fputs("null pres shell\n", inDestFile); + } -/* attribute wstring printFileName; */ -NS_IMETHODIMP nsDebugObject::GetPrintFileName(PRUnichar * *aPrintFileName) -{ - *aPrintFileName = nsCRT::strdup(mFileName); - return NS_OK; -} -NS_IMETHODIMP nsDebugObject::SetPrintFileName(const PRUnichar * aPrintFileName) -{ - if (mFileName) { - nsMemory::Free(mFileName); + // dump the frames of the sub documents + nsCOMPtr docShellAsNode(do_QueryInterface(aDocShell)); + PRInt32 numChildren; + docShellAsNode->GetChildCount(&numChildren); + for (PRInt32 i = 0; i < numChildren; i++) + { + nsCOMPtr child; + docShellAsNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + if (childAsShell) + DumpFramesRecurse(childAsShell, inDestFile); + } } - mFileName = nsCRT::strdup(aPrintFileName); - return NS_OK; } + +void +nsDebugObject::DumpViewsRecurse(nsIDocShell* aDocShell, FILE* inDestFile) +{ + if (aDocShell) + { + fprintf(inDestFile, "webshell=%p \n", aDocShell); + + nsCOMPtr presShell; + aDocShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) + { + nsCOMPtr vm; + presShell->GetViewManager(getter_AddRefs(vm)); + if (vm) + { + nsIView* root; + vm->GetRootView(root); + if (root) + root->List(inDestFile); + } + } + else + { + fputs("null pres shell\n", inDestFile); + } + + // dump the frames of the sub documents + nsCOMPtr docShellAsNode(do_QueryInterface(aDocShell)); + PRInt32 numChildren; + docShellAsNode->GetChildCount(&numChildren); + for (PRInt32 i = 0; i < numChildren; i++) + { + nsCOMPtr child; + docShellAsNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + if (childAsShell) + DumpViewsRecurse(childAsShell, inDestFile); + } + } +} + diff --git a/mozilla/extensions/layout-debug/src/nsRegressionTester.h b/mozilla/extensions/layout-debug/src/nsRegressionTester.h index 6b00725313b..524fc0a7c3e 100644 --- a/mozilla/extensions/layout-debug/src/nsRegressionTester.h +++ b/mozilla/extensions/layout-debug/src/nsRegressionTester.h @@ -22,25 +22,46 @@ #ifndef nsDebugObject_h__ #define nsDebugObject_h__ -#include "nsIDebugObject.h" +#include "nsCOMPtr.h" + +#include "nsIFrameDebugObject.h" +#include "nsILayoutDebugger.h" + +class nsIDOMWindow; +class nsIPresShell; +class nsIDocShell; +class nsIDocShellTreeItem; //***************************************************************************** //*** nsDebugObject //***************************************************************************** -class nsDebugObject : public nsIDebugObject +class nsDebugObject : public nsIFrameDebugObject { public: NS_DECL_ISUPPORTS - NS_DECL_NSIDEBUGOBJECT + NS_DECL_NSIFRAMEDEBUGOBJECT nsDebugObject(); virtual ~nsDebugObject(); protected: - PRBool mRuntimeTestIsOn; - PRBool mPrintAsIs; - PRInt16 mRuntimeTestId; - PRUnichar* mFileName; + + nsresult EnsureLayoutDebugger(); + nsresult RefreshAllWindows(); + + nsresult GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell** outShell); + nsresult GetPresShellFromWindow(nsIDOMWindow* inWindow, nsIPresShell** outShell); + + void DumpAWebShell(nsIDocShellTreeItem* inShellItem, FILE* inDestFile, PRInt32 inIndent = 0); + void DumpMultipleWebShells(nsIDOMWindow* inWindow, FILE* inDestFile); + void DumpContentRecurse(nsIDocShell* inDocShell, FILE* inDestFile); + void DumpFramesRecurse(nsIDocShell* aDocShell, FILE* inDestFile); + void DumpViewsRecurse(nsIDocShell* aDocShell, FILE* inDestFile); + +protected: + + nsCOMPtr mLayoutDebugger; + };