2000-01-24 15:28:05 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* 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 Netscape are
|
|
|
|
* Copyright (C) 2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Main Composer window debug menu functions */
|
|
|
|
|
|
|
|
// --------------------------- Output ---------------------------
|
|
|
|
|
2000-09-07 18:40:14 +00:00
|
|
|
|
|
|
|
function EditorSerialize()
|
|
|
|
{
|
|
|
|
var s = new XMLSerializer();
|
|
|
|
dump(s.serializeToString(editorShell.editorDocument) + "\n");
|
|
|
|
}
|
|
|
|
|
2000-01-24 15:28:05 +00:00
|
|
|
function EditorGetText()
|
|
|
|
{
|
|
|
|
if (editorShell) {
|
|
|
|
dump("Getting text\n");
|
|
|
|
var outputText = editorShell.GetContentsAs("text/plain", 2);
|
2000-05-01 21:49:52 +00:00
|
|
|
dump("<<" + outputText + ">>\n");
|
2000-01-24 15:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorGetHTML()
|
|
|
|
{
|
|
|
|
if (editorShell) {
|
|
|
|
dump("Getting HTML\n");
|
2000-03-28 00:10:44 +00:00
|
|
|
var outputHTML = editorShell.GetContentsAs("text/html", 256);
|
2000-01-24 15:28:05 +00:00
|
|
|
dump(outputHTML + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorDumpContent()
|
|
|
|
{
|
|
|
|
if (window.editorShell) {
|
|
|
|
dump("============== Content Tree: ================\n");
|
|
|
|
window.editorShell.DumpContentTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorInsertText(textToInsert)
|
|
|
|
{
|
|
|
|
editorShell.InsertText(textToInsert);
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorTestSelection()
|
|
|
|
{
|
|
|
|
dump("Testing selection\n");
|
|
|
|
var selection = editorShell.editorSelection;
|
|
|
|
if (!selection)
|
|
|
|
{
|
|
|
|
dump("No selection!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump("Selection contains:\n");
|
2000-05-16 05:12:57 +00:00
|
|
|
// 3rd param = column to wrap
|
|
|
|
dump(selection.toString("text/plain", gOutputFormatted & gOutputSelectionOnly, 0) + "\n");
|
2000-01-24 15:28:05 +00:00
|
|
|
|
|
|
|
var output;
|
|
|
|
|
|
|
|
dump("====== Selection as unformatted text ==========\n");
|
|
|
|
output = editorShell.GetContentsAs("text/plain", 1);
|
|
|
|
dump(output + "\n\n");
|
|
|
|
|
|
|
|
dump("====== Selection as formatted text ============\n");
|
|
|
|
output = editorShell.GetContentsAs("text/plain", 3);
|
|
|
|
dump(output + "\n\n");
|
|
|
|
|
|
|
|
dump("====== Selection as HTML ======================\n");
|
|
|
|
output = editorShell.GetContentsAs("text/html", 1);
|
|
|
|
dump(output + "\n\n");
|
|
|
|
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
dump("====== Selection as prettyprinted HTML ========\n");
|
|
|
|
output = editorShell.GetContentsAs("text/html", 3);
|
|
|
|
dump(output + "\n\n");
|
|
|
|
|
2000-01-24 15:28:05 +00:00
|
|
|
dump("====== Length and status =====================\n");
|
|
|
|
output = "Document is ";
|
|
|
|
if (editorShell.documentIsEmpty)
|
|
|
|
output += "empty\n";
|
|
|
|
else
|
|
|
|
output += "not empty\n";
|
|
|
|
output += "Document length is " + editorShell.documentLength + " characters";
|
|
|
|
dump(output + "\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorTestTableLayout()
|
|
|
|
{
|
2000-03-21 06:05:24 +00:00
|
|
|
dump("\n\n\n************ Dump Selection Ranges ************\n");
|
|
|
|
var selection = editorShell.editorSelection;
|
|
|
|
for (i = 0; i < selection.rangeCount; i++)
|
|
|
|
{
|
|
|
|
var range = selection.getRangeAt(i);
|
|
|
|
if (range)
|
|
|
|
{
|
|
|
|
dump("Range "+i+": StartParent="+range.startParent+", offset="+range.startOffset+"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dump("\n\n");
|
|
|
|
|
2000-01-24 15:28:05 +00:00
|
|
|
var table = editorShell.GetElementOrParentByTagName("table", null);
|
|
|
|
if (!table) {
|
|
|
|
dump("Enclosing Table not found: Place caret in a table cell to do this test\n\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cell;
|
|
|
|
var startRowIndexObj = new Object();
|
|
|
|
var startColIndexObj = new Object();
|
|
|
|
var rowSpanObj = new Object();
|
|
|
|
var colSpanObj = new Object();
|
2000-01-26 14:57:43 +00:00
|
|
|
var actualRowSpanObj = new Object();
|
|
|
|
var actualColSpanObj = new Object();
|
2000-01-24 15:28:05 +00:00
|
|
|
var isSelectedObj = new Object();
|
|
|
|
var startRowIndex = 0;
|
|
|
|
var startColIndex = 0;
|
|
|
|
var rowSpan;
|
|
|
|
var colSpan;
|
2000-01-26 14:57:43 +00:00
|
|
|
var actualRowSpan;
|
|
|
|
var actualColSpan;
|
2000-01-24 15:28:05 +00:00
|
|
|
var isSelected;
|
|
|
|
var col = 0;
|
|
|
|
var row = 0;
|
|
|
|
var rowCount = 0;
|
|
|
|
var maxColCount = 0;
|
|
|
|
var doneWithRow = false;
|
|
|
|
var doneWithCol = false;
|
|
|
|
|
|
|
|
dump("\n\n\n************ Starting Table Layout test ************\n");
|
|
|
|
|
|
|
|
// Note: We could also get the number of rows, cols and use for loops,
|
|
|
|
// but this tests using out-of-bounds offsets to detect end of row or column
|
|
|
|
|
|
|
|
while (!doneWithRow) // Iterate through rows
|
|
|
|
{
|
2000-01-26 14:57:43 +00:00
|
|
|
dump("* Data for ROW="+row+":\n");
|
2000-01-24 15:28:05 +00:00
|
|
|
while(!doneWithCol) // Iterate through cells in the row
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
cell = editorShell.GetCellDataAt(table, row, col, startRowIndexObj, startColIndexObj,
|
2000-01-26 14:57:43 +00:00
|
|
|
rowSpanObj, colSpanObj, actualRowSpanObj, actualColSpanObj,
|
|
|
|
isSelectedObj);
|
2000-01-24 15:28:05 +00:00
|
|
|
|
|
|
|
if (cell)
|
|
|
|
{
|
|
|
|
rowSpan = rowSpanObj.value;
|
|
|
|
colSpan = colSpanObj.value;
|
2000-01-26 14:57:43 +00:00
|
|
|
actualRowSpan = actualRowSpanObj.value;
|
|
|
|
actualColSpan = actualColSpanObj.value;
|
2000-01-24 15:28:05 +00:00
|
|
|
isSelected = isSelectedObj.value;
|
|
|
|
|
2000-01-26 14:57:43 +00:00
|
|
|
dump(" Row="+row+", Col="+col+" StartRow="+startRowIndexObj.value+", StartCol="+startColIndexObj.value+"\n");
|
|
|
|
dump(" RowSpan="+rowSpan+", ColSpan="+colSpan+" ActualRowSpan="+actualRowSpan+", ActualColSpan="+actualColSpan);
|
2000-01-24 15:28:05 +00:00
|
|
|
if (isSelected)
|
|
|
|
dump(" Cell is selected\n");
|
|
|
|
else
|
|
|
|
dump(" Cell is NOT selected\n");
|
|
|
|
|
|
|
|
// Save the indexes of a cell that will span across the cellmap grid
|
|
|
|
if (rowSpan > 1)
|
|
|
|
startRowIndex = startRowIndexObj.value;
|
|
|
|
if (colSpan > 1)
|
|
|
|
startColIndex = startColIndexObj.value;
|
|
|
|
|
|
|
|
// Initialize these for efficient spanned-cell search
|
|
|
|
startRowIndexObj.value = startRowIndex;
|
|
|
|
startColIndexObj.value = startColIndex;
|
|
|
|
|
|
|
|
col++;
|
|
|
|
} else {
|
|
|
|
doneWithCol = true;
|
|
|
|
// Get maximum number of cells in any row
|
|
|
|
if (col > maxColCount)
|
|
|
|
maxColCount = col;
|
2000-01-26 14:57:43 +00:00
|
|
|
dump(" End of row found\n\n");
|
2000-01-24 15:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2000-01-26 22:57:35 +00:00
|
|
|
dump(" *** GetCellDataAt failed at Row="+row+", Col="+col+" ***\n\n");
|
2000-01-26 14:57:43 +00:00
|
|
|
return;
|
2000-01-24 15:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (col == 0) {
|
|
|
|
// Didn't find a cell in the first col of a row,
|
|
|
|
// thus no more rows in table
|
|
|
|
doneWithRow = true;
|
|
|
|
rowCount = row;
|
|
|
|
dump("No more rows in table\n\n");
|
|
|
|
} else {
|
|
|
|
// Setup for next row
|
|
|
|
col = 0;
|
|
|
|
row++;
|
|
|
|
doneWithCol = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dump("Counted during scan: Number of rows="+rowCount+" Number of Columns="+maxColCount+"\n");
|
|
|
|
rowCount = editorShell.GetTableRowCount(table);
|
|
|
|
maxColCount = editorShell.GetTableColumnCount(table);
|
|
|
|
dump("From nsITableLayout: Number of rows="+rowCount+" Number of Columns="+maxColCount+"\n****** End of Table Layout Test *****\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorShowEmbeddedObjects()
|
|
|
|
{
|
|
|
|
dump("\nEmbedded Objects:\n");
|
|
|
|
var objectArray = editorShell.GetEmbeddedObjects();
|
|
|
|
dump(objectArray.Count() + " embedded objects\n");
|
|
|
|
for (var i=0; i < objectArray.Count(); ++i)
|
|
|
|
dump(objectArray.GetElementAt(i) + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorUnitTests()
|
|
|
|
{
|
|
|
|
dump("Running Unit Tests\n");
|
|
|
|
editorShell.RunUnitTests();
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorTestDocument()
|
|
|
|
{
|
|
|
|
dump("Getting document\n");
|
|
|
|
var theDoc = editorShell.editorDocument;
|
|
|
|
if (theDoc)
|
|
|
|
{
|
|
|
|
dump("Got the doc\n");
|
|
|
|
dump("Document name:" + theDoc.nodeName + "\n");
|
|
|
|
dump("Document type:" + theDoc.doctype + "\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dump("Failed to get the doc\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------- Logging stuff ---------------------------
|
|
|
|
|
|
|
|
function EditorExecuteScript(fileSpec)
|
|
|
|
{
|
|
|
|
fileSpec.openStreamForReading();
|
|
|
|
|
|
|
|
var buf = { value:null };
|
|
|
|
var tmpBuf = { value:null };
|
|
|
|
var didTruncate = { value:false };
|
|
|
|
var lineNum = 0;
|
|
|
|
var ex;
|
|
|
|
|
|
|
|
// Log files can be quite huge, so read in a line
|
|
|
|
// at a time and execute it:
|
|
|
|
|
|
|
|
while (!fileSpec.eof())
|
|
|
|
{
|
|
|
|
buf.value = "";
|
|
|
|
didTruncate.value = true;
|
|
|
|
|
|
|
|
// Keep looping until we get a complete line of
|
|
|
|
// text, or we hit the end of file:
|
|
|
|
|
|
|
|
while (didTruncate.value && !fileSpec.eof())
|
|
|
|
{
|
|
|
|
didTruncate.value = false;
|
|
|
|
fileSpec.readLine(tmpBuf, 1024, didTruncate);
|
|
|
|
buf.value += tmpBuf.value;
|
|
|
|
|
|
|
|
// XXX Need to null out tmpBuf.value to avoid crashing
|
|
|
|
// XXX in some JavaScript string allocation method.
|
|
|
|
// XXX This is probably leaking the buffer allocated
|
|
|
|
// XXX by the readLine() implementation.
|
|
|
|
|
|
|
|
tmpBuf.value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
++lineNum;
|
|
|
|
|
|
|
|
try { eval(buf.value); }
|
|
|
|
catch(ex) { dump("Playback ERROR: Line " + lineNum + " " + ex + "\n"); return; }
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorGetScriptFileSpec()
|
|
|
|
{
|
2000-09-13 23:57:52 +00:00
|
|
|
var fs = Components.classes["@mozilla.org/filespec;1"].createInstance();
|
2000-01-24 15:28:05 +00:00
|
|
|
fs = fs.QueryInterface(Components.interfaces.nsIFileSpec);
|
|
|
|
fs.unixStyleFilePath = "journal.js";
|
|
|
|
return fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorStartLog()
|
|
|
|
{
|
|
|
|
var fs;
|
|
|
|
|
|
|
|
fs = EditorGetScriptFileSpec();
|
|
|
|
editorShell.StartLogging(fs);
|
2000-06-22 00:48:45 +00:00
|
|
|
window._content.focus();
|
2000-01-24 15:28:05 +00:00
|
|
|
|
|
|
|
fs = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorStopLog()
|
|
|
|
{
|
|
|
|
editorShell.StopLogging();
|
2000-06-22 00:48:45 +00:00
|
|
|
window._content.focus();
|
2000-01-24 15:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function EditorRunLog()
|
|
|
|
{
|
|
|
|
var fs;
|
|
|
|
fs = EditorGetScriptFileSpec();
|
|
|
|
EditorExecuteScript(fs);
|
2000-06-22 00:48:45 +00:00
|
|
|
window._content.focus();
|
2000-01-24 15:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|