2001-09-26 02:53:13 +04: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 17:19:10 +04:00
|
|
|
*
|
2001-09-26 02:53:13 +04: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 17:19:10 +04:00
|
|
|
*
|
2001-09-26 02:53:13 +04: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 17:19:10 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-26 02:53:13 +04: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 06:43:54 +03:00
|
|
|
*
|
2001-09-26 02:53:13 +04:00
|
|
|
* Contributor(s):
|
2000-01-11 23:49:15 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-26 02:53:13 +04: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 17:19:10 +04: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 15:45:01 +04:00
|
|
|
#include "nsISelection.h"
|
1999-08-19 17:19:10 +04:00
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsHTMLEditorLog.h"
|
2003-01-18 07:21:04 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-08-19 17:19:10 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2002-11-18 18:43:19 +03:00
|
|
|
#include "prprf.h"
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
#include "nsEditorTxnLog.h"
|
|
|
|
|
|
|
|
#define LOCK_LOG(doc)
|
|
|
|
#define UNLOCK_LOG(doc)
|
|
|
|
|
|
|
|
nsHTMLEditorLog::nsHTMLEditorLog()
|
|
|
|
{
|
|
|
|
mLocked = -1;
|
|
|
|
mEditorTxnLog = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLEditorLog::~nsHTMLEditorLog()
|
|
|
|
{
|
|
|
|
StopLogging();
|
|
|
|
}
|
|
|
|
|
2001-10-02 07:18:08 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLEditorLog, nsHTMLEditor, nsIEditorLogging)
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::SetInlineProperty(nsIAtom *aProperty, const nsAString &aAttribute, const nsAString &aValue)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoString propStr;
|
|
|
|
|
|
|
|
aProperty->ToString(propStr);
|
|
|
|
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("atomService = Components.classes[\"@mozilla.org/atom-service;1\"].getService(Components.interfaces.nsIAtomService);\n");
|
|
|
|
Write("propAtom = atomService.getAtom(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(propStr);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("\");\n");
|
|
|
|
Write("GetCurrentEditor().setInlineProperty(propAtom, \"");
|
2001-04-07 04:45:26 +04:00
|
|
|
if (aAttribute.Length())
|
|
|
|
PrintUnicode(aAttribute);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("\", \"");
|
2001-04-07 04:45:26 +04:00
|
|
|
if (aValue.Length())
|
|
|
|
PrintUnicode(aValue);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetInlineProperty(aProperty, aAttribute, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-03 03:19:29 +04:00
|
|
|
nsHTMLEditorLog::SetParagraphFormat(const nsAString& aParagraphFormat)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().setParagraphFormat(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aParagraphFormat);
|
1999-12-22 22:44:00 +03:00
|
|
|
Write("\");\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetParagraphFormat(aParagraphFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::RemoveInlineProperty(nsIAtom *aProperty, const nsAString &aAttribute)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoString propStr;
|
|
|
|
|
|
|
|
aProperty->ToString(propStr);
|
|
|
|
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("atomService = Components.classes[\"@mozilla.org/atom-service;1\"].getService(Components.interfaces.nsIAtomService);\n");
|
|
|
|
Write("propAtom = atomService.getAtom(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(propStr);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("\");\n");
|
|
|
|
Write("GetCurrentEditor().removeInlineProperty(propAtom, \"");
|
2001-04-07 04:45:26 +04:00
|
|
|
if (aAttribute.Length())
|
|
|
|
PrintUnicode(aAttribute);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::RemoveInlineProperty(aProperty, aAttribute);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-07 11:30:19 +03:00
|
|
|
nsHTMLEditorLog::DeleteSelection(nsIEditor::EDirection aAction)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().deleteSelection(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aAction);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteSelection(aAction);
|
|
|
|
}
|
|
|
|
|
1999-10-06 23:34:09 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::InsertText(const nsAString& aStringToInsert)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertText(\"");
|
2000-11-17 03:25:31 +03:00
|
|
|
nsAutoString str(aStringToInsert);
|
|
|
|
PrintUnicode(str);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertText(aStringToInsert);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-17 03:25:31 +03:00
|
|
|
nsHTMLEditorLog::InsertLineBreak()
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertLineBreak();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-11-17 03:25:31 +03:00
|
|
|
return nsHTMLEditor::InsertLineBreak();
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Undo(PRUint32 aCount)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().undo(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aCount);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Undo(aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Redo(PRUint32 aCount)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().redo(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aCount);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Redo(aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::BeginTransaction()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().beginTransaction();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::BeginTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::EndTransaction()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().endTransaction();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::EndTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::SelectAll()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().selectAll();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::BeginningOfDocument()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().beginningOfDocument();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::BeginningOfDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::EndOfDocument()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().endOfDocument();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::EndOfDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Cut()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().cut();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::Copy()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().copy();\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-09-20 16:41:24 +04:00
|
|
|
nsHTMLEditorLog::Paste(PRInt32 aClipboardType)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().paste(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aClipboardType);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
return nsHTMLEditor::Paste(aClipboardType);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-09-20 16:41:24 +04:00
|
|
|
nsHTMLEditorLog::PasteAsQuotation(PRInt32 aClipboardType)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().pasteAsQuotation(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aClipboardType);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
return nsHTMLEditor::PasteAsQuotation(aClipboardType);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-09-20 16:41:24 +04:00
|
|
|
nsHTMLEditorLog::PasteAsPlaintextQuotation(PRInt32 aClipboardType)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().pasteAsQuotation(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aClipboardType);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
return nsHTMLEditor::PasteAsPlaintextQuotation(aClipboardType);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::PasteAsCitedQuotation(const nsAString& aCitation,
|
2002-09-20 16:41:24 +04:00
|
|
|
PRInt32 aClipboardType)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().pasteAsCitedQuotation(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aCitation);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("\", ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aClipboardType);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
return nsHTMLEditor::PasteAsCitedQuotation(aCitation, aClipboardType);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::InsertAsQuotation(const nsAString& aQuotedText,
|
1999-11-24 23:48:59 +03:00
|
|
|
nsIDOMNode **aNodeInserted)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertAsQuotation(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aQuotedText);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
1999-11-24 23:48:59 +03:00
|
|
|
return nsHTMLEditor::InsertAsQuotation(aQuotedText, aNodeInserted);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
|
2002-10-09 01:22:27 +04:00
|
|
|
PRBool aAddCites,
|
1999-11-24 23:48:59 +03:00
|
|
|
nsIDOMNode **aNodeInserted)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertAsQuotation(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aQuotedText);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2002-10-09 01:22:27 +04:00
|
|
|
return nsHTMLEditor::InsertAsPlaintextQuotation(aQuotedText,
|
|
|
|
aAddCites,
|
|
|
|
aNodeInserted);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::InsertAsCitedQuotation(const nsAString& aQuotedText,
|
|
|
|
const nsAString& aCitation,
|
2000-03-21 02:13:25 +03:00
|
|
|
PRBool aInsertHTML,
|
1999-11-24 23:48:59 +03:00
|
|
|
nsIDOMNode **aNodeInserted)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertAsCitedQuotation(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aQuotedText);
|
|
|
|
Write("\", \"");
|
|
|
|
PrintUnicode(aCitation);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("\", ");
|
|
|
|
Write(aInsertHTML ? "true" : "false");
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-03-21 02:13:25 +03:00
|
|
|
return nsHTMLEditor::InsertAsCitedQuotation(aQuotedText, aCitation, aInsertHTML,
|
2003-06-12 18:51:37 +04:00
|
|
|
aNodeInserted);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::SetBackgroundColor(const nsAString& aColor)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().setBackgroundColor(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aColor);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetBackgroundColor(aColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::SetBodyAttribute(const nsAString& aAttr, const nsAString& aValue)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().setBodyAttribute(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aAttr);
|
|
|
|
Write("\", \"");
|
|
|
|
PrintUnicode(aValue);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetBodyAttribute(aAttr, aValue);
|
|
|
|
}
|
|
|
|
|
2000-02-10 08:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: InsertTableCell(PRInt32 aNumber, PRBool aAfter)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertTableCell(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aNumber);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(", ");
|
|
|
|
Write(aAfter ? "true" : "false");
|
|
|
|
Write(");\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertTableCell(aNumber, aAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertTableColumn(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aNumber);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(", ");
|
|
|
|
Write(aAfter ? "true" : "false");
|
|
|
|
Write(");\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertTableColumn(aNumber, aAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: InsertTableRow(PRInt32 aNumber, PRBool aAfter)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertTableRow(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aNumber);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(", ");
|
|
|
|
Write(aAfter ? "true" : "false");
|
|
|
|
Write(");\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertTableRow(aNumber, aAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTable()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().deleteTable();\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableCell(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().deleteTableCell(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aNumber);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableCell(aNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableCellContents()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().deleteTableCellContents();\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableCellContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableColumn(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().deleteTableColumn(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aNumber);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableColumn(aNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: DeleteTableRow(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().deleteTableRow(");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aNumber);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(");\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::DeleteTableRow(aNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-07-01 04:37:12 +04:00
|
|
|
nsHTMLEditorLog:: JoinTableCells(PRBool aMergeNonContiguousContents)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().joinTableCells(");
|
|
|
|
Write(aMergeNonContiguousContents ? "true" : "false");
|
|
|
|
Write(");\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2000-07-01 04:37:12 +04:00
|
|
|
return nsHTMLEditor::JoinTableCells(aMergeNonContiguousContents);
|
2000-02-10 08:14:52 +03:00
|
|
|
}
|
|
|
|
|
2000-05-05 02:32:24 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: SplitTableCell()
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-05-05 02:32:24 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().splitTableCell();\n");
|
2000-05-05 02:32:24 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SplitTableCell();
|
|
|
|
}
|
|
|
|
|
2000-02-10 08:14:52 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-02-10 08:14:52 +03:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aTable);
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PrintNode(node, 0);
|
|
|
|
Write("GetCurrentEditor().normalizeTable(n0);\n");
|
2000-02-10 08:14:52 +03:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::NormalizeTable(aTable);
|
|
|
|
}
|
|
|
|
|
2000-07-01 04:37:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
2000-07-01 04:37:12 +04:00
|
|
|
{
|
2002-09-20 16:41:24 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aSourceCell);
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PrintNode(node, 0);
|
|
|
|
Write("GetCurrentEditor().switchTableCellHeaderType(n0);\n");
|
2000-07-01 04:37:12 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SwitchTableCellHeaderType(aSourceCell, aNewCell);
|
|
|
|
}
|
2000-02-10 08:14:52 +03:00
|
|
|
|
1999-08-19 17:19:10 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::MakeOrChangeList(const nsAString& aListType, PRBool entireList, const nsAString& aBulletType)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().makeOrChangeList(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aListType);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("\", ");
|
|
|
|
Write(entireList ? "true" : "false");
|
|
|
|
Write(", \"");
|
|
|
|
PrintUnicode(aBulletType);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
2001-12-12 06:57:32 +03:00
|
|
|
return nsHTMLEditor::MakeOrChangeList(aListType, entireList, aBulletType);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::Indent(const nsAString& aIndent)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().indent(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aIndent);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Indent(aIndent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::Align(const nsAString& aAlign)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().align(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(aAlign);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::Align(aAlign);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:13:27 +04:00
|
|
|
nsHTMLEditorLog::InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDeleteSelection)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04: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);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertElementAtSelection(n0, ");
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(aDeleteSelection ? "true" : "false");
|
|
|
|
Write(");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:13:27 +04:00
|
|
|
return nsHTMLEditor::InsertElementAtSelection(aElement, aDeleteSelection);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLEditorLog::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
|
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (!mLocked && mFileStream)
|
1999-08-19 17:19:10 +04: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);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().insertLinkAroundSelection(n0);\n");
|
1999-08-19 17:19:10 +04:00
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::InsertLinkAroundSelection(aAnchorElement);
|
|
|
|
}
|
|
|
|
|
2001-02-27 01:02:58 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::SetDocumentTitle(const nsAString& aTitle)
|
2001-02-27 01:02:58 +03:00
|
|
|
{
|
|
|
|
nsAutoHTMLEditorLogLock logLock(this);
|
|
|
|
|
|
|
|
if (!mLocked && mFileStream)
|
|
|
|
{
|
|
|
|
PrintSelection();
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
Write("GetCurrentEditor().setDocumentTitle(\"");
|
2001-02-27 01:02:58 +03:00
|
|
|
nsAutoString str(aTitle);
|
|
|
|
PrintUnicode(str);
|
|
|
|
Write("\");\n");
|
|
|
|
Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsHTMLEditor::SetDocumentTitle(aTitle);
|
|
|
|
}
|
|
|
|
|
1999-08-19 17:19:10 +04:00
|
|
|
NS_IMETHODIMP
|
2001-01-10 01:47:02 +03:00
|
|
|
nsHTMLEditorLog::StartLogging(nsIFile *aLogFile)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!aLogFile)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
result = StopLogging();
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-01-18 07:21:04 +03:00
|
|
|
result = NS_NewLocalFileOutputStream(getter_AddRefs(mFileStream), aLogFile);
|
2001-01-10 01:47:02 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
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-10 01:47:02 +03:00
|
|
|
if (mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2001-01-10 01:47:02 +03:00
|
|
|
mFileStream->Close();
|
|
|
|
mFileStream = nsnull;
|
1999-08-19 17:19:10 +04: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-10 01:47:02 +03:00
|
|
|
if (mFileStream)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2001-01-10 01:47:02 +03:00
|
|
|
PRUint32 retval;
|
1999-08-19 17:19:10 +04:00
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
result = mFileStream->Write(aBuffer, len, &retval);
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
#ifdef VERY_SLOW
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
result = mFileStream->Flush();
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
#endif // VERY_SLOW
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fwrite(aBuffer, 1, len, stdout);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-11-18 18:43:19 +03:00
|
|
|
nsHTMLEditorLog::WriteInt(PRInt32 aInt)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
|
2002-11-18 18:43:19 +03:00
|
|
|
PR_snprintf(buf, sizeof(buf), "%d", aInt);
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
return Write(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::Flush()
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2001-01-10 01:47:02 +03:00
|
|
|
if (mFileStream)
|
|
|
|
result = mFileStream->Flush();
|
1999-08-19 17:19:10 +04:00
|
|
|
else
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLEditorLog::PrintUnicode(const nsAString &aString)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2001-06-30 15:02:25 +04:00
|
|
|
//const PRUnichar *uc = aString.get();
|
1999-08-19 17:19:10 +04:00
|
|
|
char buf[10];
|
2001-04-07 04:45:26 +04:00
|
|
|
nsReadingIterator <PRUnichar> beginIter,endIter;
|
|
|
|
aString.BeginReading(beginIter);
|
|
|
|
aString.EndReading(endIter);
|
|
|
|
while(beginIter != endIter)
|
1999-08-19 17:19:10 +04:00
|
|
|
{
|
2001-04-07 04:45:26 +04:00
|
|
|
if (nsCRT::IsAsciiAlpha(*beginIter) || nsCRT::IsAsciiDigit(*beginIter) || *beginIter == ' ')
|
2002-11-18 18:43:19 +03:00
|
|
|
PR_snprintf(buf, sizeof(buf), "%c", *beginIter);
|
1999-08-19 17:19:10 +04:00
|
|
|
else
|
2002-11-18 18:43:19 +03:00
|
|
|
PR_snprintf(buf, sizeof(buf), "\\u%.4x", *beginIter);
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
nsresult result = Write(buf);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-04-07 04:45:26 +04:00
|
|
|
++beginIter;
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLEditorLog::PrintSelection()
|
|
|
|
{
|
2000-09-14 15:45:01 +04:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
1999-08-19 17:19:10 +04: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 07:54:30 +04:00
|
|
|
result = range->GetStartContainer(getter_AddRefs(startNode));
|
1999-08-19 17:19:10 +04: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 07:54:30 +04:00
|
|
|
result = range->GetEndContainer(getter_AddRefs(endNode));
|
1999-08-19 17:19:10 +04: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(", ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(offsetArray[j]);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Write("], ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(startOffset);
|
1999-08-19 17:19:10 +04:00
|
|
|
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(", ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(offsetArray[j]);
|
1999-08-19 17:19:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
delete []offsetArray;
|
|
|
|
|
|
|
|
Write("], ");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(endOffset);
|
1999-08-19 17:19:10 +04:00
|
|
|
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");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(" = GetCurrentEditor().editorDocument.createElement(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
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");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(" = GetCurrentEditor().editorDocument.createAttribute(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
PrintUnicode(str);
|
|
|
|
Write("\");\n");
|
|
|
|
|
|
|
|
result = attr->GetValue(str);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Write("a");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(".value = \"");
|
|
|
|
PrintUnicode(str);
|
|
|
|
Write("\";\n");
|
|
|
|
|
|
|
|
Write("n");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(".setAttributeNode(a");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth);
|
1999-08-19 17:19:10 +04:00
|
|
|
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");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth);
|
1999-08-19 17:19:10 +04:00
|
|
|
Write(".appendChild(n");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth+1);
|
1999-08-19 17:19:10 +04:00
|
|
|
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");
|
2002-11-18 18:43:19 +03:00
|
|
|
WriteInt(aDepth);
|
2002-09-20 16:41:24 +04:00
|
|
|
Write(" = GetCurrentEditor().editorDocument.createTextNode(\"");
|
1999-08-19 17:19:10 +04:00
|
|
|
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;
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
node = GetCurrentEditor().editorDocument;
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
for (i = 0; i < offsets.length; i++)
|
|
|
|
{
|
|
|
|
node = node.childNodes[offsets[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EditorSetSelectionFromOffsets(selRanges)
|
|
|
|
{
|
|
|
|
var rangeArr, start, end, i, node, offset;
|
2002-09-20 16:41:24 +04:00
|
|
|
var selection = GetCurrentEditor().editorSelection;
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
selection.clearSelection();
|
|
|
|
|
|
|
|
for (i = 0; i < selRanges.length; i++)
|
|
|
|
{
|
|
|
|
rangeArr = selRanges[i];
|
|
|
|
start = rangeArr[0];
|
|
|
|
end = rangeArr[1];
|
|
|
|
|
2002-09-20 16:41:24 +04:00
|
|
|
var range = GetCurrentEditor().editorDocument.createRange();
|
1999-08-19 17:19:10 +04:00
|
|
|
|
|
|
|
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
|