2001-09-25 22:53:13 +00:00
|
|
|
/* -*- 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
|
1999-08-19 13:19:10 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* 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/
|
1999-08-19 13:19:10 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* 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.
|
1999-08-19 13:19:10 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* 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.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* Contributor(s):
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-25 22:53:13 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMAttr.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsIDOMCharacterData.h"
|
|
|
|
#include "nsIDOMNamedNodeMap.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
1999-08-19 13:19:10 +00:00
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsHTMLEditorLog.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsEditorTxnLog.h"
|
|
|
|
|
|
|
|
#define LOCK_LOG(doc)
|
|
|
|
#define UNLOCK_LOG(doc)
|
|
|
|
|
|
|
|
nsHTMLEditorLog::nsHTMLEditorLog()
|
|
|
|
{
|
|
|
|
mLocked = -1;
|
|
|
|
mEditorTxnLog = 0;
|
2001-01-09 22:47:02 +00:00
|
|
|
|
|
|
|
NS_INIT_ISUPPORTS();
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLEditorLog::~nsHTMLEditorLog()
|
|
|
|
{
|
|
|
|
StopLogging();
|
|
|
|
}
|
|
|
|
|
2001-10-02 03:18:08 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLEditorLog, nsHTMLEditor, nsIEditorLogging)
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::SetInlineProperty(nsIAtom *aProperty, const nsAReadableString &aAttribute, const nsAReadableString &aValue)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoString propStr;
|
|
|
|
|
|
|
|
aProperty->ToString(propStr);
|
|
|
|
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.SetTextProperty(\"");
|
|
|
|
PrintUnicode(propStr);
|
|
|
|
Write("\", \"");
|
2001-04-07 00:45:26 +00:00
|
|
|
if (aAttribute.Length())
|
|
|
|
PrintUnicode(aAttribute);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\", \"");
|
2001-04-07 00:45:26 +00:00
|
|
|
if (aValue.Length())
|
|
|
|
PrintUnicode(aValue);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetInlineProperty(aProperty, aAttribute, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-02 23:19:29 +00:00
|
|
|
nsHTMLEditorLog::SetParagraphFormat(const nsAString& aParagraphFormat)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
1999-12-22 19:44:00 +00:00
|
|
|
Write("window.editorShell.SetParagraphFormat(\"");
|
1999-08-19 13:19:10 +00:00
|
|
|
PrintUnicode(aParagraphFormat);
|
1999-12-22 19:44:00 +00:00
|
|
|
Write("\");\n");
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetParagraphFormat(aParagraphFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::RemoveInlineProperty(nsIAtom *aProperty, const nsAReadableString &aAttribute)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoString propStr;
|
|
|
|
|
|
|
|
aProperty->ToString(propStr);
|
|
|
|
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.RemoveTextProperty(\"");
|
|
|
|
PrintUnicode(propStr);
|
|
|
|
Write("\", \"");
|
2001-04-07 00:45:26 +00:00
|
|
|
if (aAttribute.Length())
|
|
|
|
PrintUnicode(aAttribute);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::RemoveInlineProperty(aProperty, aAttribute);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-07 08:30:19 +00:00
|
|
|
nsHTMLEditorLog::DeleteSelection(nsIEditor::EDirection aAction)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.DeleteSelection(");
|
|
|
|
WriteInt("%d", aAction);
|
|
|
|
Write(");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteSelection(aAction);
|
|
|
|
}
|
|
|
|
|
1999-10-06 19:34:09 +00:00
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::InsertText(const nsAReadableString& aStringToInsert)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
|
|
|
Write("window.editorShell.InsertText(\"");
|
2000-11-17 00:25:31 +00:00
|
|
|
nsAutoString str(aStringToInsert);
|
|
|
|
PrintUnicode(str);
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertText(aStringToInsert);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-17 00:25:31 +00:00
|
|
|
nsHTMLEditorLog::InsertLineBreak()
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.InsertBreak();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-11-17 00:25:31 +00:00
|
|
|
return nsHTMLEditor::InsertLineBreak();
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Undo(PRUint32 aCount)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.Undo();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Undo(aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Redo(PRUint32 aCount)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.Redo();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Redo(aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::BeginTransaction()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.BeginBatchChanges();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::BeginTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::EndTransaction()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.EndBatchChanges();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::EndTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::SelectAll()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.SelectAll();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::BeginningOfDocument()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.BeginningOfDocument();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::BeginningOfDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::EndOfDocument()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.EndOfDocument();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::EndOfDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Cut()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.Cut();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Copy()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.Copy();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-14 23:38:21 +00:00
|
|
|
nsHTMLEditorLog::Paste(PRInt32 aSelectionType)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.Paste();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-04-14 23:38:21 +00:00
|
|
|
return nsHTMLEditor::Paste(aSelectionType);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-14 23:38:21 +00:00
|
|
|
nsHTMLEditorLog::PasteAsQuotation(PRInt32 aSelectionType)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.PasteAsQuotation();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-04-14 23:38:21 +00:00
|
|
|
return nsHTMLEditor::PasteAsQuotation(aSelectionType);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-14 23:38:21 +00:00
|
|
|
nsHTMLEditorLog::PasteAsPlaintextQuotation(PRInt32 aSelectionType)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.PasteAsQuotation();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-04-14 23:38:21 +00:00
|
|
|
return nsHTMLEditor::PasteAsPlaintextQuotation(aSelectionType);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::PasteAsCitedQuotation(const nsAReadableString& aCitation,
|
2000-04-14 23:38:21 +00:00
|
|
|
PRInt32 aSelectionType)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.PasteAsCitedQuotation(\"");
|
|
|
|
PrintUnicode(aCitation);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-04-14 23:38:21 +00:00
|
|
|
return nsHTMLEditor::PasteAsCitedQuotation(aCitation, aSelectionType);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::InsertAsQuotation(const nsAReadableString& aQuotedText,
|
1999-11-24 20:48:59 +00:00
|
|
|
nsIDOMNode **aNodeInserted)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.InsertAsQuotation(\"");
|
|
|
|
PrintUnicode(aQuotedText);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
1999-11-24 20:48:59 +00:00
|
|
|
return nsHTMLEditor::InsertAsQuotation(aQuotedText, aNodeInserted);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::InsertAsPlaintextQuotation(const nsAReadableString& aQuotedText,
|
1999-11-24 20:48:59 +00:00
|
|
|
nsIDOMNode **aNodeInserted)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.InsertAsQuotation(\"");
|
|
|
|
PrintUnicode(aQuotedText);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
1999-11-24 20:48:59 +00:00
|
|
|
return nsHTMLEditor::InsertAsPlaintextQuotation(aQuotedText, aNodeInserted);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::InsertAsCitedQuotation(const nsAReadableString& aQuotedText,
|
|
|
|
const nsAReadableString& aCitation,
|
2000-03-20 23:13:25 +00:00
|
|
|
PRBool aInsertHTML,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString& aCharset,
|
1999-11-24 20:48:59 +00:00
|
|
|
nsIDOMNode **aNodeInserted)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
Write("window.editorShell.InsertAsCitedQuotation(\"");
|
|
|
|
PrintUnicode(aQuotedText);
|
|
|
|
Write("\", \"");
|
|
|
|
PrintUnicode(aCitation);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-03-20 23:13:25 +00:00
|
|
|
return nsHTMLEditor::InsertAsCitedQuotation(aQuotedText, aCitation, aInsertHTML,
|
2000-01-04 20:38:12 +00:00
|
|
|
aCharset, aNodeInserted);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::SetBackgroundColor(const nsAReadableString& aColor)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.SetBackgroundColor(\"");
|
|
|
|
PrintUnicode(aColor);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetBackgroundColor(aColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::SetBodyAttribute(const nsAReadableString& aAttr, const nsAReadableString& aValue)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.SetBodyAttribute(\"");
|
|
|
|
PrintUnicode(aAttr);
|
|
|
|
Write("\", \"");
|
|
|
|
PrintUnicode(aValue);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetBodyAttribute(aAttr, aValue);
|
|
|
|
}
|
|
|
|
|
2000-02-10 05:14:52 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: InsertTableCell(PRInt32 aNumber, PRBool aAfter)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.InsertTableCell(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertTableCell(aNumber, aAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.InsertTableColumn(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertTableColumn(aNumber, aAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: InsertTableRow(PRInt32 aNumber, PRBool aAfter)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.InsertTableRow(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertTableRow(aNumber, aAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTable()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.DeleteTable();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableCell(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.DeleteTableCell(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableCell(aNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableCellContents()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.DeleteTableCellContents();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableCellContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableColumn(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.DeleteTableColumn(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableColumn(aNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableRow(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.DeleteTableRow(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableRow(aNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-07-01 00:37:12 +00:00
|
|
|
nsHTMLEditorLog:: JoinTableCells(PRBool aMergeNonContiguousContents)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.JoinTableCells();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-07-01 00:37:12 +00:00
|
|
|
return nsHTMLEditor::JoinTableCells(aMergeNonContiguousContents);
|
2000-02-10 05:14:52 +00:00
|
|
|
}
|
|
|
|
|
2000-05-04 22:32:24 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: SplitTableCell()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-05-04 22:32:24 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.SplitTableCell();\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SplitTableCell();
|
|
|
|
}
|
|
|
|
|
2000-02-10 05:14:52 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 05:14:52 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.NormalizeTable(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::NormalizeTable(aTable);
|
|
|
|
}
|
|
|
|
|
2000-07-01 00:37:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
2000-07-01 00:37:12 +00:00
|
|
|
{
|
|
|
|
Write("window.editorShell.SwitchTableCellHeaderType(\"");
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SwitchTableCellHeaderType(aSourceCell, aNewCell);
|
|
|
|
}
|
2000-02-10 05:14:52 +00:00
|
|
|
|
1999-08-19 13:19:10 +00:00
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::MakeOrChangeList(const nsAReadableString& aListType, PRBool entireList)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
1999-10-26 23:13:00 +00:00
|
|
|
Write("window.editorShell.MakeOrChangeList(\"");
|
1999-08-19 13:19:10 +00:00
|
|
|
PrintUnicode(aListType);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-09-14 05:59:19 +00:00
|
|
|
return nsHTMLEditor::MakeOrChangeList(aListType, entireList);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::Indent(const nsAReadableString& aIndent)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
|
|
|
Write("window.editorShell.Indent(\"");
|
|
|
|
PrintUnicode(aIndent);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Indent(aIndent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::Align(const nsAReadableString& aAlign)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
|
|
|
Write("window.editorShell.Align(\"");
|
|
|
|
PrintUnicode(aAlign);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Align(aAlign);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-14 00:13:27 +00:00
|
|
|
nsHTMLEditorLog::InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDeleteSelection)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
if (!aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PrintSelection();
|
|
|
|
PrintNode(node, 0);
|
1999-10-14 00:13:27 +00:00
|
|
|
Write("window.editorShell.InsertElementAtSelection(n0, ");
|
1999-08-19 13:19:10 +00:00
|
|
|
Write(aDeleteSelection ? "true" : "false");
|
|
|
|
Write(");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
1999-10-14 00:13:27 +00:00
|
|
|
return nsHTMLEditor::InsertElementAtSelection(aElement, aDeleteSelection);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
if (!aAnchorElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aAnchorElement);
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PrintSelection();
|
|
|
|
PrintNode(node, 0);
|
|
|
|
Write("window.editorShell.InsertLinkAroundSelection(n0);\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertLinkAroundSelection(aAnchorElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::ApplyStyleSheet(const nsAReadableString& aURL, nsICSSStyleSheet **aStyleSheet)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
2000-03-31 04:18:29 +00:00
|
|
|
// Note that the editorShell (IDL) method does
|
|
|
|
// not return the style sheet created from aURL
|
|
|
|
// TODO: Investigate if RemoveStyleSheet works or do we have to
|
|
|
|
// store the returned style sheet!
|
1999-08-19 13:19:10 +00:00
|
|
|
Write("window.editorShell.ApplyStyleSheet(\"");
|
|
|
|
PrintUnicode(aURL);
|
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-03-31 04:18:29 +00:00
|
|
|
return nsHTMLEditor::ApplyStyleSheet(aURL, aStyleSheet);
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 22:02:58 +00:00
|
|
|
NS_IMETHODIMP
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::SetDocumentTitle(const nsAReadableString& aTitle)
|
2001-02-26 22:02:58 +00:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
|
|
|
if (!mLocked && mFileStream)
|
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
|
|
|
Write("window.editorShell.SetDocumentTitle(\"");
|
|
|
|
nsAutoString str(aTitle);
|
|
|
|
PrintUnicode(str);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetDocumentTitle(aTitle);
|
|
|
|
}
|
|
|
|
|
1999-08-19 13:19:10 +00:00
|
|
|
NS_IMETHODIMP
|
2001-01-09 22:47:02 +00:00
|
|
|
nsHTMLEditorLog::StartLogging(nsIFile *aLogFile)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!aLogFile)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
|
|
|
result = StopLogging();
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
mFileStream = do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &result);
|
|
|
|
if (NS_FAILED(result)) return result;
|
1999-08-19 13:19:10 +00:00
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
result = mFileStream->Init(aLogFile, -1, -1);
|
1999-08-19 13:19:10 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
{
|
2001-01-09 22:47:02 +00:00
|
|
|
mFileStream = nsnull;
|
1999-08-19 13:19:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTxnMgr)
|
|
|
|
{
|
|
|
|
mEditorTxnLog = new nsEditorTxnLog(this);
|
|
|
|
|
|
|
|
if (mEditorTxnLog)
|
|
|
|
{
|
|
|
|
NS_ADDREF(mEditorTxnLog);
|
|
|
|
mTxnMgr->AddListener(mEditorTxnLog);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::StopLogging()
|
|
|
|
{
|
|
|
|
if (mTxnMgr && mEditorTxnLog)
|
|
|
|
mTxnMgr->RemoveListener(mEditorTxnLog);
|
|
|
|
|
|
|
|
if (mEditorTxnLog)
|
|
|
|
{
|
|
|
|
NS_RELEASE(mEditorTxnLog);
|
|
|
|
mEditorTxnLog = 0;
|
|
|
|
}
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
2001-01-09 22:47:02 +00:00
|
|
|
mFileStream->Close();
|
|
|
|
mFileStream = nsnull;
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::Write(const char *aBuffer)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (!aBuffer)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PRInt32 len = strlen(aBuffer);
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (mFileStream)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
2001-01-09 22:47:02 +00:00
|
|
|
PRUint32 retval;
|
1999-08-19 13:19:10 +00:00
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
result = mFileStream->Write(aBuffer, len, &retval);
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
#ifdef VERY_SLOW
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
result = mFileStream->Flush();
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
#endif // VERY_SLOW
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fwrite(aBuffer, 1, len, stdout);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::WriteInt(const char *aFormat, PRInt32 aInt)
|
|
|
|
{
|
|
|
|
if (!aFormat)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
sprintf(buf, aFormat, aInt);
|
|
|
|
|
|
|
|
return Write(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::Flush()
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2001-01-09 22:47:02 +00:00
|
|
|
if (mFileStream)
|
|
|
|
result = mFileStream->Flush();
|
1999-08-19 13:19:10 +00:00
|
|
|
else
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2001-04-07 00:45:26 +00:00
|
|
|
nsHTMLEditorLog::PrintUnicode(const nsAReadableString &aString)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
2001-06-30 11:02:25 +00:00
|
|
|
//const PRUnichar *uc = aString.get();
|
1999-08-19 13:19:10 +00:00
|
|
|
char buf[10];
|
2001-04-07 00:45:26 +00:00
|
|
|
nsReadingIterator <PRUnichar> beginIter,endIter;
|
|
|
|
aString.BeginReading(beginIter);
|
|
|
|
aString.EndReading(endIter);
|
|
|
|
while(beginIter != endIter)
|
1999-08-19 13:19:10 +00:00
|
|
|
{
|
2001-04-07 00:45:26 +00:00
|
|
|
if (nsCRT::IsAsciiAlpha(*beginIter) || nsCRT::IsAsciiDigit(*beginIter) || *beginIter == ' ')
|
|
|
|
sprintf(buf, "%c", *beginIter);
|
1999-08-19 13:19:10 +00:00
|
|
|
else
|
2001-04-07 00:45:26 +00:00
|
|
|
sprintf(buf, "\\u%.4x", *beginIter);
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
nsresult result = Write(buf);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-04-07 00:45:26 +00:00
|
|
|
++beginIter;
|
1999-08-19 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::PrintSelection()
|
|
|
|
{
|
2000-09-14 11:45:01 +00:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
1999-08-19 13:19:10 +00:00
|
|
|
nsresult result;
|
|
|
|
PRInt32 rangeCount;
|
|
|
|
|
|
|
|
result = GetSelection(getter_AddRefs(selection));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
result = selection->GetRangeCount(&rangeCount);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Write("selRanges = [ ");
|
|
|
|
|
|
|
|
PRInt32 i, j;
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 startOffset, endOffset;
|
|
|
|
|
|
|
|
for (i = 0; i < rangeCount; i++)
|
|
|
|
{
|
|
|
|
result = selection->GetRangeAt(i, getter_AddRefs(range));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-08-24 03:54:30 +00:00
|
|
|
result = range->GetStartContainer(getter_AddRefs(startNode));
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!startNode)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
result = range->GetStartOffset(&startOffset);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-08-24 03:54:30 +00:00
|
|
|
result = range->GetEndContainer(getter_AddRefs(endNode));
|
1999-08-19 13:19:10 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!endNode)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
result = range->GetEndOffset(&endOffset);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRInt32 *offsetArray = 0;
|
|
|
|
PRInt32 arrayLength = 0;
|
|
|
|
|
|
|
|
result = GetNodeTreeOffsets(startNode, &offsetArray, &arrayLength);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
Write(",\n ");
|
|
|
|
|
|
|
|
Write("[ [[");
|
|
|
|
|
|
|
|
for (j = 0; j < arrayLength; j++)
|
|
|
|
{
|
|
|
|
if (j != 0)
|
|
|
|
Write(", ");
|
|
|
|
WriteInt("%d", offsetArray[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Write("], ");
|
|
|
|
WriteInt("%3d", startOffset);
|
|
|
|
Write("], ");
|
|
|
|
|
|
|
|
if (startNode != endNode)
|
|
|
|
{
|
|
|
|
delete []offsetArray;
|
|
|
|
offsetArray = 0;
|
|
|
|
arrayLength = 0;
|
|
|
|
|
|
|
|
result = GetNodeTreeOffsets(endNode, &offsetArray, &arrayLength);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Write("[[");
|
|
|
|
|
|
|
|
for (j = 0; j < arrayLength; j++)
|
|
|
|
{
|
|
|
|
if (j != 0)
|
|
|
|
Write(", ");
|
|
|
|
WriteInt("%d", offsetArray[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete []offsetArray;
|
|
|
|
|
|
|
|
Write("], ");
|
|
|
|
WriteInt("%3d", endOffset);
|
|
|
|
Write("] ]");
|
|
|
|
}
|
|
|
|
|
|
|
|
Write(" ];\nEditorSetSelectionFromOffsets(selRanges);\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::PrintElementNode(nsIDOMNode *aNode, PRInt32 aDepth)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
nsAutoString tag, name, value;
|
|
|
|
nsCOMPtr<nsIDOMElement> ele = do_QueryInterface(aNode);
|
|
|
|
nsCOMPtr<nsIDOMNamedNodeMap> map;
|
|
|
|
|
|
|
|
if (!ele)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
result = ele->GetTagName(tag);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Write("n");
|
|
|
|
WriteInt("%d", aDepth);
|
|
|
|
Write(" = window.editorShell.editorDocument.createElement(\"");
|
|
|
|
PrintUnicode(tag);
|
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
result = aNode->GetAttributes(getter_AddRefs(map));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!map)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PRUint32 i, len;
|
|
|
|
nsCOMPtr<nsIDOMNode> attr;
|
|
|
|
|
|
|
|
result = map->GetLength(&len);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
result = map->Item(i, getter_AddRefs(attr));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!attr)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
result = PrintAttributeNode(attr, aDepth);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = PrintNodeChildren(aNode, aDepth);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::PrintAttributeNode(nsIDOMNode *aNode, PRInt32 aDepth)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIDOMAttr> attr = do_QueryInterface(aNode);
|
|
|
|
|
|
|
|
if (!attr)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsAutoString str;
|
|
|
|
|
|
|
|
result = attr->GetName(str);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Write("a");
|
|
|
|
WriteInt("%d", aDepth);
|
|
|
|
Write(" = window.editorShell.editorDocument.createAttribute(\"");
|
|
|
|
PrintUnicode(str);
|
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
result = attr->GetValue(str);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Write("a");
|
|
|
|
WriteInt("%d", aDepth);
|
|
|
|
Write(".value = \"");
|
|
|
|
PrintUnicode(str);
|
|
|
|
Write("\";\n");
|
|
|
|
|
|
|
|
Write("n");
|
|
|
|
WriteInt("%d", aDepth);
|
|
|
|
Write(".setAttributeNode(a");
|
|
|
|
WriteInt("%d", aDepth);
|
|
|
|
Write(");\n");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::PrintNodeChildren(nsIDOMNode *aNode, PRInt32 aDepth)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (!aNode)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> list;
|
|
|
|
|
|
|
|
result = aNode->GetChildNodes(getter_AddRefs(list));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!list)
|
|
|
|
{
|
|
|
|
// Must not have any children!
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 i, len;
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
|
|
|
|
result = list->GetLength(&len);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
result = list->Item(i, getter_AddRefs(node));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
result = PrintNode(node, aDepth + 1);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Write("n");
|
|
|
|
WriteInt("%d", aDepth);
|
|
|
|
Write(".appendChild(n");
|
|
|
|
WriteInt("%d", aDepth+1);
|
|
|
|
Write(");\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::PrintTextNode(nsIDOMNode *aNode, PRInt32 aDepth)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMCharacterData> cd = do_QueryInterface(aNode);
|
|
|
|
|
|
|
|
if (!cd)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsAutoString str;
|
|
|
|
|
|
|
|
result = cd->GetData(str);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Write("n");
|
|
|
|
WriteInt("%d", aDepth);
|
|
|
|
Write(" = window.editorShell.editorDocument.createTextNode(\"");
|
|
|
|
PrintUnicode(str);
|
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::PrintNode(nsIDOMNode *aNode, PRInt32 aDepth)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
if (!aNode)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PRUint16 nodeType;
|
|
|
|
|
|
|
|
result = aNode->GetNodeType(&nodeType);
|
|
|
|
|
|
|
|
switch (nodeType)
|
|
|
|
{
|
|
|
|
case nsIDOMNode::ELEMENT_NODE:
|
|
|
|
result = PrintElementNode(aNode, aDepth);
|
|
|
|
break;
|
|
|
|
case nsIDOMNode::TEXT_NODE:
|
|
|
|
result = PrintTextNode(aNode, aDepth);
|
|
|
|
break;
|
|
|
|
case nsIDOMNode::ATTRIBUTE_NODE:
|
|
|
|
result = PrintAttributeNode(aNode, aDepth);
|
|
|
|
break;
|
|
|
|
case nsIDOMNode::CDATA_SECTION_NODE:
|
|
|
|
case nsIDOMNode::ENTITY_REFERENCE_NODE:
|
|
|
|
case nsIDOMNode::ENTITY_NODE:
|
|
|
|
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
|
|
|
|
case nsIDOMNode::COMMENT_NODE:
|
|
|
|
case nsIDOMNode::DOCUMENT_NODE:
|
|
|
|
case nsIDOMNode::DOCUMENT_TYPE_NODE:
|
|
|
|
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
|
|
|
|
case nsIDOMNode::NOTATION_NODE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::GetNodeTreeOffsets(nsIDOMNode *aNode, PRInt32 **aResult, PRInt32 *aLength)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (!aNode || !aResult || !aLength)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aResult = 0;
|
|
|
|
*aLength = 0;
|
|
|
|
|
|
|
|
nsIDOMNode *parent = aNode;
|
|
|
|
PRInt32 i = 0;
|
|
|
|
|
|
|
|
// Count the number of parent nodes above aNode.
|
|
|
|
|
|
|
|
while (parent)
|
|
|
|
{
|
|
|
|
result = parent->GetParentNode(&parent);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate an array big enough to hold all the offsets.
|
|
|
|
|
|
|
|
*aResult = new PRInt32[i];
|
|
|
|
|
|
|
|
if (!aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aLength = i;
|
|
|
|
|
|
|
|
while (aNode && i > 0)
|
|
|
|
{
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
|
|
|
|
result = aNode->GetParentNode(&parent);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
{
|
|
|
|
delete [](*aResult);
|
|
|
|
*aResult = 0;
|
|
|
|
*aLength = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (aNode)
|
|
|
|
{
|
|
|
|
result = aNode->GetPreviousSibling(&aNode);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
{
|
|
|
|
delete [](*aResult);
|
|
|
|
*aResult = 0;
|
|
|
|
*aLength = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aNode)
|
|
|
|
++offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*aResult)[--i] = offset;
|
|
|
|
aNode = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::Lock()
|
|
|
|
{
|
|
|
|
mLocked++;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::Unlock()
|
|
|
|
{
|
|
|
|
--mLocked;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NEVER_ENABLE_THIS_JAVASCRIPT
|
|
|
|
|
|
|
|
function EditorGetNodeAtOffsets(offsets)
|
|
|
|
{
|
|
|
|
var node = null;
|
|
|
|
var i;
|
|
|
|
|
|
|
|
node = window.editorShell.editorDocument;
|
|
|
|
|
|
|
|
for (i = 0; i < offsets.length; i++)
|
|
|
|
{
|
|
|
|
node = node.childNodes[offsets[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorSetSelectionFromOffsets(selRanges)
|
|
|
|
{
|
|
|
|
var rangeArr, start, end, i, node, offset;
|
|
|
|
var selection = window.editorShell.editorSelection;
|
|
|
|
|
|
|
|
selection.clearSelection();
|
|
|
|
|
|
|
|
for (i = 0; i < selRanges.length; i++)
|
|
|
|
{
|
|
|
|
rangeArr = selRanges[i];
|
|
|
|
start = rangeArr[0];
|
|
|
|
end = rangeArr[1];
|
|
|
|
|
|
|
|
var range = window.editorShell.editorDocument.createRange();
|
|
|
|
|
|
|
|
node = EditorGetNodeAtOffsets(start[0]);
|
|
|
|
offset = start[1];
|
|
|
|
|
|
|
|
range.setStart(node, offset);
|
|
|
|
|
|
|
|
node = EditorGetNodeAtOffsets(end[0]);
|
|
|
|
offset = end[1];
|
|
|
|
|
|
|
|
range.setEnd(node, offset);
|
|
|
|
|
|
|
|
selection.addRange(range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|